Mon Jun 3 15:21:17 PDT 2002
[netwalk.git] / widget.e
blob89bdcd6941aab4246332f4ee23d7aad22e36ff15
1 deferred class WIDGET
2 inherit
3 SDL_CONSTANT;
4 COLOR_TABLE;
5 CONFIG
6 feature
7 has_focus : BOOLEAN
9 put_focus(b : BOOLEAN) is
11 has_focus := b
12 end
14 font : TTF_FONT is
16 Result := config.mainfont
17 end
19 widget_init is
21 !!signal_table.make
22 end
24 free is
26 end
28 signal_activate : INTEGER is 1
29 signal_cancel : INTEGER is 2
30 signal_change : INTEGER is 3
32 signal_table : DICTIONARY[COMMAND, INTEGER]
34 put_command(c : COMMAND; i : INTEGER) is
36 signal_table.put(c, i)
37 end
39 raise_signal(i : INTEGER) is
41 if signal_table.has(i) then
42 signal_table.at(i).execute
43 end
44 end
46 offsetx : INTEGER
47 offsety : INTEGER
48 width : INTEGER
49 height : INTEGER
51 put_xy(x, y : INTEGER) is
53 offsetx := x
54 offsety := y
55 end
57 put_size(w, h : INTEGER) is
59 width := w
60 height := h
61 end
63 contains(x, y : INTEGER) : BOOLEAN is
65 Result := x >= offsetx and then x < offsetx + width
66 and then y >= offsety and then y < offsety + height
67 end
69 handle_event(e : EVENT) is
71 e.put_x(e.x - offsetx)
72 e.put_y(e.y - offsety)
73 process_event(e)
74 end
76 process_event(e : EVENT) is
77 deferred
78 end
80 update is
81 deferred
82 end
84 blank is
86 fill_rect(0, 0, width, height, black)
87 end
89 fill_rect(x, y, w, h : INTEGER; c : COLOR) is
91 ext_fill_rect(x + offsetx, y + offsety, w, h, c.to_integer)
92 end
94 ext_fill_rect(x, y, w, h, c : INTEGER) is
95 external "C"
96 end
98 blit(img : IMAGE; x, y : INTEGER) is
100 img.blit(x + offsetx, y + offsety)
103 ext_blit_surface(p : POINTER; x, y : INTEGER) is
104 external "C"
107 ext_get_mouse_state is
108 external "C"
111 last_mouse_x : INTEGER is
113 Result := get_last_mouse_x - offsetx
116 last_mouse_y : INTEGER is
118 Result := get_last_mouse_y - offsety
121 get_last_mouse_x : INTEGER is
122 external "C"
125 get_last_mouse_y : INTEGER is
126 external "C"
129 text_width : INTEGER
130 text_height : INTEGER
131 measure_text_size(s : STRING) is
133 ext_get_text_size(font.to_external, s.to_external)
134 text_width := ext_get_tsw
135 text_height := ext_get_tsh
138 ext_get_text_size(f : POINTER; s : POINTER) is
139 external "C"
142 ext_get_tsw : INTEGER is
143 external "C"
146 ext_get_tsh : INTEGER is
147 external "C"