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