Rev 8383 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7773 | leency | 1 | #define MEMSIZE 4096*40 |
2 | |||
7778 | leency | 3 | #include "../lib/gui.h" |
7773 | leency | 4 | #include "../lib/collection.h" |
5 | #include "../lib/list_box.h" |
||
6 | #include "../lib/fs.h" |
||
7 | |||
8 | #define ITEM_H 19 |
||
7796 | leency | 9 | #define SEP_H 4 |
7773 | leency | 10 | |
11 | llist menu1; |
||
7972 | leency | 12 | collection names=0; |
13 | collection hotkeys=0; |
||
7773 | leency | 14 | |
7780 | leency | 15 | int selected, win_x, win_y; |
7773 | leency | 16 | |
17 | int max_name_len; |
||
18 | int max_hotkey_len; |
||
7796 | leency | 19 | int menu_w, menu_h; |
7773 | leency | 20 | |
21 | void GetWindowPosition() |
||
22 | { |
||
7780 | leency | 23 | int position; |
24 | shared_mem = memopen(#shared_name, 16, SHM_OPEN + SHM_WRITE); |
||
25 | selected = ESDWORD[shared_mem ]; |
||
7779 | leency | 26 | win_x = ESDWORD[shared_mem + 4]; |
27 | win_y = ESDWORD[shared_mem + 8]; |
||
7778 | leency | 28 | position = ESDWORD[shared_mem + 12]; |
8021 | leency | 29 | if (position == MENU_TOP_RIGHT) win_x -= menu1.w; |
30 | if (position == MENU_BOT_LEFT) win_y -= menu1.h; |
||
31 | if (position == MENU_BOT_RIGHT) { |
||
7773 | leency | 32 | win_x -= menu1.w; |
33 | win_y -= menu1.h; |
||
34 | } |
||
35 | } |
||
36 | |||
7780 | leency | 37 | void GetMenuWidths() |
38 | { |
||
39 | int i; |
||
40 | for (i=0; i |
||
41 | max_name_len = math.max(max_name_len, strlen(names.get(i))); |
||
42 | } |
||
43 | for (i=0; i |
||
44 | max_hotkey_len = math.max(max_hotkey_len, strlen(hotkeys.get(i))); |
||
45 | } |
||
46 | max_name_len = max_name_len * 6; |
||
47 | max_hotkey_len *= 6; |
||
48 | if (max_hotkey_len) max_name_len += 12; |
||
49 | } |
||
50 | |||
7773 | leency | 51 | void GetMenuItems(dword current_name) |
52 | { |
||
53 | dword next_name = strchr(current_name, '\n'); |
||
54 | dword hotkey = strchr(current_name, '|'); |
||
55 | |||
56 | ESBYTE[next_name] = '\0'; |
||
57 | |||
58 | if (hotkey) && (hotkey < next_name) { |
||
59 | ESBYTE[hotkey] = '\0'; |
||
60 | } else { |
||
61 | if (hotkey) && (!next_name) { |
||
62 | ESBYTE[hotkey] = '\0'; |
||
63 | } else { |
||
7780 | leency | 64 | hotkey = " "; |
7773 | leency | 65 | } |
66 | } |
||
67 | |||
68 | hotkeys.add(hotkey+1); |
||
69 | names.add(current_name); |
||
70 | |||
71 | if (next_name) GetMenuItems(next_name+2); |
||
72 | } |
||
73 | |||
7796 | leency | 74 | int GetSeparatorsCount() |
75 | { |
||
76 | int i, count=0; |
||
77 | for (i=0; i |
||
78 | if (streq(names.get(i), "-")) count++; |
||
79 | } |
||
80 | return count; |
||
81 | } |
||
82 | |||
83 | int MoveMouseToHandleSeparators(int _mouse_y) |
||
84 | { |
||
85 | int i, item_y=menu1.y; |
||
86 | int item_i=0; |
||
87 | for (i=0; i |
||
88 | { |
||
89 | if (streq(names.get(i), "-")) { |
||
90 | item_y += SEP_H; |
||
91 | } else { |
||
92 | item_y += ITEM_H; |
||
93 | item_i++; |
||
94 | } |
||
95 | if (_mouse_y >= item_y) && (_mouse_y < item_y + ITEM_H) { |
||
96 | return item_i * ITEM_H + menu1.y; |
||
97 | } |
||
98 | } |
||
7797 | leency | 99 | return _mouse_y; |
7796 | leency | 100 | } |
101 | |||
7773 | leency | 102 | void main() |
103 | { |
||
104 | proc_info Form; |
||
105 | |||
7984 | leency | 106 | if (!param) RunProgram("/sys/network/WebView", "http://board.kolibrios.org/viewtopic.php?f=24&t=4233#p74599"); |
7778 | leency | 107 | |
108 | GetMenuItems(#param); |
||
7780 | leency | 109 | GetMenuWidths(); |
7773 | leency | 110 | |
7796 | leency | 111 | menu_w = max_name_len + max_hotkey_len + 23; |
112 | menu_h = GetSeparatorsCount() * SEP_H |
||
113 | + calc(names.count - GetSeparatorsCount() * ITEM_H); |
||
114 | |||
7773 | leency | 115 | menu1.count = names.count; |
116 | menu1.SetFont(6, 9, 0x80); |
||
7796 | leency | 117 | menu1.SetSizes(2,2, menu_w, menu_h, ITEM_H); |
7773 | leency | 118 | menu1.cur_y = -1; |
119 | |||
120 | GetWindowPosition(); |
||
121 | |||
7984 | leency | 122 | @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE); |
7773 | leency | 123 | loop() switch(WaitEvent()) |
124 | { |
||
125 | case evMouse: |
||
126 | GetProcessInfo(#Form, SelfInfo); |
||
127 | if (!CheckActiveProcess(Form.ID)) exit(); |
||
128 | mouse.get(); |
||
7796 | leency | 129 | if (menu1.MouseOver(mouse.x, mouse.y)) { |
130 | mouse.y = MoveMouseToHandleSeparators(mouse.y); |
||
131 | if (menu1.ProcessMouse(mouse.x, mouse.y)) draw_list(); |
||
132 | if (mouse.lkm)&&(mouse.up) click(); |
||
133 | } |
||
7773 | leency | 134 | break; |
135 | |||
136 | case evKey: |
||
137 | ProcessKeys(); |
||
138 | break; |
||
139 | |||
140 | case evReDraw: |
||
7783 | leency | 141 | DefineAndDrawWindow(win_x, win_y, menu1.w+4, menu1.h+4, 0x01, 0, 0, 0x01fffFFF); |
7806 | leency | 142 | sc.get(); |
7773 | leency | 143 | Draw3DPopup(0,0,menu1.w+2,menu1.h+2); |
144 | draw_list(); |
||
145 | } |
||
146 | } |
||
147 | |||
7878 | leency | 148 | void CorrectLastItem() |
149 | { |
||
150 | if (menu1.cur_y > menu1.count - GetSeparatorsCount() - 1) { |
||
151 | menu1.cur_y = menu1.count - GetSeparatorsCount() - 1; |
||
152 | } |
||
153 | } |
||
154 | |||
7984 | leency | 155 | inline ProcessKeys() |
7773 | leency | 156 | { |
8881 | leency | 157 | @GetKeyScancode(); |
158 | switch(AL) |
||
7773 | leency | 159 | { |
160 | case SCAN_CODE_ESC: |
||
161 | exit(); |
||
162 | |||
163 | case SCAN_CODE_ENTER: |
||
164 | click(); |
||
165 | |||
166 | case SCAN_CODE_DOWN: |
||
7796 | leency | 167 | if (!menu1.KeyDown()) |
168 | || (menu1.count - menu1.cur_y - GetSeparatorsCount() -1 < 0) menu1.KeyHome(); |
||
7773 | leency | 169 | draw_list(); |
170 | break; |
||
171 | |||
172 | case SCAN_CODE_UP: |
||
7878 | leency | 173 | if (!menu1.KeyUp()) { |
174 | menu1.KeyEnd(); |
||
175 | CorrectLastItem(); |
||
176 | } |
||
7773 | leency | 177 | draw_list(); |
178 | break; |
||
179 | |||
7878 | leency | 180 | case SCAN_CODE_END: |
181 | menu1.KeyEnd(); |
||
182 | CorrectLastItem(); |
||
183 | draw_list(); |
||
184 | break; |
||
185 | |||
7773 | leency | 186 | default: |
8881 | leency | 187 | if (menu1.ProcessKey(AL)) draw_list(); |
7773 | leency | 188 | } |
189 | } |
||
190 | |||
191 | void draw_list() |
||
192 | { |
||
7796 | leency | 193 | int i, item_y=menu1.y, item_i=0; |
7784 | leency | 194 | dword name_color; |
195 | dword hotkey_color; |
||
7773 | leency | 196 | |
7784 | leency | 197 | static dword inactive_background_color; |
198 | static dword active_background_color; |
||
199 | static dword active_top_border_color; |
||
200 | static dword inactive_text_shadow_color; |
||
201 | static bool skin_dark; |
||
7773 | leency | 202 | |
7784 | leency | 203 | static bool colors_set; |
204 | if (!colors_set) { |
||
205 | colors_set = true; |
||
7806 | leency | 206 | inactive_background_color = MixColors(sc.work, 0xFFFfff,230); |
207 | active_background_color = MixColors(sc.button, sc.work,230); |
||
208 | active_top_border_color = MixColors(sc.work_graph, sc.button,240); |
||
209 | inactive_text_shadow_color = MixColors(sc.work,0xFFFfff,120); |
||
7784 | leency | 210 | skin_dark = skin_is_dark(); |
211 | } |
||
212 | |||
7773 | leency | 213 | for (i=0; i |
214 | { |
||
7796 | leency | 215 | if (streq(names.get(i), "-")) { |
216 | DrawBar(menu1.x, item_y+0, menu1.w, 1, inactive_background_color); |
||
7806 | leency | 217 | DrawBar(menu1.x-1, item_y+1, menu1.w+1, 1, sc.work_dark); |
218 | DrawBar(menu1.x, item_y+2, menu1.w, 1, sc.work_light); |
||
7796 | leency | 219 | DrawBar(menu1.x, item_y+3, menu1.w, 1, inactive_background_color); |
7798 | leency | 220 | //DrawBar(menu1.x, item_y+0, menu1.w, 4, inactive_background_color); |
7806 | leency | 221 | //DrawBar(13, item_y+1, menu1.w-24, 1, sc.work_dark); |
222 | //DrawBar(13, item_y+2, menu1.w-24, 1, sc.work_light); |
||
7796 | leency | 223 | item_y += SEP_H; |
7773 | leency | 224 | } else { |
7796 | leency | 225 | if (item_i==menu1.cur_y) { |
7806 | leency | 226 | hotkey_color = name_color = sc.button_text; |
7796 | leency | 227 | DrawBar(menu1.x, item_y+1, menu1.w, ITEM_H-2, active_background_color); |
228 | DrawBar(menu1.x, item_y, menu1.w, 1, active_top_border_color); |
||
7806 | leency | 229 | DrawBar(menu1.x, item_y+ITEM_H-1, menu1.w, 1, sc.work_light); |
7796 | leency | 230 | } else { |
7806 | leency | 231 | name_color = sc.work_text; |
232 | hotkey_color = sc.work_graph; |
||
7796 | leency | 233 | DrawBar(menu1.x, item_y, menu1.w, ITEM_H, inactive_background_color); |
234 | if (!skin_dark) WriteText(13+1, item_y + menu1.text_y +1, 0x80, |
||
235 | inactive_text_shadow_color, names.get(i)); |
||
236 | } |
||
237 | WriteText(-strlen(hotkeys.get(i))*6 + 13 + max_name_len + max_hotkey_len, |
||
238 | item_y + menu1.text_y, 0x80, hotkey_color, hotkeys.get(i)); |
||
239 | WriteText(13, item_y + menu1.text_y, 0x80, name_color, names.get(i)); |
||
240 | item_y += ITEM_H; |
||
241 | item_i++; |
||
7773 | leency | 242 | } |
243 | } |
||
7780 | leency | 244 | if (selected) WriteText(5, selected-1*ITEM_H + menu1.y + menu1.text_y, 0x80, 0xEE0000, "\x10"); |
7773 | leency | 245 | } |
246 | |||
247 | void click() |
||
248 | { |
||
7780 | leency | 249 | ESDWORD[shared_mem] = menu1.cur_y + 1; |
7773 | leency | 250 | ExitProcess(); |
251 | } |
||
252 | |||
253 | void exit() |
||
254 | { |
||
7780 | leency | 255 | ESDWORD[shared_mem] = 0; |
7773 | leency | 256 | ExitProcess(); |
257 | }>>> |