Fix #149 GUI scrollbar working differently

This commit is contained in:
Nedelosk committed 2017-06-24 15:22:29 +02:00
1 parent bbc87beb38
commit 866e8d0711
3 files changed
+6 -6

No files matched your search

@@ -25,7 +25,7 @@ public class ControlScrollBar extends Control {
this.addSelfEventHandler(new EventMouse.Drag.Handler() {
@Override
public void onEvent(final EventMouse.Drag event) {
ControlScrollBar.this.scrollable.movePercentage(event.getDy() / (ControlScrollBar.this.height() - ControlScrollBar.this.getBarHeight()));
ControlScrollBar.this.scrollable.movePercentage(event.getDy() / (float) (ControlScrollBar.this.height() - ControlScrollBar.this.getBarHeight()));
}
});
this.addSelfEventHandler(new EventMouse.Down.Handler() {
@@ -35,13 +35,13 @@ public class ControlScrollBar extends Control {
final float percentageIndex = ControlScrollBar.this.scrollable.getPercentageIndex();
final float minPercent = (1.0f - shownPercentage) * percentageIndex;
final float maxPercent = minPercent + shownPercentage;
float clickedPercentage = ControlScrollBar.this.getRelativeMousePosition().y() / (ControlScrollBar.this.height() - 2.0f);
float clickedPercentage = (float)ControlScrollBar.this.getRelativeMousePosition().y() / (float) (ControlScrollBar.this.height() - 2.0f);
clickedPercentage = Math.max(Math.min(clickedPercentage, 1.0f), 0.0f);
if (clickedPercentage > maxPercent) {
ControlScrollBar.this.scrollable.setPercentageIndex((clickedPercentage - shownPercentage) / (1.0f - shownPercentage));
ControlScrollBar.this.scrollable.setPercentageIndex((float) (clickedPercentage - shownPercentage) / (float) (1.0f - shownPercentage));
}
if (clickedPercentage < minPercent) {
ControlScrollBar.this.scrollable.setPercentageIndex(clickedPercentage / (1.0f - shownPercentage));
ControlScrollBar.this.scrollable.setPercentageIndex(clickedPercentage / (float) (1.0f - shownPercentage));
}
}
});
@@ -65,7 +65,7 @@ public class ControlScrollableContent<T extends IWidget> extends Control impleme
if (this.controlChild == null || this.controlChild.getSize().y() == 0) {
return 1;
}
final float shown = this.getSize().y() / this.controlChild.getSize().y();
float shown = (float)this.getSize().y() / (float) this.controlChild.getSize().y();
return Math.min(shown, 1);
}
@@ -252,7 +252,7 @@ public class GuiCraftGUI extends GuiContainer {
//@Override
protected void mouseMovedOrUp(final int x, final int y, final int button) {
final IWidget origin = (this.window.getMousedOverWidget() == null) ? this.window : this.window.getMousedOverWidget();
if (button == -1) {
if (button == 0) {
final float dx = Mouse.getEventDX() * this.width / (float) this.mc.displayWidth;
final float dy = -(Mouse.getEventDY() * this.height / (float) this.mc.displayHeight);
} else {