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