Added a PictureMovable widget, that you can drag and drop around. Area of action is constrainted by the parent.

Added getTop() getBottom() to IWidget interface (shortcuts for getPos().getY() and getPos().getY() + getSize().getY() )
This commit is contained in:
Thomas Guimbretiere committed 2013-10-19 15:38:51 +02:00
1 parent e681b98231
commit 24efba751d
6 files changed
+57 -10

No files matched your search

+7 -7
View File
@@ -41,14 +41,14 @@ public class ConfigKeyHandler extends KeyHandler {
new KeyBinding(Constants.BIND_WAILA_LIQUID, Keyboard.KEY_NUMPAD2),
new KeyBinding(Constants.BIND_WAILA_RECIPE, Keyboard.KEY_NUMPAD3),
new KeyBinding(Constants.BIND_WAILA_USAGE, Keyboard.KEY_NUMPAD4),
//new KeyBinding(Constants.BIND_WAILA_TESTING, Keyboard.KEY_NUMPAD9),
new KeyBinding(Constants.BIND_WAILA_TESTING, Keyboard.KEY_NUMPAD9),
}, new boolean[]{
false,
false,
false,
false,
false,
//false
false
});
LanguageRegistry.instance().addStringLocalization(Constants.BIND_WAILA_CFG, "[Waila] Config screen");
@@ -56,7 +56,7 @@ public class ConfigKeyHandler extends KeyHandler {
LanguageRegistry.instance().addStringLocalization(Constants.BIND_WAILA_LIQUID, "[Waila] Show liquids");
LanguageRegistry.instance().addStringLocalization(Constants.BIND_WAILA_RECIPE, "[Waila] Show recipe");
LanguageRegistry.instance().addStringLocalization(Constants.BIND_WAILA_USAGE, "[Waila] Show usage");
//LanguageRegistry.instance().addStringLocalization(Constants.BIND_WAILA_TESTING, "[Waila] Testing");
LanguageRegistry.instance().addStringLocalization(Constants.BIND_WAILA_TESTING, "[Waila] Testing");
//LanguageRegistry.instance().addStringLocalization("key.wailatedump", "[Waila] Dump server TE");
}
@@ -69,10 +69,10 @@ public class ConfigKeyHandler extends KeyHandler {
mc.displayGuiScreen(new ScreenConfig(mc.currentScreen));
}
//if (kb.keyDescription == Constants.BIND_WAILA_TESTING){
// if(mc.currentScreen == null)
// mc.displayGuiScreen(new ScreenConfig(mc.currentScreen));
//}
if (kb.keyDescription == Constants.BIND_WAILA_TESTING){
if(mc.currentScreen == null)
mc.displayGuiScreen(new ScreenTest(mc.currentScreen));
}
if (mc.currentScreen != null)
return;
@@ -19,6 +19,8 @@ public interface IWidget {
Point getSize();
int getRight();
int getLeft();
int getTop();
int getBottom();
void draw();
void draw(Point pos);
+3 -2
View File
@@ -3,6 +3,7 @@ package mcp.mobius.waila.gui.testing;
import mcp.mobius.waila.gui.screens.ScreenBase;
import mcp.mobius.waila.gui.widgets.LabelFixedFont;
import mcp.mobius.waila.gui.widgets.PictureDisplay;
import mcp.mobius.waila.gui.widgets.PictureMovable;
import mcp.mobius.waila.gui.widgets.PictureSwitch;
import mcp.mobius.waila.gui.widgets.WidgetGeometry;
import mcp.mobius.waila.gui.widgets.buttons.ButtonBoolean;
@@ -16,7 +17,7 @@ public class ScreenTest extends ScreenBase {
public ScreenTest(GuiScreen parent) {
super(parent);
this.getRoot().addWidget("Button", new ButtonScreenChange(this.getRoot(), "Next screen", new ScreenTest2(this)));
this.getRoot().getWidget("Button").setGeometry(new WidgetGeometry(50.0, 50.0, 100.0, 20.0, true, false, WidgetGeometry.Align.CENTER, WidgetGeometry.Align.CENTER));
this.getRoot().addWidget("Picture", new PictureMovable(this.getRoot(), "waila:textures/test.png"));
}
}
@@ -10,7 +10,7 @@ import org.lwjgl.util.Point;
public class PictureDisplay extends WidgetBase {
private ResourceLocation texture;
protected ResourceLocation texture;
public PictureDisplay(IWidget parent, String uri){
super(parent);
@@ -0,0 +1,39 @@
package mcp.mobius.waila.gui.widgets;
import mcp.mobius.waila.gui.events.MouseEvent;
import mcp.mobius.waila.gui.interfaces.IWidget;
import org.lwjgl.util.Point;
public class PictureMovable extends PictureDisplay {
private int offsetX, offsetY;
public PictureMovable(IWidget parent, String uri) {
super(parent, uri);
}
@Override
public void onMouseClick(MouseEvent event){
this.offsetX = event.x - this.getPos().getX();
this.offsetY = event.y - this.getPos().getY();
}
@Override
public void onMouseDrag(MouseEvent event){
int newX = event.x - this.offsetX;
int newY = event.y - this.offsetY;
newX = Math.max(newX, this.parent.getLeft());
newY = Math.max(newY, this.parent.getTop());
if (newX + this.getSize().getX() > this.parent.getRight())
newX = this.parent.getRight() - this.getSize().getX();
if (newY + this.getSize().getY() > this.parent.getBottom())
newY = this.parent.getBottom() - this.getSize().getY();
this.setGeometry(new WidgetGeometry(newX, newY, this.getSize().getX(), this.getSize().getY(),
false, false, this.geom.fracSizeX, this.geom.fracSizeY, this.geom.alignX, this.geom.alignY));
}
}
@@ -118,6 +118,11 @@ public abstract class WidgetBase implements IWidget {
public int getLeft() { return this.getPos().getX(); }
@Override
public int getRight() { return this.getPos().getX() + this.getSize().getX(); }
@Override
public int getTop() { return this.getPos().getY(); }
@Override
public int getBottom() { return this.getPos().getY() + this.getSize().getY(); }
////////////////////////////
// SOME RENDERING HELPERS //