]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/hud_config.qc
Merge remote branch 'origin/master' into samual/hud_updates
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud_config.qc
1 #define HUD_Write(s) fputs(fh, s)
2 // q: quoted, n: not quoted
3 #define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
4 #define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
5 #define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
6 #define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
7 // Save the config
8 void HUD_Panel_ExportCfg(string cfgname)
9 {
10         float fh;
11         string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
12         fh = fopen(filename, FILE_WRITE);
13         if(fh >= 0)
14         {
15                 HUD_Write_Cvar_q("hud_skin");
16                 HUD_Write_Cvar_q("hud_panel_bg");
17                 HUD_Write_Cvar_q("hud_panel_bg_color");
18                 HUD_Write_Cvar_q("hud_panel_bg_color_team");
19                 HUD_Write_Cvar_q("hud_panel_bg_alpha");
20                 HUD_Write_Cvar_q("hud_panel_bg_border");
21                 HUD_Write_Cvar_q("hud_panel_bg_padding");
22                 HUD_Write_Cvar_q("hud_panel_fg_alpha");
23                 HUD_Write("\n");
24
25                 HUD_Write_Cvar_q("hud_dock");
26                 HUD_Write_Cvar_q("hud_dock_color");
27                 HUD_Write_Cvar_q("hud_dock_color_team");
28                 HUD_Write_Cvar_q("hud_dock_alpha");
29                 HUD_Write("\n");
30
31                 HUD_Write_Cvar_q("hud_progressbar_alpha");
32                 HUD_Write_Cvar_q("hud_progressbar_strength_color");
33                 HUD_Write_Cvar_q("hud_progressbar_shield_color");
34                 HUD_Write_Cvar_q("hud_progressbar_health_color");
35                 HUD_Write_Cvar_q("hud_progressbar_armor_color");
36                 HUD_Write_Cvar_q("hud_progressbar_fuel_color");
37                 HUD_Write_Cvar_q("hud_progressbar_nexball_color");
38                 HUD_Write("\n");
39
40                 HUD_Write_Cvar_q("_hud_panelorder");
41                 HUD_Write("\n");
42
43                 HUD_Write_Cvar_q("hud_configure_grid");
44                 HUD_Write_Cvar_q("hud_configure_grid_xsize");
45                 HUD_Write_Cvar_q("hud_configure_grid_ysize");
46                 HUD_Write("\n");
47
48                 // common cvars for all panels
49                 float i;
50                 for (i = 0; i < HUD_PANEL_NUM; ++i)
51                 {
52                         HUD_Panel_GetName(i);
53
54                         HUD_Write_PanelCvar_n("");
55                         HUD_Write_PanelCvar_q("_pos");
56                         HUD_Write_PanelCvar_q("_size");
57                         HUD_Write_PanelCvar_q("_bg");
58                         HUD_Write_PanelCvar_q("_bg_color");
59                         HUD_Write_PanelCvar_q("_bg_color_team");
60                         HUD_Write_PanelCvar_q("_bg_alpha");
61                         HUD_Write_PanelCvar_q("_bg_border");
62                         HUD_Write_PanelCvar_q("_bg_padding");
63                         switch(i) {
64                                 case HUD_PANEL_WEAPONS:
65                                         HUD_Write_PanelCvar_q("_complainbubble");
66                                         HUD_Write_PanelCvar_q("_complainbubble_padding");
67                                         HUD_Write_PanelCvar_q("_complainbubble_time");
68                                         HUD_Write_PanelCvar_q("_complainbubble_fadetime");
69                                         HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
70                                         HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
71                                         HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
72                                         HUD_Write_PanelCvar_q("_ammo_color");
73                                         HUD_Write_PanelCvar_q("_ammo_alpha");
74                                         HUD_Write_PanelCvar_q("_aspect");
75                                         HUD_Write_PanelCvar_q("_timeout");
76                                         HUD_Write_PanelCvar_q("_timeout_effect");
77                                         break;
78                                 case HUD_PANEL_AMMO:
79                                         HUD_Write_PanelCvar_q("_onlycurrent");
80                                         HUD_Write_PanelCvar_q("_iconalign");
81                                         HUD_Write_PanelCvar_q("_progressbar");
82                                         HUD_Write_PanelCvar_q("_progressbar_name");
83                                         HUD_Write_PanelCvar_q("_progressbar_xoffset");
84                                         HUD_Write_PanelCvar_q("_text");
85                                         break;
86                                 case HUD_PANEL_POWERUPS:
87                                         HUD_Write_PanelCvar_q("_flip");
88                                         HUD_Write_PanelCvar_q("_iconalign");
89                                         HUD_Write_PanelCvar_q("_baralign");
90                                         HUD_Write_PanelCvar_q("_progressbar");
91                                         HUD_Write_PanelCvar_q("_progressbar_strength");
92                                         HUD_Write_PanelCvar_q("_progressbar_shield");
93                                         break;
94                                 case HUD_PANEL_HEALTHARMOR:
95                                         HUD_Write_PanelCvar_q("_flip");
96                                         HUD_Write_PanelCvar_q("_iconalign");
97                                         HUD_Write_PanelCvar_q("_baralign");
98                                         HUD_Write_PanelCvar_q("_progressbar");
99                                         HUD_Write_PanelCvar_q("_progressbar_health");
100                                         HUD_Write_PanelCvar_q("_progressbar_armor");
101                                         HUD_Write_PanelCvar_q("_text");
102                                         break;
103                                 case HUD_PANEL_NOTIFY:
104                                         HUD_Write_PanelCvar_q("_flip");
105                                         HUD_Write_PanelCvar_q("_fontsize");
106                                         HUD_Write_PanelCvar_q("_print");
107                                         break;
108                                 case HUD_PANEL_RADAR:
109                                         HUD_Write_PanelCvar_q("_foreground_alpha");
110                                         break;
111                                 case HUD_PANEL_SCORE:
112                                         HUD_Write_PanelCvar_q("_rankings");
113                                         break;
114                                 case HUD_PANEL_VOTE:
115                                         HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
116                                         break;
117                                 case HUD_PANEL_PRESSEDKEYS:
118                                         HUD_Write_PanelCvar_q("_aspect");
119                                         break;
120                                 case HUD_PANEL_INFOMESSAGES:
121                                         HUD_Write_PanelCvar_q("_flip");
122                                         break;
123                                 case HUD_PANEL_PHYSICS:
124                                         HUD_Write_PanelCvar_q("_flip");
125                                         HUD_Write_PanelCvar_q("_baralign");
126                                         HUD_Write_PanelCvar_q("_progressbar");
127                                         HUD_Write_PanelCvar_q("_acceleration_mode");
128                                         break;
129                                 case HUD_PANEL_CENTERPRINT:
130                                         HUD_Write_PanelCvar_q("_align");
131                                         HUD_Write_PanelCvar_q("_flip");
132                                         HUD_Write_PanelCvar_q("_fontscale");
133                                         HUD_Write_PanelCvar_q("_time");
134                                         HUD_Write_PanelCvar_q("_fadetime");
135                                         break;
136                         }
137                         HUD_Write("\n");
138                 }
139                 HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
140
141                 print(sprintf(_("^2Successfully exported to %s! (Note: It's saved in data/data/)\n"), filename));
142                 fclose(fh);
143         }
144         else
145                 print(sprintf(_("^1Couldn't write to %s\n"), filename));
146 }
147
148 // check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
149 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
150 {
151         float i;
152         float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
153         vector myTarget;
154         myTarget = myPos;
155
156         for (i = 0; i < HUD_PANEL_NUM; ++i) {
157                 if(i == highlightedPanel || !panel_enabled)
158                         continue;
159
160                 HUD_Panel_UpdatePosSizeForId(i);
161
162                 panel_pos -= '1 1 0' * panel_bg_border;
163                 panel_size += '2 2 0' * panel_bg_border;
164
165                 if(myPos_y + mySize_y < panel_pos_y)
166                         continue;
167                 if(myPos_y > panel_pos_y + panel_size_y)
168                         continue;
169
170                 if(myPos_x + mySize_x < panel_pos_x)
171                         continue;
172                 if(myPos_x > panel_pos_x + panel_size_x)
173                         continue;
174
175                 // OK, there IS a collision.
176
177                 myCenter_x = myPos_x + 0.5 * mySize_x;
178                 myCenter_y = myPos_y + 0.5 * mySize_y;
179
180                 targCenter_x = panel_pos_x + 0.5 * panel_size_x;
181                 targCenter_y = panel_pos_y + 0.5 * panel_size_y;
182
183                 if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
184                 {
185                         if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
186                                 myTarget_x = panel_pos_x - mySize_x;
187                         else // push it upwards
188                                 myTarget_y = panel_pos_y - mySize_y;
189                 }
190                 else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
191                 {
192                         if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
193                                 myTarget_x = panel_pos_x + panel_size_x;
194                         else // push it upwards
195                                 myTarget_y = panel_pos_y - mySize_y;
196                 }
197                 else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
198                 {
199                         if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
200                                 myTarget_x = panel_pos_x - mySize_x;
201                         else // push it downwards
202                                 myTarget_y = panel_pos_y + panel_size_y;
203                 }
204                 else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
205                 {
206                         if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
207                                 myTarget_x = panel_pos_x + panel_size_x;
208                         else // push it downwards
209                                 myTarget_y = panel_pos_y + panel_size_y;
210                 }
211                 //if(cvar("hud_configure_checkcollisions_debug"))
212                         //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
213         }
214
215         return myTarget;
216 }
217
218 void HUD_Panel_SetPos(vector pos)
219 {
220         HUD_Panel_UpdatePosSizeForId(highlightedPanel);
221         vector mySize;
222         mySize = panel_size;
223
224         //if(cvar("hud_configure_checkcollisions_debug"))
225                 //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
226
227         if(autocvar_hud_configure_grid)
228         {
229                 pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
230                 pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
231         }
232
233         if(hud_configure_checkcollisions)
234                 pos = HUD_Panel_CheckMove(pos, mySize);
235
236         pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
237         pos_y = bound(0, pos_y, vid_conheight - mySize_y);
238
239         string s;
240         s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
241
242         HUD_Panel_GetName(highlightedPanel);
243         cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
244 }
245
246 // check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
247 vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
248         float i;
249
250         vector targEndPos;
251
252         float dist_x, dist_y;
253         float ratio;
254         ratio = mySize_x/mySize_y;
255
256         for (i = 0; i < HUD_PANEL_NUM; ++i) {
257                 if(i == highlightedPanel || !panel_enabled)
258                         continue;
259
260                 HUD_Panel_UpdatePosSizeForId(i);
261
262                 panel_pos -= '1 1 0' * panel_bg_border;
263                 panel_size += '2 2 0' * panel_bg_border;
264
265                 targEndPos = panel_pos + panel_size;
266
267                 // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
268                 if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
269                         continue;
270
271                 if (resizeCorner == 1)
272                 {
273                         // check if this panel is on our way
274                         if (resizeorigin_x <= panel_pos_x)
275                                 continue;
276                         if (resizeorigin_y <= panel_pos_y)
277                                 continue;
278                         if (targEndPos_x <= resizeorigin_x - mySize_x)
279                                 continue;
280                         if (targEndPos_y <= resizeorigin_y - mySize_y)
281                                 continue;
282
283                         // there is a collision:
284                         // detect which side of the panel we are facing is actually limiting the resizing
285                         // (which side the resize direction finds for first) and reduce the size up to there
286                         //
287                         // dist is the distance between resizeorigin and the "analogous" point of the panel
288                         // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
289                         dist_x = resizeorigin_x - targEndPos_x;
290                         dist_y = resizeorigin_y - targEndPos_y;
291                         if (dist_y <= 0 || dist_x / dist_y > ratio)
292                                 mySize_x = min(mySize_x, dist_x);
293                         else
294                                 mySize_y = min(mySize_y, dist_y);
295                 }
296                 else if (resizeCorner == 2)
297                 {
298                         if (resizeorigin_x >= targEndPos_x)
299                                 continue;
300                         if (resizeorigin_y <= panel_pos_y)
301                                 continue;
302                         if (panel_pos_x >= resizeorigin_x + mySize_x)
303                                 continue;
304                         if (targEndPos_y <= resizeorigin_y - mySize_y)
305                                 continue;
306
307                         dist_x = panel_pos_x - resizeorigin_x;
308                         dist_y = resizeorigin_y - targEndPos_y;
309                         if (dist_y <= 0 || dist_x / dist_y > ratio)
310                                 mySize_x = min(mySize_x, dist_x);
311                         else
312                                 mySize_y = min(mySize_y, dist_y);
313                 }
314                 else if (resizeCorner == 3)
315                 {
316                         if (resizeorigin_x <= panel_pos_x)
317                                 continue;
318                         if (resizeorigin_y >= targEndPos_y)
319                                 continue;
320                         if (targEndPos_x <= resizeorigin_x - mySize_x)
321                                 continue;
322                         if (panel_pos_y >= resizeorigin_y + mySize_y)
323                                 continue;
324
325                         dist_x = resizeorigin_x - targEndPos_x;
326                         dist_y = panel_pos_y - resizeorigin_y;
327                         if (dist_y <= 0 || dist_x / dist_y > ratio)
328                                 mySize_x = min(mySize_x, dist_x);
329                         else
330                                 mySize_y = min(mySize_y, dist_y);
331                 }
332                 else if (resizeCorner == 4)
333                 {
334                         if (resizeorigin_x >= targEndPos_x)
335                                 continue;
336                         if (resizeorigin_y >= targEndPos_y)
337                                 continue;
338                         if (panel_pos_x >= resizeorigin_x + mySize_x)
339                                 continue;
340                         if (panel_pos_y >= resizeorigin_y + mySize_y)
341                                 continue;
342
343                         dist_x = panel_pos_x - resizeorigin_x;
344                         dist_y = panel_pos_y - resizeorigin_y;
345                         if (dist_y <= 0 || dist_x / dist_y > ratio)
346                                 mySize_x = min(mySize_x, dist_x);
347                         else
348                                 mySize_y = min(mySize_y, dist_y);
349                 }
350                 //if(cvar("hud_configure_checkcollisions_debug"))
351                         //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
352         }
353
354         return mySize;
355 }
356
357 void HUD_Panel_SetPosSize(vector mySize)
358 {
359         HUD_Panel_UpdatePosSizeForId(highlightedPanel);
360         vector resizeorigin;
361         resizeorigin = panel_click_resizeorigin;
362         vector myPos;
363
364         // minimum panel size cap
365         mySize_x = max(0.025 * vid_conwidth, mySize_x);
366         mySize_y = max(0.025 * vid_conheight, mySize_y);
367
368         if(highlightedPanel == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
369         {
370                 mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
371                 mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
372         }
373
374         // collision testing|
375         // -----------------+
376
377         // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
378         if(resizeCorner == 1) {
379                 myPos_x = resizeorigin_x - mySize_x;
380                 myPos_y = resizeorigin_y - mySize_y;
381         } else if(resizeCorner == 2) {
382                 myPos_x = resizeorigin_x;
383                 myPos_y = resizeorigin_y - mySize_y;
384         } else if(resizeCorner == 3) {
385                 myPos_x = resizeorigin_x - mySize_x;
386                 myPos_y = resizeorigin_y;
387         } else { // resizeCorner == 4
388                 myPos_x = resizeorigin_x;
389                 myPos_y = resizeorigin_y;
390         }
391
392         // left/top screen edges
393         if(myPos_x < 0)
394                 mySize_x = mySize_x + myPos_x;
395         if(myPos_y < 0)
396                 mySize_y = mySize_y + myPos_y;
397
398         // bottom/right screen edges
399         if(myPos_x + mySize_x > vid_conwidth)
400                 mySize_x = vid_conwidth - myPos_x;
401         if(myPos_y + mySize_y > vid_conheight)
402                 mySize_y = vid_conheight - myPos_y;
403
404         //if(cvar("hud_configure_checkcollisions_debug"))
405                 //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
406
407         // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
408         if(autocvar_hud_configure_grid)
409         {
410                 mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
411                 mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
412         }
413
414         if(hud_configure_checkcollisions)
415                 mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
416
417         // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
418         mySize_x = max(0.025 * vid_conwidth, mySize_x);
419         mySize_y = max(0.025 * vid_conheight, mySize_y);
420
421         // do another pos check, as size might have changed by now
422         if(resizeCorner == 1) {
423                 myPos_x = resizeorigin_x - mySize_x;
424                 myPos_y = resizeorigin_y - mySize_y;
425         } else if(resizeCorner == 2) {
426                 myPos_x = resizeorigin_x;
427                 myPos_y = resizeorigin_y - mySize_y;
428         } else if(resizeCorner == 3) {
429                 myPos_x = resizeorigin_x - mySize_x;
430                 myPos_y = resizeorigin_y;
431         } else { // resizeCorner == 4
432                 myPos_x = resizeorigin_x;
433                 myPos_y = resizeorigin_y;
434         }
435
436         //if(cvar("hud_configure_checkcollisions_debug"))
437                 //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
438
439         HUD_Panel_GetName(highlightedPanel);
440         string s;
441         s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
442         cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
443
444         s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
445         cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
446 }
447
448 float pressed_key_time;
449 vector highlightedPanel_initial_pos, highlightedPanel_initial_size;
450 void HUD_Panel_Arrow_Action(float nPrimary)
451 {
452         if (highlightedPanel == -1)
453                 return;
454
455         hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
456
457         float step;
458         if(autocvar_hud_configure_grid)
459         {
460                 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
461                 {
462                         if (hudShiftState & S_SHIFT)
463                                 step = hud_configure_realGridSize_y;
464                         else
465                                 step = 2 * hud_configure_realGridSize_y;
466                 }
467                 else
468                 {
469                         if (hudShiftState & S_SHIFT)
470                                 step = hud_configure_realGridSize_x;
471                         else
472                                 step = 2 * hud_configure_realGridSize_x;
473                 }
474         }
475         else
476         {
477                 if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
478                         step = vid_conheight;
479                 else
480                         step = vid_conwidth;
481                 if (hudShiftState & S_SHIFT)
482                         step = (step / 256); // more precision
483                 else
484                         step = (step / 64) * (1 + 2 * (time - pressed_key_time));
485         }
486
487         HUD_Panel_UpdatePosSizeForId(highlightedPanel);
488
489         highlightedPanel_initial_pos = panel_pos;
490         highlightedPanel_initial_size = panel_size;
491
492         if (hudShiftState & S_ALT) // resize
493         {
494                 highlightedAction = 1;
495                 if(nPrimary == K_UPARROW)
496                         resizeCorner = 1;
497                 else if(nPrimary == K_RIGHTARROW)
498                         resizeCorner = 2;
499                 else if(nPrimary == K_LEFTARROW)
500                         resizeCorner = 3;
501                 else // if(nPrimary == K_DOWNARROW)
502                         resizeCorner = 4;
503
504                 // ctrl+arrow reduces the size, instead of increasing it
505                 // Note that ctrl disables collisions check too, but it's fine
506                 // since we don't collide with anything reducing the size
507                 if (hudShiftState & S_CTRL) {
508                         step = -step;
509                         resizeCorner = 5 - resizeCorner;
510                 }
511
512                 vector mySize;
513                 mySize = panel_size;
514                 panel_click_resizeorigin = panel_pos;
515                 if(resizeCorner == 1) {
516                         panel_click_resizeorigin += mySize;
517                         mySize_y += step;
518                 } else if(resizeCorner == 2) {
519                         panel_click_resizeorigin_y += mySize_y;
520                         mySize_x += step;
521                 } else if(resizeCorner == 3) {
522                         panel_click_resizeorigin_x += mySize_x;
523                         mySize_x += step;
524                 } else { // resizeCorner == 4
525                         mySize_y += step;
526                 }
527                 HUD_Panel_SetPosSize(mySize);
528         }
529         else // move
530         {
531                 highlightedAction = 2;
532                 vector pos;
533                 pos = panel_pos;
534                 if(nPrimary == K_UPARROW)
535                         pos_y -= step;
536                 else if(nPrimary == K_DOWNARROW)
537                         pos_y += step;
538                 else if(nPrimary == K_LEFTARROW)
539                         pos_x -= step;
540                 else // if(nPrimary == K_RIGHTARROW)
541                         pos_x += step;
542
543                 HUD_Panel_SetPos(pos);
544         }
545
546         HUD_Panel_UpdatePosSizeForId(highlightedPanel);
547
548         if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
549         {
550                 // backup!
551                 panel_pos_backup = highlightedPanel_initial_pos;
552                 panel_size_backup = highlightedPanel_initial_size;
553                 highlightedPanel_backup = highlightedPanel;
554         }
555 }
556
557 const float S_MOUSE1 = 1;
558 const float S_MOUSE2 = 2;
559 const float S_MOUSE3 = 4;
560 float mouseClicked;
561 float prevMouseClicked; // previous state
562 float prevMouseClickedTime; // time during previous left mouse click, to check for doubleclicks
563 vector prevMouseClickedPos; // pos during previous left mouse click, to check for doubleclicks
564
565 void HUD_Panel_EnableMenu();
566 float tab_panels[HUD_PANEL_NUM];
567 float tab_panel, tab_backward;
568 vector tab_panel_pos;
569 void HUD_Panel_FirstInDrawQ(float id);
570 void reset_tab_panels()
571 {
572         int i;
573         for(i = 0; i < HUD_PANEL_NUM; ++i)
574                 tab_panels[i] = -1;
575 }
576 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
577 {
578         string s;
579
580         // we only care for keyboard events
581         if(bInputType != 0 && bInputType != 1)
582                 return false;
583
584         if(!autocvar__hud_configure)
585                 return false;
586
587         // allow console bind to work
588         string con_keys;
589         float keys;
590         con_keys = findkeysforcommand("toggleconsole");
591         keys = tokenize(con_keys);
592
593         float hit_con_bind, i;
594         for (i = 0; i < keys; ++i)
595         {
596                 if(nPrimary == stof(argv(i)))
597                         hit_con_bind = 1;
598         }
599
600         if(bInputType == 0) {
601                 if(nPrimary == K_ALT) hudShiftState |= S_ALT;
602                 if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
603                 if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
604         }
605         else if(bInputType == 1) {
606                 if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
607                 if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
608                 if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
609         }
610
611         if(nPrimary == K_CTRL)
612         {
613                 if (bInputType == 1) //ctrl has been released
614                 {
615                         if (tab_panel != -1)
616                         {
617                                 //switch to selected panel
618                                 highlightedPanel = tab_panel;
619                                 highlightedAction = 0;
620                                 HUD_Panel_FirstInDrawQ(highlightedPanel);
621                         }
622                         tab_panel = -1;
623                         reset_tab_panels();
624                 }
625         }
626
627         if(nPrimary == K_MOUSE1)
628         {
629                 if(bInputType == 0) // key pressed
630                         mouseClicked |= S_MOUSE1;
631                 else if(bInputType == 1) // key released
632                         mouseClicked -= (mouseClicked & S_MOUSE1);
633         }
634         else if(nPrimary == K_MOUSE2)
635         {
636                 if(bInputType == 0) // key pressed
637                         mouseClicked |= S_MOUSE2;
638                 else if(bInputType == 1) // key released
639                         mouseClicked -= (mouseClicked & S_MOUSE2);
640         }
641         else if(nPrimary == K_ESCAPE)
642         {
643                 if (bInputType == 1)
644                         return true;
645                 menu_enabled = 1;
646                 menu_enabled_time = time;
647                 localcmd("menu_showhudexit\n");
648         }
649         else if(nPrimary == K_BACKSPACE && hudShiftState & S_CTRL)
650         {
651                 if (bInputType == 1)
652                         return true;
653                 if (!menu_enabled)
654                         cvar_set("_hud_configure", "0");
655         }
656         else if(nPrimary == K_TAB && hudShiftState & S_CTRL) // select and highlight another panel
657         {
658                 if (bInputType == 1 || mouseClicked)
659                         return true;
660
661                 //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
662                 //of other panels then next consecutive ctrl-tab will select the highlighted panel too
663                 //(it should only after every other panel of the hud)
664                 //It's a minor bug anyway, we can live with it
665
666                 float starting_panel;
667                 float old_tab_panel = tab_panel;
668                 if (tab_panel == -1) //first press of TAB
669                 {
670                         if (highlightedPanel != -1)
671                                 HUD_Panel_UpdatePosSizeForId(highlightedPanel)
672                         else
673                                 panel_pos = '0 0 0';
674                         starting_panel = highlightedPanel; //can be -1, it means no starting panel
675                         tab_panel_pos = panel_pos; //to compute level
676                 }
677                 else
678                 {
679                         if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
680                                 reset_tab_panels();
681                         starting_panel = tab_panel;
682                 }
683                 tab_backward = (hudShiftState & S_SHIFT);
684
685                 float k, level, start_pos_x;
686                 vector candidate_pos;
687                 const float LEVELS_NUM = 4;
688                 float level_height = vid_conheight / LEVELS_NUM;
689 :find_tab_panel
690                 level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
691                 candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
692                 start_pos_x = tab_panel_pos_x;
693                 tab_panel = -1;
694                 k=0;
695                 while(++k)
696                 {
697                         for(i = 0; i < HUD_PANEL_NUM; ++i)
698                         {
699                                 if (i == tab_panels[i] || i == starting_panel)
700                                         continue;
701                                 HUD_Panel_UpdatePosSizeForId(i)
702                                 if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
703                                 if (  ( !tab_backward && panel_pos_x >= start_pos_x && (panel_pos_x < candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y <= candidate_pos_y)) )
704                                         || ( tab_backward && panel_pos_x <= start_pos_x && (panel_pos_x > candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y >= candidate_pos_y)) )  )
705                                 {
706                                         tab_panel = i;
707                                         tab_panel_pos = candidate_pos = panel_pos;
708                                 }
709                         }
710                         if (tab_panel != -1)
711                                 break;
712                         if (k == LEVELS_NUM) //tab_panel not found
713                         {
714                                 reset_tab_panels();
715                                 if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
716                                 {
717                                         tab_panel = -1;
718                                         return true;
719                                 }
720                                 starting_panel = old_tab_panel;
721                                 old_tab_panel = -2;
722                                 goto find_tab_panel; //u must find tab_panel!
723                         }
724                         if (!tab_backward)
725                         {
726                                 level = mod(level + level_height, vid_conheight);
727                                 start_pos_x = 0;
728                                 candidate_pos_x = vid_conwidth;
729                         }
730                         else
731                         {
732                                 level = mod(level - level_height, vid_conheight);
733                                 start_pos_x = vid_conwidth;
734                                 candidate_pos_x = 0;
735                         }
736                 }
737
738                 tab_panels[tab_panel] = tab_panel;
739         }
740         else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
741         {
742                 if (bInputType == 1 || mouseClicked)
743                         return true;
744
745                 if (highlightedPanel != -1)
746                 {
747                         HUD_Panel_GetName(highlightedPanel);
748                         cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
749                 }
750                 else
751                         cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
752         }
753         else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
754         {
755                 if (bInputType == 1 || mouseClicked)
756                         return true;
757
758                 if (highlightedPanel != -1)
759                 {
760                         HUD_Panel_UpdatePosSizeForId(highlightedPanel);
761                         panel_size_copied = panel_size;
762                         highlightedPanel_copied = highlightedPanel;
763                 }
764         }
765         else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
766         {
767                 if (bInputType == 1 || mouseClicked)
768                         return true;
769
770                 if (highlightedPanel_copied == -1 || highlightedPanel == -1)
771                         return true;
772
773                 HUD_Panel_UpdatePosSizeForId(highlightedPanel);
774
775                 // reduce size if it'd go beyond screen boundaries
776                 vector tmp_size = panel_size_copied;
777                 if (panel_pos_x + panel_size_copied_x > vid_conwidth)
778                         tmp_size_x = vid_conwidth - panel_pos_x;
779                 if (panel_pos_y + panel_size_copied_y > vid_conheight)
780                         tmp_size_y = vid_conheight - panel_pos_y;
781
782                 if (panel_size == tmp_size)
783                         return true;
784
785                 // backup first!
786                 panel_pos_backup = panel_pos;
787                 panel_size_backup = panel_size;
788                 highlightedPanel_backup = highlightedPanel;
789
790                 s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
791                 HUD_Panel_GetName(highlightedPanel);
792                 cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
793         }
794         else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
795         {
796                 if (bInputType == 1 || mouseClicked)
797                         return true;
798                 //restore previous values
799                 if (highlightedPanel_backup != -1)
800                 {
801                         HUD_Panel_GetName(highlightedPanel_backup);
802                         s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
803                         cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
804                         s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
805                         cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
806                         highlightedPanel_backup = -1;
807                 }
808         }
809         else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
810         {
811                 if (bInputType == 1)
812                 {
813                         pressed_key_time = 0;
814                         return true;
815                 }
816                 else if (pressed_key_time == 0)
817                         pressed_key_time = time;
818
819                 if (!mouseClicked)
820                         HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
821         }
822         else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
823         {
824                 if (bInputType == 1)
825                         return true;
826                 if (highlightedPanel != -1)
827                         HUD_Panel_EnableMenu();
828         }
829         else if(hit_con_bind)
830                 return false;
831
832         return true;
833 }
834
835 float HUD_Panel_Check_Mouse_Pos(float allow_move)
836 {
837         float i, j, border;
838
839         while(j < HUD_PANEL_NUM)
840         {
841                 i = panel_order[j];
842                 j += 1;
843
844                 HUD_Panel_UpdatePosSizeForId(i);
845
846                 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
847
848                 // move
849                 if(allow_move && mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
850                 {
851                         return 1;
852                 }
853                 // resize from topleft border
854                 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
855                 {
856                         return 2;
857                 }
858                 // resize from topright border
859                 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
860                 {
861                         return 3;
862                 }
863                 // resize from bottomleft border
864                 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
865                 {
866                         return 3;
867                 }
868                 // resize from bottomright border
869                 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
870                 {
871                         return 2;
872                 }
873         }
874         return 0;
875 }
876
877 // move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
878 void HUD_Panel_FirstInDrawQ(float id)
879 {
880         float i;
881         var float place = -1;
882         // find out where in the array our current id is, save into place
883         for(i = 0; i < HUD_PANEL_NUM; ++i)
884         {
885                 if(panel_order[i] == id)
886                 {
887                         place = i;
888                         break;
889                 }
890         }
891         // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
892         if(place == -1)
893                 place = HUD_PANEL_NUM - 1;
894
895         // move all ids up by one step in the array until "place"
896         for(i = place; i > 0; --i)
897         {
898                 panel_order[i] = panel_order[i-1];
899         }
900         // now save the new top id
901         panel_order[0] = id;
902         
903         // let's save them into the cvar by some strcat trickery
904         string s;
905         for(i = 0; i < HUD_PANEL_NUM; ++i)
906         {
907                 s = strcat(s, ftos(panel_order[i]), " ");
908         }
909         cvar_set("_hud_panelorder", s);
910         if(hud_panelorder_prev)
911                 strunzone(hud_panelorder_prev);
912         hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
913 }
914
915 void HUD_Panel_Highlight(float allow_move)
916 {
917         float i, j, border;
918
919         while(j < HUD_PANEL_NUM)
920         {
921                 i = panel_order[j];
922                 j += 1;
923
924                 HUD_Panel_UpdatePosSizeForId(i);
925
926                 border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
927
928                 // move
929                 if(allow_move && mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
930                 {
931                         highlightedPanel = i;
932                         HUD_Panel_FirstInDrawQ(i);
933                         highlightedAction = 1;
934                         panel_click_distance = mousepos - panel_pos;
935                         return;
936                 }
937                 // resize from topleft border
938                 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
939                 {
940                         highlightedPanel = i;
941                         HUD_Panel_FirstInDrawQ(i);
942                         highlightedAction = 2;
943                         resizeCorner = 1;
944                         panel_click_distance = mousepos - panel_pos;
945                         panel_click_resizeorigin = panel_pos + panel_size;
946                         return;
947                 }
948                 // resize from topright border
949                 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
950                 {
951                         highlightedPanel = i;
952                         HUD_Panel_FirstInDrawQ(i);
953                         highlightedAction = 2;
954                         resizeCorner = 2;
955                         panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
956                         panel_click_distance_y = mousepos_y - panel_pos_y;
957                         panel_click_resizeorigin = panel_pos + eY * panel_size_y;
958                         return;
959                 }
960                 // resize from bottomleft border
961                 else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
962                 {
963                         highlightedPanel = i;
964                         HUD_Panel_FirstInDrawQ(i);
965                         highlightedAction = 2;
966                         resizeCorner = 3;
967                         panel_click_distance_x = mousepos_x - panel_pos_x;
968                         panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
969                         panel_click_resizeorigin = panel_pos + eX * panel_size_x;
970                         return;
971                 }
972                 // resize from bottomright border
973                 else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
974                 {
975                         highlightedPanel = i;
976                         HUD_Panel_FirstInDrawQ(i);
977                         highlightedAction = 2;
978                         resizeCorner = 4;
979                         panel_click_distance = panel_size - mousepos + panel_pos;
980                         panel_click_resizeorigin = panel_pos;
981                         return;
982                 }
983         }
984         highlightedPanel = -1;
985         highlightedAction = 0;
986 }
987
988 void HUD_Panel_EnableMenu()
989 {
990         menu_enabled = 2;
991         menu_enabled_time = time;
992         HUD_Panel_GetName(highlightedPanel);
993         localcmd("menu_showhudoptions ", panel_name, "\n");
994 }
995 float mouse_over_panel;
996 void HUD_Panel_Mouse()
997 {
998         // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
999         if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
1000                 menu_enabled = 0;
1001
1002         /*
1003         print("menu_enabled: ", ftos(menu_enabled), "\n");
1004         print("Highlighted: ", ftos(highlightedPanel), "\n");
1005         print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
1006         */
1007
1008         // instantly hide the editor cursor if we open the HUDExit dialog
1009         // as hud_fade_alpha doesn't decrease to 0 in this case
1010         // TODO: find a way to fade the cursor out even in this case
1011         if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
1012                 return;
1013
1014         mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
1015
1016         mousepos_x = bound(0, mousepos_x, vid_conwidth);
1017         mousepos_y = bound(0, mousepos_y, vid_conheight);
1018
1019         if(mouseClicked)
1020         {
1021                 if(prevMouseClicked == 0)
1022                 {
1023                         if (tab_panel != -1)
1024                         {
1025                                 //stop ctrl-tab selection
1026                                 tab_panel = -1;
1027                                 reset_tab_panels();
1028                         }
1029                         HUD_Panel_Highlight(mouseClicked & S_MOUSE1); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
1030                                                                         // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
1031                         if (highlightedPanel != -1)
1032                         {
1033                                 highlightedPanel_initial_pos = panel_pos;
1034                                 highlightedPanel_initial_size = panel_size;
1035                         }
1036                         // doubleclick check
1037                         if ((mouseClicked & S_MOUSE1) && time - prevMouseClickedTime < 0.4 && highlightedPanel != -1 && prevMouseClickedPos == mousepos)
1038                         {
1039                                 mouseClicked = 0; // to prevent spam, I guess.
1040                                 HUD_Panel_EnableMenu();
1041                         }
1042                         else
1043                         {
1044                                 if (mouseClicked & S_MOUSE1)
1045                                 {
1046                                         prevMouseClickedTime = time;
1047                                         prevMouseClickedPos = mousepos;
1048                                 }
1049                                 mouse_over_panel = HUD_Panel_Check_Mouse_Pos(mouseClicked & S_MOUSE1);
1050                         }
1051                 }
1052                 else
1053                         HUD_Panel_UpdatePosSizeForId(highlightedPanel);
1054
1055                 if (highlightedPanel != -1)
1056                 {
1057                         drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1058                         if (highlightedPanel_initial_pos != panel_pos || highlightedPanel_initial_size != panel_size)
1059                         {
1060                                 hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
1061                                 // backup!
1062                                 panel_pos_backup = highlightedPanel_initial_pos;
1063                                 panel_size_backup = highlightedPanel_initial_size;
1064                                 highlightedPanel_backup = highlightedPanel;
1065                         }
1066                         else
1067                                 // in case the clicked panel is inside another panel and we aren't
1068                                 // moving it, avoid the immediate "fix" of its position/size
1069                                 // (often unwanted and hateful) by disabling collisions check
1070                                 hud_configure_checkcollisions = false;
1071                 }
1072
1073                 if(highlightedAction == 1)
1074                         HUD_Panel_SetPos(mousepos - panel_click_distance);
1075                 else if(highlightedAction == 2)
1076                 {
1077                         vector mySize;
1078                         if(resizeCorner == 1) {
1079                                 mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
1080                                 mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
1081                         } else if(resizeCorner == 2) {
1082                                 mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
1083                                 mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
1084                         } else if(resizeCorner == 3) {
1085                                 mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
1086                                 mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
1087                         } else { // resizeCorner == 4
1088                                 mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
1089                                 mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
1090                         }
1091                         HUD_Panel_SetPosSize(mySize);
1092                 }
1093         }
1094         else
1095         {
1096                 if(menu_enabled == 2)
1097                         mouse_over_panel = 0;
1098                 else
1099                         mouse_over_panel = HUD_Panel_Check_Mouse_Pos(TRUE);
1100                 if (mouse_over_panel && tab_panel == -1)
1101                         drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL);
1102         }
1103         // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel
1104         const vector cursorsize = '32 32 0';
1105
1106         if(!mouse_over_panel)
1107                 drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1108         else if(mouse_over_panel == 1)
1109                 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1110         else if(mouse_over_panel == 2)
1111                 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1112         else
1113                 drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
1114
1115         prevMouseClicked = mouseClicked;
1116 }
1117
1118 const float hlBorderSize = 4;
1119 const string hlBorder = "gfx/hud/default/border_highlighted";
1120 const string hlBorder2 = "gfx/hud/default/border_highlighted2";
1121 void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
1122 {
1123         drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
1124         drawpic_tiled(panel_pos - '1 1 0' * myBorder, hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1125         drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * (panel_size_y + 2 * myBorder - hlBorderSize), hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1126         drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize, hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1127         drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize + eX * (panel_size_x + 2 * myBorder - hlBorderSize), hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
1128 }