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