Rev 4073 | Rev 4078 | 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 |
2 | |||
3 | struct llist |
||
4 | { |
||
4049 | leency | 5 | int x, y, w, h, min_h, line_h; |
3225 | leency | 6 | int count, visible, first, current; |
4049 | leency | 7 | int current_temp; |
3225 | leency | 8 | void ClearList(); |
4073 | leency | 9 | int ProcessKey(dword key); |
4077 | leency | 10 | int MouseOver(int xx, yy); |
11 | int ProcessMouse(int xx, yy); |
||
4059 | leency | 12 | int KeyDown(); |
13 | int KeyUp(); |
||
4063 | leency | 14 | int KeyHome(); |
15 | int KeyEnd(); |
||
3225 | leency | 16 | void SetSizes(int xx, yy, ww, hh, min_hh, line_hh); |
17 | int MouseScroll(dword scroll_state); |
||
18 | }; |
||
19 | |||
20 | |||
21 | void llist::ClearList() |
||
22 | { |
||
23 | count = visible = first = current = 0; |
||
24 | } |
||
25 | |||
26 | |||
27 | void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh) |
||
28 | { |
||
29 | x = xx; |
||
30 | y = yy; |
||
31 | w = ww; |
||
32 | h = hh; |
||
33 | min_h = min_hh; |
||
34 | line_h = line_hh; |
||
3368 | leency | 35 | visible = h / line_h; |
3225 | leency | 36 | } |
37 | |||
38 | |||
39 | int llist::MouseScroll(dword scroll_state) |
||
40 | { |
||
41 | if (scroll_state == 65535) |
||
42 | { |
||
43 | if (first == 0) return 0; |
||
44 | if (first > 3) first -= 2; else first=0; |
||
45 | return 1; |
||
46 | } |
||
47 | if (scroll_state == 1) |
||
48 | { |
||
49 | if (visible+first+3 >= count) first = count - visible; else first+=2; |
||
50 | return 1; |
||
51 | } |
||
52 | return 0; |
||
4059 | leency | 53 | } |
54 | |||
4077 | leency | 55 | int llist::MouseOver(int xx, yy) |
56 | { |
||
57 | if (xx>x) && (xx |
||
58 | return 0; |
||
59 | } |
||
60 | |||
61 | int llist::ProcessMouse(int xx, yy) |
||
62 | { |
||
63 | if (MouseOver(xx, yy)) |
||
64 | { |
||
65 | current_temp = yy - y / line_h + first; |
||
66 | if (current_temp != current) |
||
67 | { |
||
68 | current = current_temp; |
||
69 | return 1; |
||
70 | } |
||
71 | } |
||
72 | return 0; |
||
73 | } |
||
74 | |||
4073 | leency | 75 | int llist::ProcessKey(dword key) |
76 | { |
||
77 | switch(key) |
||
78 | { |
||
79 | case 177: return KeyDown(); |
||
80 | case 178: return KeyUp(); |
||
81 | case 180: return KeyHome(); |
||
82 | case 181: return KeyEnd(); |
||
83 | } |
||
84 | return 0; |
||
85 | } |
||
86 | |||
4059 | leency | 87 | int llist::KeyDown() |
88 | { |
||
89 | if (current-first+1 |
||
90 | { |
||
4063 | leency | 91 | if (current+1>=count) return 0; |
4059 | leency | 92 | current++; |
93 | } |
||
94 | else |
||
95 | { |
||
4063 | leency | 96 | if (visible+first>=count) return 0; |
4059 | leency | 97 | first++; |
98 | current++; |
||
99 | } |
||
100 | return 1; |
||
101 | } |
||
102 | |||
103 | int llist::KeyUp() |
||
104 | { |
||
105 | if (current>first) |
||
106 | { |
||
107 | current--; |
||
108 | } |
||
109 | else |
||
110 | { |
||
4063 | leency | 111 | if (first==0) return 0; |
4059 | leency | 112 | first--; |
113 | current--; |
||
114 | } |
||
115 | return 1; |
||
4063 | leency | 116 | } |
117 | |||
118 | int llist::KeyHome() |
||
119 | { |
||
120 | if (current==0) && (first==0) return 0; |
||
121 | current=0; |
||
122 | first=0; |
||
123 | return 1; |
||
124 | } |
||
125 | |||
126 | int llist::KeyEnd() |
||
127 | { |
||
128 | if (current==count-1) && (first==count-visible) return 0; |
||
129 | current=count-1; |
||
130 | first=count-visible; |
||
131 | return 1; |
||
3225 | leency | 132 | } |