Migrated SDL2 to SDL3

This commit is contained in:
OmniaX-Dev 2026-03-31 02:31:51 +02:00
parent 6f1899b1a6
commit 2bec8e1b39
28 changed files with 11539 additions and 113 deletions

View file

@ -79,6 +79,12 @@ list(APPEND OSTD_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/src/ostd/utils/Time.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ostd/utils/Time.cpp
) )
list(APPEND OGFX_SOURCE_FILES list(APPEND OGFX_SOURCE_FILES
# sdl3_gfx
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_framerate.c
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.c
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_imageFilter.c
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_rotozoom.c
# gui # gui
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/WindowBase.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/WindowBase.cpp
@ -131,7 +137,7 @@ endif()
if (WIN32) if (WIN32)
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC mingw32) target_link_libraries(${OMNIA_GFX_LIB} PUBLIC mingw32)
target_link_libraries(${OMNIA_STD_LIB} PUBLIC mingw32) target_link_libraries(${OMNIA_STD_LIB} PUBLIC mingw32)
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC SDL2main SDL2 SDL2_gfx SDL2_ttf SDL2_image) target_link_libraries(${OMNIA_GFX_LIB} PUBLIC SDL3 SDL3_ttf SDL3_image)
endif (WIN32) endif (WIN32)
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC ${OMNIA_STD_LIB}) target_link_libraries(${OMNIA_GFX_LIB} PUBLIC ${OMNIA_STD_LIB})
@ -169,6 +175,6 @@ elseif (UNIX)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN',-rpath,/usr/lib,-rpath,/usr/local/lib") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,'$ORIGIN',-rpath,/usr/lib,-rpath,/usr/local/lib")
target_link_libraries(${OMNIA_STD_LIB} PUBLIC tinfo boost_regex) target_link_libraries(${OMNIA_STD_LIB} PUBLIC tinfo boost_regex)
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC xcb xcb-randr) target_link_libraries(${OMNIA_GFX_LIB} PUBLIC xcb xcb-randr)
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC SDL2main SDL2 SDL2_gfx SDL2_ttf SDL2_image) target_link_libraries(${OMNIA_GFX_LIB} PUBLIC SDL3 SDL3_ttf SDL3_image)
endif () endif ()
#----------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------

View file

@ -22,7 +22,7 @@ Once you have the **MSYS2 UCRT64 terminal** open, run theese two commands to pre
```bash ```bash
pacman -Syuu pacman -Syuu
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-clang mingw-w64-ucrt-x86_64-gdb mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-boost mingw-w64-ucrt-x86_64-SDL2 mingw-w64-ucrt-x86_64-SDL2_mixer mingw-w64-ucrt-x86_64-SDL2_image mingw-w64-ucrt-x86_64-SDL2_ttf mingw-w64-ucrt-x86_64-SDL2_gfx pacman -S --needed base-devel mingw-w64-ucrt-x86_64-clang mingw-w64-ucrt-x86_64-gdb mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-boost mingw-w64-ucrt-x86_64-SDL3 mingw-w64-ucrt-x86_64-SDL3_mixer mingw-w64-ucrt-x86_64-SDL3_image mingw-w64-ucrt-x86_64-SDL3_ttf
``` ```
#### Step 3: build OmniaFramework #### Step 3: build OmniaFramework
@ -86,21 +86,21 @@ Installs the library MSYS2's UCRT64 profile.
- **<u>Arch Linux</u>** - **<u>Arch Linux</u>**
```bash ```bash
sudo pacman -S --needed base-devel clang gdb cmake make boost sdl2 sdl2_mixer sdl2_image sdl2_ttf sdl2_gfx sudo pacman -S --needed base-devel clang gdb cmake make boost sdl3 sdl3_mixer sdl3_image sdl3_ttf
``` ```
- **<u>Ubuntu</u>** - **<u>Ubuntu</u>**
```bash ```bash
sudo apt update && sudo apt upgrade sudo apt update && sudo apt upgrade
sudo apt install build-essential dkms linux-headers-$(uname -r) clang gdb make cmake libssl-dev libboost-all-dev libsdl2-dev libsdl2-mixer-dev libsdl2-image-dev libsdl2-ttf-dev libsdl2-gfx-dev libxcb-randr0-dev sudo apt install build-essential dkms linux-headers-$(uname -r) clang gdb make cmake libssl-dev libboost-all-dev libsdl3-dev libsdl3-mixer-dev libsdl3-image-dev libsdl3-ttf-dev libxcb-randr0-dev
``` ```
- **<u>Fedora</u>** - **<u>Fedora</u>**
```bash ```bash
sudo dnf update sudo dnf update
sudo dnf install gcc gcc-c++ make clang gdb cmake clang-tools-extra boost boost-devel SDL2 SDL2_image SDL2_mixer SDL2_ttf SDL2_gfx SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel SDL2_gfx-devel sudo dnf install gcc gcc-c++ make clang gdb cmake clang-tools-extra boost boost-devel SDL3 SDL3_image SDL3_mixer SDL3_ttf SDL3-devel SDL3_image-devel SDL3_mixer-devel SDL3_ttf-devel
``` ```
> **NOTE**: For other Linux distros, you need to install the same dependencies through your package manager. > **NOTE**: For other Linux distros, you need to install the same dependencies through your package manager.
@ -145,7 +145,7 @@ eval "$(/usr/local/bin/brew shellenv)"
##### Step 3: Install dependencies ##### Step 3: Install dependencies
```bash ```bash
brew install git llvm gdb cmake make boost sdl2 sdl2_mixer sdl2_image sdl2_ttf sdl2_gfx pkg-config brew install git llvm gdb cmake make boost sdl3 sdl3_mixer sdl3_image sdl3_ttf pkg-config
``` ```
##### Step 4: Build OmniaFramework ##### Step 4: Build OmniaFramework

View file

@ -0,0 +1,25 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.3.2, February 17th, 2026
Copyright (C) 1995-2026 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
*/

View file

@ -1 +1 @@
2034 2038

View file

@ -34,18 +34,16 @@ elif [[ "$(uname -s)" == MINGW64_NT* ]]; then
cp $MSYS_ROOT/ucrt64/bin/SDL2_ttf.dll $RELEASE_DIR/lib cp $MSYS_ROOT/ucrt64/bin/SDL2_ttf.dll $RELEASE_DIR/lib
cp $MSYS_ROOT/ucrt64/bin/libSDL2_gfx-1-0-0.dll $RELEASE_DIR/lib cp $MSYS_ROOT/ucrt64/bin/libSDL2_gfx-1-0-0.dll $RELEASE_DIR/lib
fi fi
cp -r ../licences $RELEASE_DIR
cp ../LICENSE $RELEASE_DIR/licences/OmniaFramework-LICENCE.txt
mkdir -p $RELEASE_DIR/include/ostd/vendor # OSTD
mkdir -p $RELEASE_DIR/include/ostd/vendor/midifile mkdir -p $RELEASE_DIR/include/ostd/vendor/midifile
mkdir -p $RELEASE_DIR/include/ostd/data mkdir -p $RELEASE_DIR/include/ostd/data
mkdir -p $RELEASE_DIR/include/ostd/io mkdir -p $RELEASE_DIR/include/ostd/io
mkdir -p $RELEASE_DIR/include/ostd/math mkdir -p $RELEASE_DIR/include/ostd/math
mkdir -p $RELEASE_DIR/include/ostd/string mkdir -p $RELEASE_DIR/include/ostd/string
mkdir -p $RELEASE_DIR/include/ostd/utils mkdir -p $RELEASE_DIR/include/ostd/utils
mkdir -p $RELEASE_DIR/include/ogfx/gui
mkdir -p $RELEASE_DIR/include/ogfx/render
mkdir -p $RELEASE_DIR/include/ogfx/resources
mkdir -p $RELEASE_DIR/include/ogfx/utils
find ../src/ostd -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd \; find ../src/ostd -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd \;
find ../src/ostd/data -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/data \; find ../src/ostd/data -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/data \;
find ../src/ostd/io -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/io \; find ../src/ostd/io -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/io \;
@ -54,11 +52,19 @@ find ../src/ostd/string -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/inclu
find ../src/ostd/utils -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/utils \; find ../src/ostd/utils -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/utils \;
find ../src/ostd/vendor -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/vendor \; find ../src/ostd/vendor -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/vendor \;
find ../src/ostd/vendor/midifile -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/vendor/midifile \; find ../src/ostd/vendor/midifile -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/vendor/midifile \;
cp -r ../src/ostd/vendor/nlohmann $RELEASE_DIR/include/ostd/vendor/
# OGFX
mkdir -p $RELEASE_DIR/include/ogfx/vendor/sdl3_gfx
mkdir -p $RELEASE_DIR/include/ogfx/gui
mkdir -p $RELEASE_DIR/include/ogfx/render
mkdir -p $RELEASE_DIR/include/ogfx/resources
mkdir -p $RELEASE_DIR/include/ogfx/utils
find ../src/ogfx -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx \; find ../src/ogfx -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx \;
find ../src/ogfx/gui -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/gui \; find ../src/ogfx/gui -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/gui \;
find ../src/ogfx/render -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/render \; find ../src/ogfx/render -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/render \;
find ../src/ogfx/resources -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/resources \; find ../src/ogfx/resources -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/resources \;
find ../src/ogfx/utils -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/utils \; find ../src/ogfx/utils -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/utils \;
cp -r ../src/ostd/vendor/nlohmann $RELEASE_DIR/include/ostd/vendor/ find ../src/ogfx/vendor -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/vendor \;
cp -r ../licences $RELEASE_DIR find ../src/ogfx/vendor/sdl3_gfx -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/vendor/sdl3_gfx \;
cp ../LICENSE $RELEASE_DIR/licences/OmniaFramework-LICENCE.txt

211
src/ogfx/gui/GuiWindow.cpp Normal file
View file

@ -0,0 +1,211 @@
/*
OmniaFramework - A collection of useful functionality
Copyright (C) 2025 OmniaX-Dev
This file is part of OmniaFramework.
OmniaFramework is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OmniaFramework 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
#include "GuiWindow.hpp"
namespace ogfx
{
namespace gui
{
Window::~Window(void)
{
onDestroy();
SDL_DestroyCursor(m_cursor_IBeam);
SDL_DestroyCursor(m_cursor_Arrow);
SDL_DestroyRenderer(m_renderer);
SDL_DestroyWindow(m_window);
SDL_Quit();
TTF_Quit();
}
void Window::initialize(int32_t width, int32_t height, const ostd::String& windowTitle)
{
if (m_initialized) return;
m_windowWidth = width;
m_windowHeight = height;
m_title = windowTitle;
if (!SDL_Init(SDL_INIT_VIDEO))
{
printf( "SDL could not initialize! Error: %s\n", SDL_GetError() );
exit(ErrorCodes::SDLInitFailed);
}
m_window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE);
setSize(m_windowWidth, m_windowHeight);
m_renderer = SDL_CreateRenderer(m_window, nullptr);
SDL_SetWindowMinimumSize(m_window, m_windowWidth, m_windowHeight);
SDL_SetWindowTitle(m_window, m_title.c_str());
SDL_StartTextInput(m_window);
m_cursor_Arrow = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_DEFAULT);
m_cursor_IBeam = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_TEXT);
m_initialized = true;
m_running = true;
setTypeName("ogfx::gui::Window");
enableSignals(true);
validate();
onInitialize();
}
void Window::close(void)
{
m_running = false;
onClose();
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::RealTime, *this);
}
int32_t Window::startMainLoop(void)
{
if (!m_initialized) return ErrorCodes::Uninitialized;
while (m_running)
{
__handle_events();
SDL_SetRenderDrawColor(m_renderer, m_clearColor.r, m_clearColor.g, m_clearColor.b, m_clearColor.a);
SDL_RenderClear(m_renderer);
SDL_RenderPresent(m_renderer);
}
return ErrorCodes::ExitSuccess;
}
void Window::setSize(int32_t width, int32_t height)
{
if (!isInitialized()) return;
SDL_SetWindowSize(m_window, width, height);
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime);
}
void Window::setTitle(const ostd::String& title)
{
if (!isInitialized()) return;
m_title = title;
SDL_SetWindowTitle(m_window, m_title.c_str());
}
void Window::setCursor(eCursor cursor)
{
switch (cursor)
{
case eCursor::Arrow:
SDL_SetCursor(m_cursor_Arrow);
break;
case eCursor::IBeam:
SDL_SetCursor(m_cursor_IBeam);
break;
default:
SDL_SetCursor(m_cursor_Arrow);
break;
}
}
void Window::enableResizable(bool enable)
{
SDL_SetWindowResizable(m_window, enable);
m_resizeable = enable;
}
void Window::setIcon(const ostd::String& iconFilePath)
{
SDL_Surface* appIcon = IMG_Load(iconFilePath);
if (appIcon == nullptr)
{
//TODO: Error
return;
}
SDL_SetWindowIcon(m_window, appIcon);
SDL_DestroySurface(appIcon);
}
void Window::__handle_events(void)
{
if (!m_initialized) return;
auto l_getMouseState = [this](void) -> MouseEventData {
float mx = 0, my = 0;
uint32_t btn = SDL_GetMouseState(&mx, &my);
MouseEventData::eButton button = MouseEventData::eButton::None;
switch (btn)
{
case SDL_BUTTON_MASK(1): button = MouseEventData::eButton::Left; break;
case SDL_BUTTON_MASK(2): button = MouseEventData::eButton::Middle; break;
case SDL_BUTTON_MASK(3): button = MouseEventData::eButton::Right; break;
default: button = MouseEventData::eButton::None; break;
}
MouseEventData mmd(*this, mx, my, button);
return mmd;
};
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_EVENT_QUIT)
{
m_running = false;
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this);
}
else if (event.type == SDL_EVENT_WINDOW_RESIZED)
{
WindowResizedData wrd(*this, m_windowWidth, m_windowHeight, 0, 0);
SDL_GetWindowSize(m_window, &m_windowWidth, &m_windowHeight);
wrd.new_width = m_windowWidth;
wrd.new_height = m_windowHeight;
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime, wrd);
}
else if (event.type == SDL_EVENT_MOUSE_MOTION)
{
MouseEventData mmd = l_getMouseState();
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd);
}
else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
{
MouseEventData mmd = l_getMouseState();
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd);
}
else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP)
{
MouseEventData mmd = l_getMouseState();
switch (event.button.button)
{
case SDL_BUTTON_MASK(1): mmd.button = MouseEventData::eButton::Left; break;
case SDL_BUTTON_MASK(2): mmd.button = MouseEventData::eButton::Middle; break;
case SDL_BUTTON_MASK(3): mmd.button = MouseEventData::eButton::Right; break;
default: mmd.button = MouseEventData::eButton::None; break;
}
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseReleased, ostd::tSignalPriority::RealTime, mmd);
}
else if (event.type == SDL_EVENT_KEY_DOWN)
{
KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Pressed);
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyPressed, ostd::tSignalPriority::RealTime, ked);
}
else if (event.type == SDL_EVENT_KEY_UP)
{
KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Released);
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyReleased, ostd::tSignalPriority::RealTime, ked);
}
else if (event.type == SDL_EVENT_TEXT_INPUT)
{
KeyEventData ked(*this, 0, event.text.text[0], KeyEventData::eKeyEvent::Text);
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::TextEntered, ostd::tSignalPriority::RealTime, ked);
}
}
}
}
}

141
src/ogfx/gui/GuiWindow.hpp Normal file
View file

@ -0,0 +1,141 @@
/*
OmniaFramework - A collection of useful functionality
Copyright (C) 2025 OmniaX-Dev
This file is part of OmniaFramework.
OmniaFramework is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OmniaFramework 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <ogfx/utils/SDLInclude.hpp>
#include <ostd/utils/Signals.hpp>
#include <ostd/utils/Time.hpp>
#include <ostd/io/IOHandlers.hpp>
namespace ogfx
{
namespace gui
{
class Window : public ostd::BaseObject
{
public: enum class eCursor { Arrow = 0, IBeam };
public: struct ErrorCodes {
inline static constexpr uint16_t ExitSuccess { 0 };
inline static constexpr uint16_t SDLInitFailed { 1 };
inline static constexpr uint16_t SDLImageInitFailed { 2 };
inline static constexpr uint16_t Uninitialized { 3 };
};
public:
inline Window(void) { }
~Window(void);
inline Window(int32_t width, int32_t height, const ostd::String& windowTitle) { initialize(width, height, windowTitle); }
void initialize(int32_t width, int32_t height, const ostd::String& windowTitle);
void close(void);
int32_t startMainLoop(void);
void setSize(int32_t width, int32_t height);
void setTitle(const ostd::String& title);
void setCursor(eCursor cursor);
void enableResizable(bool enable = true);
void setIcon(const ostd::String& iconFilePath);
inline virtual void onInitialize(void) { }
inline virtual void onDestroy(void) { }
inline virtual void onClose(void) { }
inline bool isInitialized(void) const { return m_initialized; }
inline bool isRunning(void) const { return m_running; }
inline bool isVisible(void) const { return m_visible; }
inline bool isResizeable(void) const { return m_resizeable; }
inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; }
inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; }
inline ostd::String getTitle(void) const { return m_title; }
inline int32_t getWindowWidth(void) const { return m_windowWidth; }
inline int32_t getWindowHeight(void) const { return m_windowHeight; }
inline ostd::Color getClearColor(void) const { return m_clearColor; }
inline void setClearColor(const ostd::Color& color) { m_clearColor = color; }
inline SDL_Renderer* getSDLRenderer(void) const { return m_renderer; }
private:
void __handle_events(void);
protected:
SDL_Window* m_window { nullptr };
SDL_Renderer* m_renderer { nullptr };
private:
ostd::Color m_clearColor { 10, 10, 10, 255 };
int32_t m_windowWidth { 0 };
int32_t m_windowHeight { 0 };
ostd::String m_title { "" };
bool m_running { false };
bool m_initialized { false };
bool m_visible { true };
bool m_resizeable { true };
SDL_Cursor* m_cursor_IBeam { nullptr };
SDL_Cursor* m_cursor_Arrow { nullptr };
};
class WindowResizedData : public ostd::BaseObject
{
public:
inline WindowResizedData(Window& parent, int32_t _oldx, int32_t _oldy, int32_t _newx, int32_t _newy) : parentWindow(parent), old_width(_oldx), old_height(_oldy), new_width(_newx), new_height(_newy)
{
setTypeName("ogfx::gui::WindowResizedData");
validate();
}
public:
int32_t new_width;
int32_t new_height;
int32_t old_width;
int32_t old_height;
Window& parentWindow;
};
class MouseEventData : public ostd::BaseObject
{
public: enum class eButton { None = 0, Left, Middle, Right };
public:
inline MouseEventData(Window& parent, int32_t mousex, int32_t mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn)
{
setTypeName("ogfx::gui::MouseEventData");
validate();
}
public:
int32_t position_x;
int32_t position_y;
eButton button;
Window& parentWindow;
};
class KeyEventData : public ostd::BaseObject
{
public: enum class eKeyEvent { Pressed = 0, Released, Text };
public:
inline KeyEventData(Window& parent, int32_t key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt)
{
setTypeName("ogfx::gui::KeyEventData");
validate();
}
public:
int32_t keyCode;
char text;
eKeyEvent eventType;
Window& parentWindow;
};
}
}

View file

@ -20,17 +20,19 @@
#include "WindowBase.hpp" #include "WindowBase.hpp"
#include "../../ostd/utils/Time.hpp" #include "../../ostd/utils/Time.hpp"
#include <SDL2/SDL_render.h>
#include <SDL3/SDL_events.h>
#include <SDL3/SDL_mouse.h>
namespace ogfx namespace ogfx
{ {
WindowBase::~WindowBase(void) WindowBase::~WindowBase(void)
{ {
onDestroy(); onDestroy();
SDL_FreeCursor(m_cursor_IBeam); SDL_DestroyCursor(m_cursor_IBeam);
SDL_FreeCursor(m_cursor_Arrow); SDL_DestroyCursor(m_cursor_Arrow);
SDL_DestroyRenderer(m_renderer); SDL_DestroyRenderer(m_renderer);
SDL_DestroyWindow(m_window); SDL_DestroyWindow(m_window);
IMG_Quit();
SDL_Quit(); SDL_Quit();
TTF_Quit(); TTF_Quit();
} }
@ -41,25 +43,20 @@ namespace ogfx
m_windowWidth = width; m_windowWidth = width;
m_windowHeight = height; m_windowHeight = height;
m_title = windowTitle; m_title = windowTitle;
if (SDL_Init(SDL_INIT_VIDEO) != 0) if (!SDL_Init(SDL_INIT_VIDEO))
{ {
printf( "SDL could not initialize! Error: %s\n", SDL_GetError() ); printf( "SDL could not initialize! Error: %s\n", SDL_GetError() );
exit(1); exit(1);
} }
int imgFlags = IMG_INIT_PNG; m_window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE);
if (!(IMG_Init(imgFlags) & imgFlags)) SDL_SetWindowResizable(m_window, false);
{ m_renderer = SDL_CreateRenderer(m_window, nullptr);
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
exit(2);
}
m_window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_windowWidth, m_windowHeight, SDL_WINDOW_RESIZABLE);
SDL_SetWindowResizable(m_window, SDL_FALSE);
m_renderer = SDL_CreateRenderer(m_window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetWindowMinimumSize(m_window, m_windowWidth, m_windowHeight); SDL_SetWindowMinimumSize(m_window, m_windowWidth, m_windowHeight);
SDL_SetWindowTitle(m_window, m_title.c_str()); SDL_SetWindowTitle(m_window, m_title.c_str());
SDL_StartTextInput(m_window);
m_cursor_Arrow = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_ARROW); m_cursor_Arrow = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_DEFAULT);
m_cursor_IBeam = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_IBEAM); m_cursor_IBeam = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_TEXT);
m_initialized = true; m_initialized = true;
m_running = true; m_running = true;
@ -76,9 +73,10 @@ namespace ogfx
this->m_frameCount = 0; this->m_frameCount = 0;
}); });
setTypeName("dragon::WindowBase"); setTypeName("ogfx::WindowBase");
enableSignals(true); enableSignals(true);
validate(); validate();
setSize(m_windowWidth, m_windowHeight);
onInitialize(); onInitialize();
} }
@ -138,7 +136,7 @@ namespace ogfx
void WindowBase::enableResizable(bool enable) void WindowBase::enableResizable(bool enable)
{ {
SDL_SetWindowResizable(m_window, (enable ? SDL_TRUE : SDL_FALSE)); SDL_SetWindowResizable(m_window, enable);
} }
void WindowBase::setIcon(const ostd::String& iconFilePath) void WindowBase::setIcon(const ostd::String& iconFilePath)
@ -150,21 +148,21 @@ namespace ogfx
return; return;
} }
SDL_SetWindowIcon(m_window, appIcon); SDL_SetWindowIcon(m_window, appIcon);
SDL_FreeSurface(appIcon); SDL_DestroySurface(appIcon);
} }
void WindowBase::__handle_events(void) void WindowBase::__handle_events(void)
{ {
if (!m_initialized) return; if (!m_initialized) return;
auto l_getMouseState = [this](void) -> MouseEventData { auto l_getMouseState = [this](void) -> MouseEventData {
int32_t mx = 0, my = 0; float mx = 0, my = 0;
uint32_t btn = SDL_GetMouseState(&mx, &my); uint32_t btn = SDL_GetMouseState(&mx, &my);
MouseEventData::eButton button = MouseEventData::eButton::None; MouseEventData::eButton button = MouseEventData::eButton::None;
switch (btn) switch (btn)
{ {
case SDL_BUTTON(1): button = MouseEventData::eButton::Left; break; case SDL_BUTTON_MASK(1): button = MouseEventData::eButton::Left; break;
case SDL_BUTTON(2): button = MouseEventData::eButton::Middle; break; case SDL_BUTTON_MASK(2): button = MouseEventData::eButton::Middle; break;
case SDL_BUTTON(3): button = MouseEventData::eButton::Right; break; case SDL_BUTTON_MASK(3): button = MouseEventData::eButton::Right; break;
default: button = MouseEventData::eButton::None; break; default: button = MouseEventData::eButton::None; break;
} }
MouseEventData mmd(*this, mx, my, button); MouseEventData mmd(*this, mx, my, button);
@ -173,22 +171,20 @@ namespace ogfx
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
if (event.type == SDL_QUIT) if (event.type == SDL_EVENT_QUIT)
{ {
m_running = false; m_running = false;
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this);
} }
else if (event.type == SDL_WINDOWEVENT) else if (event.type == SDL_EVENT_WINDOW_RESIZED)
{ {
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
WindowResizedData wrd(*this, m_windowWidth, m_windowHeight, 0, 0); WindowResizedData wrd(*this, m_windowWidth, m_windowHeight, 0, 0);
SDL_GetWindowSize(m_window, &m_windowWidth, &m_windowHeight); SDL_GetWindowSize(m_window, &m_windowWidth, &m_windowHeight);
wrd.new_width = m_windowWidth; wrd.new_width = m_windowWidth;
wrd.new_height = m_windowHeight; wrd.new_height = m_windowHeight;
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime, wrd); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowResized, ostd::tSignalPriority::RealTime, wrd);
} }
} else if (event.type == SDL_EVENT_MOUSE_MOTION)
else if (event.type == SDL_MOUSEMOTION)
{ {
MouseEventData mmd = l_getMouseState(); MouseEventData mmd = l_getMouseState();
if (isMouseDragEventEnabled() && mmd.button != MouseEventData::eButton::None) if (isMouseDragEventEnabled() && mmd.button != MouseEventData::eButton::None)
@ -196,34 +192,34 @@ namespace ogfx
else else
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd);
} }
else if (event.type == SDL_MOUSEBUTTONDOWN) else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
{ {
MouseEventData mmd = l_getMouseState(); MouseEventData mmd = l_getMouseState();
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd);
} }
else if (event.type == SDL_MOUSEBUTTONUP) else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP)
{ {
MouseEventData mmd = l_getMouseState(); MouseEventData mmd = l_getMouseState();
switch (event.button.button) switch (event.button.button)
{ {
case SDL_BUTTON(1): mmd.button = MouseEventData::eButton::Left; break; case SDL_BUTTON_MASK(1): mmd.button = MouseEventData::eButton::Left; break;
case SDL_BUTTON(2): mmd.button = MouseEventData::eButton::Middle; break; case SDL_BUTTON_MASK(2): mmd.button = MouseEventData::eButton::Middle; break;
case SDL_BUTTON(3): mmd.button = MouseEventData::eButton::Right; break; case SDL_BUTTON_MASK(3): mmd.button = MouseEventData::eButton::Right; break;
default: mmd.button = MouseEventData::eButton::None; break; default: mmd.button = MouseEventData::eButton::None; break;
} }
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseReleased, ostd::tSignalPriority::RealTime, mmd); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseReleased, ostd::tSignalPriority::RealTime, mmd);
} }
else if (event.type == SDL_KEYDOWN) else if (event.type == SDL_EVENT_KEY_DOWN)
{ {
KeyEventData ked(*this, (int32_t)event.key.keysym.sym, 0, KeyEventData::eKeyEvent::Pressed); KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Pressed);
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyPressed, ostd::tSignalPriority::RealTime, ked); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyPressed, ostd::tSignalPriority::RealTime, ked);
} }
else if (event.type == SDL_KEYUP) else if (event.type == SDL_EVENT_KEY_UP)
{ {
KeyEventData ked(*this, (int32_t)event.key.keysym.sym, 0, KeyEventData::eKeyEvent::Released); KeyEventData ked(*this, (int32_t)event.key.key, 0, KeyEventData::eKeyEvent::Released);
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyReleased, ostd::tSignalPriority::RealTime, ked); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyReleased, ostd::tSignalPriority::RealTime, ked);
} }
else if (event.type == SDL_TEXTINPUT) else if (event.type == SDL_EVENT_TEXT_INPUT)
{ {
KeyEventData ked(*this, 0, event.text.text[0], KeyEventData::eKeyEvent::Text); KeyEventData ked(*this, 0, event.text.text[0], KeyEventData::eKeyEvent::Text);
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::TextEntered, ostd::tSignalPriority::RealTime, ked); ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::TextEntered, ostd::tSignalPriority::RealTime, ked);

View file

@ -27,6 +27,61 @@
namespace ogfx namespace ogfx
{ {
// class WindowCore : public ostd::BaseObject
// {
// public: enum class eCursor { Arrow = 0, IBeam };
// public:
// inline WindowCore(void) { }
// virtual ~WindowCore(void);
// inline WindowCore(int32_t width, int32_t height, const ostd::String& windowTitle) { initialize(width, height, windowTitle); }
// void initialize(int32_t width, int32_t height, const ostd::String& windowTitle);
// void close(void);
// void update(void);
// void setSize(int32_t width, int32_t height);
// void setTitle(const ostd::String& title);
// void setCursor(eCursor cursor);
// void enableResizable(bool enable = true);
// void setIcon(const ostd::String& iconFilePath);
// inline virtual void onWindowInitialize(void) { }
// inline virtual void onWindowDestroy(void) { }
// inline virtual void onWindowClose(void) { }
// inline bool isInitialized(void) const { return m_initialized; }
// inline bool isRunning(void) const { return m_running; }
// inline bool isVisible(void) const { return m_visible; }
// inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; }
// inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; }
// inline ostd::String getTitle(void) const { return m_title; }
// inline int32_t getWindowWidth(void) const { return m_windowWidth; }
// inline int32_t getWindowHeight(void) const { return m_windowHeight; }
// inline ostd::Color getClearColor(void) const { return m_clearColor; }
// inline void setClearColor(const ostd::Color& color) { m_clearColor = color; }
// inline SDL_Renderer* getSDLRenderer(void) { return m_renderer; }
// private:
// void __handle_events(void);
// protected:
// ostd::ConsoleOutputHandler out;
// SDL_Window* m_window { nullptr };
// SDL_Renderer* m_renderer { nullptr };
// bool m_refreshScreen { true };
// private:
// ostd::Color m_clearColor { 10, 10, 10, 255 };
// int32_t m_windowWidth { 0 };
// int32_t m_windowHeight { 0 };
// ostd::String m_title { "" };
// bool m_running { false };
// bool m_initialized { false };
// bool m_visible { true };
// SDL_Cursor* m_cursor_IBeam { nullptr };
// SDL_Cursor* m_cursor_Arrow { nullptr };
// };
class WindowBase : public ostd::BaseObject class WindowBase : public ostd::BaseObject
{ {
public: enum class eCursor { Arrow = 0, IBeam }; public: enum class eCursor { Arrow = 0, IBeam };
@ -63,7 +118,7 @@ namespace ogfx
inline void enableMouseDragEvent(bool enable = true) { m_deagEventEnabled = enable; } inline void enableMouseDragEvent(bool enable = true) { m_deagEventEnabled = enable; }
inline ostd::Color getClearColor(void) const { return m_clearColor; } inline ostd::Color getClearColor(void) const { return m_clearColor; }
inline void setClearColor(const ostd::Color& color) { m_clearColor = color; } inline void setClearColor(const ostd::Color& color) { m_clearColor = color; }
inline SDL_Renderer* getSDLRenderer(void) const { return m_renderer; } inline SDL_Renderer* getSDLRenderer(void) { return m_renderer; }
private: private:
void __handle_events(void); void __handle_events(void);
@ -116,15 +171,15 @@ namespace ogfx
{ {
public: enum class eButton { None = 0, Left, Middle, Right }; public: enum class eButton { None = 0, Left, Middle, Right };
public: public:
inline MouseEventData(WindowBase& parent, int32_t mousex, int32_t mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn) inline MouseEventData(WindowBase& parent, float mousex, float mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn)
{ {
setTypeName("ogfx::MouseEventData"); setTypeName("ogfx::MouseEventData");
validate(); validate();
} }
public: public:
int32_t position_x; float position_x;
int32_t position_y; float position_y;
eButton button; eButton button;
WindowBase& parentWindow; WindowBase& parentWindow;
}; };

View file

@ -42,27 +42,27 @@ namespace ogfx
m_ttfr.setFontSize(fontSize); m_ttfr.setFontSize(fontSize);
} }
void BasicRenderer2D::drawImage(const ogfx::Image& image, const ostd::Vec2& position, const ostd::Rectangle& rect) void BasicRenderer2D::drawImage(ogfx::Image& image, const ostd::Vec2& position, const ostd::Rectangle& rect)
{ {
if (!m_initialized) return; if (!m_initialized) return;
if (!image.isLoaded()) return; if (!image.isLoaded()) return;
SDL_Rect texr; SDL_FRect texr;
texr.x = position.x; texr.x = position.x;
texr.y = position.y; texr.y = position.y;
texr.w = image.getSize().x; texr.w = image.getSize().x;
texr.h = image.getSize().y; texr.h = image.getSize().y;
SDL_Rect srcRect; SDL_FRect srcRect;
srcRect.x = rect.x; srcRect.x = rect.x;
srcRect.y = rect.y; srcRect.y = rect.y;
srcRect.w = rect.w; srcRect.w = rect.w;
srcRect.h = rect.w; srcRect.h = rect.w;
if (srcRect.x == 0 && srcRect.y == 0 && srcRect.w == 0 && srcRect.h == 0) if (srcRect.x == 0 && srcRect.y == 0 && srcRect.w == 0 && srcRect.h == 0)
SDL_RenderCopy(m_window->getSDLRenderer(), image.getSDLTexture(), nullptr, &texr); SDL_RenderTexture(m_window->getSDLRenderer(), image.getSDLTexture(), nullptr, &texr);
else else
{ {
texr.w = srcRect.w; texr.w = srcRect.w;
texr.h = srcRect.h; texr.h = srcRect.h;
SDL_RenderCopy(m_window->getSDLRenderer(), image.getSDLTexture(), &srcRect, &texr); SDL_RenderTexture(m_window->getSDLRenderer(), image.getSDLTexture(), &srcRect, &texr);
} }
} }
@ -70,7 +70,7 @@ namespace ogfx
{ {
if (!m_initialized) return; if (!m_initialized) return;
if (!anim.hasImage()) return; if (!anim.hasImage()) return;
const auto& img = anim.getSpriteSheet(); Image img = anim.getSpriteSheet();
if (!img.isLoaded() || !img.isValid()) return; if (!img.isLoaded() || !img.isValid()) return;
drawImage(img, position, anim.getFrameRect()); drawImage(img, position, anim.getFrameRect());
} }

View file

@ -41,7 +41,7 @@ namespace ogfx
void setFont(const ostd::String& fontFilePath); void setFont(const ostd::String& fontFilePath);
void setFontSize(int32_t fontSize); void setFontSize(int32_t fontSize);
void drawImage(const ogfx::Image& image, const ostd::Vec2& position, const ostd::Rectangle& rect = { 0, 0, 0, 0 }); void drawImage(ogfx::Image& image, const ostd::Vec2& position, const ostd::Rectangle& rect = { 0, 0, 0, 0 });
void drawAnimation(const Animation& anim, const ostd::Vec2& position); void drawAnimation(const Animation& anim, const ostd::Vec2& position);
void drawString(const ostd::String& str, const ostd::Vec2& position, const ostd::Color& color, int32_t fontSize = 0); void drawString(const ostd::String& str, const ostd::Vec2& position, const ostd::Color& color, int32_t fontSize = 0);

View file

@ -19,6 +19,8 @@
*/ */
#include "FontUtils.hpp" #include "FontUtils.hpp"
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_render.h>
namespace ogfx namespace ogfx
{ {
@ -50,7 +52,7 @@ namespace ogfx
return; return;
} }
setFontSize(fontSize); setFontSize(fontSize);
SDL_Surface* surf = TTF_RenderText_Blended(m_font, message.c_str(), { color.r, color.g, color.b, color.a }); SDL_Surface* surf = TTF_RenderText_Blended(m_font, message.c_str(), message.len(), { color.r, color.g, color.b, color.a });
if (surf == nullptr) if (surf == nullptr)
{ {
set_error_state(tErrors::TTFRenderTextBlendedFail); set_error_state(tErrors::TTFRenderTextBlendedFail);
@ -64,17 +66,17 @@ namespace ogfx
print_ttf_error("SDL_CreateTextureFromSurface"); print_ttf_error("SDL_CreateTextureFromSurface");
return; return;
} }
SDL_FreeSurface(surf); SDL_DestroySurface(surf);
int32_t w = 0, h = 0; float w = 0, h = 0;
SDL_QueryTexture(texture, NULL, NULL, &w, &h); SDL_GetTextureSize(texture, &w, &h);
SDL_Rect dst; SDL_FRect dst;
dst.x = x; dst.x = x;
dst.y = y; dst.y = y;
dst.w = w; dst.w = w;
dst.h = h; dst.h = h;
SDL_RenderCopy(m_renderer, texture, NULL, &dst); SDL_RenderTexture(m_renderer, texture, NULL, &dst);
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
} }
@ -101,7 +103,7 @@ namespace ogfx
return; return;
} }
setFontSize(fontSize); setFontSize(fontSize);
SDL_Surface* surf = TTF_RenderText_Blended(m_font, message.c_str(), { color.r, color.g, color.b, color.a }); SDL_Surface* surf = TTF_RenderText_Blended(m_font, message.c_str(), message.len(), { color.r, color.g, color.b, color.a });
if (surf == nullptr) if (surf == nullptr)
{ {
set_error_state(tErrors::TTFRenderTextBlendedFail); set_error_state(tErrors::TTFRenderTextBlendedFail);
@ -115,17 +117,17 @@ namespace ogfx
print_ttf_error("SDL_CreateTextureFromSurface"); print_ttf_error("SDL_CreateTextureFromSurface");
return; return;
} }
SDL_FreeSurface(surf); SDL_DestroySurface(surf);
int32_t w = 0, h = 0; float w = 0, h = 0;
SDL_QueryTexture(texture, NULL, NULL, &w, &h); SDL_GetTextureSize(texture, &w, &h);
SDL_Rect dst; SDL_FRect dst;
dst.x = center_x - (w / 2); dst.x = center_x - (w / 2);
dst.y = center_y - (h / 2); dst.y = center_y - (h / 2);
dst.w = w; dst.w = w;
dst.h = h; dst.h = h;
SDL_RenderCopy(m_renderer, texture, NULL, &dst); SDL_RenderTexture(m_renderer, texture, NULL, &dst);
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
} }
@ -152,7 +154,7 @@ namespace ogfx
return { 0, 0 }; return { 0, 0 };
} }
setFontSize(fontSize); setFontSize(fontSize);
SDL_Surface* surf = TTF_RenderText_Blended(m_font, message.c_str(), { 0, 0, 0, 255 }); SDL_Surface* surf = TTF_RenderText_Blended(m_font, message.c_str(), message.len(), { 0, 0, 0, 255 });
if (surf == nullptr) if (surf == nullptr)
{ {
set_error_state(tErrors::TTFRenderTextBlendedFail); set_error_state(tErrors::TTFRenderTextBlendedFail);
@ -166,19 +168,19 @@ namespace ogfx
print_ttf_error("SDL_CreateTextureFromSurface"); print_ttf_error("SDL_CreateTextureFromSurface");
return { 0, 0 }; return { 0, 0 };
} }
SDL_FreeSurface(surf); SDL_DestroySurface(surf);
int32_t w = 0, h = 0; float w = 0, h = 0;
SDL_QueryTexture(texture, NULL, NULL, &w, &h); SDL_GetTextureSize(texture, &w, &h);
SDL_DestroyTexture(texture); SDL_DestroyTexture(texture);
return { w, h }; return { static_cast<int32_t>(w), static_cast<int32_t>(h) };
} }
int32_t TTFRenderer::init(SDL_Renderer* renderer) int32_t TTFRenderer::init(SDL_Renderer* renderer)
{ {
if (TTFRenderer::m_initialized) return set_error_state(tErrors::NoError); if (TTFRenderer::m_initialized) return set_error_state(tErrors::NoError);
if (renderer == nullptr) return set_error_state(tErrors::NullRenderer); if (renderer == nullptr) return set_error_state(tErrors::NullRenderer);
if (TTF_Init() != 0) if (!TTF_Init())
{ {
print_ttf_error("TTF_Init"); print_ttf_error("TTF_Init");
SDL_Quit(); SDL_Quit();
@ -233,6 +235,6 @@ namespace ogfx
void TTFRenderer::print_ttf_error(const ostd::String& funcName) void TTFRenderer::print_ttf_error(const ostd::String& funcName)
{ {
m_out.fg(ostd::ConsoleColors::Red).p(funcName).p("(...) failed: ").p(ostd::String(TTF_GetError())).reset().nl(); m_out.fg(ostd::ConsoleColors::Red).p(funcName).p("(...) failed: ").p(ostd::String(SDL_GetError())).reset().nl();
} }
} }

View file

@ -21,6 +21,7 @@
#include "PixelRenderer.hpp" #include "PixelRenderer.hpp"
#include "../gui/WindowBase.hpp" #include "../gui/WindowBase.hpp"
#include "../../ostd/io/Memory.hpp" #include "../../ostd/io/Memory.hpp"
#include <SDL3/SDL_render.h>
namespace ogfx namespace ogfx
{ {
@ -171,8 +172,8 @@ namespace ogfx
void PixelRenderer::displayBuffer(void) void PixelRenderer::displayBuffer(void)
{ {
if (isInvalid()) return; if (isInvalid()) return;
SDL_Rect rect { 0, 0, m_windowWidth, m_windowHeight }; SDL_FRect rect { 0, 0, static_cast<float>(m_windowWidth), static_cast<float>(m_windowHeight) };
SDL_RenderCopy(m_parent->getSDLRenderer(), m_texture, NULL, &rect); SDL_RenderTexture(m_parent->getSDLRenderer(), m_texture, NULL, &rect);
} }
void PixelRenderer::clear(const ostd::Color& color) void PixelRenderer::clear(const ostd::Color& color)

View file

@ -73,7 +73,7 @@ namespace ogfx
} }
inline ~Font(void) inline ~Font(void)
{ {
SDL_FreeSurface(m_fontSurface); SDL_DestroySurface(m_fontSurface);
} }
public: public:

View file

@ -41,10 +41,10 @@ namespace ogfx
m_sdl_texture = IMG_LoadTexture(gfx.getWindow().getSDLRenderer(), filePath.c_str()); m_sdl_texture = IMG_LoadTexture(gfx.getWindow().getSDLRenderer(), filePath.c_str());
if (!m_sdl_texture) if (!m_sdl_texture)
{ {
OX_ERROR("Failed to load Image: %s", IMG_GetError()); OX_ERROR("Failed to load Image: %s", SDL_GetError());
return *this; return *this;
} }
SDL_QueryTexture(m_sdl_texture, nullptr, nullptr, &m_width, &m_height); SDL_GetTextureSize(m_sdl_texture, &m_width, &m_height);
m_loaded = true; m_loaded = true;
setTypeName("ogfx::Image"); setTypeName("ogfx::Image");
validate(); validate();

View file

@ -35,14 +35,14 @@ namespace ogfx
inline ~Image(void) { destroy(); } inline ~Image(void) { destroy(); }
void destroy(void); void destroy(void);
Image& loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx); Image& loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx);
inline ostd::IPoint getSize(void) const { return { m_width, m_height }; } inline ostd::Vec2 getSize(void) const { return { m_width, m_height }; }
inline bool isLoaded(void) const { return m_loaded; } inline bool isLoaded(void) const { return m_loaded; }
inline SDL_Texture* getSDLTexture(void) const { return m_sdl_texture; } inline SDL_Texture* getSDLTexture(void) { return m_sdl_texture; }
private: private:
SDL_Texture* m_sdl_texture { nullptr }; SDL_Texture* m_sdl_texture { nullptr };
int32_t m_width { 0 }; float m_width { 0 };
int32_t m_height { 0 }; float m_height { 0 };
bool m_loaded { false }; bool m_loaded { false };
}; };
} }

View file

@ -78,7 +78,7 @@ namespace ogfx
inline void setColumnOffset(int32_t o) { m_column_offset = o; } inline void setColumnOffset(int32_t o) { m_column_offset = o; }
inline void setRowOffset(int32_t o) { m_row_offset = o; } inline void setRowOffset(int32_t o) { m_row_offset = o; }
inline void setStill(bool s) { m_still = s; } inline void setStill(bool s) { m_still = s; }
inline void setSpriteSheet(const Image& img) { m_spriteSheet = &img; } inline void setSpriteSheet(Image& img) { m_spriteSheet = &img; }
inline int32_t getFrameNumber(void) const { return m_frames; } inline int32_t getFrameNumber(void) const { return m_frames; }
inline int32_t getColumnNumber(void) const { return m_columns; } inline int32_t getColumnNumber(void) const { return m_columns; }
@ -89,11 +89,12 @@ namespace ogfx
inline bool isStill(void) const { return m_still; } inline bool isStill(void) const { return m_still; }
inline ostd::Rectangle getFrameRect(void) const { return m_frame_rect; } inline ostd::Rectangle getFrameRect(void) const { return m_frame_rect; }
inline const Image& getSpriteSheet(void) const { return (m_spriteSheet != nullptr ? *m_spriteSheet : InvalidImage); } inline const Image& getSpriteSheet(void) const { return (m_spriteSheet != nullptr ? *m_spriteSheet : InvalidImage); }
inline Image& getSpriteSheet(void) { return (m_spriteSheet != nullptr ? *m_spriteSheet : InvalidImage); }
inline bool hasImage(void) const { return m_spriteSheet != nullptr; } inline bool hasImage(void) const { return m_spriteSheet != nullptr; }
private: private:
const Image* m_spriteSheet { nullptr }; Image* m_spriteSheet { nullptr };
inline static const Image InvalidImage; inline static Image InvalidImage;
int32_t m_frames; int32_t m_frames;
int32_t m_rows; int32_t m_rows;

View file

@ -20,15 +20,12 @@
#pragma once #pragma once
#ifdef _WIN32 #include <ostd/utils/Defines.hpp>
#define SDL_MAIN_HANDLED
#undef __linux__
#endif
#include <SDL2/SDL.h> #include <SDL3/SDL.h>
#include <SDL2/SDL2_gfxPrimitives.h> #include <ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.h>
#include <SDL2/SDL_ttf.h> #include <SDL3_ttf/SDL_ttf.h>
#include <SDL2/SDL_image.h> #include <SDL3_image/SDL_image.h>
#include <SDL2/SDL_surface.h> #include <SDL3/SDL_surface.h>
#include <SDL2/SDL_rect.h> #include <SDL3/SDL_rect.h>
#include <SDL2/SDL_render.h> #include <SDL3/SDL_render.h>

View file

@ -0,0 +1,189 @@
/*
SDL3_framerate.c: framerate manager
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#include "SDL3_framerate.h"
/*!
\brief Internal wrapper to SDL_GetTicks that ensures a non-zero return value.
\return The tick count.
*/
Uint64 _getTicks()
{
Uint64 ticks = SDL_GetTicks();
/*
* Since baseticks!=0 is used to track initialization
* we need to ensure that the tick count is always >0
* since SDL_GetTicks may not have incremented yet and
* return 0 depending on the timing of the calls.
*/
if (ticks == 0) {
return 1;
} else {
return ticks;
}
}
/*!
\brief Initialize the framerate manager.
Initialize the framerate manager, set default framerate of 30Hz and
reset delay interpolation.
\param manager Pointer to the framerate manager.
*/
void SDL_initFramerate(FPSmanager * manager)
{
/*
* Store some sane values
*/
manager->framecount = 0;
manager->rate = FPS_DEFAULT;
manager->rateticks = (1000.0f / (float) FPS_DEFAULT);
manager->baseticks = _getTicks();
manager->lastticks = manager->baseticks;
}
/*!
\brief Set the framerate in Hz
Sets a new framerate for the manager and reset delay interpolation.
Rate values must be between FPS_LOWER_LIMIT and FPS_UPPER_LIMIT inclusive to be accepted.
\param manager Pointer to the framerate manager.
\param rate The new framerate in Hz (frames per second).
\return 0 for sucess and -1 for error.
*/
int SDL_setFramerate(FPSmanager * manager, Uint32 rate)
{
if ((rate >= FPS_LOWER_LIMIT) && (rate <= FPS_UPPER_LIMIT)) {
manager->framecount = 0;
manager->rate = rate;
manager->rateticks = (1000.0f / (float) rate);
return (0);
} else {
return (-1);
}
}
/*!
\brief Return the current target framerate in Hz
Get the currently set framerate of the manager.
\param manager Pointer to the framerate manager.
\return Current framerate in Hz or -1 for error.
*/
int SDL_getFramerate(FPSmanager * manager)
{
if (manager == NULL) {
return (-1);
} else {
return ((int)manager->rate);
}
}
/*!
\brief Return the current framecount.
Get the current framecount from the framerate manager.
A frame is counted each time SDL_framerateDelay is called.
\param manager Pointer to the framerate manager.
\return Current frame count or -1 for error.
*/
int SDL_getFramecount(FPSmanager * manager)
{
if (manager == NULL) {
return (-1);
} else {
return ((int)manager->framecount);
}
}
/*!
\brief Delay execution to maintain a constant framerate and calculate fps.
Generate a delay to accomodate currently set framerate. Call once in the
graphics/rendering loop. If the computer cannot keep up with the rate (i.e.
drawing too slow), the delay is zero and the delay interpolation is reset.
\param manager Pointer to the framerate manager.
\return The time that passed since the last call to the function in ms. May return 0.
*/
Uint64 SDL_framerateDelay(FPSmanager * manager)
{
Uint64 current_ticks;
Uint64 target_ticks;
Uint64 the_delay;
Uint64 time_passed = 0;
/*
* No manager, no delay
*/
if (manager == NULL) {
return 0;
}
/*
* Initialize uninitialized manager
*/
if (manager->baseticks == 0) {
SDL_initFramerate(manager);
}
/*
* Next frame
*/
manager->framecount++;
/*
* Get/calc ticks
*/
current_ticks = _getTicks();
time_passed = current_ticks - manager->lastticks;
manager->lastticks = current_ticks;
target_ticks = manager->baseticks + (Uint64) ((float) manager->framecount * manager->rateticks);
if (current_ticks <= target_ticks) {
the_delay = target_ticks - current_ticks;
SDL_Delay(the_delay);
} else {
manager->framecount = 0;
manager->baseticks = _getTicks();
}
return time_passed;
}

View file

@ -0,0 +1,100 @@
/*
SDL3_framerate.h: framerate manager
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL3_framerate_h
#define _SDL3_framerate_h
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* --- */
#include <SDL3/SDL.h>
/* --------- Definitions */
/*!
\brief Highest possible rate supported by framerate controller in Hz (1/s).
*/
#define FPS_UPPER_LIMIT 200
/*!
\brief Lowest possible rate supported by framerate controller in Hz (1/s).
*/
#define FPS_LOWER_LIMIT 1
/*!
\brief Default rate of framerate controller in Hz (1/s).
*/
#define FPS_DEFAULT 30
/*!
\brief Structure holding the state and timing information of the framerate controller.
*/
typedef struct {
Uint32 framecount;
float rateticks;
Uint64 baseticks;
Uint64 lastticks;
Uint32 rate;
} FPSmanager;
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL3_GFX_DLL_IMPORT)
# define SDL3_FRAMERATE_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL3_GFX_DLL_IMPORT
# define SDL3_FRAMERATE_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL3_FRAMERATE_SCOPE
# define SDL3_FRAMERATE_SCOPE extern
#endif
/* Functions return 0 or value for sucess and -1 for error */
SDL3_FRAMERATE_SCOPE void SDL_initFramerate(FPSmanager * manager);
SDL3_FRAMERATE_SCOPE int SDL_setFramerate(FPSmanager * manager, Uint32 rate);
SDL3_FRAMERATE_SCOPE int SDL_getFramerate(FPSmanager * manager);
SDL3_FRAMERATE_SCOPE int SDL_getFramecount(FPSmanager * manager);
SDL3_FRAMERATE_SCOPE Uint64 SDL_framerateDelay(FPSmanager * manager);
/* --- */
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL3_framerate_h */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,241 @@
/*
SDL3_gfxPrimitives.h: graphics primitives for SDL
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL3_gfxPrimitives_h
#define _SDL3_gfxPrimitives_h
#include <math.h>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#include <SDL3/SDL.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* ----- Versioning */
#define SDL3_GFXPRIMITIVES_MAJOR 1
#define SDL3_GFXPRIMITIVES_MINOR 0
#define SDL3_GFXPRIMITIVES_MICRO 0
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL3_GFX_DLL_IMPORT)
# define SDL3_GFXPRIMITIVES_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL3_GFX_DLL_IMPORT
# define SDL3_GFXPRIMITIVES_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL3_GFXPRIMITIVES_SCOPE
# define SDL3_GFXPRIMITIVES_SCOPE extern
#endif
/* Note: all ___Color routines expect the color to be in format 0xRRGGBBAA */
/* Pixel */
SDL3_GFXPRIMITIVES_SCOPE bool pixelColor(SDL_Renderer * renderer, float x, float y, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool pixelRGBA(SDL_Renderer * renderer, float x, float y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Horizontal line */
SDL3_GFXPRIMITIVES_SCOPE bool hlineColor(SDL_Renderer * renderer, float x1, float x2, float y, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool hlineRGBA(SDL_Renderer * renderer, float x1, float x2, float y, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Vertical line */
SDL3_GFXPRIMITIVES_SCOPE bool vlineColor(SDL_Renderer * renderer, float x, float y1, float y2, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool vlineRGBA(SDL_Renderer * renderer, float x, float y1, float y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Rectangle */
SDL3_GFXPRIMITIVES_SCOPE bool rectangleColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool rectangleRGBA(SDL_Renderer * renderer, float x1, float y1,
float x2, float y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Rounded-Corner Rectangle */
SDL3_GFXPRIMITIVES_SCOPE bool roundedRectangleColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float rad, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool roundedRectangleRGBA(SDL_Renderer * renderer, float x1, float y1,
float x2, float y2, float rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled rectangle (Box) */
SDL3_GFXPRIMITIVES_SCOPE bool boxColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool boxRGBA(SDL_Renderer * renderer, float x1, float y1, float x2,
float y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Rounded-Corner Filled rectangle (Box) */
SDL3_GFXPRIMITIVES_SCOPE bool roundedBoxColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float rad, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool roundedBoxRGBA(SDL_Renderer * renderer, float x1, float y1, float x2,
float y2, float rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Line */
SDL3_GFXPRIMITIVES_SCOPE bool lineColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool lineRGBA(SDL_Renderer * renderer, float x1, float y1,
float x2, float y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Line */
SDL3_GFXPRIMITIVES_SCOPE bool aalineColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool aalineRGBA(SDL_Renderer * renderer, float x1, float y1,
float x2, float y2, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Thick Line */
SDL3_GFXPRIMITIVES_SCOPE bool thickLineColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2,
float width, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool thickLineRGBA(SDL_Renderer * renderer, float x1, float y1, float x2, float y2,
float width, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Circle */
SDL3_GFXPRIMITIVES_SCOPE bool circleColor(SDL_Renderer * renderer, float x, float y, float rad, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool circleRGBA(SDL_Renderer * renderer, float x, float y, float rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Arc */
SDL3_GFXPRIMITIVES_SCOPE bool arcColor(SDL_Renderer * renderer, float x, float y, float rad, Sint32 start, Sint32 end, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool arcRGBA(SDL_Renderer * renderer, float x, float y, float rad, Sint32 start, Sint32 end,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Circle */
SDL3_GFXPRIMITIVES_SCOPE bool aacircleColor(SDL_Renderer * renderer, float x, float y, float rad, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool aacircleRGBA(SDL_Renderer * renderer, float x, float y,
float rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Circle */
SDL3_GFXPRIMITIVES_SCOPE bool filledCircleColor(SDL_Renderer * renderer, float x, float y, float r, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool filledCircleRGBA(SDL_Renderer * renderer, float x, float y,
float rad, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Ellipse */
SDL3_GFXPRIMITIVES_SCOPE bool ellipseColor(SDL_Renderer * renderer, float x, float y, float rx, float ry, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool ellipseRGBA(SDL_Renderer * renderer, float x, float y,
float rx, float ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA Ellipse */
SDL3_GFXPRIMITIVES_SCOPE bool aaellipseColor(SDL_Renderer * renderer, float x, float y, float rx, float ry, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool aaellipseRGBA(SDL_Renderer * renderer, float x, float y,
float rx, float ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Ellipse */
SDL3_GFXPRIMITIVES_SCOPE bool filledEllipseColor(SDL_Renderer * renderer, float x, float y, float rx, float ry, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool filledEllipseRGBA(SDL_Renderer * renderer, float x, float y,
float rx, float ry, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Pie */
SDL3_GFXPRIMITIVES_SCOPE bool pieColor(SDL_Renderer * renderer, float x, float y, float rad,
Sint32 start, Sint32 end, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool pieRGBA(SDL_Renderer * renderer, float x, float y, float rad,
Sint32 start, Sint32 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Pie */
SDL3_GFXPRIMITIVES_SCOPE bool filledPieColor(SDL_Renderer * renderer, float x, float y, float rad,
Sint32 start, Sint32 end, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool filledPieRGBA(SDL_Renderer * renderer, float x, float y, float rad,
Sint32 start, Sint32 end, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Trigon */
SDL3_GFXPRIMITIVES_SCOPE bool trigonColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float x3, float y3, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool trigonRGBA(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float x3, float y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA-Trigon */
SDL3_GFXPRIMITIVES_SCOPE bool aatrigonColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float x3, float y3, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool aatrigonRGBA(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float x3, float y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Trigon */
SDL3_GFXPRIMITIVES_SCOPE bool filledTrigonColor(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float x3, float y3, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool filledTrigonRGBA(SDL_Renderer * renderer, float x1, float y1, float x2, float y2, float x3, float y3,
Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Polygon */
SDL3_GFXPRIMITIVES_SCOPE bool polygonColor(SDL_Renderer * renderer, const float * vx, const float * vy, Sint32 n, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool polygonRGBA(SDL_Renderer * renderer, const float * vx, const float * vy,
Sint32 n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* AA-Polygon */
SDL3_GFXPRIMITIVES_SCOPE bool aapolygonColor(SDL_Renderer * renderer, const float * vx, const float * vy, Sint32 n, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool aapolygonRGBA(SDL_Renderer * renderer, const float * vx, const float * vy,
Sint32 n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Filled Polygon */
SDL3_GFXPRIMITIVES_SCOPE bool filledPolygonColor(SDL_Renderer * renderer, const float * vx, const float * vy, Sint32 n, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool filledPolygonRGBA(SDL_Renderer * renderer, const float * vx,
const float * vy, Sint32 n, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Textured Polygon */
SDL3_GFXPRIMITIVES_SCOPE bool texturedPolygon(SDL_Renderer * renderer, const float * vx, const float * vy, Sint32 n, SDL_Surface * texture,Sint32 texture_dx,Sint32 texture_dy);
/* Bezier */
SDL3_GFXPRIMITIVES_SCOPE bool bezierColor(SDL_Renderer * renderer, const float * vx, const float * vy, Sint32 n, Sint32 s, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool bezierRGBA(SDL_Renderer * renderer, const float * vx, const float * vy,
Sint32 n, Sint32 s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Characters/Strings */
SDL3_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFont(const void *fontdata, Uint32 cw, Uint32 ch);
SDL3_GFXPRIMITIVES_SCOPE void gfxPrimitivesSetFontRotation(Uint32 rotation);
SDL3_GFXPRIMITIVES_SCOPE bool characterColor(SDL_Renderer * renderer, float x, float y, char c, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool characterRGBA(SDL_Renderer * renderer, float x, float y, char c, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
SDL3_GFXPRIMITIVES_SCOPE bool stringColor(SDL_Renderer * renderer, float x, float y, const char *s, Uint32 color);
SDL3_GFXPRIMITIVES_SCOPE bool stringRGBA(SDL_Renderer * renderer, float x, float y, const char *s, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL3_gfxPrimitives_h */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,161 @@
/*
SDL3_imageFilter.h: byte-image "filter" routines
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL3_imageFilter_h
#define _SDL3_imageFilter_h
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL3_GFX_DLL_IMPORT)
# define SDL3_IMAGEFILTER_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL3_GFX_DLL_IMPORT
# define SDL3_IMAGEFILTER_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL3_IMAGEFILTER_SCOPE
# define SDL3_IMAGEFILTER_SCOPE extern
#endif
/* Comments: */
/* 1.) Convolution routines are not implemented at this time. */
//
// All routines return:
// true OK
// false Error (internal error, parameter error)
//
// SDL_imageFilterAdd: D = saturation255(S1 + S2)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterAdd(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMean: D = S1/2 + S2/2
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterMean(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterSub: D = saturation0(S1 - S2)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterSub(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterAbsDiff: D = | S1 - S2 |
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterAbsDiff(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMult: D = saturation(S1 * S2)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterMult(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMultUnbound: D = S1 * S2 unbound
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterMultUnbound(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMultInv: D = 255 - ((255 - S1) * (255 - S2))
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterMultInv(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterMultDivby2: D = saturation255(S1/2 * S2)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterMultDivby2(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest,
unsigned int length);
// SDL_imageFilterMultDivby4: D = saturation255(S1/2 * S2/2)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterMultDivby4(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest,
unsigned int length);
// SDL_imageFilterBitAnd: D = S1 & S2
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterBitAnd(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterBitOr: D = S1 | S2
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterBitOr(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterDiv: D = S1 / S2
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterDiv(unsigned char *Src1, unsigned char *Src2, unsigned char *Dest, unsigned int length);
// SDL_imageFilterBitNegation: D = !S
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterBitNegation(unsigned char *Src1, unsigned char *Dest, unsigned int length);
// SDL_imageFilterAddByte: D = saturation255(S + C)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterAddByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
// SDL_imageFilterAddUint: D = saturation255(S + (uint)C)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterAddUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned int bpp, unsigned int C);
// SDL_imageFilterAddByteToHalf: D = saturation255(S/2 + C)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterAddByteToHalf(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char C);
// SDL_imageFilterSubByte: D = saturation0(S - C)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterSubByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
// SDL_imageFilterSubUint: D = saturation0(S - (uint)C)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterSubUint(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned int bpp, unsigned int C);
// SDL_imageFilterShiftRight: D = saturation0(S >> N)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterShiftRight(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
// SDL_imageFilterShiftRightUint: D = saturation0((uint)S >> N)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterShiftRightUint(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned int bpp, unsigned char N);
// SDL_imageFilterMultByByte: D = saturation255(S * C)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterMultByByte(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char C);
// SDL_imageFilterShiftRightAndMultByByte: D = saturation255((S >> N) * C)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterShiftRightAndMultByByte(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char N, unsigned char C);
// SDL_imageFilterShiftLeftByte: D = (S << N)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterShiftLeftByte(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char N);
// SDL_imageFilterShiftLeftUint: D = ((uint)S << N)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterShiftLeftUint(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned int bpp, unsigned char N);
// SDL_imageFilterShiftLeft: D = saturation255(S << N)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterShiftLeft(unsigned char *Src1, unsigned char *Dest, unsigned int length, unsigned char N);
// SDL_imageFilterBinarizeUsingThreshold: D = S >= T ? 255:0
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterBinarizeUsingThreshold(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char T);
// SDL_imageFilterClipToRange: D = (S >= Tmin) & (S <= Tmax) 255:0
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterClipToRange(unsigned char *Src1, unsigned char *Dest, unsigned int length,
unsigned char Tmin, unsigned char Tmax);
// SDL_imageFilterNormalizeLinear: D = saturation255((Nmax - Nmin)/(Cmax - Cmin)*(S - Cmin) + Nmin)
SDL3_IMAGEFILTER_SCOPE bool SDL_imageFilterNormalizeLinear(unsigned char *Src, unsigned char *Dest, unsigned int length, int Cmin,
int Cmax, int Nmin, int Nmax);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL3_imageFilter_h */

1636
src/ogfx/vendor/sdl3_gfx/SDL3_rotozoom.c vendored Normal file

File diff suppressed because it is too large Load diff

123
src/ogfx/vendor/sdl3_gfx/SDL3_rotozoom.h vendored Normal file
View file

@ -0,0 +1,123 @@
/*
SDL3_rotozoom.c: rotozoomer, zoomer and shrinker for 32bit or 8bit surfaces
Copyright (C) 2012-2014 Andreas Schiffler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#ifndef _SDL3_rotozoom_h
#define _SDL3_rotozoom_h
#include <math.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
#include <SDL3/SDL.h>
/* ---- Defines */
/*!
\brief Disable anti-aliasing (no smoothing).
*/
#define SMOOTHING_OFF 0
/*!
\brief Enable anti-aliasing (smoothing).
*/
#define SMOOTHING_ON 1
/* ---- Function Prototypes */
#ifdef _MSC_VER
# if defined(DLL_EXPORT) && !defined(LIBSDL3_GFX_DLL_IMPORT)
# define SDL3_ROTOZOOM_SCOPE __declspec(dllexport)
# else
# ifdef LIBSDL3_GFX_DLL_IMPORT
# define SDL3_ROTOZOOM_SCOPE __declspec(dllimport)
# endif
# endif
#endif
#ifndef SDL3_ROTOZOOM_SCOPE
# define SDL3_ROTOZOOM_SCOPE extern
#endif
/*
Rotozoom functions
*/
SDL3_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth);
SDL3_ROTOZOOM_SCOPE SDL_Surface *rotozoomSurfaceXY
(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth);
SDL3_ROTOZOOM_SCOPE void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth,
int *dstheight);
SDL3_ROTOZOOM_SCOPE void rotozoomSurfaceSizeXY
(int width, int height, double angle, double zoomx, double zoomy,
int *dstwidth, int *dstheight);
/*
Zooming functions
*/
SDL3_ROTOZOOM_SCOPE SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth);
SDL3_ROTOZOOM_SCOPE void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight);
/*
Shrinking functions
*/
SDL3_ROTOZOOM_SCOPE SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory);
/*
Specialized rotation functions
*/
SDL3_ROTOZOOM_SCOPE SDL_Surface* rotateSurface90Degrees(SDL_Surface* src, int numClockwiseTurns);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#endif /* _SDL3_rotozoom_h */

View file

@ -18,6 +18,24 @@
along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>. along with OmniaFramework. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*
* Label
* Button
* Panel / Container
* Checkbox
* Radio Button (Group)
* Text Input
* Horizontal Slider
* Image / Icon
* ScrollView
* ListBox
* ComboBox
* TreeView
*/
#include <ogfx/ogfx.hpp> #include <ogfx/ogfx.hpp>
ostd::ConsoleOutputHandler out; ostd::ConsoleOutputHandler out;
@ -94,7 +112,7 @@ class Window : public ogfx::WindowBase
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
Window window; Window window;
window.initialize(1280, 720, "OmniaFramework - Test Window"); window.initialize(800, 600, "OmniaFramework - Test Window");
window.setClearColor({ 0, 2 , 15 }); window.setClearColor({ 0, 2 , 15 });
while (window.isRunning()) while (window.isRunning())