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

feat(Drawable): add more setColor methods #3

Merged
merged 6 commits into from
Sep 17, 2023
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
53 changes: 50 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,53 @@
# Project exclude paths
out
build
.doc
.tmp
.gradle
bin

# github java .gitignore
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

# github gradle .gitignore
.gradle
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

# Eclipse Gradle plugin generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
46 changes: 43 additions & 3 deletions src/main/java/paintingcanvas/drawable/Drawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,22 @@ public T setColor(int r, int g, int b) {
return this.setColor(new Color(r, g, b));
}

/**
* Set the color of the element with <a href="https://en.wikipedia.org/wiki/RGBA_color_model">RGBA</a>.
* <pre>{@code
* Circle o = new Circle(100, 100, 20);
* o.setColor(255, 0, 0); // Set color to red
* }</pre>
*
* @param r The red component of the color (0-255)
* @param g The green component of the color (0-255)
* @param b The blue component of the color (0-255)
* @return The original object to allow method chaining
*/
public T setColor(int r, int g, int b, int a) {
return this.setColor(new Color(r, g, b, a));
}

/**
* Get the current color of an element as a {@link Color}
*
Expand All @@ -429,19 +445,43 @@ public T setColor(Color color) {
return getThis();
}

/**
* Set the color of the object with a {@link Hue} object.
* <pre>{@code
* Circle o = new Circle(100, 100, 20);
* o.setColor(Hue.GREEN); // Set color to red
* }</pre>
*
* @param color color.
* @return The original object to allow method chaining
*/
public T setColor(Hue hue) {
synchronized (Canvas.drawableSync) {
this.color = hue.getColor();
}
return getThis();
}

/**
* Set the color of the object with a certain color by name
* Set the color of the object with a certain color by name, or by a <a href="https://en.wikipedia.org/wiki/RGB_color_model">hex code</a>. string.
* (see {@link Hue} for list of all valid names)
* <pre>{@code
* Circle o = new Circle(100, 100, 20);
* o.setColor("red"); // Set color to red
* // #FF0000 is hex for (255, 0, 0), which is red
* o.setColor("#FF0000"); // Set color to red, in a different way
* }</pre>
*
* @param color The name of the color (case-insensitive)
* @return The original object to allow method chaining
*/
public T setColor(String color) {
return setColor(Hue.getColor(color));
public T setColor(String name) {
try {
var color = Color.decode(name);
return setColor(color);
} catch (Exception e) {
return setColor(Hue.getColor(name));
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/paintingcanvas/drawable/Triangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class Triangle extends Drawable<Triangle> {
*/
public int height;

private Polygon poly;

/**
* Create a new Triangle element.
* <pre>{@code
Expand Down Expand Up @@ -144,4 +142,4 @@ protected void drawOutline(Graphics2D gc) {
protected Triangle getThis() {
return this;
}
}
}
1 change: 0 additions & 1 deletion src/main/java/paintingcanvas/extensions/InfoDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import paintingcanvas.canvas.RenderLifecycle;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
* Displays some information on the screen, such as
Expand Down
1 change: 0 additions & 1 deletion src/test/java/examples/Tessellation.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ void draw(int x, int y) {
var height = Const.height;

var p1 = new Point(-size / 2, -height);
var p2 = new Point(size / 2, -height);

path = new Path().setPos(x, y);
outline = new Path().setPos(x, y);
Expand Down
Loading