Skip to content

Commit

Permalink
feat(glfw3): classes for splashscreen implementation on GLFW3. Enable…
Browse files Browse the repository at this point in the history
… Composite Build for Terasology workspace.
  • Loading branch information
DarkWeird committed Jul 28, 2020
1 parent 196975e commit f9828ca
Show file tree
Hide file tree
Showing 18 changed files with 2,467 additions and 1 deletion.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply plugin: 'com.github.spotbugs'
apply plugin: 'maven-publish'
apply plugin: 'java-library'

group = 'org.terasology'

Expand Down Expand Up @@ -53,6 +54,14 @@ dependencies {

codeMetrics(group: 'org.terasology.config', name: 'codemetrics', version: '1.3.2', ext: 'zip')

// GLFW splash screen
implementation platform("org.lwjgl:lwjgl-bom:3.2.3")
implementation 'org.lwjgl:lwjgl'
implementation 'org.lwjgl:lwjgl-opengl'
implementation 'org.lwjgl:lwjgl-glfw'
implementation group: 'de.matthiasmann.twl', name: 'PNGDecoder', version: '1111'
implementation group: 'org.joml', name: 'joml', version: '1.9.25'

testImplementation group: 'junit', name: 'junit', version: '4.12'

// testRuntime group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.3'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.4-SNAPSHOT
version=1.1.0
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'splash-screen'
275 changes: 275 additions & 0 deletions src/main/java/org/terasology/splash/glfw/graphics/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

/*
* The MIT License
*
* Copyright © 2015, Heiko Brumme
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.terasology.splash.glfw.graphics;

import org.joml.Vector3f;
import org.joml.Vector4f;

/**
* This class represents a RGBA color.
*
* @author Heiko Brumme
*/
public final class Color {

public static final Color WHITE = new Color(1f, 1f, 1f);
public static final Color BLACK = new Color(0f, 0f, 0f);
public static final Color RED = new Color(1f, 0f, 0f);
public static final Color GREEN = new Color(0f, 1f, 0f);
public static final Color BLUE = new Color(0f, 0f, 1f);

/**
* This value specifies the red component.
*/
private float red;

/**
* This value specifies the green component.
*/
private float green;

/**
* This value specifies the blue component.
*/
private float blue;

/**
* This value specifies the transparency.
*/
private float alpha;

/**
* The default color is black.
*/
public Color() {
this(0f, 0f, 0f);
}

/**
* Creates a RGB-Color with an alpha value of 1.
*
* @param red The red component. Range from 0f to 1f.
* @param green The green component. Range from 0f to 1f.
* @param blue The blue component. Range from 0f to 1f.
*/
public Color(float red, float green, float blue) {
this(red, green, blue, 1f);
}

/**
* Creates a RGBA-Color.
*
* @param red The red component. Range from 0f to 1f.
* @param green The green component. Range from 0f to 1f.
* @param blue The blue component. Range from 0f to 1f.
* @param alpha The transparency. Range from 0f to 1f.
*/
public Color(float red, float green, float blue, float alpha) {
setRed(red);
setGreen(green);
setBlue(blue);
setAlpha(alpha);
}

/**
* Creates a RGB-Color with an alpha value of 1.
*
* @param red The red component. Range from 0 to 255.
* @param green The green component. Range from 0 to 255.
* @param blue The blue component. Range from 0 to 255.
*/
public Color(int red, int green, int blue) {
this(red, green, blue, 255);
}

/**
* Creates a RGBA-Color.
*
* @param red The red component. Range from 0 to 255.
* @param green The green component. Range from 0 to 255.
* @param blue The blue component. Range from 0 to 255.
* @param alpha The transparency. Range from 0 to 255.
*/
public Color(int red, int green, int blue, int alpha) {
setRed(red);
setGreen(green);
setBlue(blue);
setAlpha(alpha);
}

/**
* Returns the red component.
*
* @return The red component.
*/
public float getRed() {
return red;
}

/**
* Sets the red component.
*
* @param red The red component. Range from 0f to 1f.
*/
public void setRed(float red) {
if (red < 0f) {
red = 0f;
}
if (red > 1f) {
red = 1f;
}
this.red = red;
}

/**
* Sets the red component.
*
* @param red The red component. Range from 0 to 255.
*/
public void setRed(int red) {
setRed(red / 255f);
}

/**
* Returns the green component.
*
* @return The green component.
*/
public float getGreen() {
return green;
}

/**
* Sets the green component.
*
* @param green The green component. Range from 0f to 1f.
*/
public void setGreen(float green) {
if (green < 0f) {
green = 0f;
}
if (green > 1f) {
green = 1f;
}
this.green = green;
}

/**
* Sets the green component.
*
* @param green The green component. Range from 0 to 255.
*/
public void setGreen(int green) {
setGreen(green / 255f);
}

/**
* Returns the blue component.
*
* @return The blue component.
*/
public float getBlue() {
return blue;
}

/**
* Sets the blue component.
*
* @param blue The blue component. Range from 0f to 1f.
*/
public void setBlue(float blue) {
if (blue < 0f) {
blue = 0f;
}
if (blue > 1f) {
blue = 1f;
}
this.blue = blue;
}

/**
* Sets the blue component.
*
* @param blue The blue component. Range from 0 to 255.
*/
public void setBlue(int blue) {
setBlue(blue / 255f);
}

/**
* Returns the transparency.
*
* @return The transparency.
*/
public float getAlpha() {
return alpha;
}

/**
* Sets the transparency.
*
* @param alpha The transparency. Range from 0f to 1f.
*/
public void setAlpha(float alpha) {
if (alpha < 0f) {
alpha = 0f;
}
if (alpha > 1f) {
alpha = 1f;
}
this.alpha = alpha;
}

/**
* Sets the transparency.
*
* @param alpha The transparency. Range from 0 to 255.
*/
public void setAlpha(int alpha) {
setAlpha(alpha / 255f);
}

/**
* Returns the color as a (x,y,z)-Vector.
*
* @return The color as vec3.
*/
public Vector3f toVector3f() {
return new Vector3f(red, green, blue);
}

/**
* Returns the color as a (x,y,z,w)-Vector.
*
* @return The color as vec4.
*/
public Vector4f toVector4f() {
return new Vector4f(red, green, blue, alpha);
}

}
Loading

0 comments on commit f9828ca

Please sign in to comment.