From 145f96749fb4038187d6e68077ea941c6df63f77 Mon Sep 17 00:00:00 2001 From: johni0702 Date: Sat, 20 Feb 2016 16:11:56 +0100 Subject: [PATCH] Move GUI framework to subproject --- .gitmodules | 3 + build.gradle | 2 + jGui | 1 + settings.gradle | 1 + .../johni0702/minecraft/gui/GuiRenderer.java | 71 -- .../minecraft/gui/MinecraftGuiRenderer.java | 204 ------ .../minecraft/gui/OffsetGuiRenderer.java | 203 ------ .../johni0702/minecraft/gui/RenderInfo.java | 51 -- .../AbstractGuiClickableContainer.java | 81 --- .../gui/container/AbstractGuiContainer.java | 271 ------- .../gui/container/AbstractGuiOverlay.java | 253 ------- .../gui/container/AbstractGuiScreen.java | 231 ------ .../gui/container/AbstractGuiScrollable.java | 154 ---- .../container/AbstractGuiVerticalList.java | 205 ------ .../minecraft/gui/container/GuiClickable.java | 38 - .../minecraft/gui/container/GuiContainer.java | 50 -- .../minecraft/gui/container/GuiOverlay.java | 30 - .../minecraft/gui/container/GuiPanel.java | 57 -- .../minecraft/gui/container/GuiScreen.java | 47 -- .../gui/container/GuiScrollable.java | 30 - .../gui/container/GuiVerticalList.java | 37 - .../element/AbstractComposedGuiElement.java | 178 ----- .../gui/element/AbstractGuiButton.java | 107 --- .../gui/element/AbstractGuiCheckbox.java | 112 --- .../gui/element/AbstractGuiClickable.java | 79 -- .../gui/element/AbstractGuiElement.java | 179 ----- .../gui/element/AbstractGuiImage.java | 177 ----- .../gui/element/AbstractGuiLabel.java | 96 --- .../gui/element/AbstractGuiNumberField.java | 129 ---- .../gui/element/AbstractGuiPasswordField.java | 46 -- .../gui/element/AbstractGuiSlider.java | 189 ----- .../gui/element/AbstractGuiTextField.java | 602 ---------------- .../element/AbstractGuiTexturedButton.java | 218 ------ .../gui/element/AbstractGuiToggleButton.java | 77 -- .../gui/element/AbstractGuiTooltip.java | 109 --- .../gui/element/ComposedGuiElement.java | 40 -- .../minecraft/gui/element/GuiButton.java | 39 - .../minecraft/gui/element/GuiCheckbox.java | 39 - .../minecraft/gui/element/GuiElement.java | 60 -- .../minecraft/gui/element/GuiImage.java | 43 -- .../minecraft/gui/element/GuiLabel.java | 39 - .../minecraft/gui/element/GuiNumberField.java | 39 - .../gui/element/GuiPasswordField.java | 39 - .../minecraft/gui/element/GuiSlider.java | 39 - .../minecraft/gui/element/GuiTextField.java | 39 - .../gui/element/GuiTexturedButton.java | 39 - .../gui/element/GuiToggleButton.java | 39 - .../minecraft/gui/element/GuiTooltip.java | 30 - .../minecraft/gui/element/IGuiButton.java | 31 - .../minecraft/gui/element/IGuiCheckbox.java | 35 - .../minecraft/gui/element/IGuiClickable.java | 27 - .../minecraft/gui/element/IGuiImage.java | 41 -- .../minecraft/gui/element/IGuiLabel.java | 41 -- .../gui/element/IGuiNumberField.java | 43 -- .../minecraft/gui/element/IGuiSlider.java | 36 - .../minecraft/gui/element/IGuiTextField.java | 166 ----- .../gui/element/IGuiTexturedButton.java | 50 -- .../gui/element/IGuiToggleButton.java | 35 - .../advanced/AbstractGuiDropdownMenu.java | 247 ------- .../advanced/AbstractGuiProgressBar.java | 89 --- .../AbstractGuiResourceLoadingList.java | 218 ------ .../element/advanced/AbstractGuiTextArea.java | 679 ------------------ .../element/advanced/AbstractGuiTimeline.java | 257 ------- .../gui/element/advanced/GuiDropdownMenu.java | 40 -- .../gui/element/advanced/GuiProgressBar.java | 39 - .../advanced/GuiResourceLoadingList.java | 41 -- .../gui/element/advanced/GuiTextArea.java | 39 - .../gui/element/advanced/GuiTimeline.java | 39 - .../element/advanced/IGuiDropdownMenu.java | 46 -- .../gui/element/advanced/IGuiProgressBar.java | 37 - .../gui/element/advanced/IGuiTextArea.java | 71 -- .../gui/element/advanced/IGuiTimeline.java | 88 --- .../minecraft/gui/function/Clickable.java | 29 - .../minecraft/gui/function/Closeable.java | 27 - .../minecraft/gui/function/Draggable.java | 30 - .../minecraft/gui/function/Focusable.java | 36 - .../minecraft/gui/function/Loadable.java | 27 - .../minecraft/gui/function/Scrollable.java | 36 - .../minecraft/gui/function/Tickable.java | 27 - .../minecraft/gui/function/Typeable.java | 29 - .../minecraft/gui/layout/CustomLayout.java | 131 ---- .../minecraft/gui/layout/GridLayout.java | 133 ---- .../gui/layout/HorizontalLayout.java | 123 ---- .../minecraft/gui/layout/Layout.java | 39 - .../minecraft/gui/layout/LayoutData.java | 27 - .../minecraft/gui/layout/VerticalLayout.java | 123 ---- .../minecraft/gui/layout/VoidLayoutData.java | 31 - .../minecraft/gui/popup/AbstractGuiPopup.java | 196 ----- .../minecraft/gui/popup/GuiYesNoPopup.java | 118 --- .../johni0702/minecraft/gui/utils/Colors.java | 35 - .../minecraft/gui/utils/Consumer.java | 27 - .../minecraft/gui/utils/Consumers.java | 34 - 92 files changed, 7 insertions(+), 8528 deletions(-) create mode 100644 .gitmodules create mode 160000 jGui create mode 100644 settings.gradle delete mode 100644 src/main/java/de/johni0702/minecraft/gui/GuiRenderer.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/MinecraftGuiRenderer.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/OffsetGuiRenderer.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/RenderInfo.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiClickableContainer.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiContainer.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScrollable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiVerticalList.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/GuiClickable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/GuiContainer.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/GuiOverlay.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/GuiPanel.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/GuiScreen.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/GuiScrollable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/container/GuiVerticalList.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractComposedGuiElement.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiCheckbox.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiClickable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiElement.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiImage.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiLabel.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiNumberField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiPasswordField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiSlider.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTextField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTexturedButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiToggleButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTooltip.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/ComposedGuiElement.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiCheckbox.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiElement.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiImage.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiLabel.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiNumberField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiPasswordField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiSlider.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiTextField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiTexturedButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiToggleButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/GuiTooltip.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiCheckbox.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiClickable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiImage.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiLabel.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiNumberField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiSlider.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiTextField.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiTexturedButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/IGuiToggleButton.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiDropdownMenu.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiProgressBar.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiResourceLoadingList.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTextArea.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTimeline.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiDropdownMenu.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiProgressBar.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiResourceLoadingList.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTextArea.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTimeline.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiDropdownMenu.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiProgressBar.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTextArea.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTimeline.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Clickable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Closeable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Draggable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Focusable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Loadable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Scrollable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Tickable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/function/Typeable.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/layout/CustomLayout.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/layout/GridLayout.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/layout/HorizontalLayout.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/layout/Layout.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/layout/LayoutData.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/layout/VerticalLayout.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/layout/VoidLayoutData.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/popup/AbstractGuiPopup.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/popup/GuiYesNoPopup.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/utils/Colors.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/utils/Consumer.java delete mode 100644 src/main/java/de/johni0702/minecraft/gui/utils/Consumers.java diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..32c0bfa5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "jGui"] + path = jGui + url = https://github.com/ReplayMod/jGui diff --git a/build.gradle b/build.gradle index f456006b..d2d28605 100755 --- a/build.gradle +++ b/build.gradle @@ -60,6 +60,8 @@ dependencies { compile 'org.aspectj:aspectjrt:1.8.2' + compile project(':jGui') + // you may put jars on which you depend on in ./libs // or you may define them like so.. //compile "some.group:artifact:version:classifier" diff --git a/jGui b/jGui new file mode 160000 index 00000000..74f8c219 --- /dev/null +++ b/jGui @@ -0,0 +1 @@ +Subproject commit 74f8c2197f6d2f8560e5b0a312cd547f317488e9 diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..855fec1c --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include 'jGui' \ No newline at end of file diff --git a/src/main/java/de/johni0702/minecraft/gui/GuiRenderer.java b/src/main/java/de/johni0702/minecraft/gui/GuiRenderer.java deleted file mode 100644 index 9c1b5b49..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/GuiRenderer.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui; - -import net.minecraft.client.renderer.texture.ITextureObject; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.util.ReadableColor; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -public interface GuiRenderer { - - ReadablePoint getOpenGlOffset(); - - ReadableDimension getSize(); - - void setDrawingArea(int x, int y, int width, int height); - - void bindTexture(ResourceLocation location); - - void bindTexture(ITextureObject texture); - - void drawTexturedRect(int x, int y, int u, int v, int width, int height); - - void drawTexturedRect(int x, int y, int u, int v, int width, int height, int uWidth, int vHeight, int textureWidth, int textureHeight); - - void drawRect(int x, int y, int width, int height, int color); - - void drawRect(int x, int y, int width, int height, ReadableColor color); - - void drawRect(int x, int y, int width, int height, int topLeftColor, int topRightColor, int bottomLeftColor, int bottomRightColor); - - void drawRect(int x, int y, int width, int height, ReadableColor topLeftColor, ReadableColor topRightColor, ReadableColor bottomLeftColor, ReadableColor bottomRightColor); - - int drawString(int x, int y, int color, String text); - - int drawString(int x, int y, ReadableColor color, String text); - - int drawCenteredString(int x, int y, int color, String text); - - int drawCenteredString(int x, int y, ReadableColor color, String text); - - int drawString(int x, int y, int color, String text, boolean shadow); - - int drawString(int x, int y, ReadableColor color, String text, boolean shadow); - - int drawCenteredString(int x, int y, int color, String text, boolean shadow); - - int drawCenteredString(int x, int y, ReadableColor color, String text, boolean shadow); - -} diff --git a/src/main/java/de/johni0702/minecraft/gui/MinecraftGuiRenderer.java b/src/main/java/de/johni0702/minecraft/gui/MinecraftGuiRenderer.java deleted file mode 100644 index aa60bffb..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/MinecraftGuiRenderer.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui; - -import lombok.NonNull; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.renderer.texture.ITextureObject; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.Color; -import org.lwjgl.util.*; - -import static net.minecraft.client.renderer.GlStateManager.*; -import static org.lwjgl.opengl.GL11.*; - -public class MinecraftGuiRenderer implements GuiRenderer { - - private final Gui gui = new Gui(); - - @NonNull - private final ScaledResolution size; - - public MinecraftGuiRenderer(ScaledResolution size) { - this.size = size; - } - - @Override - public ReadablePoint getOpenGlOffset() { - return new Point(0, 0); - } - - @Override - public ReadableDimension getSize() { - return new ReadableDimension() { - @Override - public int getWidth() { - return size.getScaledWidth(); - } - - @Override - public int getHeight() { - return size.getScaledHeight(); - } - - @Override - public void getSize(WritableDimension dest) { - dest.setSize(getWidth(), getHeight()); - } - }; - } - - @Override - public void setDrawingArea(int x, int y, int width, int height) { - // glScissor origin is bottom left corner whereas otherwise it's top left - y = size.getScaledHeight() - y - height; - - int f = size.getScaleFactor(); - GL11.glScissor(x * f, y * f, width * f, height * f); - } - - @Override - public void bindTexture(ResourceLocation location) { - Minecraft.getMinecraft().getTextureManager().bindTexture(location); - } - - @Override - public void bindTexture(ITextureObject texture) { - GlStateManager.bindTexture(texture.getGlTextureId()); - } - - @Override - public void drawTexturedRect(int x, int y, int u, int v, int width, int height) { - gui.drawTexturedModalRect(x, y, u, v, width, height); - } - - @Override - public void drawTexturedRect(int x, int y, int u, int v, int width, int height, int uWidth, int vHeight, int textureWidth, int textureHeight) { - GlStateManager.color(1, 1, 1); - Gui.drawScaledCustomSizeModalRect(x, y, u, v, uWidth, vHeight, width, height, textureWidth, textureHeight); - } - - @Override - public void drawRect(int x, int y, int width, int height, int color) { - Gui.drawRect(x, y, x + width, y + height, color); - GlStateManager.color(1, 1, 1); - } - - @Override - public void drawRect(int x, int y, int width, int height, ReadableColor color) { - drawRect(x, y, width, height, color(color)); - } - - @Override - public void drawRect(int x, int y, int width, int height, int topLeftColor, int topRightColor, int bottomLeftColor, int bottomRightColor) { - drawRect(x, y, width, height, color(topLeftColor), color(topRightColor), color(bottomLeftColor), color(bottomRightColor)); - } - - @Override - public void drawRect(int x, int y, int width, int height, ReadableColor tl, ReadableColor tr, ReadableColor bl, ReadableColor br) { - disableTexture2D(); - enableBlend(); - disableAlpha(); - tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, 0); - shadeModel(GL_SMOOTH); - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer renderer = tessellator.getWorldRenderer(); - renderer.startDrawingQuads(); - renderer.setColorRGBA(bl.getRed(), bl.getGreen(), bl.getBlue(), bl.getAlpha()); - renderer.addVertex(x, y + height, 0); - renderer.setColorRGBA(br.getRed(), br.getGreen(), br.getBlue(), br.getAlpha()); - renderer.addVertex(x + width, y + height, 0); - renderer.setColorRGBA(tr.getRed(), tr.getGreen(), tr.getBlue(), tr.getAlpha()); - renderer.addVertex(x + width, y, 0); - renderer.setColorRGBA(tl.getRed(), tl.getGreen(), tl.getBlue(), tl.getAlpha()); - renderer.addVertex(x, y, 0); - tessellator.draw(); - shadeModel(GL_FLAT); - disableBlend(); - enableAlpha(); - enableTexture2D(); - } - - @Override - public int drawString(int x, int y, int color, String text) { - return drawString(x, y, color, text, false); - } - - @Override - public int drawString(int x, int y, ReadableColor color, String text) { - return drawString(x, y, color(color), text); - } - - @Override - public int drawCenteredString(int x, int y, int color, String text) { - return drawCenteredString(x, y, color, text, false); - } - - @Override - public int drawCenteredString(int x, int y, ReadableColor color, String text) { - return drawCenteredString(x, y, color(color), text); - } - - @Override - public int drawString(int x, int y, int color, String text, boolean shadow) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - int ret = shadow ? fontRenderer.drawStringWithShadow(text, x, y, color) : fontRenderer.drawString(text, x, y, color); - GlStateManager.color(1, 1, 1); - return ret; - } - - @Override - public int drawString(int x, int y, ReadableColor color, String text, boolean shadow) { - return drawString(x, y, color(color), text, shadow); - } - - @Override - public int drawCenteredString(int x, int y, int color, String text, boolean shadow) { - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; - x-=fontRenderer.getStringWidth(text) / 2; - return drawString(x, y, color, text, shadow); - } - - @Override - public int drawCenteredString(int x, int y, ReadableColor color, String text, boolean shadow) { - return drawCenteredString(x, y, color(color), text, shadow); - } - - private int color(ReadableColor color) { - return color.getAlpha() << 24 - | color.getRed() << 16 - | color.getGreen() << 8 - | color.getBlue(); - } - - private ReadableColor color(int color) { - return new Color((color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff, (color >> 24) & 0xff); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/OffsetGuiRenderer.java b/src/main/java/de/johni0702/minecraft/gui/OffsetGuiRenderer.java deleted file mode 100644 index 8a2fb03c..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/OffsetGuiRenderer.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui; - -import lombok.NonNull; -import net.minecraft.client.renderer.texture.ITextureObject; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.*; - -public class OffsetGuiRenderer implements GuiRenderer { - - @NonNull - private final GuiRenderer renderer; - - @NonNull - private final ReadablePoint position; - - @NonNull - private final ReadableDimension size; - - private final boolean strict; - - /** - * Creates a new strict offset gui renderer with the same settings as the supplied one. - * @see #OffsetGuiRenderer(GuiRenderer, ReadablePoint, ReadableDimension, boolean) - * @param renderer The renderer to copy from - */ - public OffsetGuiRenderer(OffsetGuiRenderer renderer) { - this(renderer.renderer, renderer.position, renderer.size, true); - } - - /** - * Create a new offset GUI renderer. All calls to this renderer are forwarded to the parent - * renderer with coordinates offset by the specified position. - * This also ensures that drawing happens within the specified bounds. - * @param renderer The parent renderer - * @param position The position of this renderer within the parent (used as is, not copied) - * @param size The size of the drawable area (used as is, not copied) - */ - public OffsetGuiRenderer(GuiRenderer renderer, ReadablePoint position, ReadableDimension size) { - this(renderer, position, size, true); - } - - - /** - * Create a new offset GUI renderer. All calls to this renderer are forwarded to the parent - * renderer with coordinates offset by the specified position. - * If strict is {@code true}, this also ensures that drawing happens within the specified bounds. - * @param renderer The parent renderer - * @param position The position of this renderer within the parent (used as is, not copied) - * @param size The size of the drawable area (used as is, not copied) - * @param strict Whether drawing should be forced to be within the drawable area - */ - public OffsetGuiRenderer(GuiRenderer renderer, ReadablePoint position, ReadableDimension size, boolean strict) { - this.renderer = renderer; - this.position = position; - this.size = size; - this.strict = strict; - } - - @Override - public ReadablePoint getOpenGlOffset() { - ReadablePoint parentOffset = renderer.getOpenGlOffset(); - return new Point(parentOffset.getX() + position.getX(), parentOffset.getY() + position.getY()); - } - - @Override - public ReadableDimension getSize() { - return size; - } - - @Override - public void setDrawingArea(int x, int y, int width, int height) { - if (!strict) { - renderer.setDrawingArea(x + position.getX(), y + position.getY(), width, height); - return; - } - int x2 = x + width; - int y2 = y + height; - // Convert and clamp top and left border - x = Math.max(0, x + position.getX()); - y = Math.max(0, y + position.getY()); - // Clamp and convert bottom and right border - x2 = Math.min(x2, size.getWidth()) + position.getX(); - y2 = Math.min(y2, size.getHeight()) + position.getY(); - // Make sure bottom and top / right and left aren't flipped - x2 = Math.max(x2, x); - y2 = Math.max(y2, y); - // Pass to parent - renderer.setDrawingArea(x, y, x2 - x, y2 - y); - } - - public void startUsing() { - GL11.glPushAttrib(GL11.GL_SCISSOR_BIT); - GL11.glEnable(GL11.GL_SCISSOR_TEST); - setDrawingArea(0, 0, size.getWidth(), size.getHeight()); - } - - public void stopUsing() { - GL11.glPopAttrib(); - } - - @Override - public void bindTexture(ResourceLocation location) { - renderer.bindTexture(location); - } - - @Override - public void bindTexture(ITextureObject texture) { - renderer.bindTexture(texture); - } - - @Override - public void drawTexturedRect(int x, int y, int u, int v, int width, int height) { - renderer.drawTexturedRect(x + position.getX(), y + position.getY(), u, v, width, height); - } - - @Override - public void drawTexturedRect(int x, int y, int u, int v, int width, int height, int uWidth, int vHeight, int textureWidth, int textureHeight) { - renderer.drawTexturedRect(x + position.getX(), y + position.getY(), u, v, width, height, uWidth, vHeight, textureWidth, textureHeight); - } - - @Override - public void drawRect(int x, int y, int width, int height, int color) { - renderer.drawRect(x + position.getX(), y + position.getY(), width, height, color); - } - - @Override - public void drawRect(int x, int y, int width, int height, ReadableColor color) { - renderer.drawRect(x + position.getX(), y + position.getY(), width, height, color); - } - - @Override - public void drawRect(int x, int y, int width, int height, int topLeftColor, int topRightColor, int bottomLeftColor, int bottomRightColor) { - renderer.drawRect(x + position.getX(), y + position.getY(), width, height, topLeftColor, topRightColor, bottomLeftColor, bottomRightColor); - } - - @Override - public void drawRect(int x, int y, int width, int height, ReadableColor topLeftColor, ReadableColor topRightColor, ReadableColor bottomLeftColor, ReadableColor bottomRightColor) { - renderer.drawRect(x + position.getX(), y + position.getY(), width, height, topLeftColor, topRightColor, bottomLeftColor, bottomRightColor); - } - - @Override - public int drawString(int x, int y, int color, String text) { - return renderer.drawString(x + position.getX(), y + position.getY(), color, text) - position.getX(); - } - - @Override - public int drawString(int x, int y, ReadableColor color, String text) { - return renderer.drawString(x + position.getX(), y + position.getY(), color, text) - position.getX(); - } - - @Override - public int drawCenteredString(int x, int y, int color, String text) { - return renderer.drawCenteredString(x + position.getX(), y + position.getY(), color, text) - position.getX(); - } - - @Override - public int drawCenteredString(int x, int y, ReadableColor color, String text) { - return renderer.drawCenteredString(x + position.getX(), y + position.getY(), color, text) - position.getX(); - } - - @Override - public int drawString(int x, int y, int color, String text, boolean shadow) { - return renderer.drawString(x + position.getX(), y + position.getY(), color, text, shadow) - position.getX(); - } - - @Override - public int drawString(int x, int y, ReadableColor color, String text, boolean shadow) { - return renderer.drawString(x + position.getX(), y + position.getY(), color, text, shadow) - position.getX(); - } - - @Override - public int drawCenteredString(int x, int y, int color, String text, boolean shadow) { - return renderer.drawCenteredString(x + position.getX(), y + position.getY(), color, text, shadow) - position.getX(); - } - - @Override - public int drawCenteredString(int x, int y, ReadableColor color, String text, boolean shadow) { - return renderer.drawCenteredString(x + position.getX(), y + position.getY(), color, text, shadow) - position.getX(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/RenderInfo.java b/src/main/java/de/johni0702/minecraft/gui/RenderInfo.java deleted file mode 100644 index c1355d3f..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/RenderInfo.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui; - -import lombok.Data; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; - -@Data -public class RenderInfo { - public final float partialTick; - public final int mouseX; - public final int mouseY; - public final int layer; - - public RenderInfo offsetMouse(int minusX, int minusY) { - return new RenderInfo(partialTick, mouseX - minusX, mouseY - minusY, layer); - } - - public RenderInfo layer(int layer) { - return this.layer == layer ? this : new RenderInfo(partialTick, mouseX, mouseY, layer); - } - - public void addTo(CrashReport crashReport) { - CrashReportCategory category = crashReport.makeCategory("Render info details"); - category.addCrashSection("Partial Tick", partialTick); - category.addCrashSection("Mouse X", mouseX); - category.addCrashSection("Mouse Y", mouseY); - category.addCrashSection("Layer", layer); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiClickableContainer.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiClickableContainer.java deleted file mode 100644 index 7d513a21..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiClickableContainer.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.element.IGuiClickable; -import de.johni0702.minecraft.gui.function.Clickable; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -public abstract class AbstractGuiClickableContainer> - extends AbstractGuiContainer implements Clickable, IGuiClickable { - private Runnable onClick; - private ReadableDimension size; - - public AbstractGuiClickableContainer() { - } - - public AbstractGuiClickableContainer(GuiContainer container) { - super(container); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - Point pos = new Point(position); - if (getContainer() != null) { - getContainer().convertFor(this, pos); - } - - if (isMouseHovering(pos) && isEnabled()) { - onClick(); - return true; - } - return false; - } - - protected boolean isMouseHovering(ReadablePoint pos) { - return pos.getX() > 0 && pos.getY() > 0 - && pos.getX() < size.getWidth() && pos.getY() < size.getHeight(); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - this.size = size; - super.draw(renderer, size, renderInfo); - } - - protected void onClick() { - if (onClick != null) { - onClick.run(); - } - } - - @Override - public T onClick(Runnable onClick) { - this.onClick = onClick; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiContainer.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiContainer.java deleted file mode 100644 index 96226f13..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiContainer.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Ordering; -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.OffsetGuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.element.AbstractComposedGuiElement; -import de.johni0702.minecraft.gui.element.ComposedGuiElement; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.layout.HorizontalLayout; -import de.johni0702.minecraft.gui.layout.Layout; -import de.johni0702.minecraft.gui.layout.LayoutData; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.util.ReportedException; -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableColor; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.util.*; -import java.util.concurrent.Callable; - -import static com.google.common.base.Preconditions.checkState; - -public abstract class AbstractGuiContainer> - extends AbstractComposedGuiElement implements GuiContainer { - - private static final Layout DEFAULT_LAYOUT = new HorizontalLayout(); - - private final Map elements = new LinkedHashMap(); - - private Map> layedOutElements; - - private Layout layout = DEFAULT_LAYOUT; - - private ReadableColor backgroundColor; - - public AbstractGuiContainer() { - } - - public AbstractGuiContainer(GuiContainer container) { - super(container); - } - - @Override - public T setLayout(Layout layout) { - this.layout = layout; - return getThis(); - } - - @Override - public Layout getLayout() { - return layout; - } - - @Override - public void convertFor(GuiElement element, Point point) { - checkState(layedOutElements != null, "Cannot convert position unless rendered at least once."); - Pair pair = layedOutElements.get(element); - checkState(pair != null, "Element " + element + " not part of " + this); - ReadablePoint pos = pair.getKey(); - if (getContainer() != null) { - getContainer().convertFor(this, point); - } - point.translate(-pos.getX(), -pos.getY()); - } - - @Override - public Collection getChildren() { - return Collections.unmodifiableCollection(elements.keySet()); - } - - @Override - public Map getElements() { - return Collections.unmodifiableMap(elements); - } - - @Override - public T addElements(LayoutData layoutData, GuiElement... elements) { - if (layoutData == null) { - layoutData = LayoutData.NONE; - } - for (GuiElement element : elements) { - this.elements.put(element, layoutData); - element.setContainer(this); - } - return getThis(); - } - - @Override - public T removeElement(GuiElement element) { - if (elements.remove(element) != null) { - element.setContainer(null); - if (layedOutElements != null) { - layedOutElements.remove(element); - } - } - return getThis(); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - try { - layedOutElements = layout.layOut(this, size); - } catch (Exception ex) { - CrashReport crashReport = CrashReport.makeCrashReport(ex, "Gui Layout"); - renderInfo.addTo(crashReport); - CrashReportCategory category = crashReport.makeCategory("Gui container details"); - category.addCrashSectionCallable("Container", new Callable() { - @Override - public Object call() throws Exception { - return this; - } - }); - category.addCrashSectionCallable("Layout", new Callable() { - @Override - public Object call() throws Exception { - return layout; - } - }); - throw new ReportedException(crashReport); - } - if (backgroundColor != null && renderInfo.getLayer() == 0) { - renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), backgroundColor); - } - for (final Map.Entry> e : layedOutElements.entrySet()) { - GuiElement element = e.getKey(); - boolean strict; - if (element instanceof ComposedGuiElement) { - if (((ComposedGuiElement) element).getMaxLayer() < renderInfo.layer) { - continue; - } - strict = renderInfo.layer == 0; - } else { - if (element.getLayer() != renderInfo.layer) { - continue; - } - strict = true; - } - final ReadablePoint ePosition = e.getValue().getLeft(); - final ReadableDimension eSize = e.getValue().getRight(); - try { - OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, ePosition, eSize, strict); - eRenderer.startUsing(); - e.getKey().draw(eRenderer, eSize, renderInfo.offsetMouse(ePosition.getX(), ePosition.getY()) - .layer(renderInfo.getLayer() - e.getKey().getLayer())); - eRenderer.stopUsing(); - } catch (Exception ex) { - CrashReport crashReport = CrashReport.makeCrashReport(ex, "Rendering Gui"); - renderInfo.addTo(crashReport); - CrashReportCategory category = crashReport.makeCategory("Gui container details"); - category.addCrashSectionCallable("Container", new Callable() { - @Override - public Object call() throws Exception { - return this; - } - }); - category.addCrashSection("Width", size.getWidth()); - category.addCrashSection("Height", size.getHeight()); - category.addCrashSectionCallable("Layout", new Callable() { - @Override - public Object call() throws Exception { - return layout; - } - }); - category = crashReport.makeCategory("Gui element details"); - category.addCrashSectionCallable("Element", new Callable() { - @Override - public Object call() throws Exception { - return e.getKey(); - } - }); - category.addCrashSectionCallable("Position", new Callable() { - @Override - public Object call() throws Exception { - return ePosition; - } - }); - category.addCrashSectionCallable("Size", new Callable() { - @Override - public Object call() throws Exception { - return eSize; - } - }); - if (e.getKey() instanceof GuiContainer) { - category.addCrashSectionCallable("Layout", new Callable() { - @Override - public Object call() throws Exception { - return ((GuiContainer) e.getKey()).getLayout(); - } - }); - } - throw new ReportedException(crashReport); - } - } - } - - @Override - public ReadableDimension calcMinSize() { - return layout.calcMinSize(this); - } - - @Override - public T sortElements() { - sortElements(new Comparator() { - @SuppressWarnings("unchecked") - @Override - public int compare(GuiElement o1, GuiElement o2) { - if (o1 instanceof Comparable && o2 instanceof Comparable) { - return ((Comparable) o1).compareTo(o2); - } - return o1.hashCode() - o2.hashCode(); - } - }); - return getThis(); - } - - @Override - public T sortElements(final Comparator comparator) { - Ordering> ordering = new Ordering>() { - @Override - public int compare(Map.Entry left, Map.Entry right) { - return comparator.compare(left.getKey(), right.getKey()); - } - }; - if (!ordering.isOrdered(elements.entrySet())) { - ImmutableList> sorted = ordering.immutableSortedCopy(elements.entrySet()); - elements.clear(); - for (Map.Entry entry : sorted) { - elements.put(entry.getKey(), entry.getValue()); - } - } - return getThis(); - } - - @Override - public ReadableColor getBackgroundColor() { - return backgroundColor; - } - - @Override - public T setBackgroundColor(ReadableColor backgroundColor) { - this.backgroundColor = backgroundColor; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java deleted file mode 100644 index 6aef5114..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiOverlay.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.MinecraftGuiRenderer; -import de.johni0702.minecraft.gui.OffsetGuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.function.*; -import eu.crushedpixel.replaymod.utils.MouseUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.util.ReportedException; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import org.lwjgl.input.Mouse; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.io.IOException; -import java.util.concurrent.Callable; - -public abstract class AbstractGuiOverlay> extends AbstractGuiContainer { - - private final UserInputGuiScreen userInputGuiScreen = new UserInputGuiScreen(); - private final EventHandler eventHandler = new EventHandler(); - private boolean visible; - private Dimension screenSize; - private boolean mouseVisible; - - public boolean isVisible() { - return visible; - } - - public void setVisible(boolean visible) { - if (this.visible != visible) { - if (visible) { - forEach(Loadable.class).load(); - MinecraftForge.EVENT_BUS.register(eventHandler); - } else { - forEach(Closeable.class).close(); - MinecraftForge.EVENT_BUS.unregister(eventHandler); - } - updateUserInputGui(); - } - this.visible = visible; - } - - public boolean isMouseVisible() { - return mouseVisible; - } - - public void setMouseVisible(boolean mouseVisible) { - this.mouseVisible = mouseVisible; - updateUserInputGui(); - } - - private void updateUserInputGui() { - Minecraft mc = getMinecraft(); - if (visible) { - if (mouseVisible) { - if (mc.currentScreen != userInputGuiScreen) { - mc.displayGuiScreen(userInputGuiScreen); - } - } else { - if (mc.currentScreen == userInputGuiScreen) { - mc.displayGuiScreen(null); - } - } - } - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - super.draw(renderer, size, renderInfo); - if (mouseVisible && renderInfo.layer == getMaxLayer()) { - final GuiElement tooltip = forEach(GuiElement.class).getTooltip(renderInfo); - if (tooltip != null) { - final ReadableDimension tooltipSize = tooltip.getMinSize(); - int x, y; - if (renderInfo.mouseX + 8 + tooltipSize.getWidth() < screenSize.getWidth()) { - x = renderInfo.mouseX + 8; - } else { - x = screenSize.getWidth() - tooltipSize.getWidth() - 1; - } - if (renderInfo.mouseY + 8 + tooltipSize.getHeight() < screenSize.getHeight()) { - y = renderInfo.mouseY + 8; - } else { - y = screenSize.getHeight() - tooltipSize.getHeight() - 1; - } - final ReadablePoint position = new Point(x, y); - try { - OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, position, tooltipSize); - tooltip.draw(eRenderer, tooltipSize, renderInfo); - } catch (Exception ex) { - CrashReport crashReport = CrashReport.makeCrashReport(ex, "Rendering Gui Tooltip"); - renderInfo.addTo(crashReport); - CrashReportCategory category = crashReport.makeCategory("Gui container details"); - category.addCrashSectionCallable("Container", new Callable() { - @Override - public Object call() throws Exception { - return this; - } - }); - category.addCrashSection("Width", size.getWidth()); - category.addCrashSection("Height", size.getHeight()); - category = crashReport.makeCategory("Tooltip details"); - category.addCrashSectionCallable("Element", new Callable() { - @Override - public Object call() throws Exception { - return tooltip; - } - }); - category.addCrashSectionCallable("Position", new Callable() { - @Override - public Object call() throws Exception { - return position; - } - }); - category.addCrashSectionCallable("Size", new Callable() { - @Override - public Object call() throws Exception { - return tooltipSize; - } - }); - throw new ReportedException(crashReport); - } - } - } - } - - @Override - public ReadableDimension getMinSize() { - return screenSize; - } - - @Override - public ReadableDimension getMaxSize() { - return screenSize; - } - - private class EventHandler { - private MinecraftGuiRenderer renderer; - - @SubscribeEvent - public void renderOverlay(RenderGameOverlayEvent.Post event) { - if (event.type == RenderGameOverlayEvent.ElementType.ALL) { - updateRenderer(); - int layers = getMaxLayer(); - int mouseX = -1, mouseY = -1; - if (mouseVisible) { - Point mouse = MouseUtils.getMousePos(); - mouseX = mouse.getX(); - mouseY = mouse.getY(); - } - for (int layer = 0; layer <= layers; layer++) { - draw(renderer, screenSize, new RenderInfo(event.partialTicks, mouseX, mouseY, layer)); - } - } - } - - @SubscribeEvent - public void tickOverlay(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.START) { - forEach(Tickable.class).tick(); - } - } - - private void updateRenderer() { - Minecraft mc = getMinecraft(); - ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); - if (screenSize == null - || screenSize.getWidth() != res.getScaledWidth() - || screenSize.getHeight() != res.getScaledHeight()) { - screenSize = new Dimension(res.getScaledWidth(), res.getScaledHeight()); - renderer = new MinecraftGuiRenderer(res); - } - } - } - - protected class UserInputGuiScreen extends net.minecraft.client.gui.GuiScreen { - - { - allowUserInput = true; - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - forEach(Typeable.class).typeKey(MouseUtils.getMousePos(), keyCode, typedChar, isCtrlKeyDown(), isShiftKeyDown()); - super.keyTyped(typedChar, keyCode); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - forEach(Clickable.class).mouseClick(new Point(mouseX, mouseY), mouseButton); - } - - @Override - protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { - forEach(Draggable.class).mouseRelease(new Point(mouseX, mouseY), mouseButton); - } - - @Override - protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) { - forEach(Draggable.class).mouseDrag(new Point(mouseX, mouseY), mouseButton, timeSinceLastClick); - } - - @Override - public void updateScreen() { - forEach(Tickable.class).tick(); - } - - @Override - public void handleMouseInput() throws IOException { - super.handleMouseInput(); - if (Mouse.hasWheel() && Mouse.getEventDWheel() != 0) { - forEach(Scrollable.class).scroll(MouseUtils.getMousePos(), Mouse.getEventDWheel()); - } - } - - @Override - public void onGuiClosed() { - mouseVisible = false; - } - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java deleted file mode 100644 index 01899d91..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScreen.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.MinecraftGuiRenderer; -import de.johni0702.minecraft.gui.OffsetGuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.element.GuiLabel; -import de.johni0702.minecraft.gui.function.*; -import eu.crushedpixel.replaymod.utils.MouseUtils; -import lombok.Getter; -import lombok.Setter; -import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.util.ReportedException; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.io.IOException; -import java.util.concurrent.Callable; - -public abstract class AbstractGuiScreen> extends AbstractGuiContainer { - - private final MinecraftGuiScreen wrapped = new MinecraftGuiScreen(); - - private Dimension screenSize; - - @Getter - @Setter - private boolean drawBackground = true; - - @Getter - private boolean enabledRepeatedKeyEvents = true; - - @Getter - @Setter - private GuiLabel title; - - public net.minecraft.client.gui.GuiScreen toMinecraft() { - return wrapped; - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - if (renderInfo.layer == 0) { - if (drawBackground) { - wrapped.drawDefaultBackground(); - } - if (title != null) { - ReadableDimension titleSize = title.getMinSize(); - int x = screenSize.getWidth() / 2 - titleSize.getWidth() / 2; - OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, new Point(x, 10), new Dimension(0, 0)); - title.draw(eRenderer, titleSize, null); - } - } - super.draw(renderer, size, renderInfo); - if (renderInfo.layer == getMaxLayer()) { - final GuiElement tooltip = forEach(GuiElement.class).getTooltip(renderInfo); - if (tooltip != null) { - final ReadableDimension tooltipSize = tooltip.getMinSize(); - int x, y; - if (renderInfo.mouseX + 8 + tooltipSize.getWidth() < screenSize.getWidth()) { - x = renderInfo.mouseX + 8; - } else { - x = screenSize.getWidth() - tooltipSize.getWidth() - 1; - } - if (renderInfo.mouseY + 8 + tooltipSize.getHeight() < screenSize.getHeight()) { - y = renderInfo.mouseY + 8; - } else { - y = screenSize.getHeight() - tooltipSize.getHeight() - 1; - } - final ReadablePoint position = new Point(x, y); - try { - OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, position, tooltipSize); - tooltip.draw(eRenderer, tooltipSize, renderInfo); - } catch (Exception ex) { - CrashReport crashReport = CrashReport.makeCrashReport(ex, "Rendering Gui Tooltip"); - renderInfo.addTo(crashReport); - CrashReportCategory category = crashReport.makeCategory("Gui container details"); - category.addCrashSectionCallable("Container", new Callable() { - @Override - public Object call() throws Exception { - return this; - } - }); - category.addCrashSection("Width", size.getWidth()); - category.addCrashSection("Height", size.getHeight()); - category = crashReport.makeCategory("Tooltip details"); - category.addCrashSectionCallable("Element", new Callable() { - @Override - public Object call() throws Exception { - return tooltip; - } - }); - category.addCrashSectionCallable("Position", new Callable() { - @Override - public Object call() throws Exception { - return position; - } - }); - category.addCrashSectionCallable("Size", new Callable() { - @Override - public Object call() throws Exception { - return tooltipSize; - } - }); - throw new ReportedException(crashReport); - } - } - } - } - - @Override - public ReadableDimension getMinSize() { - return screenSize; - } - - @Override - public ReadableDimension getMaxSize() { - return screenSize; - } - - public void setEnabledRepeatedKeyEvents(boolean enableRepeatKeyEvents) { - this.enabledRepeatedKeyEvents = enableRepeatKeyEvents; - if (wrapped.active) { - Keyboard.enableRepeatEvents(enableRepeatKeyEvents); - } - } - - public void display() { - getMinecraft().displayGuiScreen(toMinecraft()); - } - - protected class MinecraftGuiScreen extends net.minecraft.client.gui.GuiScreen { - private MinecraftGuiRenderer renderer; - private boolean active; - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - int layers = getMaxLayer(); - for (int layer = 0; layer <= layers; layer++) { - draw(renderer, screenSize, new RenderInfo(partialTicks, mouseX, mouseY, layer)); - } - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - forEach(Typeable.class).typeKey(MouseUtils.getMousePos(), keyCode, typedChar, isCtrlKeyDown(), isShiftKeyDown()); - super.keyTyped(typedChar, keyCode); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - forEach(Clickable.class).mouseClick(new Point(mouseX, mouseY), mouseButton); - } - - @Override - protected void mouseReleased(int mouseX, int mouseY, int mouseButton) { - forEach(Draggable.class).mouseRelease(new Point(mouseX, mouseY), mouseButton); - } - - @Override - protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long timeSinceLastClick) { - forEach(Draggable.class).mouseDrag(new Point(mouseX, mouseY), mouseButton, timeSinceLastClick); - } - - @Override - public void updateScreen() { - forEach(Tickable.class).tick(); - } - - @Override - public void handleMouseInput() throws IOException { - super.handleMouseInput(); - if (Mouse.hasWheel() && Mouse.getEventDWheel() != 0) { - forEach(Scrollable.class).scroll(MouseUtils.getMousePos(), Mouse.getEventDWheel()); - } - } - - @Override - public void onGuiClosed() { - forEach(Closeable.class).close(); - active = false; - if (enabledRepeatedKeyEvents) { - Keyboard.enableRepeatEvents(false); - } - } - - @Override - public void initGui() { - active = false; - if (enabledRepeatedKeyEvents) { - Keyboard.enableRepeatEvents(true); - } - screenSize = new Dimension(width, height); - renderer = new MinecraftGuiRenderer(new ScaledResolution(mc, mc.displayWidth, mc.displayHeight)); - forEach(Loadable.class).load(); - } - - public T getWrapper() { - return AbstractGuiScreen.this.getThis(); - } - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScrollable.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScrollable.java deleted file mode 100644 index 7d81025f..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiScrollable.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.OffsetGuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.function.Scrollable; -import org.lwjgl.util.*; - -public abstract class AbstractGuiScrollable> extends AbstractGuiContainer - implements Scrollable { - private int offsetX, offsetY; - private final ReadablePoint negativeOffset = new ReadablePoint() { - @Override - public int getX() { - return -offsetX; - } - - @Override - public int getY() { - return -offsetY; - } - - @Override - public void getLocation(WritablePoint dest) { - dest.setLocation(getX(), getY()); - } - }; - - private Direction scrollDirection = Direction.VERTICAL; - - protected ReadableDimension lastRenderSize; - - public AbstractGuiScrollable() { - } - - public AbstractGuiScrollable(GuiContainer container) { - super(container); - } - - @Override - public void convertFor(GuiElement element, Point point) { - super.convertFor(element, point); - if (point.getX() > 0 && point.getX() < lastRenderSize.getWidth() - && point.getY() > 0 && point.getY() < lastRenderSize.getHeight()) { - point.translate(offsetX, offsetY); - } else { - point.setLocation(Integer.MIN_VALUE, Integer.MIN_VALUE); - } - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - int width = size.getWidth(); - int height = size.getHeight(); - lastRenderSize = size; - size = super.calcMinSize(); - size = new Dimension(Math.max(width, size.getWidth()), Math.max(height, size.getHeight())); - renderInfo = renderInfo.offsetMouse(-offsetX, -offsetY); - - OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, negativeOffset, size); - offsetRenderer.startUsing(); - super.draw(offsetRenderer, size, renderInfo); - offsetRenderer.stopUsing(); - } - - @Override - public ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } - - @Override - public boolean scroll(ReadablePoint mousePosition, int dWheel) { - Point mouse = new Point(mousePosition); - if (getContainer() != null) { - getContainer().convertFor(this, mouse); - } - if (mouse.getX() > 0 && mouse.getY() > 0 - && mouse.getX() < lastRenderSize.getWidth() && mouse.getY() < lastRenderSize.getHeight()) { - // Reduce scrolling speed but make sure it is never rounded to 0 - dWheel = (int) Math.copySign(Math.ceil(Math.abs(dWheel) / 4.0), dWheel); - if (scrollDirection == Direction.HORIZONTAL) { - scrollX(dWheel); - } else { - scrollY(dWheel); - } - return true; - } - return false; - } - - public int getOffsetX() { - return offsetX; - } - - public T setOffsetX(int offsetX) { - this.offsetX = offsetX; - return getThis(); - } - - public int getOffsetY() { - return offsetY; - } - - public T setOffsetY(int offsetY) { - this.offsetY = offsetY; - return getThis(); - } - - public Direction getScrollDirection() { - return scrollDirection; - } - - public T setScrollDirection(Direction scrollDirection) { - this.scrollDirection = scrollDirection; - return getThis(); - } - - public T scrollX(int dPixel) { - offsetX = Math.max(0, Math.min(super.calcMinSize().getWidth() - lastRenderSize.getWidth(), offsetX - dPixel)); - return getThis(); - } - - public T scrollY(int dPixel) { - offsetY = Math.max(0, Math.min(super.calcMinSize().getHeight() - lastRenderSize.getHeight(), offsetY - dPixel)); - return getThis(); - } - - public enum Direction { - VERTICAL, HORIZONTAL; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiVerticalList.java b/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiVerticalList.java deleted file mode 100644 index 6fa990d6..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/AbstractGuiVerticalList.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.function.Draggable; -import de.johni0702.minecraft.gui.layout.CustomLayout; -import de.johni0702.minecraft.gui.layout.VerticalLayout; -import lombok.Getter; -import org.lwjgl.util.*; - -import static de.johni0702.minecraft.gui.utils.Colors.TRANSPARENT; -import static org.lwjgl.util.ReadableColor.BLACK; - -public abstract class AbstractGuiVerticalList> extends AbstractGuiScrollable - implements Draggable { - public static final ReadableColor BACKGROUND = new Color(0, 0, 0, 150); - - @Getter - private final VerticalLayout listLayout = new VerticalLayout().setSpacing(3); - - @Getter - private final GuiPanel listPanel = new GuiPanel(this).setLayout(listLayout); - - { - setLayout(new CustomLayout() { - @Override - protected void layout(T container, int width, int height) { - pos(listPanel, width / 2 - width(listPanel) / 2, 5); - } - - @Override - public ReadableDimension calcMinSize(GuiContainer container) { - final ReadableDimension panelSize = listPanel.getMinSize(); - return new ReadableDimension() { - @Override - public int getWidth() { - return panelSize.getWidth(); - } - - @Override - public int getHeight() { - return panelSize.getHeight() + 10; - } - - @Override - public void getSize(WritableDimension dest) { - dest.setSize(getWidth(), getHeight()); - } - }; - } - }); - } - - private boolean drawShadow, drawSlider; - - private ReadablePoint lastMousePos; - private boolean draggingSlider; - - public AbstractGuiVerticalList() { - } - - public AbstractGuiVerticalList(GuiContainer container) { - super(container); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - int width = size.getWidth(); - int height = size.getHeight(); - if (drawShadow) { - renderer.drawRect(0, 0, width, height, BACKGROUND); - super.draw(renderer, size, renderInfo); - renderer.drawRect(0, 0, width, 4, BLACK, BLACK, TRANSPARENT, TRANSPARENT); - renderer.drawRect(0, height - 4, width, 4, TRANSPARENT, TRANSPARENT, BLACK, BLACK); - } else { - super.draw(renderer, size, renderInfo); - } - - if (drawSlider) { - ReadableDimension contentSize = listPanel.calcMinSize(); - int contentHeight = contentSize.getHeight() + 10; - if (contentHeight > height) { - int sliderX = width / 2 + contentSize.getWidth() / 2 + 3; - renderer.drawRect(sliderX, 0, 6, height, BLACK); // Draw slider background - int sliderY = getOffsetY() * height / contentHeight; - int sliderSize = height * height / contentHeight; - // Draw slider, with shadows - renderer.drawRect(sliderX, sliderY, 6, sliderSize, Color.LTGREY); // Slider - renderer.drawRect(sliderX + 5, sliderY, 1, sliderSize, Color.GREY); // Right shadow - renderer.drawRect(sliderX, sliderY + sliderSize - 1, 6, 1, Color.GREY); // Bottom shadow - } - } - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - position = convert(position); - if (isOnThis(position)) { - if (isOnSliderBar(position)) { - draggingSlider = true; - } - lastMousePos = position; - // We must not return true here - // because if we did, non of our children were able to process click events at all - } - return false; - } - - @Override - public boolean mouseDrag(ReadablePoint position, int button, long timeSinceLastCall) { - position = convert(position); - if (lastMousePos != null) { - int dPixel = lastMousePos.getY() - position.getY(); - if (draggingSlider) { - int contentHeight = listPanel.calcMinSize().getHeight(); - int renderHeight = lastRenderSize.getHeight(); - scrollY(dPixel * (contentHeight + renderHeight) / renderHeight); - } else { - scrollY(-dPixel); - } - lastMousePos = position; - // Returning false on purpose, see #mouseClick - } - return false; - } - - @Override - public boolean mouseRelease(ReadablePoint position, int button) { - if (lastMousePos != null) { - lastMousePos = null; - draggingSlider = false; - // Returning false on purpose, see #mouseClick - } - return false; - } - - private ReadablePoint convert(ReadablePoint readablePoint) { - if (getContainer() != null) { - Point point = new Point(readablePoint); - getContainer().convertFor(this, point); - return point; - } - return readablePoint; - } - - private boolean isOnThis(ReadablePoint point) { - return point.getX() > 0 && point.getY() > 0 - && point.getX() < lastRenderSize.getWidth() && point.getY() < lastRenderSize.getHeight(); - } - - private boolean isOnSliderBar(ReadablePoint point) { - if (!drawSlider) { - return false; - } - int sliderX = lastRenderSize.getWidth() / 2 + listPanel.calcMinSize().getWidth() / 2 + 3; - return sliderX <= point.getX() && point.getX() < sliderX + 6; - } - - private boolean isOnBackground(ReadablePoint point) { - int width = lastRenderSize.getWidth(); - int listPanelWidth = listPanel.calcMinSize().getWidth(); - return point.getX() < width / 2 - listPanelWidth / 2 - || width / 2 + listPanelWidth / 2 + (drawSlider ? 6 : 0) < point.getX(); - } - - public boolean doesDrawSlider() { - return drawSlider; - } - - public T setDrawSlider(boolean drawSlider) { - this.drawSlider = drawSlider; - return getThis(); - } - - public boolean doesDrawShadow() { - return drawShadow; - } - - public T setDrawShadow(boolean drawShadow) { - this.drawShadow = drawShadow; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/GuiClickable.java b/src/main/java/de/johni0702/minecraft/gui/container/GuiClickable.java deleted file mode 100644 index 5f35460c..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/GuiClickable.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -public class GuiClickable extends AbstractGuiClickableContainer { - - public GuiClickable() { - } - - public GuiClickable(GuiContainer container) { - super(container); - } - - @Override - protected GuiClickable getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/GuiContainer.java b/src/main/java/de/johni0702/minecraft/gui/container/GuiContainer.java deleted file mode 100644 index 4e1e444c..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/GuiContainer.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import de.johni0702.minecraft.gui.element.ComposedGuiElement; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.layout.Layout; -import de.johni0702.minecraft.gui.layout.LayoutData; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableColor; - -import java.util.Comparator; -import java.util.Map; - -public interface GuiContainer> extends ComposedGuiElement { - - T setLayout(Layout layout); - Layout getLayout(); - - void convertFor(GuiElement element, Point point); - - Map getElements(); - T addElements(LayoutData layoutData, GuiElement...elements); - T removeElement(GuiElement element); - T sortElements(); - T sortElements(Comparator comparator); - - ReadableColor getBackgroundColor(); - T setBackgroundColor(ReadableColor backgroundColor); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/GuiOverlay.java b/src/main/java/de/johni0702/minecraft/gui/container/GuiOverlay.java deleted file mode 100644 index acfe39b6..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/GuiOverlay.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -public class GuiOverlay extends AbstractGuiOverlay { - @Override - protected GuiOverlay getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/GuiPanel.java b/src/main/java/de/johni0702/minecraft/gui/container/GuiPanel.java deleted file mode 100644 index 359975be..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/GuiPanel.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.layout.Layout; -import de.johni0702.minecraft.gui.layout.LayoutData; -import lombok.Builder; -import lombok.Singular; - -import java.util.Map; - -public class GuiPanel extends AbstractGuiContainer { - - public GuiPanel() { - } - - public GuiPanel(GuiContainer container) { - super(container); - } - - @Builder - GuiPanel(Layout layout, int width , int height, @Singular("with") Map withElements) { - setLayout(layout); - if (width != 0 || height != 0) { - setSize(width, height); - } - for (Map.Entry e : withElements.entrySet()) { - addElements(e.getValue(), e.getKey()); - } - } - - @Override - protected GuiPanel getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/GuiScreen.java b/src/main/java/de/johni0702/minecraft/gui/container/GuiScreen.java deleted file mode 100644 index 292eeca6..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/GuiScreen.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -public class GuiScreen extends AbstractGuiScreen { - @SuppressWarnings("unchecked") - public static AbstractGuiScreen from(net.minecraft.client.gui.GuiScreen minecraft) { - if (!(minecraft instanceof AbstractGuiScreen.MinecraftGuiScreen)) { - return null; - } - return ((AbstractGuiScreen.MinecraftGuiScreen) minecraft).getWrapper(); - } - - public static GuiScreen wrap(final net.minecraft.client.gui.GuiScreen minecraft) { - return new GuiScreen() { - @Override - public net.minecraft.client.gui.GuiScreen toMinecraft() { - return minecraft; - } - }; - } - - @Override - protected GuiScreen getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/GuiScrollable.java b/src/main/java/de/johni0702/minecraft/gui/container/GuiScrollable.java deleted file mode 100644 index 44c98047..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/GuiScrollable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -public class GuiScrollable extends AbstractGuiScrollable { - @Override - protected GuiScrollable getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/container/GuiVerticalList.java b/src/main/java/de/johni0702/minecraft/gui/container/GuiVerticalList.java deleted file mode 100644 index 78d113da..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/container/GuiVerticalList.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.container; - -public class GuiVerticalList extends AbstractGuiVerticalList { - public GuiVerticalList() { - } - - public GuiVerticalList(GuiContainer container) { - super(container); - } - - @Override - protected GuiVerticalList getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractComposedGuiElement.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractComposedGuiElement.java deleted file mode 100644 index 51de9ef3..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractComposedGuiElement.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Ordering; -import de.johni0702.minecraft.gui.container.GuiContainer; -import net.minecraft.crash.CrashReport; -import net.minecraft.crash.CrashReportCategory; -import net.minecraft.util.ReportedException; - -import javax.annotation.Nullable; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.Callable; - -public abstract class AbstractComposedGuiElement> - extends AbstractGuiElement implements ComposedGuiElement { - public AbstractComposedGuiElement() { - } - - public AbstractComposedGuiElement(GuiContainer container) { - super(container); - } - - @Override - public int getMaxLayer() { - return getLayer() + Ordering.natural().max(Iterables.concat(Collections.singleton(0), - Iterables.transform(getChildren(), new Function() { - - @Nullable - @Override - public Integer apply(GuiElement e) { - return e instanceof ComposedGuiElement ? ((ComposedGuiElement) e).getMaxLayer() : e.getLayer(); - } - }))); - } - - @Override - @SuppressWarnings("unchecked") - public C forEach(final Class ofType) { - int maxLayer = getMaxLayer(); - final List layers = new ArrayList(maxLayer + 1); - for (int i = maxLayer; i >= 0; i--) { - layers.add(forEach(i, ofType)); - } - return (C) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ofType}, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - boolean isGetter = method.getName().startsWith("get"); - Object handled = method.getReturnType().equals(boolean.class) ? false : null; - for (final C layer : layers) { - handled = method.invoke(layer, args); - if (handled != null) { - if (handled instanceof Boolean) { - if (Boolean.TRUE.equals(handled)) { - break; - } - } else if (isGetter) { - return handled; - } - } - } - return handled; - } - }); - } - - @Override - @SuppressWarnings("unchecked") - public C forEach(final int layer, final Class ofType) { - return (C) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ofType}, new InvocationHandler() { - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - boolean isGetter = method.getName().startsWith("get"); - Object handled = method.getReturnType().equals(boolean.class) ? false : null; - final AbstractComposedGuiElement self = AbstractComposedGuiElement.this; - if (ofType.isInstance(self) && self.getLayer() == layer) { - try { - handled = method.invoke(self, args); - } catch (Exception e) { - CrashReport crash = CrashReport.makeCrashReport(e, "Calling Gui method"); - CrashReportCategory category = crash.makeCategory("Gui"); - category.addCrashSection("Method", method); - category.addCrashSectionCallable("ComposedElement", new Callable() { - @Override - public Object call() throws Exception { - return self; - } - }); - category.addCrashSectionCallable("Element", new Callable() { - @Override - public Object call() throws Exception { - return self; - } - }); - throw new ReportedException(crash); - } - if (handled != null) { - if (handled instanceof Boolean) { - if (Boolean.TRUE.equals(handled)) { - return true; - } - } else if (isGetter) { - return handled; - } - } - } - for (final GuiElement element : getChildren()) { - try { - if (element instanceof ComposedGuiElement) { - ComposedGuiElement composed = (ComposedGuiElement) element; - if (layer <= composed.getMaxLayer()) { - Object elementProxy = composed.forEach(layer - composed.getLayer(), ofType); - handled = method.invoke(elementProxy, args); - } - } else if (ofType.isInstance(element) && element.getLayer() == layer) { - handled = method.invoke(element, args); - } - if (handled != null) { - if (handled instanceof Boolean) { - if (Boolean.TRUE.equals(handled)) { - break; - } - } else if (isGetter) { - return handled; - } - } - } catch (Exception e) { - CrashReport crash = CrashReport.makeCrashReport(e, "Calling Gui method"); - CrashReportCategory category = crash.makeCategory("Gui"); - category.addCrashSection("Method", method); - category.addCrashSectionCallable("ComposedElement", new Callable() { - @Override - public Object call() throws Exception { - return element; - } - }); - category.addCrashSectionCallable("Element", new Callable() { - @Override - public Object call() throws Exception { - return element; - } - }); - throw new ReportedException(crash); - } - } - return handled; - } - }); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiButton.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiButton.java deleted file mode 100644 index 79908f77..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiButton.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.function.Clickable; -import lombok.Getter; -import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; - -import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; -import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; - -public abstract class AbstractGuiButton> extends AbstractGuiClickable implements Clickable, IGuiButton { - protected static final ResourceLocation BUTTON_SOUND = new ResourceLocation("gui.button.press"); - protected static final ResourceLocation WIDGETS_TEXTURE = new ResourceLocation("textures/gui/widgets.png"); - - @Getter - private String label; - - public AbstractGuiButton() { - } - - public AbstractGuiButton(GuiContainer container) { - super(container); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - super.draw(renderer, size, renderInfo); - - renderer.bindTexture(WIDGETS_TEXTURE); - GlStateManager.color(1, 1, 1, 1); - - byte texture = 1; - int color = 0xe0e0e0; - if (!isEnabled()) { - texture = 0; - color = 0xa0a0a0; - } else if (isMouseHovering(new Point(renderInfo.mouseX, renderInfo.mouseY))) { - texture = 2; - color = 0xffffa0; - } - - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, 0); - GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - int textureY = 46 + texture * 20; - int halfWidth = size.getWidth() / 2; - - renderer.drawTexturedRect(0, 0, 0, textureY, halfWidth, size.getHeight()); - renderer.drawTexturedRect(halfWidth, 0, 200 - halfWidth, textureY, halfWidth, size.getHeight()); - renderer.drawCenteredString(halfWidth, (size.getHeight() - 8) / 2, color, label, true); - } - - @Override - public ReadableDimension calcMinSize() { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - return new Dimension(fontRenderer.getStringWidth(label), 20); - } - - @Override - public void onClick() { - getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F)); - super.onClick(); - } - - @Override - public T setLabel(String label) { - this.label = label; - return getThis(); - } - - @Override - public T setI18nLabel(String label, Object... args) { - return setLabel(I18n.format(label, args)); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiCheckbox.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiCheckbox.java deleted file mode 100644 index f9632b02..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiCheckbox.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import lombok.Getter; -import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.util.Color; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.ReadableColor; -import org.lwjgl.util.ReadableDimension; - -public abstract class AbstractGuiCheckbox> - extends AbstractGuiClickable implements IGuiCheckbox { - protected static final ResourceLocation BUTTON_SOUND = new ResourceLocation("gui.button.press"); - protected static final ReadableColor BOX_BACKGROUND_COLOR = new Color(46, 46, 46); - - @Getter - private String label; - - @Getter - private boolean checked; - - public AbstractGuiCheckbox() { - } - - public AbstractGuiCheckbox(GuiContainer container) { - super(container); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - super.draw(renderer, size, renderInfo); - - int color = 0xe0e0e0; - if (!isEnabled()) { - color = 0xa0a0a0; - } - - int boxSize = size.getHeight(); - renderer.drawRect(0, 0, boxSize, boxSize, ReadableColor.BLACK); - renderer.drawRect(1, 1, boxSize - 2, boxSize - 2, BOX_BACKGROUND_COLOR); - - if(isChecked()) { - renderer.drawCenteredString(boxSize / 2 + 1, 1, color, "x", true); - } - - renderer.drawString(boxSize + 2, 2, color, label); - } - - @Override - public ReadableDimension calcMinSize() { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int height = fontRenderer.FONT_HEIGHT + 2; - int width = height + 2 + fontRenderer.getStringWidth(label); - return new Dimension(width, height); - } - - @Override - public ReadableDimension getMaxSize() { - return getMinSize(); - } - - @Override - public void onClick() { - getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F)); - setChecked(!isChecked()); - super.onClick(); - } - - @Override - public T setLabel(String label) { - this.label = label; - return getThis(); - } - - @Override - public T setI18nLabel(String label, Object... args) { - return setLabel(I18n.format(label, args)); - } - - @Override - public T setChecked(boolean checked) { - this.checked = checked; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiClickable.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiClickable.java deleted file mode 100644 index 2fd4fa49..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiClickable.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.function.Clickable; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -public abstract class AbstractGuiClickable> extends AbstractGuiElement implements Clickable, IGuiClickable { - private Runnable onClick; - private ReadableDimension size; - - public AbstractGuiClickable() { - } - - public AbstractGuiClickable(GuiContainer container) { - super(container); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - Point pos = new Point(position); - if (getContainer() != null) { - getContainer().convertFor(this, pos); - } - - if (isMouseHovering(pos) && isEnabled()) { - onClick(); - return true; - } - return false; - } - - protected boolean isMouseHovering(ReadablePoint pos) { - return pos.getX() > 0 && pos.getY() > 0 - && pos.getX() < size.getWidth() && pos.getY() < size.getHeight(); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - this.size = size; - } - - protected void onClick() { - if (onClick != null) { - onClick.run(); - } - } - - @Override - public T onClick(Runnable onClick) { - this.onClick = onClick; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiElement.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiElement.java deleted file mode 100644 index 1aa93307..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiElement.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import lombok.Getter; -import net.minecraft.client.Minecraft; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; - -public abstract class AbstractGuiElement> implements GuiElement { - protected static final ResourceLocation TEXTURE = new ResourceLocation("guiapi", "gui.png"); - - @Getter - private final Minecraft minecraft = Minecraft.getMinecraft(); - - @Getter - private GuiContainer container; - - private GuiElement tooltip; - - @Getter - private boolean enabled = true; - - protected Dimension minSize, maxSize; - - public AbstractGuiElement() { - } - - public AbstractGuiElement(GuiContainer container) { - container.addElements(null, this); - } - - protected abstract T getThis(); - - @Override - public T setEnabled(boolean enabled) { - this.enabled = enabled; - return getThis(); - } - - @Override - public T setEnabled() { - return setEnabled(true); - } - - @Override - public T setDisabled() { - return setEnabled(false); - } - - @Override - public GuiElement getTooltip(RenderInfo renderInfo) { - if (tooltip != null) { - Point mouse = new Point(renderInfo.mouseX, renderInfo.mouseY); - if (container != null) { - container.convertFor(this, mouse); - } - ReadableDimension size = getMinSize(); - if (mouse.getX() > 0 - && mouse.getY() > 0 - && mouse.getX() < size.getWidth() - && mouse.getY() < size.getHeight()) { - return tooltip; - } - } - return null; - } - - @Override - public T setTooltip(GuiElement tooltip) { - this.tooltip = tooltip; - return getThis(); - } - - @Override - public T setContainer(GuiContainer container) { - this.container = container; - return getThis(); - } - - public T setMinSize(ReadableDimension minSize) { - this.minSize = new Dimension(minSize); - return getThis(); - } - - public T setMaxSize(ReadableDimension maxSize) { - this.maxSize = new Dimension(maxSize); - return getThis(); - } - - public T setSize(ReadableDimension size) { - setMinSize(size); - return setMaxSize(size); - } - - public T setSize(int width, int height) { - return setSize(new Dimension(width, height)); - } - - public T setWidth(int width) { - if (minSize == null) { - minSize = new Dimension(width, 0); - } else { - minSize.setWidth(width); - } - if (maxSize == null) { - maxSize = new Dimension(width, Integer.MAX_VALUE); - } else { - maxSize.setWidth(width); - } - return getThis(); - } - - public T setHeight(int height) { - if (minSize == null) { - minSize = new Dimension(0, height); - } else { - minSize.setHeight(height); - } - if (maxSize == null) { - maxSize = new Dimension(Integer.MAX_VALUE, height); - } else { - maxSize.setHeight(height); - } - return getThis(); - } - - public int getLayer() { - return 0; - } - - @Override - public ReadableDimension getMinSize() { - ReadableDimension calcSize = calcMinSize(); - if (minSize == null) { - return calcSize; - } else { - if (minSize.getWidth() >= calcSize.getWidth() && minSize.getHeight() >= calcSize.getHeight()) { - return minSize; - } else { - return new Dimension( - Math.max(calcSize.getWidth(), minSize.getWidth()), - Math.max(calcSize.getHeight(), minSize.getHeight()) - ); - } - } - } - - protected abstract ReadableDimension calcMinSize(); - - @Override - public ReadableDimension getMaxSize() { - return maxSize == null ? new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE) : maxSize; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiImage.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiImage.java deleted file mode 100644 index 0c3f42d3..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiImage.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import com.google.common.base.Preconditions; -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import lombok.RequiredArgsConstructor; -import net.minecraft.client.renderer.texture.DynamicTexture; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.ReadableDimension; - -import java.awt.image.BufferedImage; - -public abstract class AbstractGuiImage> - extends AbstractGuiElement implements IGuiImage { - private DynamicTexture texture; - private ResourceLocation resourceLocation; - private int u, v; - private int uWidth, vHeight; - private int textureWidth, textureHeight; - - /** - * Reference to the copied image to prevent it from being garbage collected - * and subsequently releasing the OpenGL texture. - */ - private AbstractGuiImage copyOf; - - public AbstractGuiImage() { - } - - public AbstractGuiImage(GuiContainer container) { - super(container); - } - - public AbstractGuiImage(AbstractGuiImage copyOf) { - this.texture = copyOf.texture; - this.resourceLocation = copyOf.resourceLocation; - this.u = copyOf.u; - this.v = copyOf.v; - this.uWidth = copyOf.uWidth; - this.vHeight = copyOf.vHeight; - this.textureWidth = copyOf.textureWidth; - this.textureHeight = copyOf.textureHeight; - this.copyOf = copyOf; - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - if (texture != null) { - renderer.bindTexture(texture); - } else { - renderer.bindTexture(resourceLocation); - } - int w = size.getWidth(); - int h = size.getHeight(); - renderer.drawTexturedRect(0, 0, u, v, w, h, uWidth, vHeight, textureWidth, textureHeight); - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - if (texture != null && copyOf == null) { - getMinecraft().addScheduledTask(new Finalizer(texture)); - } - } - - @Override - public ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } - - @Override - public T setTexture(BufferedImage img) { - Preconditions.checkState(copyOf == null, "Cannot change texture of copy."); - resourceLocation = null; - if (texture != null) { - texture.deleteGlTexture(); - } - texture = new DynamicTexture(img); - textureWidth = uWidth = img.getWidth(); - textureHeight = vHeight = img.getHeight(); - return getThis(); - } - - @Override - public T setTexture(ResourceLocation resourceLocation) { - Preconditions.checkState(copyOf == null, "Cannot change texture of copy."); - if (texture != null) { - texture.deleteGlTexture(); - texture = null; - } - this.resourceLocation = resourceLocation; - textureWidth = textureHeight = 256; - return getThis(); - } - - @Override - public T setTexture(ResourceLocation resourceLocation, int u, int v, int width, int height) { - setTexture(resourceLocation); - setUV(u, v); - setUVSize(width, height); - return getThis(); - } - - @Override - public T setU(int u) { - this.u = u; - return getThis(); - } - - @Override - public T setV(int v) { - this.v = v; - return getThis(); - } - - @Override - public T setUV(int u, int v) { - setU(u); - return setV(v); - } - - @Override - public T setUWidth(int width) { - this.uWidth = width; - return getThis(); - } - - @Override - public T setVHeight(int height) { - this.vHeight = height; - return getThis(); - } - - @Override - public T setUVSize(int width, int height) { - setUWidth(width); - return setVHeight(height); - } - - /** - * We use a static class here in order to prevent the inner class from keeping the outer class - * alive after finalization when still unloading the texture. - */ - @RequiredArgsConstructor - private static final class Finalizer implements Runnable { - private final DynamicTexture texture; - - @Override - public void run() { - texture.deleteGlTexture(); - } - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiLabel.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiLabel.java deleted file mode 100644 index a851e9ae..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiLabel.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import lombok.Getter; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.resources.I18n; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.ReadableColor; -import org.lwjgl.util.ReadableDimension; - -import java.util.List; - -public abstract class AbstractGuiLabel> extends AbstractGuiElement implements IGuiLabel { - @Getter - private String text = ""; - - @Getter - private ReadableColor color = ReadableColor.WHITE, disabledColor = ReadableColor.GREY; - - public AbstractGuiLabel() { - } - - public AbstractGuiLabel(GuiContainer container) { - super(container); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - @SuppressWarnings("unchecked") - List lines = fontRenderer.listFormattedStringToWidth(text, size.getWidth()); - int y = 0; - for (String line : lines) { - renderer.drawString(0, y, isEnabled() ? color : disabledColor, line); - y+=fontRenderer.FONT_HEIGHT; - } - } - - @Override - public ReadableDimension calcMinSize() { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - return new Dimension(fontRenderer.getStringWidth(text), fontRenderer.FONT_HEIGHT); - } - - @Override - public ReadableDimension getMaxSize() { - return getMinSize(); - } - - @Override - public T setText(String text) { - this.text = text; - return getThis(); - } - - @Override - public T setI18nText(String text, Object... args) { - return setText(I18n.format(text, args)); - } - - @Override - public T setColor(ReadableColor color) { - this.color = color; - return getThis(); - } - - @Override - public T setDisabledColor(ReadableColor disabledColor) { - this.disabledColor = disabledColor; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiNumberField.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiNumberField.java deleted file mode 100644 index b80ddaee..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiNumberField.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import com.google.common.base.Preconditions; -import de.johni0702.minecraft.gui.container.GuiContainer; - -import java.util.regex.Pattern; - -// TODO: This is suboptimal e.g. if there are trailing zeros, they stay (should be fixed after TextField is done w/o MC) -public abstract class AbstractGuiNumberField> - extends AbstractGuiTextField implements IGuiNumberField { - - private int precision; - private volatile Pattern precisionPattern; - - public AbstractGuiNumberField() { - } - - public AbstractGuiNumberField(GuiContainer container) { - super(container); - } - - { - setValue(0); - } - - @Override - public T setText(String text) { - if (!isTextValid(text)) { - throw new IllegalArgumentException(text + " is not a valid number!"); - } - return super.setText(text); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") - private boolean isTextValid(String text) { - try { - if (precision == 0) { - Integer.parseInt(text); - return true; - } else { - Double.parseDouble(text); - return precisionPattern.matcher(text).matches(); - } - } catch (NumberFormatException e) { - return false; - } - } - - @Override - protected void onTextChanged(String from) { - if (isTextValid(getText())) { - super.onTextChanged(from); - } else { - setText(from); - } - } - - @Override - public byte getByte() { - return Byte.parseByte(getText()); - } - - @Override - public short getShort() { - return Short.parseShort(getText()); - } - - @Override - public int getInteger() { - return Integer.parseInt(getText()); - } - - @Override - public long getLong() { - return Long.parseLong(getText()); - } - - @Override - public float getFloat() { - return Float.parseFloat(getText()); - } - - @Override - public double getDouble() { - return Double.parseDouble(getText()); - } - - @Override - public T setValue(int value) { - setText(Integer.toString(value)); - return getThis(); - } - - @Override - public T setValue(double value) { - setText(String.format("%." + precision + "f", value)); - return getThis(); - } - - @Override - public T setPrecision(int precision) { - Preconditions.checkArgument(precision >= 0, "precision must not be negative"); - precisionPattern = Pattern.compile(String.format("-?[0-9]*+((\\.[0-9]{0,%d})?)||(\\.)?", precision)); - this.precision = precision; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiPasswordField.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiPasswordField.java deleted file mode 100644 index 510eda5c..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiPasswordField.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import org.apache.commons.lang3.StringUtils; -import org.lwjgl.util.ReadableDimension; - -public abstract class AbstractGuiPasswordField> extends AbstractGuiTextField { - public AbstractGuiPasswordField() { - } - - public AbstractGuiPasswordField(GuiContainer container) { - super(container); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - String text = getText(); - setText(StringUtils.repeat('*', text.length())); - super.draw(renderer, size, renderInfo); - setText(text); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiSlider.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiSlider.java deleted file mode 100644 index 2a3c58b5..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiSlider.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.function.Clickable; -import de.johni0702.minecraft.gui.function.Draggable; -import net.minecraft.client.resources.I18n; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -// TODO: Currently assumes a height of 20 -public abstract class AbstractGuiSlider> extends AbstractGuiElement implements Clickable, Draggable, IGuiSlider { - private Runnable onValueChanged; - private ReadableDimension size; - - private int value; - private int steps; - - private String text = ""; - - private boolean dragging; - - public AbstractGuiSlider() { - } - - public AbstractGuiSlider(GuiContainer container) { - super(container); - } - - @Override - protected ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - Point pos = new Point(position); - if (getContainer() != null) { - getContainer().convertFor(this, pos); - } - - if (isMouseHovering(pos) && isEnabled()) { - updateValue(pos); - dragging = true; - return true; - } - return false; - } - - @Override - public boolean mouseDrag(ReadablePoint position, int button, long timeSinceLastCall) { - if (dragging) { - Point pos = new Point(position); - if (getContainer() != null) { - getContainer().convertFor(this, pos); - } - updateValue(pos); - } - return dragging; - } - - @Override - public boolean mouseRelease(ReadablePoint position, int button) { - if (dragging) { - dragging = false; - Point pos = new Point(position); - if (getContainer() != null) { - getContainer().convertFor(this, pos); - } - updateValue(pos); - return true; - } else { - return false; - } - } - - protected boolean isMouseHovering(ReadablePoint pos) { - return pos.getX() > 0 && pos.getY() > 0 - && pos.getX() < size.getWidth() && pos.getY() < size.getHeight(); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - this.size = size; - - int width = size.getWidth(); - int height = size.getHeight(); - - renderer.bindTexture(GuiButton.WIDGETS_TEXTURE); - - // Draw background - renderer.drawTexturedRect(0, 0, 0, 46, width / 2, height); - renderer.drawTexturedRect(width / 2, 0, 200 - width / 2, 46, width / 2, height); - - // Draw slider - int sliderX = (width - 8) * value / steps; - renderer.drawTexturedRect(sliderX, 0, 0, 66, 4, 20); - renderer.drawTexturedRect(sliderX + 4, 0, 196, 66, 4, 20); - - // Draw text - int color = 0xe0e0e0; - if (!isEnabled()) { - color = 0xa0a0a0; - } else if (isMouseHovering(new Point(renderInfo.mouseX, renderInfo.mouseY))) { - color = 0xffffa0; - } - renderer.drawCenteredString(width / 2, height / 2 - 4, color, text); - } - - protected void updateValue(ReadablePoint position) { - if (size == null) { - return; - } - int width = size.getWidth() - 8; - int pos = Math.max(0, Math.min(width, position.getX() - 4)); - setValue(steps * pos / width); - } - - public void onValueChanged() { - if (onValueChanged != null) { - onValueChanged.run(); - } - } - - @Override - public T setText(String text) { - this.text = text; - return getThis(); - } - - @Override - public T setI18nText(String text, Object... args) { - return setText(I18n.format(text, args)); - } - - @Override - public T setValue(int value) { - this.value = value; - onValueChanged(); - return getThis(); - } - - @Override - public int getValue() { - return value; - } - - @Override - public int getSteps() { - return steps; - } - - @Override - public T setSteps(int steps) { - this.steps = steps; - return getThis(); - } - - @Override - public T onValueChanged(Runnable runnable) { - this.onValueChanged = runnable; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTextField.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTextField.java deleted file mode 100644 index 96102cdd..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTextField.java +++ /dev/null @@ -1,602 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.function.Clickable; -import de.johni0702.minecraft.gui.function.Focusable; -import de.johni0702.minecraft.gui.function.Tickable; -import de.johni0702.minecraft.gui.function.Typeable; -import de.johni0702.minecraft.gui.utils.Consumer; -import lombok.Getter; -import lombok.NonNull; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.client.resources.I18n; -import net.minecraft.util.ChatAllowedCharacters; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.*; - -import static net.minecraft.client.renderer.GlStateManager.*; -import static net.minecraft.client.renderer.GlStateManager.disableColorLogic; -import static net.minecraft.client.renderer.GlStateManager.enableTexture2D; -import static net.minecraft.util.MathHelper.clamp_int; - -public abstract class AbstractGuiTextField> - extends AbstractGuiElement implements Clickable, Tickable, Typeable, IGuiTextField { - private static final ReadableColor BORDER_COLOR = new Color(160, 160, 160); - private static final ReadableColor CURSOR_COLOR = new Color(240, 240, 240); - private static final int BORDER = 4; - - // Focus - @Getter - private boolean focused; - @Getter - private Focusable next, previous; - - // Content - @Getter - private int maxLength = 32; - - @Getter - @NonNull - private String text = ""; - - private int cursorPos; - private int selectionPos; - - @Getter - private String hint; - - // Rendering - private int currentOffset; - private int blinkCursorTick; - public ReadableColor textColorEnabled = new Color(224, 224, 224); - public ReadableColor textColorDisabled = new Color(112, 112, 112); - private ReadableDimension size = new Dimension(0, 0); // Size of last render - - private Consumer textChanged; - private Runnable onEnter; - - public AbstractGuiTextField() { - } - - public AbstractGuiTextField(GuiContainer container) { - super(container); - } - - @Override - public T setText(String text) { - if (text.length() > maxLength) { - this.text = text.substring(0, maxLength); - } else { - this.text = text; - } - selectionPos = cursorPos = text.length(); - return getThis(); - } - - @Override - public T setI18nText(@NonNull String text, @NonNull Object... args) { - return setText(I18n.format(text, args)); - } - - @Override - public T setMaxLength(int maxLength) { - Preconditions.checkArgument(maxLength >= 0, "maxLength must not be negative"); - this.maxLength = maxLength; - if (text.length() > maxLength) { - setText(text); - } - return getThis(); - } - - @Override - public String deleteText(int from, int to) { - Preconditions.checkArgument(from <= to, "from must not be greater than to"); - Preconditions.checkArgument(from >= 0, "from must be greater than zero"); - Preconditions.checkArgument(to < text.length(), "to must be less than test.length()"); - - String deleted = text.substring(from, to + 1); - text = text.substring(0, from) + text.substring(to + 1); - return deleted; - } - - @Override - public int getSelectionFrom() { - return cursorPos > selectionPos ? selectionPos : cursorPos; - } - - @Override - public int getSelectionTo() { - return cursorPos > selectionPos ? cursorPos : selectionPos; - } - - @Override - public String getSelectedText() { - return text.substring(getSelectionFrom(), getSelectionTo()); - } - - @Override - public String deleteSelectedText() { - if (cursorPos == selectionPos) { - return ""; // Nothing selected - } - int from = getSelectionFrom(); - String deleted = deleteText(from, getSelectionTo() - 1); - cursorPos = selectionPos = from; - updateCurrentOffset(); - return deleted; - } - - /** - * Update current text offset to make sure the cursor is always visible. - */ - private void updateCurrentOffset() { - currentOffset = Math.min(currentOffset, cursorPos); - String line = text.substring(currentOffset, cursorPos); - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int currentWidth = fontRenderer.getStringWidth(line); - if (currentWidth > size.getWidth() - 2*BORDER) { - currentOffset = cursorPos - fontRenderer.trimStringToWidth(line, size.getWidth() - 2*BORDER, true).length(); - } - } - - @Override - public T writeText(String append) { - for (char c : append.toCharArray()) { - writeChar(c); - } - return getThis(); - } - - @Override - public T writeChar(char c) { - if (!ChatAllowedCharacters.isAllowedCharacter(c)) { - return getThis(); - } - - deleteSelectedText(); - - if (text.length() >= maxLength) { - return getThis(); - } - - text = text.substring(0, cursorPos) + c + text.substring(cursorPos); - selectionPos = ++cursorPos; - - updateCurrentOffset(); - return getThis(); - } - - @Override - public T deleteNextChar() { - if (cursorPos < text.length()) { - text = text.substring(0, cursorPos) + text.substring(cursorPos + 1); - } - selectionPos = cursorPos; - return getThis(); - } - - /** - * Return the amount of characters to the next word (excluding). - * If this is the last word in the line, return the amount of characters remaining to till the end. - * Everything except the Space character is considered part of a word. - * @return Length in characters - */ - protected int getNextWordLength() { - int length = 0; - boolean inWord = true; - for (int i = cursorPos; i < text.length(); i++) { - if (inWord) { - if (text.charAt(i) == ' ') { - inWord = false; - } - } else { - if (text.charAt(i) != ' ') { - return length; - } - } - length++; - } - return length; - } - - @Override - public String deleteNextWord() { - int worldLength = getNextWordLength(); - if (worldLength > 0) { - return deleteText(cursorPos, cursorPos + worldLength); - } - return ""; - } - - @Override - public T deletePreviousChar() { - if (cursorPos > 0) { - text = text.substring(0, cursorPos - 1) + text.substring(cursorPos); - selectionPos = --cursorPos; - updateCurrentOffset(); - } - return getThis(); - } - - /** - * Return the amount of characters to the previous word (including). - * If this is the first word in the line, return the amount of characters till the start. - * Everything except the Space character is considered part of a word. - * @return Length in characters - */ - protected int getPreviousWordLength() { - int length = 0; - boolean inWord = false; - for (int i = cursorPos - 1; i >= 0; i--) { - if (inWord) { - if (text.charAt(i) == ' ') { - return length; - } - } else { - if (text.charAt(i) != ' ') { - inWord = true; - } - } - length++; - } - return length; - } - - @Override - public String deletePreviousWord() { - int worldLength = getPreviousWordLength(); - String deleted = ""; - if (worldLength > 0) { - deleted = deleteText(cursorPos - worldLength, cursorPos); - selectionPos = cursorPos -= worldLength; - updateCurrentOffset(); - } - return deleted; - } - - @Override - public T setCursorPosition(int pos) { - Preconditions.checkArgument(pos >= 0 && pos <= text.length()); - selectionPos = cursorPos = pos; - updateCurrentOffset(); - return getThis(); - } - - /** - * Inverts all colors on the screen. - * @param guiRenderer The GUI Renderer - * @param right Right border of the inverted rectangle - * @param bottom Bottom border of the inverted rectangle - * @param left Left border of the inverted rectangle - * @param top Top border of the inverted rectangle - */ - private void invertColors(GuiRenderer guiRenderer, int right, int bottom, int left, int top) { - int x = guiRenderer.getOpenGlOffset().getX(); - int y = guiRenderer.getOpenGlOffset().getY(); - right+=x; - left+=x; - bottom+=y; - top+=y; - - color(0, 0, 255, 255); - disableTexture2D(); - enableColorLogic(); - colorLogicOp(GL11.GL_OR_REVERSE); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer renderer = tessellator.getWorldRenderer(); - renderer.startDrawingQuads(); - renderer.addVertex(right, top, 0); - renderer.addVertex(left, top, 0); - renderer.addVertex(left, bottom, 0); - renderer.addVertex(right, bottom, 0); - tessellator.draw(); - - disableColorLogic(); - enableTexture2D(); - } - - @Override - protected ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - if (getContainer() != null) { - getContainer().convertFor(this, (Point) (position = new Point(position))); - } - boolean hovering = isMouseHovering(position); - - if (hovering && isFocused() && button == 0) { - int mouseX = position.getX() - BORDER; - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - String text = this.text.substring(currentOffset); - int textX = fontRenderer.trimStringToWidth(text, mouseX).length() + currentOffset; - setCursorPosition(textX); - } - - setFocused(hovering); - return hovering; - } - - protected boolean isMouseHovering(ReadablePoint pos) { - return pos.getX() > 0 && pos.getY() > 0 - && pos.getX() < size.getWidth() && pos.getY() < size.getHeight(); - } - - @Override - public T setFocused(boolean isFocused) { - if (isFocused && !this.focused) { - this.blinkCursorTick = 0; // Restart blinking to indicate successful focus - } - this.focused = isFocused; - return getThis(); - } - - @Override - public T setNext(Focusable next) { - this.next = next; - return getThis(); - } - - @Override - public T setPrevious(Focusable previous) { - this.previous = previous; - return getThis(); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - this.size = size; - int width = size.getWidth(), height = size.getHeight(); - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int posY = height / 2 - fontRenderer.FONT_HEIGHT / 2; - - // Draw black rect once pixel smaller than gray rect - renderer.drawRect(0, 0, width, height, BORDER_COLOR); - renderer.drawRect(1, 1, width - 2, height - 2, ReadableColor.BLACK); - - if (text.isEmpty() && !isFocused() && !Strings.isNullOrEmpty(hint)) { - // Draw hint - String text = fontRenderer.trimStringToWidth(hint, width - 2*BORDER); - renderer.drawString(BORDER, posY, textColorDisabled, text); - } else { - // Draw text - String renderText = text.substring(currentOffset); - renderText = fontRenderer.trimStringToWidth(renderText, width - 2*BORDER); - ReadableColor color = isEnabled() ? textColorEnabled : textColorDisabled; - int lineEnd = renderer.drawString(BORDER, height / 2 - fontRenderer.FONT_HEIGHT / 2, color, renderText); - - // Draw selection - int from = getSelectionFrom(); - int to = getSelectionTo(); - String leftStr = text.substring(0, clamp_int(from - currentOffset, 0, text.length())); - String rightStr = text.substring(clamp_int(to - currentOffset, 0, text.length())); - int left = BORDER + fontRenderer.getStringWidth(leftStr); - int right = lineEnd - fontRenderer.getStringWidth(rightStr) - 1; - invertColors(renderer, right, height - 2, left, 2); - - // Draw cursor - if (blinkCursorTick / 6 % 2 == 0 && focused) { - String beforeCursor = text.substring(0, cursorPos - currentOffset); - int posX = BORDER + fontRenderer.getStringWidth(beforeCursor); - if (cursorPos == text.length()) { - renderer.drawString(posX, posY, CURSOR_COLOR, "_", true); - } else { - renderer.drawRect(posX, posY - 1, 1, 1 + fontRenderer.FONT_HEIGHT, CURSOR_COLOR); - } - } - } - } - - @Override - public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) { - if (!this.focused) { - return false; - } - - if (keyCode == Keyboard.KEY_TAB) { - Focusable other = shiftDown ? previous : next; - if (other != null) { - setFocused(false); - other.setFocused(true); - } - return true; - } - - if (keyCode == Keyboard.KEY_RETURN) { - onEnter(); - return true; - } - - String textBefore = text; - try { - if (GuiScreen.isCtrlKeyDown()) { - switch (keyCode) { - case Keyboard.KEY_A: // Select all - cursorPos = 0; - selectionPos = text.length(); - updateCurrentOffset(); - return true; - case Keyboard.KEY_C: // Copy - GuiScreen.setClipboardString(getSelectedText()); - return true; - case Keyboard.KEY_V: // Paste - if (isEnabled()) { - writeText(GuiScreen.getClipboardString()); - } - return true; - case Keyboard.KEY_X: // Cut - if (isEnabled()) { - GuiScreen.setClipboardString(deleteSelectedText()); - } - return true; - } - } - - boolean words = GuiScreen.isCtrlKeyDown(); - boolean select = GuiScreen.isShiftKeyDown(); - switch (keyCode) { - case Keyboard.KEY_HOME: - cursorPos = 0; - break; - case Keyboard.KEY_END: - cursorPos = text.length(); - break; - case Keyboard.KEY_LEFT: - if (cursorPos != 0) { - if (words) { - cursorPos -= getPreviousWordLength(); - } else { - cursorPos--; - } - } - break; - case Keyboard.KEY_RIGHT: - if (cursorPos != text.length()) { - if (words) { - cursorPos += getNextWordLength(); - } else { - cursorPos++; - } - } - break; - case Keyboard.KEY_BACK: - if (isEnabled()) { - if (getSelectedText().length() > 0) { - deleteSelectedText(); - } else if (words) { - deletePreviousWord(); - } else { - deletePreviousChar(); - } - } - return true; - case Keyboard.KEY_DELETE: - if (isEnabled()) { - if (getSelectedText().length() > 0) { - deleteSelectedText(); - } else if (words) { - deleteNextWord(); - } else { - deleteNextChar(); - } - } - return true; - default: - if (isEnabled()) { - if (keyChar == '\r') { - keyChar = '\n'; - } - writeChar(keyChar); - } - return true; - } - - updateCurrentOffset(); - - if (!select) { - selectionPos = cursorPos; - } - return true; - } finally { - if (!textBefore.equals(text)) { - onTextChanged(textBefore); - } - } - } - - @Override - public void tick() { - blinkCursorTick++; - } - - /** - * Called when the user presses the Enter/Return key while this text field is focused. - */ - protected void onEnter() { - if (onEnter != null) { - onEnter.run(); - } - } - - /** - * Called when the text has changed due to user input. - */ - protected void onTextChanged(String from) { - if (textChanged != null) { - textChanged.consume(from); - } - } - - @Override - public T onEnter(Runnable onEnter) { - this.onEnter = onEnter; - return getThis(); - } - - @Override - public T onTextChanged(Consumer textChanged) { - this.textChanged = textChanged; - return getThis(); - } - - @Override - public T setHint(String hint) { - this.hint = hint; - return getThis(); - } - - @Override - public T setI18nHint(String hint, Object... args) { - return setHint(I18n.format(hint)); - } - - @Override - public ReadableColor getTextColor() { - return textColorEnabled; - } - - @Override - public T setTextColor(ReadableColor textColor) { - this.textColorEnabled = textColor; - return getThis(); - } - - @Override - public T setTextColorDisabled(ReadableColor textColorDisabled) { - this.textColorDisabled = textColorDisabled; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTexturedButton.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTexturedButton.java deleted file mode 100644 index 02b77f6f..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTexturedButton.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.function.Clickable; -import lombok.Getter; -import net.minecraft.client.audio.PositionedSoundRecord; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.ResourceLocation; -import org.lwjgl.util.*; - -import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA; -import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; - -public abstract class AbstractGuiTexturedButton> extends AbstractGuiClickable implements Clickable, IGuiTexturedButton { - protected static final ResourceLocation BUTTON_SOUND = new ResourceLocation("gui.button.press"); - - @Getter - private ResourceLocation texture; - - @Getter - private ReadableDimension textureSize = new ReadableDimension() { - @Override - public int getWidth() { - return getMaxSize().getWidth(); - } - - @Override - public int getHeight() { - return getMaxSize().getHeight(); - } - - @Override - public void getSize(WritableDimension dest) { - getMaxSize().getSize(dest); - } - }; - - @Getter - private ReadableDimension textureTotalSize; - - @Getter - private ReadablePoint textureNormal; - - @Getter - private ReadablePoint textureHover; - - @Getter - private ReadablePoint textureDisabled; - - public AbstractGuiTexturedButton() { - } - - public AbstractGuiTexturedButton(GuiContainer container) { - super(container); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - super.draw(renderer, size, renderInfo); - - renderer.bindTexture(texture); - - ReadablePoint texture = textureNormal; - if (!isEnabled()) { - texture = textureDisabled; - } else if (isMouseHovering(new Point(renderInfo.mouseX, renderInfo.mouseY))) { - texture = textureHover; - } - - if (texture == null) { // Button is disabled but we have no texture for that - GlStateManager.color(0.5f, 0.5f, 0.5f, 1); - texture = textureNormal; - } - - GlStateManager.enableBlend(); - GlStateManager.tryBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, 0); - GlStateManager.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - renderer.drawTexturedRect(0, 0, texture.getX(), texture.getY(), size.getWidth(), size.getHeight(), - textureSize.getWidth(), textureSize.getHeight(), - textureTotalSize.getWidth(), textureTotalSize.getHeight()); - } - - @Override - public ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } - - @Override - public void onClick() { - getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(BUTTON_SOUND, 1.0F)); - super.onClick(); - } - - @Override - public T setTexture(ResourceLocation resourceLocation, int size) { - return setTexture(resourceLocation, size, size); - } - - @Override - public T setTexture(ResourceLocation resourceLocation, int width, int height) { - this.texture = resourceLocation; - this.textureTotalSize = new Dimension(width, height); - return getThis(); - } - - @Override - public T setTextureSize(int size) { - return setTextureSize(size, size); - } - - @Override - public T setTextureSize(int width, int height) { - this.textureSize = new Dimension(width, height); - return getThis(); - } - - @Override - public T setTexturePosH(final int x, final int y) { - return setTexturePosH(new Point(x, y)); - } - - @Override - public T setTexturePosV(final int x, final int y) { - return setTexturePosV(new Point(x, y)); - } - - @Override - public T setTexturePosH(final ReadablePoint pos) { - this.textureNormal = pos; - this.textureHover = new ReadablePoint() { - @Override - public int getX() { - return pos.getX() + textureSize.getWidth(); - } - - @Override - public int getY() { - return pos.getY(); - } - - @Override - public void getLocation(WritablePoint dest) { - dest.setLocation(getX(), getY()); - } - }; - return getThis(); - } - - @Override - public T setTexturePosV(final ReadablePoint pos) { - this.textureNormal = pos; - this.textureHover = new ReadablePoint() { - @Override - public int getX() { - return pos.getX(); - } - - @Override - public int getY() { - return pos.getY() + textureSize.getHeight(); - } - - @Override - public void getLocation(WritablePoint dest) { - dest.setLocation(getX(), getY()); - } - }; - return getThis(); - } - - @Override - public T setTexturePos(int normalX, int normalY, int hoverX, int hoverY) { - return setTexturePos(new Point(normalX, normalY), new Point(hoverX, hoverY)); - } - - @Override - public T setTexturePos(ReadablePoint normal, ReadablePoint hover) { - this.textureNormal = normal; - this.textureHover = hover; - return getThis(); - } - - @Override - public T setTexturePos(int normalX, int normalY, int hoverX, int hoverY, int disabledX, int disabledY) { - return setTexturePos(new Point(normalX, normalY), new Point(hoverX, hoverY), new Point(disabledX, disabledY)); - } - - @Override - public T setTexturePos(ReadablePoint normal, ReadablePoint hover, ReadablePoint disabled) { - this.textureDisabled = disabled; - return setTexturePos(normal, hover); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiToggleButton.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiToggleButton.java deleted file mode 100644 index 64bed00e..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiToggleButton.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import lombok.Getter; -import org.lwjgl.util.ReadableDimension; - -public abstract class AbstractGuiToggleButton> - extends AbstractGuiButton implements IGuiToggleButton { - - @Getter - private int selected; - - @Getter - private V[] values; - - public AbstractGuiToggleButton() { - } - - public AbstractGuiToggleButton(GuiContainer container) { - super(container); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - String orgLabel = getLabel(); - setLabel(orgLabel + ": " + values[selected]); - super.draw(renderer, size, renderInfo); - setLabel(orgLabel); - } - - @Override - public void onClick() { - selected = (selected + 1) % values.length; - super.onClick(); - } - - @Override - public T setValues(V... values) { - this.values = values; - return getThis(); - } - - @Override - public T setSelected(int selected) { - this.selected = selected; - return getThis(); - } - - @Override - public V getSelectedValue() { - return values[selected]; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTooltip.java b/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTooltip.java deleted file mode 100644 index 3893b2b7..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/AbstractGuiTooltip.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import eu.crushedpixel.replaymod.utils.StringUtils; -import lombok.Getter; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.resources.I18n; -import org.lwjgl.util.Color; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.ReadableColor; -import org.lwjgl.util.ReadableDimension; - -public abstract class AbstractGuiTooltip> extends AbstractGuiElement { - private static final int LINE_SPACING = 3; - private static final ReadableColor BACKGROUND_COLOR = new Color(16, 0, 16, 240); - private static final ReadableColor BORDER_LIGHT = new Color(80, 0, 255, 80); - private static final ReadableColor BORDER_DARK = new Color(40, 0, 127, 80); - - @Getter - private String[] text = {}; - - @Getter - private ReadableColor color = ReadableColor.WHITE; - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - int width = size.getWidth(); - int height = size.getHeight(); - - // Draw background - renderer.drawRect(1, 0, width - 2, height, BACKGROUND_COLOR); // Top to bottom - renderer.drawRect(0, 1, 1, height - 2, BACKGROUND_COLOR); // Left pixel row - renderer.drawRect(width - 1, 1, 1, height - 2, BACKGROUND_COLOR); // Right pixel row - - // Draw the border, it gets darker from top to bottom - renderer.drawRect(1, 1, width - 2, 1, BORDER_LIGHT); // Top border - renderer.drawRect(1, height - 2, width - 2, 1, BORDER_DARK); // Bottom border - renderer.drawRect(1, 2, 1, height - 4, BORDER_LIGHT, BORDER_LIGHT, BORDER_DARK, BORDER_DARK); // Left border - renderer.drawRect(width - 2, 2, 1, height - 4, BORDER_LIGHT, BORDER_LIGHT, BORDER_DARK, BORDER_DARK); // Right border - - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int y = LINE_SPACING + 1; - for (String line : text) { - renderer.drawString(LINE_SPACING + 1, y, color, line, true); - y += fontRenderer.FONT_HEIGHT + LINE_SPACING; - } - } - - @Override - public ReadableDimension calcMinSize() { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int height = 1 + LINE_SPACING + text.length * (fontRenderer.FONT_HEIGHT + LINE_SPACING); - int width = 0; - for (String line : text) { - int w = fontRenderer.getStringWidth(line); - if (w > width) { - width = w; - } - } - width+=4 * 2; - return new Dimension(width, height); - } - - @Override - public ReadableDimension getMaxSize() { - return getMinSize(); - } - - public T setText(String[]text) { - this.text = text; - return getThis(); - } - - public T setText(String text) { - return setText(StringUtils.splitStringInMultipleRows(text, 250)); - } - - public T setI18nText(String text, Object... args) { - return setText(I18n.format(text, args)); - } - - public T setColor(ReadableColor color) { - this.color = color; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/ComposedGuiElement.java b/src/main/java/de/johni0702/minecraft/gui/element/ComposedGuiElement.java deleted file mode 100644 index 02dc3741..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/ComposedGuiElement.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import java.util.Collection; - -public interface ComposedGuiElement> extends GuiElement { - Collection getChildren(); - - C forEach(Class ofType); - C forEach(int layer, Class ofType); - - /** - * Returns the highest layer this element or any of its children take part in. - * Events will be called for this composed gui element for all layers between - * layer 0 (inclusive) and the returned maximum layer (inclusive). - * @return Highest layer relevant to this element - */ - int getMaxLayer(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiButton.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiButton.java deleted file mode 100644 index 50dc69b4..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiButton.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiButton extends AbstractGuiButton { - public GuiButton() { - } - - public GuiButton(GuiContainer container) { - super(container); - } - - @Override - protected GuiButton getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiCheckbox.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiCheckbox.java deleted file mode 100644 index 85098141..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiCheckbox.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiCheckbox extends AbstractGuiCheckbox { - public GuiCheckbox() { - } - - public GuiCheckbox(GuiContainer container) { - super(container); - } - - @Override - protected GuiCheckbox getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiElement.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiElement.java deleted file mode 100644 index addd81a9..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiElement.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import net.minecraft.client.Minecraft; -import org.lwjgl.util.ReadableDimension; - -public interface GuiElement> { - - Minecraft getMinecraft(); - - GuiContainer getContainer(); - T setContainer(GuiContainer container); - - void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo); - - ReadableDimension getMinSize(); - ReadableDimension getMaxSize(); - - T setMaxSize(ReadableDimension maxSize); - - boolean isEnabled(); - T setEnabled(boolean enabled); - T setEnabled(); - T setDisabled(); - - GuiElement getTooltip(RenderInfo renderInfo); - T setTooltip(GuiElement tooltip); - - /** - * Returns the layer this element takes part in. - * The standard layer is layer 0. Event handlers will be called for this layer. - * @return The layer of this element - */ - int getLayer(); - -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiImage.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiImage.java deleted file mode 100644 index 00fe5928..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiImage.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiImage extends AbstractGuiImage { - public GuiImage() { - } - - public GuiImage(GuiContainer container) { - super(container); - } - - public GuiImage(GuiImage copyOf) { - super(copyOf); - } - - @Override - protected GuiImage getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiLabel.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiLabel.java deleted file mode 100644 index fde3d45a..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiLabel.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiLabel extends AbstractGuiLabel { - public GuiLabel() { - } - - public GuiLabel(GuiContainer container) { - super(container); - } - - @Override - protected GuiLabel getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiNumberField.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiNumberField.java deleted file mode 100644 index f25b90e8..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiNumberField.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiNumberField extends AbstractGuiNumberField { - public GuiNumberField() { - } - - public GuiNumberField(GuiContainer container) { - super(container); - } - - @Override - protected GuiNumberField getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiPasswordField.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiPasswordField.java deleted file mode 100644 index d7a5c890..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiPasswordField.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiPasswordField extends AbstractGuiPasswordField { - public GuiPasswordField() { - } - - public GuiPasswordField(GuiContainer container) { - super(container); - } - - @Override - protected GuiPasswordField getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiSlider.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiSlider.java deleted file mode 100644 index fac9909f..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiSlider.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiSlider extends AbstractGuiSlider { - public GuiSlider() { - } - - public GuiSlider(GuiContainer container) { - super(container); - } - - @Override - protected GuiSlider getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiTextField.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiTextField.java deleted file mode 100644 index f1f9c2b3..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiTextField.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiTextField extends AbstractGuiTextField { - public GuiTextField() { - } - - public GuiTextField(GuiContainer container) { - super(container); - } - - @Override - protected GuiTextField getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiTexturedButton.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiTexturedButton.java deleted file mode 100644 index dfe9ca67..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiTexturedButton.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiTexturedButton extends AbstractGuiTexturedButton { - public GuiTexturedButton() { - } - - public GuiTexturedButton(GuiContainer container) { - super(container); - } - - @Override - protected GuiTexturedButton getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiToggleButton.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiToggleButton.java deleted file mode 100644 index 431f16a0..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiToggleButton.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiToggleButton extends AbstractGuiToggleButton> { - public GuiToggleButton() { - } - - public GuiToggleButton(GuiContainer container) { - super(container); - } - - @Override - protected GuiToggleButton getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/GuiTooltip.java b/src/main/java/de/johni0702/minecraft/gui/element/GuiTooltip.java deleted file mode 100644 index 39d4b55b..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/GuiTooltip.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -public class GuiTooltip extends AbstractGuiTooltip { - @Override - protected GuiTooltip getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiButton.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiButton.java deleted file mode 100644 index 3440d266..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiButton.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -public interface IGuiButton> extends IGuiClickable { - T setLabel(String label); - - T setI18nLabel(String label, Object... args); - - String getLabel(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiCheckbox.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiCheckbox.java deleted file mode 100644 index b0fb71fd..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiCheckbox.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -public interface IGuiCheckbox> extends IGuiClickable { - T setLabel(String label); - - T setI18nLabel(String label, Object... args); - - T setChecked(boolean checked); - - String getLabel(); - - boolean isChecked(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiClickable.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiClickable.java deleted file mode 100644 index 5c27ac79..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiClickable.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -public interface IGuiClickable> extends GuiElement { - T onClick(Runnable onClick); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiImage.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiImage.java deleted file mode 100644 index 2c4407eb..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiImage.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import net.minecraft.util.ResourceLocation; - -import java.awt.image.BufferedImage; - -public interface IGuiImage> extends GuiElement { - T setTexture(BufferedImage img); - T setTexture(ResourceLocation resourceLocation); - T setTexture(ResourceLocation resourceLocation, int u, int v, int width, int height); - - T setU(int u); - T setV(int v); - T setUV(int u, int v); - - T setUWidth(int width); - T setVHeight(int height); - T setUVSize(int width, int height); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiLabel.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiLabel.java deleted file mode 100644 index c4fbcffc..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiLabel.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import org.lwjgl.util.ReadableColor; - -public interface IGuiLabel> extends GuiElement { - T setText(String text); - - T setI18nText(String text, Object... args); - - T setColor(ReadableColor color); - - T setDisabledColor(ReadableColor disabledColor); - - String getText(); - - ReadableColor getColor(); - - ReadableColor getDisabledColor(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiNumberField.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiNumberField.java deleted file mode 100644 index 78f686fc..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiNumberField.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -public interface IGuiNumberField> extends IGuiTextField { - byte getByte(); - short getShort(); - int getInteger(); - long getLong(); - float getFloat(); - double getDouble(); - - T setValue(int value); - T setValue(double value); - - /** - * Sets the amount of digits allowed after the decimal point. - * A value of {@code 0} is equal to integer precision. - * Negative values are not allowed. - * @param precision Number of digits allowed - */ - T setPrecision(int precision); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiSlider.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiSlider.java deleted file mode 100644 index 2a947c55..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiSlider.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -public interface IGuiSlider> extends GuiElement { - T setText(String text); - T setI18nText(String text, Object... args); - - T setValue(int value); - int getValue(); - - int getSteps(); - T setSteps(int steps); - - T onValueChanged(Runnable runnable); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiTextField.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiTextField.java deleted file mode 100644 index 567660e7..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiTextField.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import de.johni0702.minecraft.gui.function.Focusable; -import de.johni0702.minecraft.gui.utils.Consumer; -import lombok.NonNull; -import org.lwjgl.util.ReadableColor; - -public interface IGuiTextField> extends GuiElement, Focusable { - /** - * Set the text to the specified string. - * If the string is longer than {@link #getMaxLength()} it is truncated from the end. - * This method positions the cursor at the end of the text and removes any selections. - * @param text The new text - * @return {@code this} for chaining - */ - @NonNull T setText(@NonNull String text); - - /** - * Set the text to the specified string. - * If the string is longer than {@link #getMaxLength()} it is truncated from the end. - * This method positions the cursor at the end of the text and removes any selections. - * @param text The language key for the new text - * @param args The arguments used in translating the language key - * @return {@code this} for chaining - */ - @NonNull T setI18nText(@NonNull String text, @NonNull Object... args); - - /** - * Return the whole text in this text field. - * @return The text, may be empty - */ - @NonNull String getText(); - - /** - * Return the maximum allowed length of the text in this text field. - * @return Maximum number of characters - */ - int getMaxLength(); - - /** - * Set the maximum allowed length of the text in this text field. - * If the current test is longer than the new limit, it is truncated from the end (the cursor and selection - * are reset in that process, see {@link #setText(String)}). - * @param maxLength Maximum number of characters - * @return {@code this} for chaining - * @throws IllegalArgumentException When {@code maxLength} is negative - */ - T setMaxLength(int maxLength); - - /** - * Deletes the text between {@code from} and {@code to} (inclusive). - * @param from Index at which to start - * @param to Index to which to delete - * @return The deleted text - * @throws IllegalArgumentException If {@code from} is greater than {@code to} or either is out of bounds - */ - @NonNull String deleteText(int from, int to); - - /** - * Return the index at which the selection starts (inclusive) - * @return Index of first character - */ - int getSelectionFrom(); - - /** - * Return the index at which the selection ends (exclusive) - * @return Index after the last character - */ - int getSelectionTo(); - - /** - * Return the selected text. - * @return The selected text - */ - @NonNull String getSelectedText(); - - /** - * Delete the selected text. Positions the cursor at the beginning of the selection and clears the selection. - * @return The deleted text - */ - @NonNull String deleteSelectedText(); - - /** - * Appends the specified string to this text field character by character. - * Excess characters are ignored. - * @param append String to append - * @return {@code this} for chaining - * @see #writeChar(char) - */ - @NonNull T writeText(@NonNull String append); - - /** - * Appends the specified character to this text field replacing the current selection (if any). - * This does nothing if the maximum character limit is reached. - * @param c Character to append - * @return {@code this} for chaining - */ - @NonNull T writeChar(char c); - - /** - * Delete the nex character (if any). - * Clears the selection. - * @return {@code this} for chaining - */ - T deleteNextChar(); - - /** - * Delete everything from the cursor (inclusive) to the beginning of the next word (exclusive). - * If there are no more words, delete everything until the end of the line. - * @return The deleted text - */ - String deleteNextWord(); - - /** - * Delete the previous character (if any). - * @return {@code this} for chaining - */ - @NonNull T deletePreviousChar(); - - /** - * Delete everything from cursor to the first character of the previous word (or the start of the line). - * @return The deleted text - */ - @NonNull String deletePreviousWord(); - - /** - * Set the cursor position. - * @param pos Position of the cursor - * @return {@code this} for chaining - * @throws IllegalArgumentException If {@code pos} < 0 or pos > length - */ - @NonNull T setCursorPosition(int pos); - - T onEnter(Runnable onEnter); - T onTextChanged(Consumer textChanged); - - String getHint(); - T setHint(String hint); - T setI18nHint(String hint, Object... args); - - ReadableColor getTextColor(); - T setTextColor(ReadableColor textColor); - T setTextColorDisabled(ReadableColor textColorDisabled); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiTexturedButton.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiTexturedButton.java deleted file mode 100644 index 88637530..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiTexturedButton.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -import net.minecraft.util.ResourceLocation; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -public interface IGuiTexturedButton> extends IGuiClickable { - ResourceLocation getTexture(); - ReadableDimension getTextureTotalSize(); - T setTexture(ResourceLocation resourceLocation, int size); - T setTexture(ResourceLocation resourceLocation, int width, int height); - - ReadableDimension getTextureSize(); - T setTextureSize(int size); - T setTextureSize(int width, int height); - - ReadablePoint getTextureNormal(); - ReadablePoint getTextureHover(); - ReadablePoint getTextureDisabled(); - T setTexturePosH(int x, int y); - T setTexturePosV(int x, int y); - T setTexturePosH(ReadablePoint pos); - T setTexturePosV(ReadablePoint pos); - T setTexturePos(int normalX, int normalY, int hoverX, int hoverY); - T setTexturePos(ReadablePoint normal, ReadablePoint hover); - T setTexturePos(int normalX, int normalY, int hoverX, int hoverY, int disabledX, int disabledY); - T setTexturePos(ReadablePoint normal, ReadablePoint hover, ReadablePoint disabled); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/IGuiToggleButton.java b/src/main/java/de/johni0702/minecraft/gui/element/IGuiToggleButton.java deleted file mode 100644 index 36e758bb..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/IGuiToggleButton.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element; - -public interface IGuiToggleButton> extends IGuiButton { - T setValues(V[] values); - - T setSelected(int selected); - - V getSelectedValue(); - - int getSelected(); - - V[] getValues(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiDropdownMenu.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiDropdownMenu.java deleted file mode 100644 index 21bd4931..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiDropdownMenu.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.OffsetGuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.container.GuiPanel; -import de.johni0702.minecraft.gui.element.AbstractComposedGuiElement; -import de.johni0702.minecraft.gui.element.AbstractGuiClickable; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.function.Clickable; -import de.johni0702.minecraft.gui.layout.VerticalLayout; -import de.johni0702.minecraft.gui.utils.Consumer; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import net.minecraft.client.gui.FontRenderer; -import org.lwjgl.util.*; - -import java.util.Collection; -import java.util.Collections; - -public abstract class AbstractGuiDropdownMenu> - extends AbstractComposedGuiElement implements IGuiDropdownMenu, Clickable { - private static final ReadableColor OUTLINE_COLOR = new Color(160, 160, 160); - - @Getter - private int selected; - - @Getter - private V[] values; - - @Getter - private boolean opened; - - private Consumer onSelection; - - private GuiPanel dropdown; - - private ReadableDimension size; - - public AbstractGuiDropdownMenu() { - } - - public AbstractGuiDropdownMenu(GuiContainer container) { - super(container); - } - - @Override - public int getMaxLayer() { - return opened ? 1 : 0; - } - - @Override - protected ReadableDimension calcMinSize() { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int maxWidth = 0; - for (V value : values) { - int width = fontRenderer.getStringWidth(value.toString()); - if (width > maxWidth) { - maxWidth = width; - } - } - return new Dimension(11 + maxWidth + fontRenderer.FONT_HEIGHT, fontRenderer.FONT_HEIGHT + 4); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - if (renderInfo.layer == 0) { - this.size = size; - int width = size.getWidth(); - int height = size.getHeight(); - - // Draw box - renderer.drawRect(0, 0, width, height, OUTLINE_COLOR); - renderer.drawRect(1, 1, width - 2, height - 2, ReadableColor.BLACK); - renderer.drawRect(width - height, 0, 1, height, OUTLINE_COLOR); - - // Draw triangle - int base = height - 6; - int tHeight = base / 2; - int x = width - 3 - base / 2; - int y = height / 2 - 2; - for (int layer = tHeight; layer > 0; layer--) { - renderer.drawRect(x - layer, y + (tHeight - layer), layer * 2 - 1, 1, OUTLINE_COLOR); - } - - renderer.drawString(3, height / 2 - fontRenderer.FONT_HEIGHT / 2, ReadableColor.WHITE, getSelectedValue().toString()); - } else if (renderInfo.layer == 1) { - ReadablePoint offsetPoint = new Point(0, size.getHeight()); - ReadableDimension offsetSize = new Dimension(size.getWidth(), (fontRenderer.FONT_HEIGHT + 5) * values.length); - OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, offsetPoint, offsetSize); - offsetRenderer.startUsing(); - try { - dropdown.draw(offsetRenderer, offsetSize, renderInfo.offsetMouse(0, offsetPoint.getY()).layer(0)); - } finally { - offsetRenderer.stopUsing(); - } - } - } - - @Override - public T setValues(V... values) { - this.values = values; - dropdown = new GuiPanel(){ - @Override - public void convertFor(GuiElement element, Point point) { - super.convertFor(element, point); - point.translate(0, -size.getHeight()); - AbstractGuiDropdownMenu parent = AbstractGuiDropdownMenu.this; - if (parent.getContainer() != null) { - parent.getContainer().convertFor(parent, point); - } - } - }.setLayout(new VerticalLayout()); - for (V value : values) { - dropdown.addElements(null, new DropdownEntry(value)); - } - return getThis(); - } - - @Override - public T setSelected(int selected) { - this.selected = selected; - onSelection(selected); - return getThis(); - } - - @Override - public T setSelected(V value) { - for (int i = 0; i < values.length; i++) { - if (values[i].equals(value)) { - return setSelected(i); - } - } - throw new IllegalArgumentException("The value " + value + " is not in this dropdown menu."); - } - - @Override - public V getSelectedValue() { - return values[selected]; - } - - @Override - public T setOpened(boolean opened) { - this.opened = opened; - return getThis(); - } - - @Override - public Collection getChildren() { - return opened ? Collections.singletonList(dropdown) : Collections.emptyList(); - } - - @Override - public T onSelection(Consumer consumer) { - this.onSelection = consumer; - return getThis(); - } - - public void onSelection(Integer value) { - if (onSelection != null) { - onSelection.consume(value); - } - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - Point pos = new Point(position); - if (getContainer() != null) { - getContainer().convertFor(this, pos); - } - - if (isEnabled()) { - if (isMouseHovering(pos)) { - setOpened(!isOpened()); - return true; - } - } - return false; - } - - protected boolean isMouseHovering(ReadablePoint pos) { - return pos.getX() > 0 && pos.getY() > 0 - && pos.getX() < size.getWidth() && pos.getY() < size.getHeight(); - } - - @RequiredArgsConstructor - private class DropdownEntry extends AbstractGuiClickable { - private final V value; - - @Override - protected DropdownEntry getThis() { - return this; - } - - @Override - protected ReadableDimension calcMinSize() { - return new Dimension(0, getMinecraft().fontRendererObj.FONT_HEIGHT + 5); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - super.draw(renderer, size, renderInfo); - int width = size.getWidth(); - int height = size.getHeight(); - - renderer.drawRect(0, 0, width, height, OUTLINE_COLOR); - renderer.drawRect(1, 0, width - 2, height - 1, ReadableColor.BLACK); - renderer.drawString(3, 2, ReadableColor.WHITE, value.toString()); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - boolean result = super.mouseClick(position, button); - setOpened(false); - return result; - } - - @Override - protected void onClick() { - setSelected(value); - } - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiProgressBar.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiProgressBar.java deleted file mode 100644 index 257808a7..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiProgressBar.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.AbstractGuiElement; -import lombok.Getter; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.resources.I18n; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.ReadableColor; -import org.lwjgl.util.ReadableDimension; - -public abstract class AbstractGuiProgressBar> extends AbstractGuiElement implements IGuiProgressBar { - private static final int BORDER = 2; - - @Getter - private float progress; - - @Getter - private String label = "%d%%"; - - public AbstractGuiProgressBar() { - } - - public AbstractGuiProgressBar(GuiContainer container) { - super(container); - } - - @Override - public T setProgress(float progress) { - this.progress = progress; - return getThis(); - } - - @Override - public T setLabel(String label) { - this.label = label; - return getThis(); - } - - @Override - public T setI18nLabel(String label) { - return setLabel(I18n.format(label)); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int width = size.getWidth(); - int height = size.getHeight(); - int barTotalWidth = width - 2 * BORDER; - int barDoneWidth = (int) (barTotalWidth * progress); - - renderer.drawRect(0, 0, width, height, ReadableColor.BLACK); // Border - renderer.drawRect(BORDER, BORDER, barTotalWidth, height - 2 * BORDER, ReadableColor.WHITE); // Background - renderer.drawRect(BORDER, BORDER, barDoneWidth, height - 2 * BORDER, ReadableColor.GREY); // Progress - - String text = String.format(label, (int)(progress * 100)); - renderer.drawCenteredString(width / 2, size.getHeight() / 2 - fontRenderer.FONT_HEIGHT / 2, ReadableColor.BLACK, text); - } - - @Override - public ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiResourceLoadingList.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiResourceLoadingList.java deleted file mode 100644 index e61b2211..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiResourceLoadingList.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import com.google.common.base.Supplier; -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.AbstractGuiVerticalList; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.container.GuiPanel; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.element.GuiLabel; -import de.johni0702.minecraft.gui.function.Clickable; -import de.johni0702.minecraft.gui.function.Closeable; -import de.johni0702.minecraft.gui.function.Loadable; -import de.johni0702.minecraft.gui.function.Tickable; -import de.johni0702.minecraft.gui.layout.CustomLayout; -import de.johni0702.minecraft.gui.layout.VerticalLayout; -import de.johni0702.minecraft.gui.utils.Colors; -import de.johni0702.minecraft.gui.utils.Consumer; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.util.ArrayList; -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -public abstract class AbstractGuiResourceLoadingList - , U extends GuiElement & Comparable> - extends AbstractGuiVerticalList implements Tickable, Loadable, Closeable { - private static final String[] LOADING_TEXT = {"Ooo", "oOo", "ooO", "oOo"}; - private final GuiLabel loadingElement = new GuiLabel(); - private final GuiPanel resourcesPanel = new GuiPanel(getListPanel()).setLayout(new VerticalLayout()); - - private Consumer>> onLoad; - private Runnable onSelectionChanged; - private Thread loaderThread; - private Queue resourcesQueue = new ConcurrentLinkedQueue<>(); - private int tick; - - private Element selected; - - public AbstractGuiResourceLoadingList() { - } - - public AbstractGuiResourceLoadingList(GuiContainer container) { - super(container); - } - - @Override - public void tick() { - loadingElement.setText(LOADING_TEXT[tick++ / 5 % LOADING_TEXT.length]); - Runnable resource; - while ((resource = resourcesQueue.poll()) != null) { - resource.run(); - } - } - - @Override - public void load() { - // Stop current loading - if (loaderThread != null) { - loaderThread.interrupt(); - try { - loaderThread.join(); - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - return; - } - } - - // Clear list - resourcesQueue.clear(); - for (GuiElement element : new ArrayList<>(resourcesPanel.getChildren())) { - resourcesPanel.removeElement(element); - } - selected = null; - onSelectionChanged(); - - // Load new data - loaderThread = new Thread(new Runnable() { - @Override - public void run() { - getListPanel().addElements(new VerticalLayout.Data(0.5), loadingElement); - try { - onLoad.consume(new Consumer>() { - @Override - public void consume(final Supplier obj) { - resourcesQueue.offer(new Runnable() { - @Override - public void run() { - resourcesPanel.addElements(null, new Element(obj.get())); - resourcesPanel.sortElements(); - } - }); - } - }); - } finally { - resourcesQueue.offer(new Runnable() { - @Override - public void run() { - getListPanel().removeElement(loadingElement); - } - }); - } - } - }); - getListPanel().addElements(new VerticalLayout.Data(0.5), loadingElement); - loaderThread.start(); - } - - @Override - public void close() { - loaderThread.interrupt(); - } - - public T onLoad(Consumer>> function) { - this.onLoad = function; - return getThis(); - } - - public void onSelectionChanged() { - if (onSelectionChanged != null) { - onSelectionChanged.run(); - } - } - - public T onSelectionChanged(Runnable onSelectionChanged) { - this.onSelectionChanged = onSelectionChanged; - return getThis(); - } - - public U getSelected() { - return selected == null ? null : selected.resource; - } - - private class Element extends GuiPanel implements Clickable, Comparable { - private final U resource; - private ReadableDimension size; - - public Element(final U resource) { - this.resource = resource; - addElements(null, resource); - setLayout(new CustomLayout() { - @Override - protected void layout(GuiPanel container, int width, int height) { - pos(resource, 2, 2); - } - - @Override - public ReadableDimension calcMinSize(GuiContainer container) { - ReadableDimension size = resource.getMinSize(); - return new Dimension(size.getWidth() + 4, size.getHeight() + 4); - } - }); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - this.size = size; - if (selected == this) { - // Draw selection - int w = size.getWidth(); - int h = size.getHeight(); - // Black background - renderer.drawRect(0, 0, w, h, Colors.BLACK); - // Light gray border - renderer.drawRect(0, 0, w, 1, Colors.LIGHT_GRAY); // Top - renderer.drawRect(0, h - 1, w, 1, Colors.LIGHT_GRAY); // Bottom - renderer.drawRect(0, 0, 1, h, Colors.LIGHT_GRAY); // Left - renderer.drawRect(w - 1, 0, 1, h, Colors.LIGHT_GRAY); // Right - } - super.draw(renderer, size, renderInfo); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - Point point = new Point(position); - getContainer().convertFor(this, point); - if (point.getX() > 0 && point.getX() < size.getWidth() - && point.getY() > 0 && point.getY() < size.getHeight()) { - if (selected != this) { - selected = this; - onSelectionChanged(); - } - return true; - } - return false; - } - - @Override - public int compareTo(Element o) { - return resource.compareTo(o.resource); - } - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTextArea.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTextArea.java deleted file mode 100644 index 23ad38b3..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTextArea.java +++ /dev/null @@ -1,679 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.AbstractGuiElement; -import de.johni0702.minecraft.gui.function.Clickable; -import de.johni0702.minecraft.gui.function.Focusable; -import de.johni0702.minecraft.gui.function.Tickable; -import de.johni0702.minecraft.gui.function.Typeable; -import lombok.Getter; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.WorldRenderer; -import net.minecraft.util.ChatAllowedCharacters; -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.Color; -import org.lwjgl.util.*; - -import java.util.Arrays; - -import static net.minecraft.client.renderer.GlStateManager.*; -import static net.minecraft.util.MathHelper.clamp_int; - -public abstract class AbstractGuiTextArea> - extends AbstractGuiElement implements Clickable, Typeable, Tickable, IGuiTextArea { - private static final ReadableColor BACKGROUND_COLOR = new Color(160, 160, 160); - private static final ReadableColor CURSOR_COLOR = new Color(240, 240, 240); - private static final int BORDER = 4; - private static final int LINE_SPACING = 2; - - @Getter - private boolean focused; - @Getter - private Focusable next, previous; - - // Content - @Getter - private int maxTextWidth = -1; - @Getter - private int maxTextHeight = -1; - @Getter - private int maxCharCount = -1; - - private String[] text = {""}; - private int cursorX; - private int cursorY; - private int selectionX; - private int selectionY; - - // Rendering - private int currentXOffset; - private int currentYOffset; - private int blinkCursorTick; - public ReadableColor textColorEnabled = new Color(224, 224, 224); - public ReadableColor textColorDisabled = new Color(112, 112, 112); - private ReadableDimension size = new Dimension(0, 0); // Size of last render - - public AbstractGuiTextArea() { - } - - public AbstractGuiTextArea(GuiContainer container) { - super(container); - } - - @Override - public void setText(String[] lines) { - if (lines.length > maxTextHeight) { - lines = Arrays.copyOf(lines, maxTextHeight); - } - this.text = lines; - for (int i = 0; i < lines.length; i++) { - if (lines[i].length() > maxTextWidth) { - lines[i] = lines[i].substring(0, maxTextWidth); - } - } - } - - @Override - public String[] getText() { - return this.text; - } - - @Override - public String getText(int fromX, int fromY, int toX, int toY) { - StringBuilder sb = new StringBuilder(); - if (fromY == toY) { - sb.append(text[fromY].substring(fromX, toX)); - } else { - sb.append(text[fromY].substring(fromX)).append('\n'); - for (int y = fromY + 1; y < toY; y++) { - sb.append(text[y]).append('\n'); - } - sb.append(text[toY].substring(0, toX)); - } - return sb.toString(); - } - - private void deleteText(int fromX, int fromY, int toX, int toY) { - String[] newText = new String[text.length - (toY - fromY)]; - if (fromY > 0) { - System.arraycopy(text, 0, newText, 0, fromY); - } - - newText[fromY] = text[fromY].substring(0, fromX) + text[toY].substring(toX); - - if (toY + 1 < text.length) { - System.arraycopy(text, toY + 1, newText, fromY + 1, text.length - toY - 1); - } - text = newText; - } - - @Override - public int getSelectionFromX() { - if (cursorY == selectionY) { - return cursorX > selectionX ? selectionX : cursorX; - } - return cursorY > selectionY ? selectionX : cursorX; - } - - @Override - public int getSelectionToX() { - if (cursorY == selectionY) { - return cursorX > selectionX ? cursorX : selectionX; - } - return cursorY > selectionY ? cursorX : selectionX; - } - - @Override - public int getSelectionFromY() { - return cursorY > selectionY ? selectionY : cursorY; - } - - @Override - public int getSelectionToY() { - return cursorY > selectionY ? cursorY : selectionY; - } - - @Override - public String getSelectedText() { - if (cursorX == selectionX && cursorY == selectionY) { - return ""; - } - int fromX = getSelectionFromX(); - int fromY = getSelectionFromY(); - int toX = getSelectionToX(); - int toY = getSelectionToY(); - return getText(fromX, fromY, toX, toY); - } - - @Override - public void deleteSelectedText() { - if (cursorX == selectionX && cursorY == selectionY) { - return; - } - int fromX = getSelectionFromX(); - int fromY = getSelectionFromY(); - int toX = getSelectionToX(); - int toY = getSelectionToY(); - deleteText(fromX, fromY, toX, toY); - cursorX = selectionX = fromX; - cursorY = selectionY = fromY; - updateCurrentXOffset(); - updateCurrentYOffset(); - } - - private void updateCurrentXOffset() { - currentXOffset = Math.min(currentXOffset, cursorX); - String line = text[cursorY].substring(currentXOffset, cursorX); - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int currentWidth = fontRenderer.getStringWidth(line); - if (currentWidth > size.getWidth() - BORDER * 2) { - currentXOffset = cursorX - fontRenderer.trimStringToWidth(line, size.getWidth() - BORDER * 2, true).length(); - } - } - - private void updateCurrentYOffset() { - currentYOffset = Math.min(currentYOffset, cursorY); - int lineHeight = getMinecraft().fontRendererObj.FONT_HEIGHT + LINE_SPACING; - int contentHeight = size.getHeight() - BORDER * 2; - int maxLines = contentHeight / lineHeight; - if (cursorY - currentYOffset >= maxLines) { - currentYOffset = cursorY - maxLines + 1; - } - } - - @Override - public String cutSelectedText() { - String selection = getSelectedText(); - deleteSelectedText(); - return selection; - } - - @Override - public void writeText(String append) { - for (char c : append.toCharArray()) { - writeChar(c); - } - } - - @Override - public void writeChar(char c) { - if (!ChatAllowedCharacters.isAllowedCharacter(c) && c != '\n') { - return; - } - - int totalCharCount = 0; - for(String line : text) { - totalCharCount += line.length(); - } - - if(maxCharCount > 0 && totalCharCount-(getSelectedText().length()) >= maxCharCount) { - return; - } - - deleteSelectedText(); - - if (c == '\n') { - if (text.length >= maxTextHeight) { - return; - } - String[] newText = new String[text.length + 1]; - if (cursorY > 0) { - System.arraycopy(text, 0, newText, 0, cursorY); - } - - newText[cursorY] = text[cursorY].substring(0, cursorX); - newText[cursorY + 1] = text[cursorY].substring(cursorX); - - if (cursorY + 1 < text.length) { - System.arraycopy(text, cursorY + 1, newText, cursorY + 2, text.length - cursorY - 1); - } - text = newText; - selectionX = cursorX = 0; - selectionY = ++cursorY; - updateCurrentYOffset(); - } else { - String line = text[cursorY]; - if (line.length() >= maxTextWidth) { - return; - } - - line = line.substring(0, cursorX) + c + line.substring(cursorX); - text[cursorY] = line; - selectionX = ++cursorX; - } - updateCurrentXOffset(); - } - - private void deleteNextChar() { - String line = text[cursorY]; - if (cursorX < line.length()) { - line = line.substring(0, cursorX) + line.substring(cursorX + 1); - text[cursorY] = line; - } else if (cursorY + 1 < text.length) { - deleteText(cursorX, cursorY, 0, cursorY + 1); - } - } - - private int getNextWordLength() { - int length = 0; - String line = text[cursorY]; - boolean inWord = true; - for (int i = cursorX; i < line.length(); i++) { - if (inWord) { - if (line.charAt(i) == ' ') { - inWord = false; - } - } else { - if (line.charAt(i) != ' ') { - return length; - } - } - length++; - } - return length; - } - - private void deleteNextWord() { - int worldLength = getNextWordLength(); - if (worldLength == 0) { - deleteNextChar(); - } else { - deleteText(cursorX, cursorY, cursorX + worldLength, cursorY); - } - } - - private void deletePreviousChar() { - if (cursorX > 0) { - String line = text[cursorY]; - line = line.substring(0, cursorX - 1) + line.substring(cursorX); - selectionX = --cursorX; - text[cursorY] = line; - } else if (cursorY > 0) { - int fromX = text[cursorY - 1].length(); - deleteText(fromX, cursorY - 1, cursorX, cursorY); - selectionX = cursorX = fromX; - selectionY = --cursorY; - } - updateCurrentXOffset(); - } - - private int getPreviousWordLength() { - int length = 0; - String line = text[cursorY]; - boolean inWord = false; - for (int i = cursorX - 1; i >= 0; i--) { - if (inWord) { - if (line.charAt(i) == ' ') { - return length; - } - } else { - if (line.charAt(i) != ' ') { - inWord = true; - } - } - length++; - } - return length; - } - - private void deletePreviousWord() { - int worldLength = getPreviousWordLength(); - if (worldLength == 0) { - deletePreviousChar(); - } else { - deleteText(cursorX, cursorY, cursorX - worldLength, cursorY); - selectionX = cursorX -= worldLength; - updateCurrentXOffset(); - } - } - - @Override - public void setCursorPosition(int x, int y) { - selectionY = cursorY = clamp_int(y, 0, text.length - 1); - selectionX = cursorX = clamp_int(x, 0, text[cursorY].length()); - updateCurrentXOffset(); - updateCurrentYOffset(); - } - - private void invertColors(GuiRenderer guiRenderer, int right, int bottom, int left, int top) { - int x = guiRenderer.getOpenGlOffset().getX(); - int y = guiRenderer.getOpenGlOffset().getY(); - right+=x; - left+=x; - bottom+=y; - top+=y; - - color(0, 0, 255, 255); - disableTexture2D(); - enableColorLogic(); - colorLogicOp(GL11.GL_OR_REVERSE); - - Tessellator tessellator = Tessellator.getInstance(); - WorldRenderer renderer = tessellator.getWorldRenderer(); - renderer.startDrawingQuads(); - renderer.addVertex(right, top, 0); - renderer.addVertex(left, top, 0); - renderer.addVertex(left, bottom, 0); - renderer.addVertex(right, bottom, 0); - tessellator.draw(); - - disableColorLogic(); - enableTexture2D(); - } - - @Override - protected ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - if (getContainer() != null) { - getContainer().convertFor(this, (Point) (position = new Point(position))); - } - boolean hovering = isMouseHovering(position); - - if (hovering && isFocused() && button == 0) { - int mouseX = position.getX() - BORDER; - int mouseY = position.getY() - BORDER; - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int textY = clamp_int(mouseY / (fontRenderer.FONT_HEIGHT + LINE_SPACING) + currentYOffset, 0, text.length - 1); - if (cursorY != textY) { - currentXOffset = 0; - } - String line = text[textY].substring(currentXOffset); - int textX = fontRenderer.trimStringToWidth(line, mouseX).length() + currentXOffset; - setCursorPosition(textX, textY); - } - - setFocused(hovering); - return hovering; - } - - protected boolean isMouseHovering(ReadablePoint pos) { - return pos.getX() > 0 && pos.getY() > 0 - && pos.getX() < size.getWidth() && pos.getY() < size.getHeight(); - } - - @Override - public T setFocused(boolean isFocused) { - if (isFocused && !this.focused) { - this.blinkCursorTick = 0; // Restart blinking to indicate successful focus - } - this.focused = isFocused; - return getThis(); - } - - @Override - public T setNext(Focusable next) { - this.next = next; - return getThis(); - } - - @Override - public T setPrevious(Focusable previous) { - this.previous = previous; - return getThis(); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - this.size = size; - FontRenderer fontRenderer = getMinecraft().fontRendererObj; - int width = size.getWidth(); - int height = size.getHeight(); - - // Draw black rect once pixel smaller than gray rect - renderer.drawRect(0, 0, width, height, BACKGROUND_COLOR); - renderer.drawRect(1, 1, width - 2, height - 2, ReadableColor.BLACK); - - ReadableColor textColor = isEnabled() ? textColorEnabled : textColorDisabled; - - int lineHeight = fontRenderer.FONT_HEIGHT + LINE_SPACING; - int contentHeight = height - BORDER * 2; - int maxLines = contentHeight / lineHeight; - int contentWidth = width - BORDER * 2; - - // Draw lines - for (int i = 0; i < maxLines && i + currentYOffset < text.length; i++) { - int lineY = i + currentYOffset; - String line = text[lineY]; - int leftTrimmed = 0; - if (lineY == cursorY) { - line = line.substring(currentXOffset); - leftTrimmed = currentXOffset; - } - line = fontRenderer.trimStringToWidth(line, contentWidth); - - // Draw line - int posY = BORDER + i * lineHeight; - int lineEnd = renderer.drawString(BORDER, posY, textColor, line, true); - - // Draw selection - int fromX = getSelectionFromX(); - int fromY = getSelectionFromY(); - int toX = getSelectionToX(); - int toY = getSelectionToY(); - if (lineY > fromY && lineY < toY) { // Whole line selected - invertColors(renderer, lineEnd, posY - 1 + lineHeight, BORDER, posY - 1); - } else if (lineY == fromY && lineY == toY) { // Part of line selected - String leftStr = line.substring(0, clamp_int(fromX - leftTrimmed, 0, line.length())); - String rightStr = line.substring(clamp_int(toX - leftTrimmed, 0, line.length())); - int left = BORDER + fontRenderer.getStringWidth(leftStr); - int right = lineEnd - fontRenderer.getStringWidth(rightStr) - 1; - invertColors(renderer, right, posY - 1 + lineHeight, left, posY - 1); - } else if (lineY == fromY) { // End of line selected - String rightStr = line.substring(clamp_int(fromX - leftTrimmed, 0, line.length())); - invertColors(renderer, lineEnd, posY - 1 + lineHeight, lineEnd - fontRenderer.getStringWidth(rightStr), posY - 1); - } else if (lineY == toY) { // Beginning of line selected - String leftStr = line.substring(0, clamp_int(toX - leftTrimmed, 0, line.length())); - int right = BORDER + fontRenderer.getStringWidth(leftStr); - invertColors(renderer, right, posY - 1 + lineHeight, BORDER, posY - 1); - } - - // Draw cursor - if (lineY == cursorY && blinkCursorTick / 6 % 2 == 0 && focused) { - String beforeCursor = line.substring(0, cursorX - leftTrimmed); - int posX = BORDER + fontRenderer.getStringWidth(beforeCursor); - if (cursorX == text[lineY].length()) { - renderer.drawString(posX, posY, CURSOR_COLOR, "_", true); - } else { - renderer.drawRect(posX, posY - 1, 1, 1 + fontRenderer.FONT_HEIGHT, CURSOR_COLOR); - } - } - } - } - - @Override - public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) { - if (keyCode == Keyboard.KEY_TAB) { - Focusable other = shiftDown ? previous : next; - if (other != null) { - setFocused(false); - other.setFocused(true); - } - return true; - } - - if (!this.focused) { - return false; - } - - if (GuiScreen.isCtrlKeyDown()) { - switch (keyCode) { - case Keyboard.KEY_A: // Select all - cursorX = cursorY = 0; - selectionY = text.length - 1; - selectionX = text[selectionY].length(); - updateCurrentXOffset(); - updateCurrentYOffset(); - return true; - case Keyboard.KEY_C: // Copy - GuiScreen.setClipboardString(getSelectedText()); - return true; - case Keyboard.KEY_V: // Paste - if (isEnabled()) { - writeText(GuiScreen.getClipboardString()); - } - return true; - case Keyboard.KEY_X: // Cut - if (isEnabled()) { - GuiScreen.setClipboardString(cutSelectedText()); - } - return true; - } - } - - boolean words = GuiScreen.isCtrlKeyDown(); - boolean select = GuiScreen.isShiftKeyDown(); - switch (keyCode) { - case Keyboard.KEY_HOME: - cursorX = 0; - break; - case Keyboard.KEY_END: - cursorX = text[cursorY].length(); - break; - case Keyboard.KEY_LEFT: - if (cursorX == 0) { - if (cursorY > 0) { - cursorY--; - cursorX = text[cursorY].length(); - } - } else { - if (words) { - cursorX -= getPreviousWordLength(); - } else { - cursorX--; - } - } - break; - case Keyboard.KEY_RIGHT: - if (cursorX == text[cursorY].length()) { - if (cursorY < text.length - 1) { - cursorY++; - cursorX = 0; - } - } else { - if (words) { - cursorX += getNextWordLength(); - } else { - cursorX++; - } - } - break; - case Keyboard.KEY_UP: - if (cursorY > 0) { - cursorY--; - cursorX = Math.min(cursorX, text[cursorY].length()); - } - break; - case Keyboard.KEY_DOWN: - if (cursorY + 1 < text.length) { - cursorY++; - cursorX = Math.min(cursorX, text[cursorY].length()); - } - break; - case Keyboard.KEY_BACK: - if (isEnabled()) { - if (getSelectedText().length() > 0) { - deleteSelectedText(); - } else if (words) { - deletePreviousWord(); - } else { - deletePreviousChar(); - } - } - return true; - case Keyboard.KEY_DELETE: - if (isEnabled()) { - if (getSelectedText().length() > 0) { - deleteSelectedText(); - } else if (words) { - deleteNextWord(); - } else { - deleteNextChar(); - } - } - return true; - default: - if (isEnabled()) { - if (keyChar == '\r') { - keyChar = '\n'; - } - writeChar(keyChar); - } - return true; - } - - updateCurrentXOffset(); - updateCurrentYOffset(); - - if (!select) { - selectionX = cursorX; - selectionY = cursorY; - } - return true; - } - - @Override - public void tick() { - blinkCursorTick++; - } - - @Override - public T setMaxTextWidth(int maxTextWidth) { - this.maxTextWidth = maxTextWidth; - return getThis(); - } - - @Override - public T setMaxTextHeight(int maxTextHeight) { - this.maxTextHeight = maxTextHeight; - return getThis(); - } - - @Override - public T setMaxCharCount(int maxCharCount) { - this.maxCharCount = maxCharCount; - return getThis(); - } - - @Override - public T setTextColor(ReadableColor textColor) { - this.textColorEnabled = textColor; - return getThis(); - } - - @Override - public T setTextColorDisabled(ReadableColor textColorDisabled) { - this.textColorDisabled = textColorDisabled; - return getThis(); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTimeline.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTimeline.java deleted file mode 100644 index 529f50d6..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/AbstractGuiTimeline.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.AbstractGuiElement; -import de.johni0702.minecraft.gui.element.GuiTooltip; -import de.johni0702.minecraft.gui.function.Clickable; -import net.minecraft.util.MathHelper; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -public abstract class AbstractGuiTimeline> extends AbstractGuiElement implements IGuiTimeline, Clickable { - protected static final int TEXTURE_WIDTH = 64; - protected static final int TEXTURE_HEIGHT = 22; - - protected static final int TEXTURE_X = 0; - protected static final int TEXTURE_Y = 16; - - protected static final int BORDER_LEFT = 4; - protected static final int BORDER_RIGHT = 4; - protected static final int BORDER_TOP = 4; - protected static final int BORDER_BOTTOM = 3; - protected static final int BODY_WIDTH = TEXTURE_WIDTH - BORDER_LEFT - BORDER_RIGHT; - protected static final int BODY_HEIGHT = TEXTURE_HEIGHT - BORDER_TOP - BORDER_BOTTOM; - - private OnClick onClick; - - private int length; - private int cursorPosition; - private double zoom = 1; - private int offset; - - private ReadableDimension size; - - public AbstractGuiTimeline() { - } - - public AbstractGuiTimeline(GuiContainer container) { - super(container); - } - - { - setTooltip(new GuiTooltip(){ - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - setText(getTooltipText(renderInfo)); - super.draw(renderer, size, renderInfo); - } - }.setText("00:00")); - } - - protected String getTooltipText(RenderInfo renderInfo) { - int ms = getTimeAt(renderInfo.mouseX, renderInfo.mouseY); - int s = ms / 1000 % 60; - int m = ms / 1000 / 60; - return String.format("%02d:%02d", m, s); - } - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - this.size = size; - - int width = size.getWidth(); - int height = size.getHeight(); - - // We have to increase the border size as there is one pixel row which is part of the border while drawing - // but isn't during position calculations due to shadows - int BORDER_LEFT = GuiTimeline.BORDER_LEFT + 1; - int BODY_WIDTH = GuiTimeline.BODY_WIDTH - 1; - - renderer.bindTexture(TEXTURE); - - // Left and right borders - for (int pass = 0; pass < 2; pass++) { - int x = pass == 0 ? 0 : width - BORDER_RIGHT; - int textureX = pass == 0 ? TEXTURE_X : TEXTURE_X + TEXTURE_WIDTH - BORDER_RIGHT; - // Border - for (int y = BORDER_TOP; y < height - BORDER_BOTTOM; y += BODY_HEIGHT) { - int segmentHeight = Math.min(BODY_HEIGHT, height - BORDER_BOTTOM - y); - renderer.drawTexturedRect(x, y, textureX, TEXTURE_Y + BORDER_TOP, BORDER_LEFT, segmentHeight); - } - // Top corner - renderer.drawTexturedRect(x, 0, textureX, TEXTURE_Y, BORDER_LEFT, BORDER_TOP); - // Bottom corner - renderer.drawTexturedRect(x, height - BORDER_BOTTOM, textureX, TEXTURE_Y + TEXTURE_HEIGHT - BORDER_BOTTOM, - BORDER_LEFT, BORDER_BOTTOM); - } - - for (int x = BORDER_LEFT; x < width - BORDER_RIGHT; x += BODY_WIDTH) { - int segmentWidth = Math.min(BODY_WIDTH, width - BORDER_RIGHT - x); - int textureX = TEXTURE_X + BORDER_LEFT; - - // Content - for (int y = BORDER_TOP; y < height - BORDER_BOTTOM; y += BODY_HEIGHT) { - int segmentHeight = Math.min(BODY_HEIGHT, height - BORDER_BOTTOM - y); - renderer.drawTexturedRect(x, y, textureX, TEXTURE_Y + BORDER_TOP, segmentWidth, segmentHeight); - } - - // Top border - renderer.drawTexturedRect(x, 0, textureX, TEXTURE_Y, segmentWidth, BORDER_TOP); - // Bottom border - renderer.drawTexturedRect(x, height - BORDER_BOTTOM, textureX, TEXTURE_Y + TEXTURE_HEIGHT - BORDER_BOTTOM, - segmentWidth, BORDER_BOTTOM); - } - - drawTimelineCursor(renderer, size); - } - - /** - * Draws the timeline cursor. - * This is separate from the main draw method so subclasses can repaint the cursor - * in case it got drawn over by other elements. - * @param renderer Gui renderer used to draw the cursor - * @param size Size of the drawable area - */ - protected void drawTimelineCursor(GuiRenderer renderer, ReadableDimension size) { - int height = size.getHeight(); - renderer.bindTexture(TEXTURE); - - int visibleLength = (int) (length * zoom); - int cursor = MathHelper.clamp_int(cursorPosition, offset, offset + visibleLength); - double positionInVisible = cursor - offset; - double fractionOfVisible = positionInVisible / visibleLength; - int cursorX = (int) (BORDER_LEFT + fractionOfVisible * (size.getWidth() - BORDER_LEFT - BORDER_RIGHT)); - - // Pin - renderer.drawTexturedRect(cursorX - 2, BORDER_TOP - 1, 64, 0, 5, 4); - // Needle - for (int y = BORDER_TOP - 1; y < height - BORDER_BOTTOM; y += 11) { - int segmentHeight = Math.min(11, height - BORDER_BOTTOM - y); - renderer.drawTexturedRect(cursorX - 2, y, 64, 4, 5, segmentHeight); - } - } - - /** - * Returns the time which the mouse is at. - * @param mouseX X coordinate of the mouse - * @param mouseY Y coordinate of the mouse - * @return The time or -1 if the mouse isn't on the timeline - */ - protected int getTimeAt(int mouseX, int mouseY) { - if (size == null) { - return -1; - } - Point mouse = new Point(mouseX, mouseY); - getContainer().convertFor(this, mouse); - mouseX = mouse.getX(); - mouseY = mouse.getY(); - - if (mouseX < 0 || mouseY < 0 - || mouseX > size.getWidth() || mouseY > size.getHeight()) { - return -1; - } - - int width = size.getWidth(); - int bodyWidth = width - BORDER_LEFT - BORDER_RIGHT; - double segmentLength = length * zoom; - double segmentTime = segmentLength * (mouseX - BORDER_LEFT) / bodyWidth; - return Math.min(Math.max((int) Math.round(offset + segmentTime), 0), length); - } - - public void onClick(int time) { - if (onClick != null) { - onClick.run(time); - } - } - - @Override - public ReadableDimension calcMinSize() { - return new Dimension(0, 0); - } - - @Override - public T setLength(int length) { - this.length = length; - return getThis(); - } - - @Override - public int getLength() { - return length; - } - - @Override - public T setCursorPosition(int position) { - this.cursorPosition = position; - return getThis(); - } - - @Override - public int getCursorPosition() { - return cursorPosition; - } - - @Override - public T setZoom(double zoom) { - this.zoom = zoom; - return getThis(); - } - - @Override - public double getZoom() { - return zoom; - } - - @Override - public T setOffset(int offset) { - this.offset = offset; - return getThis(); - } - - @Override - public int getOffset() { - return offset; - } - - @Override - public T onClick(OnClick onClick) { - this.onClick = onClick; - return getThis(); - } - - @Override - public boolean mouseClick(ReadablePoint position, int button) { - int time = getTimeAt(position.getX(), position.getY()); - if (time != -1) { - onClick(time); - return true; - } - return false; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiDropdownMenu.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiDropdownMenu.java deleted file mode 100644 index db28b632..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiDropdownMenu.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiDropdownMenu extends AbstractGuiDropdownMenu> { - - public GuiDropdownMenu() { - } - - public GuiDropdownMenu(GuiContainer container) { - super(container); - } - - @Override - protected GuiDropdownMenu getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiProgressBar.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiProgressBar.java deleted file mode 100644 index bbd174fe..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiProgressBar.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiProgressBar extends AbstractGuiProgressBar { - public GuiProgressBar() { - } - - public GuiProgressBar(GuiContainer container) { - super(container); - } - - @Override - protected GuiProgressBar getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiResourceLoadingList.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiResourceLoadingList.java deleted file mode 100644 index cf4209ac..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiResourceLoadingList.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.GuiElement; - -public class GuiResourceLoadingList & Comparable> - extends AbstractGuiResourceLoadingList, U> { - public GuiResourceLoadingList() { - } - - public GuiResourceLoadingList(GuiContainer container) { - super(container); - } - - @Override - protected GuiResourceLoadingList getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTextArea.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTextArea.java deleted file mode 100644 index 422a5a53..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTextArea.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiTextArea extends AbstractGuiTextArea { - public GuiTextArea() { - } - - public GuiTextArea(GuiContainer container) { - super(container); - } - - @Override - protected GuiTextArea getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTimeline.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTimeline.java deleted file mode 100644 index d21068f8..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/GuiTimeline.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.container.GuiContainer; - -public class GuiTimeline extends AbstractGuiTimeline { - public GuiTimeline() { - } - - public GuiTimeline(GuiContainer container) { - super(container); - } - - @Override - protected GuiTimeline getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiDropdownMenu.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiDropdownMenu.java deleted file mode 100644 index 517c4804..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiDropdownMenu.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.utils.Consumer; - -public interface IGuiDropdownMenu> extends GuiElement { - T setValues(V... values); - - T setSelected(int selected); - - T setSelected(V value); - - V getSelectedValue(); - - T setOpened(boolean opened); - - int getSelected(); - - V[] getValues(); - - boolean isOpened(); - - T onSelection(Consumer consumer); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiProgressBar.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiProgressBar.java deleted file mode 100644 index 52c8925c..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiProgressBar.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.element.GuiElement; - -public interface IGuiProgressBar> extends GuiElement { - T setProgress(float progress); - - T setLabel(String label); - - T setI18nLabel(String label); - - float getProgress(); - - String getLabel(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTextArea.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTextArea.java deleted file mode 100644 index 78bab02a..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTextArea.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.function.Focusable; -import org.lwjgl.util.ReadableColor; - -public interface IGuiTextArea> extends GuiElement,Focusable { - void setText(String[] lines); - - String[] getText(); - - String getText(int fromX, int fromY, int toX, int toY); - - int getSelectionFromX(); - - int getSelectionToX(); - - int getSelectionFromY(); - - int getSelectionToY(); - - String getSelectedText(); - - void deleteSelectedText(); - - String cutSelectedText(); - - void writeText(String append); - - void writeChar(char c); - - void setCursorPosition(int x, int y); - - T setMaxTextWidth(int maxTextWidth); - - T setMaxTextHeight(int maxTextHeight); - - T setMaxCharCount(int maxCharCount); - - T setTextColor(ReadableColor textColor); - - T setTextColorDisabled(ReadableColor textColorDisabled); - - int getMaxTextWidth(); - - int getMaxTextHeight(); - - int getMaxCharCount(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTimeline.java b/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTimeline.java deleted file mode 100644 index a82f9d28..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/element/advanced/IGuiTimeline.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.element.advanced; - -import de.johni0702.minecraft.gui.element.GuiElement; - -public interface IGuiTimeline> extends GuiElement { - - /** - * Set the total length of the timeline. - * @param length length in milliseconds, must be > 0 - * @return {@code this}, for chaining - */ - T setLength(int length); - - /** - * Returns the total length of the timeline. - * @return The total length in millisconds - */ - int getLength(); - - /** - * Set the current position of the cursor. Should be between 0 and {@link #getLength()}. - * @param position Position of the cursor in milliseconds - * @return {@code this}, for chaining - */ - T setCursorPosition(int position); - - /** - * Returns the current position of the cursor. Should be between 0 and {@link #getLength()}. - * @return cursor position in milliseconds - */ - int getCursorPosition(); - - /** - * Set the zoom of this timeline. 1/10 allows the user to see 1/10 of the total length. - * @param zoom The zoom factor. Must be between 1 (inclusive) and 0 (exclusive) - * @return {@code this}, for chaining - */ - T setZoom(double zoom); - - /** - * Returns the zoom of this timeline. 1/10 allows the user to see 1/10 of the total length. - * @return The zoom factor. Must be between 1 (inclusive) and 0 (exclusive) - */ - double getZoom(); - - /** - * Set the position of the timeline which should be shown. - * The left side of the timeline will start at this offset. - * @param offset The offset in milliseconds - * @return {@code this}, for chaining - */ - T setOffset(int offset); - - /** - * Returns the position of the timeline which should be shown. - * The left side of the timeline will start at this offset. - * @return The offset in milliseconds - */ - int getOffset(); - - T onClick(OnClick onClick); - - interface OnClick { - void run(int time); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Clickable.java b/src/main/java/de/johni0702/minecraft/gui/function/Clickable.java deleted file mode 100644 index 01fe01de..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Clickable.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -import org.lwjgl.util.ReadablePoint; - -public interface Clickable { - boolean mouseClick(ReadablePoint position, int button); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Closeable.java b/src/main/java/de/johni0702/minecraft/gui/function/Closeable.java deleted file mode 100644 index 83cc63da..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Closeable.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -public interface Closeable { - void close(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Draggable.java b/src/main/java/de/johni0702/minecraft/gui/function/Draggable.java deleted file mode 100644 index 43c432a3..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Draggable.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -import org.lwjgl.util.ReadablePoint; - -public interface Draggable extends Clickable { - boolean mouseDrag(ReadablePoint position, int button, long timeSinceLastCall); - boolean mouseRelease(ReadablePoint position, int button); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Focusable.java b/src/main/java/de/johni0702/minecraft/gui/function/Focusable.java deleted file mode 100644 index e4abcd54..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Focusable.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -public interface Focusable> { - - boolean isFocused(); - T setFocused(boolean focused); - - Focusable getNext(); - T setNext(Focusable next); - - Focusable getPrevious(); - T setPrevious(Focusable previous); - -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Loadable.java b/src/main/java/de/johni0702/minecraft/gui/function/Loadable.java deleted file mode 100644 index febf8d97..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Loadable.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -public interface Loadable { - void load(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Scrollable.java b/src/main/java/de/johni0702/minecraft/gui/function/Scrollable.java deleted file mode 100644 index e5ccebab..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Scrollable.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -import org.lwjgl.util.ReadablePoint; - -public interface Scrollable { - /** - * Called when the user scrolled. - * @param mousePosition Global position of the mouse. - * @param dWheel Wheel movement (positive is upwards, negative is downwards) - * @return {@code true} if this event should be consumed, - * {@code false} if it should be delivered to other elements as well - */ - boolean scroll(ReadablePoint mousePosition, int dWheel); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Tickable.java b/src/main/java/de/johni0702/minecraft/gui/function/Tickable.java deleted file mode 100644 index 772cc08c..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Tickable.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -public interface Tickable { - void tick(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/function/Typeable.java b/src/main/java/de/johni0702/minecraft/gui/function/Typeable.java deleted file mode 100644 index 7d635d92..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/function/Typeable.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.function; - -import org.lwjgl.util.ReadablePoint; - -public interface Typeable { - boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/layout/CustomLayout.java b/src/main/java/de/johni0702/minecraft/gui/layout/CustomLayout.java deleted file mode 100644 index ed987cee..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/layout/CustomLayout.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.layout; - -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.GuiElement; -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.Map; - -public abstract class CustomLayout> implements Layout { - private final Layout parent; - private Map> result = new LinkedHashMap<>(); - - public CustomLayout() { - this(null); - } - - public CustomLayout(Layout parent) { - this.parent = parent; - } - - @Override - @SuppressWarnings("unchecked") - public Map> layOut(GuiContainer container, ReadableDimension size) { - result.clear(); - if (parent == null) { - Collection elements = container.getChildren(); - for (GuiElement element : elements) { - result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getMinSize()))); - } - } else { - Map> elements = parent.layOut(container, size); - for (Map.Entry> entry : elements.entrySet()) { - Pair pair = entry.getValue(); - result.put(entry.getKey(), Pair.of(new Point(pair.getLeft()), new Dimension(pair.getRight()))); - } - } - - layout((T) container, size.getWidth(), size.getHeight()); - - return (Map) result; - } - - private Pair entry(GuiElement element) { - return result.get(element); - } - - protected void set(GuiElement element, int x, int y, int width, int height) { - Pair entry = entry(element); - entry.getLeft().setLocation(x, y); - entry.getRight().setSize(width, height); - } - - protected void pos(GuiElement element, int x, int y) { - entry(element).getLeft().setLocation(x, y); - } - - protected void size(GuiElement element, ReadableDimension size) { - size.getSize(entry(element).getRight()); - } - - protected void size(GuiElement element, int width, int height) { - entry(element).getRight().setSize(width, height); - } - - protected void x(GuiElement element, int x) { - entry(element).getLeft().setX(x); - } - - protected void y(GuiElement element, int y) { - entry(element).getLeft().setY(y); - } - - protected void width(GuiElement element, int width) { - entry(element).getRight().setWidth(width); - } - - protected void height(GuiElement element, int height) { - entry(element).getRight().setHeight(height); - } - - protected int x(GuiElement element) { - return entry(element).getLeft().getX(); - } - - protected int y(GuiElement element) { - return entry(element).getLeft().getY(); - } - - protected int width(GuiElement element) { - return entry(element).getRight().getWidth(); - } - - protected int height(GuiElement element) { - return entry(element).getRight().getHeight(); - } - - protected abstract void layout(T container, int width, int height); - - @Override - public ReadableDimension calcMinSize(GuiContainer container) { - return new Dimension(0, 0); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/layout/GridLayout.java b/src/main/java/de/johni0702/minecraft/gui/layout/GridLayout.java deleted file mode 100644 index ff5cae99..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/layout/GridLayout.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.layout; - -import com.google.common.base.Preconditions; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.GuiElement; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -public class GridLayout implements Layout { - private static final Data DEFAULT_DATA = new Data(); - - @Accessors(chain = true) - @Getter - @Setter - private int columns; - - @Accessors(chain = true) - @Getter - @Setter - private int spacingX, spacingY; - - @Override - public Map> layOut(GuiContainer container, ReadableDimension size) { - Preconditions.checkState(columns != 0, "Columns may not be 0."); - int elements = container.getElements().size(); - int rows = (elements - 1 + columns) / columns; - if (rows < 1) { - return Collections.emptyMap(); - } - int cellWidth = (size.getWidth() + spacingX) / columns - spacingX; - int cellHeight = (size.getHeight() + spacingY) / rows - spacingY; - Map> map = new LinkedHashMap<>(); - Iterator> iter = container.getElements().entrySet().iterator(); - for (int i = 0; i < rows; i++) { - for (int j = 0; j < columns; j++) { - if (!iter.hasNext()) { - return map; - } - int x = j * (cellWidth + spacingX); - int y = i * (cellHeight + spacingY); - - Map.Entry entry = iter.next(); - GuiElement element = entry.getKey(); - Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA; - Dimension elementSize = new Dimension(element.getMinSize()); - ReadableDimension elementMaxSize = element.getMaxSize(); - elementSize.setWidth(Math.min(cellWidth, elementMaxSize.getWidth())); - elementSize.setHeight(Math.min(cellHeight, elementMaxSize.getHeight())); - - int remainingWidth = cellWidth - elementSize.getWidth(); - int remainingHeight = cellHeight - elementSize.getHeight(); - x += (int) (data.alignmentX * remainingWidth); - y += (int) (data.alignmentY * remainingHeight); - map.put(element, Pair.of(new Point(x, y), elementSize)); - } - } - return map; - } - - @Override - public ReadableDimension calcMinSize(GuiContainer container) { - Preconditions.checkState(columns != 0, "Columns may not be 0."); - int maxWidth = 0, maxHeight = 0; - int elements = 0; - for (Map.Entry entry : container.getElements().entrySet()) { - GuiElement element = entry.getKey(); - ReadableDimension minSize = element.getMinSize(); - int width = minSize.getWidth(); - if (width > maxWidth) { - maxWidth = width; - } - int height = minSize.getHeight(); - if (height > maxHeight) { - maxHeight = height; - } - elements++; - } - int rows = (elements - 1 + columns) / columns; - int totalWidth = maxWidth * columns; - int totalHeight = maxHeight * rows; - if (elements > 0) { - totalWidth+=spacingX * (columns - 1); - } - if (elements > columns) { - totalHeight+=spacingY * (rows - 1); - } - return new Dimension(totalWidth, totalHeight); - } - - @lombok.Data - @AllArgsConstructor - public static class Data implements LayoutData { - private double alignmentX, alignmentY; - - public Data() { - this(0, 0); - } - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/layout/HorizontalLayout.java b/src/main/java/de/johni0702/minecraft/gui/layout/HorizontalLayout.java deleted file mode 100644 index 78aed971..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/layout/HorizontalLayout.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.layout; - -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.GuiElement; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.util.LinkedHashMap; -import java.util.Map; - -public class HorizontalLayout implements Layout { - private static final Data DEFAULT_DATA = new Data(0); - - private final Alignment alignment; - - @Accessors(chain = true) - @Getter - @Setter - private int spacing; - - public HorizontalLayout() { - this(Alignment.LEFT); - } - - public HorizontalLayout(Alignment alignment) { - this.alignment = alignment; - } - - @Override - public Map> layOut(GuiContainer container, ReadableDimension size) { - int x = 0; - int spacing = 0; - Map> map = new LinkedHashMap<>(); - for (Map.Entry entry : container.getElements().entrySet()) { - x += spacing; - spacing = this.spacing; - - GuiElement element = entry.getKey(); - Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA; - Dimension elementSize = new Dimension(element.getMinSize()); - ReadableDimension elementMaxSize = element.getMaxSize(); - elementSize.setWidth(Math.min(size.getWidth() - x, Math.min(elementSize.getWidth(), elementMaxSize.getWidth()))); - elementSize.setHeight(Math.min(size.getHeight(), elementMaxSize.getHeight())); - int remainingHeight = size.getHeight() - elementSize.getHeight(); - int y = (int) (data.alignment * remainingHeight); - map.put(element, Pair.of(new Point(x, y), elementSize)); - x += elementSize.getWidth(); - } - if (alignment != Alignment.LEFT) { - int remaining = size.getWidth() - x; - if (alignment == Alignment.CENTER) { - remaining /= 2; - } - for (Pair pair : map.values()) { - ((Point) pair.getLeft()).translate(remaining, 0); - } - } - return map; - } - - @Override - public ReadableDimension calcMinSize(GuiContainer container) { - int maxHeight = 0; - int width = 0; - int spacing = 0; - for (Map.Entry entry : container.getElements().entrySet()) { - width += spacing; - spacing = this.spacing; - - GuiElement element = entry.getKey(); - ReadableDimension minSize = element.getMinSize(); - int height = minSize.getHeight(); - if (height > maxHeight) { - maxHeight = height; - } - width += minSize.getWidth(); - } - return new Dimension(width, maxHeight); - } - - @lombok.Data - @AllArgsConstructor - public static class Data implements LayoutData { - private double alignment; - - public Data() { - this(0); - } - } - - public enum Alignment { - LEFT, RIGHT, CENTER - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/layout/Layout.java b/src/main/java/de/johni0702/minecraft/gui/layout/Layout.java deleted file mode 100644 index 199589ba..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/layout/Layout.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.layout; - -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.GuiElement; -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.util.Map; - -public interface Layout { - - Map> layOut(GuiContainer container, ReadableDimension size); - - ReadableDimension calcMinSize(GuiContainer container); - -} diff --git a/src/main/java/de/johni0702/minecraft/gui/layout/LayoutData.java b/src/main/java/de/johni0702/minecraft/gui/layout/LayoutData.java deleted file mode 100644 index de64c7e5..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/layout/LayoutData.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.layout; - -public interface LayoutData { - LayoutData NONE = VoidLayoutData.INSTANCE; -} diff --git a/src/main/java/de/johni0702/minecraft/gui/layout/VerticalLayout.java b/src/main/java/de/johni0702/minecraft/gui/layout/VerticalLayout.java deleted file mode 100644 index d2e28cdd..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/layout/VerticalLayout.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.layout; - -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.element.GuiElement; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import org.apache.commons.lang3.tuple.Pair; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.Point; -import org.lwjgl.util.ReadableDimension; -import org.lwjgl.util.ReadablePoint; - -import java.util.LinkedHashMap; -import java.util.Map; - -public class VerticalLayout implements Layout { - private static final Data DEFAULT_DATA = new Data(0); - - private final Alignment alignment; - - @Accessors(chain = true) - @Getter - @Setter - private int spacing; - - public VerticalLayout() { - this(Alignment.TOP); - } - - public VerticalLayout(Alignment alignment) { - this.alignment = alignment; - } - - @Override - public Map> layOut(GuiContainer container, ReadableDimension size) { - int y = 0; - int spacing = 0; - Map> map = new LinkedHashMap<>(); - for (Map.Entry entry : container.getElements().entrySet()) { - y += spacing; - spacing = this.spacing; - - GuiElement element = entry.getKey(); - Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA; - Dimension elementSize = new Dimension(element.getMinSize()); - ReadableDimension elementMaxSize = element.getMaxSize(); - elementSize.setHeight(Math.min(size.getHeight() - y, Math.min(elementSize.getHeight(), elementMaxSize.getHeight()))); - elementSize.setWidth(Math.min(size.getWidth(), element.getMaxSize().getWidth())); - int remainingWidth = size.getWidth() - elementSize.getWidth(); - int x = (int) (data.alignment * remainingWidth); - map.put(element, Pair.of(new Point(x, y), elementSize)); - y += elementSize.getHeight(); - } - if (alignment != Alignment.TOP) { - int remaining = size.getHeight() - y; - if (alignment == Alignment.CENTER) { - remaining /= 2; - } - for (Pair pair : map.values()) { - ((Point) pair.getLeft()).translate(0, remaining); - } - } - return map; - } - - @Override - public ReadableDimension calcMinSize(GuiContainer container) { - int maxWidth = 0; - int height = 0; - int spacing = 0; - for (Map.Entry entry : container.getElements().entrySet()) { - height += spacing; - spacing = this.spacing; - - GuiElement element = entry.getKey(); - ReadableDimension minSize = element.getMinSize(); - int width = minSize.getWidth(); - if (width > maxWidth) { - maxWidth = width; - } - height += minSize.getHeight(); - } - return new Dimension(maxWidth, height); - } - - @lombok.Data - @AllArgsConstructor - public static class Data implements LayoutData { - private double alignment; - - public Data() { - this(0); - } - } - - public enum Alignment { - TOP, BOTTOM, CENTER - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/layout/VoidLayoutData.java b/src/main/java/de/johni0702/minecraft/gui/layout/VoidLayoutData.java deleted file mode 100644 index bf87b376..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/layout/VoidLayoutData.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.layout; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class VoidLayoutData implements LayoutData { - public static final VoidLayoutData INSTANCE = new VoidLayoutData(); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/popup/AbstractGuiPopup.java b/src/main/java/de/johni0702/minecraft/gui/popup/AbstractGuiPopup.java deleted file mode 100644 index b39c2fea..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/popup/AbstractGuiPopup.java +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.popup; - -import de.johni0702.minecraft.gui.GuiRenderer; -import de.johni0702.minecraft.gui.RenderInfo; -import de.johni0702.minecraft.gui.container.AbstractGuiContainer; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.container.GuiPanel; -import de.johni0702.minecraft.gui.layout.CustomLayout; -import de.johni0702.minecraft.gui.layout.Layout; -import org.lwjgl.util.Dimension; -import org.lwjgl.util.ReadableDimension; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.List; - -public abstract class AbstractGuiPopup> extends AbstractGuiContainer { - private final GuiPanel popupContainer = new GuiPanel(this){ - private final int u0 = 0; - private final int v0 = 39; - - @Override - public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) { - if (renderInfo.getLayer() == 0) { - renderer.bindTexture(TEXTURE); - int w = size.getWidth(); - int h = size.getHeight(); - - // Corners - renderer.drawTexturedRect(0, 0, u0, v0, 5, 5); // Top left - renderer.drawTexturedRect(w - 5, 0, u0 + 12, v0, 5, 5); // Top right - renderer.drawTexturedRect(0, h - 5, u0, v0 + 12, 5, 5); // Bottom left - renderer.drawTexturedRect(w - 5, h - 5, u0 + 12, v0 + 12, 5, 5); // Bottom right - - // Top and bottom edge - for (int x = 5; x < w - 5; x += 5) { - int rx = Math.min(5, w - 5 - x); - renderer.drawTexturedRect(x, 0, u0 + 6, v0, rx, 5); // Top - renderer.drawTexturedRect(x, h - 5, u0 + 6, v0 + 12, rx, 5); // Bottom - } - - // Left and right edge - for (int y = 5; y < w - 5; y += 5) { - int ry = Math.min(5, h - 5 - y); - renderer.drawTexturedRect(0, y, u0, v0 + 6, 5, ry); // Left - renderer.drawTexturedRect(w - 5, y, u0 + 12, v0 + 6, 5, ry); // Right - } - - // Center - for (int x = 5; x < w - 5; x += 5) { - for (int y = 5; y < w - 5; y += 5) { - int rx = Math.min(5, w - 5 - x); - int ry = Math.min(5, h - 5 - y); - renderer.drawTexturedRect(x, y, u0 + 6, v0 + 6, rx, ry); - } - } - } - - super.draw(renderer, size, renderInfo); - } - }.setLayout(new CustomLayout() { - @Override - protected void layout(GuiPanel container, int width, int height) { - pos(popup, 10, 10); - } - - @Override - public ReadableDimension calcMinSize(GuiContainer container) { - ReadableDimension size = popup.calcMinSize(); - return new Dimension(size.getWidth() + 20, size.getHeight() + 20); - } - }); - protected final GuiPanel popup = new GuiPanel(popupContainer); - - private int layer; - - { - setLayout(new CustomLayout() { - @Override - protected void layout(T container, int width, int height) { - pos(popupContainer, width / 2 - width(popupContainer) / 2, height / 2 - height(popupContainer) / 2); - } - }); - } - - private Layout originalLayout; - - private final GuiContainer container; - - public AbstractGuiPopup(GuiContainer container) { - while (container.getContainer() != null) { - container = container.getContainer(); - } - this.container = container; - } - - protected void open() { - setLayer(container.getMaxLayer() + 1); - container.addElements(null, this); - container.setLayout(new CustomLayout(originalLayout = container.getLayout()) { - @Override - protected void layout(GuiContainer container, int width, int height) { - pos(AbstractGuiPopup.this, 0, 0); - size(AbstractGuiPopup.this, width, height); - } - }); - } - - protected void close() { - getContainer().setLayout(originalLayout); - getContainer().removeElement(this); - } - - public T setLayer(int layer) { - this.layer = layer; - return getThis(); - } - - @Override - public int getLayer() { - return layer; - } - - @Override - @SuppressWarnings("unchecked") - public C forEach(int layer, final Class ofType) { - final C realProxy = super.forEach(layer, ofType); - if (layer >= 0) { - return (C) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ofType}, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if (method.getReturnType().equals(boolean.class)) { - method.invoke(forEachChild(ofType), args); - return true; - } - return method.invoke(realProxy, args); - } - }); - } else { - return realProxy; - } - } - - @SuppressWarnings("unchecked") - private C forEachChild(final Class ofType) { - int maxLayer = getMaxLayer(); - final List layers = new ArrayList(maxLayer + 1); - for (int i = maxLayer; i >= 0; i--) { - layers.add(super.forEach(i, ofType)); - } - return (C) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ofType}, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - boolean isGetter = method.getName().startsWith("get"); - Object handled = method.getReturnType().equals(boolean.class) ? false : null; - for (final C layer : layers) { - handled = method.invoke(layer, args); - if (handled != null) { - if (handled instanceof Boolean) { - if (Boolean.TRUE.equals(handled)) { - break; - } - } else if (isGetter) { - return handled; - } - } - } - return handled; - } - }); - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/popup/GuiYesNoPopup.java b/src/main/java/de/johni0702/minecraft/gui/popup/GuiYesNoPopup.java deleted file mode 100644 index 2bcbe853..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/popup/GuiYesNoPopup.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.popup; - -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.SettableFuture; -import de.johni0702.minecraft.gui.container.GuiContainer; -import de.johni0702.minecraft.gui.container.GuiPanel; -import de.johni0702.minecraft.gui.element.GuiButton; -import de.johni0702.minecraft.gui.element.GuiElement; -import de.johni0702.minecraft.gui.layout.HorizontalLayout; -import de.johni0702.minecraft.gui.layout.VerticalLayout; -import de.johni0702.minecraft.gui.utils.Colors; -import lombok.Getter; -import lombok.Setter; -import lombok.experimental.Accessors; -import org.lwjgl.util.Dimension; - -public class GuiYesNoPopup extends AbstractGuiPopup { - public static GuiYesNoPopup open(GuiContainer container, GuiElement... info) { - GuiYesNoPopup popup = new GuiYesNoPopup(container).setBackgroundColor(Colors.DARK_TRANSPARENT); - popup.getInfo().addElements(new VerticalLayout.Data(0.5), info); - popup.open(); - return popup; - } - - private final SettableFuture future = SettableFuture.create(); - - @Getter - private final GuiButton yesButton = new GuiButton().setSize(150, 20).onClick(new Runnable() { - @Override - public void run() { - close(); - future.set(true); - } - }); - - @Getter - private final GuiButton noButton = new GuiButton().setSize(150, 20).onClick(new Runnable() { - @Override - public void run() { - close(); - future.set(false); - } - }); - - @Getter - private final GuiPanel info = new GuiPanel().setMinSize(new Dimension(320, 50)) - .setLayout(new VerticalLayout(VerticalLayout.Alignment.TOP).setSpacing(2)); - - @Getter - private final GuiPanel buttons = new GuiPanel() - .setLayout(new HorizontalLayout(HorizontalLayout.Alignment.CENTER).setSpacing(5)) - .addElements(new HorizontalLayout.Data(0.5), yesButton, noButton); - - { - popup.setLayout(new VerticalLayout().setSpacing(10)) - .addElements(new VerticalLayout.Data(0.5), info, buttons); - } - - @Getter - @Setter - @Accessors(chain = true) - private int layer; - - public GuiYesNoPopup(GuiContainer container) { - super(container); - } - - public GuiYesNoPopup setYesLabel(String label) { - yesButton.setLabel(label); - return this; - } - - public GuiYesNoPopup setNoLabel(String label) { - noButton.setLabel(label); - return this; - } - - public GuiYesNoPopup setYesI18nLabel(String label, Object...args) { - yesButton.setI18nLabel(label, args); - return this; - } - - public GuiYesNoPopup setNoI18nLabel(String label, Object...args) { - noButton.setI18nLabel(label, args); - return this; - } - - public ListenableFuture getFuture() { - return future; - } - - @Override - protected GuiYesNoPopup getThis() { - return this; - } -} diff --git a/src/main/java/de/johni0702/minecraft/gui/utils/Colors.java b/src/main/java/de/johni0702/minecraft/gui/utils/Colors.java deleted file mode 100644 index 4f22aa26..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/utils/Colors.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.utils; - -import org.lwjgl.util.Color; -import org.lwjgl.util.ReadableColor; - -public interface Colors extends ReadableColor { - ReadableColor TRANSPARENT = new Color(0, 0, 0, 0); - ReadableColor LIGHT_TRANSPARENT = new Color(0, 0, 0, 64); - ReadableColor HALF_TRANSPARENT = new Color(0, 0, 0, 128); - ReadableColor DARK_TRANSPARENT = new Color(0, 0, 0, 192); - ReadableColor LIGHT_GRAY = new Color(192, 192, 192); - ReadableColor DARK_RED = new Color(170, 0, 0); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/utils/Consumer.java b/src/main/java/de/johni0702/minecraft/gui/utils/Consumer.java deleted file mode 100644 index 7f8e7a14..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/utils/Consumer.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.utils; - -public interface Consumer { - void consume(T obj); -} diff --git a/src/main/java/de/johni0702/minecraft/gui/utils/Consumers.java b/src/main/java/de/johni0702/minecraft/gui/utils/Consumers.java deleted file mode 100644 index 0410ddc4..00000000 --- a/src/main/java/de/johni0702/minecraft/gui/utils/Consumers.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2015 johni0702 - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package de.johni0702.minecraft.gui.utils; - -public class Consumers { - public static Consumer from(final Runnable runnable) { - return new Consumer() { - @Override - public void consume(U obj) { - runnable.run(); - } - }; - } -}