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