]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Shortcuts with arrow keys in conf. mode:
authorterencehill <piuntn@gmail.com>
Sun, 20 Jun 2010 19:35:34 +0000 (21:35 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 20 Jun 2010 19:35:34 +0000 (21:35 +0200)
- Arrow keys move the panel
- Alt+Arrow keys extend the size of the panel
- Ctrl+Alt+Arrow keys reduce the size of the panel
Panel must be first activated by clicking on it.

qcsrc/client/hud.qc
qcsrc/client/hud.qh

index 0345dd519b86f8ee4a0b2390c22d68fe627aaa0c..00315aebcd30cdefaa051f9a58a1a3a0f3ba884b 100644 (file)
@@ -1198,6 +1198,77 @@ void HUD_Panel_SetPosSize(float id, vector mySize)
        cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
 }
 
+float pressed_key_time;
+void HUD_Panel_Arrow_Action(float nPrimary)
+{
+       if (highlightedPanel_prev == -1)
+               return;
+
+       hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && cvar("hud_configure_checkcollisions"));
+
+       float step;
+       if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
+               step = vid_conheight / 64;
+       else
+               step = vid_conwidth / 64;
+
+       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 mouseClicked;
 float prevMouseClicked; // previous state
 float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
@@ -1254,7 +1325,18 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
                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;
 
@@ -1340,7 +1422,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;
        }
index e6d73eb09624793e447167a07c255a1ed9131b46..16bbdfaebf23003ee7e5bef699c6e91c91e4e1e4 100644 (file)
@@ -3,6 +3,7 @@ vector panel_click_distance; // mouse cursor distance from the top left corner o
 vector panel_click_resizeorigin; // coordinates for opposite point when resizing
 float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
 float highlightedPanel;
+float highlightedPanel_prev;
 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
 
 const float BORDER_MULTIPLIER = 0.25;