Search in sources :

Example 11 with IGuiRect

use of betterquesting.api2.client.gui.misc.IGuiRect 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 12 with IGuiRect

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

the class RenderUtils method endScissor.

/**
 * Pops the last scissor off the stack and returns to the last parent scissor or disables it if there are none
 */
public static void endScissor(Minecraft mc) {
    scissorStack.pop();
    if (scissorStack.empty()) {
        GL11.glDisable(GL11.GL_SCISSOR_TEST);
    } else {
        IGuiRect rect = scissorStack.peek();
        // GL11.glScissor(rect.getX() * f, (r.getScaledHeight() - rect.getY() - rect.getHeight())*f, rect.getWidth() * f, rect.getHeight() * f);
        GL11.glScissor(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
    }
}
Also used : IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect)

Example 13 with IGuiRect

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

the class PanelButton method drawPanel.

@Override
public void drawPanel(int mx, int my, float partialTick) {
    IGuiRect bounds = this.getTransform();
    GlStateManager.pushMatrix();
    GlStateManager.color(1F, 1F, 1F, 1F);
    int curState = !getBtnState() ? 0 : (bounds.contains(mx, my) ? 2 : 1);
    if (curState == 2 && pendingRelease && Mouse.isButtonDown(0)) {
        curState = 0;
    }
    IGuiTexture t = texStates[curState];
    if (// Support for text or icon only buttons in one or more states.
    t != null) {
        t.drawTexture(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 0F, partialTick);
    }
    if (texIcon != null) {
        int isz = Math.min(bounds.getHeight() - icoPadding, bounds.getWidth() - icoPadding);
        if (isz > 0) {
            texIcon.drawTexture(bounds.getX() + (bounds.getWidth() / 2) - (isz / 2), bounds.getY() + (bounds.getHeight() / 2) - (isz / 2), isz, isz, 0F, partialTick);
        }
    }
    if (btnText != null && btnText.length() > 0) {
        drawCenteredString(Minecraft.getMinecraft().fontRenderer, btnText, bounds.getX() + bounds.getWidth() / 2, bounds.getY() + bounds.getHeight() / 2 - 4, colStates[curState].getRGB(), txtShadow);
    }
    GlStateManager.popMatrix();
}
Also used : IGuiTexture(betterquesting.api2.client.gui.resources.textures.IGuiTexture)

Example 14 with IGuiRect

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

the class PanelVScrollBar method onMouseScroll.

@Override
public boolean onMouseScroll(int mx, int my, int sdx) {
    IGuiRect bounds = this.getTransform();
    if (sdx == 0 || !bounds.contains(mx, my)) {
        return false;
    }
    float dy = sdx * speed;
    if ((dy < 0F && scroll <= 0F) || (dy > 0F && scroll >= 1F)) {
        return false;
    } else {
        this.writeValue(dy + scroll);
        return true;
    }
}
Also used : IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect)

Example 15 with IGuiRect

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

the class PanelVScrollBar method drawPanel.

@Override
public void drawPanel(int mx, int my, float partialTick) {
    IGuiRect bounds = this.getTransform();
    if (isDragging && (Mouse.isButtonDown(0) || Mouse.isButtonDown(2))) {
        float cy = (float) (my - (bounds.getY() + hSize / 2)) / (float) (bounds.getHeight() - hSize);
        this.writeValue(cy);
    } else if (isDragging) {
        this.isDragging = false;
    }
    GlStateManager.pushMatrix();
    GlStateManager.color(1F, 1F, 1F, 1F);
    if (texBack != null) {
        texBack.drawTexture(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), 0F, partialTick);
    }
    int sy = MathHelper.floor((bounds.getHeight() - hSize - (inset * 2)) * scroll);
    if (texHndlHover != null && (isDragging || bounds.contains(mx, my))) {
        texHndlHover.drawTexture(bounds.getX() + inset, bounds.getY() + sy + inset, bounds.getWidth() - (inset * 2), hSize, 0F, partialTick);
    } else if (texHndlIdle != null) {
        texHndlIdle.drawTexture(bounds.getX() + inset, bounds.getY() + sy + inset, bounds.getWidth() - (inset * 2), hSize, 0F, partialTick);
    }
    GlStateManager.popMatrix();
}
Also used : IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect)

Aggregations

IGuiRect (betterquesting.api2.client.gui.misc.IGuiRect)15 GuiRectangle (betterquesting.api2.client.gui.misc.GuiRectangle)6 PanelButton (betterquesting.api2.client.gui.controls.PanelButton)4 CanvasTextured (betterquesting.api2.client.gui.panels.CanvasTextured)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 IPanelButton (betterquesting.api2.client.gui.controls.IPanelButton)3 PanelButtonStorage (betterquesting.api2.client.gui.controls.PanelButtonStorage)3 PanelTextBox (betterquesting.api2.client.gui.panels.content.PanelTextBox)3 IGuiTexture (betterquesting.api2.client.gui.resources.textures.IGuiTexture)3 Minecraft (net.minecraft.client.Minecraft)3 FontRenderer (net.minecraft.client.gui.FontRenderer)3 Vector4f (org.lwjgl.util.vector.Vector4f)3 IQuest (betterquesting.api.questing.IQuest)2 CanvasEmpty (betterquesting.api2.client.gui.panels.CanvasEmpty)2 PanelGeneric (betterquesting.api2.client.gui.panels.content.PanelGeneric)2 IGuiColor (betterquesting.api2.client.gui.resources.colors.IGuiColor)2 IGuiLine (betterquesting.api2.client.gui.resources.lines.IGuiLine)2 GuiTextureColored (betterquesting.api2.client.gui.resources.textures.GuiTextureColored)2