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