Rev 5749 | Rev 5779 | 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 | 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; |
5749 | leency | 60 | wheel_size = 3; |
4846 | leency | 61 | //if (visible > count) visible=count; |
3225 | leency | 62 | } |
63 | |||
5710 | leency | 64 | void llist::SetFont(dword font_ww, font_hh, font_tt) |
65 | { |
||
66 | font_w = font_ww; |
||
67 | font_h = font_hh; |
||
68 | font_type = font_tt; |
||
69 | } |
||
3225 | leency | 70 | |
5710 | leency | 71 | |
3225 | leency | 72 | int llist::MouseScroll(dword scroll_state) |
73 | { |
||
4533 | leency | 74 | if (count<=visible) return 0; |
3225 | leency | 75 | if (scroll_state == 65535) |
76 | { |
||
77 | if (first == 0) return 0; |
||
5749 | leency | 78 | if (first > wheel_size+1) first -= wheel_size; else first=0; |
3225 | leency | 79 | return 1; |
80 | } |
||
81 | if (scroll_state == 1) |
||
82 | { |
||
5421 | leency | 83 | if (visible + first == count) return 0; |
5749 | leency | 84 | if (visible+first+wheel_size+1 > count) first = count - visible; else first+=wheel_size; |
3225 | leency | 85 | return 1; |
86 | } |
||
87 | return 0; |
||
4059 | leency | 88 | } |
89 | |||
5616 | leency | 90 | |
4077 | leency | 91 | int llist::MouseOver(int xx, yy) |
92 | { |
||
93 | if (xx>x) && (xx |
||
94 | return 0; |
||
95 | } |
||
96 | |||
97 | int llist::ProcessMouse(int xx, yy) |
||
98 | { |
||
4078 | leency | 99 | int current_temp; |
4077 | leency | 100 | if (MouseOver(xx, yy)) |
101 | { |
||
102 | current_temp = yy - y / line_h + first; |
||
4078 | leency | 103 | if (current_temp != current) && (current_temp |
4077 | leency | 104 | { |
105 | current = current_temp; |
||
106 | return 1; |
||
107 | } |
||
108 | } |
||
109 | return 0; |
||
110 | } |
||
111 | |||
4073 | leency | 112 | int llist::ProcessKey(dword key) |
113 | { |
||
114 | switch(key) |
||
115 | { |
||
5702 | punk_joker | 116 | case SCAN_CODE_DOWN: return KeyDown(); |
117 | case SCAN_CODE_UP: return KeyUp(); |
||
118 | case SCAN_CODE_HOME: return KeyHome(); |
||
119 | case SCAN_CODE_END: return KeyEnd(); |
||
120 | case SCAN_CODE_PGUP: return KeyPgUp(); |
||
121 | case SCAN_CODE_PGDN: return KeyPgDown(); |
||
4073 | leency | 122 | } |
123 | return 0; |
||
124 | } |
||
125 | |||
4059 | leency | 126 | int llist::KeyDown() |
127 | { |
||
128 | if (current-first+1 |
||
129 | { |
||
5694 | leency | 130 | if (current + 1 >= count) return 0; |
4059 | leency | 131 | current++; |
132 | } |
||
133 | else |
||
134 | { |
||
5694 | leency | 135 | if (visible + first >= count) return 0; |
4059 | leency | 136 | first++; |
137 | current++; |
||
138 | } |
||
5694 | leency | 139 | if (current < first) || (current > first + visible) |
140 | { |
||
141 | first = current; |
||
142 | CheckDoesValuesOkey(); |
||
143 | } |
||
4059 | leency | 144 | return 1; |
145 | } |
||
146 | |||
147 | int llist::KeyUp() |
||
148 | { |
||
5694 | leency | 149 | if (current > first) |
4059 | leency | 150 | { |
151 | current--; |
||
152 | } |
||
153 | else |
||
154 | { |
||
5694 | leency | 155 | if (first == 0) return 0; |
4059 | leency | 156 | first--; |
157 | current--; |
||
158 | } |
||
5694 | leency | 159 | if (current < first) || (current > first + visible) |
160 | { |
||
161 | first = current; |
||
162 | CheckDoesValuesOkey(); |
||
163 | } |
||
4059 | leency | 164 | return 1; |
4063 | leency | 165 | } |
166 | |||
167 | int llist::KeyHome() |
||
168 | { |
||
169 | if (current==0) && (first==0) return 0; |
||
5694 | leency | 170 | current = first = 0; |
4063 | leency | 171 | return 1; |
172 | } |
||
173 | |||
174 | int llist::KeyEnd() |
||
175 | { |
||
176 | if (current==count-1) && (first==count-visible) return 0; |
||
5694 | leency | 177 | current = count-1; |
178 | first = count - visible; |
||
4063 | leency | 179 | return 1; |
5598 | pavelyakov | 180 | } |
181 | |||
5694 | leency | 182 | int llist::KeyPgUp() |
183 | { |
||
184 | if (count <= visible) return KeyHome(); |
||
185 | if (first == 0) return 0; |
||
186 | first -= visible; |
||
187 | CheckDoesValuesOkey(); |
||
188 | return 1; |
||
189 | } |
||
190 | |||
191 | int llist::KeyPgDown() |
||
192 | { |
||
193 | if (count <= visible) return KeyEnd(); |
||
194 | if (first == count - visible) return 0; |
||
195 | first += visible; |
||
196 | CheckDoesValuesOkey(); |
||
197 | return 1; |
||
198 | } |
||
199 | |||
200 | void llist::CheckDoesValuesOkey() |
||
201 | { |
||
202 | if (first < 0) first = 0; |
||
203 | if (visible + first > count) first = count - visible; |
||
204 | if (current >= count) current = count - 1; |
||
205 | if (current < 0) current = 0; |
||
206 | } |
||
207 | |||
5733 | leency | 208 | void llist_copy(dword dest, src) |
209 | { |
||
210 | EDI = dest; |
||
211 | ESI = src; |
||
212 | EDI.llist.x = ESI.llist.x; |
||
213 | EDI.llist.y = ESI.llist.y; |
||
214 | EDI.llist.w = ESI.llist.w; |
||
215 | EDI.llist.h = ESI.llist.h; |
||
216 | EDI.llist.line_h = ESI.llist.line_h; |
||
217 | EDI.llist.text_y = ESI.llist.text_y; |
||
218 | EDI.llist.font_w = ESI.llist.font_w; |
||
219 | EDI.llist.font_h = ESI.llist.font_h; |
||
220 | EDI.llist.font_type = ESI.llist.font_type; |
||
221 | EDI.llist.count = ESI.llist.count; |
||
222 | EDI.llist.visible = ESI.llist.visible; |
||
223 | EDI.llist.first = ESI.llist.first; |
||
224 | EDI.llist.current = ESI.llist.current; |
||
225 | EDI.llist.column_max = ESI.llist.column_max; |
||
226 | EDI.llist.active = ESI.llist.active; |
||
227 | } |
||
228 | |||
5598 | pavelyakov | 229 | #endif>>=>=>>> |