mirror of
https://github.com/GTNewHorizons/waila.git
synced 2026-11-20 20:22:28 +00:00
Added a PictureSwitch widget, switching between 2 pictures on mouse over.
This commit is contained in:
1 parent
d23855b263
commit
8a5dc45240
2 files changed
+49
-1
No files matched your search
@@ -2,6 +2,7 @@ package mcp.mobius.waila.gui;
|
||||
|
||||
import mcp.mobius.waila.gui.widgets.LabelFixedFont;
|
||||
import mcp.mobius.waila.gui.widgets.PictureDisplay;
|
||||
import mcp.mobius.waila.gui.widgets.PictureSwitch;
|
||||
import mcp.mobius.waila.gui.widgets.WidgetGeometry;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
@@ -9,7 +10,7 @@ public class ScreenTest extends ScreenBase {
|
||||
|
||||
public ScreenTest(GuiScreen parent) {
|
||||
super(parent);
|
||||
this.getRoot().addWidget("Picture", new PictureDisplay(this.getRoot(), "waila:textures/test.png"));
|
||||
this.getRoot().addWidget("Picture", new PictureSwitch(this.getRoot(), "waila:textures/test.png", "waila:textures/test_solar.png"));
|
||||
this.getRoot().getWidget("Picture").setGeometry(new WidgetGeometry(50.0, 50.0, 25.0, 25.0, true, true, WidgetGeometry.Align.CENTER, WidgetGeometry.Align.CENTER));
|
||||
|
||||
this.getRoot().addWidget("Text", new LabelFixedFont(this.getRoot(), "waila:textures/test.png"));
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package mcp.mobius.waila.gui.widgets;
|
||||
|
||||
import mcp.mobius.waila.gui.events.MouseEvent;
|
||||
import mcp.mobius.waila.gui.helpers.UIHelper;
|
||||
import mcp.mobius.waila.gui.interfaces.IWidget;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.util.Point;
|
||||
|
||||
public class PictureSwitch extends WidgetBase {
|
||||
|
||||
private ResourceLocation texture1;
|
||||
private ResourceLocation texture2;
|
||||
private boolean mouseOver = false;
|
||||
|
||||
public PictureSwitch(IWidget parent, String uri1, String uri2){
|
||||
super(parent);
|
||||
this.texture1 = new ResourceLocation(uri1);
|
||||
this.texture2 = new ResourceLocation(uri2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Point pos) {
|
||||
this.saveGLState();
|
||||
|
||||
ResourceLocation texture = mouseOver ? this.texture2 : this.texture1;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
this.texManager.func_110577_a(texture);
|
||||
UIHelper.drawTexture(pos.getX(), pos.getY(), this.getSize().getX(), this.getSize().getY());
|
||||
GL11.glPopMatrix();
|
||||
|
||||
this.loadGLState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseEnter(MouseEvent event){
|
||||
mouseOver = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMouseLeave(MouseEvent event){
|
||||
mouseOver = false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user