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