Removed the "CatGUI* g_pGUI" global
This commit is contained in:
parent
722bcb95cc
commit
6e524b1707
@ -20,7 +20,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "lib/xoverlay.h"
|
#include "lib/xoverlay.h"
|
||||||
#include "libpdraw/gui/gui.hpp"
|
|
||||||
#include <embed_resources.hpp>
|
#include <embed_resources.hpp>
|
||||||
#include <glez/detail/render.hpp>
|
#include <glez/detail/render.hpp>
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
@ -48,14 +47,17 @@
|
|||||||
#include "libpdraw/gui/tabbedmenu/menucontainer.hpp"
|
#include "libpdraw/gui/tabbedmenu/menucontainer.hpp"
|
||||||
#include "libpdraw/gui/tabbedmenu/menuwindow.hpp"
|
#include "libpdraw/gui/tabbedmenu/menuwindow.hpp"
|
||||||
|
|
||||||
|
#include "libpdraw/gui/ncc/background.hpp"
|
||||||
|
#include "libpdraw/gui/ncc/logo.hpp"
|
||||||
|
|
||||||
#include "input.hpp"
|
#include "input.hpp"
|
||||||
|
|
||||||
static ui::Var<int> text({ "nonya" }, "Editable Text", 1);
|
static ui::Var<int> text({ "nonya" }, "Editable Text", 1);
|
||||||
|
|
||||||
class TestWindow : public CBaseWindow {
|
class TestWindow : public CBaseWindow {
|
||||||
public:
|
public:
|
||||||
TestWindow()
|
TestWindow(IWidget* parent)
|
||||||
: CBaseWindow("root_test", nullptr) {
|
: CBaseWindow("root_test", parent) {
|
||||||
this->always_visible = false;
|
this->always_visible = false;
|
||||||
this->hover = false;
|
this->hover = false;
|
||||||
SetMaxSize(1270, 1000);
|
SetMaxSize(1270, 1000);
|
||||||
@ -100,7 +102,7 @@ public:
|
|||||||
virtual void Update() override {
|
virtual void Update() override {
|
||||||
this->CBaseWindow::Update();
|
this->CBaseWindow::Update();
|
||||||
if (this->button_clicked)
|
if (this->button_clicked)
|
||||||
g_pGUI->GetRootWindow()->ShowTooltip("This is an example of a very long tooltip! You can click me again to hide me from view. Thanks for using libpdraw ;)");
|
this->GetCanvas()->ShowTooltip("This is an example of a very long tooltip! You can click me again to hide me from view. Thanks for using libpdraw ;)");
|
||||||
}
|
}
|
||||||
CTextInput* text_box = nullptr;
|
CTextInput* text_box = nullptr;
|
||||||
bool button_clicked = false;
|
bool button_clicked = false;
|
||||||
@ -135,21 +137,22 @@ int main() {
|
|||||||
|
|
||||||
glez::init(xoverlay_library.width, xoverlay_library.height);
|
glez::init(xoverlay_library.width, xoverlay_library.height);
|
||||||
|
|
||||||
|
Canvas* canvas;
|
||||||
{
|
{
|
||||||
input::RefreshInput();
|
input::RefreshInput();
|
||||||
xoverlay_draw_begin();
|
xoverlay_draw_begin();
|
||||||
glez::begin();
|
glez::begin();
|
||||||
|
|
||||||
g_pGUI = new CatGUI();
|
canvas = new Canvas();
|
||||||
g_pGUI->Setup();
|
canvas->Setup();
|
||||||
|
|
||||||
glez::end();
|
glez::end();
|
||||||
xoverlay_draw_end();
|
xoverlay_draw_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto test_window = new TestWindow();
|
auto test_window = new TestWindow(canvas);
|
||||||
|
|
||||||
g_pGUI->m_pRootWindow->AddChild(test_window);
|
canvas->AddChild(test_window);
|
||||||
|
|
||||||
using namespace menu::ncc;
|
using namespace menu::ncc;
|
||||||
// auto* list_menu = List::FromString(menu_list);
|
// auto* list_menu = List::FromString(menu_list);
|
||||||
@ -163,9 +166,9 @@ int main() {
|
|||||||
find->brackets = true;
|
find->brackets = true;
|
||||||
list_menu->SetMaxSize(1000, 1000);
|
list_menu->SetMaxSize(1000, 1000);
|
||||||
list_menu->Show();
|
list_menu->Show();
|
||||||
g_pGUI->m_pRootWindow->AddChild(list_menu);
|
canvas->AddChild(list_menu);
|
||||||
|
|
||||||
auto* tabbedmenu = new CMenuWindow("menu_window", g_pGUI->m_pRootWindow);
|
auto* tabbedmenu = new CMenuWindow("menu_window", canvas);
|
||||||
tabbedmenu->SetMaxSize(912, 410);
|
tabbedmenu->SetMaxSize(912, 410);
|
||||||
|
|
||||||
tabbedmenu->AddTab("aimbot", "Main");
|
tabbedmenu->AddTab("aimbot", "Main");
|
||||||
@ -177,7 +180,13 @@ int main() {
|
|||||||
tabbedmenu->AddTab("esp3", "Sub3");
|
tabbedmenu->AddTab("esp3", "Sub3");
|
||||||
|
|
||||||
// tabbedmenu->SetOffset((draw::width - 912) / 2, (draw::height - 410) / 2);
|
// tabbedmenu->SetOffset((draw::width - 912) / 2, (draw::height - 410) / 2);
|
||||||
g_pGUI->m_pRootWindow->AddChild(tabbedmenu);
|
canvas->AddChild(tabbedmenu);
|
||||||
|
|
||||||
|
auto* logo = new ncc::Logo(canvas);
|
||||||
|
logo->SetOffset(500, 25);
|
||||||
|
canvas->AddChild(logo);
|
||||||
|
|
||||||
|
canvas->AddChild(new ncc::Background());
|
||||||
|
|
||||||
for (auto& i : ui::BaseVar::GetList())
|
for (auto& i : ui::BaseVar::GetList())
|
||||||
printf("ui::BaseVar: %s\n", i->command_name.c_str());
|
printf("ui::BaseVar: %s\n", i->command_name.c_str());
|
||||||
@ -192,7 +201,7 @@ int main() {
|
|||||||
// glez::draw::rect(100, 300, 200, 100, glez::rgba(255, 0, 128));
|
// glez::draw::rect(100, 300, 200, 100, glez::rgba(255, 0, 128));
|
||||||
// auto mouse = input::GetMouse();
|
// auto mouse = input::GetMouse();
|
||||||
// glez::draw::rect(mouse.first - 6, mouse.second - 6, 12, 12, glez::rgba(255, 0, 128));
|
// glez::draw::rect(mouse.first - 6, mouse.second - 6, 12, 12, glez::rgba(255, 0, 128));
|
||||||
g_pGUI->m_pRootWindow->Update();
|
canvas->Update();
|
||||||
// glez::draw::rect_textured(50, 50, 100, 100, g_pGUI->m_pRootWindow->GetColor(), dispenser, 0, 10, 40, 94, 7);
|
// glez::draw::rect_textured(50, 50, 100, 100, g_pGUI->m_pRootWindow->GetColor(), dispenser, 0, 10, 40, 94, 7);
|
||||||
/*bool pressed = input::GetKey(CatKey::CATKEY_MOUSE_1);
|
/*bool pressed = input::GetKey(CatKey::CATKEY_MOUSE_1);
|
||||||
if (!click) {
|
if (!click) {
|
||||||
|
@ -1,44 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* Libpdraw: A Versitile GUI for use with a primitive drawing system!
|
|
||||||
* 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
|
|
||||||
|
|
||||||
class IWidget;
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "canvas.hpp"
|
|
||||||
#include "input.hpp"
|
|
||||||
|
|
||||||
/// Main root object of libpdraw
|
|
||||||
/**
|
|
||||||
* The main required global of the library.
|
|
||||||
* You MUST set g_pGUI to a valid pointer and run Setup() afterwards for anything to function.
|
|
||||||
*/
|
|
||||||
class CatGUI {
|
|
||||||
public:
|
|
||||||
CatGUI();
|
|
||||||
~CatGUI();
|
|
||||||
|
|
||||||
void Setup();
|
|
||||||
Canvas* GetRootWindow(); /**< Use to get a container you can add widgets to. */
|
|
||||||
Canvas* m_pRootWindow;
|
|
||||||
};
|
|
||||||
/** Must be a valid pointer for library to function. */
|
|
||||||
extern CatGUI* g_pGUI;
|
|
@ -27,7 +27,7 @@ namespace ncc {
|
|||||||
|
|
||||||
class Logo : public CBaseWidget {
|
class Logo : public CBaseWidget {
|
||||||
public:
|
public:
|
||||||
Logo();
|
Logo(IWidget*);
|
||||||
virtual bool AlwaysVisible() override;
|
virtual bool AlwaysVisible() override;
|
||||||
virtual void Draw(int x, int y) override;
|
virtual void Draw(int x, int y) override;
|
||||||
virtual void Update() override;
|
virtual void Update() override;
|
@ -102,7 +102,7 @@ public:
|
|||||||
inline virtual IWidget* GetParent() { return m_pParent; }
|
inline virtual IWidget* GetParent() { return m_pParent; }
|
||||||
inline virtual void SetParent(IWidget* parent) { m_pParent = parent; }
|
inline virtual void SetParent(IWidget* parent) { m_pParent = parent; }
|
||||||
inline virtual std::string GetName() { return this->name; }
|
inline virtual std::string GetName() { return this->name; }
|
||||||
|
virtual Canvas* GetCanvas();
|
||||||
std::pair<int, int> AbsolutePosition();
|
std::pair<int, int> AbsolutePosition();
|
||||||
inline void SetSize(int x, int y) {
|
inline void SetSize(int x, int y) {
|
||||||
if (x >= 0)
|
if (x >= 0)
|
||||||
|
@ -33,7 +33,7 @@ enum PositionMode {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class KeyValues;
|
class KeyValues;
|
||||||
|
class Canvas;
|
||||||
class IWidget {
|
class IWidget {
|
||||||
public:
|
public:
|
||||||
virtual ~IWidget();
|
virtual ~IWidget();
|
||||||
@ -86,4 +86,5 @@ public:
|
|||||||
virtual IWidget* GetParent() = 0;
|
virtual IWidget* GetParent() = 0;
|
||||||
virtual void SetParent(IWidget*) = 0;
|
virtual void SetParent(IWidget*) = 0;
|
||||||
virtual std::string GetName() = 0;
|
virtual std::string GetName() = 0;
|
||||||
|
virtual Canvas* GetCanvas() = 0;
|
||||||
};
|
};
|
||||||
|
@ -23,7 +23,8 @@
|
|||||||
|
|
||||||
class CTextLabel : public CBaseWidget {
|
class CTextLabel : public CBaseWidget {
|
||||||
public:
|
public:
|
||||||
CTextLabel(std::string name = "unnamed", IWidget* parent = nullptr, std::string text = "", bool centered = false);
|
CTextLabel(std::string name, IWidget* parent, std::string text = "", bool centered = false);
|
||||||
|
CTextLabel(std::string name = "unnamed", bool centered = false);
|
||||||
|
|
||||||
void SetText(std::string text);
|
void SetText(std::string text);
|
||||||
std::string GetText();
|
std::string GetText();
|
||||||
|
@ -38,8 +38,6 @@
|
|||||||
|
|
||||||
#include "gui/widgets/titlebar.hpp"
|
#include "gui/widgets/titlebar.hpp"
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
ui::Var<bool> gui_draw_bounds({ "Gui", "Debug" }, "Draw Bounds", false);
|
ui::Var<bool> gui_draw_bounds({ "Gui", "Debug" }, "Draw Bounds", false);
|
||||||
ui::Var<bool> gui_visible({ "Gui" }, "Visible", true);
|
ui::Var<bool> gui_visible({ "Gui" }, "Visible", true);
|
||||||
Canvas::Canvas()
|
Canvas::Canvas()
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* Libpdraw: A Versitile GUI for use with a primitive drawing system!
|
|
||||||
* 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 <cmath>
|
|
||||||
#include <glez/draw.hpp>
|
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
|
||||||
#include "gui/gui.hpp"
|
|
||||||
#include "gui/listmenu/itemsublist.hpp"
|
|
||||||
#include "gui/listmenu/itemtitle.hpp"
|
|
||||||
#include "gui/listmenu/itemvariable.hpp"
|
|
||||||
#include "gui/listmenu/list.hpp"
|
|
||||||
#include "gui/ncc/background.hpp"
|
|
||||||
#include "gui/ncc/logo.hpp"
|
|
||||||
#include "gui/tabbedmenu/cvarcontainer.hpp"
|
|
||||||
#include "gui/tabbedmenu/menucontainer.hpp"
|
|
||||||
#include "gui/tabbedmenu/menuwindow.hpp"
|
|
||||||
#include "gui/widgets/iwidget.hpp"
|
|
||||||
#include "tooltip.hpp"
|
|
||||||
|
|
||||||
CatGUI::CatGUI() {
|
|
||||||
m_pRootWindow = nullptr;
|
|
||||||
}
|
|
||||||
void CatGUI::Setup() {
|
|
||||||
m_pRootWindow = new Canvas();
|
|
||||||
m_pRootWindow->Setup();
|
|
||||||
|
|
||||||
auto* logo = new ncc::Logo();
|
|
||||||
logo->SetOffset(500, 25);
|
|
||||||
m_pRootWindow->AddChild(logo);
|
|
||||||
|
|
||||||
m_pRootWindow->AddChild(new ncc::Background());
|
|
||||||
}
|
|
||||||
|
|
||||||
CatGUI::~CatGUI() {
|
|
||||||
delete m_pRootWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*bool CatGUI::ConsumesKey(CatKey key) {
|
|
||||||
CBaseWindow* root = dynamic_cast<CBaseWindow*>(m_pRootWindow);
|
|
||||||
if (root->Isgui_visible)
|
|
||||||
return root->ConsumesKey(key);
|
|
||||||
else return false;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
Canvas* CatGUI::GetRootWindow() {
|
|
||||||
return m_pRootWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
CatGUI* g_pGUI = 0;
|
|
@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
#include "gui/listmenu/item.hpp"
|
#include "gui/listmenu/item.hpp"
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
#include <glez/color.hpp>
|
#include <glez/color.hpp>
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ void Item::Draw(int x, int y) {
|
|||||||
// draw::DrawRect(x, y, size.first, size.second, colors::red);
|
// 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));
|
glez::draw::rect(x, y, size.first, size.second, glez::rgba(0, 0, 0, 55));
|
||||||
if (IsHovered()) {
|
if (IsHovered()) {
|
||||||
glez::draw::rect(x, y, size.first, size.second, Transparent(g_pGUI->GetRootWindow()->GetColor(), 0.32f));
|
glez::draw::rect(x, y, size.first, size.second, Transparent(this->GetCanvas()->GetColor(), 0.32f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
#include "gui/listmenu/itemsublist.hpp"
|
#include "gui/listmenu/itemsublist.hpp"
|
||||||
|
|
||||||
namespace menu {
|
namespace menu {
|
||||||
@ -67,8 +66,8 @@ void ItemSublist::Draw(int x, int y) {
|
|||||||
throw std::runtime_error("Sublist parent can't be casted to List!");
|
throw std::runtime_error("Sublist parent can't be casted to List!");
|
||||||
const auto& size = GetSize();
|
const auto& size = GetSize();
|
||||||
if (parent->open_sublist == list)
|
if (parent->open_sublist == list)
|
||||||
glez::draw::rect(x, y, size.first, size.second, Transparent(g_pGUI->GetRootWindow()->GetColor(), 0.5f));
|
glez::draw::rect(x, y, size.first, size.second, Transparent(this->GetCanvas()->GetColor(), 0.5f));
|
||||||
glez::draw::string(x + 2, y, (IsHovered() ? "[-] " : "[+] ") + title, g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x + 2, y, (IsHovered() ? "[-] " : "[+] ") + title, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemSublist::OnKeyPress(CatKey code, bool repeated) {
|
void ItemSublist::OnKeyPress(CatKey code, bool repeated) {
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
#include <glez/font.hpp>
|
#include <glez/font.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/listmenu/itemtitle.hpp"
|
#include "gui/listmenu/itemtitle.hpp"
|
||||||
|
|
||||||
namespace menu {
|
namespace menu {
|
||||||
@ -39,8 +39,8 @@ void ItemTitle::Draw(int x, int y) {
|
|||||||
bool brackets3 = this->brackets;
|
bool brackets3 = this->brackets;
|
||||||
std::string str = (brackets3 ? ">>> " : ">> ") + title + (brackets3 ? " <<<" : " <<");
|
std::string str = (brackets3 ? ">>> " : ">> ") + title + (brackets3 ? " <<<" : " <<");
|
||||||
std::pair<float, float> size;
|
std::pair<float, float> size;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(str, &size.first, &size.second);
|
this->GetCanvas()->GetFont().stringSize(str, &size.first, &size.second);
|
||||||
glez::draw::string(x + ((Item::size_x - size.first) / 2), y, str, g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x + ((Item::size_x - size.first) / 2), y, str, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,9 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <var.hpp>
|
#include <var.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/listmenu/item.hpp"
|
#include "gui/listmenu/item.hpp"
|
||||||
|
|
||||||
#include "gui/listmenu/itemvariable.hpp"
|
#include "gui/listmenu/itemvariable.hpp"
|
||||||
|
|
||||||
namespace menu {
|
namespace menu {
|
||||||
@ -136,7 +137,7 @@ void ItemVariable::Draw(int x, int y) {
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
glez::draw::string(x + 2, y, (std::string(catvar.gui_name) + ": " + val), g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x + 2, y, (std::string(catvar.gui_name) + ": " + val), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
#include "gui/listmenu/item.hpp"
|
#include "gui/listmenu/item.hpp"
|
||||||
#include "gui/listmenu/itemsublist.hpp"
|
#include "gui/listmenu/itemsublist.hpp"
|
||||||
#include "gui/listmenu/itemtitle.hpp"
|
#include "gui/listmenu/itemtitle.hpp"
|
||||||
@ -233,9 +232,9 @@ void List::OnMouseLeave() {
|
|||||||
|
|
||||||
void List::Draw(int x, int y) {
|
void List::Draw(int x, int y) {
|
||||||
// const auto& size = GetSize();
|
// const auto& size = GetSize();
|
||||||
glez::draw::rect_outline(x, y, 2 + Item::size_x, this->items * Item::size_y + 2, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::rect_outline(x, y, 2 + Item::size_x, this->items * Item::size_y + 2, this->GetCanvas()->GetColor(), 1);
|
||||||
for (int i = 1; i < this->items; i++) {
|
for (int i = 1; i < this->items; i++) {
|
||||||
glez::draw::line(x + 1, y + Item::size_y * i, Item::size_x, 0, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::line(x + 1, y + Item::size_y * i, Item::size_x, 0, this->GetCanvas()->GetColor(), 1);
|
||||||
}
|
}
|
||||||
// CBaseContainer::Draw(x, y);
|
// CBaseContainer::Draw(x, y);
|
||||||
for (int i = 0; i < ChildCount(); i++) {
|
for (int i = 0; i < ChildCount(); i++) {
|
||||||
@ -272,7 +271,7 @@ void List::Update() {
|
|||||||
CBaseContainer::Update();
|
CBaseContainer::Update();
|
||||||
if (IsPressed() && root_list == this) {
|
if (IsPressed() && root_list == this) {
|
||||||
const auto& offset = root_list->GetOffset();
|
const auto& offset = root_list->GetOffset();
|
||||||
root_list->SetOffset(offset.first + g_pGUI->GetRootWindow()->mouse_dx, offset.second + g_pGUI->GetRootWindow()->mouse_dy);
|
root_list->SetOffset(offset.first + this->GetCanvas()->mouse_dx, offset.second + this->GetCanvas()->mouse_dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,12 +22,12 @@
|
|||||||
#include <glez/color.hpp>
|
#include <glez/color.hpp>
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/widgets/basewidget.hpp"
|
#include "gui/widgets/basewidget.hpp"
|
||||||
#include "input.hpp"
|
#include "input.hpp"
|
||||||
#include "var.hpp"
|
#include "var.hpp"
|
||||||
|
|
||||||
#include "background.hpp"
|
#include "gui/ncc/background.hpp"
|
||||||
|
|
||||||
namespace ncc {
|
namespace ncc {
|
||||||
|
|
||||||
@ -52,6 +52,7 @@ Background::Background()
|
|||||||
tx_raindrop2 = glez::texture::loadFromMemory(embeded_raindrop2_png_rgba.data.begin, embeded_raindrop2_png_rgba.data.size, embeded_raindrop2_png_rgba.width, embeded_raindrop2_png_rgba.height);
|
tx_raindrop2 = glez::texture::loadFromMemory(embeded_raindrop2_png_rgba.data.begin, embeded_raindrop2_png_rgba.data.size, embeded_raindrop2_png_rgba.width, embeded_raindrop2_png_rgba.height);
|
||||||
auto bounds = input::GetBounds();
|
auto bounds = input::GetBounds();
|
||||||
SetSize(bounds.first, bounds.second);
|
SetSize(bounds.first, bounds.second);
|
||||||
|
this->zindex = -999;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Background::AlwaysVisible() {
|
bool Background::AlwaysVisible() {
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
#include <embed_resources.hpp>
|
#include <embed_resources.hpp>
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "logo.hpp"
|
#include "gui/ncc/logo.hpp"
|
||||||
#include <var.hpp>
|
#include <var.hpp>
|
||||||
|
|
||||||
namespace ncc {
|
namespace ncc {
|
||||||
@ -29,8 +29,8 @@ namespace ncc {
|
|||||||
static ui::Enum logo_enum({ "NEVER", "MENU", "ALWAYS" });
|
static ui::Enum logo_enum({ "NEVER", "MENU", "ALWAYS" });
|
||||||
static ui::Var<ui::Enum> logo({ "Gui" }, "Logo", 1, logo_enum);
|
static ui::Var<ui::Enum> logo({ "Gui" }, "Logo", 1, logo_enum);
|
||||||
|
|
||||||
Logo::Logo()
|
Logo::Logo(IWidget* parent)
|
||||||
: CBaseWidget("nc_logo") {
|
: CBaseWidget("nc_logo", parent) {
|
||||||
this->texture = glez::texture::loadFromMemory(embeded_logo_png_rgba.data.begin, embeded_logo_png_rgba.data.size, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height);
|
this->texture = glez::texture::loadFromMemory(embeded_logo_png_rgba.data.begin, embeded_logo_png_rgba.data.size, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height);
|
||||||
SetSize(576, 288);
|
SetSize(576, 288);
|
||||||
}
|
}
|
||||||
@ -41,14 +41,14 @@ bool Logo::AlwaysVisible() {
|
|||||||
|
|
||||||
void Logo::Draw(int x, int y) {
|
void Logo::Draw(int x, int y) {
|
||||||
if (logo)
|
if (logo)
|
||||||
glez::draw::rect_textured(x, y, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height, g_pGUI->m_pRootWindow->GetColor(), this->texture, 0, 0, embeded_logo_png_rgba.width, embeded_logo_png_rgba.height, 0.0f);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logo::Update() {
|
void Logo::Update() {
|
||||||
if (IsPressed()) {
|
if (this->IsPressed()) {
|
||||||
auto offset = GetOffset();
|
auto offset = GetOffset();
|
||||||
offset.first += g_pGUI->GetRootWindow()->mouse_dx;
|
offset.first += this->GetCanvas()->mouse_dx;
|
||||||
offset.second += g_pGUI->GetRootWindow()->mouse_dy;
|
offset.second += this->GetCanvas()->mouse_dy;
|
||||||
SetOffset(offset.first, offset.second);
|
SetOffset(offset.first, offset.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,11 @@
|
|||||||
|
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/tabbedmenu/menucontainer.hpp"
|
#include "gui/tabbedmenu/menucontainer.hpp"
|
||||||
#include "gui/tabbedmenu/menuwindow.hpp"
|
#include "gui/tabbedmenu/menuwindow.hpp"
|
||||||
#include "gui/widgets/basebutton.hpp"
|
#include "gui/widgets/basebutton.hpp"
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
CMenuContainer::CMenuContainer(std::string name, CMenuWindow* parent)
|
CMenuContainer::CMenuContainer(std::string name, CMenuWindow* parent)
|
||||||
: CBaseContainer(name, parent) { SetMaxSize(200, 200); }
|
: CBaseContainer(name, parent) { SetMaxSize(200, 200); }
|
||||||
|
|
||||||
@ -40,6 +39,6 @@ void CMenuContainer::MoveChildren() {
|
|||||||
void CMenuContainer::Draw(int x, int y) {
|
void CMenuContainer::Draw(int x, int y) {
|
||||||
CBaseContainer::Draw(x, y);
|
CBaseContainer::Draw(x, y);
|
||||||
for (int i = 0; i < this->columns; i++) {
|
for (int i = 0; i < this->columns; i++) {
|
||||||
glez::draw::line(x + (350 + 3) * (i + 1), y, 0, GetMaxSize().second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::line(x + (350 + 3) * (i + 1), y, 0, GetMaxSize().second, this->GetCanvas()->GetColor(), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,6 @@
|
|||||||
#include "gui/tabbedmenu/menuwindow.hpp"
|
#include "gui/tabbedmenu/menuwindow.hpp"
|
||||||
#include "menulistentry.hpp"
|
#include "menulistentry.hpp"
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
CMenuList::CMenuList(std::string name, CMenuWindow* parent)
|
CMenuList::CMenuList(std::string name, CMenuWindow* parent)
|
||||||
: CBaseContainer(name, parent) {
|
: CBaseContainer(name, parent) {
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "menulist.hpp"
|
#include "menulist.hpp"
|
||||||
#include "menulistentry.hpp"
|
#include "menulistentry.hpp"
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
|
|
||||||
CMenuListEntry::CMenuListEntry(std::string name, CMenuList* parent, std::string entry)
|
CMenuListEntry::CMenuListEntry(std::string name, CMenuList* parent, std::string entry)
|
||||||
: CBaseButton(name, parent, entry) {
|
: CBaseButton(name, parent, entry) {
|
||||||
@ -40,17 +40,17 @@ bool CMenuListEntry::IsSelected() {
|
|||||||
|
|
||||||
void CMenuListEntry::Draw(int x, int y) {
|
void CMenuListEntry::Draw(int x, int y) {
|
||||||
std::pair<float, float> texts;
|
std::pair<float, float> texts;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(GetText(), &texts.first, &texts.second);
|
this->GetCanvas()->GetFont().stringSize(GetText(), &texts.first, &texts.second);
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
if (IsSelected()) {
|
if (IsSelected()) {
|
||||||
glez::draw::line(x, y, size.first, 0, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::line(x, y, size.first, 0, this->GetCanvas()->GetColor(), 1);
|
||||||
glez::draw::line(x, y + size.second, size.first, 0, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::line(x, y + size.second, size.first, 0, this->GetCanvas()->GetColor(), 1);
|
||||||
glez::draw::line(x, y, 0, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::line(x, y, 0, size.second, this->GetCanvas()->GetColor(), 1);
|
||||||
} else {
|
} else {
|
||||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1);
|
||||||
}
|
}
|
||||||
if (IsHovered()) {
|
if (IsHovered()) {
|
||||||
glez::draw::rect(x, y, size.first, size.second, Transparent(g_pGUI->GetRootWindow()->GetColor(), 0.25));
|
glez::draw::rect(x, y, size.first, size.second, Transparent(this->GetCanvas()->GetColor(), 0.25));
|
||||||
}
|
}
|
||||||
glez::draw::string(x + (size.first - texts.first) / 2, y + (size.second - texts.second) / 2, GetText().c_str(), g_pGUI->GetRootWindow()->GetFont(), IsSelected() ? glez::color::white : g_pGUI->GetRootWindow()->GetColor(), nullptr, nullptr);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
#include "gui/listmenu/item.hpp"
|
#include "gui/listmenu/item.hpp"
|
||||||
#include "gui/widgets/textlabel.hpp"
|
#include "gui/widgets/textlabel.hpp"
|
||||||
#include "tooltip.hpp"
|
#include "tooltip.hpp"
|
||||||
@ -55,7 +54,7 @@ void Tooltip::Draw(int x, int y) {
|
|||||||
const auto& size = GetSize();
|
const auto& size = GetSize();
|
||||||
int originx = x;
|
int originx = x;
|
||||||
int originy = y;
|
int originy = y;
|
||||||
auto root_size = g_pGUI->m_pRootWindow->GetSize();
|
auto root_size = this->GetCanvas()->GetSize();
|
||||||
if (originx + size.first > root_size.first)
|
if (originx + size.first > root_size.first)
|
||||||
originx -= size.first;
|
originx -= size.first;
|
||||||
if (originx + size.second > root_size.second)
|
if (originx + size.second > root_size.second)
|
||||||
@ -63,8 +62,8 @@ void Tooltip::Draw(int x, int y) {
|
|||||||
static auto bgcolor = glez::rgba(0, 0, 0, 77); // colors::Create(70, 86, 47, 28);
|
static auto bgcolor = glez::rgba(0, 0, 0, 77); // colors::Create(70, 86, 47, 28);
|
||||||
static auto fgcolor = glez::rgba(200, 200, 190, 255);
|
static auto fgcolor = glez::rgba(200, 200, 190, 255);
|
||||||
glez::draw::rect(x, y, size.first, size.second, bgcolor);
|
glez::draw::rect(x, y, size.first, size.second, bgcolor);
|
||||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
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(), g_pGUI->GetRootWindow()->GetFont(), fgcolor, nullptr, nullptr);
|
glez::draw::string(x + this->padding.first, y + this->padding.second, GetText(), this->GetCanvas()->GetFont(), fgcolor, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include "gui/widgets/basebutton.hpp"
|
#include "gui/widgets/basebutton.hpp"
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
|
|
||||||
CBaseButton::CBaseButton(std::string name, IWidget* parent, std::string text, ButtonCallbackFn_t callback)
|
CBaseButton::CBaseButton(std::string name, IWidget* parent, std::string text, ButtonCallbackFn_t callback)
|
||||||
: CTextLabel(name, parent, text) {
|
: CTextLabel(name, parent, text) {
|
||||||
@ -36,14 +36,14 @@ void CBaseButton::SetCallback(ButtonCallbackFn_t callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CBaseButton::Draw(int x, int y) {
|
void CBaseButton::Draw(int x, int y) {
|
||||||
glez::rgba textcolor = g_pGUI->GetRootWindow()->GetColor();
|
glez::rgba textcolor = this->GetCanvas()->GetColor();
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
if (IsPressed()) {
|
if (IsPressed()) {
|
||||||
glez::draw::rect(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor());
|
glez::draw::rect(x, y, size.first, size.second, this->GetCanvas()->GetColor());
|
||||||
textcolor = glez::color::white;
|
textcolor = glez::color::white;
|
||||||
}
|
}
|
||||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
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(), g_pGUI->GetRootWindow()->GetFont(), textcolor, nullptr, nullptr);
|
glez::draw::string(x + this->padding.first, y + this->padding.second, GetText().c_str(), this->GetCanvas()->GetFont(), textcolor, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseButton::OnMousePress() {
|
void CBaseButton::OnMousePress() {
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include "gui/widgets/basecontainer.hpp"
|
#include "gui/widgets/basecontainer.hpp"
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
class IMemAlloc;
|
class IMemAlloc;
|
||||||
IMemAlloc* g_pMemAlloc = 0;
|
IMemAlloc* g_pMemAlloc = 0;
|
||||||
@ -82,7 +81,7 @@ void CBaseContainer::Draw(int x, int y) {
|
|||||||
for (auto child : m_children) {
|
for (auto child : m_children) {
|
||||||
if (child->IsVisible()) {
|
if (child->IsVisible()) {
|
||||||
auto off = child->GetOffset();
|
auto off = child->GetOffset();
|
||||||
if (AlwaysVisible() || g_pGUI->GetRootWindow()->IsVisible() || child->AlwaysVisible())
|
if (AlwaysVisible() || this->GetCanvas()->IsVisible() || child->AlwaysVisible())
|
||||||
child->Draw(x + off.first, y + off.second);
|
child->Draw(x + off.first, y + off.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -177,7 +176,7 @@ void CBaseContainer::OnMouseLeave() {
|
|||||||
void CBaseContainer::OnMousePress() {
|
void CBaseContainer::OnMousePress() {
|
||||||
CBaseWidget::OnMousePress();
|
CBaseWidget::OnMousePress();
|
||||||
auto abs = AbsolutePosition();
|
auto abs = AbsolutePosition();
|
||||||
PressOn(ChildByPoint(g_pGUI->GetRootWindow()->m_iMouseX - abs.first, g_pGUI->GetRootWindow()->m_iMouseY - abs.second));
|
PressOn(ChildByPoint(this->GetCanvas()->m_iMouseX - abs.first, this->GetCanvas()->m_iMouseY - abs.second));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBaseContainer::OnMouseRelease() {
|
void CBaseContainer::OnMouseRelease() {
|
||||||
@ -204,7 +203,7 @@ void CBaseContainer::SortByZIndex() {
|
|||||||
|
|
||||||
void CBaseContainer::UpdateHovers() {
|
void CBaseContainer::UpdateHovers() {
|
||||||
auto abs = AbsolutePosition();
|
auto abs = AbsolutePosition();
|
||||||
auto hovered = ChildByPoint(g_pGUI->GetRootWindow()->m_iMouseX - abs.first, g_pGUI->GetRootWindow()->m_iMouseY - abs.second);
|
auto hovered = ChildByPoint(this->GetCanvas()->m_iMouseX - abs.first, this->GetCanvas()->m_iMouseY - abs.second);
|
||||||
if (hovered != GetHoveredChild()) {
|
if (hovered != GetHoveredChild()) {
|
||||||
HoverOn(hovered);
|
HoverOn(hovered);
|
||||||
}
|
}
|
||||||
@ -215,7 +214,7 @@ void CBaseContainer::Update() {
|
|||||||
MoveChildren();
|
MoveChildren();
|
||||||
UpdateHovers();
|
UpdateHovers();
|
||||||
for (auto child : m_children) {
|
for (auto child : m_children) {
|
||||||
if (AlwaysVisible() || g_pGUI->GetRootWindow()->IsVisible() || child->AlwaysVisible())
|
if (AlwaysVisible() || this->GetCanvas()->IsVisible() || child->AlwaysVisible())
|
||||||
child->Update();
|
child->Update();
|
||||||
}
|
}
|
||||||
CBaseWidget::Update();
|
CBaseWidget::Update();
|
||||||
|
@ -17,12 +17,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#include "gui/widgets/basewidget.hpp"
|
#include "gui/widgets/basewidget.hpp"
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
void CBaseWidget::DrawBounds(int x, int y) {
|
void CBaseWidget::DrawBounds(int x, int y) {
|
||||||
if (!this->bounds_color)
|
if (!this->bounds_color)
|
||||||
@ -33,15 +34,15 @@ void CBaseWidget::DrawBounds(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CBaseWidget::IsHovered() {
|
bool CBaseWidget::IsHovered() {
|
||||||
return g_pGUI->GetRootWindow()->IsVisible() && this->hover;
|
return this->GetCanvas()->IsVisible() && this->hover;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBaseWidget::IsFocused() {
|
bool CBaseWidget::IsFocused() {
|
||||||
return g_pGUI->GetRootWindow()->IsVisible() && this->focus;
|
return this->GetCanvas()->IsVisible() && this->focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBaseWidget::IsPressed() {
|
bool CBaseWidget::IsPressed() {
|
||||||
return g_pGUI->GetRootWindow()->IsVisible() && this->press;
|
return this->GetCanvas()->IsVisible() && this->press;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBaseWidget::CBaseWidget(std::string _name, IWidget* parent)
|
CBaseWidget::CBaseWidget(std::string _name, IWidget* parent)
|
||||||
@ -61,7 +62,7 @@ CBaseWidget::CBaseWidget(std::string _name, IWidget* parent)
|
|||||||
|
|
||||||
void CBaseWidget::Update() {
|
void CBaseWidget::Update() {
|
||||||
if (IsHovered() && IsVisible() && !this->tooltip.empty()) {
|
if (IsHovered() && IsVisible() && !this->tooltip.empty()) {
|
||||||
g_pGUI->m_pRootWindow->ShowTooltip(tooltip);
|
this->GetCanvas()->ShowTooltip(tooltip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,3 +77,14 @@ std::pair<int, int> CBaseWidget::AbsolutePosition() {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Canvas* CBaseWidget::GetCanvas() {
|
||||||
|
auto* parent = GetParent();
|
||||||
|
if (parent) {
|
||||||
|
if (auto* canvas = parent->GetCanvas())
|
||||||
|
return canvas;
|
||||||
|
}
|
||||||
|
auto* ret = dynamic_cast<Canvas*>(this);
|
||||||
|
assert(ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -19,10 +19,9 @@
|
|||||||
|
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/widgets/basewindow.hpp"
|
#include "gui/widgets/basewindow.hpp"
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
void CBaseWindow::MoveChildren() {
|
void CBaseWindow::MoveChildren() {
|
||||||
int mx = 0, my = 2;
|
int mx = 0, my = 2;
|
||||||
for (auto c : m_children) {
|
for (auto c : m_children) {
|
||||||
@ -61,6 +60,6 @@ void CBaseWindow::Draw(int x, int y) {
|
|||||||
auto abs = AbsolutePosition();
|
auto abs = AbsolutePosition();
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
glez::draw::rect(abs.first, abs.second, size.first, size.second, Transparent(glez::color::black, 0.9));
|
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, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::rect_outline(abs.first, abs.second, size.first, size.second, this->GetCanvas()->GetColor(), 1);
|
||||||
CBaseContainer::Draw(x, y);
|
CBaseContainer::Draw(x, y);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
|
|
||||||
#include "gui/widgets/checkbox.hpp"
|
#include "gui/widgets/checkbox.hpp"
|
||||||
|
|
||||||
@ -36,9 +36,9 @@ void CCheckbox::SetWidth(int _width) {
|
|||||||
|
|
||||||
void CCheckbox::Draw(int x, int y) {
|
void CCheckbox::Draw(int x, int y) {
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1);
|
||||||
if (Value()) {
|
if (Value()) {
|
||||||
glez::draw::rect(x + 3, y + 3, size.first - 6, size.second - 6, g_pGUI->GetRootWindow()->GetColor());
|
glez::draw::rect(x + 3, y + 3, size.first - 6, size.second - 6, this->GetCanvas()->GetColor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@
|
|||||||
|
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/widgets/dropdown.hpp"
|
#include "gui/widgets/dropdown.hpp"
|
||||||
#include "gui/widgets/dropdownlist.hpp"
|
#include "gui/widgets/dropdownlist.hpp"
|
||||||
@ -28,7 +26,7 @@
|
|||||||
CDropdown::CDropdown(std::string name, IWidget* parent)
|
CDropdown::CDropdown(std::string name, IWidget* parent)
|
||||||
: CBaseButton(name, parent) {
|
: CBaseButton(name, parent) {
|
||||||
list = new CDropdownList(name + "_list", this);
|
list = new CDropdownList(name + "_list", this);
|
||||||
g_pGUI->GetRootWindow()->AddChild(list);
|
this->GetCanvas()->AddChild(list);
|
||||||
SetSize(80, 18);
|
SetSize(80, 18);
|
||||||
list->SetSize(80, 0);
|
list->SetSize(80, 0);
|
||||||
CBaseButton::SetCallback([this](CBaseButton*) -> void {
|
CBaseButton::SetCallback([this](CBaseButton*) -> void {
|
||||||
@ -60,13 +58,13 @@ std::string CDropdown::ValueName(int idx) {
|
|||||||
void CDropdown::Draw(int x, int y) {
|
void CDropdown::Draw(int x, int y) {
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
std::pair<float, float> ssize;
|
std::pair<float, float> ssize;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(ValueName(Value() - this->offset), &ssize.first, &ssize.second);
|
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(x, y, size.first, size.second, Transparent(glez::color::black));
|
||||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
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), g_pGUI->GetRootWindow()->GetFont(), g_pGUI->GetRootWindow()->GetColor(), nullptr, nullptr);
|
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);
|
||||||
std::pair<float, float> asize;
|
std::pair<float, float> asize;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(">", &asize.first, &asize.second);
|
this->GetCanvas()->GetFont().stringSize(">", &asize.first, &asize.second);
|
||||||
glez::draw::string(x + size.first - asize.first - 2, y + (size.second - asize.second) / 2, ">", g_pGUI->GetRootWindow()->GetFont(), g_pGUI->GetRootWindow()->GetColor(), nullptr, nullptr);
|
glez::draw::string(x + size.first - asize.first - 2, y + (size.second - asize.second) / 2, ">", this->GetCanvas()->GetFont(), this->GetCanvas()->GetColor(), nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDropdown::OnFocusLose() {
|
void CDropdown::OnFocusLose() {
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
|
|
||||||
#include "dropdownentry.hpp"
|
#include "dropdownentry.hpp"
|
||||||
|
|
||||||
@ -36,9 +36,9 @@ CDropdownEntry::CDropdownEntry(std::string name, CDropdownList* parent, std::str
|
|||||||
|
|
||||||
void CDropdownEntry::Draw(int x, int y) {
|
void CDropdownEntry::Draw(int x, int y) {
|
||||||
std::pair<float, float> ssize;
|
std::pair<float, float> ssize;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(GetText(), &ssize.first, &ssize.second);
|
this->GetCanvas()->GetFont().stringSize(GetText(), &ssize.first, &ssize.second);
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
glez::draw::string(x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, GetText(), g_pGUI->GetRootWindow()->GetFont(), g_pGUI->GetRootWindow()->GetColor(), nullptr, nullptr);
|
glez::draw::string(x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, GetText(), this->GetCanvas()->GetFont(), this->GetCanvas()->GetColor(), nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
CDropdownEntry::~CDropdownEntry() {
|
CDropdownEntry::~CDropdownEntry() {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "gui/widgets/dropdownentry.hpp"
|
#include "gui/widgets/dropdownentry.hpp"
|
||||||
#include "gui/widgets/dropdownlist.hpp"
|
#include "gui/widgets/dropdownlist.hpp"
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
|
|
||||||
CDropdownList::CDropdownList(std::string name, CDropdown* menu, int offset)
|
CDropdownList::CDropdownList(std::string name, CDropdown* menu, int offset)
|
||||||
: CBaseContainer(name, nullptr) {
|
: CBaseContainer(name, nullptr) {
|
||||||
@ -55,7 +55,7 @@ void CDropdownList::SetValue(int value) {
|
|||||||
void CDropdownList::Draw(int x, int y) {
|
void CDropdownList::Draw(int x, int y) {
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
glez::draw::rect(x, y, size.first, size.second, Transparent(glez::color::black, 0.85));
|
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, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1);
|
||||||
CBaseContainer::Draw(x, y);
|
CBaseContainer::Draw(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
#include "gui/canvas.hpp"
|
||||||
|
|
||||||
#include "gui/widgets/keyinput.hpp"
|
#include "gui/widgets/keyinput.hpp"
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ void CKeyInput::Draw(int x, int y) {
|
|||||||
glez::rgba color = glez::color::white;
|
glez::rgba color = glez::color::white;
|
||||||
if (this->capturing) {
|
if (this->capturing) {
|
||||||
key = "< PRESS >";
|
key = "< PRESS >";
|
||||||
color = g_pGUI->GetRootWindow()->GetColor();
|
color = this->GetCanvas()->GetColor();
|
||||||
} else {
|
} else {
|
||||||
if (!Value()) {
|
if (!Value()) {
|
||||||
if (!IsFocused()) {
|
if (!IsFocused()) {
|
||||||
@ -55,8 +55,8 @@ void CKeyInput::Draw(int x, int y) {
|
|||||||
}
|
}
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
std::pair<float, float> ss;
|
std::pair<float, float> ss;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(key, &ss.first, &ss.second);
|
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, g_pGUI->GetRootWindow()->GetFont(), color, nullptr, nullptr);
|
glez::draw::string(x + (size.first - ss.first) / 2, y + (size.second - ss.second) / 2, key, this->GetCanvas()->GetFont(), color, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeyInput::SetCallback(KeyInputCallbackFn_t callback) {
|
void CKeyInput::SetCallback(KeyInputCallbackFn_t callback) {
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
#include "gui/widgets/slider.hpp"
|
#include "gui/widgets/slider.hpp"
|
||||||
|
|
||||||
@ -72,11 +71,11 @@ float CSlider::Value() {
|
|||||||
void CSlider::Update() {
|
void CSlider::Update() {
|
||||||
if (IsPressed()) {
|
if (IsPressed()) {
|
||||||
if (m_bDragInit) {
|
if (m_bDragInit) {
|
||||||
int delta = m_nLastX - g_pGUI->GetRootWindow()->m_iMouseX;
|
int delta = m_nLastX - this->GetCanvas()->m_iMouseX;
|
||||||
if (delta) {
|
if (delta) {
|
||||||
auto abs = AbsolutePosition();
|
auto abs = AbsolutePosition();
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
int mv = g_pGUI->GetRootWindow()->m_iMouseX - abs.first;
|
int mv = this->GetCanvas()->m_iMouseX - abs.first;
|
||||||
if (mv < 0)
|
if (mv < 0)
|
||||||
mv = 0;
|
mv = 0;
|
||||||
if (mv > size.first)
|
if (mv > size.first)
|
||||||
@ -85,7 +84,7 @@ void CSlider::Update() {
|
|||||||
m_nSliderPos = mv;
|
m_nSliderPos = mv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_nLastX = g_pGUI->GetRootWindow()->m_iMouseX;
|
m_nLastX = this->GetCanvas()->m_iMouseX;
|
||||||
m_bDragInit = true;
|
m_bDragInit = true;
|
||||||
} else
|
} else
|
||||||
m_bDragInit = false;
|
m_bDragInit = false;
|
||||||
@ -94,11 +93,11 @@ void CSlider::Update() {
|
|||||||
void CSlider::Draw(int x, int y) {
|
void CSlider::Draw(int x, int y) {
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
glez::draw::rect(x, y, size.first, size.second, glez::color::black);
|
glez::draw::rect(x, y, size.first, size.second, glez::color::black);
|
||||||
glez::draw::rect(x, y, m_nSliderPos, size.second, g_pGUI->GetRootWindow()->GetColor());
|
glez::draw::rect(x, y, m_nSliderPos, size.second, this->GetCanvas()->GetColor());
|
||||||
char s[256];
|
char s[256];
|
||||||
snprintf(s, sizeof(s), "%.2f", Value());
|
snprintf(s, sizeof(s), "%.2f", Value());
|
||||||
std::string str(s);
|
std::string str(s);
|
||||||
std::pair<float, float> sl;
|
std::pair<float, float> sl;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(str, &sl.first, &sl.second);
|
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, g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x + (size.first - sl.first) / 2, y + (size.second - sl.second) / 2, str, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
#include "gui/widgets/textinput.hpp"
|
#include "gui/widgets/textinput.hpp"
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ bool CTextInput::ConsumesKey(CatKey key) {
|
|||||||
|
|
||||||
void CTextInput::SetMaxWidth(int width) {
|
void CTextInput::SetMaxWidth(int width) {
|
||||||
std::pair<float, float> length;
|
std::pair<float, float> length;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize("W", &length.first, &length.second);
|
this->GetCanvas()->GetFont().stringSize("W", &length.first, &length.second);
|
||||||
SetSize(length.first * width + 4, length.second + 4); // TODO PADDING
|
SetSize(length.first * width + 4, length.second + 4); // TODO PADDING
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,30 +53,30 @@ void CTextInput::SetValue(std::string value) {
|
|||||||
|
|
||||||
void CTextInput::Draw(int x, int y) {
|
void CTextInput::Draw(int x, int y) {
|
||||||
std::pair<float, float> wsize;
|
std::pair<float, float> wsize;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize("W", &wsize.first, &wsize.second);
|
this->GetCanvas()->GetFont().stringSize("W", &wsize.first, &wsize.second);
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
auto color = glez::rgba(0, 0, 0, 80);
|
auto color = glez::rgba(0, 0, 0, 80);
|
||||||
if (IsFocused())
|
if (IsFocused())
|
||||||
color = Transparent(g_pGUI->GetRootWindow()->GetColor(), 0.25);
|
color = Transparent(this->GetCanvas()->GetColor(), 0.25);
|
||||||
glez::draw::rect(x, y, size.first, size.second, color);
|
glez::draw::rect(x, y, size.first, size.second, color);
|
||||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor(), 1);
|
glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1);
|
||||||
int ml = 0;
|
int ml = 0;
|
||||||
int md = 0;
|
int md = 0;
|
||||||
std::pair<float, float> dotssize; // TODO static?
|
std::pair<float, float> dotssize; // TODO static?
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize("...", &dotssize.first, &dotssize.second);
|
this->GetCanvas()->GetFont().stringSize("...", &dotssize.first, &dotssize.second);
|
||||||
std::string value = Value();
|
std::string value = Value();
|
||||||
for (int i = 0; i < value.length(); i++) {
|
for (int i = 0; i < value.length(); i++) {
|
||||||
std::pair<float, float> strsize;
|
std::pair<float, float> strsize;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(value.substr(i), &strsize.first, &strsize.second);
|
this->GetCanvas()->GetFont().stringSize(value.substr(i), &strsize.first, &strsize.second);
|
||||||
if (strsize.first + 10 + dotssize.first >= size.first)
|
if (strsize.first + 10 + dotssize.first >= size.first)
|
||||||
md = i;
|
md = i;
|
||||||
if (strsize.first + 8 > size.first)
|
if (strsize.first + 8 > size.first)
|
||||||
ml = i;
|
ml = i;
|
||||||
}
|
}
|
||||||
if (ml) {
|
if (ml) {
|
||||||
glez::draw::string(x + 2, y + 2, "..." + value.substr(md), g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x + 2, y + 2, "..." + value.substr(md), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
} else {
|
} else {
|
||||||
glez::draw::string(x + 2, y + 2, value, g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr); // TODO recalc on update
|
glez::draw::string(x + 2, y + 2, value, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr); // TODO recalc on update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +100,7 @@ void CTextInput::OnKeyPress(CatKey key, bool repeat) {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
char ch = 0;
|
char ch = 0;
|
||||||
if (g_pGUI->GetRootWindow()->m_bPressedState[CatKey::CATKEY_LSHIFT] || g_pGUI->GetRootWindow()->m_bPressedState[CatKey::CATKEY_RSHIFT]) {
|
if (this->GetCanvas()->m_bPressedState[CatKey::CATKEY_LSHIFT] || this->GetCanvas()->m_bPressedState[CatKey::CATKEY_RSHIFT]) {
|
||||||
ch = toupper(input::key_names[key][0]);
|
ch = toupper(input::key_names[key][0]);
|
||||||
} else {
|
} else {
|
||||||
ch = input::key_names[key][0];
|
ch = input::key_names[key][0];
|
||||||
|
@ -20,10 +20,10 @@
|
|||||||
#include <glez/draw.hpp>
|
#include <glez/draw.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
#include "gui/widgets/textlabel.hpp"
|
#include "gui/widgets/textlabel.hpp"
|
||||||
|
|
||||||
|
#include "gui/canvas.hpp"
|
||||||
|
|
||||||
static std::string WordWrap(std::string& in, int max, glez::font& font) {
|
static std::string WordWrap(std::string& in, int max, glez::font& font) {
|
||||||
std::stringstream result, line, wordstream, next;
|
std::stringstream result, line, wordstream, next;
|
||||||
std::string word;
|
std::string word;
|
||||||
@ -73,6 +73,17 @@ CTextLabel::CTextLabel(std::string name, IWidget* parent, std::string text, bool
|
|||||||
}
|
}
|
||||||
SetText(text);
|
SetText(text);
|
||||||
}
|
}
|
||||||
|
CTextLabel::CTextLabel(std::string name, bool centered) {
|
||||||
|
this->max_size.first = 50;
|
||||||
|
this->SetPadding(3, 3);
|
||||||
|
if (centered) {
|
||||||
|
SetAutoSize(false);
|
||||||
|
SetCentered(true);
|
||||||
|
} else {
|
||||||
|
SetAutoSize(true);
|
||||||
|
SetCentered(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CTextLabel::SetAutoSize(bool _autosize) {
|
void CTextLabel::SetAutoSize(bool _autosize) {
|
||||||
this->autosize = _autosize;
|
this->autosize = _autosize;
|
||||||
@ -90,7 +101,7 @@ void CTextLabel::SetText(std::string text) {
|
|||||||
// unsigned long font_handle = Props()->GetInt("font", fonts::MENU);
|
// unsigned long font_handle = Props()->GetInt("font", fonts::MENU);
|
||||||
this->text = text;
|
this->text = text;
|
||||||
std::pair<float, float> size;
|
std::pair<float, float> size;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(text, &size.first, &size.second);
|
this->GetCanvas()->GetFont().stringSize(text, &size.first, &size.second);
|
||||||
if (this->autosize) {
|
if (this->autosize) {
|
||||||
SetSize(size.first + padding.first * 2, size.second + padding.second * 2);
|
SetSize(size.first + padding.first * 2, size.second + padding.second * 2);
|
||||||
} else {
|
} else {
|
||||||
@ -98,9 +109,9 @@ void CTextLabel::SetText(std::string text) {
|
|||||||
auto ms = this->max_size.first;
|
auto ms = this->max_size.first;
|
||||||
SetSize(-1, size.second + padding.second * 2);
|
SetSize(-1, size.second + padding.second * 2);
|
||||||
if (ms /*.first*/ > 0) {
|
if (ms /*.first*/ > 0) {
|
||||||
std::string txt = WordWrap(text, ms /*.first*/ - 2 * padding.first, g_pGUI->GetRootWindow()->GetFont());
|
std::string txt = WordWrap(text, ms /*.first*/ - 2 * padding.first, this->GetCanvas()->GetFont());
|
||||||
std::pair<float, float> size2;
|
std::pair<float, float> size2;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(txt, &size2.first, &size2.second);
|
this->GetCanvas()->GetFont().stringSize(txt, &size2.first, &size2.second);
|
||||||
SetSize(size2.first + padding.first * 2, size2.second + padding.second * 2);
|
SetSize(size2.first + padding.first * 2, size2.second + padding.second * 2);
|
||||||
this->text = txt;
|
this->text = txt;
|
||||||
}
|
}
|
||||||
@ -116,8 +127,8 @@ void CTextLabel::Draw(int x, int y) {
|
|||||||
if (this->centered) {
|
if (this->centered) {
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
std::pair<float, float> ssize;
|
std::pair<float, float> ssize;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(GetText(), &ssize.first, &ssize.second);
|
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(), g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x + (size.first - ssize.first) / 2, y + (size.second - ssize.second) / 2, GetText(), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
} else
|
} else
|
||||||
glez::draw::string(x, y, GetText(), g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x, y, GetText(), this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "gui/widgets/titlebar.hpp"
|
#include "gui/widgets/titlebar.hpp"
|
||||||
|
|
||||||
#include "gui/canvas.hpp"
|
#include "gui/canvas.hpp"
|
||||||
#include "gui/gui.hpp"
|
|
||||||
|
|
||||||
CTitleBar::CTitleBar(IWidget* parent, std::string title)
|
CTitleBar::CTitleBar(IWidget* parent, std::string title)
|
||||||
: CBaseWidget("titlebar", parent) {
|
: CBaseWidget("titlebar", parent) {
|
||||||
@ -35,16 +34,16 @@ CTitleBar::CTitleBar(IWidget* parent, std::string title)
|
|||||||
|
|
||||||
void CTitleBar::Draw(int x, int y) {
|
void CTitleBar::Draw(int x, int y) {
|
||||||
auto size = GetSize();
|
auto size = GetSize();
|
||||||
glez::draw::rect(x, y, size.first, size.second, g_pGUI->GetRootWindow()->GetColor());
|
glez::draw::rect(x, y, size.first, size.second, this->GetCanvas()->GetColor());
|
||||||
float l, h;
|
float l, h;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(m_strTitle, &l, &h);
|
this->GetCanvas()->GetFont().stringSize(m_strTitle, &l, &h);
|
||||||
glez::draw::string(x + (size.first - l) / 2, y + TITLEBAR_PADDING_H, m_strTitle, g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
glez::draw::string(x + (size.first - l) / 2, y + TITLEBAR_PADDING_H, m_strTitle, this->GetCanvas()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTitleBar::Update() {
|
void CTitleBar::Update() {
|
||||||
auto psize = GetParent()->GetSize();
|
auto psize = GetParent()->GetSize();
|
||||||
float l, h;
|
float l, h;
|
||||||
g_pGUI->GetRootWindow()->GetFont().stringSize(m_strTitle, &l, &h);
|
this->GetCanvas()->GetFont().stringSize(m_strTitle, &l, &h);
|
||||||
SetSize(psize.first, 2 * TITLEBAR_PADDING_H + h);
|
SetSize(psize.first, 2 * TITLEBAR_PADDING_H + h);
|
||||||
if (!IsPressed()) {
|
if (!IsPressed()) {
|
||||||
m_iDraggingStage = 0;
|
m_iDraggingStage = 0;
|
||||||
@ -53,11 +52,11 @@ void CTitleBar::Update() {
|
|||||||
if (m_iDraggingStage == 0) {
|
if (m_iDraggingStage == 0) {
|
||||||
m_iDraggingStage = 1;
|
m_iDraggingStage = 1;
|
||||||
} else {
|
} else {
|
||||||
int dx = g_pGUI->GetRootWindow()->m_iMouseX - m_nLastX;
|
int dx = this->GetCanvas()->m_iMouseX - m_nLastX;
|
||||||
int dy = g_pGUI->GetRootWindow()->m_iMouseY - m_nLastY;
|
int dy = this->GetCanvas()->m_iMouseY - m_nLastY;
|
||||||
auto offset = GetParent()->GetOffset();
|
auto offset = GetParent()->GetOffset();
|
||||||
GetParent()->SetOffset(offset.first + dx, offset.second + dy);
|
GetParent()->SetOffset(offset.first + dx, offset.second + dy);
|
||||||
}
|
}
|
||||||
m_nLastX = g_pGUI->GetRootWindow()->m_iMouseX;
|
m_nLastX = this->GetCanvas()->m_iMouseX;
|
||||||
m_nLastY = g_pGUI->GetRootWindow()->m_iMouseY;
|
m_nLastY = this->GetCanvas()->m_iMouseY;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user