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