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