From c40d8b01724060b35b50694de9e75483075c3e35 Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 20 Jun 2010 21:35:34 +0200 Subject: [PATCH] Shortcuts with arrow keys in conf. mode: - 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 | 85 ++++++++++++++++++++++++++++++++++++++++++++- qcsrc/client/hud.qh | 1 + 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 0345dd519..00315aebc 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -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; } diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index e6d73eb09..16bbdfaeb 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -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; -- 2.39.2