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