]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
fix bug mentioned in previous commit, now the only case where i see resizing fail...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 3a30921b64a405a4bc35dfddcd836d7ab13cd51f..66e182fdd0ef0421f817ad859e0471444757fe5d 100644 (file)
@@ -1027,14 +1027,40 @@ void HUD_Panel_SetPos(float id, vector pos)
        cvar_set(strcat("hud_", HUD_Panel_GetName(id), "_pos"), s);
 }
 
+float HUD_Panel_CheckValidity_of_ResizeSuggestion(float id, vector mySize)
+{
+       vector oldSize;
+       oldSize = mySize;
+
+       // copy pasta from SetPosSize:
+       // 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.
+       {
+               mySize_x = max(17 * cvar("con_chatsize"), mySize_x);
+               mySize_y = max(2 * cvar("con_chatsize") + 2 * HUD_Panel_GetPadding(id), mySize_y);
+       }
+
+       // cap against panel's own limits
+       vector minSize;
+       minSize = HUD_Panel_GetMinSize(id); // mySize_x at least minSize_x * mySize_y, and vice versa
+
+       mySize_x = max(minSize_x * mySize_y, mySize_x);
+       mySize_y = max(minSize_y * mySize_x, mySize_y);
+
+       if(mySize == oldSize)
+               return 1;
+       else
+               return 0;
+}
+
 // 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)
+vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize, vector resizeorigin)
 {
        float i;
 
-       vector myTarget;
-       myTarget = mySize;
-
        vector targPos;
        vector targSize;
        vector myCenter;
@@ -1046,9 +1072,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);
 
@@ -1063,6 +1086,22 @@ vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
                        continue;
 
                // OK, there IS a collision.
+               //
+
+               // Now check some special cases
+               // If the resizeorigin is too close to the target panel on either axis, we do not want to perform any collision avoidance on that axis
+               float Check_X, Check_Y;
+               Check_X = Check_Y = 1;
+               // check upper/left edges of targ panel
+               if(fabs(targPos_x - resizeorigin_x) < 0.025 * vid_conwidth)
+                       Check_X = 0;
+               if(fabs(targPos_y - resizeorigin_y) < 0.025 * vid_conheight)
+                       Check_Y = 0;
+               // check lower/right edges of targ panel
+               if(fabs(resizeorigin_x - (targPos_x + targSize_x)) < 0.025 * vid_conwidth)
+                       Check_X = 0;
+               if(fabs(resizeorigin_y - (targPos_y + targSize_y)) < 0.025 * vid_conheight)
+                       Check_Y = 0;
 
                myCenter_x = myPos_x + 0.5 * mySize_x;
                myCenter_y = myPos_y + 0.5 * mySize_y;
@@ -1072,41 +1111,52 @@ vector HUD_Panel_CheckResize(float id, vector myPos, vector mySize)
 
                if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // 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 - myPos_x;
-                       else // push it upwards
-                               myTarget_y = targPos_y - myPos_y;
+                       //if(!HUD_Panel_CheckValidity_of_ResizeSuggestion(id, eX * (targPos_x - myPos_x) + eY * (targPos_y - resizeorigin_y)))
+                       //      continue;
+
+                       if(myPos_x + mySize_x - targPos_x < myPos_y + mySize_y - targPos_y && Check_X) // push it to the side
+                               mySize_x = targPos_x - myPos_x;
+                       else if(Check_Y) // push it upwards
+                               mySize_y = targPos_y - resizeorigin_y;
                }
                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;
+                       //if(!HUD_Panel_CheckValidity_of_ResizeSuggestion(id, eX * (resizeorigin_x - (targPos_x + targSize_x)) + eY * (targPos_y - resizeorigin_y)))
+                       //      continue;
+
+                       if(targPos_x + targSize_x - myPos_x < myPos_y + mySize_y - targPos_y && Check_X) // push it to the side
+                               mySize_x = resizeorigin_x - (targPos_x + targSize_x);
+                       else if(Check_Y) // push it upwards
+                               mySize_y = targPos_y - resizeorigin_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;
-                       else // push it downwards
-                               myTarget_y = targPos_y + targSize_y;
+                       //if(!HUD_Panel_CheckValidity_of_ResizeSuggestion(id, eX * (targPos_x - resizeorigin_x) + eY * (resizeorigin_y - (targPos_y + targSize_y))))
+                       //      continue;
+
+                       if(myPos_x + mySize_x - targPos_x < targPos_y + targSize_y - myPos_y && Check_X) // push it to the side
+                               mySize_x = targPos_x - resizeorigin_x;
+                       else if(Check_Y) // push it upwards
+                               mySize_y = resizeorigin_y - (targPos_y + targSize_y);
                }
                else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // 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;
-                       else // push it downwards
-                               myTarget_y = targPos_y + targSize_y;
+                       //if(!HUD_Panel_CheckValidity_of_ResizeSuggestion(id, eX * (resizeorigin_x - (targPos_x + targSize_x)) + eY * (resizeorigin_y - (targPos_y + targSize_y))))
+                       //      continue;
+
+                       if(targPos_x + targSize_x - myPos_x < targPos_y + targSize_y - myPos_y && Check_X) // push it to the side
+                               mySize_x = resizeorigin_x - (targPos_x + targSize_x);
+                       else if(Check_Y) // push it upwards
+                               mySize_y = resizeorigin_y - (targPos_y + targSize_y);
                }
        }
 
-       return myTarget;
+       return mySize;
 }
 
 void HUD_Panel_SetPosSize(float id, vector resizeorigin)
 {
        vector mySize, myPos;
-       vector oldPos;
 
        if(resizeCorner == 1) {
                mySize_x = resizeorigin_x - (mousepos_x - panel_click_distance_x);
@@ -1165,12 +1215,8 @@ void HUD_Panel_SetPosSize(float id, vector resizeorigin)
        mySize_x = min(vid_conwidth - myPos_x, mySize_x); 
        mySize_y = min(vid_conheight - myPos_y, mySize_y); 
 
-       if(cvar("hud_configure_checkcollisions")) {
-               oldPos = myPos;
-               mySize = HUD_Panel_CheckResize(id, myPos, mySize);
-               myPos = HUD_Panel_CheckMove(id, myPos, mySize); // touching myPos won't do anything... unless we make it change mySize somehow, see next line
-               mySize = mySize - myPos + oldPos; // TODO: this is still borked in some situations :(
-       }
+       if(cvar("hud_configure_checkcollisions"))
+               mySize = HUD_Panel_CheckResize(id, myPos, mySize, resizeorigin);
 
        if(cvar("hud_configure_grid"))
        {