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