From d75681bd6b453b17da410aaeea66213af2c5ce1b Mon Sep 17 00:00:00 2001 From: terencehill Date: Sat, 15 May 2010 23:54:55 +0200 Subject: [PATCH] Snap panel to the central vertical/horizontal axis if enough close --- qcsrc/client/hud.qc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/qcsrc/client/hud.qc b/qcsrc/client/hud.qc index 222823039..39fbe9750 100644 --- a/qcsrc/client/hud.qc +++ b/qcsrc/client/hud.qc @@ -786,6 +786,7 @@ float HUD_Panel_SetSize(float id, vector mySize) return didntresize; } +// check if the panel is enough close to central vertical/horizontal axis, and // 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) { @@ -799,6 +800,29 @@ vector HUD_Panel_CheckMove(float id, vector myPos, vector mySize) vector myCenter; vector targCenter; + vector snapDistance; + snapDistance_x = vid_conwidth / 64; + snapDistance_y = vid_conheight / 64; + + myCenter = eX * (myPos_x + 0.5 * mySize_x); + targCenter = eX * (vid_conwidth * 0.5); + if (myCenter_x > targCenter_x - snapDistance_x && myCenter_x < targCenter_x + snapDistance_x) + { + // snap to central vertical axis + myTarget_x = targCenter_x - mySize_x * 0.5; + myTarget_y = myPos_y; + } + + myCenter = eY * (myPos_y + 0.5 * mySize_y); + targCenter = eY * (vid_conheight * 0.5); + if (myCenter_y > targCenter_y - snapDistance_y && myCenter_y < targCenter_y + snapDistance_y) + { + // snap to central horizontal axis + if (myTarget_x == 0) + myTarget_x = myPos_x; + myTarget_y = targCenter_y - mySize_y * 0.5; + } + for (i = 0; i < panel_cnt; ++i) { if(i == id || !HUD_Panel_CheckActive(i)) continue; -- 2.39.2