Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #32 from scireum/feature/jvo/OX-8741-Color-Functions
Browse files Browse the repository at this point in the history
Public Color Functions (OX-8741)
  • Loading branch information
jakobvogel authored Jun 21, 2022
2 parents 5198143 + 203cf88 commit 7f7fbf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ clone:

steps:
- name: compile
image: hub.scireum.com/scireum/sirius-build-jdk16:latest
image: scireum/sirius-build-jdk18
commands:
- mvn clean compile
volumes: *scireum_volumes
Expand All @@ -26,7 +26,7 @@ steps:
- push

- name: test
image: hub.scireum.com/scireum/sirius-build-jdk16:latest
image: scireum/sirius-build-jdk18
commands:
- mvn clean test
volumes: *scireum_volumes
Expand All @@ -35,7 +35,7 @@ steps:
- pull_request

- name: sonar
image: hub.scireum.com/scireum/sirius-build-jdk16:latest
image: scireum/sirius-build-jdk18
commands:
- sed -i 's/DEVELOPMENT-SNAPSHOT/${DRONE_TAG}/g' pom.xml
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test sonar:sonar -Dsonar.projectKey=${DRONE_REPO_NAME}
Expand All @@ -45,7 +45,7 @@ steps:
- tag

- name: deploy
image: hub.scireum.com/scireum/sirius-build-jdk16:latest
image: scireum/sirius-build-jdk18
commands:
- sed -i 's/DEVELOPMENT-SNAPSHOT/${DRONE_TAG}/g' pom.xml
- mvn clean deploy -DskipTests
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.scireum</groupId>
<artifactId>sirius-parent</artifactId>
<version>8.0.1</version>
<version>10.1.1</version>
</parent>
<artifactId>server-sass</artifactId>
<version>DEVELOPMENT-SNAPSHOT</version>
Expand Down
40 changes: 33 additions & 7 deletions src/main/java/org/serversass/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,46 @@ public class Functions {
private Functions() {
}

private static Expression changeLighteness(Color color, int changeInPercent) {
/**
* Modifies the given color's lightness (after conversion into the HSL model) by the given percentage. Use negative
* amounts to darken the color.
*
* @param color the original color as hex string
* @param changeInPercent the change in percent, possibly negative
* @return the lighter (or darker) version of the given color as hex string
*/
public static Color changeLightness(Color color, int changeInPercent) {
Color.HSL hsl = color.getHSL();
hsl.setL(Math.max(Math.min(hsl.getL() * (1 + (changeInPercent / 100d)), 1d), 0d));
return hsl.getColor();
}

private static Expression changeSaturation(Color color, int changeInPercent) {
/**
* Modifies the given color's saturation (after conversion into the HSL model) by the given percentage.
*
* @param color the original color as hex string
* @param changeInPercent the change in percent
* @return the modified color as hex string
*/
public static Color changeSaturation(Color color, int changeInPercent) {
Color.HSL hsl = color.getHSL();
hsl.setS(Math.max(Math.min(hsl.getS() * (1 + (changeInPercent / 100d)), 1d), 0d));
return hsl.getColor();
}

/**
* Modifies the given color's hue (on the color circle, after conversion into the HSL model) by the given angle.
*
* @param color the original color as hex string
* @param changeInDegrees the change in degrees
* @return the modified color as hex string
*/
public static Color changeHue(Color color, int changeInDegrees) {
Color.HSL hsl = color.getHSL();
hsl.setH(hsl.getH() + changeInDegrees);
return hsl.getColor();
}

/**
* Creates a color from given RGB values.
*
Expand Down Expand Up @@ -78,9 +106,7 @@ public static Expression rgba(Generator generator, FunctionCall input) {
public static Expression adjusthue(Generator generator, FunctionCall input) {
Color color = input.getExpectedColorParam(0);
int changeInDegrees = input.getExpectedIntParam(1);
Color.HSL hsl = color.getHSL();
hsl.setH(hsl.getH() + changeInDegrees);
return hsl.getColor();
return changeHue(color, changeInDegrees);
}

/**
Expand All @@ -93,7 +119,7 @@ public static Expression adjusthue(Generator generator, FunctionCall input) {
public static Expression lighten(Generator generator, FunctionCall input) {
Color color = input.getExpectedColorParam(0);
int increase = input.getExpectedIntParam(1);
return changeLighteness(color, increase);
return changeLightness(color, increase);
}

/**
Expand Down Expand Up @@ -130,7 +156,7 @@ public static Expression opacity(Generator generator, FunctionCall input) {
public static Expression darken(Generator generator, FunctionCall input) {
Color color = input.getExpectedColorParam(0);
int decrease = input.getExpectedIntParam(1);
return changeLighteness(color, -decrease);
return changeLightness(color, -decrease);
}

/**
Expand Down

0 comments on commit 7f7fbf2

Please sign in to comment.