diff --git a/.clangd b/.clangd
index 32169b9..122ab09 100644
--- a/.clangd
+++ b/.clangd
@@ -1,3 +1,2 @@
CompileFlags:
- CompilationDatabase: bin
- Add: ["--target=x86_64-w64-mingw32"]
\ No newline at end of file
+ CompilationDatabase: bin
\ No newline at end of file
diff --git a/extra/testTheme.txt b/extra/testTheme.txt
index 57dc24b..7fef94b 100644
--- a/extra/testTheme.txt
+++ b/extra/testTheme.txt
@@ -55,6 +55,7 @@ $accentColor = Color(rgb(255, 0, 0))
borderRadius = 8
borderWidth = 4
showBorder = true
+ showBackground = true
padding = Rect(15, 15, 15, 15)
showTitle = true
titleColor = Color(#000000FF)
diff --git a/other/TODO.txt b/other/TODO.txt
index 4fbae84..5bdf893 100644
--- a/other/TODO.txt
+++ b/other/TODO.txt
@@ -10,14 +10,16 @@
***Implement color constants in stylesheet
***Implement margin for widgets
***Implement mouse scroll callback
+***Fix: Text rendering bug in labels
+***Implement callback for state changes in checkbox
+***FIX: WindowOutputHandler text rendering
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 global scale (probably query desktop scale and adjust accordingly)
-Fix: Text rendering bug in labels
Implement show/hide functionality for widgets
Implement wrappers in Renderer2D to take a center and size for rects
+Implement Panel title
+Create reliable default stylesheet
@@ -38,6 +40,7 @@ Implement following widgets:
ListBox
ComboBox
TreeView
+ Progressbar
Save/Open File Dialogs (and folder dialogs)
Tab Panel
Layouts
diff --git a/other/build.nr b/other/build.nr
index 8c6e25c..f11718f 100644
--- a/other/build.nr
+++ b/other/build.nr
@@ -1 +1 @@
-2061
+2062
diff --git a/src/ogfx/gui/WidgetManager.cpp b/src/ogfx/gui/WidgetManager.cpp
index c2efb3d..bc7747c 100644
--- a/src/ogfx/gui/WidgetManager.cpp
+++ b/src/ogfx/gui/WidgetManager.cpp
@@ -1,21 +1,21 @@
/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
- This file is part of OmniaFramework.
+ 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 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.
+ 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 .
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
*/
#include "WidgetManager.hpp"
diff --git a/src/ogfx/gui/Window.cpp b/src/ogfx/gui/Window.cpp
index f501e90..5f161ac 100644
--- a/src/ogfx/gui/Window.cpp
+++ b/src/ogfx/gui/Window.cpp
@@ -1,21 +1,21 @@
/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
- This file is part of OmniaFramework.
+ 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 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.
+ 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 .
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
*/
#include "Window.hpp"
@@ -112,7 +112,7 @@ namespace ogfx
m_cursor_W_Resize = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_W_RESIZE);
m_wout.attachWindow(*this);
- m_wout.setFontSize(22);
+ // m_wout.setFontSize(22);
m_wout.setConsoleMaxCharacters({ 1000, 1000 });
m_wout.setConsolePosition({ 5, 5 });
m_wout.setWrapMode(ogfx::GraphicsWindowOutputHandler::eWrapMode::NewLine);
diff --git a/src/ogfx/gui/Window.hpp b/src/ogfx/gui/Window.hpp
index 8b75671..ad32664 100644
--- a/src/ogfx/gui/Window.hpp
+++ b/src/ogfx/gui/Window.hpp
@@ -1,21 +1,21 @@
/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
- This file is part of OmniaFramework.
+ 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 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.
+ 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 .
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
*/
#pragma once
@@ -213,7 +213,7 @@ namespace ogfx
inline virtual void onClose(void) { }
inline virtual void onSDLEvent(SDL_Event& event) { }
inline virtual void onRedraw(BasicRenderer2D& gfx) { }
- inline virtual void onUpdate(void) { }
+ inline virtual void onUpdate(double delta) { }
inline virtual void onSignal(ostd::Signal& signal) { }
protected:
diff --git a/src/ogfx/gui/WindowOutputHandler.cpp b/src/ogfx/gui/WindowOutputHandler.cpp
index 694772e..05baf7a 100644
--- a/src/ogfx/gui/WindowOutputHandler.cpp
+++ b/src/ogfx/gui/WindowOutputHandler.cpp
@@ -1,21 +1,21 @@
/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
- This file is part of OmniaFramework.
+ 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 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.
+ 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 .
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
*/
#include "WindowOutputHandler.hpp"
@@ -35,14 +35,13 @@ namespace ogfx
{
if (m_window != nullptr) return;
m_window = &window;
- // m_renderer.init(window); //TODO: Fix
+ m_renderer.init(window);
}
void GraphicsWindowOutputHandler::setMonospaceFont(const String& filePath)
{
- //TODO: Fix
- // m_renderer.setFont(filePath);
- // m_renderer.setFontSize(m_fontSize);
+ m_renderer.openFont(filePath);
+ m_renderer.setFontSize(m_fontSize);
__update_char_size();
}
@@ -55,8 +54,8 @@ namespace ogfx
}
bool GraphicsWindowOutputHandler::isReady(void)
- {//TODO: Fix
- return m_window != nullptr && /* m_renderer.getTTFRenderer().hasOpenFont() &&*/ m_fontSize > 0;
+ {
+ return m_window != nullptr && m_renderer.hasOpenFont() && m_fontSize > 0;
}
void GraphicsWindowOutputHandler::resetCursorPosition(void)
@@ -120,8 +119,7 @@ namespace ogfx
void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize)
{
m_fontSize = fontSize;
- //TODO: Fix
- // m_renderer.setFontSize(m_fontSize);
+ m_renderer.setFontSize(m_fontSize);
__update_char_size();
}
diff --git a/src/ogfx/gui/widgets/CheckBox.cpp b/src/ogfx/gui/widgets/CheckBox.cpp
index 5c52c3b..433f045 100644
--- a/src/ogfx/gui/widgets/CheckBox.cpp
+++ b/src/ogfx/gui/widgets/CheckBox.cpp
@@ -46,10 +46,10 @@ namespace ogfx
setTextColor(getThemeValue(theme, "checkbox.textColor", ostd::Colors::Black));
setBackGroundColor(getThemeValue(theme, "checkbox.backgroundColor", ostd::Colors::Transparent));
setFontSize(getThemeValue(theme, "checkbox.fontSize", 28));
- m_borderRadius = getThemeValue(theme, "checkbox.borderRadius", 10);
- m_borderWidth = getThemeValue(theme, "checkbox.borderWidth", 2);
- m_showBorder = getThemeValue(theme, "checkbox.showBorder", false);
- m_borderColor = getThemeValue(theme, "checkbox.borderColor", ostd::Colors::White);
+ setBorderRadius(getThemeValue(theme, "checkbox.borderRadius", 10));
+ setBorderWidth(getThemeValue(theme, "checkbox.borderWidth", 2));
+ enableBorder(getThemeValue(theme, "checkbox.showBorder", false));
+ setBorderColor(getThemeValue(theme, "checkbox.borderColor", ostd::Colors::White));
enableBackground(getThemeValue(theme, "checkbox.showBackground", false));
setPadding(getThemeValue(theme, "checkbox.padding", { 5, 5, 5, 5 }));
setMargin(getThemeValue(theme, "checkbox.margin", { 0, 0, 0, 0 }));
@@ -61,10 +61,6 @@ namespace ogfx
{
if (m_textChanged)
__update_size(gfx);
- if (m_showBackground)
- gfx.fillRoundRect({ getGlobalPosition(), getSize() }, m_backgroundColor, m_borderRadius);
- if (m_showBorder)
- gfx.drawRoundRect({ getGlobalPosition(), getSize() }, m_borderColor, m_borderRadius, m_borderWidth);
gfx.drawRoundRect({ getGlobalContentPosition(), m_checkSize }, getCheckBorderColor(), m_checkBorderRadius, m_checkBorderWidth);
if (isChecked())
gfx.fillRoundRect({ getGlobalContentPosition() + 5, m_checkSize - 10 }, getCheckBoxColor(), m_checkBorderRadius / 2.0f);
@@ -75,8 +71,7 @@ namespace ogfx
{
if (!isMouseInside())
return;
- m_checked = !m_checked;
- setThemeQualifier("active", m_checked);
+ setChecked(!isChecked());
}
void CheckBox::setText(const ostd::String& text)
@@ -85,6 +80,14 @@ namespace ogfx
m_textChanged = true;
}
+ void CheckBox::setChecked(bool checked)
+ {
+ m_checked = !m_checked;
+ setThemeQualifier("active", m_checked);
+ if (callback_onStateChanged)
+ callback_onStateChanged(*this, m_checked);
+ }
+
void CheckBox::__update_size(ogfx::BasicRenderer2D& gfx)
{
auto size = gfx.getStringDimensions(getText(), getFontSize());
diff --git a/src/ogfx/gui/widgets/CheckBox.hpp b/src/ogfx/gui/widgets/CheckBox.hpp
index 7987c20..e3b8a5f 100644
--- a/src/ogfx/gui/widgets/CheckBox.hpp
+++ b/src/ogfx/gui/widgets/CheckBox.hpp
@@ -40,6 +40,7 @@ namespace ogfx
void onDraw(ogfx::BasicRenderer2D& gfx) override;
void onMouseReleased(const Event& event) override;
void setText(const ostd::String& text);
+ void setChecked(bool checked);
inline ostd::String getText(void) const { return m_text; }
inline ostd::Color getCheckBorderColor(void) const { return m_checkBorderColor; }
inline void setCheckBorderColor(const ostd::Color& color) { m_checkBorderColor = color; }
@@ -49,12 +50,8 @@ namespace ogfx
inline void setTextColor(const ostd::Color& color) { m_textColor = color; }
inline int32_t getFontSize(void) const { return m_fontSize; }
inline void setFontSize(int32_t fontSize) { m_fontSize = fontSize; }
- inline void setBackGroundColor(const ostd::Color& color) { m_backgroundColor = color; }
- inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; }
- inline void enableBackground(bool enable = true) { m_showBackground = enable; }
- inline bool isBackgoundEnabled(void) const { return m_showBackground; }
inline bool isChecked(void) const { return m_checked; }
- inline void setChecked(bool checked) { m_checked = checked; }
+ inline void setStateChangedCallback(std::function callback) { callback_onStateChanged = callback; }
private:
void __update_size(ogfx::BasicRenderer2D& gfx);
@@ -65,14 +62,14 @@ namespace ogfx
bool m_textChanged { false };
int32_t m_fontSize { 20 };
ostd::Color m_textColor { 255, 255, 255 };
- bool m_showBackground { false };
- ostd::Color m_backgroundColor { ostd::Colors::Transparent };
float m_spacing { 10 };
ostd::Vec2 m_checkSize { 0, 0 };
int32_t m_checkBorderRadius { 5 };
int32_t m_checkBorderWidth { 1 };
ostd::Color m_checkBorderColor { 255, 255, 255 };
ostd::Color m_checkBoxColor { 255, 255, 255 };
+
+ std::function callback_onStateChanged { nullptr };
};
}
}
diff --git a/src/ogfx/gui/widgets/Containers.cpp b/src/ogfx/gui/widgets/Containers.cpp
index f1aa202..3612303 100644
--- a/src/ogfx/gui/widgets/Containers.cpp
+++ b/src/ogfx/gui/widgets/Containers.cpp
@@ -41,10 +41,11 @@ namespace ogfx
void Panel::applyTheme(const ostd::Stylesheet& theme)
{
setBackGroundColor(getThemeValue(theme, "panel.backgroundColor", ostd::Colors::Gray));
- m_borderRadius = getThemeValue(theme, "panel.borderRadius", 8);
- m_borderWidth = getThemeValue(theme, "panel.borderWidth", 2);
- m_showBorder = getThemeValue(theme, "panel.showBorder", true);
- m_borderColor = getThemeValue(theme, "panel.borderColor", ostd::Colors::Black);
+ setBorderRadius(getThemeValue(theme, "panel.borderRadius", 8));
+ setBorderWidth(getThemeValue(theme, "panel.borderWidth", 2));
+ enableBorder(getThemeValue(theme, "panel.showBorder", true));
+ enableBackground(getThemeValue(theme, "panel.showBackground", true));
+ setBorderColor(getThemeValue(theme, "panel.borderColor", ostd::Colors::Black));
m_titleColor = getThemeValue(theme, "panel.titleColor", ostd::Colors::Black);
m_showTitle = getThemeValue(theme, "panel.showTitle", false);
m_titleHeight = getThemeValue(theme, "panel.titleHeight", 30);
@@ -54,10 +55,6 @@ namespace ogfx
void Panel::onDraw(ogfx::BasicRenderer2D& gfx)
{
- if (m_showBorder)
- gfx.outlinedRoundRect({ getGlobalPosition(), getSize() }, getBackgroundColor(), m_borderColor, m_borderRadius, m_borderWidth);
- else
- gfx.fillRoundRect({ getGlobalPosition(), getSize() }, getBackgroundColor(), m_borderRadius);
}
}
}
diff --git a/src/ogfx/gui/widgets/Containers.hpp b/src/ogfx/gui/widgets/Containers.hpp
index 3835710..c8951ca 100644
--- a/src/ogfx/gui/widgets/Containers.hpp
+++ b/src/ogfx/gui/widgets/Containers.hpp
@@ -39,7 +39,6 @@ namespace ogfx
inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; }
private:
- ostd::Color m_backgroundColor { 150, 150, 150 };
ostd::Color m_titleColor { 0, 0, 0 };
bool m_showTitle { false };
ostd::String m_titleType = "full";
diff --git a/src/ogfx/gui/widgets/Label.cpp b/src/ogfx/gui/widgets/Label.cpp
index 6aaf3a4..3426336 100644
--- a/src/ogfx/gui/widgets/Label.cpp
+++ b/src/ogfx/gui/widgets/Label.cpp
@@ -44,10 +44,10 @@ namespace ogfx
setColor(getThemeValue(theme, "label.textColor", ostd::Colors::White));
setBackGroundColor(getThemeValue(theme, "label.backgroundColor", ostd::Colors::Transparent));
setFontSize(getThemeValue(theme, "label.fontSize", 20));
- m_borderRadius = getThemeValue(theme, "label.borderRadius", 10);
- m_borderWidth = getThemeValue(theme, "label.borderWidth", 2);
- m_showBorder = getThemeValue(theme, "label.showBorder", false);
- m_borderColor = getThemeValue(theme, "label.borderColor", ostd::Colors::White);
+ setBorderRadius(getThemeValue(theme, "label.borderRadius", 10));
+ setBorderWidth(getThemeValue(theme, "label.borderWidth", 2));
+ enableBorder(getThemeValue(theme, "label.showBorder", false));
+ setBorderColor(getThemeValue(theme, "label.borderColor", ostd::Colors::White));
enableBackground(getThemeValue(theme, "label.showBackground", false));
setPadding(getThemeValue(theme, "label.padding", { 5, 5, 5, 5 }));
setMargin(getThemeValue(theme, "label.margin", { 0, 0, 0, 0 }));
@@ -57,10 +57,6 @@ namespace ogfx
{
if (m_textChanged)
__update_size(gfx);
- if (m_showBackground)
- gfx.fillRoundRect({ getGlobalPosition(), getSize() }, m_backgroundColor, m_borderRadius);
- if (m_showBorder)
- gfx.drawRoundRect({ getGlobalPosition(), getSize() }, m_borderColor, m_borderRadius, m_borderWidth);
gfx.drawString(getText(), getGlobalContentPosition(), getColor(), getFontSize());
}
diff --git a/src/ogfx/gui/widgets/Label.hpp b/src/ogfx/gui/widgets/Label.hpp
index f240b4c..529c6c5 100644
--- a/src/ogfx/gui/widgets/Label.hpp
+++ b/src/ogfx/gui/widgets/Label.hpp
@@ -43,10 +43,6 @@ namespace ogfx
inline void setColor(const ostd::Color& color) { m_color = color; }
inline int32_t getFontSize(void) const { return m_fontSize; }
inline void setFontSize(int32_t fontSize) { m_fontSize = fontSize; }
- inline void setBackGroundColor(const ostd::Color& color) { m_backgroundColor = color; }
- inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; }
- inline void enableBackground(bool enable = true) { m_showBackground = enable; }
- inline bool isBackgoundEnabled(void) const { return m_showBackground; }
private:
void __update_size(ogfx::BasicRenderer2D& gfx);
@@ -56,10 +52,6 @@ namespace ogfx
bool m_textChanged { false };
int32_t m_fontSize { 20 };
ostd::Color m_color { 255, 255, 255 };
- bool m_showBackground { false };
- ostd::Color m_backgroundColor { ostd::Colors::Transparent };
-
- private:
};
}
}
diff --git a/src/ogfx/gui/widgets/Widget.cpp b/src/ogfx/gui/widgets/Widget.cpp
index aa26311..a6471e4 100644
--- a/src/ogfx/gui/widgets/Widget.cpp
+++ b/src/ogfx/gui/widgets/Widget.cpp
@@ -28,7 +28,6 @@ namespace ogfx
{
namespace gui
{
-
ostd::BaseObject* Widget::s_dragAndDropData { nullptr };
bool Widget::s_hasDragAndDropData { false };
@@ -171,9 +170,18 @@ namespace ogfx
{
if (isDrawBoxEnabled())
gfx.fillRect({ getGlobalPosition(), getSize() }, getDrawBoxColor());
+ else
+ {
+ if (m_showBackground && m_showBorder)
+ gfx.outlinedRoundRect({ getGlobalPosition(), getSize() }, m_backgroundColor, m_borderColor, m_borderRadius, m_borderWidth);
+ else if (m_showBackground)
+ gfx.fillRoundRect({ getGlobalPosition(), getSize() }, m_backgroundColor, m_borderRadius);
+ }
onDraw(gfx);
if (hasChildren())
m_widgets.draw(gfx);
+ if (m_showBorder)
+ gfx.drawRoundRect({ getGlobalPosition(), getSize() }, m_borderColor, m_borderRadius, m_borderWidth);
}
void Widget::__update(void)
diff --git a/src/ogfx/gui/widgets/Widget.hpp b/src/ogfx/gui/widgets/Widget.hpp
index 6131a8c..9cf5c7c 100644
--- a/src/ogfx/gui/widgets/Widget.hpp
+++ b/src/ogfx/gui/widgets/Widget.hpp
@@ -1,21 +1,21 @@
/*
- OmniaFramework - A collection of useful functionality
- Copyright (C) 2025 OmniaX-Dev
+ OmniaFramework - A collection of useful functionality
+ Copyright (C) 2025 OmniaX-Dev
- This file is part of OmniaFramework.
+ 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 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.
+ 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 .
+ You should have received a copy of the GNU General Public License
+ along with OmniaFramework. If not, see .
*/
#pragma once
@@ -140,6 +140,18 @@ namespace ogfx
inline bool isDragAndDropEnabled(void) const { return m_acceptDragAndDrop; }
inline void enableDragAndDrop(bool enable = true) { m_acceptDragAndDrop = enable; }
inline void disableDragAndDrop(void) { enableDragAndDrop(false); }
+ inline void setBackGroundColor(const ostd::Color& color) { m_backgroundColor = color; }
+ inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; }
+ inline void enableBackground(bool enable = true) { m_showBackground = enable; }
+ inline bool isBackgoundEnabled(void) const { return m_showBackground; }
+ inline void setBorderColor(const ostd::Color& color) { m_borderColor = color; }
+ inline ostd::Color getBorderColor(void) { return m_borderColor; }
+ inline void enableBorder(bool enable = true) { m_showBorder = enable; }
+ inline bool isBorderEnabled(void) const { return m_showBorder; }
+ inline void setBorderRadius(int32_t br) { m_borderRadius = br; }
+ inline int32_t getBorderRadius(void) const { return m_borderRadius; }
+ inline void setBorderWidth(int32_t bw) { m_borderWidth = bw; }
+ inline int32_t getBorderWidth(void) const { return m_borderWidth; }
template
inline T getThemeValue(const ostd::Stylesheet &theme, const ostd::String& key, const T& fallback)
@@ -165,6 +177,8 @@ namespace ogfx
int32_t m_borderWidth { 2 };
ostd::Color m_borderColor { 255, 255, 255 };
bool m_showBorder { false };
+ ostd::Color m_backgroundColor { ostd::Colors::Transparent };
+ bool m_showBackground { false };
EventCallback callback_onMousePressed { nullptr };
EventCallback callback_onMouseReleased { nullptr };
diff --git a/src/ogfx/render/BasicRenderer.cpp b/src/ogfx/render/BasicRenderer.cpp
index 7ab85f3..7f29435 100644
--- a/src/ogfx/render/BasicRenderer.cpp
+++ b/src/ogfx/render/BasicRenderer.cpp
@@ -208,6 +208,7 @@ namespace ogfx
return set_error_state(tErrors::NullFont);
if (fontSize == m_fontSize || fontSize <= 0) return set_error_state(tErrors::NoError);
TTF_SetFontSize(m_font, fontSize);
+ m_fontSize = fontSize;
return set_error_state(tErrors::NoError);
}
@@ -317,6 +318,7 @@ namespace ogfx
if (!isValid()) return;
if (fontSize <= 0)
fontSize = m_fontSize;
+ int32_t oldFontSize = m_fontSize;
setFontSize(fontSize);
auto glyphs = m_fontGlyphAtlas.processString(str, m_font, fontSize);
@@ -348,6 +350,7 @@ namespace ogfx
x += (g->advance * scale);
}
+ setFontSize(oldFontSize);
}
void BasicRenderer2D::drawCenteredString(const ostd::String& str, const ostd::Vec2& center, const ostd::Color& color, int32_t fontSize, float scale)
@@ -661,7 +664,7 @@ namespace ogfx
if (!m_initialized) return;
ostd::Rectangle offset = { 1, 1, -2, -2 };
fillRect(rect + offset, fillColor);
- drawRect(rect , outlineColor, outlineThickness);
+ drawRect(rect, outlineColor, outlineThickness);
}
void BasicRenderer2D::outlinedRoundRect(const ostd::Rectangle& rect, const ostd::Color& fillColor, const ostd::Color& outlineColor, float radius, int32_t outlineThickness)
diff --git a/src/test/GuiTest.cpp b/src/test/GuiTest.cpp
index 0787c06..2207a9a 100644
--- a/src/test/GuiTest.cpp
+++ b/src/test/GuiTest.cpp
@@ -25,42 +25,6 @@
ostd::ConsoleOutputHandler out;
-void drawTexturedQuad(SDL_Renderer* renderer, SDL_Texture* tex, const ostd::Rectangle& rect, const ostd::Vec2 uvs[4])
-{
- SDL_Vertex verts[4];
-
- // Expand rectangle into quad corners
- const float x = rect.x;
- const float y = rect.y;
- const float w = rect.w;
- const float h = rect.h;
-
- const ostd::Vec2 quad[4] = {
- { x, y },
- { x + w, y },
- { x + w, y + h },
- { x, y + h }
- };
-
- for (int i = 0; i < 4; i++)
- {
- verts[i].position.x = quad[i].x;
- verts[i].position.y = quad[i].y;
-
- verts[i].tex_coord.x = uvs[i].x;
- verts[i].tex_coord.y = uvs[i].y;
-
- auto crim = ostd::Colors::Crimson.getNormalizedColor();
- verts[i].color = SDL_FColor{crim.r, crim.g, crim.b, crim.a};
- }
-
- // Two triangles: (0,1,2) and (2,3,0)
- const int indices[6] = { 0, 1, 2, 2, 3, 0 };
-
- SDL_RenderGeometry(renderer, tex, verts, 4, indices, 6);
-}
-
-
class Window : public ogfx::gui::Window
{
public:
@@ -98,6 +62,7 @@ class Window : public ogfx::gui::Window
m_label1.setText("Hello World!");
m_label1.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void {
std::cout << "PRESS!\n";
+ m_check1.setChecked(!m_check1.isChecked());
});
m_label1.setMouseScrolledCallback([&](const ogfx::gui::Event& event) -> void {
std::cout << "SCROLL!\n";
@@ -109,6 +74,9 @@ class Window : public ogfx::gui::Window
m_check1.setPosition(30, 30);
m_check1.setText("Check this out!");
+ m_check1.setStateChangedCallback([&](ogfx::gui::widgets::CheckBox& sender, bool state) -> void {
+ std::cout << STR_BOOL(state) << "\n";
+ });
addWidget(m_check1);
m_label2.setPosition(0, 0);
@@ -152,6 +120,9 @@ class Window : public ogfx::gui::Window
m_label3.addThemeID("label3");
m_panel1.addChild(m_label3);
+ wout().setFontSize(80);
+
+
setTheme(m_theme);
}
@@ -167,6 +138,7 @@ class Window : public ogfx::gui::Window
void onRedraw(ogfx::BasicRenderer2D& gfx) override
{
+ wout().xy(100, 100).fg(ostd::Colors::Crimson).p("CIAO BELLA").resetColors();
}
private: