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