Rev 5616 | Rev 5694 | 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(); |
4073 | leency | 17 | int ProcessKey(dword key); |
4077 | leency | 18 | int MouseOver(int xx, yy); |
19 | int ProcessMouse(int xx, yy); |
||
4059 | leency | 20 | int KeyDown(); |
21 | int KeyUp(); |
||
4063 | leency | 22 | int KeyHome(); |
23 | int KeyEnd(); |
||
3225 | leency | 24 | void SetSizes(int xx, yy, ww, hh, min_hh, line_hh); |
25 | int MouseScroll(dword scroll_state); |
||
5616 | leency | 26 | int MouseScrollNoSelection(dword scroll_state); |
27 | void debug_values(); |
||
3225 | leency | 28 | }; |
29 | |||
30 | |||
5616 | leency | 31 | void llist::debug_values() |
32 | { |
||
33 | debug("current: "); |
||
34 | debugi(current); |
||
35 | debug("first: "); |
||
36 | debugi(first); |
||
37 | debug("visible: "); |
||
38 | debugi(visible); |
||
39 | debug("count: "); |
||
40 | debugi(count); |
||
41 | } |
||
4662 | leency | 42 | |
5421 | leency | 43 | |
44 | |||
3225 | leency | 45 | void llist::ClearList() |
46 | { |
||
47 | count = visible = first = current = 0; |
||
48 | } |
||
49 | |||
50 | |||
51 | void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh) |
||
52 | { |
||
53 | x = xx; |
||
54 | y = yy; |
||
55 | w = ww; |
||
56 | h = hh; |
||
57 | min_h = min_hh; |
||
58 | line_h = line_hh; |
||
4078 | leency | 59 | text_y = line_hh / 2 - 4; |
3368 | leency | 60 | visible = h / line_h; |
5616 | leency | 61 | column_max = w / 6; |
4846 | leency | 62 | //if (visible > count) visible=count; |
3225 | leency | 63 | } |
64 | |||
65 | |||
66 | int llist::MouseScroll(dword scroll_state) |
||
67 | { |
||
4533 | leency | 68 | if (count<=visible) return 0; |
3225 | leency | 69 | if (scroll_state == 65535) |
70 | { |
||
71 | if (first == 0) return 0; |
||
72 | if (first > 3) first -= 2; else first=0; |
||
73 | return 1; |
||
74 | } |
||
75 | if (scroll_state == 1) |
||
76 | { |
||
5421 | leency | 77 | if (visible + first == count) return 0; |
78 | if (visible+first+3 > count) first = count - visible; else first+=2; |
||
3225 | leency | 79 | return 1; |
80 | } |
||
81 | return 0; |
||
4059 | leency | 82 | } |
83 | |||
5616 | leency | 84 | int llist::MouseScrollNoSelection(dword scroll_state) |
85 | { |
||
86 | if (count<=visible) return 0; |
||
87 | if (scroll_state == 65535) |
||
88 | { |
||
89 | if (current == 0) return 0; |
||
90 | if (current > 3) current -= 2; else current=0; |
||
91 | return 1; |
||
92 | } |
||
93 | if (scroll_state == 1) |
||
94 | { |
||
95 | if (visible + current == count) return 0; |
||
96 | if (visible+current+3 > count) current = count - visible; else current+=2; |
||
97 | return 1; |
||
98 | } |
||
99 | return 0; |
||
100 | } |
||
101 | |||
4077 | leency | 102 | int llist::MouseOver(int xx, yy) |
103 | { |
||
104 | if (xx>x) && (xx |
||
105 | return 0; |
||
106 | } |
||
107 | |||
108 | int llist::ProcessMouse(int xx, yy) |
||
109 | { |
||
4078 | leency | 110 | int current_temp; |
4077 | leency | 111 | if (MouseOver(xx, yy)) |
112 | { |
||
113 | current_temp = yy - y / line_h + first; |
||
4078 | leency | 114 | if (current_temp != current) && (current_temp |
4077 | leency | 115 | { |
116 | current = current_temp; |
||
117 | return 1; |
||
118 | } |
||
119 | } |
||
120 | return 0; |
||
121 | } |
||
122 | |||
4073 | leency | 123 | int llist::ProcessKey(dword key) |
124 | { |
||
125 | switch(key) |
||
126 | { |
||
5465 | leency | 127 | case ASCII_KEY_DOWN: return KeyDown(); |
128 | case ASCII_KEY_UP: return KeyUp(); |
||
129 | case ASCII_KEY_HOME: return KeyHome(); |
||
130 | case ASCII_KEY_END: return KeyEnd(); |
||
4073 | leency | 131 | } |
132 | return 0; |
||
133 | } |
||
134 | |||
4059 | leency | 135 | int llist::KeyDown() |
136 | { |
||
137 | if (current-first+1 |
||
138 | { |
||
4063 | leency | 139 | if (current+1>=count) return 0; |
4059 | leency | 140 | current++; |
141 | } |
||
142 | else |
||
143 | { |
||
4063 | leency | 144 | if (visible+first>=count) return 0; |
4059 | leency | 145 | first++; |
146 | current++; |
||
147 | } |
||
148 | return 1; |
||
149 | } |
||
150 | |||
151 | int llist::KeyUp() |
||
152 | { |
||
153 | if (current>first) |
||
154 | { |
||
155 | current--; |
||
156 | } |
||
157 | else |
||
158 | { |
||
4063 | leency | 159 | if (first==0) return 0; |
4059 | leency | 160 | first--; |
161 | current--; |
||
162 | } |
||
163 | return 1; |
||
4063 | leency | 164 | } |
165 | |||
166 | int llist::KeyHome() |
||
167 | { |
||
168 | if (current==0) && (first==0) return 0; |
||
169 | current=0; |
||
170 | first=0; |
||
171 | return 1; |
||
172 | } |
||
173 | |||
174 | int llist::KeyEnd() |
||
175 | { |
||
176 | if (current==count-1) && (first==count-visible) return 0; |
||
177 | current=count-1; |
||
178 | first=count-visible; |
||
179 | return 1; |
||
5598 | pavelyakov | 180 | } |
181 | |||
182 | #endif |