Implemented new BasicRenderer2D with native SFML3 (and remove SDL3_gfx

dependency)
This commit is contained in:
OmniaX-Dev 2026-04-12 14:48:24 +02:00
parent 9a77ec20bc
commit 15d9d1265f
33 changed files with 1266 additions and 11586 deletions

View file

@ -1,3 +1,2 @@
CompileFlags: CompileFlags:
CompilationDatabase: bin CompilationDatabase: bin
Add: ["--target=x86_64-w64-mingw32"]

View file

@ -79,12 +79,6 @@ list(APPEND OSTD_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/src/ostd/utils/Time.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ostd/utils/Time.cpp
) )
list(APPEND OGFX_SOURCE_FILES list(APPEND OGFX_SOURCE_FILES
# sdl3_gfx
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_framerate.c
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.c
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_imageFilter.c
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/vendor/sdl3_gfx/SDL3_rotozoom.c
# gui # gui
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/RawTextInput.cpp
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/Window.cpp ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/gui/Window.cpp
@ -100,7 +94,6 @@ list(APPEND OGFX_SOURCE_FILES
# render # render
${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/BasicRenderer.cpp ${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 ${CMAKE_CURRENT_LIST_DIR}/src/ogfx/render/PixelRenderer.cpp
# resources # resources

View file

@ -11,6 +11,9 @@
***Implement margin for widgets ***Implement margin for widgets
***Implement mouse scroll callback ***Implement mouse scroll callback
Add theme caching Add theme caching
Implement callback for state changes in checkbox
FIX: WindowOutputHandler text rendering
find a way to add fixed update to gui::Window
Implement following widgets: Implement following widgets:

View file

@ -1 +1 @@
2054 2056

View file

@ -56,7 +56,6 @@ cp -r ../src/ostd/vendor/nlohmann $RELEASE_DIR/include/ostd/vendor/
# OGFX # OGFX
mkdir -p $RELEASE_DIR/include/ogfx/vendor/sdl3_gfx
mkdir -p $RELEASE_DIR/include/ogfx/gui mkdir -p $RELEASE_DIR/include/ogfx/gui
mkdir -p $RELEASE_DIR/include/ogfx/gui/widgets mkdir -p $RELEASE_DIR/include/ogfx/gui/widgets
mkdir -p $RELEASE_DIR/include/ogfx/render mkdir -p $RELEASE_DIR/include/ogfx/render
@ -68,5 +67,3 @@ find ../src/ogfx/gui/widgets -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/
find ../src/ogfx/render -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/render \; find ../src/ogfx/render -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/render \;
find ../src/ogfx/resources -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/resources \; find ../src/ogfx/resources -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/resources \;
find ../src/ogfx/utils -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/utils \; find ../src/ogfx/utils -maxdepth 1 -name "*.h*" -exec cp {} $RELEASE_DIR/include/ogfx/utils \;
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 \;

View file

@ -169,12 +169,12 @@ namespace ogfx
tmpStr2 = ""; tmpStr2 = "";
char c = text[i]; char c = text[i];
tmpStr1 += c; tmpStr1 += c;
int32_t strWidth1 = parent.m_gfx->getStringSize(tmpStr1, parent.m_fontSize).x; int32_t strWidth1 = parent.m_gfx->getStringDimensions(tmpStr1, parent.m_fontSize).x;
if (relativePosition.x > strWidth1) if (relativePosition.x > strWidth1)
continue; continue;
found = true; found = true;
tmpStr2 = tmpStr1.new_substr(0, tmpStr1.len() - 1); tmpStr2 = tmpStr1.new_substr(0, tmpStr1.len() - 1);
int32_t strWidth2 = (tmpStr2.len() > 0 ? parent.m_gfx->getStringSize(tmpStr2, parent.m_fontSize).x : 0); int32_t strWidth2 = (tmpStr2.len() > 0 ? parent.m_gfx->getStringDimensions(tmpStr2, parent.m_fontSize).x : 0);
int32_t d1 = (int32_t)std::abs(relativePosition.x - strWidth2); int32_t d1 = (int32_t)std::abs(relativePosition.x - strWidth2);
int32_t d2 = (int32_t)std::abs(strWidth1 - relativePosition.x); int32_t d2 = (int32_t)std::abs(strWidth1 - relativePosition.x);
if (d1 > d2) if (d1 > d2)
@ -221,7 +221,7 @@ namespace ogfx
if (m_cursorPosition > 0 && m_text != "") if (m_cursorPosition > 0 && m_text != "")
{ {
ostd::String s1 = m_text.new_substr(0, m_cursorPosition); ostd::String s1 = m_text.new_substr(0, m_cursorPosition);
strSize = gfx.getStringSize(s1, m_fontSize); strSize = gfx.getStringDimensions(s1, m_fontSize);
} }
gfx.outlinedRect(*this, m_theme.backgroundColor, m_theme.borderColor, 2); gfx.outlinedRect(*this, m_theme.backgroundColor, m_theme.borderColor, 2);

View file

@ -593,6 +593,7 @@ namespace ogfx
m_rootWidget.__update(); m_rootWidget.__update();
m_rootWidget.__draw(m_gfx); m_rootWidget.__draw(m_gfx);
onRedraw(m_gfx); onRedraw(m_gfx);
m_gfx.endFrame();
after_render(); after_render();
} }
} }

View file

@ -213,6 +213,7 @@ namespace ogfx
inline virtual void onClose(void) { } inline virtual void onClose(void) { }
inline virtual void onSDLEvent(SDL_Event& event) { } inline virtual void onSDLEvent(SDL_Event& event) { }
inline virtual void onRedraw(BasicRenderer2D& gfx) { } inline virtual void onRedraw(BasicRenderer2D& gfx) { }
inline virtual void onUpdate(void) { }
inline virtual void onSignal(ostd::Signal& signal) { } inline virtual void onSignal(ostd::Signal& signal) { }
protected: protected:

View file

@ -40,8 +40,9 @@ namespace ogfx
void GraphicsWindowOutputHandler::setMonospaceFont(const String& filePath) void GraphicsWindowOutputHandler::setMonospaceFont(const String& filePath)
{ {
m_renderer.setFont(filePath); //TODO: Fix
m_renderer.setFontSize(m_fontSize); // m_renderer.setFont(filePath);
// m_renderer.setFontSize(m_fontSize);
__update_char_size(); __update_char_size();
} }
@ -54,8 +55,8 @@ namespace ogfx
} }
bool GraphicsWindowOutputHandler::isReady(void) bool GraphicsWindowOutputHandler::isReady(void)
{ {//TODO: Fix
return m_window != nullptr && m_renderer.getTTFRenderer().hasOpenFont() && m_fontSize > 0; return m_window != nullptr && /* m_renderer.getTTFRenderer().hasOpenFont() &&*/ m_fontSize > 0;
} }
void GraphicsWindowOutputHandler::resetCursorPosition(void) void GraphicsWindowOutputHandler::resetCursorPosition(void)
@ -119,7 +120,8 @@ namespace ogfx
void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize) void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize)
{ {
m_fontSize = fontSize; m_fontSize = fontSize;
m_renderer.setFontSize(m_fontSize); //TODO: Fix
// m_renderer.setFontSize(m_fontSize);
__update_char_size(); __update_char_size();
} }
@ -132,7 +134,7 @@ namespace ogfx
{ {
if (fontSize > 0) if (fontSize > 0)
{ {
auto size = m_renderer.getStringSize("A", fontSize); auto size = m_renderer.getStringDimensions("A", fontSize);
return { (float)size.x, (float)size.y }; return { (float)size.x, (float)size.y };
} }
return m_charSize; return m_charSize;
@ -426,7 +428,7 @@ namespace ogfx
void GraphicsWindowOutputHandler::__update_char_size(void) void GraphicsWindowOutputHandler::__update_char_size(void)
{ {
auto size = m_renderer.getStringSize("A", m_fontSize); auto size = m_renderer.getStringDimensions("A", m_fontSize);
m_charSize = { (float)size.x, (float)size.y }; m_charSize = { (float)size.x, (float)size.y };
} }

View file

@ -85,7 +85,7 @@ namespace ogfx
void CheckBox::__update_size(ogfx::BasicRenderer2D& gfx) void CheckBox::__update_size(ogfx::BasicRenderer2D& gfx)
{ {
auto size = gfx.getStringSize(getText(), getFontSize()); auto size = gfx.getStringDimensions(getText(), getFontSize());
m_checkSize = { static_cast<float>(size.y), static_cast<float>(size.y) }; m_checkSize = { static_cast<float>(size.y), static_cast<float>(size.y) };
size.x += m_spacing + m_checkSize.x; size.x += m_spacing + m_checkSize.x;
size.x += getPadding().left(); size.x += getPadding().left();

View file

@ -72,7 +72,7 @@ namespace ogfx
void Label::__update_size(ogfx::BasicRenderer2D& gfx) void Label::__update_size(ogfx::BasicRenderer2D& gfx)
{ {
auto size = gfx.getStringSize(getText(), getFontSize()); auto size = gfx.getStringDimensions(getText(), getFontSize());
size.x += getPadding().left(); size.x += getPadding().left();
size.x += getPadding().right(); size.x += getPadding().right();
size.y += getPadding().top(); size.y += getPadding().top();

File diff suppressed because it is too large Load diff

View file

@ -30,44 +30,115 @@ namespace ogfx
class WindowCore; class WindowCore;
class BasicRenderer2D class BasicRenderer2D
{ {
public: struct tErrors
{
inline static constexpr int32_t NoError = 0;
inline static constexpr int32_t FailedToLoad = 1;
inline static constexpr int32_t FailedToOpenFontFile = 2;
inline static constexpr int32_t Uninitialized = 3;
inline static constexpr int32_t InvalidState = 5;
inline static constexpr int32_t TTFRenderTextBlendedFail = 6;
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;
};
private: class SignalHandler : public ostd::BaseObject
{
public:
SignalHandler(BasicRenderer2D& parent);
void handleSignal(ostd::Signal& signal) override;
private:
BasicRenderer2D& m_parent;
};
public: public:
BasicRenderer2D(void) = default; BasicRenderer2D(void) = default;
void init(WindowCore& window); ~BasicRenderer2D(void);
int32_t init(WindowCore& window);
inline TTFRenderer& getTTFRenderer(void) { return m_ttfr; } void flushBatch(void);
inline ostd::IPoint getStringSize(const ostd::String str, int32_t fontSize = 0) { return m_ttfr.getStringDimensions(str, fontSize); } void endFrame(void);
inline WindowCore& getWindow(void) { return *m_window; }
inline bool isInitialized(void) { return m_initialized; }
void pushClippingRect(const ostd::Rectangle& rect, bool additive = false); void pushClippingRect(const ostd::Rectangle& rect, bool additive = false);
void popClippingRect(void); void popClippingRect(void);
void setFont(const ostd::String& fontFilePath); int32_t loadDefaultFont(int32_t fontSize = 0);
void setDefaultFont(void); void closeFont(void);
void setFontSize(int32_t fontSize); 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);
ostd::IPoint getStringDimensions(const ostd::String& message, int32_t fontSize = 0);
void drawImage(ogfx::Image& image, const ostd::Vec2& position, const ostd::Rectangle& rect = { 0, 0, 0, 0 }); inline uint32_t getDrawCallCount(void) { return m_drawCallCount; }
void drawAnimation(const Animation& anim, const ostd::Vec2& position); inline bool hasOpenFont(void) { return m_fontOpen; }
inline TTF_Font* getSDLFont(void) { return m_font; }
inline bool isValid(void) { return m_initialized && m_fontOpen && (m_font != nullptr || m_fontFromMemory); }
inline int32_t geterrorState(void) { return m_errorState; }
inline int32_t getFontSize(void) { return m_fontSize; }
inline WindowCore& getWindow(void) { return *m_window; }
inline bool isInitialized(void) { return m_initialized; }
void drawImage(const ogfx::Image& image, const ostd::Vec2& position, const ostd::Vec2& size = { 0, 0 }, const ostd::Rectangle& srcRect = { 0, 0, 0, 0 });
void drawAnimation(const Animation& anim, const ostd::Vec2& position, const ostd::Vec2& size = { 0, 0 });
void drawString(const ostd::String& str, const ostd::Vec2& position, const ostd::Color& color, int32_t fontSize = 0); void drawString(const ostd::String& str, const ostd::Vec2& position, const ostd::Color& color, int32_t fontSize = 0);
void drawCenteredString(const ostd::String& str, const ostd::Vec2& center, const ostd::Color& color, int32_t fontSize = 0); void drawCenteredString(const ostd::String& str, const ostd::Vec2& center, const ostd::Color& color, int32_t fontSize = 0);
void drawLine(const ostd::FLine& line, const ostd::Color& color, int32_t thickness = 1); void drawLine(const ostd::FLine& line, const ostd::Color& color, int32_t thickness = 1, bool rounded = true);
void drawRect(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness = 1); void drawRect(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness = 1);
void drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, int32_t radius, int32_t thickness = 1); void drawRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, float radius, int32_t thickness = 1);
void drawCircle(const ostd::Vec2& center, int32_t radius, const ostd::Color& color, int32_t thickness = 1); void drawCircle(const ostd::Vec2& center, float radius, const ostd::Color& color, int32_t thickness = 1);
void drawCircle(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness = 1);
void drawEllipse(const ostd::Rectangle& rect, const ostd::Color& color, int32_t thickness = 1);
void fillRect(const ostd::Rectangle& rect, const ostd::Color& color); void fillRect(const ostd::Rectangle& rect, const ostd::Color& color);
void fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, int32_t radius); void fillRoundRect(const ostd::Rectangle& rect, const ostd::Color& color, float radius);
void fillCircle(const ostd::Vec2& center, int32_t radius, const ostd::Color& color); void fillCircle(const ostd::Vec2& center, float radius, const ostd::Color& color);
void fillCircle(const ostd::Rectangle& rect, const ostd::Color& color);
void fillEllipse(const ostd::Rectangle& rect, const ostd::Color& color);
void outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1, bool outlineInward = true); void outlinedRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1);
void outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t radius, int32_t outlineThickness = 1, bool outlineInward = true); void outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, float radius, int32_t outlineThickness = 1);
void outlinedCircle(const ostd::Vec2& center, int32_t radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1, bool outlineInward = true); void outlinedCircle(const ostd::Vec2& center, float radius, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1);
void outlinedCircle(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1);
void outlinedEllipse(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, int32_t outlineThickness = 1);
private: private:
TTFRenderer m_ttfr; void init_arrays(void);
void generate_half_circle(const ostd::Vec2& center, const ostd::Vec2& dir, float radius, int segments, const ostd::Color& color);
void generate_quarter_circle(const ostd::Vec2& center, float radius, float thickness, float startAngle, const ostd::Color& color, int segments);
void generate_circle_stroke(const ostd::Vec2& center, float radius, float thickness, const ostd::Color& color, int segments);
void generate_ellipse_stroke(const ostd::Vec2& center, float radiusX, float radiusY, float thickness, float startAngle, float endAngle, const ostd::Color& color, int segments);
void generate_filled_ellipse_stroke(const ostd::Vec2& center, float radiusX, float radiusY, float startAngle, const ostd::Color& color, int segments);
void generate_filled_ellipse(const ostd::Vec2& center, float radiusX, float radiusY, const ostd::Color& color, int segments);
void push_polygon(const ostd::Vec2* verts, const ostd::Vec2* texCoords, uint32_t vertCount, const uint32_t* inds, uint32_t indexCount, const ostd::Color& color, SDL_Texture* texture);
void print_ttf_error(const ostd::String& funcName);
inline int32_t set_error_state(int32_t err) { m_errorState = err; return m_errorState; }
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);
public:
inline static constexpr int32_t MaxVertices { 8192 };
inline static constexpr int32_t MaxIndices { (int32_t)(MaxVertices * 1.5f) };
private:
WindowCore* m_window { nullptr }; WindowCore* m_window { nullptr };
ostd::ConsoleOutputHandler m_out;
bool m_initialized { false }; bool m_initialized { false };
std::vector<ostd::Rectangle> m_clipStack; std::vector<ostd::Rectangle> m_clipStack;
std::array<SDL_Vertex, MaxVertices> m_vertices;
std::array<int, MaxIndices> m_indices;
int32_t m_vertexCount { 0 };
int32_t m_indexCount { 0 };
SDL_Texture* m_texture { nullptr };
uint32_t m_drawCallCount { 0 };
bool m_fontOpen { false };
TTF_Font* m_font { nullptr };
int32_t m_errorState { tErrors::NoError };
int32_t m_fontSize { DefaultFontSize };
bool m_fontFromMemory { false };
inline static constexpr int32_t DefaultFontSize { 16 };
}; };
} }

View file

@ -1,280 +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 "FontUtils.hpp"
#include "../resources/UbuntuMonoRegularTTF.hpp"
namespace ogfx
{
TTFRenderer::SignalHandler::SignalHandler(TTFRenderer& parent) : m_parent(parent)
{
enableSignals();
connectSignal(ostd::BuiltinSignals::BeforeSDLShutdown);
setTypeName("ostd::GraphicsWindowOutputHandler::SignalHandler");
validate();
}
void TTFRenderer::SignalHandler::handleSignal(ostd::Signal& signal)
{
if (signal.ID == ostd::BuiltinSignals::BeforeSDLShutdown)
{
m_parent.closeFont();
}
}
TTFRenderer::~TTFRenderer(void)
{
closeFont();
}
void TTFRenderer::renderText(const ostd::String& message, int32_t x, int32_t y, const ostd::Color& color, int32_t fontSize)
{
if (!TTFRenderer::m_initialized)
{
set_error_state(tErrors::Uninitialized);
return;
}
if (!m_fontOpen)
{
set_error_state(tErrors::NoFont);
return;
}
if (m_renderer == nullptr)
{
set_error_state(tErrors::NullRenderer);
return;
}
if (m_font == nullptr)
{
set_error_state(tErrors::NullFont);
return;
}
setFontSize(fontSize);
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);
print_ttf_error("TTF_RenderText_Blended");
return;
}
SDL_Texture* texture = SDL_CreateTextureFromSurface(m_renderer, surf);
if (texture == nullptr)
{
set_error_state(tErrors::TTFCreateTextureFromSurfaceFail);
print_ttf_error("SDL_CreateTextureFromSurface");
return;
}
SDL_DestroySurface(surf);
float w = 0, h = 0;
SDL_GetTextureSize(texture, &w, &h);
SDL_FRect dst;
dst.x = x;
dst.y = y;
dst.w = w;
dst.h = h;
SDL_RenderTexture(m_renderer, texture, NULL, &dst);
SDL_DestroyTexture(texture);
}
void TTFRenderer::renderCenteredText(const ostd::String& message, int32_t center_x, int32_t center_y, const ostd::Color& color, int32_t fontSize)
{
if (!TTFRenderer::m_initialized)
{
set_error_state(tErrors::Uninitialized);
return;
}
if (!m_fontOpen)
{
set_error_state(tErrors::NoFont);
return;
}
if (m_renderer == nullptr)
{
set_error_state(tErrors::NullRenderer);
return;
}
if (m_font == nullptr)
{
set_error_state(tErrors::NullFont);
return;
}
setFontSize(fontSize);
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);
print_ttf_error("TTF_RenderText_Blended");
return;
}
SDL_Texture* texture = SDL_CreateTextureFromSurface(m_renderer, surf);
if (texture == nullptr)
{
set_error_state(tErrors::TTFCreateTextureFromSurfaceFail);
print_ttf_error("SDL_CreateTextureFromSurface");
return;
}
SDL_DestroySurface(surf);
float w = 0, h = 0;
SDL_GetTextureSize(texture, &w, &h);
SDL_FRect dst;
dst.x = center_x - (w / 2);
dst.y = center_y - (h / 2);
dst.w = w;
dst.h = h;
SDL_RenderTexture(m_renderer, texture, NULL, &dst);
SDL_DestroyTexture(texture);
}
ostd::IPoint TTFRenderer::getStringDimensions(const ostd::String& message, int32_t fontSize)
{
if (!TTFRenderer::m_initialized)
{
set_error_state(tErrors::Uninitialized);
return { 0, 0 };
}
if (!m_fontOpen)
{
set_error_state(tErrors::NoFont);
return { 0, 0 };
}
if (m_renderer == nullptr)
{
set_error_state(tErrors::NullRenderer);
return { 0, 0 };
}
if (m_font == nullptr)
{
set_error_state(tErrors::NullFont);
return { 0, 0 };
}
setFontSize(fontSize);
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);
print_ttf_error("TTF_RenderText_Blended");
return { 0, 0 };
}
SDL_Texture* texture = SDL_CreateTextureFromSurface(m_renderer, surf);
if (texture == nullptr)
{
set_error_state(tErrors::TTFCreateTextureFromSurfaceFail);
print_ttf_error("SDL_CreateTextureFromSurface");
return { 0, 0 };
}
SDL_DestroySurface(surf);
float w = 0, h = 0;
SDL_GetTextureSize(texture, &w, &h);
SDL_DestroyTexture(texture);
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);
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;
if (m_font != nullptr)
TTF_CloseFont(m_font);
m_font = nullptr;
m_fontOpen = false;
m_fontSize = DefaultFontSize;
m_fontFromMemory = false;
set_error_state(tErrors::NoError);
}
int32_t TTFRenderer::openFont(const ostd::String& fontPath, int32_t fontSize)
{
if (!TTFRenderer::m_initialized) return set_error_state(tErrors::Uninitialized);
if (m_fontOpen) closeFont();
if (fontSize <= 0)
fontSize = m_fontSize;
else
m_fontSize = fontSize;
m_font = TTF_OpenFont(fontPath.c_str(), fontSize);
if (m_font == nullptr)
{
print_ttf_error("TTF_OpenFont");
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);
}
int32_t TTFRenderer::setFontSize(int32_t fontSize)
{
if (!TTFRenderer::m_initialized)
return set_error_state(tErrors::Uninitialized);
if (!m_fontOpen)
return set_error_state(tErrors::NoFont);
if (m_font == nullptr)
return set_error_state(tErrors::NullFont);
if (fontSize == m_fontSize || fontSize <= 0) return set_error_state(tErrors::NoError);
TTF_SetFontSize(m_font, fontSize);
return set_error_state(tErrors::NoError);
}
void TTFRenderer::print_ttf_error(const ostd::String& funcName)
{
m_out.fg(ostd::ConsoleColors::Red).p(funcName).p("(...) failed: ").p(ostd::String(SDL_GetError())).reset().nl();
}
}

View file

@ -1,91 +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 <ogfx/utils/SDLInclude.hpp>
#include <ostd/utils/Signals.hpp>
#include <ostd/io/IOHandlers.hpp>
namespace ogfx
{
class TTFRenderer
{
private: class SignalHandler : public ostd::BaseObject
{
public:
SignalHandler(TTFRenderer& parent);
void handleSignal(ostd::Signal& signal) override;
private:
TTFRenderer& m_parent;
};
public: struct tErrors
{
inline static constexpr int32_t NoError = 0;
inline static constexpr int32_t FailedToLoad = 1;
inline static constexpr int32_t FailedToOpenFontFile = 2;
inline static constexpr int32_t Uninitialized = 3;
inline static constexpr int32_t NullRenderer = 4;
inline static constexpr int32_t InvalidState = 5;
inline static constexpr int32_t TTFRenderTextBlendedFail = 6;
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);
ostd::IPoint getStringDimensions(const ostd::String& message, int32_t fontSize = 0);
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_fontFromMemory) && m_renderer != nullptr; }
inline int32_t geterrorState(void) { return m_errorState; }
inline int32_t getFontSize(void) { return m_fontSize; }
private:
void print_ttf_error(const ostd::String& funcName);
inline int32_t set_error_state(int32_t err) { m_errorState = err; return m_errorState; }
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 };
};
}

View file

@ -37,7 +37,7 @@ namespace ogfx
Image& loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx); Image& loadFromFile(const ostd::String& filePath, BasicRenderer2D& gfx);
inline ostd::Vec2 getSize(void) const { return { m_width, m_height }; } inline ostd::Vec2 getSize(void) const { return { m_width, m_height }; }
inline bool isLoaded(void) const { return m_loaded; } inline bool isLoaded(void) const { return m_loaded; }
inline SDL_Texture* getSDLTexture(void) { return m_sdl_texture; } inline SDL_Texture* getSDLTexture(void) const { return m_sdl_texture; }
private: private:
SDL_Texture* m_sdl_texture { nullptr }; SDL_Texture* m_sdl_texture { nullptr };

View file

@ -25,7 +25,6 @@
#include <ostd/utils/Signals.hpp> #include <ostd/utils/Signals.hpp>
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <ogfx/vendor/sdl3_gfx/SDL3_gfxPrimitives.h>
#include <SDL3_ttf/SDL_ttf.h> #include <SDL3_ttf/SDL_ttf.h>
#include <SDL3_image/SDL_image.h> #include <SDL3_image/SDL_image.h>
#include <SDL3/SDL_surface.h> #include <SDL3/SDL_surface.h>

View file

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

View file

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

File diff suppressed because it is too large Load diff

View file

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

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,161 +0,0 @@
/*
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 */

File diff suppressed because it is too large Load diff

View file

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

View file

@ -5,47 +5,47 @@
namespace ostd namespace ostd
{ {
Color::Color(void) Color::Color(void) : r(*this), g(*this), b(*this), a(*this)
{ {
set(); set();
setTypeName("ox::Color"); setTypeName("ox::Color");
BaseObject::setValid(true); BaseObject::setValid(true);
} }
Color::Color(uint8_t rgb_single_value, uint8_t alpha) Color::Color(uint8_t rgb_single_value, uint8_t alpha) : r(*this), g(*this), b(*this), a(*this)
{ {
set(rgb_single_value, alpha); set(rgb_single_value, alpha);
setTypeName("ox::Color"); setTypeName("ox::Color");
BaseObject::setValid(true); BaseObject::setValid(true);
} }
Color::Color(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t alpha) Color::Color(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t alpha) : r(*this), g(*this), b(*this), a(*this)
{ {
set(_r, _g, _b, alpha); set(_r, _g, _b, alpha);
setTypeName("ox::Color"); setTypeName("ox::Color");
BaseObject::setValid(true); BaseObject::setValid(true);
} }
Color::Color(const String& color_string) Color::Color(const String& color_string) : r(*this), g(*this), b(*this), a(*this)
{ {
set(color_string); set(color_string);
setTypeName("ox::Color"); setTypeName("ox::Color");
BaseObject::setValid(true); BaseObject::setValid(true);
} }
Color::Color(const FloatCol& normalized_color) Color::Color(const FloatCol& normalized_color) : r(*this), g(*this), b(*this), a(*this)
{ {
set(normalized_color); set(normalized_color);
setTypeName("ox::Color"); setTypeName("ox::Color");
BaseObject::setValid(true); BaseObject::setValid(true);
} }
Color::Color(const Color& copy) : BaseObject(copy) Color::Color(const Color& copy) : BaseObject(copy), r(*this), g(*this), b(*this), a(*this)
{ {
r = copy.r; r = static_cast<uint8_t>(copy.r);
g = copy.g; g = static_cast<uint8_t>(copy.g);
b = copy.b; b = static_cast<uint8_t>(copy.b);
a = copy.a; a = static_cast<uint8_t>(copy.a);
} }
bool Color::operator==(const Color& col2) bool Color::operator==(const Color& col2)
@ -61,10 +61,10 @@ namespace ostd
Color& Color::operator=(const Color& copy) Color& Color::operator=(const Color& copy)
{ {
BaseObject::operator=(copy); BaseObject::operator=(copy);
r = copy.r; r = static_cast<uint8_t>(copy.r);
g = copy.g; g = static_cast<uint8_t>(copy.g);
b = copy.b; b = static_cast<uint8_t>(copy.b);
a = copy.a; a = static_cast<uint8_t>(copy.a);
return *this; return *this;
} }
@ -99,7 +99,9 @@ namespace ostd
{ {
String se(color_string); String se(color_string);
se.trim(); se.trim();
r = g = b = 0; r = 0;
g = 0;
b = 0;
a = 255; a = 255;
if (se.startsWith("#")) if (se.startsWith("#"))
{ {
@ -204,7 +206,17 @@ namespace ostd
Color::FloatCol Color::getNormalizedColor(void) const Color::FloatCol Color::getNormalizedColor(void) const
{ {
return { r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f }; if (m_dirty)
{
m_cachedFloat = {
r.value * (1.0f / 255.0f),
g.value * (1.0f / 255.0f),
b.value * (1.0f / 255.0f),
a.value * (1.0f / 255.0f)
};
m_dirty = false;
}
return m_cachedFloat;
} }
String Color::toString(void) const String Color::toString(void) const

View file

@ -39,6 +39,20 @@ namespace ostd
FloatCol(void) : r(0.0f), g(0.0f), b(0.0f), a(1.0f) { } FloatCol(void) : r(0.0f), g(0.0f), b(0.0f), a(1.0f) { }
FloatCol(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) { } FloatCol(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) { }
}; };
public: struct Channel
{
uint8_t value;
Color& parent;
inline Channel(Color& _parent) : parent(_parent) { value = 0; }
inline operator uint8_t() const { return value; }
inline Channel& operator=(uint8_t v)
{
value = v;
parent.m_dirty = true;
return *this;
}
};
public: enum class eColorFormat { RGBA = 0, ARGB }; public: enum class eColorFormat { RGBA = 0, ARGB };
@ -74,10 +88,14 @@ namespace ostd
static void HSVtoRGB(float h, float s, float v, float& r, float& g, float& b); static void HSVtoRGB(float h, float s, float v, float& r, float& g, float& b);
public: public:
uint8_t r; Channel r;
uint8_t g; Channel g;
uint8_t b; Channel b;
uint8_t a; Channel a;
private:
mutable bool m_dirty { true };
mutable FloatCol m_cachedFloat { 0, 0, 0, 0 };
public: public:
}; };

View file

@ -28,7 +28,6 @@
namespace ogfx namespace ogfx
{ {
class WindowCore; class WindowCore;
class BasicRenderer2D;
}; };
namespace ostd namespace ostd

View file

@ -318,10 +318,10 @@ namespace ostd
try try
{ {
json arr = json::array(); json arr = json::array();
arr.push_back(value.r); arr.push_back(static_cast<uint8_t>(value.r));
arr.push_back(value.g); arr.push_back(static_cast<uint8_t>(value.g));
arr.push_back(value.b); arr.push_back(static_cast<uint8_t>(value.b));
if (value.a != 255) arr.push_back(value.a); if (value.a != 255) arr.push_back(static_cast<uint8_t>(value.a));
root[p] = arr; root[p] = arr;
return true; return true;
} catch (...) { return false; } } catch (...) { return false; }

View file

@ -45,40 +45,6 @@
namespace ostd namespace ostd
{ {
template<class T>
class Point : public __i_stringeable
{
public:
T x;
T y;
public:
inline Point(void) : x(0), y(0) {}
inline Point(T xx, T yy) : x(xx), y(yy) {}
inline bool operator==(const Point<T>& op2 ) const { return (x == op2.x && y == op2.y); }
inline bool operator!=(const Point<T>& op2 ) const { return (x != op2.x || y != op2.y); }
template <class T2> inline Point(Point<T2> copy)
{
x = (T2)(copy.x);
y = (T2)(copy.y);
}
inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(" }"); }
};
typedef Point<float> FPoint;
typedef Point<double> DPoint;
typedef Point<uint32_t> UIPoint;
typedef Point<uint64_t> UI64Point;
typedef Point<uint16_t> UI16Point;
typedef Point<uint8_t> UI8Point;
typedef Point<int32_t> IPoint;
typedef Point<int64_t> I64Point;
typedef Point<int16_t> I16Point;
typedef Point<int8_t> I8Point;
struct Vec2 : public __i_stringeable struct Vec2 : public __i_stringeable
{ {
//======================== Data ======================== //======================== Data ========================
@ -146,6 +112,7 @@ namespace ostd
//===================== Operators ====================== //===================== Operators ======================
inline bool operator==(const Vec2& op2 ) const { return (x == op2.x && y == op2.y); } inline bool operator==(const Vec2& op2 ) const { return (x == op2.x && y == op2.y); }
inline bool operator!=(const Vec2& op2 ) const { return (x != op2.x || y != op2.y); } inline bool operator!=(const Vec2& op2 ) const { return (x != op2.x || y != op2.y); }
inline Vec2 operator-() const { return { -x, -y }; }
inline Vec2 operator+ (const Vec2& op2 ) const { return add(op2); } inline Vec2 operator+ (const Vec2& op2 ) const { return add(op2); }
inline Vec2 operator- (const Vec2& op2 ) const { return sub(op2); } inline Vec2 operator- (const Vec2& op2 ) const { return sub(op2); }
inline Vec2 operator+ (const float& op2) const { return add(op2, op2); } inline Vec2 operator+ (const float& op2) const { return add(op2, op2); }
@ -167,6 +134,62 @@ namespace ostd
}; };
template<class T>
class Point : public __i_stringeable
{
public:
T x;
T y;
public:
inline Point(void) : x(0), y(0) { }
inline Point(T xx, T yy) : x(xx), y(yy) {}
inline Point(const Vec2& vec) { x = vec.x; y = vec.y; }
inline Point<T>& set(const Point<T>& v2) { x = v2.x; y = v2.y; return *this; }
inline Point<T>& set(float xx, float yy) { x = xx; y = yy; return *this; }
//===================== Operators ======================
inline bool operator==(const Point<T>& op2 ) const { return (x == op2.x && y == op2.y); }
inline bool operator!=(const Point<T>& op2 ) const { return (x != op2.x || y != op2.y); }
inline operator Vec2() const { return { static_cast<float>(x), static_cast<float>(y) }; }
inline Point<T> operator+ (const Point<T>& op2 ) const { return { x + op2.x, y + op2.y }; }
inline Point<T> operator- (const Point<T>& op2 ) const { return { x - op2.x, y - op2.y }; }
inline Point<T> operator+ (const T& op2) const { return { x + op2, y + op2 }; }
inline Point<T> operator- (const T& op2) const { return { x + op2, y + op2 }; }
inline Point<T> operator* (const T& op2) const { return { x * op2, y * op2 }; }
inline Point<T> operator/ (const T& op2) const { return { x / op2, y / op2 }; }
inline Point<T>& operator= (const Point<T>& val ) { return set(val); }
inline Point<T>& operator= (const T& val) { return set(val, val); }
inline Point<T>& operator+=(const Point<T>& op2 ) { x += op2.x; y += op2.y; return *this; }
inline Point<T>& operator-=(const Point<T>& op2 ) { x -= op2.x; y -= op2.y; return *this; }
inline Point<T>& operator+=(const T& op2) { x += op2; y += op2; return *this;; }
inline Point<T>& operator-=(const T& op2) { x -= op2; y -= op2; return *this; }
inline Point<T>& operator*=(const T& op2) { return x *= op2; y *= op2; return *this; }
inline Point<T>& operator/=(const T& op2) { return x /= op2; y /= op2; return *this; }
//======================================================
template <class T2> inline Point(Point<T2> copy)
{
x = (T2)(copy.x);
y = (T2)(copy.y);
}
inline Vec2 asVec2(void) const { return { static_cast<float>(x), static_cast<float>(y) }; }
inline String toString(void) const override { return String("{ ").add(x).add(", ").add(y).add(" }"); }
};
typedef Point<float> FPoint;
typedef Point<double> DPoint;
typedef Point<uint32_t> UIPoint;
typedef Point<uint64_t> UI64Point;
typedef Point<uint16_t> UI16Point;
typedef Point<uint8_t> UI8Point;
typedef Point<int32_t> IPoint;
typedef Point<int64_t> I64Point;
typedef Point<int16_t> I16Point;
typedef Point<int8_t> I8Point;
struct Vec3 : public __i_stringeable struct Vec3 : public __i_stringeable
{ {
inline Vec3(float xx = 0, float yy = 0, float zz = 0) inline Vec3(float xx = 0, float yy = 0, float zz = 0)

View file

@ -26,20 +26,11 @@ ostd::ConsoleOutputHandler out;
class Window : public ogfx::GraphicsWindow class Window : public ogfx::GraphicsWindow
{ {
public: public:
inline Window(void) : m_sigHandler(m_textInput, *this) { } inline Window(void) { }
inline void onInitialize(void) override inline void onInitialize(void) override
{ {
connectSignal(ogfx::gui::RawTextInput::actionEventSignalID); connectSignal(ogfx::gui::RawTextInput::actionEventSignalID);
m_gfx.init(*this); 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::Signal& signal) override inline void handleSignal(ostd::Signal& signal) override
@ -50,44 +41,30 @@ class Window : public ogfx::GraphicsWindow
if (evtData.keyCode == ogfx::KeyCode::Escape) if (evtData.keyCode == ogfx::KeyCode::Escape)
close(); 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 inline void onRender(void) override
{ {
m_textInput.render(m_gfx); auto l_rndPoint = [&](void) -> ostd::FPoint {
using rnd = ostd::Random;
return rnd::getVec2({ 0, (float)getWindowWidth() }, { 0, (float)getWindowHeight() });
};
for (int32_t i = 0; i < 10000; i++)
m_gfx.drawLine({ l_rndPoint(), l_rndPoint() }, ostd::Colors::Crimson, 10);
m_gfx.endFrame();
} }
inline void onFixedUpdate(double frameTime_s) override inline void onFixedUpdate(double frameTime_s) override
{ {
m_textInput.fixedUpdate(); std::cout << (int)getFPS() << "\n";
} }
inline void onUpdate(void) override inline void onUpdate(void) override
{ {
m_textInput.update();
} }
private: private:
ogfx::gui::RawTextInput m_textInput;
ogfx::BasicRenderer2D m_gfx; ogfx::BasicRenderer2D m_gfx;
ogfx::gui::RawTextInputEventListener m_sigHandler;
ogfx::gui::RawTextInputNumberCharacterFilter m_numCharFilter;
}; };
int main(int argc, char** argv) int main(int argc, char** argv)

View file

@ -30,6 +30,20 @@ class Window : public ogfx::gui::Window
inline Window(void) { } inline Window(void) { }
inline void onInitialize(void) override inline void onInitialize(void) override
{ {
test.loadFromFile("./test.png", m_gfx);
ogfx::Animation::AnimationData ad;
ad.backwards = false;
ad.columns = 9;
ad.rows = 4;
ad.frame_width = 256;
ad.frame_height = 256;
ad.length = 36;
ad.random = false;
ad.still = false;
ad.speed = 0;
m_anim.create(ad);
m_anim.setSpriteSheet(test);
m_panel1.setSize(300, 140); m_panel1.setSize(300, 140);
m_panel1.setPosition(350, 50); m_panel1.setPosition(350, 50);
m_panel1.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void { m_panel1.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void {
@ -132,7 +146,16 @@ class Window : public ogfx::gui::Window
void onRedraw(ogfx::BasicRenderer2D& gfx) override void onRedraw(ogfx::BasicRenderer2D& gfx) override
{ {
// wout().fg(ostd::Color { 255, 0, 0 }).p("Hello ").fg(ostd::Color { 0, 0, 255 }).p("World"); // auto l_rndPoint = [&](void) -> ostd::FPoint {
// using rnd = ostd::Random;
// return rnd::getVec2({ 0, (float)getWindowWidth() / 2 }, { 0, (float)getWindowHeight() / 2 });
// };
// for (int32_t i = 0; i < 1000; i++)
// gfx.drawLine({ l_rndPoint(), l_rndPoint() }, ostd::Colors::Crimson, 10);
// gfx.drawLine({ { 10, 10 }, { 200, 100 } }, ostd::Colors::Crimson, 3);
// gfx.drawRect({ 50, 50, 200, 120 }, ostd::Colors::Aquamarine, 1);
// std::cout << (int)(gfx.getDrawCallCount() + 1) << "\n";
} }
private: private:
@ -144,6 +167,8 @@ class Window : public ogfx::gui::Window
ogfx::gui::widgets::CheckBox m_check1 { *this }; ogfx::gui::widgets::CheckBox m_check1 { *this };
ostd::Stylesheet m_theme; ostd::Stylesheet m_theme;
ostd::Vec2 pos { 0, 0 }; ostd::Vec2 pos { 0, 0 };
ogfx::Image test;
ogfx::Animation m_anim;
}; };
int main(int argc, char** argv) int main(int argc, char** argv)