diff --git a/neo/ui/DeviceContext.cpp b/neo/ui/DeviceContext.cpp index 7ab11320..75778032 100644 --- a/neo/ui/DeviceContext.cpp +++ b/neo/ui/DeviceContext.cpp @@ -747,17 +747,16 @@ void idDeviceContext::DrawCursor(float *x, float *y, float size) { // the following block used to be Adjust(Cursor)Coords() // (no point in keeping that function when it's only used here) - *x *= xScale; - *y *= yScale; - size *= xScale; - // TODO: not sure if scaling it by both is the right thing to do.. - // but OTOH, probably one of them is always 1, at least when not using an anchor - // (and why would a cursor use an anchor) - size *= yScale; - // the *actual* sizes used (but not set to *x and *y) need to apply the menu fixes - float sizeW = size * fixScaleForMenu.x; - float sizeH = size * fixScaleForMenu.y; + // if cstAdjustCoords is used, x and y shouldn't be scaled, otherwise the cursor moves to a window border + if ( !cstAdjustCoords ) { + *x *= xScale; + *y *= yScale; + } + + // the *actual* sizes and position used (but not set to *x and *y) need to apply the menu fixes + float sizeW = size * fixScaleForMenu.x * xScale; + float sizeH = size * fixScaleForMenu.y * yScale; float fixedX = *x * fixScaleForMenu.x + fixOffsetForMenu.x; float fixedY = *y * fixScaleForMenu.y + fixOffsetForMenu.y; @@ -1010,22 +1009,20 @@ static void CstAdjustParmsForAnchor(int anchor, float &_xScale, float &_yScale, } } - -void idDeviceContext::CstSetSize(int anchor, int anchorTo, float factor) { - vidWidth = VIRTUAL_WIDTH; - vidHeight = VIRTUAL_HEIGHT; - xScale = 1.0f; - yScale = 1.0f; - cst_xOffset = 0.0f; - cst_yOffset = 0.0f; - cstAdjustCoords = false; +// static +bool idDeviceContext::CstGetParams(int anchor, int anchorTo, float factor, idVec2& out_Scale, idVec2& out_Offset) +{ + float xScale = 1.0f; + float yScale = 1.0f; + out_Offset.Set(0, 0); if (!CstGetVidScale(xScale, yScale)) { - return; + out_Scale.Set(1, 1); + return false; } if (anchorTo == idDeviceContext::CST_ANCHOR_NONE) { - CstAdjustParmsForAnchor(anchor, xScale, yScale, cst_xOffset, cst_yOffset); + CstAdjustParmsForAnchor(anchor, xScale, yScale, out_Offset.x, out_Offset.y); } else { float from_xScale = xScale; float from_yScale = yScale; @@ -1044,10 +1041,24 @@ void idDeviceContext::CstSetSize(int anchor, int anchorTo, float factor) { xScale = from_xScale * (1.0f - factor) + to_xScale * factor; yScale = from_yScale * (1.0f - factor) + to_yScale * factor; - cst_xOffset = from_xOffset * (1.0f - factor) + to_xOffset * factor; - cst_yOffset = from_yOffset * (1.0f - factor) + to_yOffset * factor; + out_Offset.x = from_xOffset * (1.0f - factor) + to_xOffset * factor; + out_Offset.y = from_yOffset * (1.0f - factor) + to_yOffset * factor; } - cstAdjustCoords = true; + out_Scale.Set(xScale, yScale); + return true; +} + +void idDeviceContext::CstSetSize(int anchor, int anchorTo, float factor) { + vidWidth = VIRTUAL_WIDTH; + vidHeight = VIRTUAL_HEIGHT; + + idVec2 scale; + idVec2 offset; + cstAdjustCoords = CstGetParams(anchor, anchorTo, factor, scale, offset); + xScale = scale.x; + yScale = scale.y; + cst_xOffset = offset.x; + cst_yOffset = offset.y; } //#modified-fva; END diff --git a/neo/ui/DeviceContext.h b/neo/ui/DeviceContext.h index 2cd61c63..03733aac 100644 --- a/neo/ui/DeviceContext.h +++ b/neo/ui/DeviceContext.h @@ -112,6 +112,9 @@ public: return fixOffsetForMenu.x != 0.0f || fixOffsetForMenu.y != 0.0f || cstAdjustCoords; } + // DG: used in idWindow::Contains(), so it can adjust coordinates + static bool CstGetParams(int anchor, int anchorTo, float anchorFactor, idVec2& out_Scale, idVec2& out_Offset); + enum { CURSOR_ARROW, CURSOR_HAND, diff --git a/neo/ui/Window.cpp b/neo/ui/Window.cpp index 518a6abb..502592d3 100644 --- a/neo/ui/Window.cpp +++ b/neo/ui/Window.cpp @@ -694,6 +694,18 @@ bool idWindow::Contains(const idRectangle &sr, float x, float y) { idRectangle r = sr; r.x += actualX - drawRect.x; r.y += actualY - drawRect.y; + // DG: if cstAnchor is used, the coordinates must adjusted + if ( cstAnchor != idDeviceContext::CST_ANCHOR_NONE ) { + // adjust r like idDeviceContext does for drawing + idVec2 scale, offset; + if ( idDeviceContext::CstGetParams( cstAnchor, cstAnchorTo, cstAnchorFactor, scale, offset ) ) { + r.x = r.x * scale.x + offset.x; + r.y = r.y * scale.y + offset.y; + r.w *= scale.x; + r.h *= scale.y; + } + } + return r.Contains(x, y); } @@ -706,6 +718,18 @@ bool idWindow::Contains(float x, float y) { idRectangle r = drawRect; r.x = actualX; r.y = actualY; + // DG: if cstAnchor is used, the coordinates must adjusted + if ( cstAnchor != idDeviceContext::CST_ANCHOR_NONE ) { + // adjust r like idDeviceContext does for drawing + idVec2 scale, offset; + if ( idDeviceContext::CstGetParams( cstAnchor, cstAnchorTo, cstAnchorFactor, scale, offset ) ) { + r.x = r.x * scale.x + offset.x; + r.y = r.y * scale.y + offset.y; + r.w *= scale.x; + r.h *= scale.y; + } + } + return r.Contains(x, y); }