diff options
Diffstat (limited to 'src/Java/binnie/craftgui/controls/scroll')
4 files changed, 0 insertions, 267 deletions
diff --git a/src/Java/binnie/craftgui/controls/scroll/ControlScroll.java b/src/Java/binnie/craftgui/controls/scroll/ControlScroll.java deleted file mode 100644 index 1d03f5fbc7..0000000000 --- a/src/Java/binnie/craftgui/controls/scroll/ControlScroll.java +++ /dev/null @@ -1,22 +0,0 @@ -package binnie.craftgui.controls.scroll; - -import binnie.craftgui.controls.core.Control; -import binnie.craftgui.core.IWidget; - -public class ControlScroll - extends Control -{ - private IControlScrollable scrollWidget; - - public ControlScroll(IWidget parent, float x, float y, float width, float height, IControlScrollable scrollWidget) - { - super(parent, x, y, width, height); - this.scrollWidget = scrollWidget; - new ControlScrollBar(this); - } - - public IControlScrollable getScrollableWidget() - { - return this.scrollWidget; - } -} diff --git a/src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java b/src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java deleted file mode 100644 index a94705767d..0000000000 --- a/src/Java/binnie/craftgui/controls/scroll/ControlScrollBar.java +++ /dev/null @@ -1,94 +0,0 @@ -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); - } -} diff --git a/src/Java/binnie/craftgui/controls/scroll/ControlScrollableContent.java b/src/Java/binnie/craftgui/controls/scroll/ControlScrollableContent.java deleted file mode 100644 index 442c9d3226..0000000000 --- a/src/Java/binnie/craftgui/controls/scroll/ControlScrollableContent.java +++ /dev/null @@ -1,134 +0,0 @@ -package binnie.craftgui.controls.scroll; - -import binnie.craftgui.controls.core.Control; -import binnie.craftgui.core.IWidget; -import binnie.craftgui.core.geometry.IArea; -import binnie.craftgui.core.geometry.IPoint; -import binnie.craftgui.events.EventMouse.Wheel; -import binnie.craftgui.events.EventMouse.Wheel.Handler; -import binnie.craftgui.events.EventWidget.ChangeSize; -import binnie.craftgui.events.EventWidget.ChangeSize.Handler; - -public class ControlScrollableContent<T extends IWidget> - extends Control - implements IControlScrollable -{ - protected T controlChild; - protected float scrollBarSize; - - public ControlScrollableContent(IWidget parent, float x, float y, float w, float h, float scrollBarSize) - { - super(parent, x, y, w, h); - if (scrollBarSize != 0.0F) { - new ControlScroll(this, getSize().x() - scrollBarSize, 0.0F, scrollBarSize, getSize().y(), this); - } - addEventHandler(new EventMouse.Wheel.Handler() - { - public void onEvent(EventMouse.Wheel event) - { - if ((ControlScrollableContent.this.getRelativeMousePosition().x() > 0.0F) && (ControlScrollableContent.this.getRelativeMousePosition().y() > 0.0F) && (ControlScrollableContent.this.getRelativeMousePosition().x() < ControlScrollableContent.this.getSize().x()) && (ControlScrollableContent.this.getRelativeMousePosition().y() < ControlScrollableContent.this.getSize().y())) - { - if (ControlScrollableContent.this.getMovementRange() == 0.0F) { - return; - } - float percentageMove = 0.8F / ControlScrollableContent.this.getMovementRange(); - ControlScrollableContent.this.movePercentage(percentageMove * -event.getDWheel()); - } - } - }); - this.scrollBarSize = scrollBarSize; - } - - public void setScrollableContent(T child) - { - this.controlChild = child; - if (child == null) { - return; - } - child.setCroppedZone(this, new IArea(1.0F, 1.0F, getSize().x() - 2.0F - this.scrollBarSize, getSize().y() - 2.0F)); - child.addSelfEventHandler(new EventWidget.ChangeSize.Handler() - { - public void onEvent(EventWidget.ChangeSize event) - { - ControlScrollableContent.this.controlChild.setOffset(new IPoint(0.0F, -ControlScrollableContent.this.percentageIndex * ControlScrollableContent.this.getMovementRange())); - if (ControlScrollableContent.this.getMovementRange() == 0.0F) { - ControlScrollableContent.this.percentageIndex = 0.0F; - } - } - }); - } - - public T getContent() - { - return this.controlChild; - } - - public float getPercentageShown() - { - if ((this.controlChild == null) || (this.controlChild.getSize().y() == 0.0F)) { - return 1.0F; - } - float shown = getSize().y() / this.controlChild.getSize().y(); - return Math.min(shown, 1.0F); - } - - float percentageIndex = 0.0F; - - public float getPercentageIndex() - { - return this.percentageIndex; - } - - public void movePercentage(float percentage) - { - if (this.controlChild == null) { - return; - } - this.percentageIndex += percentage; - if (this.percentageIndex > 1.0F) { - this.percentageIndex = 1.0F; - } else if (this.percentageIndex < 0.0F) { - this.percentageIndex = 0.0F; - } - if (getMovementRange() == 0.0F) { - this.percentageIndex = 0.0F; - } - this.controlChild.setOffset(new IPoint(0.0F, -this.percentageIndex * getMovementRange())); - } - - public void setPercentageIndex(float index) - { - movePercentage(index - this.percentageIndex); - } - - public float getMovementRange() - { - if (this.controlChild == null) { - return 0.0F; - } - float range = this.controlChild.getSize().y() - getSize().y(); - return Math.max(range, 0.0F); - } - - public void onUpdateClient() - { - setPercentageIndex(getPercentageIndex()); - } - - public void ensureVisible(float minY, float maxY, float totalY) - { - minY /= totalY; - maxY /= totalY; - - float shownPercentage = getPercentageShown(); - float percentageIndex = getPercentageIndex(); - float minPercent = (1.0F - shownPercentage) * percentageIndex; - float maxPercent = minPercent + shownPercentage; - if (maxY > maxPercent) { - setPercentageIndex((maxY - shownPercentage) / (1.0F - shownPercentage)); - } - if (minY < minPercent) { - setPercentageIndex(minY / (1.0F - shownPercentage)); - } - } -} diff --git a/src/Java/binnie/craftgui/controls/scroll/IControlScrollable.java b/src/Java/binnie/craftgui/controls/scroll/IControlScrollable.java deleted file mode 100644 index 39154815e5..0000000000 --- a/src/Java/binnie/craftgui/controls/scroll/IControlScrollable.java +++ /dev/null @@ -1,17 +0,0 @@ -package binnie.craftgui.controls.scroll; - -import binnie.craftgui.core.IWidget; - -public abstract interface IControlScrollable - extends IWidget -{ - public abstract float getPercentageShown(); - - public abstract float getPercentageIndex(); - - public abstract void movePercentage(float paramFloat); - - public abstract void setPercentageIndex(float paramFloat); - - public abstract float getMovementRange(); -} |