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