Rev 5598 | Rev 5676 | 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 |
||
3225 | leency | 4 | |
5598 | pavelyakov | 5 | #ifndef INCLUDE_KOLIBRI_H |
6 | #include "../lib/kolibri.h" |
||
7 | #endif |
||
8 | |||
3225 | leency | 9 | struct llist |
10 | { |
||
4078 | leency | 11 | int x, y, w, h, min_h, line_h, text_y; |
4415 | leency | 12 | int column_max; |
5616 | leency | 13 | int count, visible, first, current; //visible = row_max |
4409 | leency | 14 | int active; |
3225 | leency | 15 | void ClearList(); |
4073 | leency | 16 | int ProcessKey(dword key); |
4077 | leency | 17 | int MouseOver(int xx, yy); |
18 | int ProcessMouse(int xx, yy); |
||
4059 | leency | 19 | int KeyDown(); |
20 | int KeyUp(); |
||
4063 | leency | 21 | int KeyHome(); |
22 | int KeyEnd(); |
||
3225 | leency | 23 | void SetSizes(int xx, yy, ww, hh, min_hh, line_hh); |
24 | int MouseScroll(dword scroll_state); |
||
5616 | leency | 25 | int MouseScrollNoSelection(dword scroll_state); |
26 | void debug_values(); |
||
3225 | leency | 27 | }; |
28 | |||
29 | |||
5616 | leency | 30 | void llist::debug_values() |
31 | { |
||
32 | debug("current: "); |
||
33 | debugi(current); |
||
34 | debug("first: "); |
||
35 | debugi(first); |
||
36 | debug("visible: "); |
||
37 | debugi(visible); |
||
38 | debug("count: "); |
||
39 | debugi(count); |
||
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; |
||
4078 | leency | 58 | text_y = line_hh / 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 | { |
||
5465 | leency | 126 | case ASCII_KEY_DOWN: return KeyDown(); |
127 | case ASCII_KEY_UP: return KeyUp(); |
||
128 | case ASCII_KEY_HOME: return KeyHome(); |
||
129 | case ASCII_KEY_END: return KeyEnd(); |
||
4073 | leency | 130 | } |
131 | return 0; |
||
132 | } |
||
133 | |||
4059 | leency | 134 | int llist::KeyDown() |
135 | { |
||
136 | if (current-first+1 |
||
137 | { |
||
4063 | leency | 138 | if (current+1>=count) return 0; |
4059 | leency | 139 | current++; |
140 | } |
||
141 | else |
||
142 | { |
||
4063 | leency | 143 | if (visible+first>=count) return 0; |
4059 | leency | 144 | first++; |
145 | current++; |
||
146 | } |
||
147 | return 1; |
||
148 | } |
||
149 | |||
150 | int llist::KeyUp() |
||
151 | { |
||
152 | if (current>first) |
||
153 | { |
||
154 | current--; |
||
155 | } |
||
156 | else |
||
157 | { |
||
4063 | leency | 158 | if (first==0) return 0; |
4059 | leency | 159 | first--; |
160 | current--; |
||
161 | } |
||
162 | return 1; |
||
4063 | leency | 163 | } |
164 | |||
165 | int llist::KeyHome() |
||
166 | { |
||
167 | if (current==0) && (first==0) return 0; |
||
168 | current=0; |
||
169 | first=0; |
||
170 | return 1; |
||
171 | } |
||
172 | |||
173 | int llist::KeyEnd() |
||
174 | { |
||
175 | if (current==count-1) && (first==count-visible) return 0; |
||
176 | current=count-1; |
||
177 | first=count-visible; |
||
178 | return 1; |
||
5598 | pavelyakov | 179 | } |
180 | |||
181 | #endif |