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