Created
April 30, 2018 22:11
-
-
Save DCubix/1f6e76958fdef346db6cc65b51638c88 to your computer and use it in GitHub Desktop.
Clipping for GUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean beginClipping(int x, int y, int w, int h) { | |
IDevice dev = Age.Device; | |
if (!dev.isEnabled(Feature.Scissor)) { | |
dev.setFeatures(true, Feature.Scissor); | |
} | |
if (!clipRectStack.isEmpty()) { | |
Rectangle parent = clipRectStack.lastElement(); | |
int minX = Math.max(parent.x, x); | |
int maxX = Math.min(parent.x + parent.width, x + w); | |
if (maxX - minX < 1) return false; | |
int minY = Math.max(parent.y, y); | |
int maxY = Math.min(parent.y + parent.height, y + h); | |
if (maxY - minY < 1) return false; | |
x = minX; | |
y = minY; | |
w = maxX - minX; | |
h = Math.max(1, maxY - minY); | |
} | |
clipRectStack.push(new Rectangle(x, y, w, h)); | |
dev.setScissor(x, y, w, h); | |
return true; | |
} | |
public void endClipping() { | |
IDevice dev = Age.Device; | |
if (!clipRectStack.isEmpty()) { | |
clipRectStack.pop(); | |
} | |
if (!clipRectStack.isEmpty()) { | |
Rectangle scissor = clipRectStack.peek(); | |
dev.setScissor(scissor.x, scissor.y, scissor.width, scissor.height); | |
} else { | |
dev.setScissor(0, 0, width, height); | |
if (dev.isEnabled(Feature.Scissor)) { | |
dev.setFeatures(false, Feature.Scissor); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment