Rev 5616 | Rev 5694 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5616 | Rev 5676 | ||
---|---|---|---|
1 | //list_box |
1 | //list_box |
2 | #ifndef INCLUDE_LIST_BOX_H |
2 | #ifndef INCLUDE_LIST_BOX_H |
3 | #define INCLUDE_LIST_BOX_H |
3 | #define INCLUDE_LIST_BOX_H |
- | 4 | #print "[include |
|
4 | 5 | ||
5 | #ifndef INCLUDE_KOLIBRI_H |
6 | #ifndef INCLUDE_KOLIBRI_H |
6 | #include "../lib/kolibri.h" |
7 | #include "../lib/kolibri.h" |
7 | #endif |
8 | #endif |
8 | 9 | ||
9 | struct llist |
10 | struct llist |
10 | { |
11 | { |
11 | int x, y, w, h, min_h, line_h, text_y; |
12 | int x, y, w, h, min_h, line_h, text_y; |
12 | int column_max; |
13 | int column_max; |
13 | int count, visible, first, current; //visible = row_max |
14 | int count, visible, first, current; //visible = row_max |
14 | int active; |
15 | int active; |
15 | void ClearList(); |
16 | void ClearList(); |
16 | int ProcessKey(dword key); |
17 | int ProcessKey(dword key); |
17 | int MouseOver(int xx, yy); |
18 | int MouseOver(int xx, yy); |
18 | int ProcessMouse(int xx, yy); |
19 | int ProcessMouse(int xx, yy); |
19 | int KeyDown(); |
20 | int KeyDown(); |
20 | int KeyUp(); |
21 | int KeyUp(); |
21 | int KeyHome(); |
22 | int KeyHome(); |
22 | int KeyEnd(); |
23 | int KeyEnd(); |
23 | void SetSizes(int xx, yy, ww, hh, min_hh, line_hh); |
24 | void SetSizes(int xx, yy, ww, hh, min_hh, line_hh); |
24 | int MouseScroll(dword scroll_state); |
25 | int MouseScroll(dword scroll_state); |
25 | int MouseScrollNoSelection(dword scroll_state); |
26 | int MouseScrollNoSelection(dword scroll_state); |
26 | void debug_values(); |
27 | void debug_values(); |
27 | }; |
28 | }; |
28 | 29 | ||
29 | 30 | ||
30 | void llist::debug_values() |
31 | void llist::debug_values() |
31 | { |
32 | { |
32 | debug("current: "); |
33 | debug("current: "); |
33 | debugi(current); |
34 | debugi(current); |
34 | debug("first: "); |
35 | debug("first: "); |
35 | debugi(first); |
36 | debugi(first); |
36 | debug("visible: "); |
37 | debug("visible: "); |
37 | debugi(visible); |
38 | debugi(visible); |
38 | debug("count: "); |
39 | debug("count: "); |
39 | debugi(count); |
40 | debugi(count); |
40 | } |
41 | } |
41 | 42 | ||
42 | 43 | ||
43 | 44 | ||
44 | void llist::ClearList() |
45 | void llist::ClearList() |
45 | { |
46 | { |
46 | count = visible = first = current = 0; |
47 | count = visible = first = current = 0; |
47 | } |
48 | } |
48 | 49 | ||
49 | 50 | ||
50 | void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh) |
51 | void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh) |
51 | { |
52 | { |
52 | x = xx; |
53 | x = xx; |
53 | y = yy; |
54 | y = yy; |
54 | w = ww; |
55 | w = ww; |
55 | h = hh; |
56 | h = hh; |
56 | min_h = min_hh; |
57 | min_h = min_hh; |
57 | line_h = line_hh; |
58 | line_h = line_hh; |
58 | text_y = line_hh / 2 - 4; |
59 | text_y = line_hh / 2 - 4; |
59 | visible = h / line_h; |
60 | visible = h / line_h; |
60 | column_max = w / 6; |
61 | column_max = w / 6; |
61 | //if (visible > count) visible=count; |
62 | //if (visible > count) visible=count; |
62 | } |
63 | } |
63 | 64 | ||
64 | 65 | ||
65 | int llist::MouseScroll(dword scroll_state) |
66 | int llist::MouseScroll(dword scroll_state) |
66 | { |
67 | { |
67 | if (count<=visible) return 0; |
68 | if (count<=visible) return 0; |
68 | if (scroll_state == 65535) |
69 | if (scroll_state == 65535) |
69 | { |
70 | { |
70 | if (first == 0) return 0; |
71 | if (first == 0) return 0; |
71 | if (first > 3) first -= 2; else first=0; |
72 | if (first > 3) first -= 2; else first=0; |
72 | return 1; |
73 | return 1; |
73 | } |
74 | } |
74 | if (scroll_state == 1) |
75 | if (scroll_state == 1) |
75 | { |
76 | { |
76 | if (visible + first == count) return 0; |
77 | if (visible + first == count) return 0; |
77 | if (visible+first+3 > count) first = count - visible; else first+=2; |
78 | if (visible+first+3 > count) first = count - visible; else first+=2; |
78 | return 1; |
79 | return 1; |
79 | } |
80 | } |
80 | return 0; |
81 | return 0; |
81 | } |
82 | } |
82 | 83 | ||
83 | int llist::MouseScrollNoSelection(dword scroll_state) |
84 | int llist::MouseScrollNoSelection(dword scroll_state) |
84 | { |
85 | { |
85 | if (count<=visible) return 0; |
86 | if (count<=visible) return 0; |
86 | if (scroll_state == 65535) |
87 | if (scroll_state == 65535) |
87 | { |
88 | { |
88 | if (current == 0) return 0; |
89 | if (current == 0) return 0; |
89 | if (current > 3) current -= 2; else current=0; |
90 | if (current > 3) current -= 2; else current=0; |
90 | return 1; |
91 | return 1; |
91 | } |
92 | } |
92 | if (scroll_state == 1) |
93 | if (scroll_state == 1) |
93 | { |
94 | { |
94 | if (visible + current == count) return 0; |
95 | if (visible + current == count) return 0; |
95 | if (visible+current+3 > count) current = count - visible; else current+=2; |
96 | if (visible+current+3 > count) current = count - visible; else current+=2; |
96 | return 1; |
97 | return 1; |
97 | } |
98 | } |
98 | return 0; |
99 | return 0; |
99 | } |
100 | } |
100 | 101 | ||
101 | int llist::MouseOver(int xx, yy) |
102 | int llist::MouseOver(int xx, yy) |
102 | { |
103 | { |
103 | if (xx>x) && (xx |
104 | if (xx>x) && (xx |
104 | return 0; |
105 | return 0; |
105 | } |
106 | } |
106 | 107 | ||
107 | int llist::ProcessMouse(int xx, yy) |
108 | int llist::ProcessMouse(int xx, yy) |
108 | { |
109 | { |
109 | int current_temp; |
110 | int current_temp; |
110 | if (MouseOver(xx, yy)) |
111 | if (MouseOver(xx, yy)) |
111 | { |
112 | { |
112 | current_temp = yy - y / line_h + first; |
113 | current_temp = yy - y / line_h + first; |
113 | if (current_temp != current) && (current_temp |
114 | if (current_temp != current) && (current_temp |
114 | { |
115 | { |
115 | current = current_temp; |
116 | current = current_temp; |
116 | return 1; |
117 | return 1; |
117 | } |
118 | } |
118 | } |
119 | } |
119 | return 0; |
120 | return 0; |
120 | } |
121 | } |
121 | 122 | ||
122 | int llist::ProcessKey(dword key) |
123 | int llist::ProcessKey(dword key) |
123 | { |
124 | { |
124 | switch(key) |
125 | switch(key) |
125 | { |
126 | { |
126 | case ASCII_KEY_DOWN: return KeyDown(); |
127 | case ASCII_KEY_DOWN: return KeyDown(); |
127 | case ASCII_KEY_UP: return KeyUp(); |
128 | case ASCII_KEY_UP: return KeyUp(); |
128 | case ASCII_KEY_HOME: return KeyHome(); |
129 | case ASCII_KEY_HOME: return KeyHome(); |
129 | case ASCII_KEY_END: return KeyEnd(); |
130 | case ASCII_KEY_END: return KeyEnd(); |
130 | } |
131 | } |
131 | return 0; |
132 | return 0; |
132 | } |
133 | } |
133 | 134 | ||
134 | int llist::KeyDown() |
135 | int llist::KeyDown() |
135 | { |
136 | { |
136 | if (current-first+1 |
137 | if (current-first+1 |
137 | { |
138 | { |
138 | if (current+1>=count) return 0; |
139 | if (current+1>=count) return 0; |
139 | current++; |
140 | current++; |
140 | } |
141 | } |
141 | else |
142 | else |
142 | { |
143 | { |
143 | if (visible+first>=count) return 0; |
144 | if (visible+first>=count) return 0; |
144 | first++; |
145 | first++; |
145 | current++; |
146 | current++; |
146 | } |
147 | } |
147 | return 1; |
148 | return 1; |
148 | } |
149 | } |
149 | 150 | ||
150 | int llist::KeyUp() |
151 | int llist::KeyUp() |
151 | { |
152 | { |
152 | if (current>first) |
153 | if (current>first) |
153 | { |
154 | { |
154 | current--; |
155 | current--; |
155 | } |
156 | } |
156 | else |
157 | else |
157 | { |
158 | { |
158 | if (first==0) return 0; |
159 | if (first==0) return 0; |
159 | first--; |
160 | first--; |
160 | current--; |
161 | current--; |
161 | } |
162 | } |
162 | return 1; |
163 | return 1; |
163 | } |
164 | } |
164 | 165 | ||
165 | int llist::KeyHome() |
166 | int llist::KeyHome() |
166 | { |
167 | { |
167 | if (current==0) && (first==0) return 0; |
168 | if (current==0) && (first==0) return 0; |
168 | current=0; |
169 | current=0; |
169 | first=0; |
170 | first=0; |
170 | return 1; |
171 | return 1; |
171 | } |
172 | } |
172 | 173 | ||
173 | int llist::KeyEnd() |
174 | int llist::KeyEnd() |
174 | { |
175 | { |
175 | if (current==count-1) && (first==count-visible) return 0; |
176 | if (current==count-1) && (first==count-visible) return 0; |
176 | current=count-1; |
177 | current=count-1; |
177 | first=count-visible; |
178 | first=count-visible; |
178 | return 1; |
179 | return 1; |
179 | } |
180 | } |
180 | 181 | ||
181 | #endif |
182 | #endif |
182 | > |
183 | > |
183 | >=visible)>=visible)> |
184 | >=visible)>=visible)> |