Created ICanvas for use in deffering rendering
This commit is contained in:
parent
6a74df3391
commit
9cbc0a088d
@ -23,10 +23,11 @@
|
||||
#include <glez/color.hpp>
|
||||
#include <glez/font.hpp>
|
||||
|
||||
#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<int, int> center, float radius, glez::rgba color, int steps = 16) override;
|
||||
std::pair<int, int> String(std::pair<int, int> src, const std::string& str, glez::rgba color, std::optional<glez::rgba> outline = glez::color::black) override;
|
||||
std::pair<int, int> StringSize(const std::string& str) override;
|
||||
const ICanvas& GetBackground() const override { return *this; }
|
||||
const ICanvas& GetForeground() const override { return *this; }
|
||||
|
||||
private:
|
||||
glez::font font;
|
||||
};
|
||||
|
91
include/libpdw/gui/icanvas.hpp
Normal file
91
include/libpdw/gui/icanvas.hpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <glez/color.hpp>
|
||||
#include <glez/font.hpp>
|
||||
#include <glez/texture.hpp>
|
||||
|
||||
#include "gui/tooltip.hpp"
|
||||
#include "gui/widgets/basewindow.hpp"
|
||||
|
||||
class CanvasLayer {
|
||||
public:
|
||||
using TranslationMatrix = std::pair<std::pair<int, int>, std::pair<int, int>>; // 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<int, int> center, float radius, glez::rgba color, int steps = 16) = 0;
|
||||
virtual std::pair<int, int> String(std::pair<int, int> src, const std::string& str, glez::rgba color, std::optional<glez::rgba> outline = glez::color::black) = 0;
|
||||
virtual std::pair<int, int> 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<int, int> operator+(std::pair<int, int> v1, std::pair<int, int> v2) {
|
||||
return { v1.first + v2.first, v1.second + v2.second };
|
||||
}
|
||||
|
||||
class CanvasOffset : public ICanvas {
|
||||
ICanvas* parent;
|
||||
std::pair<int, int> offset;
|
||||
TranslationMatrix Offset(TranslationMatrix tm) {
|
||||
return { this->offset + tm.first, tm.second };
|
||||
}
|
||||
|
||||
public:
|
||||
CanvasOffset(ICanvas* parent, std::pair<int, int> 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<int, int> center, float radius, glez::rgba color, int steps = 16) override {
|
||||
this->parent->Circle(this->offset + center, radius, color, steps);
|
||||
}
|
||||
virtual std::pair<int, int> String(std::pair<int, int> src, const std::string& str, glez::rgba color, std::optional<glez::rgba> outline = glez::color::black) override {
|
||||
return this->parent->String(this->offset + src, str, color, outline);
|
||||
}
|
||||
virtual std::pair<int, int> 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; }
|
||||
};
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
virtual void OnMouseEnter() override;
|
||||
virtual void OnMouseLeave() override;
|
||||
virtual void OnMouseMove(std::pair<int, int>) 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;
|
||||
|
@ -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);
|
||||
|
@ -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<int, int>) override;
|
||||
glez::texture texture;
|
||||
};
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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; }
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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<int, int>);
|
||||
virtual void Update();
|
||||
|
||||
|
@ -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();
|
||||
|
52
src/gui/icanvas.cpp
Normal file
52
src/gui/icanvas.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#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<int, int> center, float radius, glez::rgba color, int steps) {
|
||||
glez::draw::circle(center.first, center.second, radius, color, 1, steps);
|
||||
}
|
||||
std::pair<int, int> Canvas::String(std::pair<int, int> src, const std::string& str, glez::rgba color, std::optional<glez::rgba> outline) {
|
||||
std::pair<float, float> 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<int, int> Canvas::StringSize(const std::string& str) {
|
||||
std::pair<float, float> ret;
|
||||
this->GetFont().stringSize(str, &ret.first, &ret.second);
|
||||
return ret;
|
||||
}
|
@ -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<int, int> { 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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<List*>(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) {
|
||||
|
@ -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<float, float> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<List*>(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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ Background::~Background() {
|
||||
}
|
||||
}
|
||||
|
||||
void Background::Draw(int x, int y) {
|
||||
void Background::Draw(ICanvas* canvas) {
|
||||
if (!particles)
|
||||
return;
|
||||
Particle* current = list;
|
||||
|
@ -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<int, int> delta) {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -38,19 +38,21 @@ bool CMenuListEntry::IsSelected() {
|
||||
return (dynamic_cast<CMenuList*>(GetParent())->m_pSelected == this);
|
||||
}
|
||||
|
||||
void CMenuListEntry::Draw(int x, int y) {
|
||||
void CMenuListEntry::Draw(ICanvas* canvas) {
|
||||
std::pair<float, float> texts;
|
||||
this->GetCanvas()->GetFont().stringSize(GetText(), &texts.first, &texts.second);
|
||||
auto size = GetSize();
|
||||
auto gui_color = canvas->GetColor();
|
||||
const auto zero = std::pair<int, int> { 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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<int, int> padding;
|
||||
|
@ -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<int, int> { 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() {
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<float, float> 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<float, float> 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() {
|
||||
|
@ -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() {
|
||||
|
@ -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<float, float> 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) {
|
||||
|
@ -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<float, float> 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);
|
||||
}
|
||||
|
@ -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<float, float> 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<float, float> 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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<float, float> 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);
|
||||
}
|
||||
|
@ -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<int, int> delta) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user