From 51f040589543dd876e9157367154f92b79cddae3 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Fri, 28 Jun 2024 18:06:04 +0200 Subject: [PATCH] Update Window interface --- .../graphics/opengl/OpenGlSubsystem.java | 2 +- .../graphics/opengl/classes/Window.java | 6 +-- .../GraphicsSubsystemConfiguration.java | 5 +- .../graphics/classes/ApiMainClass.java | 2 +- .../sosengine/graphics/classes/Window.java | 51 ++++++++++++++++--- .../events/GraphicsApiErrorEvent.java | 23 ++++++++- .../graphics/events/GraphicsErrorEvent.java | 23 ++++++++- .../sosengine/graphics/types/VsyncMode.java | 41 +++++++++++++++ .../sosengine/graphics/types/WindowMode.java | 51 +++++++++++++++++++ .../graphics/vulkan/VulkanSubsystem.java | 2 +- .../sosengine/testapp/Main.java | 4 +- 11 files changed, 189 insertions(+), 21 deletions(-) create mode 100644 graphics/src/main/java/de/staropensource/sosengine/graphics/types/VsyncMode.java create mode 100644 graphics/src/main/java/de/staropensource/sosengine/graphics/types/WindowMode.java diff --git a/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/OpenGlSubsystem.java b/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/OpenGlSubsystem.java index ce8355e0..205a6b84 100644 --- a/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/OpenGlSubsystem.java +++ b/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/OpenGlSubsystem.java @@ -22,9 +22,9 @@ package de.staropensource.sosengine.graphics.opengl; import de.staropensource.sosengine.base.annotations.EventListener; import de.staropensource.sosengine.base.classes.events.EventPriority; import de.staropensource.sosengine.base.classes.helpers.EventHelper; +import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; -import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.utility.Miscellaneous; import de.staropensource.sosengine.graphics.GraphicsSubsystem; import de.staropensource.sosengine.graphics.classes.ApiMainClass; diff --git a/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/classes/Window.java b/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/classes/Window.java index bcd49f64..835e9382 100644 --- a/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/classes/Window.java +++ b/graphics/opengl/src/main/java/de/staropensource/sosengine/graphics/opengl/classes/Window.java @@ -19,10 +19,10 @@ package de.staropensource.sosengine.graphics.opengl.classes; -import de.staropensource.sosengine.base.types.Vec2i; +import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; -import de.staropensource.sosengine.base.classes.logging.LogIssuer; +import de.staropensource.sosengine.base.types.Vec2i; import de.staropensource.sosengine.graphics.events.GraphicsApiErrorEvent; import lombok.Getter; import org.jetbrains.annotations.NotNull; @@ -31,8 +31,8 @@ import org.lwjgl.opengl.GL; import java.util.HashSet; import java.util.Set; -import static org.lwjgl.system.MemoryUtil.NULL; import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.system.MemoryUtil.NULL; /** * A window on your screen. diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java index 1a7c6067..b007e65d 100644 --- a/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/GraphicsSubsystemConfiguration.java @@ -20,10 +20,11 @@ package de.staropensource.sosengine.graphics; import de.staropensource.sosengine.base.classes.SubsystemConfiguration; +import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.logging.Logger; import de.staropensource.sosengine.base.types.CodePart; -import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.utility.PropertyParser; +import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -85,7 +86,7 @@ public final class GraphicsSubsystemConfiguration implements SubsystemConfigurat /** * If enabled, graphical errors thrown by GLFW will be printed to the log by the subsystem. * - * @see de.staropensource.sosengine.graphics.events.GraphicsErrorEvent + * @see GraphicsErrorEvent * @since 1-alpha0 * * -- GETTER -- diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/ApiMainClass.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/ApiMainClass.java index 9ad97706..d5d6c1bc 100644 --- a/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/ApiMainClass.java +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/ApiMainClass.java @@ -21,8 +21,8 @@ package de.staropensource.sosengine.graphics.classes; import de.staropensource.sosengine.base.Engine; import de.staropensource.sosengine.base.annotations.EventListener; -import de.staropensource.sosengine.base.classes.events.EventPriority; import de.staropensource.sosengine.base.classes.SubsystemMainClass; +import de.staropensource.sosengine.base.classes.events.EventPriority; import de.staropensource.sosengine.base.events.internal.InternalEngineShutdownEvent; import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent; import org.jetbrains.annotations.NotNull; diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/Window.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/Window.java index fceda4e1..66ba42ea 100644 --- a/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/Window.java +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/classes/Window.java @@ -20,13 +20,14 @@ package de.staropensource.sosengine.graphics.classes; import de.staropensource.sosengine.base.types.Vec2i; +import de.staropensource.sosengine.graphics.types.WindowMode; import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; /** - * A window on your screen. + * Interface for implementing windows. * * @since 1-alpha0 */ @@ -41,18 +42,54 @@ public interface Window { Set windows = new HashSet<>(); /** - * The window name. + * Contains the window identifier. * - * @since 1-alpha0 + * @since 1-alpha1 */ @NotNull - String windowName = "Hello Window!"; + String identifier = ""; /** - * The window size. + * Determines the title of this window. * - * @since 1-alpha0 + * @since 1-alpha1 */ @NotNull - Vec2i windowSize = new Vec2i(0, 0); + String title = "sos!engine window (update this title)"; + + /** + * Determines the size of this window. + * + * @since 1-alpha1 + */ + @NotNull + Vec2i size = new Vec2i(200, 200); + + /** + * Determines in which {@link WindowMode} this window is in. + * + * @since 1-alpha1 + */ + WindowMode mode = WindowMode.WINDOWED; + + /** + * Determines if this window should have a border and decorations. + * + * @since 1-alpha1 + */ + boolean borderless = false; + + /** + * Determines if this window should be displayed on top of all other windows. + * + * @since 1-alpha1 + */ + boolean onTop = false; + + /** + * Determines if this window can be resized by the user. + * + * @since 1-alpha1 + */ + boolean resizable = false; } diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsApiErrorEvent.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsApiErrorEvent.java index 80f02c56..18b1d9eb 100644 --- a/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsApiErrorEvent.java +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsApiErrorEvent.java @@ -1,10 +1,29 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.staropensource.sosengine.graphics.events; import de.staropensource.sosengine.base.classes.events.Event; -import de.staropensource.sosengine.base.events.LogEvent; +import de.staropensource.sosengine.base.classes.helpers.EventHelper; import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.classes.logging.LogLevel; -import de.staropensource.sosengine.base.classes.helpers.EventHelper; +import de.staropensource.sosengine.base.events.LogEvent; import org.jetbrains.annotations.NotNull; import java.lang.reflect.InvocationTargetException; diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsErrorEvent.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsErrorEvent.java index 9c60889a..e2614a11 100644 --- a/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsErrorEvent.java +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/events/GraphicsErrorEvent.java @@ -1,10 +1,29 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + package de.staropensource.sosengine.graphics.events; import de.staropensource.sosengine.base.classes.events.Event; -import de.staropensource.sosengine.base.events.LogEvent; +import de.staropensource.sosengine.base.classes.helpers.EventHelper; import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.classes.logging.LogLevel; -import de.staropensource.sosengine.base.classes.helpers.EventHelper; +import de.staropensource.sosengine.base.events.LogEvent; import org.jetbrains.annotations.NotNull; import java.lang.reflect.InvocationTargetException; diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/types/VsyncMode.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/VsyncMode.java new file mode 100644 index 00000000..f90befbc --- /dev/null +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/VsyncMode.java @@ -0,0 +1,41 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.sosengine.graphics.types; + +/** + * Used for determining if and how a window's frame rate should be synchronized to the monitor's refresh rate. + */ +@SuppressWarnings({ "unused" }) +public enum VsyncMode { + /** + * Disables VSync. The frame rate can be uncapped and will allow for processing an unlimited amount of frames. + */ + OFF, + + /** + * Enables VSync and will cap the window's frame rate at the refresh rate of the target monitor. + */ + ON, + + /** + * This mode will disables VSync if the window's frame rate drops below the monitor's refresh rate and enable it otherwise. + */ + ADAPTIVE +} diff --git a/graphics/src/main/java/de/staropensource/sosengine/graphics/types/WindowMode.java b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/WindowMode.java new file mode 100644 index 00000000..66e12f24 --- /dev/null +++ b/graphics/src/main/java/de/staropensource/sosengine/graphics/types/WindowMode.java @@ -0,0 +1,51 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * Licensed under the GNU Affero General Public License v3 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.staropensource.sosengine.graphics.types; + +/** + * Determines how a window should be displayed. + * + * @since 1-alpha1 + */ +@SuppressWarnings({ "unused" }) +public enum WindowMode { + /** + * Makes the window able to be dragged around. + * + * @since 1-alpha1 + */ + WINDOWED, + + /** + * Same as {@code WINDOWED} mode, but the window will have + * the same size as the monitor it is currently on. + * + * @since 1-alpha1 + */ + BORDERLESS_FULLSCREEN, + + /** + * Makes the window occupy the entire monitor it is currently on + * without allowing other windows to occupy the same space. + * + * @since 1-alpha1 + */ + EXCLUSIVE_FULLSCREEN +} diff --git a/graphics/vulkan/src/main/java/de/staropensource/sosengine/graphics/vulkan/VulkanSubsystem.java b/graphics/vulkan/src/main/java/de/staropensource/sosengine/graphics/vulkan/VulkanSubsystem.java index 99215872..43d5657a 100644 --- a/graphics/vulkan/src/main/java/de/staropensource/sosengine/graphics/vulkan/VulkanSubsystem.java +++ b/graphics/vulkan/src/main/java/de/staropensource/sosengine/graphics/vulkan/VulkanSubsystem.java @@ -21,9 +21,9 @@ package de.staropensource.sosengine.graphics.vulkan; import de.staropensource.sosengine.base.annotations.EventListener; import de.staropensource.sosengine.base.classes.events.EventPriority; +import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; -import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.utility.Miscellaneous; import de.staropensource.sosengine.graphics.GraphicsSubsystem; import de.staropensource.sosengine.graphics.classes.ApiMainClass; diff --git a/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java b/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java index 1ffe7ce2..8743bd2d 100644 --- a/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java +++ b/testapp/src/main/java/de/staropensource/sosengine/testapp/Main.java @@ -20,10 +20,10 @@ package de.staropensource.sosengine.testapp; import de.staropensource.sosengine.base.Engine; -import de.staropensource.sosengine.base.types.Vec2i; +import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; -import de.staropensource.sosengine.base.classes.logging.LogIssuer; +import de.staropensource.sosengine.base.types.Vec2i; import de.staropensource.sosengine.graphics.GraphicsSubsystem; import de.staropensource.sosengine.graphics.classes.ApiMainClass; import de.staropensource.sosengine.graphics.classes.ApiManagementClass;