Compare commits
18 Commits
0dbb8bc642
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7fe522ffbe | |||
| 4cd1528343 | |||
| 31f57eddf7 | |||
| e9808fb47f | |||
| fa05feceb8 | |||
| 4b89548102 | |||
| 99d508c5ed | |||
| fb9e93d9cf | |||
| e64fc16d6a | |||
| 73db13dcc2 | |||
| ec5d5af43e | |||
| ccbc79d496 | |||
| 7ff93e58ea | |||
| e57149e9db | |||
| 796769c6a4 | |||
| daefc73de7 | |||
| d28dbc1083 | |||
| 7e5317fdc0 |
@@ -50,7 +50,11 @@ bool Application::Init() {
|
||||
|
||||
m_AppData.windowdata.eventCallback = [this](Event &event) { RaiseEvent(event); };
|
||||
m_Window.push_back(std::make_shared<Window>(m_AppData.windowdata));
|
||||
m_Window[0]->Create();
|
||||
bool isSuccessful = m_Window[0]->Create({m_AppData.windowdata.windowFlags});
|
||||
if (!isSuccessful) {
|
||||
Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Renderer = SDL_CreateRenderer(GetSDLWindow(), nullptr);
|
||||
if (!m_Renderer) {
|
||||
@@ -131,8 +135,11 @@ void Application::Run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Rendering
|
||||
if (!m_isRunning) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Rendering
|
||||
for (auto &layer : m_LayerStack) {
|
||||
layer->OnRender();
|
||||
}
|
||||
@@ -140,7 +147,7 @@ void Application::Run() {
|
||||
m_ImGui->Begin();
|
||||
|
||||
SDL_SetRenderScale(m_Renderer, io.DisplayFramebufferScale.x, io.DisplayFramebufferScale.y);
|
||||
SDL_SetRenderDrawColor(m_Renderer, (Uint8)111, (Uint8)232, (Uint8)168, (Uint8)0);
|
||||
SDL_SetRenderDrawColor(m_Renderer, (Uint8)111, (Uint8)232, (Uint8)168, (Uint8)255);
|
||||
SDL_RenderClear(m_Renderer);
|
||||
|
||||
for (auto &layer : m_LayerStack) {
|
||||
|
||||
@@ -37,6 +37,10 @@ public:
|
||||
void SubmitCommand(LayerCommand command);
|
||||
void ProcessCommands();
|
||||
|
||||
#ifdef DEBUG
|
||||
// this is only used for the tests for now, so it will be taken out of the release build
|
||||
inline const std::vector<std::unique_ptr<Layer>> &GetLayers() const { return m_LayerStack; }
|
||||
#endif
|
||||
private:
|
||||
std::vector<LayerCommand> m_CommandQueue;
|
||||
std::vector<std::unique_ptr<Layer>> m_LayerStack;
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
#include "Window.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "InputEvents.h"
|
||||
#include "Log.h"
|
||||
#include "SDL3/SDL_events.h"
|
||||
#include "SDL3/SDL_mouse.h"
|
||||
#include "SDL3/SDL_video.h"
|
||||
#include "WindowEvents.h"
|
||||
#include <span>
|
||||
|
||||
namespace SakuraVNE {
|
||||
Window::Window(const WindowData &data) : m_Data(data) {}
|
||||
Window::Window(const WindowData &data) : m_Data(data), m_Flags(0) {}
|
||||
Window::~Window() { Destroy(); }
|
||||
|
||||
void Window::Create() {
|
||||
// TODO: maybe get an unknow amount of parameters / an array of window flags? or just provide a seperate function for it
|
||||
SDL_WindowFlags windowFlags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
||||
m_Handle = SDL_CreateWindow(m_Data.title.c_str(), m_Data.width, m_Data.height, windowFlags);
|
||||
bool Window::Create(const SDL_WindowFlags flags) {
|
||||
m_Flags |= flags;
|
||||
|
||||
m_Handle = SDL_CreateWindow(m_Data.title.c_str(), m_Data.width, m_Data.height, m_Flags);
|
||||
|
||||
if (!m_Handle) {
|
||||
LOG_ERROR("SDL window could not be created! {0}", SDL_GetError());
|
||||
// FIX: there has to be a better way to shutdown this cannot be correct, because i just quit the sdl stuff but the init continues
|
||||
Application::Get().Shutdown();
|
||||
return;
|
||||
return false;
|
||||
} else {
|
||||
LOG_INFO("SDl window created");
|
||||
}
|
||||
@@ -35,6 +32,8 @@ void Window::Create() {
|
||||
} else {
|
||||
LOG_WARN("SDL window position not set. Will not attempt to set window position.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::ProcessEvent(const SDL_Event &event) {
|
||||
@@ -90,6 +89,106 @@ void Window::ProcessEvent(const SDL_Event &event) {
|
||||
}
|
||||
}
|
||||
|
||||
void Window::AddFlags(std::span<const SDL_WindowFlags> flags) {
|
||||
for (auto &flag : flags) {
|
||||
switch (flag) {
|
||||
case SDL_WINDOW_FULLSCREEN:
|
||||
SDL_SetWindowFullscreen(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_HIDDEN:
|
||||
SDL_ShowWindow(m_Handle);
|
||||
break;
|
||||
case SDL_WINDOW_BORDERLESS:
|
||||
SDL_SetWindowBordered(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_RESIZABLE:
|
||||
SDL_SetWindowResizable(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_MINIMIZED:
|
||||
SDL_MinimizeWindow(m_Handle);
|
||||
break;
|
||||
case SDL_WINDOW_MAXIMIZED:
|
||||
SDL_MaximizeWindow(m_Handle);
|
||||
break;
|
||||
case SDL_WINDOW_MOUSE_GRABBED:
|
||||
SDL_SetWindowMouseGrab(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_MOUSE_CAPTURE:
|
||||
SDL_SetWindowMouseGrab(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_MOUSE_RELATIVE_MODE:
|
||||
SDL_SetWindowRelativeMouseMode(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_MODAL:
|
||||
SDL_SetWindowModal(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_ALWAYS_ON_TOP:
|
||||
SDL_SetWindowAlwaysOnTop(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_KEYBOARD_GRABBED:
|
||||
SDL_SetWindowKeyboardGrab(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_NOT_FOCUSABLE:
|
||||
SDL_SetWindowFocusable(m_Handle, false);
|
||||
break;
|
||||
default:
|
||||
LOG_WARN("You can only use this when creating a window or the flag is readonly");
|
||||
break;
|
||||
}
|
||||
|
||||
m_Flags |= flag;
|
||||
}
|
||||
}
|
||||
|
||||
void Window::RemoveFlags(std::span<const SDL_WindowFlags> flags) {
|
||||
for (auto &flag : flags) {
|
||||
switch (flag) {
|
||||
case SDL_WINDOW_FULLSCREEN:
|
||||
SDL_SetWindowFullscreen(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_HIDDEN:
|
||||
SDL_HideWindow(m_Handle);
|
||||
break;
|
||||
case SDL_WINDOW_BORDERLESS:
|
||||
SDL_SetWindowBordered(m_Handle, true);
|
||||
break;
|
||||
case SDL_WINDOW_RESIZABLE:
|
||||
SDL_SetWindowResizable(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_MINIMIZED:
|
||||
case SDL_WINDOW_MAXIMIZED:
|
||||
SDL_RestoreWindow(m_Handle);
|
||||
break;
|
||||
case SDL_WINDOW_MOUSE_GRABBED:
|
||||
SDL_SetWindowMouseGrab(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_MOUSE_CAPTURE:
|
||||
SDL_SetWindowMouseGrab(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_MOUSE_RELATIVE_MODE:
|
||||
SDL_SetWindowRelativeMouseMode(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_MODAL:
|
||||
SDL_SetWindowModal(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_ALWAYS_ON_TOP:
|
||||
SDL_SetWindowAlwaysOnTop(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_KEYBOARD_GRABBED:
|
||||
SDL_SetWindowKeyboardGrab(m_Handle, false);
|
||||
break;
|
||||
case SDL_WINDOW_NOT_FOCUSABLE:
|
||||
SDL_SetWindowFocusable(m_Handle, true);
|
||||
break;
|
||||
default:
|
||||
LOG_WARN("You can only use this when creating a window or the flag is readonly");
|
||||
break;
|
||||
}
|
||||
|
||||
m_Flags &= flag;
|
||||
}
|
||||
}
|
||||
|
||||
void Window::Resize() {
|
||||
SDL_GetWindowSize(m_Handle, &m_Data.width, &m_Data.height);
|
||||
SDL_SetWindowSize(m_Handle, m_Data.width, m_Data.height);
|
||||
@@ -110,13 +209,13 @@ void Window::RaiseEvent(Event &event) {
|
||||
|
||||
// TODO: this need testing because i am really not sure this is correct
|
||||
// should this be static or go somewhere else | probably in application?
|
||||
auto Window::GetMousePos() const {
|
||||
auto Window::GetMousePos() {
|
||||
struct result {
|
||||
float *x;
|
||||
float *y;
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
SDL_GetMouseState(m_MouseXPos, m_MouseYPos);
|
||||
SDL_GetMouseState(&m_MouseXPos, &m_MouseYPos);
|
||||
|
||||
return result{m_MouseXPos, m_MouseYPos};
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Event.h"
|
||||
#include "SDL3/SDL_events.h"
|
||||
#include "SDL3/SDL_video.h"
|
||||
#include "imgui_impl_sdl3.h"
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
namespace SakuraVNE {
|
||||
struct WindowData {
|
||||
SDL_WindowFlags windowFlags = 0;
|
||||
std::string title = "Window Title";
|
||||
int width = 1280;
|
||||
int height = 720;
|
||||
@@ -26,25 +27,28 @@ public:
|
||||
Window(const WindowData &data = WindowData());
|
||||
~Window();
|
||||
|
||||
void Create();
|
||||
bool Create(const SDL_WindowFlags flags = 0);
|
||||
void Destroy();
|
||||
|
||||
void Update();
|
||||
void AddFlags(std::span<const SDL_WindowFlags> flags = {});
|
||||
void RemoveFlags(std::span<const SDL_WindowFlags> flags = {});
|
||||
void Resize();
|
||||
void ProcessEvent(const SDL_Event &event);
|
||||
|
||||
void RaiseEvent(Event &event);
|
||||
|
||||
bool ShouldClose() const;
|
||||
auto GetMousePos() const;
|
||||
auto GetMousePos();
|
||||
|
||||
SDL_Window *GetHandle() const { return m_Handle; }
|
||||
|
||||
private:
|
||||
WindowData m_Data;
|
||||
SDL_Window *m_Handle = nullptr;
|
||||
float *m_MouseXPos = nullptr;
|
||||
float *m_MouseYPos = nullptr;
|
||||
SDL_WindowFlags m_Flags;
|
||||
float m_MouseXPos;
|
||||
float m_MouseYPos;
|
||||
};
|
||||
|
||||
} // namespace SakuraVNE
|
||||
|
||||
Submodule libs/catch2 updated: f4e83daa18...be2dfb45cc
Submodule libs/imgui updated: 36fa3fbd20...75929b5e8a
Submodule libs/sdl3 updated: 4d17b99d0a...c2d0b59f29
Submodule libs/spdlog updated: 45b67eee66...75e93f4bdd
Reference in New Issue
Block a user