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