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