Fixed a few bugs

This commit is contained in:
OmniaX-Dev 2026-04-14 13:03:01 +02:00
parent 17fdf08a20
commit faafd67015
18 changed files with 143 additions and 161 deletions

View file

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

View file

@ -55,6 +55,7 @@ $accentColor = Color(rgb(255, 0, 0))
borderRadius = 8 borderRadius = 8
borderWidth = 4 borderWidth = 4
showBorder = true showBorder = true
showBackground = true
padding = Rect(15, 15, 15, 15) padding = Rect(15, 15, 15, 15)
showTitle = true showTitle = true
titleColor = Color(#000000FF) titleColor = Color(#000000FF)

View file

@ -10,14 +10,16 @@
***Implement color constants in stylesheet ***Implement color constants in stylesheet
***Implement margin for widgets ***Implement margin for widgets
***Implement mouse scroll callback ***Implement mouse scroll callback
***Fix: Text rendering bug in labels
***Implement callback for state changes in checkbox
***FIX: WindowOutputHandler text rendering
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 find a way to add fixed update to gui::Window
Implement global scale (probably query desktop scale and adjust accordingly) Implement global scale (probably query desktop scale and adjust accordingly)
Fix: Text rendering bug in labels
Implement show/hide functionality for widgets Implement show/hide functionality for widgets
Implement wrappers in Renderer2D to take a center and size for rects 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 ListBox
ComboBox ComboBox
TreeView TreeView
Progressbar
Save/Open File Dialogs (and folder dialogs) Save/Open File Dialogs (and folder dialogs)
Tab Panel Tab Panel
Layouts Layouts

View file

@ -1 +1 @@
2061 2062

View file

@ -112,7 +112,7 @@ namespace ogfx
m_cursor_W_Resize = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_W_RESIZE); m_cursor_W_Resize = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_W_RESIZE);
m_wout.attachWindow(*this); m_wout.attachWindow(*this);
m_wout.setFontSize(22); // m_wout.setFontSize(22);
m_wout.setConsoleMaxCharacters({ 1000, 1000 }); m_wout.setConsoleMaxCharacters({ 1000, 1000 });
m_wout.setConsolePosition({ 5, 5 }); m_wout.setConsolePosition({ 5, 5 });
m_wout.setWrapMode(ogfx::GraphicsWindowOutputHandler::eWrapMode::NewLine); m_wout.setWrapMode(ogfx::GraphicsWindowOutputHandler::eWrapMode::NewLine);

View file

@ -213,7 +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 onUpdate(double delta) { }
inline virtual void onSignal(ostd::Signal& signal) { } inline virtual void onSignal(ostd::Signal& signal) { }
protected: protected:

View file

@ -35,14 +35,13 @@ namespace ogfx
{ {
if (m_window != nullptr) return; if (m_window != nullptr) return;
m_window = &window; m_window = &window;
// m_renderer.init(window); //TODO: Fix m_renderer.init(window);
} }
void GraphicsWindowOutputHandler::setMonospaceFont(const String& filePath) void GraphicsWindowOutputHandler::setMonospaceFont(const String& filePath)
{ {
//TODO: Fix m_renderer.openFont(filePath);
// m_renderer.setFont(filePath); m_renderer.setFontSize(m_fontSize);
// m_renderer.setFontSize(m_fontSize);
__update_char_size(); __update_char_size();
} }
@ -55,8 +54,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.hasOpenFont() && m_fontSize > 0;
} }
void GraphicsWindowOutputHandler::resetCursorPosition(void) void GraphicsWindowOutputHandler::resetCursorPosition(void)
@ -120,8 +119,7 @@ namespace ogfx
void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize) void GraphicsWindowOutputHandler::setFontSize(int32_t fontSize)
{ {
m_fontSize = fontSize; m_fontSize = fontSize;
//TODO: Fix m_renderer.setFontSize(m_fontSize);
// m_renderer.setFontSize(m_fontSize);
__update_char_size(); __update_char_size();
} }

View file

@ -46,10 +46,10 @@ namespace ogfx
setTextColor(getThemeValue<ostd::Color>(theme, "checkbox.textColor", ostd::Colors::Black)); setTextColor(getThemeValue<ostd::Color>(theme, "checkbox.textColor", ostd::Colors::Black));
setBackGroundColor(getThemeValue<ostd::Color>(theme, "checkbox.backgroundColor", ostd::Colors::Transparent)); setBackGroundColor(getThemeValue<ostd::Color>(theme, "checkbox.backgroundColor", ostd::Colors::Transparent));
setFontSize(getThemeValue<int32_t>(theme, "checkbox.fontSize", 28)); setFontSize(getThemeValue<int32_t>(theme, "checkbox.fontSize", 28));
m_borderRadius = getThemeValue<int32_t>(theme, "checkbox.borderRadius", 10); setBorderRadius(getThemeValue<int32_t>(theme, "checkbox.borderRadius", 10));
m_borderWidth = getThemeValue<int32_t>(theme, "checkbox.borderWidth", 2); setBorderWidth(getThemeValue<int32_t>(theme, "checkbox.borderWidth", 2));
m_showBorder = getThemeValue<bool>(theme, "checkbox.showBorder", false); enableBorder(getThemeValue<bool>(theme, "checkbox.showBorder", false));
m_borderColor = getThemeValue<ostd::Color>(theme, "checkbox.borderColor", ostd::Colors::White); setBorderColor(getThemeValue<ostd::Color>(theme, "checkbox.borderColor", ostd::Colors::White));
enableBackground(getThemeValue<bool>(theme, "checkbox.showBackground", false)); enableBackground(getThemeValue<bool>(theme, "checkbox.showBackground", false));
setPadding(getThemeValue<ostd::Rectangle>(theme, "checkbox.padding", { 5, 5, 5, 5 })); setPadding(getThemeValue<ostd::Rectangle>(theme, "checkbox.padding", { 5, 5, 5, 5 }));
setMargin(getThemeValue<ostd::Rectangle>(theme, "checkbox.margin", { 0, 0, 0, 0 })); setMargin(getThemeValue<ostd::Rectangle>(theme, "checkbox.margin", { 0, 0, 0, 0 }));
@ -61,10 +61,6 @@ namespace ogfx
{ {
if (m_textChanged) if (m_textChanged)
__update_size(gfx); __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); gfx.drawRoundRect({ getGlobalContentPosition(), m_checkSize }, getCheckBorderColor(), m_checkBorderRadius, m_checkBorderWidth);
if (isChecked()) if (isChecked())
gfx.fillRoundRect({ getGlobalContentPosition() + 5, m_checkSize - 10 }, getCheckBoxColor(), m_checkBorderRadius / 2.0f); gfx.fillRoundRect({ getGlobalContentPosition() + 5, m_checkSize - 10 }, getCheckBoxColor(), m_checkBorderRadius / 2.0f);
@ -75,8 +71,7 @@ namespace ogfx
{ {
if (!isMouseInside()) if (!isMouseInside())
return; return;
m_checked = !m_checked; setChecked(!isChecked());
setThemeQualifier("active", m_checked);
} }
void CheckBox::setText(const ostd::String& text) void CheckBox::setText(const ostd::String& text)
@ -85,6 +80,14 @@ namespace ogfx
m_textChanged = true; 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) void CheckBox::__update_size(ogfx::BasicRenderer2D& gfx)
{ {
auto size = gfx.getStringDimensions(getText(), getFontSize()); auto size = gfx.getStringDimensions(getText(), getFontSize());

View file

@ -40,6 +40,7 @@ namespace ogfx
void onDraw(ogfx::BasicRenderer2D& gfx) override; void onDraw(ogfx::BasicRenderer2D& gfx) override;
void onMouseReleased(const Event& event) override; void onMouseReleased(const Event& event) override;
void setText(const ostd::String& text); void setText(const ostd::String& text);
void setChecked(bool checked);
inline ostd::String getText(void) const { return m_text; } inline ostd::String getText(void) const { return m_text; }
inline ostd::Color getCheckBorderColor(void) const { return m_checkBorderColor; } inline ostd::Color getCheckBorderColor(void) const { return m_checkBorderColor; }
inline void setCheckBorderColor(const ostd::Color& color) { m_checkBorderColor = color; } 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 void setTextColor(const ostd::Color& color) { m_textColor = color; }
inline int32_t getFontSize(void) const { return m_fontSize; } inline int32_t getFontSize(void) const { return m_fontSize; }
inline void setFontSize(int32_t fontSize) { m_fontSize = 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 bool isChecked(void) const { return m_checked; }
inline void setChecked(bool checked) { m_checked = checked; } inline void setStateChangedCallback(std::function<void(CheckBox&, bool)> callback) { callback_onStateChanged = callback; }
private: private:
void __update_size(ogfx::BasicRenderer2D& gfx); void __update_size(ogfx::BasicRenderer2D& gfx);
@ -65,14 +62,14 @@ namespace ogfx
bool m_textChanged { false }; bool m_textChanged { false };
int32_t m_fontSize { 20 }; int32_t m_fontSize { 20 };
ostd::Color m_textColor { 255, 255, 255 }; ostd::Color m_textColor { 255, 255, 255 };
bool m_showBackground { false };
ostd::Color m_backgroundColor { ostd::Colors::Transparent };
float m_spacing { 10 }; float m_spacing { 10 };
ostd::Vec2 m_checkSize { 0, 0 }; ostd::Vec2 m_checkSize { 0, 0 };
int32_t m_checkBorderRadius { 5 }; int32_t m_checkBorderRadius { 5 };
int32_t m_checkBorderWidth { 1 }; int32_t m_checkBorderWidth { 1 };
ostd::Color m_checkBorderColor { 255, 255, 255 }; ostd::Color m_checkBorderColor { 255, 255, 255 };
ostd::Color m_checkBoxColor { 255, 255, 255 }; ostd::Color m_checkBoxColor { 255, 255, 255 };
std::function<void(CheckBox&, bool)> callback_onStateChanged { nullptr };
}; };
} }
} }

View file

@ -41,10 +41,11 @@ namespace ogfx
void Panel::applyTheme(const ostd::Stylesheet& theme) void Panel::applyTheme(const ostd::Stylesheet& theme)
{ {
setBackGroundColor(getThemeValue<ostd::Color>(theme, "panel.backgroundColor", ostd::Colors::Gray)); setBackGroundColor(getThemeValue<ostd::Color>(theme, "panel.backgroundColor", ostd::Colors::Gray));
m_borderRadius = getThemeValue<int32_t>(theme, "panel.borderRadius", 8); setBorderRadius(getThemeValue<int32_t>(theme, "panel.borderRadius", 8));
m_borderWidth = getThemeValue<int32_t>(theme, "panel.borderWidth", 2); setBorderWidth(getThemeValue<int32_t>(theme, "panel.borderWidth", 2));
m_showBorder = getThemeValue<bool>(theme, "panel.showBorder", true); enableBorder(getThemeValue<bool>(theme, "panel.showBorder", true));
m_borderColor = getThemeValue<ostd::Color>(theme, "panel.borderColor", ostd::Colors::Black); enableBackground(getThemeValue<bool>(theme, "panel.showBackground", true));
setBorderColor(getThemeValue<ostd::Color>(theme, "panel.borderColor", ostd::Colors::Black));
m_titleColor = getThemeValue<ostd::Color>(theme, "panel.titleColor", ostd::Colors::Black); m_titleColor = getThemeValue<ostd::Color>(theme, "panel.titleColor", ostd::Colors::Black);
m_showTitle = getThemeValue<bool>(theme, "panel.showTitle", false); m_showTitle = getThemeValue<bool>(theme, "panel.showTitle", false);
m_titleHeight = getThemeValue<float>(theme, "panel.titleHeight", 30); m_titleHeight = getThemeValue<float>(theme, "panel.titleHeight", 30);
@ -54,10 +55,6 @@ namespace ogfx
void Panel::onDraw(ogfx::BasicRenderer2D& gfx) 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);
} }
} }
} }

View file

@ -39,7 +39,6 @@ namespace ogfx
inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; } inline ostd::Color getBackgroundColor(void) { return m_backgroundColor; }
private: private:
ostd::Color m_backgroundColor { 150, 150, 150 };
ostd::Color m_titleColor { 0, 0, 0 }; ostd::Color m_titleColor { 0, 0, 0 };
bool m_showTitle { false }; bool m_showTitle { false };
ostd::String m_titleType = "full"; ostd::String m_titleType = "full";

View file

@ -44,10 +44,10 @@ namespace ogfx
setColor(getThemeValue<ostd::Color>(theme, "label.textColor", ostd::Colors::White)); setColor(getThemeValue<ostd::Color>(theme, "label.textColor", ostd::Colors::White));
setBackGroundColor(getThemeValue<ostd::Color>(theme, "label.backgroundColor", ostd::Colors::Transparent)); setBackGroundColor(getThemeValue<ostd::Color>(theme, "label.backgroundColor", ostd::Colors::Transparent));
setFontSize(getThemeValue<int32_t>(theme, "label.fontSize", 20)); setFontSize(getThemeValue<int32_t>(theme, "label.fontSize", 20));
m_borderRadius = getThemeValue<int32_t>(theme, "label.borderRadius", 10); setBorderRadius(getThemeValue<int32_t>(theme, "label.borderRadius", 10));
m_borderWidth = getThemeValue<int32_t>(theme, "label.borderWidth", 2); setBorderWidth(getThemeValue<int32_t>(theme, "label.borderWidth", 2));
m_showBorder = getThemeValue<bool>(theme, "label.showBorder", false); enableBorder(getThemeValue<bool>(theme, "label.showBorder", false));
m_borderColor = getThemeValue<ostd::Color>(theme, "label.borderColor", ostd::Colors::White); setBorderColor(getThemeValue<ostd::Color>(theme, "label.borderColor", ostd::Colors::White));
enableBackground(getThemeValue<bool>(theme, "label.showBackground", false)); enableBackground(getThemeValue<bool>(theme, "label.showBackground", false));
setPadding(getThemeValue<ostd::Rectangle>(theme, "label.padding", { 5, 5, 5, 5 })); setPadding(getThemeValue<ostd::Rectangle>(theme, "label.padding", { 5, 5, 5, 5 }));
setMargin(getThemeValue<ostd::Rectangle>(theme, "label.margin", { 0, 0, 0, 0 })); setMargin(getThemeValue<ostd::Rectangle>(theme, "label.margin", { 0, 0, 0, 0 }));
@ -57,10 +57,6 @@ namespace ogfx
{ {
if (m_textChanged) if (m_textChanged)
__update_size(gfx); __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()); gfx.drawString(getText(), getGlobalContentPosition(), getColor(), getFontSize());
} }

View file

@ -43,10 +43,6 @@ namespace ogfx
inline void setColor(const ostd::Color& color) { m_color = color; } inline void setColor(const ostd::Color& color) { m_color = color; }
inline int32_t getFontSize(void) const { return m_fontSize; } inline int32_t getFontSize(void) const { return m_fontSize; }
inline void setFontSize(int32_t fontSize) { m_fontSize = 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: private:
void __update_size(ogfx::BasicRenderer2D& gfx); void __update_size(ogfx::BasicRenderer2D& gfx);
@ -56,10 +52,6 @@ namespace ogfx
bool m_textChanged { false }; bool m_textChanged { false };
int32_t m_fontSize { 20 }; int32_t m_fontSize { 20 };
ostd::Color m_color { 255, 255, 255 }; ostd::Color m_color { 255, 255, 255 };
bool m_showBackground { false };
ostd::Color m_backgroundColor { ostd::Colors::Transparent };
private:
}; };
} }
} }

View file

@ -28,7 +28,6 @@ namespace ogfx
{ {
namespace gui namespace gui
{ {
ostd::BaseObject* Widget::s_dragAndDropData { nullptr }; ostd::BaseObject* Widget::s_dragAndDropData { nullptr };
bool Widget::s_hasDragAndDropData { false }; bool Widget::s_hasDragAndDropData { false };
@ -171,9 +170,18 @@ namespace ogfx
{ {
if (isDrawBoxEnabled()) if (isDrawBoxEnabled())
gfx.fillRect({ getGlobalPosition(), getSize() }, getDrawBoxColor()); 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); onDraw(gfx);
if (hasChildren()) if (hasChildren())
m_widgets.draw(gfx); m_widgets.draw(gfx);
if (m_showBorder)
gfx.drawRoundRect({ getGlobalPosition(), getSize() }, m_borderColor, m_borderRadius, m_borderWidth);
} }
void Widget::__update(void) void Widget::__update(void)

View file

@ -140,6 +140,18 @@ namespace ogfx
inline bool isDragAndDropEnabled(void) const { return m_acceptDragAndDrop; } inline bool isDragAndDropEnabled(void) const { return m_acceptDragAndDrop; }
inline void enableDragAndDrop(bool enable = true) { m_acceptDragAndDrop = enable; } inline void enableDragAndDrop(bool enable = true) { m_acceptDragAndDrop = enable; }
inline void disableDragAndDrop(void) { enableDragAndDrop(false); } 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<typename T> template<typename T>
inline T getThemeValue(const ostd::Stylesheet &theme, const ostd::String& key, const T& fallback) 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 }; int32_t m_borderWidth { 2 };
ostd::Color m_borderColor { 255, 255, 255 }; ostd::Color m_borderColor { 255, 255, 255 };
bool m_showBorder { false }; bool m_showBorder { false };
ostd::Color m_backgroundColor { ostd::Colors::Transparent };
bool m_showBackground { false };
EventCallback callback_onMousePressed { nullptr }; EventCallback callback_onMousePressed { nullptr };
EventCallback callback_onMouseReleased { nullptr }; EventCallback callback_onMouseReleased { nullptr };

View file

@ -208,6 +208,7 @@ namespace ogfx
return set_error_state(tErrors::NullFont); return set_error_state(tErrors::NullFont);
if (fontSize == m_fontSize || fontSize <= 0) return set_error_state(tErrors::NoError); if (fontSize == m_fontSize || fontSize <= 0) return set_error_state(tErrors::NoError);
TTF_SetFontSize(m_font, fontSize); TTF_SetFontSize(m_font, fontSize);
m_fontSize = fontSize;
return set_error_state(tErrors::NoError); return set_error_state(tErrors::NoError);
} }
@ -317,6 +318,7 @@ namespace ogfx
if (!isValid()) return; if (!isValid()) return;
if (fontSize <= 0) if (fontSize <= 0)
fontSize = m_fontSize; fontSize = m_fontSize;
int32_t oldFontSize = m_fontSize;
setFontSize(fontSize); setFontSize(fontSize);
auto glyphs = m_fontGlyphAtlas.processString(str, m_font, fontSize); auto glyphs = m_fontGlyphAtlas.processString(str, m_font, fontSize);
@ -348,6 +350,7 @@ namespace ogfx
x += (g->advance * scale); 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) void BasicRenderer2D::drawCenteredString(const ostd::String& str, const ostd::Vec2& center, const ostd::Color& color, int32_t fontSize, float scale)

View file

@ -25,42 +25,6 @@
ostd::ConsoleOutputHandler out; 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 class Window : public ogfx::gui::Window
{ {
public: public:
@ -98,6 +62,7 @@ class Window : public ogfx::gui::Window
m_label1.setText("Hello World!"); m_label1.setText("Hello World!");
m_label1.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void { m_label1.setMousePressedCallback([&](const ogfx::gui::Event& event) -> void {
std::cout << "PRESS!\n"; std::cout << "PRESS!\n";
m_check1.setChecked(!m_check1.isChecked());
}); });
m_label1.setMouseScrolledCallback([&](const ogfx::gui::Event& event) -> void { m_label1.setMouseScrolledCallback([&](const ogfx::gui::Event& event) -> void {
std::cout << "SCROLL!\n"; std::cout << "SCROLL!\n";
@ -109,6 +74,9 @@ class Window : public ogfx::gui::Window
m_check1.setPosition(30, 30); m_check1.setPosition(30, 30);
m_check1.setText("Check this out!"); 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); addWidget(m_check1);
m_label2.setPosition(0, 0); m_label2.setPosition(0, 0);
@ -152,6 +120,9 @@ class Window : public ogfx::gui::Window
m_label3.addThemeID("label3"); m_label3.addThemeID("label3");
m_panel1.addChild(m_label3); m_panel1.addChild(m_label3);
wout().setFontSize(80);
setTheme(m_theme); setTheme(m_theme);
} }
@ -167,6 +138,7 @@ class Window : public ogfx::gui::Window
void onRedraw(ogfx::BasicRenderer2D& gfx) override void onRedraw(ogfx::BasicRenderer2D& gfx) override
{ {
wout().xy(100, 100).fg(ostd::Colors::Crimson).p("CIAO BELLA").resetColors();
} }
private: private: