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