Skip to content

Commit

Permalink
More utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Dec 15, 2018
1 parent 09533cf commit 0c1f8a9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 11 deletions.
10 changes: 10 additions & 0 deletions src/main/java/mchorse/mclib/client/gui/utils/Area.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mchorse.mclib.client.gui.utils;

import net.minecraft.client.gui.Gui;

/**
* Utility class for boxes
*
Expand Down Expand Up @@ -88,4 +90,12 @@ public int getY(float anchor)
{
return this.y + (int) (this.h * anchor);
}

/**
* Draw a rect within the bound of this rect
*/
public void draw(int color)
{
Gui.drawRect(this.x, this.y, this.getX(1), this.getY(1), color);
}
}
67 changes: 67 additions & 0 deletions src/main/java/mchorse/mclib/client/gui/utils/GuiDrawable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package mchorse.mclib.client.gui.utils;

import java.util.function.Consumer;

import mchorse.mclib.client.gui.framework.GuiTooltip;
import mchorse.mclib.client.gui.framework.elements.IGuiElement;

public class GuiDrawable implements IGuiElement
{
public Consumer<Void> callback;

public GuiDrawable(Consumer<Void> callback)
{
this.callback = callback;
}

@Override
public void resize(int width, int height)
{}

@Override
public boolean isEnabled()
{
return false;
}

@Override
public boolean isVisible()
{
return true;
}

@Override
public boolean mouseClicked(int mouseX, int mouseY, int mouseButton)
{
return false;
}

@Override
public boolean mouseScrolled(int mouseX, int mouseY, int scroll)
{
return false;
}

@Override
public void mouseReleased(int mouseX, int mouseY, int state)
{}

@Override
public boolean hasActiveTextfields()
{
return false;
}

@Override
public void keyTyped(char typedChar, int keyCode)
{}

@Override
public void draw(GuiTooltip tooltip, int mouseX, int mouseY, float partialTicks)
{
if (this.callback != null)
{
this.callback.accept(null);
}
}
}
17 changes: 6 additions & 11 deletions src/main/java/mchorse/mclib/client/gui/utils/Resizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,17 @@ public class Resizer

public Resizer set(float x, float y, float w, float h)
{
this.x.value = x;
this.y.value = y;
this.w.value = w;
this.h.value = h;

return this;
return this.set(x, y, w, h, Measure.PIXELS);
}

public Resizer set(float x, float y, float w, float h, Measure measure)
{
this.x.unit = measure;
this.y.unit = measure;
this.w.unit = measure;
this.h.unit = measure;
this.x.set(x, measure);
this.y.set(y, measure);
this.w.set(w, measure);
this.h.set(h, measure);

return this.set(x, y, w, h);
return this;
}

public Resizer x(int value)
Expand Down

0 comments on commit 0c1f8a9

Please sign in to comment.