mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-25 14:34:33 +00:00
port to forestry 4.2
This commit is contained in:
1 parent
dbc5c1a564
commit
f969f63b66
3697 files changed
+78372
No files matched your search
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.controls.scroll;
|
||||
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.controls.core.Control;
|
||||
|
||||
public class ControlScroll extends Control
|
||||
{
|
||||
private IControlScrollable scrollWidget;
|
||||
|
||||
public ControlScroll(final IWidget parent, final float x, final float y, final float width, final float height, final IControlScrollable scrollWidget) {
|
||||
super(parent, x, y, width, height);
|
||||
this.scrollWidget = scrollWidget;
|
||||
new ControlScrollBar(this);
|
||||
}
|
||||
|
||||
public IControlScrollable getScrollableWidget() {
|
||||
return this.scrollWidget;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.controls.scroll;
|
||||
|
||||
import binnie.craftgui.core.CraftGUI;
|
||||
import binnie.craftgui.resource.minecraft.CraftGUITexture;
|
||||
import binnie.craftgui.core.geometry.IArea;
|
||||
import binnie.craftgui.events.EventMouse;
|
||||
import binnie.craftgui.core.Attribute;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
import binnie.craftgui.controls.core.Control;
|
||||
|
||||
public class ControlScrollBar extends Control
|
||||
{
|
||||
protected final IControlScrollable scrollable;
|
||||
|
||||
public ControlScrollBar(final ControlScroll parent) {
|
||||
this(parent, 0.0f, 0.0f, parent.getSize().x(), parent.getSize().y(), parent.getScrollableWidget());
|
||||
}
|
||||
|
||||
public ControlScrollBar(final IWidget parent, final float x, final float y, final float w, final float h, final IControlScrollable scrollable2) {
|
||||
super(parent, x, y, w, h);
|
||||
this.scrollable = scrollable2;
|
||||
this.addAttribute(Attribute.MouseOver);
|
||||
this.addSelfEventHandler(new EventMouse.Drag.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventMouse.Drag event) {
|
||||
ControlScrollBar.this.scrollable.movePercentage(event.getDy() / (ControlScrollBar.this.h() - ControlScrollBar.this.getBarHeight()));
|
||||
}
|
||||
});
|
||||
this.addSelfEventHandler(new EventMouse.Down.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventMouse.Down event) {
|
||||
final float shownPercentage = ControlScrollBar.this.scrollable.getPercentageShown();
|
||||
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.h() - 2.0f);
|
||||
clickedPercentage = Math.max(Math.min(clickedPercentage, 1.0f), 0.0f);
|
||||
if (clickedPercentage > maxPercent) {
|
||||
ControlScrollBar.this.scrollable.setPercentageIndex((clickedPercentage - shownPercentage) / (1.0f - shownPercentage));
|
||||
}
|
||||
if (clickedPercentage < minPercent) {
|
||||
ControlScrollBar.this.scrollable.setPercentageIndex(clickedPercentage / (1.0f - shownPercentage));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.scrollable.getPercentageShown() < 0.99f;
|
||||
}
|
||||
|
||||
public float getBarHeight() {
|
||||
return this.h() * this.scrollable.getPercentageShown();
|
||||
}
|
||||
|
||||
protected IArea getRenderArea() {
|
||||
float height = this.getBarHeight();
|
||||
if (height < 6.0f) {
|
||||
height = 6.0f;
|
||||
}
|
||||
final float yOffset = ((int) this.h() - (int) this.getBarHeight()) * this.scrollable.getPercentageIndex();
|
||||
return new IArea(0.0f, yOffset, this.getSize().x(), height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRenderBackground() {
|
||||
final IArea renderArea = this.getRenderArea();
|
||||
Object texture = CraftGUITexture.ScrollDisabled;
|
||||
if (this.isMouseOver()) {
|
||||
texture = CraftGUITexture.ScrollHighlighted;
|
||||
}
|
||||
else if (this.isEnabled()) {
|
||||
texture = CraftGUITexture.Scroll;
|
||||
}
|
||||
CraftGUI.Render.texture(texture, renderArea);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.controls.scroll;
|
||||
|
||||
import binnie.craftgui.core.geometry.IPoint;
|
||||
import binnie.craftgui.events.EventWidget;
|
||||
import binnie.craftgui.core.geometry.IArea;
|
||||
import binnie.craftgui.events.EventMouse;
|
||||
import binnie.craftgui.controls.core.Control;
|
||||
import binnie.craftgui.core.IWidget;
|
||||
|
||||
public class ControlScrollableContent<T extends IWidget> extends Control implements IControlScrollable
|
||||
{
|
||||
protected T controlChild;
|
||||
protected float scrollBarSize;
|
||||
float percentageIndex;
|
||||
|
||||
public ControlScrollableContent(final IWidget parent, final float x, final float y, final float w, final float h, final float scrollBarSize) {
|
||||
super(parent, x, y, w, h);
|
||||
this.percentageIndex = 0.0f;
|
||||
if (scrollBarSize != 0.0f) {
|
||||
new ControlScroll(this, this.getSize().x() - scrollBarSize, 0.0f, scrollBarSize, this.getSize().y(), this);
|
||||
}
|
||||
this.addEventHandler(new EventMouse.Wheel.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventMouse.Wheel event) {
|
||||
if (ControlScrollableContent.this.getRelativeMousePosition().x() > 0.0f && ControlScrollableContent.this.getRelativeMousePosition().y() > 0.0f && ControlScrollableContent.this.getRelativeMousePosition().x() < ControlScrollableContent.this.getSize().x() && ControlScrollableContent.this.getRelativeMousePosition().y() < ControlScrollableContent.this.getSize().y()) {
|
||||
if (ControlScrollableContent.this.getMovementRange() == 0.0f) {
|
||||
return;
|
||||
}
|
||||
final float percentageMove = 0.8f / ControlScrollableContent.this.getMovementRange();
|
||||
ControlScrollableContent.this.movePercentage(percentageMove * -event.getDWheel());
|
||||
}
|
||||
}
|
||||
});
|
||||
this.scrollBarSize = scrollBarSize;
|
||||
}
|
||||
|
||||
public void setScrollableContent(final T child) {
|
||||
this.controlChild = child;
|
||||
if (child == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
child.setCroppedZone(this, new IArea(1.0F, 1.0F, getSize().x() - 2.0F - this.scrollBarSize, getSize().y() - 2.0F));
|
||||
|
||||
child.addSelfEventHandler(new EventWidget.ChangeSize.Handler() {
|
||||
@Override
|
||||
public void onEvent(final EventWidget.ChangeSize event) {
|
||||
ControlScrollableContent.this.controlChild.setOffset(new IPoint(0.0f, -ControlScrollableContent.this.percentageIndex * ControlScrollableContent.this.getMovementRange()));
|
||||
if (ControlScrollableContent.this.getMovementRange() == 0.0f) {
|
||||
ControlScrollableContent.this.percentageIndex = 0.0f;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public T getContent() {
|
||||
return this.controlChild;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPercentageShown() {
|
||||
if (this.controlChild == null || this.controlChild.getSize().y() == 0.0f) {
|
||||
return 1.0f;
|
||||
}
|
||||
final float shown = this.getSize().y() / this.controlChild.getSize().y();
|
||||
return Math.min(shown, 1.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPercentageIndex() {
|
||||
return this.percentageIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePercentage(final float percentage) {
|
||||
if (this.controlChild == null) {
|
||||
return;
|
||||
}
|
||||
this.percentageIndex += percentage;
|
||||
if (this.percentageIndex > 1.0f) {
|
||||
this.percentageIndex = 1.0f;
|
||||
}
|
||||
else if (this.percentageIndex < 0.0f) {
|
||||
this.percentageIndex = 0.0f;
|
||||
}
|
||||
if (this.getMovementRange() == 0.0f) {
|
||||
this.percentageIndex = 0.0f;
|
||||
}
|
||||
this.controlChild.setOffset(new IPoint(0.0f, -this.percentageIndex * this.getMovementRange()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPercentageIndex(final float index) {
|
||||
this.movePercentage(index - this.percentageIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMovementRange() {
|
||||
if (this.controlChild == null) {
|
||||
return 0.0f;
|
||||
}
|
||||
final float range = this.controlChild.getSize().y() - this.getSize().y();
|
||||
return Math.max(range, 0.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateClient() {
|
||||
this.setPercentageIndex(this.getPercentageIndex());
|
||||
}
|
||||
|
||||
public void ensureVisible(float minY, float maxY, final float totalY) {
|
||||
minY /= totalY;
|
||||
maxY /= totalY;
|
||||
final float shownPercentage = this.getPercentageShown();
|
||||
final float percentageIndex = this.getPercentageIndex();
|
||||
final float minPercent = (1.0f - shownPercentage) * percentageIndex;
|
||||
final float maxPercent = minPercent + shownPercentage;
|
||||
if (maxY > maxPercent) {
|
||||
this.setPercentageIndex((maxY - shownPercentage) / (1.0f - shownPercentage));
|
||||
}
|
||||
if (minY < minPercent) {
|
||||
this.setPercentageIndex(minY / (1.0f - shownPercentage));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Decompiled by Procyon v0.5.30
|
||||
//
|
||||
|
||||
package binnie.craftgui.controls.scroll;
|
||||
|
||||
import binnie.craftgui.core.IWidget;
|
||||
|
||||
public interface IControlScrollable extends IWidget
|
||||
{
|
||||
float getPercentageShown();
|
||||
|
||||
float getPercentageIndex();
|
||||
|
||||
void movePercentage(final float p0);
|
||||
|
||||
void setPercentageIndex(final float p0);
|
||||
|
||||
float getMovementRange();
|
||||
}
|
||||
Reference in new issue
Block a user