Added possibility to load fonts from memory + added UbuntuMonoRegular as
default embedded font
This commit is contained in:
parent
1d071786d5
commit
23e69bfdfc
32 changed files with 9815 additions and 52 deletions
|
|
@ -89,6 +89,7 @@ list(APPEND OGFX_SOURCE_FILES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/Window.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/WindowOutputHandler.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/Widget.cpp
|
||||||
|
|
||||||
# render
|
# render
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/BasicRenderer.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/BasicRenderer.cpp
|
||||||
|
|
@ -97,6 +98,7 @@ list(APPEND OGFX_SOURCE_FILES
|
||||||
|
|
||||||
# resources
|
# resources
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/resources/Image.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/resources/Image.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/resources/UbuntuMonoRegularTTF.cpp
|
||||||
|
|
||||||
# utils
|
# utils
|
||||||
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/utils/Animation.cpp
|
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/utils/Animation.cpp
|
||||||
|
|
|
||||||
4
build
4
build
|
|
@ -21,7 +21,7 @@ if [[ "$1" == "debug" || "$1" == "release" ]]; then
|
||||||
rm -rf bin
|
rm -rf bin
|
||||||
cmake -B bin -S ./ -G "$MAKEFILE_TYPE" -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
cmake -B bin -S ./ -G "$MAKEFILE_TYPE" -DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||||
$MAKE_COMMAND -C bin $NJOBS --no-print-directory
|
$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=$(cat other/build.nr)
|
||||||
build_number=$((build_number + 1))
|
build_number=$((build_number + 1))
|
||||||
truncate -s 0 other/build.nr
|
truncate -s 0 other/build.nr
|
||||||
|
|
@ -34,7 +34,7 @@ elif [[ "$1" == "install" ]]; then
|
||||||
./install_release.sh
|
./install_release.sh
|
||||||
cd ..
|
cd ..
|
||||||
else
|
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"
|
printf "\n\033[0;32mBuilding Changes...\n\n\033[0m"
|
||||||
$MAKE_COMMAND -C bin $NJOBS --no-print-directory
|
$MAKE_COMMAND -C bin $NJOBS --no-print-directory
|
||||||
if [[ "$1" == "run" ]]; then
|
if [[ "$1" == "run" ]]; then
|
||||||
|
|
|
||||||
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,20 +0,0 @@
|
||||||
Copyright (C) 1995-2024 Jean-loup Gailly and Mark Adler
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
|
|
||||||
Jean-loup Gailly Mark Adler
|
|
||||||
jloup@gzip.org madler@alumni.caltech.edu
|
|
||||||
|
|
@ -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
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
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
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
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
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
|
@ -15,4 +15,3 @@ freely, subject to the following restrictions:
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
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 +1 @@
|
||||||
2039
|
2040
|
||||||
|
|
|
||||||
29
src/ogfx/gui/Widget.cpp
Normal file
29
src/ogfx/gui/Widget.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
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 "Widget.hpp"
|
||||||
|
|
||||||
|
namespace ogfx
|
||||||
|
{
|
||||||
|
namespace gui
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/ogfx/gui/Widget.hpp
Normal file
36
src/ogfx/gui/Widget.hpp
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
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>
|
||||||
|
|
||||||
|
namespace ogfx
|
||||||
|
{
|
||||||
|
namespace gui
|
||||||
|
{
|
||||||
|
class Widget : public ostd::BaseObject, public ostd::Rectangle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
#include "../../ostd/utils/Time.hpp"
|
#include "../../ostd/utils/Time.hpp"
|
||||||
|
#include "io/IOHandlers.hpp"
|
||||||
|
#include "string/String.hpp"
|
||||||
#include <SDL2/SDL_render.h>
|
#include <SDL2/SDL_render.h>
|
||||||
#include <SDL3/SDL_events.h>
|
#include <SDL3/SDL_events.h>
|
||||||
#include <SDL3/SDL_keycode.h>
|
#include <SDL3/SDL_keycode.h>
|
||||||
|
|
@ -157,7 +159,7 @@ namespace ogfx
|
||||||
|
|
||||||
if (isBlockingEventsEnabled())
|
if (isBlockingEventsEnabled())
|
||||||
{
|
{
|
||||||
if (SDL_WaitEvent(&event))
|
if (SDL_WaitEventTimeout(&event, 16))
|
||||||
__handle_event(event);
|
__handle_event(event);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -283,6 +285,7 @@ namespace ogfx
|
||||||
{
|
{
|
||||||
enableBlockingEvents();
|
enableBlockingEvents();
|
||||||
setTypeName("ogfx::gui::Window");
|
setTypeName("ogfx::gui::Window");
|
||||||
|
m_gfx.init(*this);
|
||||||
onInitialize();
|
onInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -298,7 +301,7 @@ namespace ogfx
|
||||||
handle_events();
|
handle_events();
|
||||||
SDL_SetRenderDrawColor(m_renderer, getClearColor().r, getClearColor().g, getClearColor().b, getClearColor().a);
|
SDL_SetRenderDrawColor(m_renderer, getClearColor().r, getClearColor().g, getClearColor().b, getClearColor().a);
|
||||||
SDL_RenderClear(m_renderer);
|
SDL_RenderClear(m_renderer);
|
||||||
|
m_gfx.drawString("Hello World", { 100, 100 }, { 255, 0, 0 });
|
||||||
SDL_RenderPresent(m_renderer);
|
SDL_RenderPresent(m_renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#include <ostd/utils/Time.hpp>
|
#include <ostd/utils/Time.hpp>
|
||||||
#include <ostd/io/IOHandlers.hpp>
|
#include <ostd/io/IOHandlers.hpp>
|
||||||
#include <ogfx/gui/Events.hpp>
|
#include <ogfx/gui/Events.hpp>
|
||||||
|
#include <ogfx/render/BasicRenderer.hpp>
|
||||||
|
|
||||||
namespace ogfx
|
namespace ogfx
|
||||||
{
|
{
|
||||||
|
|
@ -147,6 +148,8 @@ namespace ogfx
|
||||||
void __main_loop(void) override;
|
void __main_loop(void) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ogfx::BasicRenderer2D m_gfx;
|
||||||
|
ostd::ConsoleOutputHandler m_out;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ namespace ogfx
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsWindowOutputHandler::attachWindow(ogfx::GraphicsWindow& window)
|
void GraphicsWindowOutputHandler::attachWindow(ogfx::WindowCore& window)
|
||||||
{
|
{
|
||||||
if (m_window != nullptr) return;
|
if (m_window != nullptr) return;
|
||||||
m_window = &window;
|
m_window = &window;
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,13 @@
|
||||||
|
|
||||||
namespace ogfx
|
namespace ogfx
|
||||||
{
|
{
|
||||||
|
class WindowCore;
|
||||||
class GraphicsWindowOutputHandler : public ostd::OutputHandlerBase
|
class GraphicsWindowOutputHandler : public ostd::OutputHandlerBase
|
||||||
{
|
{
|
||||||
public: enum class eWrapMode { TripleDots, NewLine };
|
public: enum class eWrapMode { TripleDots, NewLine };
|
||||||
public:
|
public:
|
||||||
GraphicsWindowOutputHandler(void);
|
GraphicsWindowOutputHandler(void);
|
||||||
void attachWindow(GraphicsWindow& window);
|
void attachWindow(WindowCore& window);
|
||||||
void setMonospaceFont(const ostd::String& filePath);
|
void setMonospaceFont(const ostd::String& filePath);
|
||||||
ostd::Vec2 getStringSize(const ostd::String& str);
|
ostd::Vec2 getStringSize(const ostd::String& str);
|
||||||
bool isReady(void);
|
bool isReady(void);
|
||||||
|
|
@ -113,7 +114,7 @@ namespace ogfx
|
||||||
ostd::Color m_defaultForegroundColor { 0, 220, 0, 255 };
|
ostd::Color m_defaultForegroundColor { 0, 220, 0, 255 };
|
||||||
ostd::Vec2 m_curosrPosition;
|
ostd::Vec2 m_curosrPosition;
|
||||||
BasicRenderer2D m_renderer;
|
BasicRenderer2D m_renderer;
|
||||||
GraphicsWindow* m_window { nullptr };
|
WindowCore* m_window { nullptr };
|
||||||
int32_t m_fontSize { 20 };
|
int32_t m_fontSize { 20 };
|
||||||
ostd::Vec2 m_charSize;
|
ostd::Vec2 m_charSize;
|
||||||
ostd::IPoint m_consoleSize { 0, 0 };
|
ostd::IPoint m_consoleSize { 0, 0 };
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ namespace ogfx
|
||||||
m_window = &window;
|
m_window = &window;
|
||||||
m_ttfr.init(window.getSDLRenderer());
|
m_ttfr.init(window.getSDLRenderer());
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
|
setDefaultFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicRenderer2D::setFont(const ostd::String& fontFilePath)
|
void BasicRenderer2D::setFont(const ostd::String& fontFilePath)
|
||||||
|
|
@ -36,6 +37,12 @@ namespace ogfx
|
||||||
m_ttfr.openFont(fontFilePath, m_ttfr.getFontSize());
|
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)
|
void BasicRenderer2D::setFontSize(int32_t fontSize)
|
||||||
{
|
{
|
||||||
if (!m_initialized) return;
|
if (!m_initialized) return;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "gui/Window.hpp"
|
|
||||||
#include <ogfx/render/FontUtils.hpp>
|
#include <ogfx/render/FontUtils.hpp>
|
||||||
#include <ogfx/utils/Animation.hpp>
|
#include <ogfx/utils/Animation.hpp>
|
||||||
#include <ostd/math/Geometry.hpp>
|
#include <ostd/math/Geometry.hpp>
|
||||||
|
|
@ -40,6 +39,7 @@ namespace ogfx
|
||||||
inline WindowCore& getWindow(void) { return *m_window; }
|
inline WindowCore& getWindow(void) { return *m_window; }
|
||||||
inline bool isInitialized(void) { return m_initialized; }
|
inline bool isInitialized(void) { return m_initialized; }
|
||||||
void setFont(const ostd::String& fontFilePath);
|
void setFont(const ostd::String& fontFilePath);
|
||||||
|
void setDefaultFont(void);
|
||||||
void setFontSize(int32_t fontSize);
|
void setFontSize(int32_t fontSize);
|
||||||
|
|
||||||
void drawImage(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 });
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FontUtils.hpp"
|
#include "FontUtils.hpp"
|
||||||
#include <SDL3/SDL_error.h>
|
#include "../resources/UbuntuMonoRegularTTF.hpp"
|
||||||
#include <SDL3/SDL_render.h>
|
|
||||||
|
|
||||||
namespace ogfx
|
namespace ogfx
|
||||||
{
|
{
|
||||||
|
|
@ -191,6 +190,11 @@ namespace ogfx
|
||||||
return set_error_state(tErrors::NoError);
|
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)
|
void TTFRenderer::closeFont(void)
|
||||||
{
|
{
|
||||||
if (!TTFRenderer::m_initialized || !m_fontOpen) return;
|
if (!TTFRenderer::m_initialized || !m_fontOpen) return;
|
||||||
|
|
@ -199,6 +203,7 @@ namespace ogfx
|
||||||
m_font = nullptr;
|
m_font = nullptr;
|
||||||
m_fontOpen = false;
|
m_fontOpen = false;
|
||||||
m_fontSize = DefaultFontSize;
|
m_fontSize = DefaultFontSize;
|
||||||
|
m_fontFromMemory = false;
|
||||||
set_error_state(tErrors::NoError);
|
set_error_state(tErrors::NoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,6 +222,29 @@ namespace ogfx
|
||||||
return set_error_state(tErrors::FailedToOpenFontFile);
|
return set_error_state(tErrors::FailedToOpenFontFile);
|
||||||
}
|
}
|
||||||
m_fontOpen = true;
|
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);
|
return set_error_state(tErrors::NoError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,17 @@ namespace ogfx
|
||||||
inline static constexpr int32_t TTFCreateTextureFromSurfaceFail = 7;
|
inline static constexpr int32_t TTFCreateTextureFromSurfaceFail = 7;
|
||||||
inline static constexpr int32_t NullFont = 8;
|
inline static constexpr int32_t NullFont = 8;
|
||||||
inline static constexpr int32_t NoFont = 9;
|
inline static constexpr int32_t NoFont = 9;
|
||||||
|
inline static constexpr int32_t FailedToOpenFontByteStrean = 10;
|
||||||
};
|
};
|
||||||
public:
|
public:
|
||||||
TTFRenderer(void) = default;
|
TTFRenderer(void) = default;
|
||||||
~TTFRenderer(void);
|
~TTFRenderer(void);
|
||||||
inline TTFRenderer(SDL_Renderer* renderer) { init(renderer); }
|
inline TTFRenderer(SDL_Renderer* renderer) { init(renderer); }
|
||||||
int32_t init(SDL_Renderer* renderer);
|
int32_t init(SDL_Renderer* renderer);
|
||||||
|
int32_t loadDefaultFont(int32_t fontSize = 0);
|
||||||
void closeFont(void);
|
void closeFont(void);
|
||||||
int32_t openFont(const ostd::String& fontPath, int32_t fontSize = 0);
|
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);
|
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 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);
|
void renderCenteredText(const ostd::String& message, int32_t center_x, int32_t center_y, const ostd::Color& color, int32_t fontSize = 0);
|
||||||
|
|
@ -55,7 +58,7 @@ namespace ogfx
|
||||||
inline bool isInitialized(void) { return TTFRenderer::m_initialized; }
|
inline bool isInitialized(void) { return TTFRenderer::m_initialized; }
|
||||||
inline bool hasOpenFont(void) { return m_fontOpen; }
|
inline bool hasOpenFont(void) { return m_fontOpen; }
|
||||||
inline TTF_Font* getSDLFont(void) { return m_font; }
|
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 geterrorState(void) { return m_errorState; }
|
||||||
inline int32_t getFontSize(void) { return m_fontSize; }
|
inline int32_t getFontSize(void) { return m_fontSize; }
|
||||||
|
|
||||||
|
|
@ -71,6 +74,7 @@ namespace ogfx
|
||||||
SDL_Renderer* m_renderer { nullptr };
|
SDL_Renderer* m_renderer { nullptr };
|
||||||
int32_t m_errorState { tErrors::NoError };
|
int32_t m_errorState { tErrors::NoError };
|
||||||
int32_t m_fontSize { DefaultFontSize };
|
int32_t m_fontSize { DefaultFontSize };
|
||||||
|
bool m_fontFromMemory { false };
|
||||||
|
|
||||||
inline static constexpr int32_t DefaultFontSize { 16 };
|
inline static constexpr int32_t DefaultFontSize { 16 };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
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
29
src/ogfx/resources/UbuntuMonoRegularTTF.hpp
Normal file
29
src/ogfx/resources/UbuntuMonoRegularTTF.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
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>
|
||||||
|
|
||||||
|
namespace ogfx
|
||||||
|
{
|
||||||
|
extern const uint32_t ubuntu_mono_regular_ttf_size;
|
||||||
|
extern const ostd::UByte ubuntu_mono_regular_ttf_data[];
|
||||||
|
}
|
||||||
|
|
@ -113,17 +113,4 @@ namespace ostd
|
||||||
|
|
||||||
inline static bool m_initialized { false };
|
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();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue