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