- if(barflip)
- drawsetcliparea(pos_x, pos_y + mySize_y * (1 - x), mySize_x, mySize_y * x);
- else
- drawsetcliparea(pos_x, pos_y, mySize_x, mySize_y * x);
- } else {
- pic = strcat(hud_skin_path, "/", pic);
- if(precache_pic(pic) == "") {
- pic = "gfx/hud/default/statusbar";
- }
-
- if(barflip)
- drawsetcliparea(pos_x + mySize_x * (1 - x), pos_y, mySize_x * x, mySize_y);
- else
- drawsetcliparea(pos_x, pos_y, mySize_x * x, mySize_y);
- }
-
- drawpic(pos, pic, mySize, color, alpha, drawflag);
- drawresetcliparea();
-}
-
-void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alpha, float drawflag)
-{
- if(!alpha)
- return;
-
- string pic;
- pic = strcat(hud_skin_path, "/num_leading");
- if(precache_pic(pic) == "") {
- pic = "gfx/hud/default/num_leading";
- }
-
- drawsubpic(pos, eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0 0 0', '0.25 1 0', color, alpha, drawflag);
- if(mySize_x/mySize_y > 2)
- drawsubpic(pos + eX * mySize_y, eX * (mySize_x - 2 * mySize_y) + eY * mySize_y, pic, '0.25 0 0', '0.5 1 0', color, alpha, drawflag);
- drawsubpic(pos + eX * mySize_x - eX * min(mySize_x * 0.5, mySize_y), eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0.75 0 0', '0.25 1 0', color, alpha, drawflag);
-}
-
-// check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
-vector HUD_Panel_CheckMove(vector myPos, vector mySize)
-{
- float i;
-
- vector myTarget;
- myTarget = myPos;
-
- vector myCenter;
- vector targCenter;
- myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
- targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
-
- for (i = 0; i < HUD_PANEL_NUM; ++i) {
- if(i == highlightedPanel || !panel_enabled)
- continue;
-
- HUD_Panel_UpdatePosSizeForId(i);
-
- panel_pos -= '1 1 0' * panel_bg_border;
- panel_size += '2 2 0' * panel_bg_border;
-
- if(myPos_y + mySize_y < panel_pos_y)
- continue;
- if(myPos_y > panel_pos_y + panel_size_y)
- continue;
-
- if(myPos_x + mySize_x < panel_pos_x)
- continue;
- if(myPos_x > panel_pos_x + panel_size_x)
- continue;
-
- // OK, there IS a collision.
-
- myCenter_x = myPos_x + 0.5 * mySize_x;
- myCenter_y = myPos_y + 0.5 * mySize_y;
-
- targCenter_x = panel_pos_x + 0.5 * panel_size_x;
- targCenter_y = panel_pos_y + 0.5 * panel_size_y;
-
- if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
- {
- if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
- myTarget_x = panel_pos_x - mySize_x;
- else // push it upwards
- myTarget_y = panel_pos_y - mySize_y;
- }
- else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
- {
- if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
- myTarget_x = panel_pos_x + panel_size_x;
- else // push it upwards
- myTarget_y = panel_pos_y - mySize_y;
- }
- else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
- {
- if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
- myTarget_x = panel_pos_x - mySize_x;
- else // push it downwards
- myTarget_y = panel_pos_y + panel_size_y;
- }
- else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
- {
- if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
- myTarget_x = panel_pos_x + panel_size_x;
- else // push it downwards
- myTarget_y = panel_pos_y + panel_size_y;
- }
- //if(cvar("hud_configure_checkcollisions_debug"))
- //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
- }
-
- return myTarget;
-}
-
-void HUD_Panel_SetPos(vector pos)
-{
- HUD_Panel_UpdatePosSizeForId(highlightedPanel);
- vector mySize;
- mySize = panel_size;
-
- //if(cvar("hud_configure_checkcollisions_debug"))
- //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
-
- if(autocvar_hud_configure_grid)
- {
- pos_x = floor((pos_x/vid_conwidth)/bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
- pos_y = floor((pos_y/vid_conheight)/bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
- }
-
- if(hud_configure_checkcollisions)
- pos = HUD_Panel_CheckMove(pos, mySize);
-
- pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
- pos_y = bound(0, pos_y, vid_conheight - mySize_y);
-
- string s;
- s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
-
- HUD_Panel_GetName(highlightedPanel);
- cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
-}
-
-// check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
-vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
- float i;
-
- vector targEndPos;
-
- float dist_x, dist_y;
- float ratio;
- ratio = mySize_x/mySize_y;
-
- for (i = 0; i < HUD_PANEL_NUM; ++i) {
- if(i == highlightedPanel || !panel_enabled)
- continue;
-
- HUD_Panel_UpdatePosSizeForId(i);
-
- panel_pos -= '1 1 0' * panel_bg_border;
- panel_size += '2 2 0' * panel_bg_border;
-
- targEndPos = panel_pos + panel_size;
-
- // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
- if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
- continue;
-
- if (resizeCorner == 1)
- {
- // check if this panel is on our way
- if (resizeorigin_x <= panel_pos_x)
- continue;
- if (resizeorigin_y <= panel_pos_y)
- continue;
- if (targEndPos_x <= resizeorigin_x - mySize_x)
- continue;
- if (targEndPos_y <= resizeorigin_y - mySize_y)
- continue;
-
- // there is a collision:
- // detect which side of the panel we are facing is actually limiting the resizing
- // (which side the resize direction finds for first) and reduce the size up to there
- //
- // dist is the distance between resizeorigin and the "analogous" point of the panel
- // 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 || dist_x / dist_y > ratio)
- mySize_x = min(mySize_x, dist_x);
- else
- mySize_y = min(mySize_y, dist_y);
- }
- else if (resizeCorner == 2)
- {
- if (resizeorigin_x >= targEndPos_x)
- continue;
- if (resizeorigin_y <= panel_pos_y)
- continue;
- if (panel_pos_x >= resizeorigin_x + mySize_x)
- continue;
- if (targEndPos_y <= resizeorigin_y - mySize_y)
- continue;
-
- dist_x = panel_pos_x - resizeorigin_x;
- dist_y = resizeorigin_y - targEndPos_y;
- if (dist_y <= 0 || dist_x / dist_y > ratio)
- mySize_x = min(mySize_x, dist_x);
- else
- mySize_y = min(mySize_y, dist_y);
- }
- else if (resizeCorner == 3)
- {
- if (resizeorigin_x <= panel_pos_x)
- continue;
- if (resizeorigin_y >= targEndPos_y)
- continue;
- if (targEndPos_x <= resizeorigin_x - mySize_x)
- continue;
- if (panel_pos_y >= resizeorigin_y + mySize_y)
- continue;
-
- dist_x = resizeorigin_x - targEndPos_x;
- dist_y = panel_pos_y - resizeorigin_y;
- if (dist_y <= 0 || dist_x / dist_y > ratio)
- mySize_x = min(mySize_x, dist_x);
- else
- mySize_y = min(mySize_y, dist_y);
- }
- else if (resizeCorner == 4)
- {
- if (resizeorigin_x >= targEndPos_x)
- continue;
- if (resizeorigin_y >= targEndPos_y)
- continue;
- if (panel_pos_x >= resizeorigin_x + mySize_x)
- continue;
- if (panel_pos_y >= resizeorigin_y + mySize_y)
- continue;
-
- dist_x = panel_pos_x - resizeorigin_x;
- dist_y = panel_pos_y - resizeorigin_y;
- if (dist_y <= 0 || dist_x / dist_y > ratio)
- mySize_x = min(mySize_x, dist_x);
- else
- mySize_y = min(mySize_y, dist_y);
- }
- //if(cvar("hud_configure_checkcollisions_debug"))
- //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
- }
-
- return mySize;
-}
-
-void HUD_Panel_SetPosSize(vector mySize)
-{
- HUD_Panel_UpdatePosSizeForId(highlightedPanel);
- vector resizeorigin;
- resizeorigin = panel_click_resizeorigin;
- 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(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.
- {
- mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
- mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
- }
-
- // collision testing|
- // -----------------+
-
- // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
- if(resizeCorner == 1) {
- myPos_x = resizeorigin_x - mySize_x;
- myPos_y = resizeorigin_y - mySize_y;
- } else if(resizeCorner == 2) {
- myPos_x = resizeorigin_x;
- myPos_y = resizeorigin_y - mySize_y;
- } else if(resizeCorner == 3) {
- myPos_x = resizeorigin_x - mySize_x;
- myPos_y = resizeorigin_y;
- } else { // resizeCorner == 4
- myPos_x = resizeorigin_x;
- myPos_y = resizeorigin_y;
- }
-
- // left/top screen edges
- if(myPos_x < 0)
- mySize_x = mySize_x + myPos_x;
- if(myPos_y < 0)
- mySize_y = mySize_y + myPos_y;
-
- // bottom/right screen edges
- if(myPos_x + mySize_x > vid_conwidth)
- mySize_x = vid_conwidth - myPos_x;
- if(myPos_y + mySize_y > vid_conheight)
- mySize_y = vid_conheight - myPos_y;
-
- //if(cvar("hud_configure_checkcollisions_debug"))
- //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
-
- // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
- if(autocvar_hud_configure_grid)
- {
- mySize_x = floor((mySize_x/vid_conwidth)/bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
- mySize_y = floor((mySize_y/vid_conheight)/bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) + 0.5) * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
- }
-
- if(hud_configure_checkcollisions)
- mySize = HUD_Panel_CheckResize(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);
- mySize_y = max(0.025 * vid_conheight, mySize_y);
-
- // do another pos check, as size might have changed by now
- if(resizeCorner == 1) {
- myPos_x = resizeorigin_x - mySize_x;
- myPos_y = resizeorigin_y - mySize_y;
- } else if(resizeCorner == 2) {
- myPos_x = resizeorigin_x;
- myPos_y = resizeorigin_y - mySize_y;
- } else if(resizeCorner == 3) {
- myPos_x = resizeorigin_x - mySize_x;
- myPos_y = resizeorigin_y;
- } else { // resizeCorner == 4
- myPos_x = resizeorigin_x;
- myPos_y = resizeorigin_y;
- }
-
- //if(cvar("hud_configure_checkcollisions_debug"))
- //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
-
- HUD_Panel_GetName(highlightedPanel);
- string s;
- s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
- cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
-
- s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
- cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
-}
-
-float mouseClicked;
-float prevMouseClicked; // previous state
-float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
-vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
-
-float pressed_key_time;
-void HUD_Panel_Arrow_Action(float nPrimary)
-{
- if (highlightedPanel_prev == -1 || mouseClicked)
- return;
-
- hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
-
- float step;
- if(autocvar_hud_configure_grid)
- {
- if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
- {
- if (hudShiftState & S_SHIFT)
- step = bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
- else
- step = 2 * bound(0.005, autocvar_hud_configure_grid_ysize, 0.2) * vid_conheight;
- }
- else
- {
- if (hudShiftState & S_SHIFT)
- step = bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
- else
- step = 2 * bound(0.005, autocvar_hud_configure_grid_xsize, 0.2) * vid_conwidth;
- }
- }
- else
- {
- 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;
-
- HUD_Panel_UpdatePosSizeForId(highlightedPanel);
-
- vector prev_pos, prev_size;
- prev_pos = panel_pos;
- prev_size = panel_size;
-
- 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 = panel_size;
- panel_click_resizeorigin = panel_pos;
- 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(mySize);
- }
- else // move
- {
- highlightedAction = 2;
- vector pos;
- pos = panel_pos;
- 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(pos);
- }
-
- HUD_Panel_UpdatePosSizeForId(highlightedPanel);
-
- if (prev_pos != panel_pos || prev_size != panel_size)
- {
- // backup!
- panel_pos_backup = prev_pos;
- panel_size_backup = prev_size;
- highlightedPanel_backup = highlightedPanel;
- }
-}
-
-float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
-{
- string s;
-
- if(!autocvar__hud_configure)
- return false;
-
- // allow console bind to work
- string con_keys;
- float keys;
- con_keys = findkeysforcommand("toggleconsole");
- keys = tokenize(con_keys);
-
- float hit_con_bind, i;
- for (i = 0; i < keys; ++i)
- {
- if(nPrimary == stof(argv(i)))
- 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
- mouseClicked = 1;
- return true;
- }
- else if(bInputType == 1) {// key released
- mouseClicked = 0;
- return true;
- }
- }
- else if(nPrimary == K_ESCAPE)
- {
- if (bInputType == 1)
- return true;
- menu_enabled = 1;
- menu_enabled_time = time;
- localcmd("menu_showhudexit\n");
- }
- else if(hudShiftState & S_CTRL)
- {
- if (mouseClicked)
- return true;
-
- if(nPrimary == K_SPACE) // enable/disable highlighted panel or dock