Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for WLabel, WText and WDynamicLabel to have shadows #248

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion src/main/java/io/github/cottonmc/cotton/gui/widget/WLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ public WLabel(Text text) {
public void paint(DrawContext context, int x, int y, int mouseX, int mouseY) {
int yOffset = TextAlignment.getTextOffsetY(verticalAlignment, height, 1);

ScreenDrawing.drawString(context, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color);
if (areShadowsDrawn()) {
ScreenDrawing.drawStringWithShadow(context, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color);
} else {
ScreenDrawing.drawString(context, text.asOrderedText(), horizontalAlignment, x, y + yOffset, this.getWidth(), shouldRenderInDarkMode() ? darkmodeColor : color);
}

Style hoveredTextStyle = getTextStyleAt(mouseX, mouseY);
ScreenDrawing.drawTextHover(context, hoveredTextStyle, x + mouseX, y + mouseY);
Expand Down Expand Up @@ -176,6 +180,28 @@ public WLabel setColor(int color, int darkmodeColor) {
return this;
}

/**
* Checks whether shadows should be drawn for this label.
*
* @return {@code true} shadows should be drawn, {@code false} otherwise
* @since 11.0.1
MarcusElg marked this conversation as resolved.
Show resolved Hide resolved
*/
public boolean areShadowsDrawn() {
MarcusElg marked this conversation as resolved.
Show resolved Hide resolved
return drawShadows;
}

/**
* Sets whether shadows should be drawn for this labbel.
MarcusElg marked this conversation as resolved.
Show resolved Hide resolved
*
* @param drawShadows {@code true} if shadows should be drawn, {@code false} otherwise
* @return this label
* @since 11.0.1
*/
public WLabel setDrawShadows(boolean drawShadows) {
this.drawShadows = drawShadows;
return this;
}

/**
* Gets the text of this label.
*
Expand Down
Loading