Added inverted lookup for MouseWheel.

getWidgetAtPosition does return the deepest widget, so mouse events should check the parent for implementation, not the childrens !
This commit is contained in:
Thomas Guimbretiere committed 2013-10-23 20:09:27 +02:00
1 parent 83c7ef6aa9
commit b2cc1e02d7
6 files changed
+67 -7

No files matched your search

+2 -1
View File
@@ -36,7 +36,8 @@ public class MouseEvent {
//System.out.printf("%s %s\n", this.x, this.y);
this.z = Mouse.getEventDWheel();
//this.z = Mouse.getEventDWheel();
this.z = Mouse.getDWheel();
for (int i = 0; i < buttonCount; i++)
buttonState[i] = Mouse.isButtonDown(i);
+40 -2
View File
@@ -1,6 +1,10 @@
package mcp.mobius.waila.gui.testing;
import org.lwjgl.util.Point;
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 mcp.mobius.waila.gui.screens.ScreenBase;
import mcp.mobius.waila.gui.widgets.ItemStackDisplay;
@@ -8,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.WidgetBase;
import mcp.mobius.waila.gui.widgets.WidgetGeometry;
import mcp.mobius.waila.gui.widgets.buttons.ButtonBoolean;
import mcp.mobius.waila.gui.widgets.buttons.ButtonContainerLabel;
@@ -21,11 +26,44 @@ import net.minecraft.item.ItemStack;
public class ScreenTest extends ScreenBase {
public class SubLayout extends WidgetBase{
IWidget attachedWidget = null;
int yOffset = 0;
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;
}
@Override
public void draw(Point pos) {}
@Override
public void onMouseWheel(MouseEvent event){
this.yOffset += event.z / 120.0;
System.out.println(this.yOffset);
((LayoutCropping)this.getWidget("Cropping")).setOffsets(0, this.yOffset);
}
}
public ScreenTest(GuiScreen parent) {
super(parent);
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("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));
}
}
@@ -61,7 +61,8 @@ public class LayoutCanvas extends WidgetBase{
this.onMouseRelease(event);
break;
case WHEEL:
this.onMouseWheel(event);
this.getWidgetAtCoordinates(event.x, event.y).onMouseWheel(event);
//this.onMouseWheel(event);
break;
case ENTER:
if (event.trgwidget != null)
@@ -8,10 +8,18 @@ import org.lwjgl.util.Point;
public class LayoutCropping extends WidgetBase {
int xOffset = 0;
int yOffset = 0;
public LayoutCropping(IWidget parent){
super(parent);
}
public void setOffsets(int xoffset, int yoffset){
this.xOffset = xoffset;
this.yOffset = yoffset;
}
@Override
public void draw(){
this.rez = new ScaledResolution(mc.gameSettings, mc.displayWidth, mc.displayHeight);
@@ -26,6 +34,8 @@ public class LayoutCropping extends WidgetBase {
GL11.glEnable(GL11.GL_SCISSOR_TEST);
GL11.glScissor(this.getPos().getX()*this.rez.getScaleFactor(), this.rez.getScaledHeight() - this.getPos().getY()*this.rez.getScaleFactor(), this.getSize().getX()*this.rez.getScaleFactor(), this.getSize().getY()*this.rez.getScaleFactor());
GL11.glTranslatef(xOffset, yOffset, 0.0f);
for (IWidget widget: this.widgets.values())
if (widget.shouldRender())
widget.draw();
+6 -2
View File
@@ -228,11 +228,15 @@ public abstract class WidgetBase implements IWidget {
@Override
public void onMouseWheel(MouseEvent event) {
//System.out.printf("%s %s\n", this, event);
System.out.printf("%s %s\n", this, event);
if (this.parent != null)
this.parent.onMouseWheel(event);
/*
IWidget widget = this.getWidgetAtCoordinates(event.x, event.y);
if (widget != null && widget != this)
widget.onMouseWheel(event);
widget.onMouseWheel(event);
*/
}
@Override
@@ -9,7 +9,8 @@ import org.lwjgl.util.Point;
public class WidgetGeometry {
//public class WidgetGeometry implements Cloneable{
public class WidgetGeometry{
//public enum Align {LEFT, CENTER, RIGHT, TOP, BOTTOM};
@@ -184,4 +185,9 @@ public class WidgetGeometry {
public String toString(){
return String.format("Geometry : [%s %s] [%s %s] [%s %s] [%s %s]", this.x, this.y, this.sx, this.sy, this.posType, this.sizeType, this.alignX, this.alignY);
}
//@Override
//public WidgetGeometry clone() throws CloneNotSupportedException{
// return (WidgetGeometry)super.clone();
//}
}