Skip to content

Commit

Permalink
Merge pull request #39 from Jarod42/clamp_area_fix
Browse files Browse the repository at this point in the history
Clamp area fix
  • Loading branch information
Jarod42 authored Aug 12, 2024
2 parents abba23d + 6a70c1c commit 5a191c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Continue rebasing from 29eb696aaf7aa7a78cece7d25f27d0235e4559ed
* Continue rebasing from 1d9590907eb3a8cc298f660c1436d0e90808d684
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
24 changes: 17 additions & 7 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ namespace gcn
carea.y = area.y;
carea.width = area.width;
carea.height = area.height;
carea.xOffset = area.x;
carea.yOffset = area.y;
mClipStack.push(carea);
return true;
}

ClipRectangle top = mClipStack.top();
const ClipRectangle& top = mClipStack.top();
ClipRectangle carea;
carea = area;
carea.xOffset = top.xOffset + carea.x;
Expand All @@ -96,24 +98,32 @@ namespace gcn
// Clamp the pushed clip rectangle.
if (carea.x < top.x)
{
carea.width += carea.x - top.x;
carea.x = top.x;
}

if (carea.y < top.y)
{
carea.height += carea.y - top.y;
carea.y = top.y;
}

if (carea.width > top.width)
if (carea.x + carea.width > top.x + top.width)
{
carea.width = top.width;
carea.width = top.x + top.width - carea.x;

if (carea.width < 0)
{
carea.width = 0;
}
}

if (carea.height > top.height)
if (carea.y + carea.height > top.y + top.height)
{
carea.height = top.height;
carea.height = top.y + top.height - carea.y;

if (carea.height < 0)
{
carea.height = 0;
}
}

bool result = carea.isIntersecting(top);
Expand Down

0 comments on commit 5a191c3

Please sign in to comment.