From a92a5dde3c6dab5f2dfca9949d2b14cdfbabc258 Mon Sep 17 00:00:00 2001 From: Thomas Guimbretiere Date: Wed, 23 Oct 2013 21:21:34 +0200 Subject: [PATCH] ViewportScrollable is now its own class. --- mcp/mobius/waila/gui/testing/ScreenTest.java | 48 +--------------- .../waila/gui/widgets/ViewportScrollable.java | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+), 45 deletions(-) create mode 100644 mcp/mobius/waila/gui/widgets/ViewportScrollable.java diff --git a/mcp/mobius/waila/gui/testing/ScreenTest.java b/mcp/mobius/waila/gui/testing/ScreenTest.java index 6d6b460..265cfbd 100644 --- a/mcp/mobius/waila/gui/testing/ScreenTest.java +++ b/mcp/mobius/waila/gui/testing/ScreenTest.java @@ -12,6 +12,7 @@ import mcp.mobius.waila.gui.widgets.LabelFixedFont; import mcp.mobius.waila.gui.widgets.LayoutCropping; import mcp.mobius.waila.gui.widgets.PictureDisplay; import mcp.mobius.waila.gui.widgets.PictureSwitch; +import mcp.mobius.waila.gui.widgets.ViewportScrollable; import mcp.mobius.waila.gui.widgets.WidgetBase; import mcp.mobius.waila.gui.widgets.WidgetGeometry; import mcp.mobius.waila.gui.widgets.buttons.ButtonBoolean; @@ -26,53 +27,10 @@ import net.minecraft.item.ItemStack; public class ScreenTest extends ScreenBase { - public class SubLayout extends WidgetBase{ - - IWidget attachedWidget = null; - int yOffset = 0; - int step = 5; - - public SubLayout( IWidget parent){ - super(parent); - this.addWidget("Cropping", new LayoutCropping(null)).setGeometry(new WidgetGeometry(50.0,50.0,100.0,100.0,CType.RELXY, CType.RELXY, WAlign.CENTER, WAlign.CENTER)); - } - - public IWidget attachWidget(IWidget widget){ - this.attachedWidget = this.getWidget("Cropping").addWidget("Cropped", widget); - return this.attachedWidget; - } - - public IWidget getAttachedWidget(){ - return this.attachedWidget; - } - - public IWidget setStep(int step){ - this.step = step; - return this; - } - - @Override - public void draw(Point pos) {} - - @Override - public void onMouseWheel(MouseEvent event){ - this.yOffset += event.z / 120.0 * this.step; - - this.yOffset = Math.max(this.yOffset, this.getSize().getY() - this.attachedWidget.getSize().getY()); - this.yOffset = Math.min(this.yOffset, 0); - - ((LayoutCropping)this.getWidget("Cropping")).setOffsets(0, this.yOffset); - } - } - public ScreenTest(GuiScreen parent) { super(parent); - this.getRoot().addWidget("Layout", new SubLayout(null)).setGeometry(new WidgetGeometry(50.0,50.0,50.0,50.0,CType.ABSXY, CType.RELXY, WAlign.TOP, WAlign.LEFT)); - ((SubLayout)this.getRoot().getWidget("Layout")).attachWidget(new PictureSwitch(this.getRoot(), "waila:textures/test.png", "waila:textures/test_solar.png")).getGeometry().setSize(300, 300); - - //this.getRoot().addWidget("Layout", new LayoutCropping(null)).setGeometry(new WidgetGeometry(50.0,50.0,50.0,50.0,CType.ABSXY, CType.RELXY, WAlign.TOP, WAlign.LEFT)); - //this.getRoot().getWidget("Layout").addWidget("Picture", new PictureSwitch(this.getRoot(), "waila:textures/test.png", "waila:textures/test_solar.png")).getGeometry().setSize(300, 300); - //this.getRoot().addWidget("Picture", new ItemStackDisplay(null, new ItemStack(Block.dirt, 8))).setGeometry(new WidgetGeometry(50.0,50.0,75.0,75.0,CType.RELXY, CType.ABSXY, WAlign.CENTER, WAlign.CENTER)); + this.getRoot().addWidget("Layout", new ViewportScrollable(null)).setGeometry(new WidgetGeometry(50.0,50.0,50.0,50.0,CType.ABSXY, CType.RELXY, WAlign.TOP, WAlign.LEFT)); + ((ViewportScrollable)this.getRoot().getWidget("Layout")).attachWidget(new PictureSwitch(this.getRoot(), "waila:textures/test.png", "waila:textures/test_solar.png")).getGeometry().setSize(300, 300); } } diff --git a/mcp/mobius/waila/gui/widgets/ViewportScrollable.java b/mcp/mobius/waila/gui/widgets/ViewportScrollable.java new file mode 100644 index 0000000..6a344fd --- /dev/null +++ b/mcp/mobius/waila/gui/widgets/ViewportScrollable.java @@ -0,0 +1,56 @@ +package mcp.mobius.waila.gui.widgets; + +import mcp.mobius.waila.gui.events.MouseEvent; +import mcp.mobius.waila.gui.interfaces.CType; +import mcp.mobius.waila.gui.interfaces.IWidget; +import mcp.mobius.waila.gui.interfaces.WAlign; + +import org.lwjgl.util.Point; + +public class ViewportScrollable extends WidgetBase { + + public class Escalator extends WidgetBase{ + public Escalator(IWidget parent){ + this.parent = parent; + } + + @Override + public void draw(Point pos) {} + } + + IWidget attachedWidget = null; + int yOffset = 0; + int step = 5; + + public ViewportScrollable( IWidget parent){ + super(parent); + this.addWidget("Cropping", new LayoutCropping(null)).setGeometry(new WidgetGeometry(50.0,50.0,100.0,100.0,CType.RELXY, CType.RELXY, WAlign.CENTER, WAlign.CENTER)); + } + + public IWidget attachWidget(IWidget widget){ + this.attachedWidget = this.getWidget("Cropping").addWidget("Cropped", widget); + return this.attachedWidget; + } + + public IWidget getAttachedWidget(){ + return this.attachedWidget; + } + + public IWidget setStep(int step){ + this.step = step; + return this; + } + + @Override + public void draw(Point pos) {} + + @Override + public void onMouseWheel(MouseEvent event){ + this.yOffset += event.z / 120.0 * this.step; + + this.yOffset = Math.max(this.yOffset, this.getSize().getY() - this.attachedWidget.getSize().getY()); + this.yOffset = Math.min(this.yOffset, 0); + + ((LayoutCropping)this.getWidget("Cropping")).setOffsets(0, this.yOffset); + } +}