Removed the "CatGUI* g_pGUI" global
This commit is contained in:
parent
722bcb95cc
commit
6e524b1707
@ -20,7 +20,6 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "lib/xoverlay.h"
|
||||
#include "libpdraw/gui/gui.hpp"
|
||||
#include <embed_resources.hpp>
|
||||
#include <glez/detail/render.hpp>
|
||||
#include <glez/draw.hpp>
|
||||
@ -48,14 +47,17 @@
|
||||
#include "libpdraw/gui/tabbedmenu/menucontainer.hpp"
|
||||
#include "libpdraw/gui/tabbedmenu/menuwindow.hpp"
|
||||
|
||||
#include "libpdraw/gui/ncc/background.hpp"
|
||||
#include "libpdraw/gui/ncc/logo.hpp"
|
||||
|
||||
#include "input.hpp"
|
||||
|
||||
static ui::Var<int> text({ "nonya" }, "Editable Text", 1);
|
||||
|
||||
class TestWindow : public CBaseWindow {
|
||||
public:
|
||||
TestWindow()
|
||||
: CBaseWindow("root_test", nullptr) {
|
||||
TestWindow(IWidget* parent)
|
||||
: CBaseWindow("root_test", parent) {
|
||||
this->always_visible = false;
|
||||
this->hover = false;
|
||||
SetMaxSize(1270, 1000);
|
||||
@ -100,7 +102,7 @@ public:
|
||||
virtual void Update() override {
|
||||
this->CBaseWindow::Update();
|
||||
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;
|
||||
bool button_clicked = false;
|
||||
@ -135,21 +137,22 @@ int main() {
|
||||
|
||||
glez::init(xoverlay_library.width, xoverlay_library.height);
|
||||
|
||||
Canvas* canvas;
|
||||
{
|
||||
input::RefreshInput();
|
||||
xoverlay_draw_begin();
|
||||
glez::begin();
|
||||
|
||||
g_pGUI = new CatGUI();
|
||||
g_pGUI->Setup();
|
||||
canvas = new Canvas();
|
||||
canvas->Setup();
|
||||
|
||||
glez::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;
|
||||
// auto* list_menu = List::FromString(menu_list);
|
||||
@ -163,9 +166,9 @@ int main() {
|
||||
find->brackets = true;
|
||||
list_menu->SetMaxSize(1000, 1000);
|
||||
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->AddTab("aimbot", "Main");
|
||||
@ -177,7 +180,13 @@ int main() {
|
||||
tabbedmenu->AddTab("esp3", "Sub3");
|
||||
|
||||
// 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())
|
||||
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));
|
||||
// auto mouse = input::GetMouse();
|
||||
// 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);
|
||||
/*bool pressed = input::GetKey(CatKey::CATKEY_MOUSE_1);
|
||||
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 {
|
||||
public:
|
||||
Logo();
|
||||
Logo(IWidget*);
|
||||
virtual bool AlwaysVisible() override;
|
||||
virtual void Draw(int x, int y) override;
|
||||
virtual void Update() override;
|
@ -102,7 +102,7 @@ public:
|
||||
inline virtual IWidget* GetParent() { return m_pParent; }
|
||||
inline virtual void SetParent(IWidget* parent) { m_pParent = parent; }
|
||||
inline virtual std::string GetName() { return this->name; }
|
||||
|
||||
virtual Canvas* GetCanvas();
|
||||
std::pair<int, int> AbsolutePosition();
|
||||
inline void SetSize(int x, int y) {
|
||||
if (x >= 0)
|
||||
|
@ -33,7 +33,7 @@ enum PositionMode {
|
||||
};
|
||||
|
||||
class KeyValues;
|
||||
|
||||
class Canvas;
|
||||
class IWidget {
|
||||
public:
|
||||
virtual ~IWidget();
|
||||
@ -86,4 +86,5 @@ public:
|
||||
virtual IWidget* GetParent() = 0;
|
||||
virtual void SetParent(IWidget*) = 0;
|
||||
virtual std::string GetName() = 0;
|
||||
virtual Canvas* GetCanvas() = 0;
|
||||
};
|
||||
|
@ -23,7 +23,8 @@
|
||||
|
||||
class CTextLabel : public CBaseWidget {
|
||||
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);
|
||||
std::string GetText();
|
||||
|
@ -38,8 +38,6 @@
|
||||
|
||||
#include "gui/widgets/titlebar.hpp"
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
ui::Var<bool> gui_draw_bounds({ "Gui", "Debug" }, "Draw Bounds", false);
|
||||
ui::Var<bool> gui_visible({ "Gui" }, "Visible", true);
|
||||
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/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
#include <glez/color.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);
|
||||
glez::draw::rect(x, y, size.first, size.second, glez::rgba(0, 0, 0, 55));
|
||||
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 "gui/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/listmenu/itemsublist.hpp"
|
||||
|
||||
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!");
|
||||
const auto& size = GetSize();
|
||||
if (parent->open_sublist == list)
|
||||
glez::draw::rect(x, y, size.first, size.second, Transparent(g_pGUI->GetRootWindow()->GetColor(), 0.5f));
|
||||
glez::draw::string(x + 2, y, (IsHovered() ? "[-] " : "[+] ") + title, g_pGUI->GetRootWindow()->GetFont(), glez::color::white, nullptr, nullptr);
|
||||
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);
|
||||
}
|
||||
|
||||
void ItemSublist::OnKeyPress(CatKey code, bool repeated) {
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include <glez/draw.hpp>
|
||||
#include <glez/font.hpp>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/listmenu/itemtitle.hpp"
|
||||
|
||||
namespace menu {
|
||||
@ -39,8 +39,8 @@ void ItemTitle::Draw(int x, int y) {
|
||||
bool brackets3 = this->brackets;
|
||||
std::string str = (brackets3 ? ">>> " : ">> ") + title + (brackets3 ? " <<<" : " <<");
|
||||
std::pair<float, float> size;
|
||||
g_pGUI->GetRootWindow()->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);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,8 +22,9 @@
|
||||
#include <stdexcept>
|
||||
#include <var.hpp>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/listmenu/item.hpp"
|
||||
|
||||
#include "gui/listmenu/itemvariable.hpp"
|
||||
|
||||
namespace menu {
|
||||
@ -136,7 +137,7 @@ void ItemVariable::Draw(int x, int y) {
|
||||
}
|
||||
} 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 "gui/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/listmenu/item.hpp"
|
||||
#include "gui/listmenu/itemsublist.hpp"
|
||||
#include "gui/listmenu/itemtitle.hpp"
|
||||
@ -233,9 +232,9 @@ void List::OnMouseLeave() {
|
||||
|
||||
void List::Draw(int x, int y) {
|
||||
// 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++) {
|
||||
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);
|
||||
for (int i = 0; i < ChildCount(); i++) {
|
||||
@ -272,7 +271,7 @@ void List::Update() {
|
||||
CBaseContainer::Update();
|
||||
if (IsPressed() && root_list == this) {
|
||||
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/draw.hpp>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/widgets/basewidget.hpp"
|
||||
#include "input.hpp"
|
||||
#include "var.hpp"
|
||||
|
||||
#include "background.hpp"
|
||||
#include "gui/ncc/background.hpp"
|
||||
|
||||
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);
|
||||
auto bounds = input::GetBounds();
|
||||
SetSize(bounds.first, bounds.second);
|
||||
this->zindex = -999;
|
||||
}
|
||||
|
||||
bool Background::AlwaysVisible() {
|
||||
|
@ -20,8 +20,8 @@
|
||||
#include <embed_resources.hpp>
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "logo.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/ncc/logo.hpp"
|
||||
#include <var.hpp>
|
||||
|
||||
namespace ncc {
|
||||
@ -29,8 +29,8 @@ namespace ncc {
|
||||
static ui::Enum logo_enum({ "NEVER", "MENU", "ALWAYS" });
|
||||
static ui::Var<ui::Enum> logo({ "Gui" }, "Logo", 1, logo_enum);
|
||||
|
||||
Logo::Logo()
|
||||
: CBaseWidget("nc_logo") {
|
||||
Logo::Logo(IWidget* parent)
|
||||
: 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);
|
||||
SetSize(576, 288);
|
||||
}
|
||||
@ -41,14 +41,14 @@ bool Logo::AlwaysVisible() {
|
||||
|
||||
void Logo::Draw(int x, int y) {
|
||||
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() {
|
||||
if (IsPressed()) {
|
||||
if (this->IsPressed()) {
|
||||
auto offset = GetOffset();
|
||||
offset.first += g_pGUI->GetRootWindow()->mouse_dx;
|
||||
offset.second += g_pGUI->GetRootWindow()->mouse_dy;
|
||||
offset.first += this->GetCanvas()->mouse_dx;
|
||||
offset.second += this->GetCanvas()->mouse_dy;
|
||||
SetOffset(offset.first, offset.second);
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,11 @@
|
||||
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/tabbedmenu/menucontainer.hpp"
|
||||
#include "gui/tabbedmenu/menuwindow.hpp"
|
||||
#include "gui/widgets/basebutton.hpp"
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
CMenuContainer::CMenuContainer(std::string name, CMenuWindow* parent)
|
||||
: CBaseContainer(name, parent) { SetMaxSize(200, 200); }
|
||||
|
||||
@ -40,6 +39,6 @@ void CMenuContainer::MoveChildren() {
|
||||
void CMenuContainer::Draw(int x, int y) {
|
||||
CBaseContainer::Draw(x, y);
|
||||
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 "menulistentry.hpp"
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
CMenuList::CMenuList(std::string name, CMenuWindow* parent)
|
||||
: CBaseContainer(name, parent) {
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "menulist.hpp"
|
||||
#include "menulistentry.hpp"
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
|
||||
CMenuListEntry::CMenuListEntry(std::string name, CMenuList* parent, std::string entry)
|
||||
: CBaseButton(name, parent, entry) {
|
||||
@ -40,17 +40,17 @@ bool CMenuListEntry::IsSelected() {
|
||||
|
||||
void CMenuListEntry::Draw(int x, int y) {
|
||||
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();
|
||||
if (IsSelected()) {
|
||||
glez::draw::line(x, y, size.first, 0, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
glez::draw::line(x, y + size.second, size.first, 0, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
glez::draw::line(x, y, 0, size.second, 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, this->GetCanvas()->GetColor(), 1);
|
||||
glez::draw::line(x, y, 0, size.second, this->GetCanvas()->GetColor(), 1);
|
||||
} 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()) {
|
||||
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 "gui/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/listmenu/item.hpp"
|
||||
#include "gui/widgets/textlabel.hpp"
|
||||
#include "tooltip.hpp"
|
||||
@ -55,7 +54,7 @@ void Tooltip::Draw(int x, int y) {
|
||||
const auto& size = GetSize();
|
||||
int originx = x;
|
||||
int originy = y;
|
||||
auto root_size = g_pGUI->m_pRootWindow->GetSize();
|
||||
auto root_size = this->GetCanvas()->GetSize();
|
||||
if (originx + size.first > root_size.first)
|
||||
originx -= size.first;
|
||||
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 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, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
glez::draw::string(x + this->padding.first, y + this->padding.second, GetText(), g_pGUI->GetRootWindow()->GetFont(), fgcolor, nullptr, nullptr);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#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)
|
||||
: CTextLabel(name, parent, text) {
|
||||
@ -36,14 +36,14 @@ void CBaseButton::SetCallback(ButtonCallbackFn_t callback) {
|
||||
}
|
||||
|
||||
void CBaseButton::Draw(int x, int y) {
|
||||
glez::rgba textcolor = g_pGUI->GetRootWindow()->GetColor();
|
||||
glez::rgba textcolor = this->GetCanvas()->GetColor();
|
||||
auto size = GetSize();
|
||||
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;
|
||||
}
|
||||
glez::draw::rect_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->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::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);
|
||||
}
|
||||
|
||||
void CBaseButton::OnMousePress() {
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include "gui/widgets/basecontainer.hpp"
|
||||
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
class IMemAlloc;
|
||||
IMemAlloc* g_pMemAlloc = 0;
|
||||
@ -82,7 +81,7 @@ void CBaseContainer::Draw(int x, int y) {
|
||||
for (auto child : m_children) {
|
||||
if (child->IsVisible()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -177,7 +176,7 @@ void CBaseContainer::OnMouseLeave() {
|
||||
void CBaseContainer::OnMousePress() {
|
||||
CBaseWidget::OnMousePress();
|
||||
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() {
|
||||
@ -204,7 +203,7 @@ void CBaseContainer::SortByZIndex() {
|
||||
|
||||
void CBaseContainer::UpdateHovers() {
|
||||
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()) {
|
||||
HoverOn(hovered);
|
||||
}
|
||||
@ -215,7 +214,7 @@ void CBaseContainer::Update() {
|
||||
MoveChildren();
|
||||
UpdateHovers();
|
||||
for (auto child : m_children) {
|
||||
if (AlwaysVisible() || g_pGUI->GetRootWindow()->IsVisible() || child->AlwaysVisible())
|
||||
if (AlwaysVisible() || this->GetCanvas()->IsVisible() || child->AlwaysVisible())
|
||||
child->Update();
|
||||
}
|
||||
CBaseWidget::Update();
|
||||
|
@ -17,12 +17,13 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include <glez/draw.hpp>
|
||||
#include <ostream>
|
||||
|
||||
#include "gui/widgets/basewidget.hpp"
|
||||
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
void CBaseWidget::DrawBounds(int x, int y) {
|
||||
if (!this->bounds_color)
|
||||
@ -33,15 +34,15 @@ void CBaseWidget::DrawBounds(int x, int y) {
|
||||
}
|
||||
|
||||
bool CBaseWidget::IsHovered() {
|
||||
return g_pGUI->GetRootWindow()->IsVisible() && this->hover;
|
||||
return this->GetCanvas()->IsVisible() && this->hover;
|
||||
}
|
||||
|
||||
bool CBaseWidget::IsFocused() {
|
||||
return g_pGUI->GetRootWindow()->IsVisible() && this->focus;
|
||||
return this->GetCanvas()->IsVisible() && this->focus;
|
||||
}
|
||||
|
||||
bool CBaseWidget::IsPressed() {
|
||||
return g_pGUI->GetRootWindow()->IsVisible() && this->press;
|
||||
return this->GetCanvas()->IsVisible() && this->press;
|
||||
}
|
||||
|
||||
CBaseWidget::CBaseWidget(std::string _name, IWidget* parent)
|
||||
@ -61,7 +62,7 @@ CBaseWidget::CBaseWidget(std::string _name, IWidget* parent)
|
||||
|
||||
void CBaseWidget::Update() {
|
||||
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;
|
||||
}
|
||||
|
||||
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 "gui/canvas.hpp"
|
||||
#include "gui/widgets/basewindow.hpp"
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
void CBaseWindow::MoveChildren() {
|
||||
int mx = 0, my = 2;
|
||||
for (auto c : m_children) {
|
||||
@ -61,6 +60,6 @@ void CBaseWindow::Draw(int x, int y) {
|
||||
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, 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);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
|
||||
#include "gui/widgets/checkbox.hpp"
|
||||
|
||||
@ -36,9 +36,9 @@ void CCheckbox::SetWidth(int _width) {
|
||||
|
||||
void CCheckbox::Draw(int x, int y) {
|
||||
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()) {
|
||||
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 "gui/gui.hpp"
|
||||
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/widgets/dropdown.hpp"
|
||||
#include "gui/widgets/dropdownlist.hpp"
|
||||
@ -28,7 +26,7 @@
|
||||
CDropdown::CDropdown(std::string name, IWidget* parent)
|
||||
: CBaseButton(name, parent) {
|
||||
list = new CDropdownList(name + "_list", this);
|
||||
g_pGUI->GetRootWindow()->AddChild(list);
|
||||
this->GetCanvas()->AddChild(list);
|
||||
SetSize(80, 18);
|
||||
list->SetSize(80, 0);
|
||||
CBaseButton::SetCallback([this](CBaseButton*) -> void {
|
||||
@ -60,13 +58,13 @@ std::string CDropdown::ValueName(int idx) {
|
||||
void CDropdown::Draw(int x, int y) {
|
||||
auto size = GetSize();
|
||||
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_outline(x, y, size.first, size.second, g_pGUI->GetRootWindow()->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::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);
|
||||
std::pair<float, float> asize;
|
||||
g_pGUI->GetRootWindow()->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);
|
||||
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);
|
||||
}
|
||||
|
||||
void CDropdown::OnFocusLose() {
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
|
||||
#include "dropdownentry.hpp"
|
||||
|
||||
@ -36,9 +36,9 @@ CDropdownEntry::CDropdownEntry(std::string name, CDropdownList* parent, std::str
|
||||
|
||||
void CDropdownEntry::Draw(int x, int y) {
|
||||
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();
|
||||
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() {
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "gui/widgets/dropdownentry.hpp"
|
||||
#include "gui/widgets/dropdownlist.hpp"
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
|
||||
CDropdownList::CDropdownList(std::string name, CDropdown* menu, int offset)
|
||||
: CBaseContainer(name, nullptr) {
|
||||
@ -55,7 +55,7 @@ void CDropdownList::SetValue(int value) {
|
||||
void CDropdownList::Draw(int x, int y) {
|
||||
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, g_pGUI->GetRootWindow()->GetColor(), 1);
|
||||
glez::draw::rect_outline(x, y, size.first, size.second, this->GetCanvas()->GetColor(), 1);
|
||||
CBaseContainer::Draw(x, y);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
#include "gui/canvas.hpp"
|
||||
|
||||
#include "gui/widgets/keyinput.hpp"
|
||||
|
||||
@ -43,7 +43,7 @@ void CKeyInput::Draw(int x, int y) {
|
||||
glez::rgba color = glez::color::white;
|
||||
if (this->capturing) {
|
||||
key = "< PRESS >";
|
||||
color = g_pGUI->GetRootWindow()->GetColor();
|
||||
color = this->GetCanvas()->GetColor();
|
||||
} else {
|
||||
if (!Value()) {
|
||||
if (!IsFocused()) {
|
||||
@ -55,8 +55,8 @@ void CKeyInput::Draw(int x, int y) {
|
||||
}
|
||||
auto size = GetSize();
|
||||
std::pair<float, float> ss;
|
||||
g_pGUI->GetRootWindow()->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);
|
||||
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);
|
||||
}
|
||||
|
||||
void CKeyInput::SetCallback(KeyInputCallbackFn_t callback) {
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
#include "gui/widgets/slider.hpp"
|
||||
|
||||
@ -72,11 +71,11 @@ float CSlider::Value() {
|
||||
void CSlider::Update() {
|
||||
if (IsPressed()) {
|
||||
if (m_bDragInit) {
|
||||
int delta = m_nLastX - g_pGUI->GetRootWindow()->m_iMouseX;
|
||||
int delta = m_nLastX - this->GetCanvas()->m_iMouseX;
|
||||
if (delta) {
|
||||
auto abs = AbsolutePosition();
|
||||
auto size = GetSize();
|
||||
int mv = g_pGUI->GetRootWindow()->m_iMouseX - abs.first;
|
||||
int mv = this->GetCanvas()->m_iMouseX - abs.first;
|
||||
if (mv < 0)
|
||||
mv = 0;
|
||||
if (mv > size.first)
|
||||
@ -85,7 +84,7 @@ void CSlider::Update() {
|
||||
m_nSliderPos = mv;
|
||||
}
|
||||
}
|
||||
m_nLastX = g_pGUI->GetRootWindow()->m_iMouseX;
|
||||
m_nLastX = this->GetCanvas()->m_iMouseX;
|
||||
m_bDragInit = true;
|
||||
} else
|
||||
m_bDragInit = false;
|
||||
@ -94,11 +93,11 @@ void CSlider::Update() {
|
||||
void CSlider::Draw(int x, int y) {
|
||||
auto size = GetSize();
|
||||
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];
|
||||
snprintf(s, sizeof(s), "%.2f", Value());
|
||||
std::string str(s);
|
||||
std::pair<float, float> sl;
|
||||
g_pGUI->GetRootWindow()->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);
|
||||
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);
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <glez/draw.hpp>
|
||||
|
||||
#include "gui/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
#include "gui/widgets/textinput.hpp"
|
||||
|
||||
@ -37,7 +36,7 @@ bool CTextInput::ConsumesKey(CatKey key) {
|
||||
|
||||
void CTextInput::SetMaxWidth(int width) {
|
||||
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
|
||||
}
|
||||
|
||||
@ -54,30 +53,30 @@ void CTextInput::SetValue(std::string value) {
|
||||
|
||||
void CTextInput::Draw(int x, int y) {
|
||||
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 color = glez::rgba(0, 0, 0, 80);
|
||||
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_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 md = 0;
|
||||
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();
|
||||
for (int i = 0; i < value.length(); i++) {
|
||||
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)
|
||||
md = i;
|
||||
if (strsize.first + 8 > size.first)
|
||||
ml = i;
|
||||
}
|
||||
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 {
|
||||
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;
|
||||
} else {
|
||||
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]);
|
||||
} else {
|
||||
ch = input::key_names[key][0];
|
||||
|
@ -20,10 +20,10 @@
|
||||
#include <glez/draw.hpp>
|
||||
#include <sstream>
|
||||
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
#include "gui/widgets/textlabel.hpp"
|
||||
|
||||
#include "gui/canvas.hpp"
|
||||
|
||||
static std::string WordWrap(std::string& in, int max, glez::font& font) {
|
||||
std::stringstream result, line, wordstream, next;
|
||||
std::string word;
|
||||
@ -73,6 +73,17 @@ CTextLabel::CTextLabel(std::string name, IWidget* parent, std::string text, bool
|
||||
}
|
||||
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) {
|
||||
this->autosize = _autosize;
|
||||
@ -90,7 +101,7 @@ void CTextLabel::SetText(std::string text) {
|
||||
// unsigned long font_handle = Props()->GetInt("font", fonts::MENU);
|
||||
this->text = text;
|
||||
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) {
|
||||
SetSize(size.first + padding.first * 2, size.second + padding.second * 2);
|
||||
} else {
|
||||
@ -98,9 +109,9 @@ void CTextLabel::SetText(std::string text) {
|
||||
auto ms = this->max_size.first;
|
||||
SetSize(-1, size.second + padding.second * 2);
|
||||
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;
|
||||
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);
|
||||
this->text = txt;
|
||||
}
|
||||
@ -116,8 +127,8 @@ void CTextLabel::Draw(int x, int y) {
|
||||
if (this->centered) {
|
||||
auto size = GetSize();
|
||||
std::pair<float, float> ssize;
|
||||
g_pGUI->GetRootWindow()->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);
|
||||
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);
|
||||
} 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/canvas.hpp"
|
||||
#include "gui/gui.hpp"
|
||||
|
||||
CTitleBar::CTitleBar(IWidget* parent, std::string title)
|
||||
: CBaseWidget("titlebar", parent) {
|
||||
@ -35,16 +34,16 @@ CTitleBar::CTitleBar(IWidget* parent, std::string title)
|
||||
|
||||
void CTitleBar::Draw(int x, int y) {
|
||||
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;
|
||||
g_pGUI->GetRootWindow()->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);
|
||||
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);
|
||||
}
|
||||
|
||||
void CTitleBar::Update() {
|
||||
auto psize = GetParent()->GetSize();
|
||||
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);
|
||||
if (!IsPressed()) {
|
||||
m_iDraggingStage = 0;
|
||||
@ -53,11 +52,11 @@ void CTitleBar::Update() {
|
||||
if (m_iDraggingStage == 0) {
|
||||
m_iDraggingStage = 1;
|
||||
} else {
|
||||
int dx = g_pGUI->GetRootWindow()->m_iMouseX - m_nLastX;
|
||||
int dy = g_pGUI->GetRootWindow()->m_iMouseY - m_nLastY;
|
||||
int dx = this->GetCanvas()->m_iMouseX - m_nLastX;
|
||||
int dy = this->GetCanvas()->m_iMouseY - m_nLastY;
|
||||
auto offset = GetParent()->GetOffset();
|
||||
GetParent()->SetOffset(offset.first + dx, offset.second + dy);
|
||||
}
|
||||
m_nLastX = g_pGUI->GetRootWindow()->m_iMouseX;
|
||||
m_nLastY = g_pGUI->GetRootWindow()->m_iMouseY;
|
||||
m_nLastX = this->GetCanvas()->m_iMouseX;
|
||||
m_nLastY = this->GetCanvas()->m_iMouseY;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user