diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-01-20 14:24:34 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-01-20 14:24:34 +1000 |
| commit | 869c206c4fcc8001bd2e1d66f704290331813835 (patch) | |
| tree | 96735ce8fe4665e2759c3374221d6f06f4527df2 /src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java | |
| parent | ec2c72827f01dd4bb2174137f1ab162f9ddaab62 (diff) | |
| download | GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.tar.gz GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.tar.bz2 GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.zip | |
Initial Commit
Diffstat (limited to 'src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java')
| -rw-r--r-- | src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java b/src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java new file mode 100644 index 0000000000..a94705767d --- /dev/null +++ b/src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java @@ -0,0 +1,94 @@ +package binnie.craftgui.controls.scroll; + +import binnie.craftgui.controls.core.Control; +import binnie.craftgui.core.Attribute; +import binnie.craftgui.core.CraftGUI; +import binnie.craftgui.core.IWidget; +import binnie.craftgui.core.geometry.IArea; +import binnie.craftgui.core.geometry.IPoint; +import binnie.craftgui.core.renderer.Renderer; +import binnie.craftgui.events.EventMouse.Down; +import binnie.craftgui.events.EventMouse.Down.Handler; +import binnie.craftgui.events.EventMouse.Drag; +import binnie.craftgui.events.EventMouse.Drag.Handler; +import binnie.craftgui.resource.minecraft.CraftGUITexture; + +public class ControlScrollBar + extends Control +{ + protected final IControlScrollable scrollable; + + public ControlScrollBar(ControlScroll parent) + { + this(parent, 0.0F, 0.0F, parent.getSize().x(), parent.getSize().y(), parent.getScrollableWidget()); + } + + public ControlScrollBar(IWidget parent, float x, float y, float w, float h, IControlScrollable scrollable2) + { + super(parent, x, y, w, h); + this.scrollable = scrollable2; + addAttribute(Attribute.MouseOver); + + addSelfEventHandler(new EventMouse.Drag.Handler() + { + public void onEvent(EventMouse.Drag event) + { + ControlScrollBar.this.scrollable.movePercentage(event.getDy() / (ControlScrollBar.this.h() - ControlScrollBar.this.getBarHeight())); + } + }); + addSelfEventHandler(new EventMouse.Down.Handler() + { + public void onEvent(EventMouse.Down event) + { + float shownPercentage = ControlScrollBar.this.scrollable.getPercentageShown(); + float percentageIndex = ControlScrollBar.this.scrollable.getPercentageIndex(); + float minPercent = (1.0F - shownPercentage) * percentageIndex; + float maxPercent = minPercent + shownPercentage; + float clickedPercentage = ControlScrollBar.this.getRelativeMousePosition().y() / (ControlScrollBar.this.h() - 2.0F); + clickedPercentage = Math.max(Math.min(clickedPercentage, 1.0F), 0.0F); + if (clickedPercentage > maxPercent) { + ControlScrollBar.this.scrollable.setPercentageIndex((clickedPercentage - shownPercentage) / (1.0F - shownPercentage)); + } + if (clickedPercentage < minPercent) { + ControlScrollBar.this.scrollable.setPercentageIndex(clickedPercentage / (1.0F - shownPercentage)); + } + } + }); + } + + public void onUpdateClient() {} + + public boolean isEnabled() + { + return this.scrollable.getPercentageShown() < 0.99F; + } + + public float getBarHeight() + { + return h() * this.scrollable.getPercentageShown(); + } + + protected IArea getRenderArea() + { + float height = getBarHeight(); + if (height < 6.0F) { + height = 6.0F; + } + float yOffset = ((int)h() - (int)getBarHeight()) * this.scrollable.getPercentageIndex(); + + return new IArea(0.0F, yOffset, getSize().x(), height); + } + + public void onRenderBackground() + { + IArea renderArea = getRenderArea(); + + Object texture = CraftGUITexture.ScrollDisabled; + if (isMouseOver()) { + texture = CraftGUITexture.ScrollHighlighted; + } else if (isEnabled()) { + texture = CraftGUITexture.Scroll; + } + CraftGUI.Render.texture(texture, renderArea); + } +} |
