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