Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public boolean shouldRender() {
* @param drawContext The GuiGraphics instance used to render.
*/
public void render(DrawContext drawContext) {
drawContext.drawTooltip(MinecraftClient.getInstance().textRenderer, this.tooltip, HoveredTooltipPositioner.INSTANCE, this.x, this.y);
drawContext.drawTooltip(MinecraftClient.getInstance().textRenderer, this.tooltip, HoveredTooltipPositioner.INSTANCE, this.x, this.y, true);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

package org.thinkingstudio.obsidianui.border;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.*;
import net.minecraft.util.math.ColorHelper;
import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor;
import org.thinkingstudio.obsidianui.util.ColorUtil;
import org.thinkingstudio.obsidianui.widget.SpruceWidget;

Expand All @@ -31,17 +27,17 @@ public final class SimpleBorder implements Border {
public static final SimpleBorder SIMPLE_BORDER = new SimpleBorder(1, 192, 192, 192, 255);

private final int thickness;
private final int[] color;
private final int[] focusedColor;
private final int color;
private final int focusedColor;

public SimpleBorder(int thickness, int color) {
this(thickness, color, color);
}

public SimpleBorder(int thickness, int color, int focusedColor) {
this.thickness = thickness;
this.color = ColorUtil.unpackARGBColor(color);
this.focusedColor = ColorUtil.unpackARGBColor(focusedColor);
this.color = color;
this.focusedColor = focusedColor;
}

public SimpleBorder(int thickness, int red, int green, int blue, int alpha) {
Expand All @@ -50,46 +46,26 @@ public SimpleBorder(int thickness, int red, int green, int blue, int alpha) {

public SimpleBorder(int thickness, int red, int green, int blue, int alpha, int focusedRed, int focusedGreen, int focusedBlue, int focusedAlpha) {
this.thickness = thickness;
this.color = new int[]{red, green, blue, alpha};
this.focusedColor = new int[]{focusedRed, focusedGreen, focusedBlue, focusedAlpha};
this.color = ColorUtil.packARGBColor(red, green, blue, alpha);
this.focusedColor = ColorUtil.packARGBColor(focusedRed, focusedGreen, focusedBlue, focusedAlpha);
}

@Override
public void render(DrawContext drawContext, SpruceWidget widget, int mouseX, int mouseY, float delta) {
RenderLayer renderLayer = RenderLayer.getGui();
VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer);
public void render(DrawContext context, SpruceWidget widget, int mouseX, int mouseY, float delta) {
int x = widget.getX();
int y = widget.getY();
int right = x + widget.getWidth();
int bottom = y + widget.getHeight();
boolean focused = widget.isFocused();
int color = focused ? this.focusedColor : this.color;
// Top border
this.vertex(vertexConsumer, x, y + this.thickness, focused);
this.vertex(vertexConsumer, right, y + this.thickness, focused);
this.vertex(vertexConsumer, right, y, focused);
this.vertex(vertexConsumer, x, y, focused);
context.fill(x, y, right, y + thickness, color);
// Right border
this.vertex(vertexConsumer, right - this.thickness, bottom, focused);
this.vertex(vertexConsumer, right, bottom, focused);
this.vertex(vertexConsumer, right, y, focused);
this.vertex(vertexConsumer, right - this.thickness, y, focused);
context.fill(right - thickness, y, right, bottom, color);
// Bottom
this.vertex(vertexConsumer, x, bottom, focused);
this.vertex(vertexConsumer, right, bottom, focused);
this.vertex(vertexConsumer, right, bottom - this.thickness, focused);
this.vertex(vertexConsumer, x, bottom - this.thickness, focused);
context.fill(x, bottom - thickness, right, bottom, color);
// Left border
this.vertex(vertexConsumer, x, bottom, focused);
this.vertex(vertexConsumer, x + this.thickness, bottom, focused);
this.vertex(vertexConsumer, x + this.thickness, y, focused);
this.vertex(vertexConsumer, x, y, focused);
drawContext.draw();

}

private void vertex(VertexConsumer consumer, int x, int y, boolean focused) {
int[] color = focused ? this.focusedColor : this.color;
consumer.vertex(x, y, 0).color(color[0], color[1], color[2], color[3]);
context.fill(x, y, x + thickness, bottom, color);
}

@Override
Expand All @@ -101,8 +77,8 @@ public int getThickness() {
public String toString() {
return "SimpleBorder{" +
"thickness=" + this.thickness +
", color=" + Arrays.toString(this.color) +
", focusedColor=" + Arrays.toString(this.focusedColor) +
", color=" + Arrays.toString(ColorUtil.unpackARGBColor(this.color)) +
", focusedColor=" + Arrays.toString(ColorUtil.unpackARGBColor(this.focusedColor)) +
'}';
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private boolean tryNavigating(Element element, NavigationDirection direction, bo

@Override
public void render(DrawContext drawContext, int mouseX, int mouseY, float delta) {
this.renderBackground(drawContext, mouseX, mouseY, delta);
this.renderWidgets(drawContext, mouseX, mouseY, delta);
this.renderTitle(drawContext, mouseX, mouseY, delta);
Tooltip.renderAll(drawContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@

package org.thinkingstudio.obsidianui.util;

import com.mojang.blaze3d.opengl.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.RenderPipelines;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.*;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ColorHelper;
import org.thinkingstudio.obsidianui.mixin.DrawContextAccessor;

public final class RenderUtil {
/**
Expand Down Expand Up @@ -50,7 +47,7 @@ public static void renderTransparentBackgroundTexture(DrawContext drawContext, i
/**
* Renders the vanilla's transparent background texture.
*
* @param drawContext the current draw context
* @param context the current draw context
* @param x the X-coordinate
* @param y the Y-coordinate
* @param width the width
Expand All @@ -61,29 +58,12 @@ public static void renderTransparentBackgroundTexture(DrawContext drawContext, i
* @param blue the blue-component color value
* @param alpha the alpha-component alpha value
*/
public static void renderTransparentBackgroundTexture(DrawContext drawContext, int x, int y, int width, int height, float vOffset,
public static void renderTransparentBackgroundTexture(DrawContext context, int x, int y, int width, int height, float vOffset,
int red, int green, int blue, int alpha) {
RenderLayer renderLayer = RenderLayer.getGuiTextured(getListBackgroundTexture());
VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer);

int right = x + width;
int bottom = y + height;

GlStateManager._enableBlend();
vertexConsumer.vertex(x, bottom, 0)
.texture(0, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, bottom, 0)
.texture(right / 32.f, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, y, 0)
.texture(right / 32.f, y / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(x, y, 0)
.texture(0, y / 32.f + vOffset)
.color(red, green, blue, alpha);
drawContext.draw();
GlStateManager._disableBlend();
context.drawTexture(RenderPipelines.GUI_TEXTURED, getListBackgroundTexture(), x, y, x, y, width, height, (int) (right / 32.f), (int) (bottom / 32.f + vOffset), ColorUtil.packARGBColor(red, green, blue, alpha));
}
public static Identifier getListBackgroundTexture() {
return client.world == null ? MENU_LIST_BACKGROUND_TEXTURE : INWORLD_MENU_LIST_BACKGROUND_TEXTURE;
Expand All @@ -108,7 +88,7 @@ public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, i
/**
* Renders the dirt background texture.
*
* @param drawContext the current draw context
* @param context the current draw context
* @param x the X-coordinate
* @param y the Y-coordinate
* @param width the width
Expand All @@ -120,33 +100,18 @@ public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, i
* @param alpha the alpha-component alpha value
*/
@Deprecated(since = "1.20.5")
public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, int y, int width, int height, float vOffset,
public static void renderDirtBackgroundTexture(DrawContext context, int x, int y, int width, int height, float vOffset,
int red, int green, int blue, int alpha) {
RenderLayer renderLayer = RenderLayer.getGuiTextured(DIRT_BACKGROUND_TEXTURE);
VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer);

int right = x + width;
int bottom = y + height;

vertexConsumer.vertex(x, bottom, 0)
.texture(0, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, bottom, 0)
.texture(right / 32.f, bottom / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(right, y, 0)
.texture(right / 32.f, y / 32.f + vOffset)
.color(red, green, blue, alpha);
vertexConsumer.vertex(x, y, 0)
.texture(0, y / 32.f + vOffset)
.color(red, green, blue, alpha);
drawContext.draw();
context.drawTexture(RenderPipelines.GUI_TEXTURED, DIRT_BACKGROUND_TEXTURE, x, y, x, y, width, height, (int) (right / 32.f), (int) (bottom / 32.f + vOffset), ColorUtil.packARGBColor(red, green, blue, alpha));
}

/**
* Renders a selection box as background.
*
* @param drawContext the current draw context
* @param context the current draw context
* @param x the X-coordinate of the selection box
* @param y the Y-coordinate of the selection box
* @param width the width of the selection box
Expand All @@ -156,22 +121,13 @@ public static void renderDirtBackgroundTexture(DrawContext drawContext, int x, i
* @param blue the blue-component color value of the outer border
* @param alpha the alpha-component color value of the outer border
*/
public static void renderSelectionBox(DrawContext drawContext, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
public static void renderSelectionBox(DrawContext context, int x, int y, int width, int height, int red, int green, int blue, int alpha) {
int top = y + height;
int right = x + width;

RenderLayer renderLayer = RenderLayer.getGui();
VertexConsumer vertexConsumer = ((DrawContextAccessor)drawContext).getVertexConsumers().getBuffer(renderLayer);
int argb = ColorHelper.getArgb(alpha, red, green, blue);
vertexConsumer.vertex(x, top, 0).color(argb);
vertexConsumer.vertex(right, top, 0).color(argb);
vertexConsumer.vertex(right, y, 0).color(argb);
vertexConsumer.vertex(x, y, 0).color(argb);
context.fill(x, top, right, y, argb);
int dark = ColorHelper.getArgb(0, 0, 0);
vertexConsumer.vertex(x + 1, top - 1, 0).color(dark);
vertexConsumer.vertex(right - 1, top - 1, 0).color(dark);
vertexConsumer.vertex(right - 1, y + 1, 0).color(dark);
vertexConsumer.vertex(x + 1, y + 1, 0).color(dark);
drawContext.draw();
context.fill(x, top, right, y, dark);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
package org.thinkingstudio.obsidianui.widget;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gl.RenderPipelines;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.ButtonTextures;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.screen.narration.NarrationPart;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
import org.thinkingstudio.obsidianui.Position;
import org.thinkingstudio.obsidianui.Tooltip;
import org.thinkingstudio.obsidianui.Tooltipable;
import org.thinkingstudio.obsidianui.util.ColorUtil;
import org.thinkingstudio.obsidianui.wrapper.VanillaButtonWrapper;

import java.util.Optional;
Expand Down Expand Up @@ -162,8 +165,7 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo

@Override
protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) {
RenderSystem.setShaderColor(1.f, 1.f, 1.f, this.getAlpha());
drawContext.drawGuiTexture(RenderLayer::getGuiTextured, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight());
drawContext.drawGuiTexture(RenderPipelines.GUI_TEXTURED, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight(), ColorHelper.fromFloats(this.getAlpha(), 1.f, 1.f, 1.f));
}

/* Narration */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.RenderPipelines;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.OrderedText;
Expand All @@ -21,6 +22,7 @@
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.MathHelper;
import org.thinkingstudio.obsidianui.Position;
import org.thinkingstudio.obsidianui.util.ColorUtil;

/**
* Represents a checkbox widget.
Expand Down Expand Up @@ -90,21 +92,16 @@ public void setColored(boolean colored) {

@Override
protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) {
float[] oldColor = RenderSystem.getShaderColor();
float oldRed = oldColor[0], oldGreen = oldColor[1], oldBlue = oldColor[2], oldAlpha = oldColor[3];

if (this.getValue()) {
int color = ColorUtil.WHITE;
if (this.colored)
RenderSystem.setShaderColor(0.f, 1.f, 0.f, this.alpha);
drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64);
color = ColorHelper.fromFloats(this.alpha, 0.f, 1.f, 0.f);
drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX(), this.getY(), 0.f, 40.f, this.getHeight(), this.getHeight(), 64, 64, color);
} else if (this.showCross) {
int color = ColorUtil.WHITE;
if (this.colored)
RenderSystem.setShaderColor(1.f, 0.f, 0.f, this.alpha);
drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64);
}

if (this.colored) {
RenderSystem.setShaderColor(oldRed, oldGreen, oldBlue, oldAlpha);
color = ColorHelper.fromFloats(this.alpha, 1.f, 0.f, 0.f);
drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX(), this.getY(), 0.f, 20.f, this.getHeight(), this.getHeight(), 64, 64, color);
}

if (this.showMessage) {
Expand All @@ -117,7 +114,7 @@ protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, flo
@Override
protected void renderBackground(DrawContext drawContext, int mouseX, int mouseY, float delta) {
int color = ColorHelper.fromFloats(this.alpha, 1.f, 1.f, 1.f);
drawContext.drawTexture(RenderLayer::getGuiTextured, TEXTURE, this.getX(), this.getY(), this.isFocusedOrHovered() ? 20.f : 0.f, 0.f, this.getHeight(), this.getHeight(), 64, 64, color);
drawContext.drawTexture(RenderPipelines.GUI_TEXTURED, TEXTURE, this.getX(), this.getY(), this.isFocusedOrHovered() ? 20.f : 0.f, 0.f, this.getHeight(), this.getHeight(), 64, 64, color);
}

/* Narration */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected void renderWidget(DrawContext drawContext, int mouseX, int mouseY, flo
var line = it.next();
int x = this.centered ? (this.getInnerX() + this.maxWidth / 2) - this.client.textRenderer.getWidth(line) / 2
: this.getInnerX();
drawContext.drawText(this.client.textRenderer, line, x, y, 10526880, true);
drawContext.drawText(this.client.textRenderer, line, x, y, 0xffffffff, true);
}

this.getBorder().render(drawContext, this, mouseX, mouseY, delta);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
package org.thinkingstudio.obsidianui.widget;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gl.RenderPipelines;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.ColorHelper;
import net.minecraft.util.math.MathHelper;
import org.thinkingstudio.obsidianui.Position;
import org.thinkingstudio.obsidianui.Tooltipable;
Expand Down Expand Up @@ -172,10 +174,8 @@ protected Identifier getTexture() {

@Override
protected void renderButton(DrawContext drawContext, int mouseX, int mouseY, float delta) {
RenderSystem.setShaderColor(1.f, 1.f, 1.f, 1.f);

final Identifier texture = this.isFocusedOrHovered() ? SLIDER_HANDLE_HIGHLIGHTED : SLIDER_HANDLE;
drawContext.drawGuiTexture(RenderLayer::getGuiTextured, texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20);
drawContext.drawGuiTexture(RenderPipelines.GUI_TEXTURED, texture, this.getX() + (int) (this.value * (double) (this.getWidth() - 8)), this.getY(), 8, 20);

if (!this.isMouseHovered() && this.inUse) {
this.inUse = false;
Expand Down
Loading