starting to add ui code

pull/1/head
BuildTools 2019-06-01 15:57:47 +10:00
parent c866cacb4e
commit 6e6eda52a3
21 changed files with 131 additions and 168 deletions

View File

@ -4,8 +4,8 @@ import java.util.ArrayList;
import java.util.List;
import io.github.hydos.ginger.engine.cameras.ThirdPersonCamera;
import io.github.hydos.ginger.engine.elements.GuiTexture;
import io.github.hydos.ginger.engine.elements.buttons.TextureButton;
import io.github.hydos.ginger.engine.elements.buttons.GuiTexture;
import io.github.hydos.ginger.engine.elements.objects.Entity;
import io.github.hydos.ginger.engine.elements.objects.Light;
import io.github.hydos.ginger.engine.elements.objects.Player;
@ -128,9 +128,6 @@ public class Example {
float colour = 0;
terrains.add(terrain);
// GuiTexture shadowMap = new GuiTexture(masterRenderer.getShadowMapTexture(), new Vector2f(0.5f,0.5f), new Vector2f(0.5f,0.5f));
// guis.add(shadowMap);
ParticleTexture particleTexture = new ParticleTexture(Loader.loadTexture("particles/smoke.png"), 8);
TextureButton button = new TextureButton("/textures/guis/ginger.png", new Vector2f(0.8f, 0), new Vector2f(0.1f, 0.1f));
@ -149,6 +146,7 @@ public class Example {
if(Window.isUpdating()) {
Window.update();
GingerMain.update();
colour = colour + 0.001f;
picker.update();
ParticleMaster.update(camera);
@ -168,11 +166,11 @@ public class Example {
dragon.increaseRotation(0,1,0);
barrel.increaseRotation(0, 1, 0);
// fbo.bindFrameBuffer();
// masterRenderer.renderScene(entities, normalMapEntities, terrains, lights, camera, new Vector4f(0, -1, 0, 100000));
// ParticleMaster.renderParticles(camera);
// fbo.unbindFrameBuffer();
// PostProcessing.doPostProcessing(fbo.getColourTexture());
fbo.bindFrameBuffer();
masterRenderer.renderScene(entities, normalMapEntities, terrains, lights, camera, new Vector4f(0, -1, 0, 100000));
ParticleMaster.renderParticles(camera);
fbo.unbindFrameBuffer();
PostProcessing.doPostProcessing(fbo.getColourTexture());
// TODO: get fbo's working
button.update();
if(button.isClicked()) {
@ -180,7 +178,7 @@ public class Example {
button.hide(guis);
}
masterRenderer.renderScene(entities, normalMapEntities, terrains, lights, camera, new Vector4f(0, -1, 0, 100000));
// masterRenderer.renderScene(entities, normalMapEntities, terrains, lights, camera, new Vector4f(0, -1, 0, 100000));
masterRenderer.renderGuis(guis);
TextMaster.render();

View File

@ -0,0 +1,27 @@
package io.github.hydos.ginger.UI;
import java.util.List;
import io.github.hydos.ginger.UI.enums.UIDefaultClipSide;
import io.github.hydos.ginger.UI.enums.UIType;
import io.github.hydos.ginger.engine.elements.GuiTexture;
public abstract class UICanvas {
UIDefaultClipSide clippingSide = UIDefaultClipSide.centre;
UIType type = UIType.tab;
String tabName = "Welcome";
public UICanvas() {
}
public abstract void update();
public abstract void hide(List<GuiTexture> textures);
public abstract void show(List<GuiTexture> textures);
}

View File

@ -0,0 +1,24 @@
package io.github.hydos.ginger.UI;
import io.github.hydos.ginger.UI.canvases.WelcomeScreen;
import io.github.hydos.ginger.UI.enums.UIColourType;
public class UIManager {
UIColourType colourMode = UIColourType.dark;
UICanvas welcomeScreen;
public UIManager(UIColourType type) {
this.colourMode = type;
welcomeScreen = new WelcomeScreen();
}
public void update() {
welcomeScreen.update();
}
}

View File

@ -0,0 +1,33 @@
package io.github.hydos.ginger.UI.canvases;
import java.util.List;
import io.github.hydos.ginger.UI.UICanvas;
import io.github.hydos.ginger.engine.elements.GuiTexture;
public class WelcomeScreen extends UICanvas{
public WelcomeScreen() {
}
@Override
public void update() {
}
@Override
public void hide(List<GuiTexture> textures) {
}
@Override
public void show(List<GuiTexture> textures) {
}
}

View File

@ -0,0 +1,7 @@
package io.github.hydos.ginger.UI.enums;
public enum UIColourType {
light,dark
}

View File

@ -0,0 +1,6 @@
package io.github.hydos.ginger.UI.enums;
public enum UIDefaultClipSide {
top,bottom,left,right,centre
}

View File

@ -0,0 +1,7 @@
package io.github.hydos.ginger.UI.enums;
public enum UIType {
tab, wholeScreen
}

View File

@ -93,7 +93,7 @@ public class ThirdPersonCamera {
private void calculatePitch(){
if(Window.isMouseDown(1)) {
float pitchChange = (float) (Window.getDY() * 0.2f);
float pitchChange = (float) (Window.dy * 0.2f);
pitch += pitchChange;
if(pitch < 0){
pitch = 0;
@ -105,7 +105,7 @@ public class ThirdPersonCamera {
private void calculateAngleAroundPlayer(){
if(Window.isMouseDown(1)) {
float angleChange = (float) (Window.getDX() * 0.3f);
float angleChange = (float) (Window.dx * 0.3f);
angleAroundPlayer -= angleChange;
}
}

View File

@ -1,4 +1,4 @@
package io.github.hydos.ginger.engine.elements.buttons;
package io.github.hydos.ginger.engine.elements;
import io.github.hydos.ginger.engine.mathEngine.vectors.Vector2f;

View File

@ -1,86 +0,0 @@
package io.github.hydos.ginger.engine.elements.buttons;
import java.util.List;
import org.lwjgl.glfw.GLFW;
import io.github.hydos.ginger.engine.io.Window;
import io.github.hydos.ginger.engine.mathEngine.vectors.Vector2f;
import io.github.hydos.ginger.engine.utils.Loader;
public class TextureAndTextButton{
private GuiTexture guiTexture;
private boolean shown = false;
private boolean clicked = false;
private boolean isHovering = false;
public TextureAndTextButton(String texture, Vector2f position, Vector2f scale) {
guiTexture = new GuiTexture(Loader.loadTextureDirectly(texture), position, scale);
}
public void update() {
if(shown) {
Vector2f location = guiTexture.getPosition();
Vector2f scale = guiTexture.getScale();
Vector2f mouseCoords = Window.getNormalizedMouseCoordinates();
if(location.y + scale.y > -mouseCoords.y && location.y - scale.y < -mouseCoords.y && location.x + scale.x > mouseCoords.x && location.x - scale.x < mouseCoords.x) {
isHovering = true;
if(Window.isMousePressed(GLFW.GLFW_MOUSE_BUTTON_1)) {
clicked = true;
}else {
clicked = false;
}
}else {
if(isHovering) {
isHovering = false;
}
}
}else {
isHovering = false;
clicked = false;
}
}
public void show(List<GuiTexture> guiTexture) {
if(shown) {
}else {
guiTexture.add(this.guiTexture);
this.shown = true;
}
}
public void hide(List<GuiTexture> guiTexture) {
if(!shown) {
}else {
guiTexture.remove(this.guiTexture);
this.shown = false;
}
}
public boolean isShown() {
return shown;
}
public boolean isClicked() {
return clicked;
}
public boolean isHovering() {
return isHovering;
}
}

View File

@ -4,6 +4,7 @@ import java.util.List;
import org.lwjgl.glfw.GLFW;
import io.github.hydos.ginger.engine.elements.GuiTexture;
import io.github.hydos.ginger.engine.io.Window;
import io.github.hydos.ginger.engine.mathEngine.vectors.Vector2f;
import io.github.hydos.ginger.engine.utils.Loader;

View File

@ -26,19 +26,14 @@ public class Window {
private static boolean[] keys = new boolean[GLFW.GLFW_KEY_LAST];
private static boolean[] mouseButtons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST];
private static GLFWImage.Buffer iconBuffer = null;
private static GLFWImage cursorBuffer = null;
private static double fpsCap, time, processedTime = 0;
private static boolean isFullscreen = false;
private static double dy = 0;
private static double dx = 0;
public static double dy = 0;
public static double dx = 0;
static double oldX = 0;
static double oldY = 0;
static double newX = 0;
static double newY = 0;
// // Mouse positions
// private static int mouseX, mouseY;
// private static int mouseDX, mouseDY;
private static boolean mouseLocked = false;
public static GLCapabilities glContext;
public static void create(int width, int height, String title, int fps) {
@ -114,21 +109,6 @@ public class Window {
oldX = newX;
oldY = newY;
// DoubleBuffer x = BufferUtils.createDoubleBuffer(1);
// DoubleBuffer y = BufferUtils.createDoubleBuffer(1);
//
// GLFW.glfwGetCursorPos(window, x, y);
// x.rewind();
// y.rewind();
//
// newX = (float) x.get();
// newY = (float) y.get();
//
// float deltaX = newX - oldX;
// float deltaY = newY - oldY;
// Window.dx = deltaX;
// Window.dy = deltaY;
}
@Deprecated
@ -215,22 +195,6 @@ public class Window {
iconBuffer.put(0, iconImage);
}
public void setCursor(String path) {
Image cursor = Image.createImage("/res/textures/" + path);
cursorBuffer = GLFWImage.malloc();
cursorBuffer.set(cursor.getWidth(), cursor.getHeight(), cursor.getImage());
}
public static void showCursor() {
if(iconBuffer != null) {
long cursor = GLFW.glfwCreateCursor(cursorBuffer, 0, 0);
GLFW.glfwSetCursor(window, cursor);
}
}
public static void showIcon() {
if(iconBuffer != null) {
GLFW.glfwSetWindowIcon(window, iconBuffer);
@ -242,30 +206,12 @@ public class Window {
Window.isFullscreen = t;
}
public boolean isFullscreen() {
return Window.isFullscreen;
}
public void lockMouse() {
public static void lockMouse() {
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_DISABLED);
mouseLocked = true;
}
public void unlockMouse() {
public static void unlockMouse() {
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
mouseLocked = false;
}
public void toggleMouseLock() {
if(mouseLocked) {
unlockMouse();
}else {
lockMouse();
}
}
public boolean isMouseLocked() {
return mouseLocked;
}
public static Vector3f getColour() {
@ -275,14 +221,6 @@ public class Window {
private static long getCurrentTime() {
return (long) (GLFW.glfwGetTime()*1000/GLFW.glfwGetTimerFrequency());
}
public static double getDY() {
return Window.dy;
}
public static double getDX() {
return Window.dx;
}
public static Vector2f getNormalizedMouseCoordinates() {
float normalX = -1.0f + 2.0f * (float) getMouseX() / width;

View File

@ -9,7 +9,7 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;
import io.github.hydos.ginger.engine.cameras.ThirdPersonCamera;
import io.github.hydos.ginger.engine.elements.buttons.GuiTexture;
import io.github.hydos.ginger.engine.elements.GuiTexture;
import io.github.hydos.ginger.engine.elements.objects.Entity;
import io.github.hydos.ginger.engine.elements.objects.Light;
import io.github.hydos.ginger.engine.io.Window;

View File

@ -7,7 +7,7 @@ import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30;
import io.github.hydos.ginger.engine.elements.buttons.GuiTexture;
import io.github.hydos.ginger.engine.elements.GuiTexture;
import io.github.hydos.ginger.engine.mathEngine.Maths;
import io.github.hydos.ginger.engine.mathEngine.matrixes.Matrix4f;
import io.github.hydos.ginger.engine.renderEngine.models.RawModel;

View File

@ -1,5 +1,7 @@
package io.github.hydos.ginger.main;
import io.github.hydos.ginger.UI.UIManager;
import io.github.hydos.ginger.UI.enums.UIColourType;
import io.github.hydos.ginger.engine.font.TextMaster;
import io.github.hydos.ginger.engine.obj.ModelLoader;
import io.github.hydos.ginger.engine.obj.normals.NormalMappedObjLoader;
@ -9,9 +11,11 @@ import io.github.hydos.ginger.engine.renderEngine.texture.ModelTexture;
public class GingerMain {
public static UIManager manager;
public static void init() {
TextMaster.init();
manager = new UIManager(UIColourType.dark);
}
public static TexturedModel createTexturedModel(String texturePath, String modelPath) {
@ -25,6 +29,10 @@ public class GingerMain {
return texturedModel;
}
public static void update() {
manager.update();
}