mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-05-31 09:01:46 +00:00
Fix clicking in (CST) anchored windowDefs and stretched mouse cursor
This commit is contained in:
parent
3ee8ef55ef
commit
57a75f8b08
3 changed files with 62 additions and 24 deletions
|
@ -747,17 +747,16 @@ void idDeviceContext::DrawCursor(float *x, float *y, float size) {
|
||||||
|
|
||||||
// the following block used to be Adjust(Cursor)Coords()
|
// the following block used to be Adjust(Cursor)Coords()
|
||||||
// (no point in keeping that function when it's only used here)
|
// (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
|
// if cstAdjustCoords is used, x and y shouldn't be scaled, otherwise the cursor moves to a window border
|
||||||
float sizeW = size * fixScaleForMenu.x;
|
if ( !cstAdjustCoords ) {
|
||||||
float sizeH = size * fixScaleForMenu.y;
|
*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 fixedX = *x * fixScaleForMenu.x + fixOffsetForMenu.x;
|
||||||
float fixedY = *y * fixScaleForMenu.y + fixOffsetForMenu.y;
|
float fixedY = *y * fixScaleForMenu.y + fixOffsetForMenu.y;
|
||||||
|
|
||||||
|
@ -1010,22 +1009,20 @@ static void CstAdjustParmsForAnchor(int anchor, float &_xScale, float &_yScale,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
void idDeviceContext::CstSetSize(int anchor, int anchorTo, float factor) {
|
bool idDeviceContext::CstGetParams(int anchor, int anchorTo, float factor, idVec2& out_Scale, idVec2& out_Offset)
|
||||||
vidWidth = VIRTUAL_WIDTH;
|
{
|
||||||
vidHeight = VIRTUAL_HEIGHT;
|
float xScale = 1.0f;
|
||||||
xScale = 1.0f;
|
float yScale = 1.0f;
|
||||||
yScale = 1.0f;
|
out_Offset.Set(0, 0);
|
||||||
cst_xOffset = 0.0f;
|
|
||||||
cst_yOffset = 0.0f;
|
|
||||||
cstAdjustCoords = false;
|
|
||||||
|
|
||||||
if (!CstGetVidScale(xScale, yScale)) {
|
if (!CstGetVidScale(xScale, yScale)) {
|
||||||
return;
|
out_Scale.Set(1, 1);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anchorTo == idDeviceContext::CST_ANCHOR_NONE) {
|
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 {
|
} else {
|
||||||
float from_xScale = xScale;
|
float from_xScale = xScale;
|
||||||
float from_yScale = yScale;
|
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;
|
xScale = from_xScale * (1.0f - factor) + to_xScale * factor;
|
||||||
yScale = from_yScale * (1.0f - factor) + to_yScale * factor;
|
yScale = from_yScale * (1.0f - factor) + to_yScale * factor;
|
||||||
|
|
||||||
cst_xOffset = from_xOffset * (1.0f - factor) + to_xOffset * factor;
|
out_Offset.x = from_xOffset * (1.0f - factor) + to_xOffset * factor;
|
||||||
cst_yOffset = from_yOffset * (1.0f - factor) + to_yOffset * 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
|
//#modified-fva; END
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,9 @@ public:
|
||||||
return fixOffsetForMenu.x != 0.0f || fixOffsetForMenu.y != 0.0f || cstAdjustCoords;
|
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 {
|
enum {
|
||||||
CURSOR_ARROW,
|
CURSOR_ARROW,
|
||||||
CURSOR_HAND,
|
CURSOR_HAND,
|
||||||
|
|
|
@ -694,6 +694,18 @@ bool idWindow::Contains(const idRectangle &sr, float x, float y) {
|
||||||
idRectangle r = sr;
|
idRectangle r = sr;
|
||||||
r.x += actualX - drawRect.x;
|
r.x += actualX - drawRect.x;
|
||||||
r.y += actualY - drawRect.y;
|
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);
|
return r.Contains(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,6 +718,18 @@ bool idWindow::Contains(float x, float y) {
|
||||||
idRectangle r = drawRect;
|
idRectangle r = drawRect;
|
||||||
r.x = actualX;
|
r.x = actualX;
|
||||||
r.y = actualY;
|
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);
|
return r.Contains(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue