Rev 5733 | Rev 5778 | 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 | { |
||
5710 | leency | 12 | int x, y, w, h, line_h, text_y; |
13 | dword font_w, font_h, font_type; |
||
5709 | leency | 14 | int count, visible, first, current, column_max; //visible = row_max |
5749 | leency | 15 | int wheel_size; |
4409 | leency | 16 | int active; |
3225 | leency | 17 | void ClearList(); |
4077 | leency | 18 | int MouseOver(int xx, yy); |
19 | int ProcessMouse(int xx, yy); |
||
5694 | leency | 20 | int ProcessKey(dword key); |
4059 | leency | 21 | int KeyDown(); |
22 | int KeyUp(); |
||
4063 | leency | 23 | int KeyHome(); |
24 | int KeyEnd(); |
||
5694 | leency | 25 | int KeyPgDown(); |
26 | int KeyPgUp(); |
||
27 | void CheckDoesValuesOkey(); |
||
5710 | leency | 28 | void SetSizes(int xx, yy, ww, hh, line_hh); |
29 | void SetFont(dword font_ww, font_hh, font_tt); |
||
3225 | leency | 30 | int MouseScroll(dword scroll_state); |
5616 | leency | 31 | int MouseScrollNoSelection(dword scroll_state); |
32 | void debug_values(); |
||
3225 | leency | 33 | }; |
34 | |||
35 | |||
5616 | leency | 36 | void llist::debug_values() |
37 | { |
||
5694 | leency | 38 | char yi[128]; |
39 | sprintf(#yi, "%s %d %s %d %s %d %s %d", "current:", current, "first:", first, |
||
40 | "visible:", visible, "count:", count); |
||
41 | debugln(#yi); |
||
5616 | leency | 42 | } |
4662 | leency | 43 | |
5421 | leency | 44 | |
45 | |||
3225 | leency | 46 | void llist::ClearList() |
47 | { |
||
48 | count = visible = first = current = 0; |
||
49 | } |
||
50 | |||
51 | |||
5709 | leency | 52 | void llist::SetSizes(int xx, yy, ww, hh, line_hh) |
3225 | leency | 53 | { |
54 | x = xx; |
||
55 | y = yy; |
||
56 | w = ww; |
||
57 | h = hh; |
||
58 | line_h = line_hh; |
||
5710 | leency | 59 | text_y = line_h - font_h / 2; |
3368 | leency | 60 | visible = h / line_h; |
5749 | leency | 61 | wheel_size = 3; |
4846 | leency | 62 | //if (visible > count) visible=count; |
3225 | leency | 63 | } |
64 | |||
5710 | leency | 65 | void llist::SetFont(dword font_ww, font_hh, font_tt) |
66 | { |
||
67 | font_w = font_ww; |
||
68 | font_h = font_hh; |
||
69 | font_type = font_tt; |
||
70 | } |
||
3225 | leency | 71 | |
5710 | leency | 72 | |
3225 | leency | 73 | int llist::MouseScroll(dword scroll_state) |
74 | { |
||
4533 | leency | 75 | if (count<=visible) return 0; |
3225 | leency | 76 | if (scroll_state == 65535) |
77 | { |
||
78 | if (first == 0) return 0; |
||
5749 | leency | 79 | if (first > wheel_size+1) first -= wheel_size; else first=0; |
3225 | leency | 80 | return 1; |
81 | } |
||
82 | if (scroll_state == 1) |
||
83 | { |
||
5421 | leency | 84 | if (visible + first == count) return 0; |
5749 | leency | 85 | if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size; |
3225 | leency | 86 | return 1; |
87 | } |
||
88 | return 0; |
||
4059 | leency | 89 | } |
90 | |||
5616 | leency | 91 | int llist::MouseScrollNoSelection(dword scroll_state) |
92 | { |
||
93 | if (count<=visible) return 0; |
||
94 | if (scroll_state == 65535) |
||
95 | { |
||
96 | if (current == 0) return 0; |
||
97 | if (current > 3) current -= 2; else current=0; |
||
98 | return 1; |
||
99 | } |
||
100 | if (scroll_state == 1) |
||
101 | { |
||
102 | if (visible + current == count) return 0; |
||
103 | if (visible+current+3 > count) current = count - visible; else current+=2; |
||
104 | return 1; |
||
105 | } |
||
106 | return 0; |
||
107 | } |
||
108 | |||
4077 | leency | 109 | int llist::MouseOver(int xx, yy) |
110 | { |
||
111 | if (xx>x) && (xx |
||
112 | return 0; |
||
113 | } |
||
114 | |||
115 | int llist::ProcessMouse(int xx, yy) |
||
116 | { |
||
4078 | leency | 117 | int current_temp; |
4077 | leency | 118 | if (MouseOver(xx, yy)) |
119 | { |
||
120 | current_temp = yy - y / line_h + first; |
||
4078 | leency | 121 | if (current_temp != current) && (current_temp |
4077 | leency | 122 | { |
123 | current = current_temp; |
||
124 | return 1; |
||
125 | } |
||
126 | } |
||
127 | return 0; |
||
128 | } |
||
129 | |||
4073 | leency | 130 | int llist::ProcessKey(dword key) |
131 | { |
||
132 | switch(key) |
||
133 | { |
||
5702 | punk_joker | 134 | case SCAN_CODE_DOWN: return KeyDown(); |
135 | case SCAN_CODE_UP: return KeyUp(); |
||
136 | case SCAN_CODE_HOME: return KeyHome(); |
||
137 | case SCAN_CODE_END: return KeyEnd(); |
||
138 | case SCAN_CODE_PGUP: return KeyPgUp(); |
||
139 | case SCAN_CODE_PGDN: return KeyPgDown(); |
||
4073 | leency | 140 | } |
141 | return 0; |
||
142 | } |
||
143 | |||
4059 | leency | 144 | int llist::KeyDown() |
145 | { |
||
146 | if (current-first+1 |
||
147 | { |
||
5694 | leency | 148 | if (current + 1 >= count) return 0; |
4059 | leency | 149 | current++; |
150 | } |
||
151 | else |
||
152 | { |
||
5694 | leency | 153 | if (visible + first >= count) return 0; |
4059 | leency | 154 | first++; |
155 | current++; |
||
156 | } |
||
5694 | leency | 157 | if (current < first) || (current > first + visible) |
158 | { |
||
159 | first = current; |
||
160 | CheckDoesValuesOkey(); |
||
161 | } |
||
4059 | leency | 162 | return 1; |
163 | } |
||
164 | |||
165 | int llist::KeyUp() |
||
166 | { |
||
5694 | leency | 167 | if (current > first) |
4059 | leency | 168 | { |
169 | current--; |
||
170 | } |
||
171 | else |
||
172 | { |
||
5694 | leency | 173 | if (first == 0) return 0; |
4059 | leency | 174 | first--; |
175 | current--; |
||
176 | } |
||
5694 | leency | 177 | if (current < first) || (current > first + visible) |
178 | { |
||
179 | first = current; |
||
180 | CheckDoesValuesOkey(); |
||
181 | } |
||
4059 | leency | 182 | return 1; |
4063 | leency | 183 | } |
184 | |||
185 | int llist::KeyHome() |
||
186 | { |
||
187 | if (current==0) && (first==0) return 0; |
||
5694 | leency | 188 | current = first = 0; |
4063 | leency | 189 | return 1; |
190 | } |
||
191 | |||
192 | int llist::KeyEnd() |
||
193 | { |
||
194 | if (current==count-1) && (first==count-visible) return 0; |
||
5694 | leency | 195 | current = count-1; |
196 | first = count - visible; |
||
4063 | leency | 197 | return 1; |
5598 | pavelyakov | 198 | } |
199 | |||
5694 | leency | 200 | int llist::KeyPgUp() |
201 | { |
||
202 | if (count <= visible) return KeyHome(); |
||
203 | if (first == 0) return 0; |
||
204 | first -= visible; |
||
205 | CheckDoesValuesOkey(); |
||
206 | return 1; |
||
207 | } |
||
208 | |||
209 | int llist::KeyPgDown() |
||
210 | { |
||
211 | if (count <= visible) return KeyEnd(); |
||
212 | if (first == count - visible) return 0; |
||
213 | first += visible; |
||
214 | CheckDoesValuesOkey(); |
||
215 | return 1; |
||
216 | } |
||
217 | |||
218 | void llist::CheckDoesValuesOkey() |
||
219 | { |
||
220 | if (first < 0) first = 0; |
||
221 | if (visible + first > count) first = count - visible; |
||
222 | if (current >= count) current = count - 1; |
||
223 | if (current < 0) current = 0; |
||
224 | } |
||
225 | |||
5733 | leency | 226 | void llist_copy(dword dest, src) |
227 | { |
||
228 | EDI = dest; |
||
229 | ESI = src; |
||
230 | EDI.llist.x = ESI.llist.x; |
||
231 | EDI.llist.y = ESI.llist.y; |
||
232 | EDI.llist.w = ESI.llist.w; |
||
233 | EDI.llist.h = ESI.llist.h; |
||
234 | EDI.llist.line_h = ESI.llist.line_h; |
||
235 | EDI.llist.text_y = ESI.llist.text_y; |
||
236 | EDI.llist.font_w = ESI.llist.font_w; |
||
237 | EDI.llist.font_h = ESI.llist.font_h; |
||
238 | EDI.llist.font_type = ESI.llist.font_type; |
||
239 | EDI.llist.count = ESI.llist.count; |
||
240 | EDI.llist.visible = ESI.llist.visible; |
||
241 | EDI.llist.first = ESI.llist.first; |
||
242 | EDI.llist.current = ESI.llist.current; |
||
243 | EDI.llist.column_max = ESI.llist.column_max; |
||
244 | EDI.llist.active = ESI.llist.active; |
||
245 | } |
||
246 | |||
5598 | pavelyakov | 247 | #endif>>=>=>>> |