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