Search in sources :

Example 11 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class GuiScrollingBase method drawForeground.

@Override
public void drawForeground(int mx, int my, float partialTick) {
    int count = entries.size();
    int listY = posY - scroll;
    boolean isHovering = isWithin(mx, my, posX, posY, width, height);
    int mx2 = !isHovering ? -99 : mx;
    int my2 = !isHovering ? -99 : my;
    GlStateManager.pushMatrix();
    for (int i = 0; i < count; i++) {
        IScrollingEntry e = entries.get(i);
        boolean scissor = !e.canDrawOutsideBox(true);
        if (scissor) {
            RenderUtils.startScissor(mc, new GuiRectangle(posX, posY, width - 8, height));
        }
        e.drawForeground(mx2, my2, posX, listY, width - 8);
        if (scissor) {
            RenderUtils.endScissor(mc);
        }
        listY += e.getHeight();
    }
    GlStateManager.popMatrix();
}
Also used : GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle)

Example 12 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class RenderUtils method startScissor.

/**
 * Performs a OpenGL scissor based on Minecraft's resolution instead of display resolution and adds it to the stack of ongoing scissors.
 * Not using this method will result in incorrect scissoring and scaling of parent/child GUIs
 */
public static void startScissor(Minecraft mc, GuiRectangle rect) {
    if (scissorStack.size() >= 100) {
        BetterQuesting.logger.log(Level.ERROR, "More than 100 recursive scissor calls have been made!");
        return;
    }
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    ScaledResolution r = new ScaledResolution(mc);
    int f = r.getScaleFactor();
    // Have to do all this fancy crap because glScissor() isn't affected by glScale() and rather than try and convince devs to use some custom hack
    // we'll just deal with it by reading from the current MODELVIEW MATRIX to convert between screen spaces at their relative scales and translations.
    FloatBuffer fb = BufferUtils.createFloatBuffer(16);
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, fb);
    fb.rewind();
    Matrix4f fm = new Matrix4f();
    fm.load(fb);
    // GL screenspace rectangle
    GuiRectangle sRect = new GuiRectangle((int) (rect.getX() * f * fm.m00 + (fm.m30 * f)), (r.getScaledHeight() - (int) ((rect.getY() + rect.getHeight()) * fm.m11 + fm.m31)) * f, (int) (rect.getWidth() * f * fm.m00), (int) (rect.getHeight() * f * fm.m11));
    if (!scissorStack.empty()) {
        IGuiRect parentRect = scissorStack.peek();
        int x = Math.max(parentRect.getX(), sRect.getX());
        int y = Math.max(parentRect.getY(), sRect.getY());
        int w = Math.min(parentRect.getX() + parentRect.getWidth(), sRect.getX() + sRect.getWidth());
        int h = Math.min(parentRect.getY() + parentRect.getHeight(), sRect.getY() + sRect.getHeight());
        // Clamp to 0 to prevent OpenGL errors
        w = Math.max(0, w - x);
        // Clamp to 0 to prevent OpenGL errors
        h = Math.max(0, h - y);
        sRect = new GuiRectangle(x, y, w, h, 0);
    }
    // GL11.glScissor((int)(sRect.getX() * f * fm.m00), (r.getScaledHeight() - (int)((sRect.getY() + sRect.getHeight()) * fm.m11)) * f, (int)(sRect.getWidth() * f * fm.m00), (int)(sRect.getHeight() * f * fm.m11));
    GL11.glScissor(sRect.getX(), sRect.getY(), sRect.getWidth(), sRect.getHeight());
    scissorStack.add(sRect);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) Matrix4f(org.lwjgl.util.vector.Matrix4f) IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) FloatBuffer(java.nio.FloatBuffer)

Example 13 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class PanelPlayerPortrait method drawPanel.

@Override
public void drawPanel(int mx, int my, float partialTick) {
    IGuiRect bounds = this.getTransform();
    GlStateManager.pushMatrix();
    Minecraft mc = Minecraft.getMinecraft();
    RenderUtils.startScissor(mc, new GuiRectangle(bounds));
    GlStateManager.color(1F, 1F, 1F, 1F);
    int scale = Math.min(bounds.getWidth(), bounds.getHeight());
    /*double d0 = (Minecraft.getSystemTime()%5000L)/5000D;
		double d1 = (Math.sin(Math.toRadians(d0 * 360D)) + 1D)/2D;
		double d2 = (Math.cos(Math.toRadians(d0 * 360D)) + 1D)/2D;
		d1 = d1 * 5D + 10D;
		d2 = d2 * -10D;*/
    RenderUtils.RenderEntity(bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2 + (int) (scale * 1.2F), scale, yawDriver.readValue(), pitchDriver.readValue(), player);
    RenderUtils.endScissor(mc);
    GlStateManager.popMatrix();
}
Also used : IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) Minecraft(net.minecraft.client.Minecraft)

Example 14 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class PanelHBarFill method drawPanel.

@Override
public void drawPanel(int mx, int my, float partialTick) {
    IGuiRect bounds = this.getTransform();
    GlStateManager.pushMatrix();
    GlStateManager.color(1F, 1F, 1F, 1F);
    if (texBack != null) {
        texBack.drawTexture(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 0F, partialTick);
    }
    float f = MathHelper.clamp(fillDriver.readValue(), 0F, 1F);
    Minecraft mc = Minecraft.getMinecraft();
    if (this.flipBar) {
        RenderUtils.startScissor(mc, new GuiRectangle(bounds.getX() + (int) (bounds.getWidth() - (bounds.getWidth() * f)), bounds.getY(), (int) (bounds.getWidth() * f), bounds.getHeight(), 0));
    } else {
        RenderUtils.startScissor(mc, new GuiRectangle(bounds.getX(), bounds.getY(), (int) (bounds.getWidth() * f), bounds.getHeight(), 0));
    }
    if (this.clrThreshold > 0 && f < this.clrThreshold) {
        int tmpC = this.clrLow;
        if (lerpClr) {
            tmpC = RenderUtils.lerpRGB(clrLow, clrNorm, f / clrThreshold);
        }
        int a1 = (tmpC >> 24) & 255;
        int r1 = (tmpC >> 16) & 255;
        int g1 = (tmpC >> 8) & 255;
        int b1 = tmpC & 255;
        GlStateManager.color(r1 / 255F, g1 / 255F, b1 / 255F, a1 / 255F);
    } else {
        int a1 = this.clrNorm >> 24 & 255;
        int r1 = this.clrNorm >> 16 & 255;
        int g1 = this.clrNorm >> 8 & 255;
        int b1 = this.clrNorm & 255;
        GlStateManager.color(r1 / 255F, g1 / 255F, b1 / 255F, a1 / 255F);
    }
    if (texFill != null) {
        texFill.drawTexture(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 0F, partialTick);
    }
    RenderUtils.endScissor(mc);
    GlStateManager.popMatrix();
}
Also used : IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) Minecraft(net.minecraft.client.Minecraft)

Example 15 with GuiRectangle

use of betterquesting.api2.client.gui.misc.GuiRectangle in project BetterQuesting by Funwayguy.

the class SlicedTexture method readFromJson.

public static SlicedTexture readFromJson(JsonObject json) {
    ResourceLocation res = new ResourceLocation(JsonHelper.GetString(json, "texture", "minecraft:missingno"));
    int slice = JsonHelper.GetNumber(json, "sliceMode", 1).intValue();
    JsonObject jOut = JsonHelper.GetObject(json, "coordinates");
    int ox = JsonHelper.GetNumber(jOut, "u", 0).intValue();
    int oy = JsonHelper.GetNumber(jOut, "v", 0).intValue();
    int ow = JsonHelper.GetNumber(jOut, "w", 48).intValue();
    int oh = JsonHelper.GetNumber(jOut, "h", 48).intValue();
    JsonObject jIn = JsonHelper.GetObject(json, "border");
    int il = JsonHelper.GetNumber(jIn, "l", 16).intValue();
    int it = JsonHelper.GetNumber(jIn, "t", 16).intValue();
    int ir = JsonHelper.GetNumber(jIn, "r", 16).intValue();
    int ib = JsonHelper.GetNumber(jIn, "b", 16).intValue();
    return new SlicedTexture(res, new GuiRectangle(ox, oy, ow, oh), new GuiPadding(il, it, ir, ib)).setSliceMode(SliceMode.values()[slice % 3]);
}
Also used : GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) ResourceLocation(net.minecraft.util.ResourceLocation) JsonObject(com.google.gson.JsonObject) GuiPadding(betterquesting.api2.client.gui.misc.GuiPadding)

Aggregations

GuiRectangle (betterquesting.api2.client.gui.misc.GuiRectangle)12 IGuiRect (betterquesting.api2.client.gui.misc.IGuiRect)6 PanelButton (betterquesting.api2.client.gui.controls.PanelButton)5 CanvasTextured (betterquesting.api2.client.gui.panels.CanvasTextured)5 Minecraft (net.minecraft.client.Minecraft)5 IPanelButton (betterquesting.api2.client.gui.controls.IPanelButton)4 PanelVScrollBar (betterquesting.api2.client.gui.panels.bars.PanelVScrollBar)4 PanelLine (betterquesting.api2.client.gui.panels.content.PanelLine)4 CanvasScrolling (betterquesting.api2.client.gui.panels.lists.CanvasScrolling)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 Vector4f (org.lwjgl.util.vector.Vector4f)4 IQuest (betterquesting.api.questing.IQuest)3 PanelButtonStorage (betterquesting.api2.client.gui.controls.PanelButtonStorage)3 GuiPadding (betterquesting.api2.client.gui.misc.GuiPadding)3 CanvasEmpty (betterquesting.api2.client.gui.panels.CanvasEmpty)3 PanelTextBox (betterquesting.api2.client.gui.panels.content.PanelTextBox)3 IGuiTexture (betterquesting.api2.client.gui.resources.textures.IGuiTexture)3 GuiTransform (betterquesting.api2.client.gui.misc.GuiTransform)2 PanelGeneric (betterquesting.api2.client.gui.panels.content.PanelGeneric)2 IGuiColor (betterquesting.api2.client.gui.resources.colors.IGuiColor)2