From 9cbc0a088d5e65a498c4ddab2beeb8643a76a865 Mon Sep 17 00:00:00 2001 From: Rebekah Rowe Date: Sat, 23 Apr 2022 14:35:49 -0400 Subject: [PATCH] Created ICanvas for use in deffering rendering --- include/libpdw/gui/canvas.hpp | 17 +++- include/libpdw/gui/icanvas.hpp | 91 +++++++++++++++++++ include/libpdw/gui/listmenu/item.hpp | 2 +- include/libpdw/gui/listmenu/itemsublist.hpp | 2 +- include/libpdw/gui/listmenu/itemtitle.hpp | 2 +- include/libpdw/gui/listmenu/itemvariable.hpp | 2 +- include/libpdw/gui/listmenu/list.hpp | 2 +- include/libpdw/gui/ncc/background.hpp | 2 +- include/libpdw/gui/ncc/logo.hpp | 2 +- .../libpdw/gui/tabbedmenu/menucontainer.hpp | 2 +- include/libpdw/gui/widgets/basebutton.hpp | 2 +- include/libpdw/gui/widgets/basecontainer.hpp | 2 +- include/libpdw/gui/widgets/basewidget.hpp | 2 +- include/libpdw/gui/widgets/basewindow.hpp | 2 +- include/libpdw/gui/widgets/checkbox.hpp | 2 +- include/libpdw/gui/widgets/dropdown.hpp | 2 +- include/libpdw/gui/widgets/dropdownlist.hpp | 2 +- include/libpdw/gui/widgets/iwidget.hpp | 3 +- include/libpdw/gui/widgets/keyinput.hpp | 2 +- include/libpdw/gui/widgets/slider.hpp | 2 +- include/libpdw/gui/widgets/textinput.hpp | 2 +- include/libpdw/gui/widgets/textlabel.hpp | 2 +- include/libpdw/gui/widgets/titlebar.hpp | 2 +- src/gui/canvas.cpp | 6 +- src/gui/icanvas.cpp | 52 +++++++++++ src/gui/listmenu/item.cpp | 7 +- src/gui/listmenu/itemsublist.cpp | 8 +- src/gui/listmenu/itemtitle.cpp | 6 +- src/gui/listmenu/itemvariable.cpp | 6 +- src/gui/listmenu/list.cpp | 12 ++- src/gui/ncc/background.cpp | 2 +- src/gui/ncc/logo.cpp | 4 +- src/gui/tabbedmenu/menucontainer.cpp | 6 +- src/gui/tabbedmenu/menulistentry.cpp | 16 ++-- src/gui/tabbedmenu/menulistentry.hpp | 2 +- src/gui/tooltip.cpp | 13 +-- src/gui/tooltip.hpp | 2 +- src/gui/widgets/basebutton.cpp | 12 ++- src/gui/widgets/basecontainer.cpp | 9 +- src/gui/widgets/basewindow.cpp | 4 +- src/gui/widgets/checkbox.cpp | 6 +- src/gui/widgets/dropdown.cpp | 10 +- src/gui/widgets/dropdownlist.cpp | 9 +- src/gui/widgets/keyinput.cpp | 4 +- src/gui/widgets/slider.cpp | 8 +- src/gui/widgets/textinput.cpp | 10 +- src/gui/widgets/textlabel.cpp | 6 +- src/gui/widgets/titlebar.cpp | 6 +- 48 files changed, 271 insertions(+), 106 deletions(-) create mode 100644 include/libpdw/gui/icanvas.hpp create mode 100644 src/gui/icanvas.cpp diff --git a/include/libpdw/gui/canvas.hpp b/include/libpdw/gui/canvas.hpp index 69d51de..7a976c5 100644 --- a/include/libpdw/gui/canvas.hpp +++ b/include/libpdw/gui/canvas.hpp @@ -23,10 +23,11 @@ #include #include +#include "gui/icanvas.hpp" #include "gui/tooltip.hpp" #include "gui/widgets/basewindow.hpp" -class Canvas : public CBaseWindow { +class Canvas : public CBaseWindow, public ICanvas { public: Canvas(); void Setup(); @@ -38,13 +39,14 @@ public: std::chrono::steady_clock::time_point m_iPressedFrame[CatKey::CATKEY_COUNT]; std::chrono::steady_clock::time_point m_iSentFrame[CatKey::CATKEY_COUNT]; bool m_bKeysInit = false; + int m_iMouseX; int m_iMouseY; [[deprecated]] int mouse_dx; [[deprecated]] int mouse_dy; bool fake_scroll = false; - glez::rgba GetColor() const; + glez::rgba GetColor() const override; bool gui_rainbow = true; glez::rgba gui_color; @@ -52,9 +54,18 @@ public: virtual void Update() override; virtual void OnKeyPress(CatKey key, bool repeat) override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; inline virtual void MoveChildren() override {}; + void Line(TranslationMatrix tm, glez::rgba color) override; + void Rect(TranslationMatrix tm, glez::rgba color, RectType rt = RectType::Filled) override; + void Rect(TranslationMatrix tm, glez::rgba color, glez::texture& tx) override; + void Circle(std::pair center, float radius, glez::rgba color, int steps = 16) override; + std::pair String(std::pair src, const std::string& str, glez::rgba color, std::optional outline = glez::color::black) override; + std::pair StringSize(const std::string& str) override; + const ICanvas& GetBackground() const override { return *this; } + const ICanvas& GetForeground() const override { return *this; } + private: glez::font font; }; diff --git a/include/libpdw/gui/icanvas.hpp b/include/libpdw/gui/icanvas.hpp new file mode 100644 index 0000000..e26e881 --- /dev/null +++ b/include/libpdw/gui/icanvas.hpp @@ -0,0 +1,91 @@ + +/* + * Libpdw: Primitives Done Well! + * Copyright (C) 2022 Rebekah Rowe + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#pragma once + +#include +#include +#include +#include + +#include "gui/tooltip.hpp" +#include "gui/widgets/basewindow.hpp" + +class CanvasLayer { +public: + using TranslationMatrix = std::pair, std::pair>; // src, dest +public: + enum class RectType { Filled, + Outline }; + virtual void Line(TranslationMatrix, glez::rgba color) = 0; + virtual void Rect(TranslationMatrix, glez::rgba color, RectType = RectType::Filled) = 0; + virtual void Rect(TranslationMatrix, glez::rgba color, glez::texture&) = 0; + virtual void Circle(std::pair center, float radius, glez::rgba color, int steps = 16) = 0; + virtual std::pair String(std::pair src, const std::string& str, glez::rgba color, std::optional outline = glez::color::black) = 0; + virtual std::pair StringSize(const std::string& str) = 0; + virtual glez::rgba GetColor() const = 0; +}; + +class ICanvas : public CanvasLayer { +public: + // The plan is to "traverse" the canvas tree. Super easy way to manage themes maybe. We'll see! + virtual const ICanvas& GetBackground() const = 0; + virtual const ICanvas& GetForeground() const = 0; +}; + +inline std::pair operator+(std::pair v1, std::pair v2) { + return { v1.first + v2.first, v1.second + v2.second }; +} + +class CanvasOffset : public ICanvas { + ICanvas* parent; + std::pair offset; + TranslationMatrix Offset(TranslationMatrix tm) { + return { this->offset + tm.first, tm.second }; + } + +public: + CanvasOffset(ICanvas* parent, std::pair offset) + : parent(parent) + , offset(offset) { } + virtual void Line(TranslationMatrix tm, glez::rgba color) override { + this->parent->Line(this->Offset(tm), color); + } + virtual void Rect(TranslationMatrix tm, glez::rgba color, RectType rt = RectType::Filled) override { + this->parent->Rect(this->Offset(tm), color, rt); + } + virtual void Rect(TranslationMatrix tm, glez::rgba color, glez::texture& tx) override { + this->parent->Rect(this->Offset(tm), color, tx); + } + virtual void Circle(std::pair center, float radius, glez::rgba color, int steps = 16) override { + this->parent->Circle(this->offset + center, radius, color, steps); + } + virtual std::pair String(std::pair src, const std::string& str, glez::rgba color, std::optional outline = glez::color::black) override { + return this->parent->String(this->offset + src, str, color, outline); + } + virtual std::pair StringSize(const std::string& str) override { + return this->parent->StringSize(str); + } + virtual glez::rgba GetColor() const override { return this->parent->GetColor(); } + virtual const ICanvas& GetBackground() const override { return this->parent->GetBackground(); } + virtual const ICanvas& GetForeground() const override { return this->parent->GetForeground(); } + +public: + decltype(offset) GetOffset() const { return offset; } +}; diff --git a/include/libpdw/gui/listmenu/item.hpp b/include/libpdw/gui/listmenu/item.hpp index 0e6dfb4..53a5f54 100644 --- a/include/libpdw/gui/listmenu/item.hpp +++ b/include/libpdw/gui/listmenu/item.hpp @@ -35,7 +35,7 @@ public: Item(std::string name = "ncc_menu_item"); - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void HandleCustomEvent(std::string_view event) override; }; diff --git a/include/libpdw/gui/listmenu/itemsublist.hpp b/include/libpdw/gui/listmenu/itemsublist.hpp index 31873b5..312e971 100644 --- a/include/libpdw/gui/listmenu/itemsublist.hpp +++ b/include/libpdw/gui/listmenu/itemsublist.hpp @@ -35,7 +35,7 @@ public: virtual void SetParent(IWidget*) override; virtual bool IsHovered() const override; virtual void Update() override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void OnKeyPress(CatKey code, bool repeated) override; virtual void OnMouseEnter(); virtual void OnMouseLeave(); diff --git a/include/libpdw/gui/listmenu/itemtitle.hpp b/include/libpdw/gui/listmenu/itemtitle.hpp index 650d042..7d83e15 100644 --- a/include/libpdw/gui/listmenu/itemtitle.hpp +++ b/include/libpdw/gui/listmenu/itemtitle.hpp @@ -29,7 +29,7 @@ class ItemTitle : public Item { public: ItemTitle(std::string title); - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; public: const std::string title; diff --git a/include/libpdw/gui/listmenu/itemvariable.hpp b/include/libpdw/gui/listmenu/itemvariable.hpp index 7e3cee6..5689257 100644 --- a/include/libpdw/gui/listmenu/itemvariable.hpp +++ b/include/libpdw/gui/listmenu/itemvariable.hpp @@ -38,7 +38,7 @@ public: virtual void OnMousePress() override; virtual void OnFocusLose() override; virtual void OnKeyPress(CatKey key, bool repeat) override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; public: ui::BaseVar& catvar; diff --git a/include/libpdw/gui/listmenu/list.hpp b/include/libpdw/gui/listmenu/list.hpp index 541a1db..527085f 100644 --- a/include/libpdw/gui/listmenu/list.hpp +++ b/include/libpdw/gui/listmenu/list.hpp @@ -53,7 +53,7 @@ public: virtual void OnMouseEnter() override; virtual void OnMouseLeave() override; virtual void OnMouseMove(std::pair) override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void Update() override; virtual void MoveChildren() override; virtual void SetParent(IWidget* parent) override; diff --git a/include/libpdw/gui/ncc/background.hpp b/include/libpdw/gui/ncc/background.hpp index 14e0d2a..038260e 100644 --- a/include/libpdw/gui/ncc/background.hpp +++ b/include/libpdw/gui/ncc/background.hpp @@ -42,7 +42,7 @@ public: Background(); ~Background(); virtual bool AlwaysVisible() const override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void Update() override; void MakeParticle(); void KillParticle(Particle* flake); diff --git a/include/libpdw/gui/ncc/logo.hpp b/include/libpdw/gui/ncc/logo.hpp index 783547c..e0a93f4 100644 --- a/include/libpdw/gui/ncc/logo.hpp +++ b/include/libpdw/gui/ncc/logo.hpp @@ -29,7 +29,7 @@ class Logo : public CBaseWidget { public: Logo(IWidget*); virtual bool AlwaysVisible() const override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void OnMouseMove(std::pair) override; glez::texture texture; }; diff --git a/include/libpdw/gui/tabbedmenu/menucontainer.hpp b/include/libpdw/gui/tabbedmenu/menucontainer.hpp index 00d66d3..e46adfd 100644 --- a/include/libpdw/gui/tabbedmenu/menucontainer.hpp +++ b/include/libpdw/gui/tabbedmenu/menucontainer.hpp @@ -29,6 +29,6 @@ public: virtual inline void SortByZIndex() override {}; virtual void MoveChildren() override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; int columns; }; diff --git a/include/libpdw/gui/widgets/basebutton.hpp b/include/libpdw/gui/widgets/basebutton.hpp index 038b858..3546ace 100644 --- a/include/libpdw/gui/widgets/basebutton.hpp +++ b/include/libpdw/gui/widgets/basebutton.hpp @@ -36,7 +36,7 @@ public: CBaseButton(std::string name = "unnamed", IWidget* parent = nullptr, std::string text = "", ButtonCallbackFn_t callback = nullptr) : CBaseButton(parent, name, text, callback) { } - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void OnMousePress() override; void SetCallback(ButtonCallbackFn_t callback); diff --git a/include/libpdw/gui/widgets/basecontainer.hpp b/include/libpdw/gui/widgets/basecontainer.hpp index 58f2982..d073049 100644 --- a/include/libpdw/gui/widgets/basecontainer.hpp +++ b/include/libpdw/gui/widgets/basecontainer.hpp @@ -40,7 +40,7 @@ public: virtual IWidget* ChildByPoint(int x, int y); virtual bool ConsumesKey(CatKey key); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); virtual void DrawBounds(int x, int y); virtual void Hide(); virtual void OnFocusLose(); diff --git a/include/libpdw/gui/widgets/basewidget.hpp b/include/libpdw/gui/widgets/basewidget.hpp index c5f389e..53ba675 100644 --- a/include/libpdw/gui/widgets/basewidget.hpp +++ b/include/libpdw/gui/widgets/basewidget.hpp @@ -34,7 +34,7 @@ public: CBaseWidget(std::string name = "unnamed", IWidget* parent = nullptr); virtual void Update(); - inline virtual void Draw(int x, int y) {}; + virtual void Draw(ICanvas*) { } virtual void DrawBounds(int x, int y); inline virtual KeyValues* Props() const { diff --git a/include/libpdw/gui/widgets/basewindow.hpp b/include/libpdw/gui/widgets/basewindow.hpp index 7b716ea..33058fb 100644 --- a/include/libpdw/gui/widgets/basewindow.hpp +++ b/include/libpdw/gui/widgets/basewindow.hpp @@ -29,6 +29,6 @@ public: virtual void OnFocusGain() override; virtual void OnFocusLose() override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void MoveChildren() override; }; diff --git a/include/libpdw/gui/widgets/checkbox.hpp b/include/libpdw/gui/widgets/checkbox.hpp index 88715c4..69c57b9 100644 --- a/include/libpdw/gui/widgets/checkbox.hpp +++ b/include/libpdw/gui/widgets/checkbox.hpp @@ -37,7 +37,7 @@ public: void SetCallback(CheckboxCallbackFn_t callback); virtual void OnMousePress(); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); CheckboxCallbackFn_t m_pCallback; bool checked; diff --git a/include/libpdw/gui/widgets/dropdown.hpp b/include/libpdw/gui/widgets/dropdown.hpp index 252adab..d435877 100644 --- a/include/libpdw/gui/widgets/dropdown.hpp +++ b/include/libpdw/gui/widgets/dropdown.hpp @@ -43,7 +43,7 @@ public: void ShowList(); void SetCallback(DropdownCallbackFn_t callback); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); virtual void OnFocusLose(); DropdownCallbackFn_t m_pDropdownCallback; diff --git a/include/libpdw/gui/widgets/dropdownlist.hpp b/include/libpdw/gui/widgets/dropdownlist.hpp index bad7f68..433d17f 100644 --- a/include/libpdw/gui/widgets/dropdownlist.hpp +++ b/include/libpdw/gui/widgets/dropdownlist.hpp @@ -29,7 +29,7 @@ public: CDropdownList(std::string name = "unnamed", CDropdown* menu = nullptr, int offset = 0); ~CDropdownList(); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); virtual void MoveChildren(); inline virtual void SortByZIndex() override {}; inline virtual bool DoesStealFocus() { return false; } diff --git a/include/libpdw/gui/widgets/iwidget.hpp b/include/libpdw/gui/widgets/iwidget.hpp index f3cc52c..72d908d 100644 --- a/include/libpdw/gui/widgets/iwidget.hpp +++ b/include/libpdw/gui/widgets/iwidget.hpp @@ -34,12 +34,13 @@ enum PositionMode { class KeyValues; class Canvas; +class ICanvas; class IWidget { public: virtual ~IWidget(); virtual void Update() = 0; - virtual void Draw(int x, int y) = 0; + virtual void Draw(ICanvas*) = 0; virtual void DrawBounds(int x, int y) = 0; virtual KeyValues* Props() const = 0; diff --git a/include/libpdw/gui/widgets/keyinput.hpp b/include/libpdw/gui/widgets/keyinput.hpp index 1216821..5dddeae 100644 --- a/include/libpdw/gui/widgets/keyinput.hpp +++ b/include/libpdw/gui/widgets/keyinput.hpp @@ -38,7 +38,7 @@ public: KeyInputCallbackFn_t m_pCallback; virtual void OnKeyPress(CatKey key, bool repeat) override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void OnMousePress() override; virtual void OnFocusLose() override; virtual bool ConsumesKey(CatKey key) const override; diff --git a/include/libpdw/gui/widgets/slider.hpp b/include/libpdw/gui/widgets/slider.hpp index e361848..392b3c7 100644 --- a/include/libpdw/gui/widgets/slider.hpp +++ b/include/libpdw/gui/widgets/slider.hpp @@ -38,7 +38,7 @@ public: void SetCallback(SliderCallbackFn_t callback); virtual void Update(); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); SliderCallbackFn_t m_pCallback; diff --git a/include/libpdw/gui/widgets/textinput.hpp b/include/libpdw/gui/widgets/textinput.hpp index e0c3df0..7eabeec 100644 --- a/include/libpdw/gui/widgets/textinput.hpp +++ b/include/libpdw/gui/widgets/textinput.hpp @@ -32,7 +32,7 @@ public: : CTextInput(parent, name) { } virtual void OnKeyPress(CatKey key, bool repeat); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); virtual bool ConsumesKey(CatKey key); void PutChar(char ch); diff --git a/include/libpdw/gui/widgets/textlabel.hpp b/include/libpdw/gui/widgets/textlabel.hpp index 39bf664..30c4f93 100644 --- a/include/libpdw/gui/widgets/textlabel.hpp +++ b/include/libpdw/gui/widgets/textlabel.hpp @@ -34,7 +34,7 @@ public: void SetAutoSize(bool autosize); void SetCentered(bool centered); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); private: bool autosize; diff --git a/include/libpdw/gui/widgets/titlebar.hpp b/include/libpdw/gui/widgets/titlebar.hpp index 33d9c81..0034f8c 100644 --- a/include/libpdw/gui/widgets/titlebar.hpp +++ b/include/libpdw/gui/widgets/titlebar.hpp @@ -28,7 +28,7 @@ class CTitleBar : public CBaseWidget { public: CTitleBar(IWidget* parent, std::string title); - virtual void Draw(int x, int y); + virtual void Draw(ICanvas*); virtual void OnMouseMove(std::pair); virtual void Update(); diff --git a/src/gui/canvas.cpp b/src/gui/canvas.cpp index 771ee1f..834fbbb 100644 --- a/src/gui/canvas.cpp +++ b/src/gui/canvas.cpp @@ -170,7 +170,7 @@ void Canvas::Update() { tooltip->Hide(); CBaseWindow::Update(); - this->Draw(0, 0); + this->Draw((ICanvas*)this); // Draw Mouse glez::draw::rect(m_iMouseX - 5, m_iMouseY - 5, 10, 10, Transparent(glez::color::black)); @@ -180,11 +180,11 @@ void Canvas::Update() { this->DrawBounds(0, 0); } -void Canvas::Draw(int x, int y) { +void Canvas::Draw(ICanvas* canvas) { if (tooltip->IsVisible()) { tooltip->SetOffset(this->m_iMouseX + 24, this->m_iMouseY + 8); } - CBaseContainer::Draw(x, y); + CBaseContainer::Draw(canvas); } static auto start_time = std::chrono::steady_clock::now(); diff --git a/src/gui/icanvas.cpp b/src/gui/icanvas.cpp new file mode 100644 index 0000000..8e06091 --- /dev/null +++ b/src/gui/icanvas.cpp @@ -0,0 +1,52 @@ + +/* + * Libpdw: Primitives Done Well! + * Copyright (C) 2022 Rebekah Rowe + * + * This program 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. + * + * This program 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 this program. If not, see . + */ + +#include + +#include "gui/icanvas.hpp" +#include "gui/canvas.hpp" + +void Canvas::Line(TranslationMatrix tm, glez::rgba color) { + glez::draw::line(tm.first.first, tm.first.second, tm.second.first, tm.second.second, color, 1); +} +void Canvas::Rect(TranslationMatrix tm, glez::rgba color, RectType rt) { + if (rt == RectType::Filled) + glez::draw::rect(tm.first.first, tm.first.second, tm.second.first, tm.second.second, color); + else if (rt == RectType::Outline) + glez::draw::rect_outline(tm.first.first, tm.first.second, tm.second.first, tm.second.second, color, 1); +} +void Canvas::Rect(TranslationMatrix tm, glez::rgba color, glez::texture& tx) { + glez::draw::rect_textured(tm.first.first, tm.first.second, tm.second.first, tm.second.second, color, tx, 0, 0, tx.width, tx.height, 0.0f); +} +void Canvas::Circle(std::pair center, float radius, glez::rgba color, int steps) { + glez::draw::circle(center.first, center.second, radius, color, 1, steps); +} +std::pair Canvas::String(std::pair src, const std::string& str, glez::rgba color, std::optional outline) { + std::pair ret; + if (outline) + glez::draw::outlined_string(src.first, src.second, str, this->GetFont(), color, *outline, &ret.first, &ret.second); + else + glez::draw::string(src.first, src.second, str, this->GetFont(), color, &ret.first, &ret.second); + return ret; +} +std::pair Canvas::StringSize(const std::string& str) { + std::pair ret; + this->GetFont().stringSize(str, &ret.first, &ret.second); + return ret; +} diff --git a/src/gui/listmenu/item.cpp b/src/gui/listmenu/item.cpp index 12d6451..38276a3 100644 --- a/src/gui/listmenu/item.cpp +++ b/src/gui/listmenu/item.cpp @@ -35,12 +35,13 @@ Item::Item(std::string name) SetMaxSize(psize_x, psize_y); } -void Item::Draw(int x, int y) { +void Item::Draw(ICanvas* canvas) { const auto& size = GetSize(); // draw::DrawRect(x, y, size.first, size.second, colors::red); - glez::draw::rect(x, y, size.first, size.second, glez::rgba(0, 0, 0, 55)); + auto zero = std::pair { 0, 0 }; + canvas->Rect({ zero, size }, glez::rgba(0, 0, 0, 55)); if (IsHovered()) { - glez::draw::rect(x, y, size.first, size.second, Transparent(this->GetCanvas()->GetColor(), 0.32f)); + canvas->Rect({ zero, size }, Transparent(this->GetCanvas()->GetColor(), 0.32f)); } } diff --git a/src/gui/listmenu/itemsublist.cpp b/src/gui/listmenu/itemsublist.cpp index 5fe8e52..b8ba105 100644 --- a/src/gui/listmenu/itemsublist.cpp +++ b/src/gui/listmenu/itemsublist.cpp @@ -59,15 +59,15 @@ void ItemSublist::Update() { } } -void ItemSublist::Draw(int x, int y) { - Item::Draw(x, y); +void ItemSublist::Draw(ICanvas* canvas) { + Item::Draw(canvas); List* parent = dynamic_cast(GetParent()); if (!parent) throw std::runtime_error("Sublist parent can't be casted to List!"); const auto& size = GetSize(); if (parent->open_sublist == list) - glez::draw::rect(x, y, size.first, size.second, Transparent(this->GetCanvas()->GetColor(), 0.5f)); - glez::draw::string(x + 2, y, (IsHovered() ? "[-] " : "[+] ") + title, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->Rect({ { 0, 0 }, size }, Transparent(this->GetCanvas()->GetColor(), 0.5f)); + canvas->String({ 2, 0 }, (IsHovered() ? "[-] " : "[+] ") + title, glez::color::white); } void ItemSublist::OnKeyPress(CatKey code, bool repeated) { diff --git a/src/gui/listmenu/itemtitle.cpp b/src/gui/listmenu/itemtitle.cpp index 4e38253..54c48c5 100644 --- a/src/gui/listmenu/itemtitle.cpp +++ b/src/gui/listmenu/itemtitle.cpp @@ -33,14 +33,14 @@ ItemTitle::ItemTitle(std::string title) this->brackets = false; } -void ItemTitle::Draw(int x, int y) { - Item::Draw(x, y); +void ItemTitle::Draw(ICanvas* canvas) { + Item::Draw(canvas); // nailed it bool brackets3 = this->brackets; std::string str = (brackets3 ? ">>> " : ">> ") + title + (brackets3 ? " <<<" : " <<"); std::pair size; this->GetCanvas()->GetFont().stringSize(str, &size.first, &size.second); - glez::draw::string(x + ((Item::size_x - size.first) / 2), y, str, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->String({ ((Item::size_x - size.first) / 2), 0 }, str, glez::color::white); } } diff --git a/src/gui/listmenu/itemvariable.cpp b/src/gui/listmenu/itemvariable.cpp index 5b84f3c..ab9088a 100644 --- a/src/gui/listmenu/itemvariable.cpp +++ b/src/gui/listmenu/itemvariable.cpp @@ -114,8 +114,8 @@ void ItemVariable::OnKeyPress(CatKey key, bool repeat) { } } -void ItemVariable::Draw(int x, int y) { - Item::Draw(x, y); +void ItemVariable::Draw(ICanvas* canvas) { + Item::Draw(canvas); std::string val = "[UNDEFINED]"; switch (catvar.type) { case ui::BaseVar::Type::kBool: @@ -137,7 +137,7 @@ void ItemVariable::Draw(int x, int y) { } } break; } - glez::draw::string(x + 2, y, (std::string(catvar.gui_name) + ": " + val), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->String({ 2, 0 }, (std::string(catvar.gui_name) + ": " + val), glez::color::white); } } diff --git a/src/gui/listmenu/list.cpp b/src/gui/listmenu/list.cpp index 67606e6..2f068e8 100644 --- a/src/gui/listmenu/list.cpp +++ b/src/gui/listmenu/list.cpp @@ -230,11 +230,11 @@ void List::OnMouseLeave() { } } -void List::Draw(int x, int y) { +void List::Draw(ICanvas* canvas) { // const auto& size = GetSize(); - glez::draw::rect_outline(x, y, 2 + Item::size_x, this->items * Item::size_y + 2, this->GetCanvas()->GetColor(), 1); + canvas->Rect({ { 0, 0 }, { 2 + Item::size_x, this->items * Item::size_y + 2 } }, this->GetCanvas()->GetColor(), CanvasLayer::RectType::Outline); for (int i = 1; i < this->items; i++) { - glez::draw::line(x + 1, y + Item::size_y * i, Item::size_x, 0, this->GetCanvas()->GetColor(), 1); + canvas->Line({ { 1, Item::size_y * i }, { Item::size_x, 0 } }, this->GetCanvas()->GetColor()); } // CBaseContainer::Draw(x, y); for (int i = 0; i < ChildCount(); i++) { @@ -245,11 +245,13 @@ void List::Draw(int x, int y) { throw std::runtime_error("Invalid cast in NCC-List:Draw!"); } const auto& offset = item->GetOffset(); - item->Draw(x + offset.first, y + offset.second); + CanvasOffset offsetted_canvas(canvas, offset); + item->Draw(&offsetted_canvas); } if (dynamic_cast(open_sublist)) { const auto& offset = open_sublist->GetOffset(); - open_sublist->Draw(x + offset.first, y + offset.second); + CanvasOffset offsetted_canvas(canvas, offset); + open_sublist->Draw(&offsetted_canvas); } } diff --git a/src/gui/ncc/background.cpp b/src/gui/ncc/background.cpp index 8b15c04..93a46c0 100644 --- a/src/gui/ncc/background.cpp +++ b/src/gui/ncc/background.cpp @@ -89,7 +89,7 @@ Background::~Background() { } } -void Background::Draw(int x, int y) { +void Background::Draw(ICanvas* canvas) { if (!particles) return; Particle* current = list; diff --git a/src/gui/ncc/logo.cpp b/src/gui/ncc/logo.cpp index e3d0ce1..075a05e 100644 --- a/src/gui/ncc/logo.cpp +++ b/src/gui/ncc/logo.cpp @@ -39,9 +39,9 @@ bool Logo::AlwaysVisible() const { return (int)logo == 2; } -void Logo::Draw(int x, int y) { +void Logo::Draw(ICanvas* canvas) { if (logo) - glez::draw::rect_textured(x, y, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height, this->GetCanvas()->GetColor(), this->texture, 0, 0, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height, 0.0f); + canvas->Rect({ { 0, 0 }, { embeded_logo_png_rgba.width, embeded_logo_png_rgba.height } }, this->GetCanvas()->GetColor(), this->texture); } void Logo::OnMouseMove(std::pair delta) { diff --git a/src/gui/tabbedmenu/menucontainer.cpp b/src/gui/tabbedmenu/menucontainer.cpp index a22a4c3..6f1b504 100644 --- a/src/gui/tabbedmenu/menucontainer.cpp +++ b/src/gui/tabbedmenu/menucontainer.cpp @@ -48,9 +48,9 @@ void CMenuContainer::MoveChildren() { this->columns = columns; } -void CMenuContainer::Draw(int x, int y) { - CBaseContainer::Draw(x, y); +void CMenuContainer::Draw(ICanvas* canvas) { + CBaseContainer::Draw(canvas); for (int i = 0; i < this->columns; i++) { - glez::draw::line(x + (350 + 3) * (i + 1), y, 0, GetMaxSize().second, this->GetCanvas()->GetColor(), 1); + canvas->Line({ { (350 + 3) * (i + 1), 0 }, { 0, GetMaxSize().second } }, this->GetCanvas()->GetColor()); } } diff --git a/src/gui/tabbedmenu/menulistentry.cpp b/src/gui/tabbedmenu/menulistentry.cpp index e50a958..eccc5d6 100644 --- a/src/gui/tabbedmenu/menulistentry.cpp +++ b/src/gui/tabbedmenu/menulistentry.cpp @@ -38,19 +38,21 @@ bool CMenuListEntry::IsSelected() { return (dynamic_cast(GetParent())->m_pSelected == this); } -void CMenuListEntry::Draw(int x, int y) { +void CMenuListEntry::Draw(ICanvas* canvas) { std::pair texts; this->GetCanvas()->GetFont().stringSize(GetText(), &texts.first, &texts.second); auto size = GetSize(); + auto gui_color = canvas->GetColor(); + const auto zero = std::pair { 0, 0 }; if (IsSelected()) { - glez::draw::line(x, y, size.first, 0, this->GetCanvas()->GetColor(), 1); - glez::draw::line(x, y + size.second, size.first, 0, this->GetCanvas()->GetColor(), 1); - glez::draw::line(x, y, 0, size.second, this->GetCanvas()->GetColor(), 1); + canvas->Line({ zero, { size.first, 0 } }, gui_color); + canvas->Line({ { 0, size.second }, { size.first, 0 } }, gui_color); + canvas->Line({ zero, { 0, size.second } }, gui_color); } else { - glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1); + canvas->Rect({ zero, size }, gui_color, CanvasLayer::RectType::Outline); } if (IsHovered()) { - glez::draw::rect(x, y, size.first, size.second, Transparent(this->GetCanvas()->GetColor(), 0.25)); + canvas->Rect({ zero, size }, Transparent(gui_color, 0.25)); } - glez::draw::string(x + (size.first - texts.first) / 2, y + (size.second - texts.second) / 2, GetText().c_str(), this->GetCanvas()->GetFont(), IsSelected() ? glez::color::white : this->GetCanvas()->GetColor(), nullptr, nullptr); + canvas->String({ (size.first - texts.first) / 2, (size.second - texts.second) / 2 }, GetText(), IsSelected() ? glez::color::white : gui_color); } diff --git a/src/gui/tabbedmenu/menulistentry.hpp b/src/gui/tabbedmenu/menulistentry.hpp index 342ecf0..24242ac 100644 --- a/src/gui/tabbedmenu/menulistentry.hpp +++ b/src/gui/tabbedmenu/menulistentry.hpp @@ -30,7 +30,7 @@ public: bool IsSelected(); virtual void SetMaxSize(int x, int y) override; - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; public: std::string entry; diff --git a/src/gui/tooltip.cpp b/src/gui/tooltip.cpp index c211a35..38e557a 100644 --- a/src/gui/tooltip.cpp +++ b/src/gui/tooltip.cpp @@ -50,10 +50,11 @@ void Tooltip::HandleCustomEvent(std::string_view event) { }*/ } -void Tooltip::Draw(int x, int y) { +void Tooltip::Draw(ICanvas* canvas) { const auto& size = GetSize(); - int originx = x; - int originy = y; + auto offset = this->GetOffset(); + int originx = offset.first; + int originy = offset.second; auto root_size = this->GetCanvas()->GetSize(); if (originx + size.first > root_size.first) originx -= size.first; @@ -61,9 +62,9 @@ void Tooltip::Draw(int x, int y) { originy -= size.second; static auto bgcolor = glez::rgba(0, 0, 0, 77); // colors::Create(70, 86, 47, 28); static auto fgcolor = glez::rgba(200, 200, 190, 255); - glez::draw::rect(x, y, size.first, size.second, bgcolor); - glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1); - glez::draw::string(x + this->padding.first, y + this->padding.second, GetText(), this->GetCanvas()->GetFont(), fgcolor, nullptr, nullptr); + canvas->Rect({ { 0, 0 }, size }, bgcolor); + canvas->Rect({ { 0, 0 }, size }, this->GetCanvas()->GetColor(), CanvasLayer::RectType::Outline); + canvas->String(this->padding, GetText(), fgcolor); } } diff --git a/src/gui/tooltip.hpp b/src/gui/tooltip.hpp index 30b143b..81dcd80 100644 --- a/src/gui/tooltip.hpp +++ b/src/gui/tooltip.hpp @@ -28,7 +28,7 @@ class Tooltip : public CTextLabel { public: Tooltip(); - virtual void Draw(int x, int y) override; + virtual void Draw(ICanvas*) override; virtual void HandleCustomEvent(std::string_view event) override; inline virtual PositionMode GetPositionMode() const override { return PositionMode::FLOATING; } std::pair padding; diff --git a/src/gui/widgets/basebutton.cpp b/src/gui/widgets/basebutton.cpp index ecc3bad..cedc85d 100644 --- a/src/gui/widgets/basebutton.cpp +++ b/src/gui/widgets/basebutton.cpp @@ -35,15 +35,17 @@ void CBaseButton::SetCallback(ButtonCallbackFn_t callback) { m_pCallback = callback; } -void CBaseButton::Draw(int x, int y) { - glez::rgba textcolor = this->GetCanvas()->GetColor(); +void CBaseButton::Draw(ICanvas* canvas) { + auto gui_color = canvas->GetColor(); + auto textcolor = gui_color; auto size = GetSize(); + const auto zero = std::pair { 0, 0 }; if (IsPressed()) { - glez::draw::rect(x, y, size.first, size.second, this->GetCanvas()->GetColor()); + canvas->Rect({ zero, size }, gui_color); textcolor = glez::color::white; } - glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1); - glez::draw::string(x + this->padding.first, y + this->padding.second, GetText().c_str(), this->GetCanvas()->GetFont(), textcolor, nullptr, nullptr); + canvas->Rect({ zero, size }, gui_color, CanvasLayer::RectType::Outline); + canvas->String(this->padding, GetText(), textcolor); } void CBaseButton::OnMousePress() { diff --git a/src/gui/widgets/basecontainer.cpp b/src/gui/widgets/basecontainer.cpp index ff99afc..633ea8d 100644 --- a/src/gui/widgets/basecontainer.cpp +++ b/src/gui/widgets/basecontainer.cpp @@ -77,16 +77,17 @@ int CBaseContainer::ChildCount() { return m_children.size(); } -void CBaseContainer::Draw(int x, int y) { +void CBaseContainer::Draw(ICanvas* canvas) { for (auto child : m_children) { if (child->IsVisible()) { auto off = child->GetOffset(); - if (AlwaysVisible() || this->GetCanvas()->IsVisible() || child->AlwaysVisible()) - child->Draw(x + off.first, y + off.second); + if (AlwaysVisible() || this->GetCanvas()->IsVisible() || child->AlwaysVisible()) { + CanvasOffset offsetted_canvas(canvas, off); + child->Draw(&offsetted_canvas); + } } } } - void CBaseContainer::DrawBounds(int x, int y) { for (auto child : m_children) { if (child->IsVisible()) { diff --git a/src/gui/widgets/basewindow.cpp b/src/gui/widgets/basewindow.cpp index 9061752..6449cda 100644 --- a/src/gui/widgets/basewindow.cpp +++ b/src/gui/widgets/basewindow.cpp @@ -55,10 +55,10 @@ void CBaseWindow::OnFocusLose() { CBaseContainer::OnFocusLose(); } -void CBaseWindow::Draw(int x, int y) { +void CBaseWindow::Draw(ICanvas* canvas) { auto abs = AbsolutePosition(); auto size = GetSize(); glez::draw::rect(abs.first, abs.second, size.first, size.second, Transparent(glez::color::black, 0.9)); glez::draw::rect_outline(abs.first, abs.second, size.first, size.second, this->GetCanvas()->GetColor(), 1); - CBaseContainer::Draw(x, y); + CBaseContainer::Draw(canvas); } diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index e0d8c55..1f3bd92 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -34,11 +34,11 @@ void CCheckbox::SetWidth(int _width) { SetSize(_width, _width); } -void CCheckbox::Draw(int x, int y) { +void CCheckbox::Draw(ICanvas* canvas) { auto size = GetSize(); - glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1); + canvas->Rect({ { 0, 0 }, size }, this->GetCanvas()->GetColor(), CanvasLayer::RectType::Outline); if (Value()) { - glez::draw::rect(x + 3, y + 3, size.first - 6, size.second - 6, this->GetCanvas()->GetColor()); + canvas->Rect({ { 3, 3 }, { size.first - 6, size.second - 6 } }, this->GetCanvas()->GetColor()); } } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 3b3e631..0854c2b 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -55,16 +55,16 @@ std::string CDropdown::ValueName(int idx) { return m_values.at(idx); } -void CDropdown::Draw(int x, int y) { +void CDropdown::Draw(ICanvas* canvas) { auto size = GetSize(); std::pair ssize; this->GetCanvas()->GetFont().stringSize(ValueName(Value() - this->offset), &ssize.first, &ssize.second); - glez::draw::rect(x, y, size.first, size.second, Transparent(glez::color::black)); - glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1); - glez::draw::string(x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, ValueName(Value() - this->offset), this->GetCanvas()->GetFont(), this->GetCanvas()->GetColor(), nullptr, nullptr); + canvas->Rect({ { 0, 0 }, { size } }, Transparent(glez::color::black)); + canvas->Rect({ { 0, 0 }, { size } }, this->GetCanvas()->GetColor(), CanvasLayer::RectType::Outline); + canvas->String({ (size.first - ssize.first) / 2, (size.second - ssize.second) / 2 }, ValueName(Value() - this->offset), this->GetCanvas()->GetColor()); std::pair asize; this->GetCanvas()->GetFont().stringSize(">", &asize.first, &asize.second); - glez::draw::string(x + size.first - asize.first - 2, y + (size.second - asize.second) / 2, ">", this->GetCanvas()->GetFont(), this->GetCanvas()->GetColor(), nullptr, nullptr); + canvas->String({ size.first - asize.first - 2, (size.second - asize.second) / 2 }, ">", this->GetCanvas()->GetColor()); } void CDropdown::OnFocusLose() { diff --git a/src/gui/widgets/dropdownlist.cpp b/src/gui/widgets/dropdownlist.cpp index f71c029..9e4d9f1 100644 --- a/src/gui/widgets/dropdownlist.cpp +++ b/src/gui/widgets/dropdownlist.cpp @@ -52,11 +52,12 @@ void CDropdownList::SetValue(int value) { Hide(); } -void CDropdownList::Draw(int x, int y) { +void CDropdownList::Draw(ICanvas* canvas) { auto size = GetSize(); - glez::draw::rect(x, y, size.first, size.second, Transparent(glez::color::black, 0.85)); - glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1); - CBaseContainer::Draw(x, y); + + canvas->Rect({ { 0, 0 }, size }, Transparent(glez::color::black, 0.85)); + canvas->Rect({ { 0, 0 }, size }, this->GetCanvas()->GetColor(), CanvasLayer::RectType::Outline); + CBaseContainer::Draw(canvas); } void CDropdownList::MoveChildren() { diff --git a/src/gui/widgets/keyinput.cpp b/src/gui/widgets/keyinput.cpp index 8fe7374..38184e6 100644 --- a/src/gui/widgets/keyinput.cpp +++ b/src/gui/widgets/keyinput.cpp @@ -38,7 +38,7 @@ void CKeyInput::SetValue(int value) { this->value = value; } -void CKeyInput::Draw(int x, int y) { +void CKeyInput::Draw(ICanvas* canvas) { std::string key = ""; glez::rgba color = glez::color::white; if (this->capturing) { @@ -56,7 +56,7 @@ void CKeyInput::Draw(int x, int y) { auto size = GetSize(); std::pair ss; this->GetCanvas()->GetFont().stringSize(key, &ss.first, &ss.second); - glez::draw::string(x + (size.first - ss.first) / 2, y + (size.second - ss.second) / 2, key, this->GetCanvas()->GetFont(), color, nullptr, nullptr); + canvas->String({ (size.first - ss.first) / 2, (size.second - ss.second) / 2 }, key, color); } void CKeyInput::SetCallback(KeyInputCallbackFn_t callback) { diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp index ea88ca4..7b35f03 100644 --- a/src/gui/widgets/slider.cpp +++ b/src/gui/widgets/slider.cpp @@ -90,14 +90,14 @@ void CSlider::Update() { m_bDragInit = false; } -void CSlider::Draw(int x, int y) { +void CSlider::Draw(ICanvas* canvas) { auto size = GetSize(); - glez::draw::rect(x, y, size.first, size.second, glez::color::black); - glez::draw::rect(x, y, m_nSliderPos, size.second, this->GetCanvas()->GetColor()); + canvas->Rect({ { 0, 0 }, size }, glez::color::black); + canvas->Rect({ { 0, 0 }, { m_nSliderPos, size.second } }, this->GetCanvas()->GetColor()); char s[256]; snprintf(s, sizeof(s), "%.2f", Value()); std::string str(s); std::pair sl; this->GetCanvas()->GetFont().stringSize(str, &sl.first, &sl.second); - glez::draw::string(x + (size.first - sl.first) / 2, y + (size.second - sl.second) / 2, str, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->String({ (size.first - sl.first) / 2, (size.second - sl.second) / 2 }, str, glez::color::white); } diff --git a/src/gui/widgets/textinput.cpp b/src/gui/widgets/textinput.cpp index 9df9be8..a1aebc9 100644 --- a/src/gui/widgets/textinput.cpp +++ b/src/gui/widgets/textinput.cpp @@ -51,15 +51,15 @@ void CTextInput::SetValue(std::string value) { this->value = value; } -void CTextInput::Draw(int x, int y) { +void CTextInput::Draw(ICanvas* canvas) { std::pair wsize; this->GetCanvas()->GetFont().stringSize("W", &wsize.first, &wsize.second); auto size = GetSize(); auto color = glez::rgba(0, 0, 0, 80); if (IsFocused()) color = Transparent(this->GetCanvas()->GetColor(), 0.25); - glez::draw::rect(x, y, size.first, size.second, color); - glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1); + canvas->Rect({ { 0, 0 }, { size } }, color); + canvas->Rect({ { 0, 0 }, { size } }, this->GetCanvas()->GetColor(), CanvasLayer::RectType::Outline); int ml = 0; int md = 0; std::pair dotssize; // TODO static? @@ -74,9 +74,9 @@ void CTextInput::Draw(int x, int y) { ml = i; } if (ml) { - glez::draw::string(x + 2, y + 2, "..." + value.substr(md), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->String({ 2, 2 }, "..." + value.substr(md), glez::color::white); } else { - glez::draw::string(x + 2, y + 2, value, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); // TODO recalc on update + canvas->String({ 2, 2 }, value, glez::color::white); // TODO recalc on update } } diff --git a/src/gui/widgets/textlabel.cpp b/src/gui/widgets/textlabel.cpp index 898b17f..e5e38f7 100644 --- a/src/gui/widgets/textlabel.cpp +++ b/src/gui/widgets/textlabel.cpp @@ -123,12 +123,12 @@ std::string CTextLabel::GetText() { return this->text; } -void CTextLabel::Draw(int x, int y) { +void CTextLabel::Draw(ICanvas* canvas) { if (this->centered) { auto size = GetSize(); std::pair ssize; this->GetCanvas()->GetFont().stringSize(GetText(), &ssize.first, &ssize.second); - glez::draw::string(x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, GetText(), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->String({ (size.first - ssize.first) / 2, (size.second - ssize.second) / 2 }, GetText(), glez::color::white); } else - glez::draw::string(x, y, GetText(), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->String({ 0, 0 }, GetText(), glez::color::white); } diff --git a/src/gui/widgets/titlebar.cpp b/src/gui/widgets/titlebar.cpp index 81884be..ade10f5 100644 --- a/src/gui/widgets/titlebar.cpp +++ b/src/gui/widgets/titlebar.cpp @@ -29,12 +29,12 @@ CTitleBar::CTitleBar(IWidget* parent, std::string title) SetPositionMode(ABSOLUTE); } -void CTitleBar::Draw(int x, int y) { +void CTitleBar::Draw(ICanvas* canvas) { auto size = GetSize(); - glez::draw::rect(x, y, size.first, size.second, this->GetCanvas()->GetColor()); + canvas->Rect({ { 0, 0 }, { size } }, this->GetCanvas()->GetColor()); float l, h; this->GetCanvas()->GetFont().stringSize(m_strTitle, &l, &h); - glez::draw::string(x + (size.first - l) / 2, y + TITLEBAR_PADDING_H, m_strTitle, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); + canvas->String({ (size.first - l) / 2, TITLEBAR_PADDING_H }, m_strTitle, glez::color::white); } void CTitleBar::OnMouseMove(std::pair delta) {