Rev 7227 | Rev 7757 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7227 | Rev 7447 | ||
---|---|---|---|
1 | //list_box |
- | |
2 | #ifndef INCLUDE_LIST_BOX_H |
1 | #ifndef INCLUDE_LIST_BOX_H |
3 | #define INCLUDE_LIST_BOX_H |
2 | #define INCLUDE_LIST_BOX_H |
4 | 3 | ||
5 | #ifndef INCLUDE_KOLIBRI_H |
4 | #ifndef INCLUDE_KOLIBRI_H |
6 | #include "../lib/kolibri.h" |
5 | #include "../lib/kolibri.h" |
7 | #endif |
6 | #endif |
8 | 7 | ||
9 | struct llist |
8 | struct llist |
10 | { |
9 | { |
11 | int x, y, w, h, item_h, item_w; |
10 | int x, y, w, h, item_h, item_w; |
12 | int count, visible, first, column_max; //visible = row_max |
11 | int count, visible, first, column_max; //visible = row_max |
13 | int cur_x, cur_y; |
12 | int cur_x, cur_y; |
14 | int text_y; |
13 | int text_y; |
15 | byte font_w, font_h, font_type; |
14 | byte font_w, font_h, font_type; |
16 | byte wheel_size; |
15 | byte wheel_size; |
17 | byte active; |
16 | byte active; |
18 | byte no_selection; |
17 | byte no_selection; |
19 | byte horisontal_selelection; |
18 | byte horisontal_selelection; |
20 | void ClearList(); |
19 | void ClearList(); |
21 | void SetSizes(int xx, yy, ww, hh, item_hh); |
20 | void SetSizes(int xx, yy, ww, hh, item_hh); |
22 | void SetFont(dword font_ww, font_hh, font_tt); |
21 | void SetFont(dword font_ww, font_hh, font_tt); |
23 | int ProcessKey(dword key); |
22 | int ProcessKey(dword key); |
24 | int ProcessMouse(int xx, yy); |
23 | int ProcessMouse(int xx, yy); |
25 | int MouseOver(int xx, yy); |
24 | int MouseOver(int xx, yy); |
26 | int MouseScroll(dword scroll_state); |
25 | int MouseScroll(dword scroll_state); |
27 | int KeyDown(); |
26 | int KeyDown(); |
28 | int KeyUp(); |
27 | int KeyUp(); |
29 | int KeyHome(); |
28 | int KeyHome(); |
30 | int KeyEnd(); |
29 | int KeyEnd(); |
31 | int KeyPgDown(); |
30 | int KeyPgDown(); |
32 | int KeyPgUp(); |
31 | int KeyPgUp(); |
33 | int KeyLeft(); |
32 | int KeyLeft(); |
34 | int KeyRight(); |
33 | int KeyRight(); |
35 | void CheckDoesValuesOkey(); |
34 | void CheckDoesValuesOkey(); |
36 | void debug(); |
35 | void debug(); |
37 | }; |
36 | }; |
38 | 37 | ||
39 | :void llist::debug() |
38 | :void llist::debug() |
40 | { |
39 | { |
41 | char yi[128]; |
40 | char yi[128]; |
42 | sprintf(#yi, "%s %d %s %d %s %d %s %d %s %d %s %d", "first:", first, "visible:", visible, "count:", count, "col_max:", column_max, "cur_y:", cur_y, "cur_x:", cur_x); |
41 | sprintf(#yi, "%s %d %s %d %s %d %s %d %s %d %s %d", "first:", first, "visible:", visible, "count:", count, "col_max:", column_max, "cur_y:", cur_y, "cur_x:", cur_x); |
43 | debugln(#yi); |
42 | debugln(#yi); |
44 | } |
43 | } |
45 | 44 | ||
46 | 45 | ||
47 | :void llist::ClearList() |
46 | :void llist::ClearList() |
48 | { |
47 | { |
49 | count = visible = first = cur_y = cur_x = 0; |
48 | count = visible = first = cur_y = cur_x = 0; |
50 | } |
49 | } |
51 | 50 | ||
52 | 51 | ||
53 | :void llist::SetSizes(int xx, yy, ww, hh, item_hh) |
52 | :void llist::SetSizes(int xx, yy, ww, hh, item_hh) |
54 | { |
53 | { |
55 | x = xx; |
54 | x = xx; |
56 | y = yy; |
55 | y = yy; |
57 | w = ww; |
56 | w = ww; |
58 | h = hh; |
57 | h = hh; |
59 | item_h = item_hh; |
58 | item_h = item_hh; |
60 | text_y = item_h - font_h / 2; |
59 | text_y = item_h - font_h / 2; |
61 | visible = h / item_h; |
60 | visible = h / item_h; |
62 | wheel_size = 3; |
61 | wheel_size = 3; |
63 | CheckDoesValuesOkey(); |
62 | CheckDoesValuesOkey(); |
64 | } |
63 | } |
65 | 64 | ||
66 | 65 | ||
67 | :void llist::SetFont(dword font_ww, font_hh, font_tt) |
66 | :void llist::SetFont(dword font_ww, font_hh, font_tt) |
68 | { |
67 | { |
69 | font_w = font_ww; |
68 | font_w = font_ww; |
70 | font_h = font_hh; |
69 | font_h = font_hh; |
71 | font_type = font_tt; |
70 | font_type = font_tt; |
72 | } |
71 | } |
73 | 72 | ||
74 | 73 | ||
75 | :int llist::MouseScroll(dword scroll_state) |
74 | :int llist::MouseScroll(dword scroll_state) |
76 | { |
75 | { |
77 | if (count<=visible) return 0; |
76 | if (count<=visible) return 0; |
78 | if (scroll_state == 65535) |
77 | if (scroll_state == 65535) |
79 | { |
78 | { |
80 | if (first == 0) return 0; |
79 | if (first == 0) return 0; |
81 | if (first > wheel_size+1) first -= wheel_size; else first=0; |
80 | if (first > wheel_size+1) first -= wheel_size; else first=0; |
82 | return 1; |
81 | return 1; |
83 | } |
82 | } |
84 | if (scroll_state == 1) |
83 | if (scroll_state == 1) |
85 | { |
84 | { |
86 | if (visible + first == count) return 0; |
85 | if (visible + first == count) return 0; |
87 | if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size; |
86 | if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size; |
88 | return 1; |
87 | return 1; |
89 | } |
88 | } |
90 | return 0; |
89 | return 0; |
91 | } |
90 | } |
92 | 91 | ||
93 | 92 | ||
94 | :int llist::MouseOver(int xx, yy) |
93 | :int llist::MouseOver(int xx, yy) |
95 | { |
94 | { |
96 | if (xx>x) && (xx |
95 | if (xx>x) && (xx |
97 | return 0; |
96 | return 0; |
98 | } |
97 | } |
99 | 98 | ||
100 | :int llist::ProcessMouse(int xx, yy) |
99 | :int llist::ProcessMouse(int xx, yy) |
101 | { |
100 | { |
102 | int cur_y_temp, cur_x_temp, ret=0; |
101 | int cur_y_temp, cur_x_temp, ret=0; |
103 | if (MouseOver(xx, yy)) |
102 | if (MouseOver(xx, yy)) |
104 | { |
103 | { |
105 | cur_y_temp = yy - y / item_h + first; |
104 | cur_y_temp = yy - y / item_h + first; |
106 | if (cur_y_temp != cur_y) && (cur_y_temp |
105 | if (cur_y_temp != cur_y) && (cur_y_temp |
107 | { |
106 | { |
108 | cur_y = cur_y_temp; |
107 | cur_y = cur_y_temp; |
109 | ret = 1; |
108 | ret = 1; |
110 | } |
109 | } |
111 | if (horisontal_selelection) |
110 | if (horisontal_selelection) |
112 | { |
111 | { |
113 | cur_x_temp = xx - x / item_w; |
112 | cur_x_temp = xx - x / item_w; |
114 | if (cur_x_temp != cur_x) && (cur_x_temp |
113 | if (cur_x_temp != cur_x) && (cur_x_temp |
115 | { |
114 | { |
116 | cur_x = cur_x_temp; |
115 | cur_x = cur_x_temp; |
117 | ret = 1; |
116 | ret = 1; |
118 | } |
117 | } |
119 | } |
118 | } |
120 | } |
119 | } |
121 | return ret; |
120 | return ret; |
122 | } |
121 | } |
123 | 122 | ||
124 | :int llist::ProcessKey(dword key) |
123 | :int llist::ProcessKey(dword key) |
125 | { |
124 | { |
126 | switch(key) |
125 | switch(key) |
127 | { |
126 | { |
128 | case SCAN_CODE_DOWN: return KeyDown(); |
127 | case SCAN_CODE_DOWN: return KeyDown(); |
129 | case SCAN_CODE_UP: return KeyUp(); |
128 | case SCAN_CODE_UP: return KeyUp(); |
130 | case SCAN_CODE_HOME: return KeyHome(); |
129 | case SCAN_CODE_HOME: return KeyHome(); |
131 | case SCAN_CODE_END: return KeyEnd(); |
130 | case SCAN_CODE_END: return KeyEnd(); |
132 | case SCAN_CODE_PGUP: return KeyPgUp(); |
131 | case SCAN_CODE_PGUP: return KeyPgUp(); |
133 | case SCAN_CODE_PGDN: return KeyPgDown(); |
132 | case SCAN_CODE_PGDN: return KeyPgDown(); |
134 | } |
133 | } |
135 | if (horisontal_selelection) switch(key) |
134 | if (horisontal_selelection) switch(key) |
136 | { |
135 | { |
137 | case SCAN_CODE_LEFT: return KeyLeft(); |
136 | case SCAN_CODE_LEFT: return KeyLeft(); |
138 | case SCAN_CODE_RIGHT: return KeyRight(); |
137 | case SCAN_CODE_RIGHT: return KeyRight(); |
139 | } |
138 | } |
140 | return 0; |
139 | return 0; |
141 | } |
140 | } |
142 | 141 | ||
143 | :int llist::KeyDown() |
142 | :int llist::KeyDown() |
144 | { |
143 | { |
145 | if (no_selection) |
144 | if (no_selection) |
146 | { |
145 | { |
147 | if (visible + first >= count) return 0; |
146 | if (visible + first >= count) return 0; |
148 | first++; |
147 | first++; |
149 | return 1; |
148 | return 1; |
150 | } |
149 | } |
151 | 150 | ||
152 | if (cur_y-first+1 |
151 | if (cur_y-first+1 |
153 | { |
152 | { |
154 | if (cur_y + 1 >= count) return 0; |
153 | if (cur_y + 1 >= count) return 0; |
155 | cur_y++; |
154 | cur_y++; |
156 | } |
155 | } |
157 | else |
156 | else |
158 | { |
157 | { |
159 | if (visible + first >= count) return 0; |
158 | if (visible + first >= count) return 0; |
160 | first++; |
159 | first++; |
161 | cur_y++; |
160 | cur_y++; |
162 | } |
161 | } |
163 | if (cur_y < first) || (cur_y > first + visible) |
162 | if (cur_y < first) || (cur_y > first + visible) |
164 | { |
163 | { |
165 | first = cur_y; |
164 | first = cur_y; |
166 | CheckDoesValuesOkey(); |
165 | CheckDoesValuesOkey(); |
167 | } |
166 | } |
168 | return 1; |
167 | return 1; |
169 | } |
168 | } |
170 | 169 | ||
171 | :int llist::KeyUp() |
170 | :int llist::KeyUp() |
172 | { |
171 | { |
173 | if (no_selection) |
172 | if (no_selection) |
174 | { |
173 | { |
175 | if (first == 0) return 0; |
174 | if (first == 0) return 0; |
176 | first--; |
175 | first--; |
177 | return 1; |
176 | return 1; |
178 | } |
177 | } |
179 | 178 | ||
180 | if (cur_y > first) |
179 | if (cur_y > first) |
181 | { |
180 | { |
182 | cur_y--; |
181 | cur_y--; |
183 | } |
182 | } |
184 | else |
183 | else |
185 | { |
184 | { |
186 | if (first == 0) return 0; |
185 | if (first == 0) return 0; |
187 | first--; |
186 | first--; |
188 | cur_y--; |
187 | cur_y--; |
189 | } |
188 | } |
190 | if (cur_y < first) || (cur_y > first + visible) |
189 | if (cur_y < first) || (cur_y > first + visible) |
191 | { |
190 | { |
192 | first = cur_y; |
191 | first = cur_y; |
193 | CheckDoesValuesOkey(); |
192 | CheckDoesValuesOkey(); |
194 | } |
193 | } |
195 | return 1; |
194 | return 1; |
196 | } |
195 | } |
197 | 196 | ||
198 | :int llist::KeyHome() |
197 | :int llist::KeyHome() |
199 | { |
198 | { |
200 | if (cur_y==0) && (first==0) return 0; |
199 | if (cur_y==0) && (first==0) return 0; |
201 | cur_y = first = 0; |
200 | cur_y = first = 0; |
202 | return 1; |
201 | return 1; |
203 | } |
202 | } |
204 | 203 | ||
205 | :int llist::KeyEnd() |
204 | :int llist::KeyEnd() |
206 | { |
205 | { |
207 | if (cur_y==count-1) && (first==count-visible) return 0; |
206 | if (cur_y==count-1) && (first==count-visible) return 0; |
208 | cur_y = count-1; |
207 | cur_y = count-1; |
209 | first = count - visible; |
208 | first = count - visible; |
210 | return 1; |
209 | return 1; |
211 | } |
210 | } |
212 | 211 | ||
213 | :int llist::KeyPgUp() |
212 | :int llist::KeyPgUp() |
214 | { |
213 | { |
215 | if (count <= visible) return KeyHome(); |
214 | if (count <= visible) return KeyHome(); |
216 | if (first == 0) return 0; |
215 | if (first == 0) return 0; |
217 | first -= visible; |
216 | first -= visible; |
218 | cur_y = first; |
217 | cur_y = first; |
219 | CheckDoesValuesOkey(); |
218 | CheckDoesValuesOkey(); |
220 | return 1; |
219 | return 1; |
221 | } |
220 | } |
222 | 221 | ||
223 | :int llist::KeyPgDown() |
222 | :int llist::KeyPgDown() |
224 | { |
223 | { |
225 | if (count <= visible) return KeyEnd(); |
224 | if (count <= visible) return KeyEnd(); |
226 | if (first == count - visible) return 0; |
225 | if (first == count - visible) return 0; |
227 | first += visible; |
226 | first += visible; |
228 | cur_y = first + visible - 1; |
227 | cur_y = first + visible - 1; |
229 | CheckDoesValuesOkey(); |
228 | CheckDoesValuesOkey(); |
230 | return 1; |
229 | return 1; |
231 | } |
230 | } |
232 | 231 | ||
233 | :void llist::CheckDoesValuesOkey() |
232 | :void llist::CheckDoesValuesOkey() |
234 | { |
233 | { |
235 | if (visible + first > count) first = count - visible; |
234 | if (visible + first > count) first = count - visible; |
236 | if (first < 0) first = 0; |
235 | if (first < 0) first = 0; |
237 | if (cur_y >= count) cur_y = count - 1; |
236 | if (cur_y >= count) cur_y = count - 1; |
238 | if (cur_y < 0) cur_y = 0; |
237 | if (cur_y < 0) cur_y = 0; |
239 | if (cur_x < 0) cur_x = 0; |
238 | if (cur_x < 0) cur_x = 0; |
240 | } |
239 | } |
241 | 240 | ||
242 | :int llist::KeyRight() |
241 | :int llist::KeyRight() |
243 | { |
242 | { |
244 | if (cur_x < column_max) |
243 | if (cur_x < column_max) |
245 | { |
244 | { |
246 | cur_x++; |
245 | cur_x++; |
247 | } |
246 | } |
248 | else |
247 | else |
249 | { |
248 | { |
250 | if (!KeyDown()) return 0; |
249 | if (!KeyDown()) return 0; |
251 | cur_x = 0; |
250 | cur_x = 0; |
252 | } |
251 | } |
253 | return 1; |
252 | return 1; |
254 | } |
253 | } |
255 | 254 | ||
256 | :int llist::KeyLeft() |
255 | :int llist::KeyLeft() |
257 | { |
256 | { |
258 | if (cur_x > 0) |
257 | if (cur_x > 0) |
259 | { |
258 | { |
260 | cur_x--; |
259 | cur_x--; |
261 | } |
260 | } |
262 | else |
261 | else |
263 | { |
262 | { |
264 | if (!KeyUp()) return 0; |
263 | if (!KeyUp()) return 0; |
265 | cur_x = column_max; |
264 | cur_x = column_max; |
266 | } |
265 | } |
267 | return 1; |
266 | return 1; |
268 | } |
267 | } |
269 | 268 | ||
270 | 269 | ||
271 | :void llist_copy(dword dest, src) |
270 | :void llist_copy(dword dest, src) |
272 | { |
271 | { |
273 | EDI = dest; |
272 | EDI = dest; |
274 | ESI = src; |
273 | ESI = src; |
275 | EDI.llist.x = ESI.llist.x; |
274 | EDI.llist.x = ESI.llist.x; |
276 | EDI.llist.y = ESI.llist.y; |
275 | EDI.llist.y = ESI.llist.y; |
277 | EDI.llist.w = ESI.llist.w; |
276 | EDI.llist.w = ESI.llist.w; |
278 | EDI.llist.h = ESI.llist.h; |
277 | EDI.llist.h = ESI.llist.h; |
279 | EDI.llist.item_h = ESI.llist.item_h; |
278 | EDI.llist.item_h = ESI.llist.item_h; |
280 | EDI.llist.text_y = ESI.llist.text_y; |
279 | EDI.llist.text_y = ESI.llist.text_y; |
281 | EDI.llist.font_w = ESI.llist.font_w; |
280 | EDI.llist.font_w = ESI.llist.font_w; |
282 | EDI.llist.font_h = ESI.llist.font_h; |
281 | EDI.llist.font_h = ESI.llist.font_h; |
283 | EDI.llist.font_type = ESI.llist.font_type; |
282 | EDI.llist.font_type = ESI.llist.font_type; |
284 | EDI.llist.count = ESI.llist.count; |
283 | EDI.llist.count = ESI.llist.count; |
285 | EDI.llist.visible = ESI.llist.visible; |
284 | EDI.llist.visible = ESI.llist.visible; |
286 | EDI.llist.first = ESI.llist.first; |
285 | EDI.llist.first = ESI.llist.first; |
287 | EDI.llist.cur_y = ESI.llist.cur_y; |
286 | EDI.llist.cur_y = ESI.llist.cur_y; |
288 | EDI.llist.column_max = ESI.llist.column_max; |
287 | EDI.llist.column_max = ESI.llist.column_max; |
289 | EDI.llist.active = ESI.llist.active; |
288 | EDI.llist.active = ESI.llist.active; |
290 | } |
289 | } |
291 | 290 | ||
292 | #endif>>>>=>=>>> |
291 | #endif>>>>=>=>>> |
293 | > |
292 | > |
294 | > |
293 | > |
295 | >=visible)> |
294 | >=visible)> |