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