]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
fade out the visible highlight when doubleclicking panel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index b4cf9b8bfbae4499c2fa8ecdc4abf9a50a6ba60c..4f8ce3572cf00aa2292e3e4fb07e04dbcd101dfd 100644 (file)
@@ -14,6 +14,13 @@ Misc HUD functions
 //   1/4 height: bottom part
 void draw_BorderPicture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha, vector theBorderSize)
 {
+       if (theBorderSize_x <= 0 && theBorderSize_y <= 0) // no border
+       {
+               // draw only the central part
+               drawsubpic(theOrigin, theSize, pic, '0.25 0.25 0', '0.5 0.5 0', theColor, theAlpha, 0);
+               return;
+       }
+
        vector dX, dY;
        vector width, height;
        vector bW, bH;
@@ -527,27 +534,30 @@ void HUD_Panel_ExportCfg(string cfgname)
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_border \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_border")), "\"", "\n"));
                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_bg_padding \"", cvar_string(strcat("hud_", HUD_Panel_GetName(i), "_bg_padding")), "\"", "\n"));
                        switch(i) {
-                               case 0:
+                               case HUD_PANEL_WEAPONICONS:
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_accuracy_yellow ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_accuracy_yellow"))), "\n"));
                                        break;
-                               case 1:
+                               case HUD_PANEL_INVENTORY:
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_onlycurrent ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_onlycurrent"))), "\n"));
+                                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_iconalign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
                                        break;
-                               case 2:
+                               case HUD_PANEL_POWERUPS:
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
-                                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
+                                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_iconalign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
+                                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_baralign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
                                        break;
-                               case 3:
+                               case HUD_PANEL_HEALTHARMOR:
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
-                                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_mirror ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
+                                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_iconalign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
+                                       fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_baralign ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_mirror"))), "\n"));
                                        break;
-                               case 4:
+                               case HUD_PANEL_NOTIFY:
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_flip ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_flip"))), "\n"));
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_info_top ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_info_top"))), "\n"));
                                        break;
-                               case 6:
+                               case HUD_PANEL_RADAR:
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_foreground_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_foreground_alpha"))), "\n"));
-                               case 9:
+                               case HUD_PANEL_VOTE:
                                        fputs(fh, strcat("seta hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha ", ftos(cvar(strcat("hud_", HUD_Panel_GetName(i), "_alreadyvoted_alpha"))), "\n"));
                                        break;
                        }
@@ -641,7 +651,7 @@ vector HUD_Panel_GetColor(float id)
 
        // fetch per-panel color
        if(teamplay && cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")) != "") {
-               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               f = stof(getplayerkey(player_localentnum - 1, "colors"));
                color = vtos(colormapPaletteColor(mod(f, 16), 1) * cvar(strcat("hud_", HUD_Panel_GetName(id), "_bg_color_team")));
        }
        else
@@ -652,24 +662,24 @@ vector HUD_Panel_GetColor(float id)
                color = cvar_string("hud_bg_color");
                color_vec = stov(color);
                if(teamplay && cvar(strcat("hud_bg_color_team"))) {
-                       f = stof(getplayerkey(self.sv_entnum, "colors"));
+                       f = stof(getplayerkey(player_localentnum - 1, "colors"));
                        color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_bg_color_team");
                }
                else if(color == "shirt") {
-                       f = stof(getplayerkey(self.sv_entnum, "colors"));
+                       f = stof(getplayerkey(player_localentnum - 1, "colors"));
                        color_vec = colormapPaletteColor(floor(f / 16), 0);
                }
                else if(color == "pants") {
-                       f = stof(getplayerkey(self.sv_entnum, "colors"));
+                       f = stof(getplayerkey(player_localentnum - 1, "colors"));
                        color_vec = colormapPaletteColor(mod(f, 16), 1);
                }
        }
        else if(color == "shirt") {
-               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               f = stof(getplayerkey(player_localentnum - 1, "colors"));
                color_vec = colormapPaletteColor(floor(f / 16), 0);
        }
        else if(color == "pants") {
-               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               f = stof(getplayerkey(player_localentnum - 1, "colors"));
                color_vec = colormapPaletteColor(mod(f, 16), 1);
        }
        return color_vec;
@@ -683,15 +693,15 @@ vector HUD_Panel_Dock_GetColor(void)
        color = cvar_string("hud_dock_color");
        color_vec = stov(color);
        if(teamplay && cvar(strcat("hud_dock_color_team"))) {
-               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               f = stof(getplayerkey(player_localentnum - 1, "colors"));
                color_vec = colormapPaletteColor(mod(f, 16), 1) * cvar("hud_dock_color_team");
        }
        else if(color == "shirt") {
-               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               f = stof(getplayerkey(player_localentnum - 1, "colors"));
                color_vec = colormapPaletteColor(floor(f / 16), 0);
        }
        else if(color == "pants") {
-               f = stof(getplayerkey(self.sv_entnum, "colors"));
+               f = stof(getplayerkey(player_localentnum - 1, "colors"));
                color_vec = colormapPaletteColor(mod(f, 16), 1);
        }
        return color_vec;
@@ -764,7 +774,7 @@ void HUD_Panel_DrawBg(float id, vector pos, vector mySize, float alpha)
        if(bg != "0")
        {
                float border;
-               border = max(0.0000001, HUD_Panel_GetBorder(id)); // draw_BorderPicture does not like border = 0
+               border = HUD_Panel_GetBorder(id);
 
                vector color;
                color = HUD_Panel_GetColor(id);
@@ -776,6 +786,9 @@ void HUD_Panel_DrawBg(float id, vector pos, vector mySize, float alpha)
 
                draw_BorderPicture(pos - '1 1 0' * border, strcat("gfx/hud/", cvar_string("hud_skin"), "/", bg), mySize + '1 1 0' * 2 * border, color, alpha, '1 1 0' * (border/BORDER_MULTIPLIER));
        }
+
+       if(highlightedPanel_prev == id)
+               drawfill(pos - '1 1 0' * border, mySize + '1 1 0' * 2 * border, '1 1 1', .1 * (1 - cvar("_menu_alpha")), DRAWFLAG_ADDITIVE);
 }
 
 void HUD_Panel_DrawProgressBar(vector pos, float vertical, vector mySize, vector color, float alpha, float drawflag)
@@ -884,7 +897,7 @@ void HUD_Panel_SetPos(float id, vector pos)
        vector mySize;
        mySize = HUD_Panel_GetSize(id);
 
-       if(cvar("hud_configure_checkcollisions"))
+       if(hud_configure_checkcollisions)
                pos = HUD_Panel_CheckMove(id, pos, mySize);
 
        pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
@@ -910,7 +923,10 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
        vector targPos;
        vector targSize;
        vector targEndPos;
+
        vector dist;
+       float ratio;
+       ratio = mySize_x/mySize_y;
 
        for (i = 0; i < HUD_PANEL_NUM; ++i) {
                if(i == id || !HUD_Panel_CheckActive(i))
@@ -922,7 +938,7 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
                targEndPos = targPos + targSize;
 
                // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
-               if(resizeorigin_x > targPos_x && resizeorigin_x < targPos_x + targSize_x && resizeorigin_y > targPos_y && resizeorigin_y < targPos_y + targSize_y)
+               if(resizeorigin_x > targPos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > targPos_y && resizeorigin_y < targEndPos_y)
                        continue;
 
                if (resizeCorner == 1)
@@ -945,7 +961,7 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
                        // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
                        dist_x = resizeorigin_x - targEndPos_x;
                        dist_y = resizeorigin_y - targEndPos_y;
-                       if (dist_y < 0)
+                       if (dist_y < 0 || dist_x / dist_y > ratio)
                                mySize_x = min(mySize_x, dist_x);
                        else
                                mySize_y = min(mySize_y, dist_y);
@@ -963,7 +979,7 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
 
                        dist_x = targPos_x - resizeorigin_x;
                        dist_y = resizeorigin_y - targEndPos_y;
-                       if (dist_y < 0)
+                       if (dist_y < 0 || dist_x / dist_y > ratio)
                                mySize_x = min(mySize_x, dist_x);
                        else
                                mySize_y = min(mySize_y, dist_y);
@@ -981,7 +997,7 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
 
                        dist_x = resizeorigin_x - targEndPos_x;
                        dist_y = targPos_y - resizeorigin_y;
-                       if (dist_y < 0)
+                       if (dist_y < 0 || dist_x / dist_y > ratio)
                                mySize_x = min(mySize_x, dist_x);
                        else
                                mySize_y = min(mySize_y, dist_y);
@@ -999,7 +1015,7 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
 
                        dist_x = targPos_x - resizeorigin_x;
                        dist_y = targPos_y - resizeorigin_y;
-                       if (dist_y < 0)
+                       if (dist_y < 0 || dist_x / dist_y > ratio)
                                mySize_x = min(mySize_x, dist_x);
                        else
                                mySize_y = min(mySize_y, dist_y);
@@ -1011,31 +1027,17 @@ vector HUD_Panel_CheckResize(float id, vector mySize, vector resizeorigin) {
        return mySize;
 }
 
-void HUD_Panel_SetPosSize(float id)
+void HUD_Panel_SetPosSize(float id, vector mySize)
 {
        vector resizeorigin;
        resizeorigin = panel_click_resizeorigin;
-       vector mySize, myPos;
-
-       if(resizeCorner == 1) {
-               mySize_x = resizeorigin_x - (mousepos_x - panel_click_distance_x);
-               mySize_y = resizeorigin_y - (mousepos_y - panel_click_distance_y);
-       } else if(resizeCorner == 2) {          
-               mySize_x = mousepos_x + panel_click_distance_x - resizeorigin_x;
-               mySize_y = panel_click_distance_y + resizeorigin_y - mousepos_y;
-       } else if(resizeCorner == 3) {
-               mySize_x = resizeorigin_x + panel_click_distance_x - mousepos_x;
-               mySize_y = mousepos_y + panel_click_distance_y - resizeorigin_y;
-       } else { // resizeCorner == 4
-               mySize_x = mousepos_x - (resizeorigin_x - panel_click_distance_x);
-               mySize_y = mousepos_y - (resizeorigin_y - panel_click_distance_y);
-       }
+       vector myPos;
 
        // minimum panel size cap
        mySize_x = max(0.025 * vid_conwidth, mySize_x);
        mySize_y = max(0.025 * vid_conheight, mySize_y);
 
-       if(id == 12) // 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.
+       if(id == 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.
        {
                mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
                mySize_y = max(2 * cvar("con_chatsize") + 2 * HUD_Panel_GetPadding(id), mySize_y);
@@ -1081,10 +1083,8 @@ void HUD_Panel_SetPosSize(float id)
                mySize_y = floor((mySize_y/vid_conheight)/bound(0.005, cvar("hud_configure_grid_y"), 0.2) + 0.5) * bound(0.005, cvar("hud_configure_grid_y"), 0.2) * vid_conheight;
        }
 
-       if(cvar("hud_configure_checkcollisions"))
-       {
+       if(hud_configure_checkcollisions)
                mySize = HUD_Panel_CheckResize(id, mySize, resizeorigin);
-       }
 
        // 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)
        mySize_x = max(0.025 * vid_conwidth, mySize_x);
@@ -1106,7 +1106,6 @@ void HUD_Panel_SetPosSize(float id)
        }
 
        if(cvar("hud_configure_checkcollisions_debug"))
-       if(cvar("hud_configure_checkcollisions"))
                drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
 
        string s;
@@ -1124,6 +1123,81 @@ vector prevMouseClickedPos; // pos during previous mouse click, to check for dou
 
 float menu_enabled;
 float menu_enabled_time;
+float pressed_key_time;
+void HUD_Panel_Arrow_Action(float nPrimary)
+{
+       if (highlightedPanel_prev == -1 || mouseClicked)
+               return;
+
+       hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
+
+       float step;
+       if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
+               step = vid_conheight;
+       else
+               step = vid_conwidth;
+       if (hudShiftState & S_SHIFT)
+               step = (step / 256); // more precision
+       else
+               step = (step / 64) * (1 + 2 * (time - pressed_key_time));
+
+       highlightedPanel = highlightedPanel_prev;
+
+       if (hudShiftState & S_ALT) // resize
+       {
+               highlightedAction = 1;
+               if(nPrimary == K_UPARROW)
+                       resizeCorner = 1;
+               else if(nPrimary == K_RIGHTARROW)
+                       resizeCorner = 2;
+               else if(nPrimary == K_LEFTARROW)
+                       resizeCorner = 3;
+               else // if(nPrimary == K_DOWNARROW)
+                       resizeCorner = 4;
+
+               // ctrl+arrow reduces the size, instead of increasing it
+               // Note that ctrl disables collisions check too, but it's fine
+               // since we don't collide with anything reducing the size
+               if (hudShiftState & S_CTRL) {
+                       step = -step;
+                       resizeCorner = 5 - resizeCorner;
+               }
+
+               vector mySize;
+               mySize = HUD_Panel_GetSize(highlightedPanel);
+               panel_click_resizeorigin = HUD_Panel_GetPos(highlightedPanel);
+               if(resizeCorner == 1) {
+                       panel_click_resizeorigin += mySize;
+                       mySize_y += step;
+               } else if(resizeCorner == 2) {
+                       panel_click_resizeorigin_y += mySize_y;
+                       mySize_x += step;
+               } else if(resizeCorner == 3) {
+                       panel_click_resizeorigin_x += mySize_x;
+                       mySize_x += step;
+               } else { // resizeCorner == 4
+                       mySize_y += step;
+               }
+               HUD_Panel_SetPosSize(highlightedPanel, mySize);
+       }
+       else // move
+       {
+               highlightedAction = 2;
+               vector pos;
+               pos = HUD_Panel_GetPos(highlightedPanel);
+               if(nPrimary == K_UPARROW)
+                       pos_y -= step;
+               else if(nPrimary == K_DOWNARROW)
+                       pos_y += step;
+               else if(nPrimary == K_LEFTARROW)
+                       pos_x -= step;
+               else // if(nPrimary == K_RIGHTARROW)
+                       pos_x += step;
+
+               HUD_Panel_SetPos(highlightedPanel, pos);
+       }
+}
+
 float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
 {
        if(!hud_configure)
@@ -1142,6 +1216,17 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
                        hit_con_bind = 1;
        }
 
+       if(bInputType == 0) {
+               if(nPrimary == K_ALT) hudShiftState |= S_ALT;
+               if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
+               if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
+       }
+       else if(bInputType == 1) {
+               if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
+               if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
+               if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
+       }
+
        if(nPrimary == K_MOUSE1)
        {
                if(bInputType == 0) { // key pressed
@@ -1155,18 +1240,96 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
        }
        else if(nPrimary == K_ESCAPE)
        {
+               if (bInputType == 1)
+                       return true;
                disable_menu_alphacheck = 1;
                menu_enabled = 1;
                menu_enabled_time = time;
                localcmd("menu_showhudexit\n");
        }
+       else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
+       {
+               if (bInputType == 1)
+               {
+                       pressed_key_time = 0;
+                       return true;
+               }
+               else if (pressed_key_time == 0)
+                       pressed_key_time = time;
 
+               HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
+       }
        else if(hit_con_bind)
                return false;
 
        return true; // Suppress ALL other input
 }
 
+void HUD_Panel_Highlight()
+{
+       float i, border;
+       vector panelPos;
+       vector panelSize;
+
+       for(i = 0; i < HUD_PANEL_NUM; ++i)
+       {
+               panelPos = HUD_Panel_GetPos(i);
+               panelSize = HUD_Panel_GetSize(i);
+               border = HUD_Panel_GetBorder(i);
+
+               // move
+               if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
+               {
+                       highlightedPanel = i;
+                       highlightedAction = 1;
+                       panel_click_distance = mousepos - panelPos;
+                       return;
+               }
+               // resize from topleft border
+               else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
+               {
+                       highlightedPanel = i;
+                       highlightedAction = 2;
+                       resizeCorner = 1;
+                       panel_click_distance = mousepos - panelPos;
+                       panel_click_resizeorigin = panelPos + panelSize;
+                       return;
+               }
+               // resize from topright border
+               else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
+               {
+                       highlightedPanel = i;
+                       highlightedAction = 2;
+                       resizeCorner = 2;
+                       panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
+                       panel_click_distance_y = mousepos_y - panelPos_y;
+                       panel_click_resizeorigin = panelPos + eY * panelSize_y;
+                       return;
+               }
+               // resize from bottomleft border
+               else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
+               {
+                       highlightedPanel = i;
+                       highlightedAction = 2;
+                       resizeCorner = 3;
+                       panel_click_distance_x = mousepos_x - panelPos_x;
+                       panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
+                       panel_click_resizeorigin = panelPos + eX * panelSize_x;
+                       return;
+               }
+               // resize from bottomright border
+               else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
+               {
+                       highlightedPanel = i;
+                       highlightedAction = 2;
+                       resizeCorner = 4;
+                       panel_click_distance = panelSize - mousepos + panelPos;
+                       panel_click_resizeorigin = panelPos;
+                       return;
+               }
+       }
+}
+
 void HUD_Panel_Mouse()
 {
        // 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
@@ -1181,7 +1344,8 @@ void HUD_Panel_Mouse()
        print("Menu alpha: ", cvar_string("_menu_alpha"), "\n");
        */
 
-       if(mouseClicked == 0 && disable_menu_alphacheck != 2) { // don't reset these variables in disable_menu_alphacheck mode 2!
+       if(mouseClicked == 0 && disable_menu_alphacheck != 2 && highlightedPanel >= 0) { // don't reset these variables in disable_menu_alphacheck mode 2!
+               highlightedPanel_prev = highlightedPanel;
                highlightedPanel = -1;
                highlightedAction = 0;
        }
@@ -1195,86 +1359,30 @@ void HUD_Panel_Mouse()
 
        if(mouseClicked)
        {
-               float i, border;
-               vector panelPos;
-               vector panelSize;
-
-               for(i = 0; i < HUD_PANEL_NUM; ++i)
-               {
-                       panelPos = HUD_Panel_GetPos(i);
-                       panelSize = HUD_Panel_GetSize(i);
-                       border = HUD_Panel_GetBorder(i);
-                       if(prevMouseClicked == 0) {
-                               // move
-                               if(mousepos_x >= panelPos_x && mousepos_y >= panelPos_y && mousepos_x <= panelPos_x + panelSize_x && mousepos_y <= panelPos_y + panelSize_y)
-                               {
-                                       highlightedPanel = i;
-                                       highlightedAction = 1;
-                               }
-                               // resize from topleft border
-                               else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
-                               {
-                                       highlightedPanel = i;
-                                       highlightedAction = 2;
-                                       resizeCorner = 1;
-                               }
-                               // resize from topright border
-                               else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y - border && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + 0.5 * panelSize_y)
-                               {
-                                       highlightedPanel = i;
-                                       highlightedAction = 2;
-                                       resizeCorner = 2;
-                               }
-                               // resize from bottomleft border
-                               else if(mousepos_x >= panelPos_x - border && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + 0.5 * panelSize_x && mousepos_y <= panelPos_y + panelSize_y + border)
-                               {
-                                       highlightedPanel = i;
-                                       highlightedAction = 2;
-                                       resizeCorner = 3;
-                               }
-                               // resize from bottomright border
-                               else if(mousepos_x >= panelPos_x + 0.5 * panelSize_x && mousepos_y >= panelPos_y + 0.5 * panelSize_y && mousepos_x <= panelPos_x + panelSize_x + border && mousepos_y <= panelPos_y + panelSize_y + border)
-                               {
-                                       highlightedPanel = i;
-                                       highlightedAction = 2;
-                                       resizeCorner = 4;
-                               }
-                       }
-
-                       if(highlightedPanel == i)
-                       {
-                               if(prevMouseClicked == 0)
-                               {
-                                       if(highlightedAction == 1)
-                                               panel_click_distance = mousepos - panelPos;
-                                       else if(highlightedAction == 2)
-                                       {
-                                               if(resizeCorner == 1) {
-                                                       panel_click_distance = mousepos - panelPos;
-                                                       panel_click_resizeorigin = panelPos + panelSize;
-                                               } else if(resizeCorner == 2) {
-                                                       panel_click_distance_x = panelSize_x - mousepos_x + panelPos_x;
-                                                       panel_click_distance_y = mousepos_y - panelPos_y;
-                                                       panel_click_resizeorigin = panelPos + eY * panelSize_y;
-                                               } else if(resizeCorner == 3) {
-                                                       panel_click_distance_x = mousepos_x - panelPos_x;
-                                                       panel_click_distance_y = panelSize_y - mousepos_y + panelPos_y;
-                                                       panel_click_resizeorigin = panelPos + eX * panelSize_x;
-                                               } else if(resizeCorner == 4) {
-                                                       panel_click_distance = panelSize - mousepos + panelPos;
-                                                       panel_click_resizeorigin = panelPos;
-                                               }
-                                       }       
-                               }
+               if(prevMouseClicked == 0)
+                       HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
 
-                               if(cvar("hud_configure_checkcollisions_debug"))
-                                       drawfill(panelPos, panelSize, '1 0 0', .3, DRAWFLAG_NORMAL);
+               hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
 
-                               if(highlightedAction == 1)
-                                       HUD_Panel_SetPos(i, mousepos - panel_click_distance);
-                               else if(highlightedAction == 2)
-                                       HUD_Panel_SetPosSize(i);
+               if(highlightedAction == 1)
+                       HUD_Panel_SetPos(highlightedPanel, mousepos - panel_click_distance);
+               else if(highlightedAction == 2)
+               {
+                       vector mySize;
+                       if(resizeCorner == 1) {
+                               mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
+                               mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
+                       } else if(resizeCorner == 2) {
+                               mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
+                               mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
+                       } else if(resizeCorner == 3) {
+                               mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
+                               mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
+                       } else { // resizeCorner == 4
+                               mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
+                               mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
                        }
+                       HUD_Panel_SetPosSize(highlightedPanel, mySize);
                }
 
                // doubleclick check
@@ -3329,6 +3437,24 @@ void HUD_RaceTimer (void) {
                mySize -= '2 2 0' * padding;
        }
 
+       // always force 2:1 aspect
+       vector newSize;
+       if(mySize_x/mySize_y > 2)
+       {
+               newSize_x = 2 * mySize_y;
+               newSize_y = mySize_y;
+
+               pos_x = pos_x + (mySize_x - newSize_x) / 2;
+       }
+       else
+       {
+               newSize_y = 1/2 * mySize_x;
+               newSize_x = mySize_x;
+
+               pos_y = pos_y + (mySize_y - newSize_y) / 2;
+       }
+       mySize = newSize;
+
        drawfont = hud_bigfont;
        float a, t;
        string s, forcetime;
@@ -3497,14 +3623,32 @@ void HUD_VoteWindow(void)
                mySize -= '2 2 0' * padding;
        }
 
+       // always force 2:1 aspect
+       vector newSize;
+       if(mySize_x/mySize_y > 2)
+       {
+               newSize_x = 2 * mySize_y;
+               newSize_y = mySize_y;
+
+               pos_x = pos_x + (mySize_x - newSize_x) / 2;
+       }
+       else
+       {
+               newSize_y = 1/2 * mySize_x;
+               newSize_x = mySize_x;
+
+               pos_y = pos_y + (mySize_y - newSize_y) / 2;
+       }
+       mySize = newSize;
+
        drawpic_skin(pos, "voteprogress_back", mySize, '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
 
        s = "A vote has been called for: ";
-       drawstring(pos + '0.5 0 0' * mySize_x + '0 0.1 0' * mySize_y - eX * stringwidth(s, FALSE, '1 1 0' * 0.5 * mySize_y*(1/5)), s, '1 1 0' * mySize_y*(1/5), '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
-       s = textShortenToWidth(vote_called_vote, mySize_x * 0.96, '1 1 0' * mySize_y*(1/5), stringwidth_colors); // TODO: broken?
+       drawstring_aspect(pos + eY * (1/12) * mySize_y, s, eX * mySize_x + eY * (3/12) * mySize_y, mySize_y*(3/12), '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
+       s = textShortenToWidth(vote_called_vote, mySize_x, '1 1 0' * mySize_y * (3/12), stringwidth_colors); // TODO: broken?
        if(hud_configure)
                s = "Configure the HUD";
-       drawcolorcodedstring(pos + '0.52 0 0' * mySize_x + '0 0.3 0' * mySize_y - eX * stringwidth(s, FALSE, '1 1 0' * 0.5 * mySize_y*(1/6)), s, '1 1 0' * mySize_y*(1/6), a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
+       drawstring_aspect(pos + eY * (4/12) * mySize_y, s, eX * mySize_x + eY * (2/12) * mySize_y, mySize_y*(2/12), '1 1 1', a * HUD_Panel_GetFgAlpha(id), DRAWFLAG_NORMAL);
 
        // print the yes/no counts
        s = strcat("Yes: ", ftos(vote_yescount));