Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
2764741cc3
73 changed files with 23132 additions and 835 deletions
|
|
@ -79,17 +79,33 @@ list(APPEND OSTD_SOURCE_FILES
|
|||
${CMAKE_CURRENT_LIST_DIR}/src/ostd/utils/Time.cpp
|
||||
)
|
||||
list(APPEND OGFX_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/FontUtils.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/WindowBase.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/BasicRenderer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/RawTextInput.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/Image.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/WindowBaseOutputHandler.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/PixelRenderer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/Animation.cpp
|
||||
# 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
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/Window.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/WindowOutputHandler.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/Widgets.cpp
|
||||
|
||||
# render
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/BasicRenderer.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/FontUtils.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/PixelRenderer.cpp
|
||||
|
||||
# resources
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/resources/Image.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/resources/UbuntuMonoRegularTTF.cpp
|
||||
|
||||
# utils
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/utils/Animation.cpp
|
||||
)
|
||||
list(APPEND TEST_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/test.cpp
|
||||
# ${CMAKE_CURRENT_LIST_DIR}/src/test/GraphicsWindowTest.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/test/GuiTest.cpp
|
||||
)
|
||||
#-----------------------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -139,7 +155,7 @@ endif()
|
|||
if (WIN32)
|
||||
target_link_libraries(${OMNIA_GFX_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)
|
||||
|
||||
target_link_libraries(${OMNIA_GFX_LIB} PUBLIC ${OMNIA_STD_LIB})
|
||||
|
|
@ -177,6 +193,6 @@ elseif (UNIX)
|
|||
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_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 ()
|
||||
#-----------------------------------------------------------------------------------------
|
||||
|
|
|
|||
10
README.md
10
README.md
|
|
@ -22,7 +22,7 @@ Once you have the **MSYS2 UCRT64 terminal** open, run theese two commands to pre
|
|||
|
||||
```bash
|
||||
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
|
||||
|
|
@ -86,21 +86,21 @@ Installs the library MSYS2's UCRT64 profile.
|
|||
- **<u>Arch Linux</u>**
|
||||
|
||||
```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>**
|
||||
|
||||
```bash
|
||||
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>**
|
||||
|
||||
```bash
|
||||
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.
|
||||
|
|
@ -145,7 +145,7 @@ eval "$(/usr/local/bin/brew shellenv)"
|
|||
##### Step 3: Install dependencies
|
||||
|
||||
```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
|
||||
|
|
|
|||
4
build
4
build
|
|
@ -21,7 +21,7 @@ if [[ "$1" == "debug" || "$1" == "release" ]]; then
|
|||
rm -rf bin
|
||||
cmake -B bin -S ./ -G "$MAKEFILE_TYPE" -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
$MAKE_COMMAND -C bin $NJOBS --no-print-directory
|
||||
cp -r extra/* bin/
|
||||
find extra -mindepth 1 -maxdepth 1 -exec cp -r {} bin/ \;
|
||||
build_number=$(cat other/build.nr)
|
||||
build_number=$((build_number + 1))
|
||||
truncate -s 0 other/build.nr
|
||||
|
|
@ -34,7 +34,7 @@ elif [[ "$1" == "install" ]]; then
|
|||
./install_release.sh
|
||||
cd ..
|
||||
else
|
||||
cp -r extra/* bin/
|
||||
find extra -mindepth 1 -maxdepth 1 -exec cp -r {} bin/ \;
|
||||
printf "\n\033[0;32mBuilding Changes...\n\n\033[0m"
|
||||
$MAKE_COMMAND -C bin $NJOBS --no-print-directory
|
||||
if [[ "$1" == "run" ]]; then
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 251 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
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.
|
||||
|
|
@ -7,12 +7,11 @@ 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.
|
||||
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.
|
||||
|
||||
96
licences/Ubuntu-Font-LICENCE.txt
Normal file
96
licences/Ubuntu-Font-LICENCE.txt
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
-------------------------------
|
||||
UBUNTU FONT LICENCE Version 1.0
|
||||
-------------------------------
|
||||
|
||||
PREAMBLE
|
||||
This licence allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely. The fonts, including any derivative works, can be
|
||||
bundled, embedded, and redistributed provided the terms of this licence
|
||||
are met. The fonts and derivatives, however, cannot be released under
|
||||
any other licence. The requirement for fonts to remain under this
|
||||
licence does not require any document created using the fonts or their
|
||||
derivatives to be published under this licence, as long as the primary
|
||||
purpose of the document is not to be a vehicle for the distribution of
|
||||
the fonts.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this licence and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Original Version" refers to the collection of Font Software components
|
||||
as received under this licence.
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to
|
||||
a new environment.
|
||||
|
||||
"Copyright Holder(s)" refers to all individuals and companies who have a
|
||||
copyright ownership of the Font Software.
|
||||
|
||||
"Substantially Changed" refers to Modified Versions which can be easily
|
||||
identified as dissimilar to the Font Software by users of the Font
|
||||
Software comparing the Original Version with the Modified Version.
|
||||
|
||||
To "Propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification and with or without charging
|
||||
a redistribution fee), making available to the public, and in some
|
||||
countries other activities as well.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
This licence does not grant any rights under trademark law and all such
|
||||
rights are reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of the Font Software, to propagate the Font Software, subject to
|
||||
the below conditions:
|
||||
|
||||
1) Each copy of the Font Software must contain the above copyright
|
||||
notice and this licence. These can be included either as stand-alone
|
||||
text files, human-readable headers or in the appropriate machine-
|
||||
readable metadata fields within text or binary files as long as those
|
||||
fields can be easily viewed by the user.
|
||||
|
||||
2) The font name complies with the following:
|
||||
(a) The Original Version must retain its name, unmodified.
|
||||
(b) Modified Versions which are Substantially Changed must be renamed to
|
||||
avoid use of the name of the Original Version or similar names entirely.
|
||||
(c) Modified Versions which are not Substantially Changed must be
|
||||
renamed to both (i) retain the name of the Original Version and (ii) add
|
||||
additional naming elements to distinguish the Modified Version from the
|
||||
Original Version. The name of such Modified Versions must be the name of
|
||||
the Original Version, with "derivative X" where X represents the name of
|
||||
the new work, appended to that name.
|
||||
|
||||
3) The name(s) of the Copyright Holder(s) and any contributor to the
|
||||
Font Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except (i) as required by this licence, (ii) to
|
||||
acknowledge the contribution(s) of the Copyright Holder(s) or (iii) with
|
||||
their explicit written permission.
|
||||
|
||||
4) The Font Software, modified or unmodified, in part or in whole, must
|
||||
be distributed entirely under this licence, and must not be distributed
|
||||
under any other licence. The requirement for fonts to remain under this
|
||||
licence does not affect any document created using the Font Software,
|
||||
except any version of the Font Software extracted from a document
|
||||
created using the Font Software may only be distributed under this
|
||||
licence.
|
||||
|
||||
TERMINATION
|
||||
This licence becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER
|
||||
DEALINGS IN THE FONT SOFTWARE.
|
||||
23
licences/midifile-LICENSE.txt
Normal file
23
licences/midifile-LICENSE.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Copyright (c) 1999-2018, Craig Stuart Sapp
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
and the following disclaimer in the documentation and/or other materials
|
||||
provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
||||
/* 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
|
||||
|
|
@ -18,3 +21,5 @@ Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
|||
|
||||
Jean-loup Gailly Mark Adler
|
||||
jloup@gzip.org madler@alumni.caltech.edu
|
||||
|
||||
*/
|
||||
5
other/TODO.txt
Normal file
5
other/TODO.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
***Add Color constants to ostd::Color
|
||||
Add MouseEntered/MouseExited callbacks
|
||||
Fix mouse detection currently using local coordinates
|
||||
implement JSON theme loading
|
||||
Implemenmt MouseDragged callback
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
[0.2.1958]
|
||||
Added ostd::OutputHandlerBase::tab() virtual function
|
||||
Added ogfx::WindowBaseOutputHandler class
|
||||
|
||||
[0.2.1936]
|
||||
Added JsonFile class to handle Json files
|
||||
Added MidiParser class to parse Midi files
|
||||
|
||||
[0.2.1923]
|
||||
Added MacOS support
|
||||
|
||||
[0.1.1823]
|
||||
Added more Builtin signals
|
||||
|
||||
[0.1.1818]
|
||||
Added ostd::String::fixedLength(...) method, with corresponding 'new_fixedLength' version.
|
||||
Added "KeyboardController" class to <Console.hpp> (implemented in <Keyboard.cpp>) to handle
|
||||
keypresses in the console in a cross-platform way
|
||||
Added helper functions in ostd::Utils for dealing with raw arrays
|
||||
|
|
@ -34,24 +34,37 @@ elif [[ "$(uname -s)" == MINGW64_NT* ]]; then
|
|||
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
|
||||
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/data
|
||||
mkdir -p $RELEASE_DIR/include/ostd/io
|
||||
mkdir -p $RELEASE_DIR/include/ostd/math
|
||||
mkdir -p $RELEASE_DIR/include/ostd/string
|
||||
mkdir -p $RELEASE_DIR/include/ostd/utils
|
||||
mkdir -p $RELEASE_DIR/include/ogfx/
|
||||
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/io -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/io \;
|
||||
find ../src/ostd/math -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/math \;
|
||||
find ../src/ostd/string -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/string \;
|
||||
find ../src/ostd/utils -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ostd/utils \;
|
||||
find ../src/ogfx -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx \;
|
||||
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 \;
|
||||
cp -r ../src/ostd/vendor/nlohmann $RELEASE_DIR/include/ostd/vendor/
|
||||
cp -r ../licences $RELEASE_DIR
|
||||
cp ../LICENSE $RELEASE_DIR/licences/OmniaFramework-LICENCE.txt
|
||||
|
||||
|
||||
# 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/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/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/vendor -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/vendor \;
|
||||
find ../src/ogfx/vendor/sdl3_gfx -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/vendor/sdl3_gfx \;
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
#include "Image.hpp"
|
||||
#include "io/Logger.hpp"
|
||||
#include <SDL2/SDL_render.h>
|
||||
#include <ogfx/BasicRenderer.hpp>
|
||||
#include <ogfx/WindowBase.hpp>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
void Image::destroy(void)
|
||||
{
|
||||
SDL_DestroyTexture(m_sdl_texture);
|
||||
m_loaded = false;
|
||||
m_sdl_texture = nullptr;
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
}
|
||||
|
||||
Image& Image::loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx)
|
||||
{
|
||||
if (!gfx.isInitialized())
|
||||
return *this; //TODO: Error
|
||||
m_sdl_texture = IMG_LoadTexture(gfx.getWindow().getSDLRenderer(), filePath.c_str());
|
||||
if (!m_sdl_texture)
|
||||
{
|
||||
OX_ERROR("Failed to load Image: %s", IMG_GetError());
|
||||
return *this;
|
||||
}
|
||||
SDL_QueryTexture(m_sdl_texture, nullptr, nullptr, &m_width, &m_height);
|
||||
m_loaded = true;
|
||||
setTypeName("ogfx::Image");
|
||||
validate();
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,215 +0,0 @@
|
|||
#include "WindowBase.hpp"
|
||||
#include "../ostd/utils/Time.hpp"
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_surface.h>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
WindowBase::~WindowBase(void)
|
||||
{
|
||||
onDestroy();
|
||||
SDL_FreeCursor(m_cursor_IBeam);
|
||||
SDL_FreeCursor(m_cursor_Arrow);
|
||||
SDL_DestroyRenderer(m_renderer);
|
||||
SDL_DestroyWindow(m_window);
|
||||
// IMG_Quit();
|
||||
SDL_Quit();
|
||||
TTF_Quit();
|
||||
}
|
||||
|
||||
void WindowBase::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) != 0)
|
||||
{
|
||||
printf( "SDL could not initialize! Error: %s\n", SDL_GetError() );
|
||||
exit(1);
|
||||
}
|
||||
int imgFlags = IMG_INIT_PNG;
|
||||
if (!(IMG_Init(imgFlags) & imgFlags))
|
||||
{
|
||||
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_SetWindowTitle(m_window, m_title.c_str());
|
||||
|
||||
m_cursor_Arrow = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_ARROW);
|
||||
m_cursor_IBeam = SDL_CreateSystemCursor(SDL_SystemCursor::SDL_SYSTEM_CURSOR_IBEAM);
|
||||
|
||||
m_initialized = true;
|
||||
m_running = true;
|
||||
|
||||
m_fixedUpdateTImer.create(60.0, [this](double frameTime_s){
|
||||
this->onFixedUpdate(frameTime_s);
|
||||
});
|
||||
|
||||
m_fpsUpdateTimer.create(1.0, [this](double frameTime_s){
|
||||
if (this->m_frameCount == 0) return;
|
||||
if (this->m_frameTimeAcc == 0) return;
|
||||
this->m_fps = (int32_t)(1.0f / (static_cast<double>(this->m_frameTimeAcc) / static_cast<double>(this->m_frameCount)));
|
||||
this->m_frameTimeAcc = 0;
|
||||
this->m_frameCount = 0;
|
||||
});
|
||||
|
||||
setTypeName("dragon::WindowBase");
|
||||
enableSignals(true);
|
||||
validate();
|
||||
|
||||
onInitialize();
|
||||
}
|
||||
|
||||
void WindowBase::close(void)
|
||||
{
|
||||
m_running = false;
|
||||
onClose();
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::RealTime, *this);
|
||||
}
|
||||
|
||||
void WindowBase::update(void)
|
||||
{
|
||||
if (!m_initialized) return;
|
||||
__handle_events();
|
||||
SDL_SetRenderDrawColor(m_renderer, m_clearColor.r, m_clearColor.g, m_clearColor.b, m_clearColor.a);
|
||||
if (m_refreshScreen)
|
||||
SDL_RenderClear(m_renderer);
|
||||
m_fixedUpdateTImer.update();
|
||||
onUpdate();
|
||||
onRender();
|
||||
SDL_RenderPresent(m_renderer);
|
||||
m_frameTimeAcc += m_fpsUpdateClock.restart(ostd::eTimeUnits::Seconds);
|
||||
m_frameCount++;
|
||||
m_fpsUpdateTimer.update();
|
||||
}
|
||||
|
||||
void WindowBase::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 WindowBase::setTitle(const ostd::String& title)
|
||||
{
|
||||
if (!isInitialized()) return;
|
||||
m_title = title;
|
||||
SDL_SetWindowTitle(m_window, m_title.c_str());
|
||||
}
|
||||
|
||||
void WindowBase::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 WindowBase::enableResizable(bool enable)
|
||||
{
|
||||
SDL_SetWindowResizable(m_window, (enable ? SDL_TRUE : SDL_FALSE));
|
||||
}
|
||||
|
||||
void WindowBase::setIcon(const ostd::String& iconFilePath)
|
||||
{
|
||||
SDL_Surface* appIcon = IMG_Load(iconFilePath);
|
||||
if (appIcon == nullptr)
|
||||
{
|
||||
//TODO: Error
|
||||
return;
|
||||
}
|
||||
SDL_SetWindowIcon(m_window, appIcon);
|
||||
SDL_FreeSurface(appIcon);
|
||||
}
|
||||
|
||||
void WindowBase::__handle_events(void)
|
||||
{
|
||||
if (!m_initialized) return;
|
||||
auto l_getMouseState = [this](void) -> MouseEventData {
|
||||
int32_t mx = 0, my = 0;
|
||||
uint32_t btn = SDL_GetMouseState(&mx, &my);
|
||||
MouseEventData::eButton button = MouseEventData::eButton::None;
|
||||
switch (btn)
|
||||
{
|
||||
case SDL_BUTTON(1): button = MouseEventData::eButton::Left; break;
|
||||
case SDL_BUTTON(2): button = MouseEventData::eButton::Middle; break;
|
||||
case SDL_BUTTON(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_QUIT)
|
||||
{
|
||||
m_running = false;
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this);
|
||||
}
|
||||
else if (event.type == SDL_WINDOWEVENT)
|
||||
{
|
||||
if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
|
||||
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_MOUSEMOTION)
|
||||
{
|
||||
MouseEventData mmd = l_getMouseState();
|
||||
if (isMouseDragEventEnabled() && mmd.button != MouseEventData::eButton::None)
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseDragged, ostd::tSignalPriority::RealTime, mmd);
|
||||
else
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd);
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
MouseEventData mmd = l_getMouseState();
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd);
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONUP)
|
||||
{
|
||||
MouseEventData mmd = l_getMouseState();
|
||||
switch (event.button.button)
|
||||
{
|
||||
case SDL_BUTTON(1): mmd.button = MouseEventData::eButton::Left; break;
|
||||
case SDL_BUTTON(2): mmd.button = MouseEventData::eButton::Middle; break;
|
||||
case SDL_BUTTON(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_KEYDOWN)
|
||||
{
|
||||
KeyEventData ked(*this, (int32_t)event.key.keysym.sym, 0, KeyEventData::eKeyEvent::Pressed);
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyPressed, ostd::tSignalPriority::RealTime, ked);
|
||||
}
|
||||
else if (event.type == SDL_KEYUP)
|
||||
{
|
||||
KeyEventData ked(*this, (int32_t)event.key.keysym.sym, 0, KeyEventData::eKeyEvent::Released);
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::KeyReleased, ostd::tSignalPriority::RealTime, ked);
|
||||
}
|
||||
else if (event.type == SDL_TEXTINPUT)
|
||||
{
|
||||
KeyEventData ked(*this, 0, event.text.text[0], KeyEventData::eKeyEvent::Text);
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::TextEntered, ostd::tSignalPriority::RealTime, ked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
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 <SDL2/SDL_surface.h>
|
||||
#include <ogfx/SDLInclude.hpp>
|
||||
#include <ostd/utils/Signals.hpp>
|
||||
#include <ostd/utils/Time.hpp>
|
||||
#include <ostd/io/IOHandlers.hpp>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
class WindowBase : public ostd::BaseObject
|
||||
{
|
||||
public: enum class eCursor { Arrow = 0, IBeam };
|
||||
public:
|
||||
inline WindowBase(void) { }
|
||||
~WindowBase(void);
|
||||
inline WindowBase(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 onRender(void) { }
|
||||
inline virtual void onUpdate(void) { }
|
||||
inline virtual void onFixedUpdate(double frameTime_s) { }
|
||||
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 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 getFPS(void) const { return m_fps; }
|
||||
inline int32_t getWindowWidth(void) const { return m_windowWidth; }
|
||||
inline int32_t getWindowHeight(void) const { return m_windowHeight; }
|
||||
inline bool isMouseDragEventEnabled(void) const { return m_deagEventEnabled; }
|
||||
inline void enableMouseDragEvent(bool enable = true) { m_deagEventEnabled = enable; }
|
||||
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:
|
||||
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 { "" };
|
||||
int32_t m_fps { 0 };
|
||||
|
||||
ostd::StepTimer m_fixedUpdateTImer;
|
||||
ostd::StepTimer m_fpsUpdateTimer;
|
||||
ostd::Timer m_fpsUpdateClock;
|
||||
uint64_t m_frameTimeAcc { 0 };
|
||||
int32_t m_frameCount { 0 };
|
||||
|
||||
bool m_deagEventEnabled { false };
|
||||
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 WindowResizedData : public ostd::BaseObject
|
||||
{
|
||||
public:
|
||||
inline WindowResizedData(WindowBase& 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::WindowResizedData");
|
||||
validate();
|
||||
}
|
||||
|
||||
public:
|
||||
int32_t new_width;
|
||||
int32_t new_height;
|
||||
int32_t old_width;
|
||||
int32_t old_height;
|
||||
WindowBase& parentWindow;
|
||||
};
|
||||
class MouseEventData : public ostd::BaseObject
|
||||
{
|
||||
public: enum class eButton { None = 0, Left, Middle, Right };
|
||||
public:
|
||||
inline MouseEventData(WindowBase& parent, int32_t mousex, int32_t mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn)
|
||||
{
|
||||
setTypeName("ogfx::MouseEventData");
|
||||
validate();
|
||||
}
|
||||
|
||||
public:
|
||||
int32_t position_x;
|
||||
int32_t position_y;
|
||||
eButton button;
|
||||
WindowBase& parentWindow;
|
||||
};
|
||||
class KeyEventData : public ostd::BaseObject
|
||||
{
|
||||
public: enum class eKeyEvent { Pressed = 0, Released, Text };
|
||||
public:
|
||||
inline KeyEventData(WindowBase& parent, int32_t key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt)
|
||||
{
|
||||
setTypeName("ogfx::KeyEventData");
|
||||
validate();
|
||||
}
|
||||
|
||||
public:
|
||||
int32_t keyCode;
|
||||
char text;
|
||||
eKeyEvent eventType;
|
||||
WindowBase& parentWindow;
|
||||
};
|
||||
}
|
||||
100
src/ogfx/gui/Events.hpp
Normal file
100
src/ogfx/gui/Events.hpp
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
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 <ostd/data/BaseObject.hpp>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
class WindowCore;
|
||||
namespace gui
|
||||
{
|
||||
class Widget;
|
||||
}
|
||||
class WindowResizedData : public ostd::BaseObject
|
||||
{
|
||||
public:
|
||||
inline WindowResizedData(WindowCore& 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::WindowResizedData");
|
||||
validate();
|
||||
}
|
||||
|
||||
public:
|
||||
int32_t new_width;
|
||||
int32_t new_height;
|
||||
int32_t old_width;
|
||||
int32_t old_height;
|
||||
WindowCore& parentWindow;
|
||||
};
|
||||
class MouseEventData : public ostd::BaseObject
|
||||
{
|
||||
public: enum class eButton { None = 0, Left, Middle, Right };
|
||||
public:
|
||||
inline MouseEventData(WindowCore& parent, float mousex, float mousey, eButton btn) : parentWindow(parent), position_x(mousex), position_y(mousey), button(btn)
|
||||
{
|
||||
setTypeName("ogfx::MouseEventData");
|
||||
validate();
|
||||
}
|
||||
|
||||
public:
|
||||
float position_x;
|
||||
float position_y;
|
||||
eButton button;
|
||||
gui::Widget* mousePressedOnWidget { nullptr };
|
||||
WindowCore& parentWindow;
|
||||
};
|
||||
class KeyEventData : public ostd::BaseObject
|
||||
{
|
||||
public: enum class eKeyEvent { Pressed = 0, Released, Text };
|
||||
public:
|
||||
inline KeyEventData(WindowCore& parent, int32_t key, char _text, eKeyEvent evt) : parentWindow(parent), keyCode(key), text(_text), eventType(evt)
|
||||
{
|
||||
setTypeName("ogfx::KeyEventData");
|
||||
validate();
|
||||
}
|
||||
|
||||
public:
|
||||
int32_t keyCode;
|
||||
char text;
|
||||
eKeyEvent eventType;
|
||||
WindowCore& parentWindow;
|
||||
};
|
||||
namespace gui
|
||||
{
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
inline Event(WindowCore& _window) : window(_window) { }
|
||||
inline void handle(void) { m_handled = true; }
|
||||
inline bool isHandled(void) const { return m_handled; }
|
||||
|
||||
public:
|
||||
WindowCore& window;
|
||||
WindowResizedData* windowResized { nullptr };
|
||||
MouseEventData* mouse { nullptr };
|
||||
KeyEventData* keyboard { nullptr };
|
||||
|
||||
private:
|
||||
bool m_handled { false };
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,26 @@
|
|||
/*
|
||||
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 "RawTextInput.hpp"
|
||||
#include <ogfx/WindowBase.hpp>
|
||||
#include <ostd/io/Logger.hpp>
|
||||
#include "../gui/Window.hpp"
|
||||
#include "../../io/Logger.hpp"
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
|
|
@ -272,13 +292,13 @@ namespace ogfx
|
|||
if (getParent().isMouseInside())
|
||||
{
|
||||
if (!m_ibeamCursorSet)
|
||||
window.setCursor(ogfx::WindowBase::eCursor::IBeam);
|
||||
window.setCursor(ogfx::WindowCore::eCursor::IBeam);
|
||||
m_ibeamCursorSet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_ibeamCursorSet)
|
||||
window.setCursor(ogfx::WindowBase::eCursor::Arrow);
|
||||
window.setCursor(ogfx::WindowCore::eCursor::Arrow);
|
||||
m_ibeamCursorSet = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <ogfx/BasicRenderer.hpp>
|
||||
#include <ogfx/render/BasicRenderer.hpp>
|
||||
#include <ostd/utils/Time.hpp>
|
||||
|
||||
namespace ogfx
|
||||
|
|
@ -170,11 +170,11 @@ namespace ogfx
|
|||
class RawTextInputEventListener : public RawTextInput::EventListener
|
||||
{
|
||||
public:
|
||||
inline RawTextInputEventListener(ogfx::gui::RawTextInput& _parent, ogfx::WindowBase& _window) : ogfx::gui::RawTextInput::EventListener::EventListener(_parent), window(_window) { }
|
||||
inline RawTextInputEventListener(ogfx::gui::RawTextInput& _parent, ogfx::WindowCore& _window) : ogfx::gui::RawTextInput::EventListener::EventListener(_parent), window(_window) { }
|
||||
void onSignalHandled(ostd::tSignal& signal) override;
|
||||
|
||||
public:
|
||||
ogfx::WindowBase& window;
|
||||
ogfx::WindowCore& window;
|
||||
bool m_ibeamCursorSet { false };
|
||||
};
|
||||
class RawTextInputNumberCharacterFilter : public RawTextInput::CharacterFilter
|
||||
90
src/ogfx/gui/Themes.hpp
Normal file
90
src/ogfx/gui/Themes.hpp
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
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 <ostd/data/Color.hpp>
|
||||
#include <ostd/math/Geometry.hpp>
|
||||
#include <variant>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
namespace gui
|
||||
{
|
||||
struct Theme
|
||||
{
|
||||
public: using ThemeValue = std::variant<int, float, bool, ostd::String, ostd::Color, ostd::Rectangle, ostd::Vec2>;
|
||||
public:
|
||||
inline Theme(bool blank = false)
|
||||
{
|
||||
if (blank) return;
|
||||
|
||||
set("window.backgroundColor", ostd::Colors::Black);
|
||||
|
||||
set("label.textColor", ostd::Colors::White);
|
||||
set("label.backgroundColor", ostd::Colors::Transparent);
|
||||
set("label.borderColor", ostd::Colors::White);
|
||||
set("label.fontSize", 20);
|
||||
set("label.borderRadius", 20);
|
||||
set("label.borderWidth", 2);
|
||||
set("label.showBackground", false);
|
||||
set("label.showBorder", false);
|
||||
set("label.padding", ostd::Rectangle { 5, 5, 5, 5 });
|
||||
}
|
||||
|
||||
inline Theme& blank(void)
|
||||
{
|
||||
m_values.clear();
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Theme& loadFromJsonFile(const ostd::String& jsonFilePath)
|
||||
{
|
||||
return *this; //TODO: Implement
|
||||
}
|
||||
|
||||
inline void set(const std::string& key, ThemeValue value)
|
||||
{
|
||||
m_values[key] = std::move(value);
|
||||
}
|
||||
|
||||
inline const ThemeValue* __get(const ostd::String& key) const
|
||||
{
|
||||
auto it = m_values.find(key);
|
||||
return it != m_values.end() ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T get(const ostd::String& key, const T& fallback) const
|
||||
{
|
||||
if (auto v = __get(key))
|
||||
{
|
||||
if (auto p = std::get_if<T>(v))
|
||||
return *p;
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<ostd::String, ThemeValue> m_values;
|
||||
};
|
||||
}
|
||||
}
|
||||
526
src/ogfx/gui/Widgets.cpp
Normal file
526
src/ogfx/gui/Widgets.cpp
Normal file
|
|
@ -0,0 +1,526 @@
|
|||
/*
|
||||
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 "Widgets.hpp"
|
||||
#include <ogfx/render/BasicRenderer.hpp>
|
||||
#include <ogfx/gui/Window.hpp>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
namespace gui
|
||||
{
|
||||
WidgetManager::WidgetManager(WindowCore& window, Widget& owner) : m_window(window), m_owner(owner)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
bool WidgetManager::hasWidget(Widget& widget)
|
||||
{
|
||||
bool found = std::ranges::find(m_widgetList, &widget) != m_widgetList.end();
|
||||
return found && widget.isValid();
|
||||
}
|
||||
|
||||
bool WidgetManager::requestFocus(Widget& widget)
|
||||
{
|
||||
if (!hasWidget(widget)) return false;
|
||||
if (&widget == m_focused) return true;
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (w->m_focused)
|
||||
{
|
||||
w->m_focused = false;
|
||||
w->onFocusLost(Event(m_window));
|
||||
}
|
||||
else
|
||||
w->m_focused = false;
|
||||
}
|
||||
widget.m_focused = true;
|
||||
widget.onFocusGained(Event(m_window));
|
||||
m_focused = &widget;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WidgetManager::addWidget(Widget& widget)
|
||||
{
|
||||
if (hasWidget(widget)) return false;
|
||||
widget.m_parent = &m_owner;
|
||||
m_widgetList.push_back(&widget);
|
||||
std::ranges::sort(m_widgetList, {}, [](Widget* w) {
|
||||
return w->m_zIndex;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget* WidgetManager::focusNext(void)
|
||||
{
|
||||
if (m_widgetList.empty())
|
||||
return nullptr;
|
||||
|
||||
Widget* next = nullptr;
|
||||
Widget* smallest = nullptr;
|
||||
|
||||
int32_t currentTabIndex = (m_focused != nullptr ? m_focused->m_tabIndex : std::numeric_limits<int32_t>::max());
|
||||
for (Widget* w : m_widgetList)
|
||||
{
|
||||
int tab_i = w->m_tabIndex;
|
||||
if (tab_i < 0) continue;
|
||||
if (!smallest || tab_i < smallest->m_tabIndex)
|
||||
smallest = w;
|
||||
if (tab_i > currentTabIndex)
|
||||
{
|
||||
if (!next || tab_i < next->m_tabIndex)
|
||||
next = w;
|
||||
}
|
||||
}
|
||||
Widget* w = next ? next : smallest;
|
||||
requestFocus(*w);
|
||||
return w;
|
||||
}
|
||||
|
||||
void WidgetManager::draw(ogfx::BasicRenderer2D& gfx)
|
||||
{
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
w->__draw(gfx);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::update(void)
|
||||
{
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
w->__update();
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onThemeApplied(const Theme& theme)
|
||||
{
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
w->__applyTheme(theme, true);
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onMousePressed(const Event& event)
|
||||
{
|
||||
for (int32_t i = m_widgetList.size() - 1; i >= 0; i--)
|
||||
{
|
||||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
|
||||
continue;
|
||||
w->__onMousePressed(event);
|
||||
m_mousePressedOnWidget = w;
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onMouseReleased(const Event& event)
|
||||
{
|
||||
for (int32_t i = m_widgetList.size() - 1; i >= 0; i--)
|
||||
{
|
||||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
event.mouse->mousePressedOnWidget = m_mousePressedOnWidget;
|
||||
w->__onMouseReleased(event);
|
||||
requestFocus(*w);
|
||||
m_mousePressedOnWidget = nullptr;
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onMouseMoved(const Event& event)
|
||||
{
|
||||
for (int32_t i = m_widgetList.size() - 1; i >= 0; i--)
|
||||
{
|
||||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
|
||||
continue;
|
||||
w->__onMouseMoved(event);
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onMouseDragged(const Event& event)
|
||||
{
|
||||
for (int32_t i = m_widgetList.size() - 1; i >= 0; i--)
|
||||
{
|
||||
Widget* w = m_widgetList[i];
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
if (!w->contains(event.mouse->position_x, event.mouse->position_y, true))
|
||||
continue;
|
||||
w->__onMouseDragged(event);
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onKeyPressed(const Event& event)
|
||||
{
|
||||
if (!m_focused) return;
|
||||
m_focused->__onKeyPressed(event);
|
||||
}
|
||||
|
||||
void WidgetManager::onKeyReleased(const Event& event)
|
||||
{
|
||||
if (!m_focused) return;
|
||||
m_focused->__onKeyReleased(event);
|
||||
if (m_tabNavigationEnabled && event.keyboard->keyCode == SDLK_TAB)
|
||||
focusNext();
|
||||
}
|
||||
|
||||
void WidgetManager::onTextEntered(const Event& event)
|
||||
{
|
||||
if (!m_focused) return;
|
||||
m_focused->__onTextEntered(event);
|
||||
}
|
||||
|
||||
void WidgetManager::onWindowClosed(const Event& event)
|
||||
{
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
w->__onWindowClosed(event);
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onWindowResized(const Event& event)
|
||||
{
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
w->__onWindowResized(event);
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onWindowFocused(const Event& event)
|
||||
{
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
w->__onWIndowFocused(event);
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void WidgetManager::onWindowFocusLost(const Event& event)
|
||||
{
|
||||
for (auto& w : m_widgetList)
|
||||
{
|
||||
if (w == nullptr) continue;
|
||||
if (w->isInvalid()) continue;
|
||||
w->__onWindowFocusLost(event);
|
||||
if (event.isHandled())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Widget::Widget(const ostd::Rectangle& bounds, WindowCore& window) : Rectangle(bounds), m_widgets(window, *this)
|
||||
{
|
||||
m_window = &window;
|
||||
}
|
||||
|
||||
bool Widget::addChild(Widget& child)
|
||||
{
|
||||
if (!m_allowChildren)
|
||||
return false;
|
||||
return m_widgets.addWidget(child);
|
||||
}
|
||||
|
||||
ostd::Vec2 Widget::getGlobalPosition(void) const
|
||||
{
|
||||
ostd::Vec2 glob = getPosition();
|
||||
if (!m_rootChild && m_parent != nullptr)
|
||||
glob += m_parent->getGlobalPosition();
|
||||
return glob;
|
||||
}
|
||||
|
||||
void Widget::applyThemeValue(Theme& theme, const ostd::String& key, Theme::ThemeValue value, bool propagate)
|
||||
{
|
||||
auto currentValue = theme.__get(key);
|
||||
if (currentValue == nullptr) return;
|
||||
theme.set(key, value);
|
||||
__applyTheme(theme, propagate);
|
||||
theme.set(key, *currentValue);
|
||||
}
|
||||
|
||||
void Widget::__draw(ogfx::BasicRenderer2D& gfx)
|
||||
{
|
||||
if (isDrawBoxEnabled())
|
||||
gfx.fillRect({ getGlobalPosition(), getSize() }, getDrawBoxColor());
|
||||
onDraw(gfx);
|
||||
if (hasChildren())
|
||||
m_widgets.draw(gfx);
|
||||
}
|
||||
|
||||
void Widget::__update(void)
|
||||
{
|
||||
onUpdate();
|
||||
if (hasChildren())
|
||||
m_widgets.update();
|
||||
}
|
||||
|
||||
void Widget::__onMousePressed(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onMousePressed(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onMousePressed)
|
||||
callback_onMousePressed(event);
|
||||
onMousePressed(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onMouseReleased(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onMouseReleased(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onMouseReleased)
|
||||
callback_onMouseReleased(event);
|
||||
onMouseReleased(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onMouseMoved(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onMouseMoved(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onMouseMoved)
|
||||
callback_onMouseMoved(event);
|
||||
onMouseMoved(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onMouseDragged(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onMouseDragged(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onMouseDragged)
|
||||
callback_onMouseDragged(event);
|
||||
onMouseDragged(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onKeyPressed(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onKeyPressed(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onKeyPressed)
|
||||
callback_onKeyPressed(event);
|
||||
onKeyPressed(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onKeyReleased(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onKeyReleased(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onKeyReleased)
|
||||
callback_onKeyReleased(event);
|
||||
onKeyReleased(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onTextEntered(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onTextEntered(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onTextEntered)
|
||||
callback_onTextEntered(event);
|
||||
onTextEntered(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onWindowClosed(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onWindowClosed(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onWindowClosed)
|
||||
callback_onWindowClosed(event);
|
||||
onWindowClosed(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onWindowResized(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onWindowResized(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onWindowResized)
|
||||
callback_onWindowResized(event);
|
||||
onWindowResized(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onWIndowFocused(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onWindowFocused(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onWindowFocused)
|
||||
callback_onWindowFocused(event);
|
||||
onWindowFocused(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__onWindowFocusLost(const Event& event)
|
||||
{
|
||||
if (hasChildren())
|
||||
m_widgets.onWindowFocusLost(event);
|
||||
if (!event.isHandled())
|
||||
{
|
||||
if (callback_onWindowFocusLost)
|
||||
callback_onWindowFocusLost(event);
|
||||
onWindowFocusLost(event);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::__applyTheme(const Theme& theme, bool propagate)
|
||||
{
|
||||
if (propagate && hasChildren())
|
||||
m_widgets.onThemeApplied(theme);
|
||||
applyTheme(theme);
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace widgets
|
||||
{
|
||||
RootWidget::RootWidget(WindowCore& window) : Widget({ 0, 0, 0, 0 }, window)
|
||||
{
|
||||
m_rootChild = true;
|
||||
setSize(static_cast<float>(window.getWindowWidth()), static_cast<float>(window.getWindowHeight()));
|
||||
enableDrawBox();
|
||||
setDrawBoxColor(window.getClearColor());
|
||||
setTypeName("ogfx::gui::widgets::RootWidget");
|
||||
}
|
||||
|
||||
void RootWidget::onWindowResized(const Event& event)
|
||||
{
|
||||
setSize(static_cast<float>(event.windowResized->new_width), static_cast<float>(event.windowResized->new_height));
|
||||
}
|
||||
|
||||
void RootWidget::applyTheme(const Theme& theme)
|
||||
{
|
||||
setDrawBoxColor(theme.get<ostd::Color>("window.backgroundColor", getWindow().getClearColor()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Label& Label::create(const ostd::String& text)
|
||||
{
|
||||
setText(text);
|
||||
setPadding({ 5, 5, 5, 5 });
|
||||
setTypeName("ogfx::gui::widgets::Label");
|
||||
disableDrawBox();
|
||||
enableBackground(false);
|
||||
validate();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Label::applyTheme(const Theme& theme)
|
||||
{
|
||||
setColor(theme.get<ostd::Color>("label.textColor", ostd::Colors::White));
|
||||
setBackGroundColor(theme.get<ostd::Color>("label.backgroundColor", ostd::Colors::Transparent));
|
||||
setFontSize(theme.get<int32_t>("label.fontSize", 20));
|
||||
m_borderRadius = theme.get<int32_t>("label.borderRadius", 10);
|
||||
m_borderWidth = theme.get<int32_t>("label.borderWidth", 2);
|
||||
m_showBorder = theme.get<bool>("label.showBorder", false);
|
||||
m_borderColor = theme.get<ostd::Color>("label.borderColor", ostd::Colors::White);
|
||||
enableBackground(theme.get<bool>("label.showBackground", false));
|
||||
setPadding(theme.get<ostd::Rectangle>("label.padding", { 5, 5, 5, 5 }));
|
||||
}
|
||||
|
||||
void Label::onDraw(ogfx::BasicRenderer2D& gfx)
|
||||
{
|
||||
if (m_textChanged)
|
||||
__update_size(gfx);
|
||||
if (m_showBackground)
|
||||
gfx.fillRoundRect({ getGlobalPosition(), getSize() }, m_backgroundColor, m_borderRadius);
|
||||
if (m_showBorder)
|
||||
gfx.drawRoundRect({ getGlobalPosition(), getSize() }, m_borderColor, m_borderRadius, m_borderWidth);
|
||||
gfx.drawString(getText(), getGlobalPosition() + ostd::Vec2 { getPadding().left(), getPadding().top() }, getColor());
|
||||
}
|
||||
|
||||
void Label::setText(const ostd::String& text)
|
||||
{
|
||||
m_text = text;
|
||||
m_textChanged = true;
|
||||
}
|
||||
|
||||
void Label::__update_size(ogfx::BasicRenderer2D& gfx)
|
||||
{
|
||||
auto size = gfx.getStringSize(getText(), getFontSize());
|
||||
size.x += getPadding().left();
|
||||
size.x += getPadding().right();
|
||||
size.y += getPadding().top();
|
||||
size.y += getPadding().bottom();
|
||||
setSize({ static_cast<float>(size.x), static_cast<float>(size.y) });
|
||||
m_textChanged = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
226
src/ogfx/gui/Widgets.hpp
Normal file
226
src/ogfx/gui/Widgets.hpp
Normal file
|
|
@ -0,0 +1,226 @@
|
|||
/*
|
||||
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 <ostd/data/BaseObject.hpp>
|
||||
#include <ostd/math/Geometry.hpp>
|
||||
#include <ostd/data/Color.hpp>
|
||||
#include <ogfx/gui/Themes.hpp>
|
||||
#include <functional>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
class BasicRenderer2D;
|
||||
class WindowCore;
|
||||
namespace gui
|
||||
{
|
||||
class Event;
|
||||
class Widget;
|
||||
class WidgetManager
|
||||
{
|
||||
public:
|
||||
WidgetManager(WindowCore& window, Widget& owner);
|
||||
bool hasWidget(Widget& widget);
|
||||
bool requestFocus(Widget& widget);
|
||||
bool addWidget(Widget& widget);
|
||||
Widget* focusNext(void);
|
||||
|
||||
void draw(ogfx::BasicRenderer2D& gfx);
|
||||
void update(void);
|
||||
void onThemeApplied(const Theme& theme);
|
||||
void onMousePressed(const Event& event);
|
||||
void onMouseReleased(const Event& event);
|
||||
void onMouseMoved(const Event& event);
|
||||
void onMouseDragged(const Event& event);
|
||||
void onKeyPressed(const Event& event);
|
||||
void onKeyReleased(const Event& event);
|
||||
void onTextEntered(const Event& event);
|
||||
void onWindowClosed(const Event& event);
|
||||
void onWindowResized(const Event& event);
|
||||
void onWindowFocused(const Event& event);
|
||||
void onWindowFocusLost(const Event& event);
|
||||
|
||||
inline int32_t widgetCount(void) const { return m_widgetList.size(); }
|
||||
inline WindowCore& getWindow(void) { return m_window; }
|
||||
|
||||
private:
|
||||
WindowCore& m_window;
|
||||
Widget& m_owner;
|
||||
std::vector<Widget*> m_widgetList;
|
||||
Widget* m_focused { nullptr };
|
||||
bool m_tabNavigationEnabled { true };
|
||||
Widget* m_mousePressedOnWidget { nullptr };
|
||||
};
|
||||
class Widget : public ostd::BaseObject, public ostd::Rectangle
|
||||
{
|
||||
public: using EventCallback = std::function<void(const Event&)>;
|
||||
public:
|
||||
Widget(const ostd::Rectangle& bounds, WindowCore& window);
|
||||
bool addChild(Widget& child);
|
||||
ostd::Vec2 getGlobalPosition(void) const;
|
||||
virtual void applyTheme(const Theme& theme) = 0;
|
||||
void applyThemeValue(Theme& theme, const ostd::String& key, Theme::ThemeValue value, bool propagate);
|
||||
|
||||
inline virtual void onDraw(ogfx::BasicRenderer2D& gfx) { }
|
||||
inline virtual void onUpdate(void) { }
|
||||
|
||||
inline virtual void onMousePressed(const Event& event) { }
|
||||
inline virtual void onMouseReleased(const Event& event) { }
|
||||
inline virtual void onMouseMoved(const Event& event) { }
|
||||
inline virtual void onMouseDragged(const Event& event) { }
|
||||
inline virtual void onKeyPressed(const Event& event) { }
|
||||
inline virtual void onKeyReleased(const Event& event) { }
|
||||
inline virtual void onTextEntered(const Event& event) { }
|
||||
inline virtual void onFocusGained(const Event& event) { }
|
||||
inline virtual void onFocusLost(const Event& event) { }
|
||||
inline virtual void onWindowClosed(const Event& event) { }
|
||||
inline virtual void onWindowResized(const Event& event) { }
|
||||
inline virtual void onWindowFocused(const Event& event) { }
|
||||
inline virtual void onWindowFocusLost(const Event& event) { }
|
||||
|
||||
void __draw(ogfx::BasicRenderer2D& gfx);
|
||||
void __update(void);
|
||||
void __onMousePressed(const Event& event);
|
||||
void __onMouseReleased(const Event& event);
|
||||
void __onMouseMoved(const Event& event);
|
||||
void __onMouseDragged(const Event& event);
|
||||
void __onKeyPressed(const Event& event);
|
||||
void __onKeyReleased(const Event& event);
|
||||
void __onTextEntered(const Event& event);
|
||||
void __onWindowClosed(const Event& event);
|
||||
void __onWindowResized(const Event& event);
|
||||
void __onWIndowFocused(const Event& event);
|
||||
void __onWindowFocusLost(const Event& event);
|
||||
void __applyTheme(const Theme& theme, bool propagate);
|
||||
|
||||
inline virtual void setMousePressedCallback(EventCallback callback) { callback_onMousePressed = callback; }
|
||||
inline virtual void setMouseReleasedCallback(EventCallback callback) { callback_onMouseReleased = callback; }
|
||||
inline virtual void setMouseMovedCallback(EventCallback callback) { callback_onMouseMoved = callback; }
|
||||
inline virtual void setMouseDraggedCallback(EventCallback callback) { callback_onMouseDragged = callback; }
|
||||
inline virtual void setKeyPressedCallback(EventCallback callback) { callback_onKeyPressed = callback; }
|
||||
inline virtual void setKeyReleasedCallback(EventCallback callback) { callback_onKeyReleased = callback; }
|
||||
inline virtual void setTextEnteredCallback(EventCallback callback) { callback_onTextEntered = callback; }
|
||||
inline virtual void setWindowClosedCallback(EventCallback callback) { callback_onWindowClosed = callback; }
|
||||
inline virtual void setWindowResizedCallback(EventCallback callback) { callback_onWindowResized = callback; }
|
||||
inline virtual void setWIndowFocusedCallback(EventCallback callback) { callback_onWindowFocused = callback; }
|
||||
inline virtual void setWindowFocusLostCallback(EventCallback callback) { callback_onWindowFocusLost = callback; }
|
||||
|
||||
inline bool hasChildren(void) const { return m_allowChildren && m_widgets.widgetCount() > 0; }
|
||||
inline virtual bool isInvalid(void) const override { return ostd::BaseObject::isInvalid() || (m_parent == nullptr && !m_rootChild); }
|
||||
inline void setTabIndex(int32_t tabIndex) { m_tabIndex = tabIndex; }
|
||||
inline int32_t getTabIndex(void) const { return m_tabIndex; }
|
||||
inline bool isFocused(void) const { return m_focused; }
|
||||
inline WindowCore& getWindow(void) { return *m_window; }
|
||||
inline Widget* getParent(void) { return m_parent; }
|
||||
inline int32_t getZIndex(void) const { return m_zIndex; }
|
||||
inline bool isChildrenEnabled(void) const { return m_allowChildren; }
|
||||
inline void setPadding(const ostd::Rectangle& pad) { m_padding = pad; }
|
||||
inline Rectangle getPadding(void) { return m_padding; }
|
||||
|
||||
protected:
|
||||
inline void disableChildren(void) { m_allowChildren = false; }
|
||||
inline void disableDrawBox(void) { m_drawBox = false; }
|
||||
inline void enableDrawBox(void) { m_drawBox = true; }
|
||||
inline bool isDrawBoxEnabled(void) const { return m_drawBox; }
|
||||
inline void setDrawBoxColor(const ostd::Color& color) { m_drawBoxColor = color; }
|
||||
inline ostd::Color getDrawBoxColor(void) { return m_drawBoxColor; }
|
||||
|
||||
protected:
|
||||
bool m_rootChild { false };
|
||||
|
||||
EventCallback callback_onMousePressed { nullptr };
|
||||
EventCallback callback_onMouseReleased { nullptr };
|
||||
EventCallback callback_onMouseMoved { nullptr };
|
||||
EventCallback callback_onMouseDragged { nullptr };
|
||||
EventCallback callback_onKeyPressed { nullptr };
|
||||
EventCallback callback_onKeyReleased { nullptr };
|
||||
EventCallback callback_onTextEntered { nullptr };
|
||||
EventCallback callback_onWindowClosed { nullptr };
|
||||
EventCallback callback_onWindowResized { nullptr };
|
||||
EventCallback callback_onWindowFocused { nullptr };
|
||||
EventCallback callback_onWindowFocusLost { nullptr };
|
||||
|
||||
private:
|
||||
WindowCore* m_window { nullptr };
|
||||
Widget* m_parent { nullptr };
|
||||
bool m_focused { false };
|
||||
int32_t m_tabIndex { -1 };
|
||||
int32_t m_zIndex { -1 };
|
||||
WidgetManager m_widgets;
|
||||
bool m_allowChildren { true };
|
||||
|
||||
bool m_drawBox { true };
|
||||
ostd::Color m_drawBoxColor { 255, 0, 0 };
|
||||
|
||||
ostd::Rectangle m_padding { 0, 0, 0, 0 };
|
||||
|
||||
friend class WidgetManager;
|
||||
};
|
||||
namespace widgets
|
||||
{
|
||||
class RootWidget : public Widget
|
||||
{
|
||||
public:
|
||||
RootWidget(WindowCore& window);
|
||||
void onWindowResized(const Event& event) override;
|
||||
void applyTheme(const Theme& theme) override;
|
||||
|
||||
private:
|
||||
};
|
||||
class Label : public Widget
|
||||
{
|
||||
public:
|
||||
inline Label(WindowCore& window) : Widget({ 0, 0, 0, 0 }, window) { create(""); }
|
||||
inline Label(WindowCore& window, const ostd::String& text) : Widget({ 0, 0, 0, 0 }, window) { create(text); }
|
||||
Label& create(const ostd::String& text);
|
||||
void applyTheme(const Theme& theme) override;
|
||||
void onDraw(ogfx::BasicRenderer2D& gfx) override;
|
||||
void setText(const ostd::String& text);
|
||||
inline ostd::String getText(void) const { return m_text; }
|
||||
inline ostd::Color getColor(void) const { return m_color; }
|
||||
inline void setColor(const ostd::Color& color) { m_color = color; }
|
||||
inline int32_t getFontSize(void) const { return m_fontSize; }
|
||||
inline void setFontSize(int32_t fontSize) { m_fontSize = fontSize; }
|
||||
inline void setBackGroundColor(const ostd::Color& color) { m_backgroundColor = color; }
|
||||
inline ostd::Color getBackgroundColor(const ostd::Color& color) { return m_backgroundColor; }
|
||||
inline void enableBackground(bool enable = true) { m_showBackground = enable; }
|
||||
inline bool isBackgoundEnabled(void) const { return m_showBackground; }
|
||||
|
||||
private:
|
||||
void __update_size(ogfx::BasicRenderer2D& gfx);
|
||||
|
||||
private:
|
||||
ostd::String m_text { "" };
|
||||
bool m_textChanged { false };
|
||||
int32_t m_fontSize { 20 };
|
||||
ostd::Color m_color { 255, 255, 255 };
|
||||
int32_t m_borderRadius { 10 };
|
||||
int32_t m_borderWidth { 2 };
|
||||
bool m_showBorder { false };
|
||||
bool m_showBackground { false };
|
||||
ostd::Color m_backgroundColor { ostd::Colors::Transparent };
|
||||
ostd::Color m_borderColor { 255, 255, 255 };
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
450
src/ogfx/gui/Window.cpp
Normal file
450
src/ogfx/gui/Window.cpp
Normal file
|
|
@ -0,0 +1,450 @@
|
|||
/*
|
||||
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 "Window.hpp"
|
||||
#include "../../ostd/utils/Time.hpp"
|
||||
#include <SDL3/SDL_events.h>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
const Uint32 REDRAW_EVENT = SDL_RegisterEvents(1);
|
||||
|
||||
WindowCore::~WindowCore(void)
|
||||
{
|
||||
__on_window_destroy();
|
||||
SDL_DestroyCursor(m_cursor_IBeam);
|
||||
SDL_DestroyCursor(m_cursor_Arrow);
|
||||
SDL_DestroyRenderer(m_renderer);
|
||||
SDL_DestroyWindow(m_window);
|
||||
SDLSysten::release();
|
||||
}
|
||||
|
||||
void WindowCore::initialize(int32_t width, int32_t height, const ostd::String& title)
|
||||
{
|
||||
if (m_initialized) return;
|
||||
SDLSysten::acquire();
|
||||
m_windowWidth = width;
|
||||
m_windowHeight = height;
|
||||
m_title = title;
|
||||
setBlockingEventsRefreshFPS(DefaultBlockingEventsFPS);
|
||||
|
||||
m_window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOW_RESIZABLE);
|
||||
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_wout.attachWindow(*this);
|
||||
m_wout.setFontSize(22);
|
||||
m_wout.setConsoleMaxCharacters({ 1000, 1000 });
|
||||
m_wout.setConsolePosition({ 5, 5 });
|
||||
m_wout.setWrapMode(ogfx::GraphicsWindowOutputHandler::eWrapMode::NewLine);
|
||||
m_wout.setDefaultForegroundColor({ 255, 255, 255, 255 });
|
||||
|
||||
m_initialized = true;
|
||||
m_running = true;
|
||||
|
||||
setTypeName("ogfx::WindowCore");
|
||||
enableSignals(true);
|
||||
validate();
|
||||
setSize(m_windowWidth, m_windowHeight);
|
||||
|
||||
connectSignal(ostd::tBuiltinSignals::KeyPressed);
|
||||
connectSignal(ostd::tBuiltinSignals::KeyReleased);
|
||||
connectSignal(ostd::tBuiltinSignals::TextEntered);
|
||||
connectSignal(ostd::tBuiltinSignals::MousePressed);
|
||||
connectSignal(ostd::tBuiltinSignals::MouseReleased);
|
||||
connectSignal(ostd::tBuiltinSignals::MouseMoved);
|
||||
connectSignal(ostd::tBuiltinSignals::MouseMoved);
|
||||
connectSignal(ostd::tBuiltinSignals::OnGuiEvent);
|
||||
connectSignal(ostd::tBuiltinSignals::WindowClosed);
|
||||
connectSignal(ostd::tBuiltinSignals::WindowResized);
|
||||
connectSignal(ostd::tBuiltinSignals::WindowFocused);
|
||||
connectSignal(ostd::tBuiltinSignals::WindowLostFocus);
|
||||
|
||||
__on_window_init(width, height, title);
|
||||
}
|
||||
|
||||
void WindowCore::mainLoop(void)
|
||||
{
|
||||
if (isInitialized())
|
||||
__main_loop();
|
||||
}
|
||||
|
||||
void WindowCore::close(void)
|
||||
{
|
||||
__on_window_close();
|
||||
m_running = false;
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowClosed, ostd::tSignalPriority::Normal, *this);
|
||||
}
|
||||
|
||||
void WindowCore::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 WindowCore::setTitle(const ostd::String& title)
|
||||
{
|
||||
if (!isInitialized()) return;
|
||||
m_title = title;
|
||||
SDL_SetWindowTitle(m_window, m_title.c_str());
|
||||
}
|
||||
|
||||
void WindowCore::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 WindowCore::enableResizable(bool enable)
|
||||
{
|
||||
SDL_SetWindowResizable(m_window, enable);
|
||||
m_resizeable = enable;
|
||||
}
|
||||
|
||||
void WindowCore::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 WindowCore::setBlockingEventsRefreshFPS(uint32_t fps)
|
||||
{
|
||||
if (fps == 0 || fps > MaxBlockingEventsFPS)
|
||||
{
|
||||
setBlockingEventsRefreshFPS(DefaultBlockingEventsFPS);
|
||||
return;
|
||||
}
|
||||
m_blockingEventsDelay = static_cast<int>(std::floor((1.0 / (double)fps) * 1000));
|
||||
}
|
||||
|
||||
void WindowCore::requestRedraw(void)
|
||||
{
|
||||
SDL_Event e{};
|
||||
SDL_zero(e);
|
||||
e.type = REDRAW_EVENT;
|
||||
SDL_PushEvent(&e);
|
||||
}
|
||||
|
||||
void WindowCore::handleSignal(ostd::tSignal& signal)
|
||||
{
|
||||
__on_signal(signal);
|
||||
}
|
||||
|
||||
MouseEventData WindowCore::get_mouse_state(void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
void WindowCore::handle_events(void)
|
||||
{
|
||||
if (!isInitialized()) return;
|
||||
SDL_Event event;
|
||||
|
||||
if (isBlockingEventsEnabled())
|
||||
{
|
||||
if (SDL_WaitEventTimeout(&event, m_blockingEventsDelay))
|
||||
__handle_event(event);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (SDL_PollEvent(&event))
|
||||
__handle_event(event);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowCore::before_render(void)
|
||||
{
|
||||
SDL_SetRenderDrawColor(m_renderer, getClearColor().r, getClearColor().g, getClearColor().b, getClearColor().a);
|
||||
if (m_refreshScreen)
|
||||
SDL_RenderClear(m_renderer);
|
||||
wout().beginFrame();
|
||||
}
|
||||
|
||||
void WindowCore::after_render(void)
|
||||
{
|
||||
SDL_RenderPresent(m_renderer);
|
||||
}
|
||||
|
||||
void WindowCore::__handle_event(SDL_Event& event)
|
||||
{
|
||||
if (event.type == REDRAW_EVENT)
|
||||
{
|
||||
//Doesn't need to do anything, the event exists just to make SDL_WaitEventTimeout() return early
|
||||
}
|
||||
else if (event.type == SDL_EVENT_QUIT)
|
||||
{
|
||||
close();
|
||||
}
|
||||
else if (event.type == SDL_EVENT_WINDOW_FOCUS_GAINED)
|
||||
{
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowFocused, ostd::tSignalPriority::RealTime, *this);
|
||||
}
|
||||
else if (event.type == SDL_EVENT_WINDOW_FOCUS_LOST)
|
||||
{
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::WindowLostFocus, ostd::tSignalPriority::RealTime, *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 = get_mouse_state();
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MouseMoved, ostd::tSignalPriority::RealTime, mmd);
|
||||
}
|
||||
else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN)
|
||||
{
|
||||
MouseEventData mmd = get_mouse_state();
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::MousePressed, ostd::tSignalPriority::RealTime, mmd);
|
||||
}
|
||||
else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP)
|
||||
{
|
||||
MouseEventData mmd = get_mouse_state();
|
||||
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);
|
||||
}
|
||||
__on_event(event);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void GraphicsWindow::__on_window_init(int32_t width, int32_t height, const ostd::String& title)
|
||||
{
|
||||
SDL_SetWindowResizable(m_window, false);
|
||||
|
||||
m_fixedUpdateTImer.create(60.0, [this](double frameTime_s){
|
||||
this->onFixedUpdate(frameTime_s);
|
||||
});
|
||||
|
||||
m_fpsUpdateTimer.create(1.0, [this](double frameTime_s){
|
||||
if (this->m_frameCount == 0) return;
|
||||
if (this->m_frameTimeAcc == 0) return;
|
||||
this->m_fps = (int32_t)(1.0f / (static_cast<double>(this->m_frameTimeAcc) / static_cast<double>(this->m_frameCount)));
|
||||
this->m_frameTimeAcc = 0;
|
||||
this->m_frameCount = 0;
|
||||
});
|
||||
|
||||
setTypeName("ogfx::GraphicsWindow");
|
||||
onInitialize();
|
||||
}
|
||||
|
||||
void GraphicsWindow::__on_window_close(void)
|
||||
{
|
||||
onClose();
|
||||
}
|
||||
|
||||
void GraphicsWindow::__main_loop(void)
|
||||
{
|
||||
handle_events();
|
||||
before_render();
|
||||
m_fixedUpdateTImer.update();
|
||||
onUpdate();
|
||||
onRender();
|
||||
after_render();
|
||||
m_frameTimeAcc += m_fpsUpdateClock.restart(ostd::eTimeUnits::Seconds);
|
||||
m_frameCount++;
|
||||
m_fpsUpdateTimer.update();
|
||||
}
|
||||
|
||||
void GraphicsWindow::__on_signal(ostd::tSignal& signal)
|
||||
{
|
||||
onSignal(signal);
|
||||
}
|
||||
|
||||
void GraphicsWindow::__on_event(SDL_Event& event)
|
||||
{
|
||||
onSDLEvent(event);
|
||||
}
|
||||
|
||||
void GraphicsWindow::__on_window_destroy(void)
|
||||
{
|
||||
onDestroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
namespace gui
|
||||
{
|
||||
void Window::addWidget(Widget& widget)
|
||||
{
|
||||
m_rootWidget.addChild(widget);
|
||||
setTheme(*m_guiTheme);
|
||||
}
|
||||
|
||||
void Window::setTheme(const gui::Theme& theme)
|
||||
{
|
||||
m_guiTheme = &theme;
|
||||
m_rootWidget.__applyTheme(theme, true);
|
||||
}
|
||||
|
||||
void Window::__on_window_init(int32_t width, int32_t height, const ostd::String& title)
|
||||
{
|
||||
enableBlockingEvents();
|
||||
setTypeName("ogfx::gui::Window");
|
||||
m_gfx.init(*this);
|
||||
loadDefaultTHeme();
|
||||
onInitialize();
|
||||
}
|
||||
|
||||
void Window::__on_window_close(void)
|
||||
{
|
||||
onClose();
|
||||
}
|
||||
|
||||
void Window::__main_loop(void)
|
||||
{
|
||||
while (isRunning())
|
||||
{
|
||||
handle_events();
|
||||
before_render();
|
||||
m_rootWidget.__update();
|
||||
m_rootWidget.__draw(m_gfx);
|
||||
onRedraw(m_gfx);
|
||||
after_render();
|
||||
}
|
||||
}
|
||||
|
||||
void Window::__on_signal(ostd::tSignal& signal)
|
||||
{
|
||||
Event evt(*this);
|
||||
if (signal.ID == ostd::tBuiltinSignals::WindowClosed)
|
||||
{
|
||||
m_rootWidget.__onWindowClosed(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::WindowFocused)
|
||||
{
|
||||
m_rootWidget.__onWIndowFocused(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::WindowLostFocus)
|
||||
{
|
||||
m_rootWidget.__onWindowFocusLost(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::WindowResized)
|
||||
{
|
||||
evt.windowResized = &(ogfx::WindowResizedData&)signal.userData;
|
||||
m_rootWidget.__onWindowResized(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::MouseMoved)
|
||||
{
|
||||
evt.mouse = &(ogfx::MouseEventData&)signal.userData;
|
||||
m_rootWidget.__onMouseMoved(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::MousePressed)
|
||||
{
|
||||
evt.mouse = &(ogfx::MouseEventData&)signal.userData;
|
||||
m_rootWidget.__onMousePressed(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::MouseReleased)
|
||||
{
|
||||
evt.mouse = &(ogfx::MouseEventData&)signal.userData;
|
||||
m_rootWidget.__onMouseReleased(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::KeyPressed)
|
||||
{
|
||||
evt.keyboard = &(ogfx::KeyEventData&)signal.userData;
|
||||
m_rootWidget.__onKeyPressed(evt);
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::KeyReleased)
|
||||
{
|
||||
evt.keyboard = &(ogfx::KeyEventData&)signal.userData;
|
||||
m_rootWidget.__onKeyReleased(evt);
|
||||
if (evt.keyboard->keyCode == SDLK_ESCAPE)
|
||||
close();
|
||||
}
|
||||
else if (signal.ID == ostd::tBuiltinSignals::TextEntered)
|
||||
{
|
||||
evt.keyboard = &(ogfx::KeyEventData&)signal.userData;
|
||||
m_rootWidget.__onTextEntered(evt);
|
||||
}
|
||||
onSignal(signal);
|
||||
}
|
||||
|
||||
void Window::__on_event(SDL_Event& event)
|
||||
{
|
||||
onSDLEvent(event);
|
||||
}
|
||||
|
||||
void Window::__on_window_destroy(void)
|
||||
{
|
||||
onDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
186
src/ogfx/gui/Window.hpp
Normal file
186
src/ogfx/gui/Window.hpp
Normal file
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
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>
|
||||
#include <ogfx/gui/Events.hpp>
|
||||
#include <ogfx/gui/Widgets.hpp>
|
||||
#include <ogfx/render/BasicRenderer.hpp>
|
||||
#include <ogfx/gui/WindowOutputHandler.hpp>
|
||||
#include <ogfx/gui/Themes.hpp>
|
||||
|
||||
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& title) { initialize(width, height, title); }
|
||||
void initialize(int32_t width, int32_t height, const ostd::String& title);
|
||||
void mainLoop(void);
|
||||
void close(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);
|
||||
void setBlockingEventsRefreshFPS(uint32_t fps);
|
||||
void requestRedraw(void);
|
||||
void handleSignal(ostd::tSignal& signal) override;
|
||||
|
||||
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) { return m_renderer; }
|
||||
inline void enableBlockingEvents(bool enable = true) { m_blockingEvents = enable; }
|
||||
inline bool isBlockingEventsEnabled(void) const { return m_blockingEvents; }
|
||||
inline ostd::ConsoleOutputHandler& out(void) { return m_out; }
|
||||
inline GraphicsWindowOutputHandler& wout(void) { return m_wout; }
|
||||
|
||||
protected:
|
||||
MouseEventData get_mouse_state(void);
|
||||
virtual void handle_events(void);
|
||||
virtual void before_render(void);
|
||||
virtual void after_render(void);
|
||||
inline virtual void __on_event(SDL_Event& event) { }
|
||||
inline virtual void __on_window_init(int32_t width, int32_t height, const ostd::String& title) { }
|
||||
inline virtual void __on_window_destroy(void) { }
|
||||
inline virtual void __on_window_close(void) { }
|
||||
inline virtual void __on_signal(ostd::tSignal& signal) { }
|
||||
inline virtual void __main_loop(void) = 0;
|
||||
|
||||
private:
|
||||
void __handle_event(SDL_Event& event);
|
||||
|
||||
protected:
|
||||
SDL_Window* m_window { nullptr };
|
||||
SDL_Renderer* m_renderer { nullptr };
|
||||
ostd::ConsoleOutputHandler m_out;
|
||||
GraphicsWindowOutputHandler m_wout;
|
||||
|
||||
private:
|
||||
ostd::Color m_clearColor { 10, 10, 10, 255 };
|
||||
|
||||
int32_t m_windowWidth { 0 };
|
||||
int32_t m_windowHeight { 0 };
|
||||
ostd::String m_title { "" };
|
||||
int32_t m_blockingEventsDelay { 33 };
|
||||
|
||||
bool m_running { false };
|
||||
bool m_initialized { false };
|
||||
bool m_visible { true };
|
||||
bool m_blockingEvents { false };
|
||||
bool m_resizeable { true };
|
||||
bool m_refreshScreen { true };
|
||||
|
||||
SDL_Cursor* m_cursor_IBeam { nullptr };
|
||||
SDL_Cursor* m_cursor_Arrow { nullptr };
|
||||
|
||||
public:
|
||||
inline static constexpr int32_t MaxBlockingEventsFPS { 240 };
|
||||
inline static constexpr int32_t DefaultBlockingEventsFPS { 30 };
|
||||
inline static const gui::Theme DefaultTheme;
|
||||
};
|
||||
class GraphicsWindow : public WindowCore
|
||||
{
|
||||
public: enum class eCursor { Arrow = 0, IBeam };
|
||||
public:
|
||||
inline GraphicsWindow(void) { }
|
||||
inline GraphicsWindow(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); }
|
||||
|
||||
inline virtual void onRender(void) { }
|
||||
inline virtual void onUpdate(void) { }
|
||||
inline virtual void onFixedUpdate(double frameTime_s) { }
|
||||
inline virtual void onInitialize(void) { }
|
||||
inline virtual void onDestroy(void) { }
|
||||
inline virtual void onClose(void) { }
|
||||
inline virtual void onSDLEvent(SDL_Event& event) { }
|
||||
inline virtual void onSignal(ostd::tSignal& signal) { }
|
||||
|
||||
inline int32_t getFPS(void) const { return m_fps; }
|
||||
|
||||
protected:
|
||||
void __on_window_init(int32_t width, int32_t height, const ostd::String& title) override;
|
||||
void __on_event(SDL_Event& event) override;
|
||||
void __on_window_destroy(void) override;
|
||||
void __on_window_close(void) override;
|
||||
void __main_loop(void) override;
|
||||
void __on_signal(ostd::tSignal& signal) override;
|
||||
|
||||
private:
|
||||
int32_t m_fps { 0 };
|
||||
ostd::StepTimer m_fixedUpdateTImer;
|
||||
ostd::StepTimer m_fpsUpdateTimer;
|
||||
ostd::Timer m_fpsUpdateClock;
|
||||
uint64_t m_frameTimeAcc { 0 };
|
||||
int32_t m_frameCount { 0 };
|
||||
};
|
||||
namespace gui
|
||||
{
|
||||
class Window : public WindowCore
|
||||
{
|
||||
public: enum class eCursor { Arrow = 0, IBeam };
|
||||
public:
|
||||
inline Window(void) { }
|
||||
inline Window(int32_t width, int32_t height, const ostd::String& title) { initialize(width, height, title); }
|
||||
void addWidget(Widget& widget);
|
||||
|
||||
inline virtual void onInitialize(void) { }
|
||||
inline virtual void onDestroy(void) { }
|
||||
inline virtual void onClose(void) { }
|
||||
inline virtual void onSDLEvent(SDL_Event& event) { }
|
||||
inline virtual void onRedraw(BasicRenderer2D& gfx) { }
|
||||
inline virtual void onSignal(ostd::tSignal& signal) { }
|
||||
|
||||
inline const gui::Theme& theme(void) const { return *m_guiTheme; }
|
||||
void setTheme(const gui::Theme& theme);
|
||||
inline void loadDefaultTHeme(void) { setTheme(DefaultTheme); }
|
||||
|
||||
protected:
|
||||
void __on_window_init(int32_t width, int32_t height, const ostd::String& title) override;
|
||||
void __on_event(SDL_Event& event) override;
|
||||
void __on_window_destroy(void) override;
|
||||
void __on_window_close(void) override;
|
||||
void __main_loop(void) override;
|
||||
void __on_signal(ostd::tSignal& signal) override;
|
||||
|
||||
private:
|
||||
BasicRenderer2D m_gfx;
|
||||
widgets::RootWidget m_rootWidget { *this };
|
||||
const gui::Theme* m_guiTheme { nullptr };
|
||||
|
||||
inline static const gui::Theme DefaultTheme;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +1,51 @@
|
|||
#include "WindowBaseOutputHandler.hpp"
|
||||
#include "BasicRenderer.hpp"
|
||||
#include "../string/TextStyleParser.hpp"
|
||||
/*
|
||||
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 "WindowOutputHandler.hpp"
|
||||
#include "../render/BasicRenderer.hpp"
|
||||
#include "../../string/TextStyleParser.hpp"
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
using namespace ostd;
|
||||
|
||||
WindowBaseOutputHandler::WindowBaseOutputHandler(void)
|
||||
|
||||
GraphicsWindowOutputHandler::GraphicsWindowOutputHandler(void)
|
||||
{
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::attachWindow(ogfx::WindowBase& window)
|
||||
void GraphicsWindowOutputHandler::attachWindow(ogfx::WindowCore& window)
|
||||
{
|
||||
if (m_window != nullptr) return;
|
||||
m_window = &window;
|
||||
m_renderer.init(window);
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::setMonospaceFont(const String& filePath)
|
||||
void GraphicsWindowOutputHandler::setMonospaceFont(const String& filePath)
|
||||
{
|
||||
m_renderer.setFont(filePath);
|
||||
m_renderer.setFontSize(m_fontSize);
|
||||
__update_char_size();
|
||||
}
|
||||
|
||||
Vec2 WindowBaseOutputHandler::getStringSize(const String& str)
|
||||
Vec2 GraphicsWindowOutputHandler::getStringSize(const String& str)
|
||||
{
|
||||
Vec2 size = { 0.0f, m_charSize.y };
|
||||
if (str.len() == 0) return size;
|
||||
|
|
@ -32,23 +53,23 @@ namespace ogfx
|
|||
return size;
|
||||
}
|
||||
|
||||
bool WindowBaseOutputHandler::isReady(void)
|
||||
bool GraphicsWindowOutputHandler::isReady(void)
|
||||
{
|
||||
return m_window != nullptr && m_renderer.getTTFRenderer().hasOpenFont() && m_fontSize > 0;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::resetCursorPosition(void)
|
||||
void GraphicsWindowOutputHandler::resetCursorPosition(void)
|
||||
{
|
||||
m_curosrPosition = { 0, 0 };
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::resetColors(void)
|
||||
void GraphicsWindowOutputHandler::resetColors(void)
|
||||
{
|
||||
m_foregroundColor = m_defaultForegroundColor;
|
||||
m_backgroundColor = m_defaultBackgroundColor;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::beginFrame(void)
|
||||
void GraphicsWindowOutputHandler::beginFrame(void)
|
||||
{
|
||||
resetColors();
|
||||
resetCursorPosition();
|
||||
|
|
@ -57,37 +78,37 @@ namespace ogfx
|
|||
|
||||
|
||||
|
||||
void WindowBaseOutputHandler::setConsoleMaxCharacters(const IPoint& size)
|
||||
void GraphicsWindowOutputHandler::setConsoleMaxCharacters(const IPoint& size)
|
||||
{
|
||||
m_consoleSize = size;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::setConsolePosition(const Vec2& pos)
|
||||
void GraphicsWindowOutputHandler::setConsolePosition(const Vec2& pos)
|
||||
{
|
||||
m_consolePosition = pos;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::setWrapMode(eWrapMode wrapMode)
|
||||
void GraphicsWindowOutputHandler::setWrapMode(eWrapMode wrapMode)
|
||||
{
|
||||
m_wrapMode = wrapMode;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::setPadding(const Rectangle& rect)
|
||||
void GraphicsWindowOutputHandler::setPadding(const Rectangle& rect)
|
||||
{
|
||||
m_padding = rect;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::setDefaultBackgorundColor(const Color& color)
|
||||
void GraphicsWindowOutputHandler::setDefaultBackgorundColor(const Color& color)
|
||||
{
|
||||
m_defaultBackgroundColor = color;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::setDefaultForegroundColor(const Color& color)
|
||||
void GraphicsWindowOutputHandler::setDefaultForegroundColor(const Color& color)
|
||||
{
|
||||
m_defaultForegroundColor = color;
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::setTabWidth(uint8_t tw)
|
||||
void GraphicsWindowOutputHandler::setTabWidth(uint8_t tw)
|
||||
{
|
||||
m_tabWidth = tw;
|
||||
}
|
||||
|
|
@ -95,19 +116,19 @@ namespace ogfx
|
|||
|
||||
|
||||
|
||||
void WindowBaseOutputHandler::setFontSize(int32_t fontSize)
|
||||
void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize)
|
||||
{
|
||||
m_fontSize = fontSize;
|
||||
m_renderer.setFontSize(m_fontSize);
|
||||
__update_char_size();
|
||||
}
|
||||
|
||||
int32_t WindowBaseOutputHandler::getFontSize(void)
|
||||
int32_t GraphicsWindowOutputHandler::getFontSize(void)
|
||||
{
|
||||
return m_fontSize;
|
||||
}
|
||||
|
||||
Vec2 WindowBaseOutputHandler::getCharacterSize(int32_t fontSize)
|
||||
Vec2 GraphicsWindowOutputHandler::getCharacterSize(int32_t fontSize)
|
||||
{
|
||||
if (fontSize > 0)
|
||||
{
|
||||
|
|
@ -117,37 +138,37 @@ namespace ogfx
|
|||
return m_charSize;
|
||||
}
|
||||
|
||||
Vec2 WindowBaseOutputHandler::getConsolePosition(void)
|
||||
Vec2 GraphicsWindowOutputHandler::getConsolePosition(void)
|
||||
{
|
||||
return m_consolePosition;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler::eWrapMode WindowBaseOutputHandler::getWrapMode(void)
|
||||
GraphicsWindowOutputHandler::eWrapMode GraphicsWindowOutputHandler::getWrapMode(void)
|
||||
{
|
||||
return m_wrapMode;
|
||||
}
|
||||
|
||||
Rectangle WindowBaseOutputHandler::getPadding(void)
|
||||
Rectangle GraphicsWindowOutputHandler::getPadding(void)
|
||||
{
|
||||
return m_padding;
|
||||
}
|
||||
|
||||
Color WindowBaseOutputHandler::getDefaultBackgroundColor(void)
|
||||
Color GraphicsWindowOutputHandler::getDefaultBackgroundColor(void)
|
||||
{
|
||||
return m_defaultBackgroundColor;
|
||||
}
|
||||
|
||||
Color WindowBaseOutputHandler::getDefaultForegroundColor(void)
|
||||
Color GraphicsWindowOutputHandler::getDefaultForegroundColor(void)
|
||||
{
|
||||
return m_defaultForegroundColor;
|
||||
}
|
||||
|
||||
uint8_t WindowBaseOutputHandler::getTabWidth(void)
|
||||
uint8_t GraphicsWindowOutputHandler::getTabWidth(void)
|
||||
{
|
||||
return m_tabWidth;
|
||||
}
|
||||
|
||||
Rectangle WindowBaseOutputHandler::getConsoleBounds(void)
|
||||
Rectangle GraphicsWindowOutputHandler::getConsoleBounds(void)
|
||||
{
|
||||
float console_w = ((float)m_consoleSize.x * getCharacterSize().x) + getPadding().x + getPadding().w;
|
||||
float console_h = ((float)m_consoleSize.y * getCharacterSize().y) + getPadding().y + getPadding().h;
|
||||
|
|
@ -157,54 +178,54 @@ namespace ogfx
|
|||
|
||||
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const Color& color)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::bg(const Color& color)
|
||||
{
|
||||
m_backgroundColor = color;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const ConsoleColors::tConsoleColor& color)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::bg(const ConsoleColors::tConsoleColor& color)
|
||||
{
|
||||
m_backgroundColor = color.fullColor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::bg(const String& color)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::bg(const String& color)
|
||||
{
|
||||
m_backgroundColor = ConsoleColors::getFromName(color).fullColor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const Color& color)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::fg(const Color& color)
|
||||
{
|
||||
m_foregroundColor = color;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const ConsoleColors::tConsoleColor& color)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::fg(const ConsoleColors::tConsoleColor& color)
|
||||
{
|
||||
m_foregroundColor = color.fullColor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::fg(const String& color)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::fg(const String& color)
|
||||
{
|
||||
m_foregroundColor = ConsoleColors::getFromName(color).fullColor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::pChar(char c)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pChar(char c)
|
||||
{
|
||||
__print_string(ostd::String("").addChar(c));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(const String& styled)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pStyled(const String& styled)
|
||||
{
|
||||
return pStyled(TextStyleParser::parse(styled, { m_backgroundColor, "", true }, { m_foregroundColor, "", false }));
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(const TextStyleParser::tStyledString& styled)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pStyled(const TextStyleParser::tStyledString& styled)
|
||||
{
|
||||
if (!styled.validate()) return *this;
|
||||
Color oldBgCol = m_backgroundColor;
|
||||
|
|
@ -216,7 +237,7 @@ namespace ogfx
|
|||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::pStyled(TextStyleBuilder::IRichStringBase& styled)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pStyled(TextStyleBuilder::IRichStringBase& styled)
|
||||
{
|
||||
auto oldBg = styled.getDefaultBackgroundColor();
|
||||
auto oldFg = styled.getDefaultForegroundColor();
|
||||
|
|
@ -228,79 +249,79 @@ namespace ogfx
|
|||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::pObject(const BaseObject& bo)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::pObject(const BaseObject& bo)
|
||||
{
|
||||
__print_string(bo.toString());
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(const String& se)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(const String& se)
|
||||
{
|
||||
__print_string(se);
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint8_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint8_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int8_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int8_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint16_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint16_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int16_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int16_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint32_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint32_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int32_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int32_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(uint64_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(uint64_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(int64_t i)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(int64_t i)
|
||||
{
|
||||
__print_string(ostd::String("").add(i));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(float f, uint8_t precision)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(float f, uint8_t precision)
|
||||
{
|
||||
__print_string(ostd::String("").add(f, precision));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::p(double f, uint8_t precision)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::p(double f, uint8_t precision)
|
||||
{
|
||||
__print_string(ostd::String("").add(f, precision));
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::nl(void)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::nl(void)
|
||||
{
|
||||
if (m_curosrPosition.y >= getConsoleSize().y) return *this;
|
||||
m_curosrPosition.y++;
|
||||
|
|
@ -308,7 +329,7 @@ namespace ogfx
|
|||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::tab(void)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::tab(void)
|
||||
{
|
||||
if (m_curosrPosition.x == 0)
|
||||
{
|
||||
|
|
@ -323,68 +344,68 @@ namespace ogfx
|
|||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::flush(void)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::flush(void)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::clear(void)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::clear(void)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::reset(void)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::reset(void)
|
||||
{
|
||||
resetColors();
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::xy(IPoint position)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::xy(IPoint position)
|
||||
{
|
||||
m_curosrPosition = { (float)position.x, (float)position.y };
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::xy(int32_t x, int32_t y)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::xy(int32_t x, int32_t y)
|
||||
{
|
||||
m_curosrPosition = { (float)x, (float)y };
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::x(int32_t x)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::x(int32_t x)
|
||||
{
|
||||
m_curosrPosition.x = (float)x;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WindowBaseOutputHandler& WindowBaseOutputHandler::y(int32_t y)
|
||||
GraphicsWindowOutputHandler& GraphicsWindowOutputHandler::y(int32_t y)
|
||||
{
|
||||
m_curosrPosition.y = (float)y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
IPoint WindowBaseOutputHandler::getCursorPosition(void)
|
||||
IPoint GraphicsWindowOutputHandler::getCursorPosition(void)
|
||||
{
|
||||
return { (int32_t)std::round(m_curosrPosition.x), (int32_t)std::round(m_curosrPosition.y) };
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::getCursorPosition(int32_t& outX, int32_t& outY)
|
||||
void GraphicsWindowOutputHandler::getCursorPosition(int32_t& outX, int32_t& outY)
|
||||
{
|
||||
outX = (int32_t)std::round(m_curosrPosition.x);
|
||||
outY = (int32_t)std::round(m_curosrPosition.y);
|
||||
}
|
||||
|
||||
int32_t WindowBaseOutputHandler::getCursorX(void)
|
||||
int32_t GraphicsWindowOutputHandler::getCursorX(void)
|
||||
{
|
||||
return (int32_t)std::round(m_curosrPosition.x);
|
||||
}
|
||||
|
||||
int32_t WindowBaseOutputHandler::getCursorY(void)
|
||||
int32_t GraphicsWindowOutputHandler::getCursorY(void)
|
||||
{
|
||||
return (int32_t)std::round(m_curosrPosition.y);
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::getConsoleSize(int32_t& outColumns, int32_t& outRows)
|
||||
void GraphicsWindowOutputHandler::getConsoleSize(int32_t& outColumns, int32_t& outRows)
|
||||
{
|
||||
int32_t console_rows = std::numeric_limits<int>::max();
|
||||
int32_t console_cols = std::numeric_limits<int>::max();
|
||||
|
|
@ -394,7 +415,7 @@ namespace ogfx
|
|||
outRows = console_rows;
|
||||
}
|
||||
|
||||
IPoint WindowBaseOutputHandler::getConsoleSize(void)
|
||||
IPoint GraphicsWindowOutputHandler::getConsoleSize(void)
|
||||
{
|
||||
int32_t console_rows = std::numeric_limits<int>::max();
|
||||
int32_t console_cols = std::numeric_limits<int>::max();
|
||||
|
|
@ -403,13 +424,13 @@ namespace ogfx
|
|||
return { console_cols, console_rows };
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::__update_char_size(void)
|
||||
void GraphicsWindowOutputHandler::__update_char_size(void)
|
||||
{
|
||||
auto size = m_renderer.getStringSize("A", m_fontSize);
|
||||
m_charSize = { (float)size.x, (float)size.y };
|
||||
}
|
||||
|
||||
void WindowBaseOutputHandler::__print_string(const String& str)
|
||||
void GraphicsWindowOutputHandler::__print_string(const String& str)
|
||||
{
|
||||
if (!isReady()) return;
|
||||
auto l_endOfConsole = [&](void) -> bool {
|
||||
|
|
@ -22,16 +22,17 @@
|
|||
|
||||
#include <ostd/io/IOHandlers.hpp>
|
||||
#include <ostd/string/TextStyleParser.hpp>
|
||||
#include <ogfx/BasicRenderer.hpp>
|
||||
#include <ogfx/render/BasicRenderer.hpp>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
class WindowBaseOutputHandler : public ostd::OutputHandlerBase
|
||||
class WindowCore;
|
||||
class GraphicsWindowOutputHandler : public ostd::OutputHandlerBase
|
||||
{
|
||||
public: enum class eWrapMode { TripleDots, NewLine };
|
||||
public:
|
||||
WindowBaseOutputHandler(void);
|
||||
void attachWindow(WindowBase& window);
|
||||
GraphicsWindowOutputHandler(void);
|
||||
void attachWindow(WindowCore& window);
|
||||
void setMonospaceFont(const ostd::String& filePath);
|
||||
ostd::Vec2 getStringSize(const ostd::String& str);
|
||||
bool isReady(void);
|
||||
|
|
@ -58,41 +59,41 @@ namespace ogfx
|
|||
uint8_t getTabWidth(void);
|
||||
ostd::Rectangle getConsoleBounds(void);
|
||||
|
||||
WindowBaseOutputHandler& bg(const ostd::Color& color) override;
|
||||
WindowBaseOutputHandler& bg(const ostd::ConsoleColors::tConsoleColor& color) override;
|
||||
WindowBaseOutputHandler& bg(const ostd::String& color) override;
|
||||
WindowBaseOutputHandler& fg(const ostd::Color& color) override;
|
||||
WindowBaseOutputHandler& fg(const ostd::ConsoleColors::tConsoleColor& color) override;
|
||||
WindowBaseOutputHandler& fg(const ostd::String& color) override;
|
||||
GraphicsWindowOutputHandler& bg(const ostd::Color& color) override;
|
||||
GraphicsWindowOutputHandler& bg(const ostd::ConsoleColors::tConsoleColor& color) override;
|
||||
GraphicsWindowOutputHandler& bg(const ostd::String& color) override;
|
||||
GraphicsWindowOutputHandler& fg(const ostd::Color& color) override;
|
||||
GraphicsWindowOutputHandler& fg(const ostd::ConsoleColors::tConsoleColor& color) override;
|
||||
GraphicsWindowOutputHandler& fg(const ostd::String& color) override;
|
||||
|
||||
WindowBaseOutputHandler& pChar(char c) override;
|
||||
WindowBaseOutputHandler& pStyled(const ostd::String& styled) override;
|
||||
WindowBaseOutputHandler& pStyled(const ostd::TextStyleParser::tStyledString& styled) override;
|
||||
WindowBaseOutputHandler& pStyled(ostd::TextStyleBuilder::IRichStringBase& styled) override;
|
||||
WindowBaseOutputHandler& pObject(const ostd::BaseObject& bo) override;
|
||||
GraphicsWindowOutputHandler& pChar(char c) override;
|
||||
GraphicsWindowOutputHandler& pStyled(const ostd::String& styled) override;
|
||||
GraphicsWindowOutputHandler& pStyled(const ostd::TextStyleParser::tStyledString& styled) override;
|
||||
GraphicsWindowOutputHandler& pStyled(ostd::TextStyleBuilder::IRichStringBase& styled) override;
|
||||
GraphicsWindowOutputHandler& pObject(const ostd::BaseObject& bo) override;
|
||||
|
||||
WindowBaseOutputHandler& p(const ostd::String& se) override;
|
||||
WindowBaseOutputHandler& p(uint8_t i) override;
|
||||
WindowBaseOutputHandler& p(int8_t i) override;
|
||||
WindowBaseOutputHandler& p(uint16_t i) override;
|
||||
WindowBaseOutputHandler& p(int16_t i) override;
|
||||
WindowBaseOutputHandler& p(uint32_t i) override;
|
||||
WindowBaseOutputHandler& p(int32_t i) override;
|
||||
WindowBaseOutputHandler& p(uint64_t i) override;
|
||||
WindowBaseOutputHandler& p(int64_t i) override;
|
||||
WindowBaseOutputHandler& p(float f, uint8_t precision = 0) override;
|
||||
WindowBaseOutputHandler& p(double f, uint8_t precision = 0) override;
|
||||
GraphicsWindowOutputHandler& p(const ostd::String& se) override;
|
||||
GraphicsWindowOutputHandler& p(uint8_t i) override;
|
||||
GraphicsWindowOutputHandler& p(int8_t i) override;
|
||||
GraphicsWindowOutputHandler& p(uint16_t i) override;
|
||||
GraphicsWindowOutputHandler& p(int16_t i) override;
|
||||
GraphicsWindowOutputHandler& p(uint32_t i) override;
|
||||
GraphicsWindowOutputHandler& p(int32_t i) override;
|
||||
GraphicsWindowOutputHandler& p(uint64_t i) override;
|
||||
GraphicsWindowOutputHandler& p(int64_t i) override;
|
||||
GraphicsWindowOutputHandler& p(float f, uint8_t precision = 0) override;
|
||||
GraphicsWindowOutputHandler& p(double f, uint8_t precision = 0) override;
|
||||
|
||||
WindowBaseOutputHandler& nl(void) override;
|
||||
WindowBaseOutputHandler& tab(void) override;
|
||||
WindowBaseOutputHandler& flush(void) override;
|
||||
WindowBaseOutputHandler& clear(void) override;
|
||||
WindowBaseOutputHandler& reset(void) override;
|
||||
GraphicsWindowOutputHandler& nl(void) override;
|
||||
GraphicsWindowOutputHandler& tab(void) override;
|
||||
GraphicsWindowOutputHandler& flush(void) override;
|
||||
GraphicsWindowOutputHandler& clear(void) override;
|
||||
GraphicsWindowOutputHandler& reset(void) override;
|
||||
|
||||
WindowBaseOutputHandler& xy(ostd::IPoint position) override;
|
||||
WindowBaseOutputHandler& xy(int32_t x, int32_t y) override;
|
||||
WindowBaseOutputHandler& x(int32_t x) override;
|
||||
WindowBaseOutputHandler& y(int32_t y) override;
|
||||
GraphicsWindowOutputHandler& xy(ostd::IPoint position) override;
|
||||
GraphicsWindowOutputHandler& xy(int32_t x, int32_t y) override;
|
||||
GraphicsWindowOutputHandler& x(int32_t x) override;
|
||||
GraphicsWindowOutputHandler& y(int32_t y) override;
|
||||
|
||||
ostd::IPoint getCursorPosition(void) override;
|
||||
void getCursorPosition(int32_t& outX, int32_t& outY) override;
|
||||
|
|
@ -113,7 +114,7 @@ namespace ogfx
|
|||
ostd::Color m_defaultForegroundColor { 0, 220, 0, 255 };
|
||||
ostd::Vec2 m_curosrPosition;
|
||||
BasicRenderer2D m_renderer;
|
||||
WindowBase* m_window { nullptr };
|
||||
WindowCore* m_window { nullptr };
|
||||
int32_t m_fontSize { 20 };
|
||||
ostd::Vec2 m_charSize;
|
||||
ostd::IPoint m_consoleSize { 0, 0 };
|
||||
35
src/ogfx/ogfx.hpp
Normal file
35
src/ogfx/ogfx.hpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
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 <ostd/ostd.hpp>
|
||||
|
||||
#include <ogfx/gui/RawTextInput.hpp>
|
||||
#include <ogfx/gui/Window.hpp>
|
||||
#include <ogfx/gui/WindowOutputHandler.hpp>
|
||||
|
||||
#include <ogfx/render/BasicRenderer.hpp>
|
||||
#include <ogfx/render/PixelRenderer.hpp>
|
||||
|
||||
#include <ogfx/resources/Image.hpp>
|
||||
|
||||
#include <ogfx/utils/Animation.hpp>
|
||||
#include <ogfx/utils/SDLInclude.hpp>
|
||||
|
|
@ -1,14 +1,34 @@
|
|||
/*
|
||||
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 "BasicRenderer.hpp"
|
||||
#include "WindowBase.hpp"
|
||||
#include <SDL2/SDL_rect.h>
|
||||
#include "../gui/Window.hpp"
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
void BasicRenderer2D::init(WindowBase& window)
|
||||
void BasicRenderer2D::init(WindowCore& window)
|
||||
{
|
||||
m_window = &window;
|
||||
m_ttfr.init(window.getSDLRenderer());
|
||||
m_initialized = true;
|
||||
setDefaultFont();
|
||||
}
|
||||
|
||||
void BasicRenderer2D::setFont(const ostd::String& fontFilePath)
|
||||
|
|
@ -17,33 +37,39 @@ namespace ogfx
|
|||
m_ttfr.openFont(fontFilePath, m_ttfr.getFontSize());
|
||||
}
|
||||
|
||||
void BasicRenderer2D::setDefaultFont(void)
|
||||
{
|
||||
if (!m_initialized) return;
|
||||
m_ttfr.loadDefaultFont(m_ttfr.getFontSize());
|
||||
}
|
||||
|
||||
void BasicRenderer2D::setFontSize(int32_t fontSize)
|
||||
{
|
||||
if (!m_initialized) return;
|
||||
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 (!image.isLoaded()) return;
|
||||
SDL_Rect texr;
|
||||
SDL_FRect texr;
|
||||
texr.x = position.x;
|
||||
texr.y = position.y;
|
||||
texr.w = image.getSize().x;
|
||||
texr.h = image.getSize().y;
|
||||
SDL_Rect srcRect;
|
||||
SDL_FRect srcRect;
|
||||
srcRect.x = rect.x;
|
||||
srcRect.y = rect.y;
|
||||
srcRect.w = rect.w;
|
||||
srcRect.h = rect.w;
|
||||
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
|
||||
{
|
||||
texr.w = srcRect.w;
|
||||
texr.h = srcRect.h;
|
||||
SDL_RenderCopy(m_window->getSDLRenderer(), image.getSDLTexture(), &srcRect, &texr);
|
||||
SDL_RenderTexture(m_window->getSDLRenderer(), image.getSDLTexture(), &srcRect, &texr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +77,7 @@ namespace ogfx
|
|||
{
|
||||
if (!m_initialized) return;
|
||||
if (!anim.hasImage()) return;
|
||||
const auto& img = anim.getSpriteSheet();
|
||||
Image img = anim.getSpriteSheet();
|
||||
if (!img.isLoaded() || !img.isValid()) return;
|
||||
drawImage(img, position, anim.getFrameRect());
|
||||
}
|
||||
|
|
@ -20,28 +20,29 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Animation.hpp"
|
||||
#include <ogfx/FontUtils.hpp>
|
||||
#include <ogfx/render/FontUtils.hpp>
|
||||
#include <ogfx/utils/Animation.hpp>
|
||||
#include <ostd/math/Geometry.hpp>
|
||||
#include <ogfx/Image.hpp>
|
||||
#include <ogfx/resources/Image.hpp>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
class WindowBase;
|
||||
class WindowCore;
|
||||
class BasicRenderer2D
|
||||
{
|
||||
public:
|
||||
BasicRenderer2D(void) = default;
|
||||
void init(WindowBase& window);
|
||||
void init(WindowCore& window);
|
||||
|
||||
inline TTFRenderer& getTTFRenderer(void) { return m_ttfr; }
|
||||
inline ostd::IPoint getStringSize(const ostd::String str, int32_t fontSize = 0) { return m_ttfr.getStringDimensions(str, fontSize); }
|
||||
inline WindowBase& getWindow(void) { return *m_window; }
|
||||
inline WindowCore& getWindow(void) { return *m_window; }
|
||||
inline bool isInitialized(void) { return m_initialized; }
|
||||
void setFont(const ostd::String& fontFilePath);
|
||||
void setDefaultFont(void);
|
||||
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 drawString(const ostd::String& str, const ostd::Vec2& position, const ostd::Color& color, int32_t fontSize = 0);
|
||||
|
|
@ -63,7 +64,7 @@ namespace ogfx
|
|||
|
||||
private:
|
||||
TTFRenderer m_ttfr;
|
||||
WindowBase* m_window { nullptr };
|
||||
WindowCore* m_window { nullptr };
|
||||
bool m_initialized { false };
|
||||
};
|
||||
}
|
||||
|
|
@ -1,7 +1,46 @@
|
|||
/*
|
||||
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 "FontUtils.hpp"
|
||||
#include "../resources/UbuntuMonoRegularTTF.hpp"
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
TTFRenderer::SignalHandler::SignalHandler(TTFRenderer& parent) : m_parent(parent)
|
||||
{
|
||||
enableSignals();
|
||||
connectSignal(ostd::tBuiltinSignals::BeforeSDLShutdown);
|
||||
setTypeName("ostd::GraphicsWindowOutputHandler::SignalHandler");
|
||||
validate();
|
||||
}
|
||||
|
||||
void TTFRenderer::SignalHandler::handleSignal(ostd::tSignal& signal)
|
||||
{
|
||||
if (signal.ID == ostd::tBuiltinSignals::BeforeSDLShutdown)
|
||||
{
|
||||
m_parent.closeFont();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TTFRenderer::~TTFRenderer(void)
|
||||
{
|
||||
closeFont();
|
||||
|
|
@ -30,7 +69,7 @@ namespace ogfx
|
|||
return;
|
||||
}
|
||||
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)
|
||||
{
|
||||
set_error_state(tErrors::TTFRenderTextBlendedFail);
|
||||
|
|
@ -44,17 +83,17 @@ namespace ogfx
|
|||
print_ttf_error("SDL_CreateTextureFromSurface");
|
||||
return;
|
||||
}
|
||||
SDL_FreeSurface(surf);
|
||||
SDL_DestroySurface(surf);
|
||||
|
||||
int32_t w = 0, h = 0;
|
||||
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
|
||||
float w = 0, h = 0;
|
||||
SDL_GetTextureSize(texture, &w, &h);
|
||||
|
||||
SDL_Rect dst;
|
||||
SDL_FRect dst;
|
||||
dst.x = x;
|
||||
dst.y = y;
|
||||
dst.w = w;
|
||||
dst.h = h;
|
||||
SDL_RenderCopy(m_renderer, texture, NULL, &dst);
|
||||
SDL_RenderTexture(m_renderer, texture, NULL, &dst);
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +120,7 @@ namespace ogfx
|
|||
return;
|
||||
}
|
||||
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)
|
||||
{
|
||||
set_error_state(tErrors::TTFRenderTextBlendedFail);
|
||||
|
|
@ -95,17 +134,17 @@ namespace ogfx
|
|||
print_ttf_error("SDL_CreateTextureFromSurface");
|
||||
return;
|
||||
}
|
||||
SDL_FreeSurface(surf);
|
||||
SDL_DestroySurface(surf);
|
||||
|
||||
int32_t w = 0, h = 0;
|
||||
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
|
||||
float w = 0, h = 0;
|
||||
SDL_GetTextureSize(texture, &w, &h);
|
||||
|
||||
SDL_Rect dst;
|
||||
SDL_FRect dst;
|
||||
dst.x = center_x - (w / 2);
|
||||
dst.y = center_y - (h / 2);
|
||||
dst.w = w;
|
||||
dst.h = h;
|
||||
SDL_RenderCopy(m_renderer, texture, NULL, &dst);
|
||||
SDL_RenderTexture(m_renderer, texture, NULL, &dst);
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +171,7 @@ namespace ogfx
|
|||
return { 0, 0 };
|
||||
}
|
||||
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)
|
||||
{
|
||||
set_error_state(tErrors::TTFRenderTextBlendedFail);
|
||||
|
|
@ -146,29 +185,28 @@ namespace ogfx
|
|||
print_ttf_error("SDL_CreateTextureFromSurface");
|
||||
return { 0, 0 };
|
||||
}
|
||||
SDL_FreeSurface(surf);
|
||||
SDL_DestroySurface(surf);
|
||||
|
||||
int32_t w = 0, h = 0;
|
||||
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
|
||||
float w = 0, h = 0;
|
||||
SDL_GetTextureSize(texture, &w, &h);
|
||||
SDL_DestroyTexture(texture);
|
||||
return { w, h };
|
||||
return { static_cast<int32_t>(w), static_cast<int32_t>(h) };
|
||||
}
|
||||
|
||||
int32_t TTFRenderer::init(SDL_Renderer* renderer)
|
||||
{
|
||||
if (TTFRenderer::m_initialized) return set_error_state(tErrors::NoError);
|
||||
if (renderer == nullptr) return set_error_state(tErrors::NullRenderer);
|
||||
if (TTF_Init() != 0)
|
||||
{
|
||||
print_ttf_error("TTF_Init");
|
||||
SDL_Quit();
|
||||
return set_error_state(tErrors::FailedToLoad);
|
||||
}
|
||||
m_renderer = renderer;
|
||||
TTFRenderer::m_initialized = true;
|
||||
return set_error_state(tErrors::NoError);
|
||||
}
|
||||
|
||||
int32_t TTFRenderer::loadDefaultFont(int32_t fontSize)
|
||||
{
|
||||
return openFont(ubuntu_mono_regular_ttf_data, ubuntu_mono_regular_ttf_size, fontSize);
|
||||
}
|
||||
|
||||
void TTFRenderer::closeFont(void)
|
||||
{
|
||||
if (!TTFRenderer::m_initialized || !m_fontOpen) return;
|
||||
|
|
@ -177,6 +215,7 @@ namespace ogfx
|
|||
m_font = nullptr;
|
||||
m_fontOpen = false;
|
||||
m_fontSize = DefaultFontSize;
|
||||
m_fontFromMemory = false;
|
||||
set_error_state(tErrors::NoError);
|
||||
}
|
||||
|
||||
|
|
@ -195,6 +234,29 @@ namespace ogfx
|
|||
return set_error_state(tErrors::FailedToOpenFontFile);
|
||||
}
|
||||
m_fontOpen = true;
|
||||
m_fontFromMemory = false;
|
||||
return set_error_state(tErrors::NoError);
|
||||
}
|
||||
|
||||
int32_t TTFRenderer::openFont(const ostd::UByte resource_data[], uint32_t data_size, int32_t fontSize)
|
||||
{
|
||||
if (!TTFRenderer::m_initialized) return set_error_state(tErrors::Uninitialized);
|
||||
if (data_size < 100) // Arbitrary 100 bytes
|
||||
return set_error_state(tErrors::FailedToOpenFontFile);
|
||||
if (m_fontOpen) closeFont();
|
||||
if (fontSize <= 0)
|
||||
fontSize = m_fontSize;
|
||||
else
|
||||
m_fontSize = fontSize;
|
||||
SDL_IOStream* rw = SDL_IOFromConstMem(resource_data, data_size);
|
||||
m_font = TTF_OpenFontIO(rw, true, fontSize);
|
||||
if (m_font == nullptr)
|
||||
{
|
||||
print_ttf_error("TTF_OpenFont");
|
||||
return set_error_state(tErrors::FailedToOpenFontFile);
|
||||
}
|
||||
m_fontOpen = true;
|
||||
m_fontFromMemory = true;
|
||||
return set_error_state(tErrors::NoError);
|
||||
}
|
||||
|
||||
|
|
@ -213,6 +275,6 @@ namespace ogfx
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <ogfx/SDLInclude.hpp>
|
||||
#include <ogfx/utils/SDLInclude.hpp>
|
||||
#include <ostd/utils/Signals.hpp>
|
||||
#include <ostd/io/IOHandlers.hpp>
|
||||
|
||||
|
|
@ -28,6 +28,15 @@ namespace ogfx
|
|||
{
|
||||
class TTFRenderer
|
||||
{
|
||||
private: class SignalHandler : public ostd::BaseObject
|
||||
{
|
||||
public:
|
||||
SignalHandler(TTFRenderer& parent);
|
||||
void handleSignal(ostd::tSignal& signal) override;
|
||||
|
||||
private:
|
||||
TTFRenderer& m_parent;
|
||||
};
|
||||
public: struct tErrors
|
||||
{
|
||||
inline static constexpr int32_t NoError = 0;
|
||||
|
|
@ -40,14 +49,17 @@ namespace ogfx
|
|||
inline static constexpr int32_t TTFCreateTextureFromSurfaceFail = 7;
|
||||
inline static constexpr int32_t NullFont = 8;
|
||||
inline static constexpr int32_t NoFont = 9;
|
||||
inline static constexpr int32_t FailedToOpenFontByteStrean = 10;
|
||||
};
|
||||
public:
|
||||
TTFRenderer(void) = default;
|
||||
~TTFRenderer(void);
|
||||
inline TTFRenderer(SDL_Renderer* renderer) { init(renderer); }
|
||||
int32_t init(SDL_Renderer* renderer);
|
||||
int32_t loadDefaultFont(int32_t fontSize = 0);
|
||||
void closeFont(void);
|
||||
int32_t openFont(const ostd::String& fontPath, int32_t fontSize = 0);
|
||||
int32_t openFont(const ostd::UByte resource_data[], uint32_t data_size, int32_t fontSize = 0);
|
||||
int32_t setFontSize(int32_t fontSize);
|
||||
void renderText(const ostd::String& message, int32_t x, int32_t y, const ostd::Color& color, int32_t fontSize = 0);
|
||||
void renderCenteredText(const ostd::String& message, int32_t center_x, int32_t center_y, const ostd::Color& color, int32_t fontSize = 0);
|
||||
|
|
@ -55,7 +67,7 @@ namespace ogfx
|
|||
inline bool isInitialized(void) { return TTFRenderer::m_initialized; }
|
||||
inline bool hasOpenFont(void) { return m_fontOpen; }
|
||||
inline TTF_Font* getSDLFont(void) { return m_font; }
|
||||
inline bool isValid(void) { return TTFRenderer::m_initialized && m_fontOpen && m_font != nullptr && m_renderer != nullptr; }
|
||||
inline bool isValid(void) { return TTFRenderer::m_initialized && m_fontOpen && (m_font != nullptr || m_fontFromMemory) && m_renderer != nullptr; }
|
||||
inline int32_t geterrorState(void) { return m_errorState; }
|
||||
inline int32_t getFontSize(void) { return m_fontSize; }
|
||||
|
||||
|
|
@ -65,12 +77,14 @@ namespace ogfx
|
|||
|
||||
private:
|
||||
ostd::ConsoleOutputHandler m_out;
|
||||
SignalHandler m_sigHndl { *this };
|
||||
bool m_initialized { false };
|
||||
bool m_fontOpen { false };
|
||||
TTF_Font* m_font { nullptr };
|
||||
SDL_Renderer* m_renderer { nullptr };
|
||||
int32_t m_errorState { tErrors::NoError };
|
||||
int32_t m_fontSize { DefaultFontSize };
|
||||
bool m_fontFromMemory { false };
|
||||
|
||||
inline static constexpr int32_t DefaultFontSize { 16 };
|
||||
};
|
||||
|
|
@ -1,6 +1,27 @@
|
|||
/*
|
||||
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 "PixelRenderer.hpp"
|
||||
#include "WindowBase.hpp"
|
||||
#include "../ostd/io/Memory.hpp"
|
||||
#include "../gui/Window.hpp"
|
||||
#include "../../ostd/io/Memory.hpp"
|
||||
#include <SDL3/SDL_render.h>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
|
|
@ -111,7 +132,7 @@ namespace ogfx
|
|||
SDL_DestroyTexture(m_texture);
|
||||
}
|
||||
|
||||
void PixelRenderer::initialize(WindowBase& parent)
|
||||
void PixelRenderer::initialize(WindowCore& parent)
|
||||
{
|
||||
if (isValid()) return; //TODO: Error
|
||||
if (!parent.isValid() || !parent.isInitialized())
|
||||
|
|
@ -151,8 +172,8 @@ namespace ogfx
|
|||
void PixelRenderer::displayBuffer(void)
|
||||
{
|
||||
if (isInvalid()) return;
|
||||
SDL_Rect rect { 0, 0, m_windowWidth, m_windowHeight };
|
||||
SDL_RenderCopy(m_parent->getSDLRenderer(), m_texture, NULL, &rect);
|
||||
SDL_FRect rect { 0, 0, static_cast<float>(m_windowWidth), static_cast<float>(m_windowHeight) };
|
||||
SDL_RenderTexture(m_parent->getSDLRenderer(), m_texture, NULL, &rect);
|
||||
}
|
||||
|
||||
void PixelRenderer::clear(const ostd::Color& color)
|
||||
|
|
@ -23,12 +23,12 @@
|
|||
#include <ostd/io/IOHandlers.hpp>
|
||||
#include <ostd/string/String.hpp>
|
||||
#include <ostd/data/Color.hpp>
|
||||
#include <ogfx/SDLInclude.hpp>
|
||||
#include <ogfx/utils/SDLInclude.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
class WindowBase;
|
||||
class WindowCore;
|
||||
class PixelRenderer : public ostd::BaseObject
|
||||
{
|
||||
public: class TextRenderer
|
||||
|
|
@ -73,7 +73,7 @@ namespace ogfx
|
|||
}
|
||||
inline ~Font(void)
|
||||
{
|
||||
SDL_FreeSurface(m_fontSurface);
|
||||
SDL_DestroySurface(m_fontSurface);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
@ -83,7 +83,7 @@ namespace ogfx
|
|||
public:
|
||||
inline PixelRenderer(void) { invalidate(); }
|
||||
~PixelRenderer(void);
|
||||
void initialize(WindowBase& parent);
|
||||
void initialize(WindowCore& parent);
|
||||
void handleSignal(ostd::tSignal& signal) override;
|
||||
void updateBuffer(void);
|
||||
void displayBuffer(void);
|
||||
|
|
@ -94,7 +94,7 @@ namespace ogfx
|
|||
private:
|
||||
uint32_t* m_pixels { nullptr };
|
||||
SDL_Texture* m_texture { nullptr };
|
||||
WindowBase* m_parent { nullptr };
|
||||
WindowCore* m_parent { nullptr };
|
||||
int32_t m_windowWidth { 0 };
|
||||
int32_t m_windowHeight { 0 };
|
||||
};
|
||||
53
src/ogfx/resources/Image.cpp
Normal file
53
src/ogfx/resources/Image.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
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 "Image.hpp"
|
||||
#include "../../io/Logger.hpp"
|
||||
#include "../render/BasicRenderer.hpp"
|
||||
#include "../gui/Window.hpp"
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
void Image::destroy(void)
|
||||
{
|
||||
SDL_DestroyTexture(m_sdl_texture);
|
||||
m_loaded = false;
|
||||
m_sdl_texture = nullptr;
|
||||
m_width = 0;
|
||||
m_height = 0;
|
||||
}
|
||||
|
||||
Image& Image::loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx)
|
||||
{
|
||||
if (!gfx.isInitialized())
|
||||
return *this; //TODO: Error
|
||||
m_sdl_texture = IMG_LoadTexture(gfx.getWindow().getSDLRenderer(), filePath.c_str());
|
||||
if (!m_sdl_texture)
|
||||
{
|
||||
OX_ERROR("Failed to load Image: %s", SDL_GetError());
|
||||
return *this;
|
||||
}
|
||||
SDL_GetTextureSize(m_sdl_texture, &m_width, &m_height);
|
||||
m_loaded = true;
|
||||
setTypeName("ogfx::Image");
|
||||
validate();
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <ostd/data/BaseObject.hpp>
|
||||
#include <ogfx/SDLInclude.hpp>
|
||||
#include <ogfx/utils/SDLInclude.hpp>
|
||||
#include <ostd/math/Geometry.hpp>
|
||||
|
||||
namespace ogfx
|
||||
|
|
@ -35,14 +35,14 @@ namespace ogfx
|
|||
inline ~Image(void) { destroy(); }
|
||||
void destroy(void);
|
||||
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 SDL_Texture* getSDLTexture(void) const { return m_sdl_texture; }
|
||||
inline SDL_Texture* getSDLTexture(void) { return m_sdl_texture; }
|
||||
|
||||
private:
|
||||
SDL_Texture* m_sdl_texture { nullptr };
|
||||
int32_t m_width { 0 };
|
||||
int32_t m_height { 0 };
|
||||
float m_width { 0 };
|
||||
float m_height { 0 };
|
||||
bool m_loaded { false };
|
||||
};
|
||||
}
|
||||
9536
src/ogfx/resources/UbuntuMonoRegularTTF.cpp
Normal file
9536
src/ogfx/resources/UbuntuMonoRegularTTF.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -20,12 +20,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#ifdef _WIN32
|
||||
#define SDL_MAIN_HANDLED
|
||||
#undef __linux__
|
||||
#endif
|
||||
#include <ostd/data/Types.hpp>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL2_gfxPrimitives.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
namespace ogfx
|
||||
{
|
||||
extern const uint32_t ubuntu_mono_regular_ttf_size;
|
||||
extern const ostd::UByte ubuntu_mono_regular_ttf_data[];
|
||||
}
|
||||
|
|
@ -1,5 +1,25 @@
|
|||
/*
|
||||
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 "Animation.hpp"
|
||||
#include <ostd/math/Random.hpp>
|
||||
#include "../../ostd/math/Random.hpp"
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
|
|
@ -1,8 +1,28 @@
|
|||
/*
|
||||
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 <ostd/data/Types.hpp>
|
||||
#include <ostd/math/Geometry.hpp>
|
||||
#include <ogfx/Image.hpp>
|
||||
#include <ogfx/resources/Image.hpp>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
|
|
@ -58,7 +78,7 @@ namespace ogfx
|
|||
inline void setColumnOffset(int32_t o) { m_column_offset = o; }
|
||||
inline void setRowOffset(int32_t o) { m_row_offset = o; }
|
||||
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 getColumnNumber(void) const { return m_columns; }
|
||||
|
|
@ -69,11 +89,12 @@ namespace ogfx
|
|||
inline bool isStill(void) const { return m_still; }
|
||||
inline ostd::Rectangle getFrameRect(void) const { return m_frame_rect; }
|
||||
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; }
|
||||
|
||||
private:
|
||||
const Image* m_spriteSheet { nullptr };
|
||||
inline static const Image InvalidImage;
|
||||
Image* m_spriteSheet { nullptr };
|
||||
inline static Image InvalidImage;
|
||||
|
||||
int32_t m_frames;
|
||||
int32_t m_rows;
|
||||
85
src/ogfx/utils/SDLInclude.hpp
Normal file
85
src/ogfx/utils/SDLInclude.hpp
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
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 <ostd/utils/Defines.hpp>
|
||||
#include <ostd/io/Logger.hpp>
|
||||
#include <ostd/utils/Signals.hpp>
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.h>
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <SDL3/SDL_surface.h>
|
||||
#include <SDL3/SDL_rect.h>
|
||||
#include <SDL3/SDL_render.h>
|
||||
|
||||
namespace ogfx
|
||||
{
|
||||
class SDLSysten
|
||||
{
|
||||
public:
|
||||
static inline void acquire(void)
|
||||
{
|
||||
if (s_refCount == 0)
|
||||
init_sdl();
|
||||
s_refCount++;
|
||||
}
|
||||
|
||||
static inline void release(void)
|
||||
{
|
||||
s_refCount--;
|
||||
if (s_refCount == 0)
|
||||
shutdown_sdl();
|
||||
}
|
||||
|
||||
private:
|
||||
static inline void init_sdl(void)
|
||||
{
|
||||
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||
{
|
||||
OX_FATAL("SDL could not initialize! Error: %s\n", SDL_GetError());
|
||||
exit(ErrorSDLInitFailed);
|
||||
}
|
||||
if (!TTF_Init())
|
||||
{
|
||||
OX_FATAL("SDL_ttf could not initialize! Error: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(ErrorSDLTTFInitFailed);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void shutdown_sdl(void)
|
||||
{
|
||||
ostd::SignalHandler::emitSignal(ostd::tBuiltinSignals::BeforeSDLShutdown, ostd:: tSignalPriority::RealTime);
|
||||
TTF_Quit();
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
private:
|
||||
inline static int s_refCount { 0 };
|
||||
|
||||
public:
|
||||
inline static constexpr int32_t ErrorSDLInitFailed { 1 };
|
||||
inline static constexpr int32_t ErrorSDLTTFInitFailed { 2 };
|
||||
|
||||
};
|
||||
}
|
||||
189
src/ogfx/vendor/sdl3_gfx/SDL3_framerate.c
vendored
Normal file
189
src/ogfx/vendor/sdl3_gfx/SDL3_framerate.c
vendored
Normal 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;
|
||||
}
|
||||
100
src/ogfx/vendor/sdl3_gfx/SDL3_framerate.h
vendored
Normal file
100
src/ogfx/vendor/sdl3_gfx/SDL3_framerate.h
vendored
Normal 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 */
|
||||
3794
src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.c
vendored
Normal file
3794
src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
241
src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.h
vendored
Normal file
241
src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.h
vendored
Normal 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 */
|
||||
3106
src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives_font.h
vendored
Normal file
3106
src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives_font.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
1617
src/ogfx/vendor/sdl3_gfx/SDL3_imageFilter.c
vendored
Normal file
1617
src/ogfx/vendor/sdl3_gfx/SDL3_imageFilter.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
161
src/ogfx/vendor/sdl3_gfx/SDL3_imageFilter.h
vendored
Normal file
161
src/ogfx/vendor/sdl3_gfx/SDL3_imageFilter.h
vendored
Normal 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
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
123
src/ogfx/vendor/sdl3_gfx/SDL3_rotozoom.h
vendored
Normal 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 */
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <ostd/utils/Defines.hpp>
|
||||
|
||||
#define get_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n
|
||||
#define set_bit(__bit_field, __bit_n ) __bit_field.bits.b##__bit_n = true
|
||||
|
|
|
|||
|
|
@ -78,5 +78,62 @@ namespace ostd
|
|||
uint8_t g;
|
||||
uint8_t b;
|
||||
uint8_t a;
|
||||
|
||||
public:
|
||||
};
|
||||
struct Colors
|
||||
{
|
||||
inline static const Color Transparent { 0, 0, 0, 0 };
|
||||
inline static const Color Black { 0, 0, 0, 255 };
|
||||
inline static const Color White { 255, 255, 255, 255 };
|
||||
inline static const Color Gray { 128, 128, 128, 255 };
|
||||
inline static const Color LightGray { 192, 192, 192, 255 };
|
||||
inline static const Color DarkGray { 64, 64, 64, 255 };
|
||||
|
||||
inline static const Color Red { 255, 0, 0, 255 };
|
||||
inline static const Color Green { 0, 255, 0, 255 };
|
||||
inline static const Color Blue { 0, 0, 255, 255 };
|
||||
|
||||
inline static const Color Yellow { 255, 255, 0, 255 };
|
||||
inline static const Color Cyan { 0, 255, 255, 255 };
|
||||
inline static const Color Magenta { 255, 0, 255, 255 };
|
||||
|
||||
inline static const Color Orange { 255, 165, 0, 255 };
|
||||
inline static const Color Purple { 128, 0, 128, 255 };
|
||||
inline static const Color Brown { 139, 69, 19, 255 };
|
||||
inline static const Color Pink { 255, 192, 203, 255 };
|
||||
inline static const Color Lime { 50, 205, 50, 255 };
|
||||
inline static const Color Olive { 128, 128, 0, 255 };
|
||||
inline static const Color Teal { 0, 128, 128, 255 };
|
||||
inline static const Color Navy { 0, 0, 128, 255 };
|
||||
inline static const Color Maroon { 128, 0, 0, 255 };
|
||||
inline static const Color Indigo { 75, 0, 130, 255 };
|
||||
inline static const Color Gold { 255, 215, 0, 255 };
|
||||
inline static const Color Silver { 192, 192, 192, 255 };
|
||||
inline static const Color Beige { 245, 245, 220, 255 };
|
||||
inline static const Color Coral { 255, 127, 80, 255 };
|
||||
inline static const Color Salmon { 250, 128, 114, 255 };
|
||||
inline static const Color Chocolate { 210, 105, 30, 255 };
|
||||
inline static const Color Khaki { 240, 230, 140, 255 };
|
||||
inline static const Color Lavender { 230, 230, 250, 255 };
|
||||
inline static const Color Mint { 189, 252, 201, 255 };
|
||||
inline static const Color SkyBlue { 135, 206, 235, 255 };
|
||||
inline static const Color RoyalBlue { 65, 105, 225, 255 };
|
||||
inline static const Color DeepSkyBlue { 0, 191, 255, 255 };
|
||||
inline static const Color Turquoise { 64, 224, 208, 255 };
|
||||
inline static const Color Aquamarine { 127, 255, 212, 255 };
|
||||
inline static const Color ForestGreen { 34, 139, 34, 255 };
|
||||
inline static const Color SeaGreen { 46, 139, 87, 255 };
|
||||
inline static const Color SpringGreen { 0, 255, 127, 255 };
|
||||
inline static const Color Firebrick { 178, 34, 34, 255 };
|
||||
inline static const Color Crimson { 220, 20, 60, 255 };
|
||||
inline static const Color Tomato { 255, 99, 71, 255 };
|
||||
inline static const Color DarkOrange { 255, 140, 0, 255 };
|
||||
inline static const Color DarkRed { 139, 0, 0, 255 };
|
||||
inline static const Color DarkBlue { 0, 0, 139, 255 };
|
||||
inline static const Color DarkGreen { 0, 100, 0, 255 };
|
||||
inline static const Color DarkCyan { 0, 139, 139, 255 };
|
||||
inline static const Color DarkMagenta { 139, 0, 139, 255 };
|
||||
inline static const Color DarkYellow { 204, 204, 0, 255 };
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <ostd/utils/Defines.hpp>
|
||||
|
||||
namespace ostd
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
namespace ogfx
|
||||
{
|
||||
class WindowBase;
|
||||
class WindowCore;
|
||||
class BasicRenderer2D;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -345,6 +345,11 @@ namespace ostd
|
|||
inline virtual Vec2 bottomLeft(void) const { return Vec2(getx(), gety() + geth()); }
|
||||
inline virtual Vec2 bottomRight(void) const { return Vec2(getx() + getw(), gety() + geth()); }
|
||||
|
||||
inline virtual float left(void) const { return getx(); }
|
||||
inline virtual float right(void) const { return getw(); }
|
||||
inline virtual float top(void) const { return gety(); }
|
||||
inline virtual float bottom(void) const { return geth(); }
|
||||
|
||||
inline virtual bool intersects(Rectangle rect, bool includeBounds = true) const
|
||||
{
|
||||
if (includeBounds)
|
||||
|
|
@ -376,9 +381,9 @@ namespace ostd
|
|||
inline virtual bool contains(Vec2 p, bool includeBounds = false) const
|
||||
{
|
||||
if (includeBounds)
|
||||
return p.x >= x && p.y >= y & p.x <= x + w && p.y <= y + h;
|
||||
return p.x >= x && p.y >= y && p.x <= x + w && p.y <= y + h;
|
||||
else
|
||||
return p.x > x && p.y > y & p.x < x + w && p.y < y + h;
|
||||
return p.x > x && p.y > y && p.x < x + w && p.y < y + h;
|
||||
}
|
||||
inline virtual bool contains(float xx, float yy, bool includeBounds = false) const { return contains({ xx, yy }); }
|
||||
|
||||
|
|
|
|||
|
|
@ -45,3 +45,11 @@
|
|||
|
||||
#include <ostd/utils/Signals.hpp>
|
||||
#include <ostd/utils/Time.hpp>
|
||||
|
||||
namespace ostd
|
||||
{
|
||||
inline void initialize(void)
|
||||
{
|
||||
ostd::SignalHandler::init(true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include <mutex>
|
||||
#include <atomic>
|
||||
#include <optional>
|
||||
#include <ostd/utils/Defines.hpp>
|
||||
|
||||
namespace ostd
|
||||
{
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <unordered_map>
|
||||
#include <deque>
|
||||
#include <cstdint>
|
||||
#include <ostd/utils/Defines.hpp>
|
||||
|
||||
namespace ostd
|
||||
{
|
||||
|
|
|
|||
|
|
@ -27,10 +27,16 @@ namespace ostd
|
|||
SignalHandler::m_windowResizedRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||
SignalHandler::m_windowClosedRecievers.clear();
|
||||
SignalHandler::m_windowClosedRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||
SignalHandler::m_windowFocusedRecievers.clear();
|
||||
SignalHandler::m_windowFocusedRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||
SignalHandler::m_windowLostFocusRecievers.clear();
|
||||
SignalHandler::m_windowLostFocusRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||
SignalHandler::m_delegatedSignals.clear();
|
||||
SignalHandler::m_delegatedSignals.reserve(SignalHandler::__DELEGATED_SIGNALS_BUFFER_START_SIZE);
|
||||
SignalHandler::m_onGuiEventRecievers.clear();
|
||||
SignalHandler::m_onGuiEventRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||
SignalHandler::m_beforeSDLShutdownRecievers.clear();
|
||||
SignalHandler::m_beforeSDLShutdownRecievers.reserve(SignalHandler::__SIGNAL_BUFFER_START_SIZE);
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
|
|
@ -69,8 +75,14 @@ namespace ostd
|
|||
sig_list = &m_windowResizedRecievers;
|
||||
else if (signal_id == tBuiltinSignals::WindowClosed)
|
||||
sig_list = &m_windowClosedRecievers;
|
||||
else if (signal_id == tBuiltinSignals::WindowLostFocus)
|
||||
sig_list = &m_windowLostFocusRecievers;
|
||||
else if (signal_id == tBuiltinSignals::WindowFocused)
|
||||
sig_list = &m_windowFocusedRecievers;
|
||||
else if (signal_id == tBuiltinSignals::OnGuiEvent)
|
||||
sig_list = &m_onGuiEventRecievers;
|
||||
else if (signal_id == tBuiltinSignals::BeforeSDLShutdown)
|
||||
sig_list = &m_beforeSDLShutdownRecievers;
|
||||
else if (signal_id > tBuiltinSignals::CustomSignalBase)
|
||||
sig_list = &m_customRecievers;
|
||||
if (sig_list == nullptr)
|
||||
|
|
@ -108,8 +120,14 @@ namespace ostd
|
|||
m_windowResizedRecievers.push_back({ &object, signal_id });
|
||||
else if (signal_id == tBuiltinSignals::WindowClosed)
|
||||
m_windowClosedRecievers.push_back({ &object, signal_id });
|
||||
else if (signal_id == tBuiltinSignals::WindowLostFocus)
|
||||
m_windowLostFocusRecievers.push_back({ &object, signal_id });
|
||||
else if (signal_id == tBuiltinSignals::WindowFocused)
|
||||
m_windowFocusedRecievers.push_back({ &object, signal_id });
|
||||
else if (signal_id == tBuiltinSignals::OnGuiEvent)
|
||||
m_onGuiEventRecievers.push_back({ &object, signal_id });
|
||||
else if (signal_id == tBuiltinSignals::BeforeSDLShutdown)
|
||||
m_beforeSDLShutdownRecievers.push_back({ &object, signal_id });
|
||||
else if (signal_id > tBuiltinSignals::CustomSignalBase)
|
||||
m_customRecievers.push_back({ &object, signal_id });
|
||||
else
|
||||
|
|
|
|||
|
|
@ -45,8 +45,12 @@ namespace ostd
|
|||
|
||||
inline static constexpr uint32_t OnGuiEvent = 0x2001;
|
||||
|
||||
inline static constexpr uint32_t BeforeSDLShutdown = 0x3001;
|
||||
|
||||
inline static constexpr uint32_t WindowResized = 0x1001;
|
||||
inline static constexpr uint32_t WindowClosed = 0x1002;
|
||||
inline static constexpr uint32_t WindowFocused = 0x1003;
|
||||
inline static constexpr uint32_t WindowLostFocus = 0x1004;
|
||||
/*********************/
|
||||
|
||||
inline static constexpr uint32_t CustomSignalBase = 0xFF0000;
|
||||
|
|
@ -105,7 +109,10 @@ namespace ostd
|
|||
inline static std::vector<tSignalObjPair> m_textEnteredRecievers;
|
||||
inline static std::vector<tSignalObjPair> m_windowResizedRecievers;
|
||||
inline static std::vector<tSignalObjPair> m_windowClosedRecievers;
|
||||
inline static std::vector<tSignalObjPair> m_windowFocusedRecievers;
|
||||
inline static std::vector<tSignalObjPair> m_windowLostFocusRecievers;
|
||||
inline static std::vector<tSignalObjPair> m_onGuiEventRecievers;
|
||||
inline static std::vector<tSignalObjPair> m_beforeSDLShutdownRecievers;
|
||||
/************************************/
|
||||
|
||||
inline static constexpr uint16_t __SIGNAL_BUFFER_START_SIZE { 128 };
|
||||
|
|
@ -113,17 +120,4 @@ namespace ostd
|
|||
|
||||
inline static bool m_initialized { false };
|
||||
};
|
||||
|
||||
class WindowSizeObj : public BaseObject
|
||||
{
|
||||
public:
|
||||
const int32_t width;
|
||||
const int32_t height;
|
||||
|
||||
inline WindowSizeObj(int32_t _w, int32_t _h) : width(_w), height(_h)
|
||||
{
|
||||
setTypeName("ox::WindowSizeObj");
|
||||
validate();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
190
src/test.cpp
190
src/test.cpp
|
|
@ -1,190 +0,0 @@
|
|||
/*
|
||||
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 <ostd/String.hpp>
|
||||
// #include <ostd/IOHandlers.hpp>
|
||||
// #include <ostd/Logger.hpp>
|
||||
// #include <ostd/Console.hpp>
|
||||
|
||||
#include "Image.hpp"
|
||||
#include "utils/Hash.hpp"
|
||||
#include <ogfx/WindowBase.hpp>
|
||||
#include <ogfx/RawTextInput.hpp>
|
||||
#include <ostd/ostd.hpp>
|
||||
|
||||
ostd::ConsoleOutputHandler out;
|
||||
|
||||
class Window : public ogfx::WindowBase
|
||||
{
|
||||
public:
|
||||
inline Window(void) : m_sigHandler(m_textInput, *this) { }
|
||||
inline void onInitialize(void) override
|
||||
{
|
||||
enableSignals();
|
||||
connectSignal(ostd::tBuiltinSignals::KeyReleased);
|
||||
connectSignal(ogfx::gui::RawTextInput::actionEventSignalID);
|
||||
|
||||
m_gfx.init(*this);
|
||||
m_gfx.setFont("res/ttf/Courier Prime.ttf");
|
||||
|
||||
float w = getWindowWidth();
|
||||
float h = 40.0f;
|
||||
m_textInput.create({ 0.0f, (float)(getWindowHeight() - h) }, { w, h }, "MainInputTXT");
|
||||
m_textInput.setEventListener(m_sigHandler);
|
||||
// m_textInput.setCharacterFilter(m_numCharFilter);
|
||||
m_textInput.getTheme().extraPaddingTop = 3;
|
||||
|
||||
m_testImg.loadFromFile("res/test.png", m_gfx);
|
||||
out.p("Image loaded: ").p(STR_BOOL(m_testImg.isLoaded())).nl();
|
||||
out.p(" ").p(m_testImg.getSize().x).nl();
|
||||
}
|
||||
|
||||
inline void handleSignal(ostd::tSignal& signal) override
|
||||
{
|
||||
if (signal.ID == ostd::tBuiltinSignals::KeyReleased)
|
||||
{
|
||||
auto& evtData = (ogfx::KeyEventData&)signal.userData;
|
||||
if (evtData.keyCode == SDLK_ESCAPE)
|
||||
close();
|
||||
}
|
||||
if (signal.ID == ogfx::gui::RawTextInput::actionEventSignalID)
|
||||
{
|
||||
auto& data = (ogfx::gui::RawTextInput::ActionEventData&)signal.userData;
|
||||
if (data.senderName != "MainInputTXT")
|
||||
return;
|
||||
if (data.eventType == ogfx::gui::RawTextInput::eActionEventType::Enter)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Green).p(data.sender.getText()).reset().nl();
|
||||
data.sender.setText("");
|
||||
}
|
||||
else if (data.eventType == ogfx::gui::RawTextInput::eActionEventType::Tab)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Red).p("TAB").reset().nl();
|
||||
data.sender.appendText("TAB");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void onRender(void) override
|
||||
{
|
||||
m_textInput.render(m_gfx);
|
||||
// m_gfx.drawImage(m_testImg, { 0, 0 });´
|
||||
}
|
||||
|
||||
inline void onFixedUpdate(double frameTime_s) override
|
||||
{
|
||||
m_textInput.fixedUpdate();
|
||||
}
|
||||
|
||||
inline void onUpdate(void) override
|
||||
{
|
||||
m_textInput.update();
|
||||
}
|
||||
|
||||
private:
|
||||
ogfx::gui::RawTextInput m_textInput;
|
||||
ogfx::BasicRenderer2D m_gfx;
|
||||
ogfx::gui::RawTextInputEventListener m_sigHandler;
|
||||
ogfx::gui::RawTextInputNumberCharacterFilter m_numCharFilter;
|
||||
|
||||
ogfx::Image m_testImg;
|
||||
};
|
||||
|
||||
// void test2(const std::string& str) {}
|
||||
// void test3(const ostd::String& str) {}
|
||||
// void test4(const char* str) {}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
out.p(STR_BOOL(ostd::Hash::md5("") == "d41d8cd98f00b204e9800998ecf8427e")).nl();
|
||||
out.p(STR_BOOL(ostd::Hash::md5("abc") == "900150983cd24fb0d6963f7d28e17f72")).nl();
|
||||
out.p(STR_BOOL(ostd::Hash::md5("message digest") == "f96b697d7cb7938d525a2f31aaf161d0")).nl();
|
||||
|
||||
Window window;
|
||||
window.initialize(1280, 720, "OmniaFramework - Test Window");
|
||||
window.setClearColor({ 0, 2 , 15 });
|
||||
|
||||
while (window.isRunning())
|
||||
{
|
||||
window.update();
|
||||
}
|
||||
|
||||
|
||||
// out.fg(ostd::ConsoleColors::Red).p("Hello World!!").reset().nl();
|
||||
|
||||
// ostd::String str1, str2 = "Hello";
|
||||
// bool b = str1 == str2;
|
||||
// const ostd::String str3 = "CIAO";
|
||||
// b = str2 == str1;
|
||||
// b = str3 == "CICCIO";
|
||||
// // b = "ciao" == str2;
|
||||
// str2 = str3;
|
||||
// std::string str = "cc";
|
||||
// str1 = str;
|
||||
// test2(str1);
|
||||
// test3(str);
|
||||
// str1 = str2 + str;
|
||||
// str1 = str2 + "str";
|
||||
// str1 = str2 + str3;
|
||||
// str1 = str2 + str1;
|
||||
// test4(str1);
|
||||
// test4(str3);
|
||||
|
||||
// str1 += "ciao";
|
||||
// str1 += str;
|
||||
// str1 += str1;
|
||||
// str1 += str3;
|
||||
// str1 += 'c';
|
||||
|
||||
// OX_FATAL(str2);
|
||||
|
||||
// ostd::RegexRichString rgxrstr("Hello World");
|
||||
// rgxrstr.fg("Hello", "Blue");
|
||||
// std::cout << rgxrstr << "\n";
|
||||
|
||||
// out.nl().nl();
|
||||
// ostd::String test_str = "Hello World, my love";
|
||||
// ostd::String test_str_2 = "HEELO";
|
||||
// ostd::String test_str_3 = "0123456789";
|
||||
// out.p("==========\n");
|
||||
// test_str.fixedLength(10, ' ', "..........");
|
||||
// test_str_2.fixedLength(10);
|
||||
// test_str_3.fixedLength(10);
|
||||
// out.p(test_str).p("|").nl();
|
||||
// out.p(test_str_2).p("|").nl();
|
||||
// out.p(test_str_3).p("|").nl();
|
||||
|
||||
// ostd::KeyboardController keyboard;
|
||||
// keyboard.disableCommandBuffer();
|
||||
|
||||
// out.p("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n");
|
||||
// out.p("HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
|
||||
// out.p("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
|
||||
// out.p(" ");
|
||||
// out.p("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
|
||||
|
||||
// ostd::eKeys k = ostd::eKeys::NoKeyPressed;
|
||||
// do
|
||||
// {
|
||||
// k = keyboard.waitForKeyPress();
|
||||
// } while (k != ostd::eKeys::Escape);
|
||||
|
||||
return 0;
|
||||
}
|
||||
103
src/test/GraphicsWindowTest.cpp
Normal file
103
src/test/GraphicsWindowTest.cpp
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
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 <ogfx/ogfx.hpp>
|
||||
|
||||
ostd::ConsoleOutputHandler out;
|
||||
|
||||
class Window : public ogfx::GraphicsWindow
|
||||
{
|
||||
public:
|
||||
inline Window(void) : m_sigHandler(m_textInput, *this) { }
|
||||
inline void onInitialize(void) override
|
||||
{
|
||||
connectSignal(ogfx::gui::RawTextInput::actionEventSignalID);
|
||||
|
||||
m_gfx.init(*this);
|
||||
m_gfx.setFont("res/ttf/Courier Prime.ttf");
|
||||
|
||||
float w = getWindowWidth();
|
||||
float h = 40.0f;
|
||||
m_textInput.create({ 0.0f, (float)(getWindowHeight() - h) }, { w, h }, "MainInputTXT");
|
||||
m_textInput.setEventListener(m_sigHandler);
|
||||
// m_textInput.setCharacterFilter(m_numCharFilter);
|
||||
m_textInput.getTheme().extraPaddingTop = 3;
|
||||
}
|
||||
|
||||
inline void handleSignal(ostd::tSignal& signal) override
|
||||
{
|
||||
if (signal.ID == ostd::tBuiltinSignals::KeyReleased)
|
||||
{
|
||||
auto& evtData = (ogfx::KeyEventData&)signal.userData;
|
||||
if (evtData.keyCode == SDLK_ESCAPE)
|
||||
close();
|
||||
}
|
||||
if (signal.ID == ogfx::gui::RawTextInput::actionEventSignalID)
|
||||
{
|
||||
auto& data = (ogfx::gui::RawTextInput::ActionEventData&)signal.userData;
|
||||
if (data.senderName != "MainInputTXT")
|
||||
return;
|
||||
if (data.eventType == ogfx::gui::RawTextInput::eActionEventType::Enter)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Green).p(data.sender.getText()).reset().nl();
|
||||
data.sender.setText("");
|
||||
}
|
||||
else if (data.eventType == ogfx::gui::RawTextInput::eActionEventType::Tab)
|
||||
{
|
||||
out.fg(ostd::ConsoleColors::Red).p("TAB").reset().nl();
|
||||
data.sender.appendText("TAB");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void onRender(void) override
|
||||
{
|
||||
m_textInput.render(m_gfx);
|
||||
}
|
||||
|
||||
inline void onFixedUpdate(double frameTime_s) override
|
||||
{
|
||||
m_textInput.fixedUpdate();
|
||||
}
|
||||
|
||||
inline void onUpdate(void) override
|
||||
{
|
||||
m_textInput.update();
|
||||
}
|
||||
|
||||
private:
|
||||
ogfx::gui::RawTextInput m_textInput;
|
||||
ogfx::BasicRenderer2D m_gfx;
|
||||
ogfx::gui::RawTextInputEventListener m_sigHandler;
|
||||
ogfx::gui::RawTextInputNumberCharacterFilter m_numCharFilter;
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Window window;
|
||||
window.initialize(800, 600, "OmniaFramework - Test Window");
|
||||
window.setClearColor({ 0, 2 , 15 });
|
||||
|
||||
while (window.isRunning())
|
||||
{
|
||||
window.mainLoop();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
98
src/test/GuiTest.cpp
Normal file
98
src/test/GuiTest.cpp
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Label
|
||||
* Button
|
||||
* Panel / Container
|
||||
* Checkbox
|
||||
* Radio Button (Group)
|
||||
* Text Input
|
||||
* Horizontal Slider
|
||||
* Image / Icon
|
||||
* ScrollView
|
||||
* ListBox
|
||||
* ComboBox
|
||||
* TreeView
|
||||
* Save/Open File Dialogs (and folder dialogs)
|
||||
* Tab Panel
|
||||
*/
|
||||
|
||||
#include <ogfx/ogfx.hpp>
|
||||
|
||||
ostd::ConsoleOutputHandler out;
|
||||
|
||||
class Window : public ogfx::gui::Window
|
||||
{
|
||||
public:
|
||||
inline Window(void) { }
|
||||
inline void onInitialize(void) override
|
||||
{
|
||||
m_label1.setPosition(100, 200);
|
||||
m_label1.setText("Hello World!");
|
||||
m_label1.setMouseMovedCallback([&](const ogfx::gui::Event& event) -> void {
|
||||
m_label1.applyThemeValue(m_theme, "label.backgroundColor", ostd::Colors::DarkBlue, false);
|
||||
});
|
||||
addWidget(m_label1);
|
||||
|
||||
m_label2.setPosition(100, 400);
|
||||
m_label2.setText("Ciccia Bella!");
|
||||
addWidget(m_label2);
|
||||
|
||||
m_theme.set("label.textColor", ostd::Colors::White);
|
||||
m_theme.set("label.backgroundColor", ostd::Colors::DarkRed);
|
||||
m_theme.set("label.showBackground", true);
|
||||
m_theme.set("label.borderRadius", 0);
|
||||
setTheme(m_theme);
|
||||
}
|
||||
|
||||
inline void onSignal(ostd::tSignal& signal) override
|
||||
{
|
||||
if (signal.ID == ostd::tBuiltinSignals::KeyReleased)
|
||||
{
|
||||
auto& evtData = (ogfx::KeyEventData&)signal.userData;
|
||||
if (evtData.keyCode == SDLK_ESCAPE)
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
void onRedraw(ogfx::BasicRenderer2D& gfx) override
|
||||
{
|
||||
// wout().fg(ostd::Color { 255, 0, 0 }).p("Hello ").fg(ostd::Color { 0, 0, 255 }).p("World");
|
||||
}
|
||||
|
||||
private:
|
||||
ogfx::gui::widgets::Label m_label1 { *this };
|
||||
ogfx::gui::widgets::Label m_label2 { *this };
|
||||
ogfx::gui::Theme m_theme = ogfx::gui::Theme();
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
ostd::initialize();
|
||||
Window window;
|
||||
window.initialize(800, 600, "OmniaFramework - Test Window");
|
||||
window.setClearColor({ 0, 0, 0 });
|
||||
window.mainLoop();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in a new issue