]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
start reworking the resizing code completely from scratch... dont try
authorFruitieX <rasse@rasse-lappy.localdomain>
Thu, 3 Jun 2010 15:16:27 +0000 (18:16 +0300)
committerFruitieX <rasse@rasse-lappy.localdomain>
Thu, 3 Jun 2010 15:16:27 +0000 (18:16 +0300)
any other corner than top left right now :)

defaultXonotic.cfg
qcsrc/client/hud.qc

index 9a1f88155f31b0a3db1c85cce9a0965b70c0517f..4e6d1a409501db742ad960f741e1eb510d36cebc 100644 (file)
@@ -1332,7 +1332,7 @@ seta hud_progressbar_alpha "0.5" "alpha of progressbars"
 
 seta hud_configure_checkcollisions 1 "check for collisions against other panels when in hud configure mode"
 seta hud_configure_bg_minalpha 0.5 "minimum panel background alpha when in hud configure mode"
-seta hud_configure_grid 0 "snap to grid when moving/resizing panels"
+seta hud_configure_grid 1 "snap to grid when moving/resizing panels"
 seta hud_configure_grid_x 10 "snap each X pixels"
 seta hud_configure_grid_y 10 "snap each Y pixels"
 
index 0024859bc3207c167817a3f1f773d0f2b223cca9..bc1bfa85df1186e6095d8ea795f1598c537a8bc1 100644 (file)
@@ -639,40 +639,41 @@ void HUD_Panel_ExportCfg(string cfgname)
        fclose(fh);
 }
 
-vector HUD_Panel_CheckLimitSize(float id, vector mySize)
+vector HUD_Panel_GetMinSize(float id)
 {
+       vector mySize;
        switch(id) {
                case 0: 
-                       mySize_x = max(mySize_y * (1/10), mySize_x); // at least 1/10 * height
-                       mySize_y = max(mySize_x * (1/26), mySize_y); // at least 1/26 * width
+                       mySize_x = 1/10; // at least 1/10 * height
+                       mySize_y = 1/26; // at least 1/26 * width
                        break;
                case 1: 
                        if(cvar("hud_inventory_onlycurrent"))
-                               mySize_y = mySize_x * (2/5); //  2/5 width
+                               mySize_y = 2/5; //  2/5 width
                        else
-                               mySize_x = max(mySize_y * 0.7, mySize_x); // at least 0.7 * height
+                               mySize_x = 0.7; // at least 0.7 * height
                        break;
                case 3: 
                        if(cvar("hud_healtharmor") == 2)
-                               mySize_y = 0.23 * mySize_x; // 0.23 * width, trial and error...
+                               mySize_y = 0.23; // 0.23 * width, trial and error...
                        break;
                case 5: 
-                       mySize_y = (1/4.1) * mySize_x; // 1/4.1 * width, trial and error...
+                       mySize_y = 1/4.1; // 1/4.1 * width, trial and error...
                        break;
                case 7: 
-                       mySize_y = (1/4) * mySize_x; // 1/4 * width
+                       mySize_y = 1/4; // 1/4 * width
                        break;
                case 8: 
-                       mySize_y = (1/4) * mySize_x; // 1/4 * width
+                       mySize_y = 1/4; // 1/4 * width
                        break;
                case 9: 
-                       mySize_y = (1/4) * mySize_x; // 1/4 * width
+                       mySize_y = 1/4; // 1/4 * width
                        break;
                case 10: 
-                       mySize_y = (1/2) * mySize_x; // 1/2 * width
+                       mySize_y = 1/2; // 1/2 * width
                        break;
                case 11: 
-                       mySize_y = 0.5898 * mySize_x; // 0.5898 * width, reason: bg has weird dimensions...
+                       mySize_y = 0.5898; // 0.5898 * width, reason: bg has weird dimensions...
                        break;
        }
        return mySize;
@@ -843,14 +844,13 @@ vector HUD_Panel_GetProgressBarColor(string item)
        return stov(cvar_string(strcat("hud_progressbar_", item, "_color")));
 }
 
-float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
-// 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(float id, vector myPos, vector mySize)
+// 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(float id, vector myPos, vector mySize)
 {
        float i;
 
        vector myTarget;
-       myTarget = mySize;
+       myTarget = myPos;
 
        vector targPos;
        vector targSize;
@@ -863,9 +863,6 @@ vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
                if(i == id || !HUD_Panel_CheckActive(i))
                        continue;
 
-               targPos = HUD_Panel_GetPos(i);
-               targSize = HUD_Panel_GetSize(i);
-
                targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
                targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
 
@@ -887,24 +884,24 @@ vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
                targCenter_x = targPos_x + 0.5 * targSize_x;
                targCenter_y = targPos_y + 0.5 * targSize_y;
 
-               if(myCenter_x < targCenter_x && myCenter_y < targCenter_y && resizeCorner != 1) // top left (of target panel)
+               if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
                {
                        if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
-                               myTarget_x = targPos_x - myPos_x;
+                               myTarget_x = targPos_x - mySize_x;
                        else // push it upwards
-                               myTarget_y = targPos_y - myPos_y;
+                               myTarget_y = targPos_y - mySize_y;
                }
-               else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y && resizeCorner != 2) // top right
+               else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
                {
                        if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
                                myTarget_x = targPos_x + targSize_x;
                        else // push it upwards
-                               myTarget_y = targPos_y - myPos_y;
+                               myTarget_y = targPos_y - mySize_y;
                }
                else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
                {
                        if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
-                               myTarget_x = targPos_x - myPos_x;
+                               myTarget_x = targPos_x - mySize_x;
                        else // push it downwards
                                myTarget_y = targPos_y + targSize_y;
                }
@@ -920,58 +917,45 @@ vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
        return myTarget;
 }
 
-// TODO: checkResize
-float HUD_Panel_SetSize(float id, vector mySize)
+void HUD_Panel_SetPos(float id, vector pos)
 {
-       float didntresize;
-
-       vector oldSize;
-       oldSize = stov(cvar_string(strcat("hud_", HUD_Panel_GetName(id), "_size")));
+       vector oldPos;
+       oldPos = HUD_Panel_GetPos(id);
 
-       vector myPos;
-       myPos = HUD_Panel_GetPos(id);
+       vector mySize;
+       mySize = HUD_Panel_GetSize(id);
 
-       // check for collisions
        if(cvar("hud_configure_checkcollisions"))
-               mySize = HUD_Panel_CheckResize(id, HUD_Panel_GetPos(id), mySize);
-
-       mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth - myPos_x);
-       mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight - myPos_y);
-
-       // cap against panel's own limits
-       mySize = HUD_Panel_CheckLimitSize(id, mySize);
+               pos = HUD_Panel_CheckMove(id, pos, mySize);
 
-       //mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth);
-       //mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight);
+       pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
+       pos_y = bound(0, pos_y, vid_conheight - mySize_y);
 
        if(cvar("hud_configure_grid"))
        {
-               mySize_x = floor(mySize_x/cvar("hud_configure_grid_x") + 0.5) * cvar("hud_configure_grid_x");
-               mySize_y = floor(mySize_y/cvar("hud_configure_grid_y") + 0.5) * cvar("hud_configure_grid_y");
+               pos_x = floor(pos_x/cvar("hud_configure_grid_x") + 0.5) * cvar("hud_configure_grid_x");
+               pos_y = floor(pos_y/cvar("hud_configure_grid_y") + 0.5) * cvar("hud_configure_grid_y");
        }
 
-       // TODO: is this needed?
-       // this is to check if (and how) SetPos should be called
-       if(mySize_x == oldSize_x && mySize_y == oldSize_y)
-               didntresize = 3; // didnt resize either
-       else if(mySize_x == oldSize_x && mySize_y != oldSize_y)
-               didntresize = 2; // resized Y
-       else if(mySize_y == oldSize_y && mySize_x != oldSize_x)
-               didntresize = 1; // resized X
+       if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
+               pos_x = pos_x - vid_conwidth;
+       if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
+               pos_y = pos_y - vid_conheight;
 
        string s;
-       s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
-       cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
-       return didntresize;
+       s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
+
+       cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
 }
 
-// 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(float id, vector myPos, vector mySize)
+float resizeCorner; // 1 = topleft, 2 = topright, 3 = bottomleft, 4 = bottomright
+// 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(float id, vector myPos, vector mySize)
 {
        float i;
 
        vector myTarget;
-       myTarget = myPos;
+       myTarget = mySize;
 
        vector targPos;
        vector targSize;
@@ -984,6 +968,9 @@ vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
                if(i == id || !HUD_Panel_CheckActive(i))
                        continue;
 
+               targPos = HUD_Panel_GetPos(i);
+               targSize = HUD_Panel_GetSize(i);
+
                targPos = HUD_Panel_GetPos(i) - '1 1 0' * HUD_Panel_GetBorder(id);
                targSize = HUD_Panel_GetSize(i) + '2 2 0' * HUD_Panel_GetBorder(id);
 
@@ -1005,28 +992,28 @@ vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
                targCenter_x = targPos_x + 0.5 * targSize_x;
                targCenter_y = targPos_y + 0.5 * targSize_y;
 
-               if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
+               if(myCenter_x < targCenter_x && myCenter_y < targCenter_y && resizeCorner != 1) // top left (of target panel)
                {
                        if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
-                               myTarget_x = targPos_x - mySize_x;
+                               myTarget_x = targPos_x - myPos_x;
                        else // push it upwards
-                               myTarget_y = targPos_y - mySize_y;
+                               myTarget_y = targPos_y - myPos_y;
                }
-               else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
+               else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y && resizeCorner != 2) // top right
                {
                        if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y) // push it to the side
                                myTarget_x = targPos_x + targSize_x;
                        else // push it upwards
-                               myTarget_y = targPos_y - mySize_y;
+                               myTarget_y = targPos_y - myPos_y;
                }
-               else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
+               else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y && resizeCorner != 3) // bottom left
                {
                        if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
-                               myTarget_x = targPos_x - mySize_x;
+                               myTarget_x = targPos_x - myPos_x;
                        else // push it downwards
                                myTarget_y = targPos_y + targSize_y;
                }
-               else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
+               else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y && resizeCorner != 4) // bottom right
                {
                        if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y) // push it to the side
                                myTarget_x = targPos_x + targSize_x;
@@ -1038,40 +1025,65 @@ vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize)
        return myTarget;
 }
 
-void HUD_Panel_SetPos(float id, vector pos, float didntresize)
+void HUD_Panel_SetPosSize(float id, vector myPos, vector resizeorigin)
 {
-       vector oldPos;
-       oldPos = HUD_Panel_GetPos(id);
-       if(didntresize == 2)
-               pos_x = oldPos_x;
-       else if(didntresize == 1)
-               pos_y = oldPos_y;
-       else if(didntresize == 3)
-               return;
+       vector oldSize, oldPos;
 
        vector mySize;
-       mySize = HUD_Panel_GetSize(id);
+       mySize = resizeorigin - myPos;
 
-       if(cvar("hud_configure_checkcollisions"))
-               pos = HUD_Panel_CheckMove(id, pos, mySize);
+       // cap against panel's own limits
+       vector minSize;
+       minSize = HUD_Panel_GetMinSize(id); // mySize_x at least minSize_x * mySize_y, and vice versa // TODO: this likely fails at minlimit now
 
-       pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
-       pos_y = bound(0, pos_y, vid_conheight - mySize_y);
+       mySize_x = max(minSize_x * mySize_y, mySize_x);
+       mySize_y = max(minSize_y * mySize_x, mySize_y);
+
+       oldPos = HUD_Panel_GetPos(id);
+       oldSize = HUD_Panel_GetSize(id);
 
+       myPos_x = resizeorigin_x - mySize_x;
+       myPos_y = resizeorigin_y - mySize_y;
+       /*
        if(cvar("hud_configure_grid"))
        {
-               pos_x = floor(pos_x/cvar("hud_configure_grid_x") + 0.5) * cvar("hud_configure_grid_x");
-               pos_y = floor(pos_y/cvar("hud_configure_grid_y") + 0.5) * cvar("hud_configure_grid_y");
+               mySize_x = floor(mySize_x/cvar("hud_configure_grid_x") + 0.5) * cvar("hud_configure_grid_x");
+               mySize_y = floor(mySize_y/cvar("hud_configure_grid_y") + 0.5) * cvar("hud_configure_grid_y");
        }
 
-       if (pos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
-               pos_x = pos_x - vid_conwidth;
-       if (pos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
-               pos_y = pos_y - vid_conheight;
+       if(cvar("hud_configure_checkcollisions")) {
+               mySize = HUD_Panel_CheckResize(id, myPos, mySize);
+               myPos = HUD_Panel_CheckMove(id, myPos, mySize);
+       }
+
+       mySize_x = bound(0.025 * vid_conwidth, mySize_x, vid_conwidth - myPos_x);
+       mySize_y = bound(0.025 * vid_conheight, mySize_y, vid_conheight - myPos_y);
+
+       if(oldSize_x == mySize_x)
+               myPos_x = oldPos_x;
+       if(oldSize_y == mySize_y)
+               myPos_y = oldPos_y;
+
+       myPos_x = bound(0, myPos_x, vid_conwidth - mySize_x);
+       myPos_y = bound(0, myPos_y, vid_conheight - mySize_y);
+
+       if(cvar("hud_configure_grid"))
+       {
+               myPos_x = floor(myPos_x/cvar("hud_configure_grid_x") + 0.5) * cvar("hud_configure_grid_x");
+               myPos_y = floor(myPos_y/cvar("hud_configure_grid_y") + 0.5) * cvar("hud_configure_grid_y");
+       }
+
+       if (myPos_x + 0.5 * mySize_x > 0.5 * vid_conwidth)
+               myPos_x = myPos_x - vid_conwidth;
+       if (myPos_y + 0.5 * mySize_y > 0.5 * vid_conheight)
+               myPos_y = myPos_y - vid_conheight;
+       */
 
        string s;
-       s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
+       s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
+       cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_size"), s);
 
+       s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
        cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
 }
 
@@ -1094,10 +1106,10 @@ float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
        return false;
 }
 
+// get rid of mouseprevpos, it was a terrible idea TODO
 vector mousepos, mouseprevpos;
 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
-vector panel_click_pos; // panel pos (saved only upon a click)
-vector panel_click_size; // panel size (saved only upon a click)
+vector panel_click_resizeorigin; // coordinates for opposite point when resizing
 float highlightedPanel;
 float highlightedAction; // 0 = nothing, 1 = move, 2 = resize
 void HUD_Panel_Mouse()
@@ -1167,32 +1179,23 @@ void HUD_Panel_Mouse()
                                if(prevMouseClicked == 0)
                                {
                                        panel_click_distance = mousepos - panelPos;
-                                       panel_click_pos = panelPos;
-                                       panel_click_size = panelSize;
+                                       if(highlightedAction == 2)
+                                       {
+                                               if(resizeCorner == 1)
+                                                       panel_click_resizeorigin = panelPos + panelSize;
+                                               else if(resizeCorner == 2)
+                                                       panel_click_resizeorigin = panelPos + eY * panelSize_y;
+                                               else if(resizeCorner == 3)
+                                                       panel_click_resizeorigin = panelPos + eX * panelSize_x;
+                                               else if(resizeCorner == 4)
+                                                       panel_click_resizeorigin = panelPos;
+                                       }       
                                }
 
                                if(highlightedAction == 1)
-                                       HUD_Panel_SetPos(i, mousepos - panel_click_distance, 0);
+                                       HUD_Panel_SetPos(i, mousepos - panel_click_distance);
                                else if(highlightedAction == 2)
-                               {
-                                       float didntresize; // panel too big/too small, dont resize (also has to affect moving)
-                                       if(resizeCorner == 1) {
-                                               didntresize = HUD_Panel_SetSize(i, panelSize + mouseprevpos - mousepos);
-                                               HUD_Panel_SetPos(i, mousepos - panel_click_distance, didntresize);
-                                       }
-                                       if(resizeCorner == 2) {
-                                               didntresize = HUD_Panel_SetSize(i, eY * panel_click_size_y + eX * (mousepos_x - panelPos_x - (panel_click_distance_x - panel_click_size_x))
-                                                               + eY * (panel_click_distance_y + (panel_click_pos_y - mousepos_y)));
-                                               HUD_Panel_SetPos(i, eX * panelPos_x + eY * (mousepos_y - panel_click_distance_y), didntresize);
-                                       }
-                                       if(resizeCorner == 3) {
-                                               didntresize = HUD_Panel_SetSize(i, panelSize + eX * (mouseprevpos_x - mousepos_x) + eY * (mousepos_y - mouseprevpos_y));
-                                               HUD_Panel_SetPos(i, eX * (mousepos_x - panel_click_distance_x) + eY * panelPos_y, didntresize);
-                                       }
-                                       if(resizeCorner == 4) {
-                                               HUD_Panel_SetSize(i, mousepos - panelPos - (panel_click_distance - panel_click_size));
-                                       }
-                               }
+                                       HUD_Panel_SetPosSize(i, mousepos - panel_click_distance, panel_click_resizeorigin);
                        }
                }
        }
@@ -1200,14 +1203,6 @@ void HUD_Panel_Mouse()
        prevMouseClicked = mouseClicked;
 }
 
-/*void HUD_DrawDockEdge(float id, vector p1, vector p2, float target)
-{
-       vector pos;
-       vector size;
-
-       pos =
-*/ // maybe one day, since this will be quite complicated
-
 // Weapon icons (#0)
 //
 float weaponspace[10];