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