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