Thu, 04 Nov 2021 16:55:16 +0200
* Automatic background color for UI window
* Window accepts color for background
--- a/Source/Gorgon/Graphics/Color.h Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/Graphics/Color.h Thu Nov 04 16:55:16 2021 +0200 @@ -1014,6 +1014,9 @@ /// A color that is used for alternate list items Even, + /// A color that is used for main window background + Workspace, + /// User defined colors should start from this index. Some systems support user defined /// colors. User = 64
--- a/Source/Gorgon/UI/Window.cpp Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/UI/Window.cpp Thu Nov 04 16:55:16 2021 +0200 @@ -81,6 +81,17 @@ underadapter.SetFocusChangedHandler([this] { focuschangedin(underadapter); }); + + regtoken = Widgets::Registry::Changed.Register(*this, &Window::updateregistry); + } + + void Window::updateregistry() { + if(autobg) { + if(!bgimg) + bgimg = new Graphics::BlankImage; + bgimg->SetColor(Widgets::Registry::Active().Backcolor(Graphics::Color::Workspace)); + Gorgon::Window::SetBackground(static_cast<Graphics::RectangularAnimation&>(*bgimg)); + } } void Window::focuschangedin(LayerAdapter &cont) { @@ -173,6 +184,10 @@ underlayer = other.underlayer; other.Layer::Remove(*underlayer); other.underlayer = nullptr; + + bgimg = other.bgimg; + other.bgimg = nullptr; + autobg = other.autobg; other.Destroy(); @@ -213,10 +228,14 @@ Tooltips.SetContainer(*this); Tooltips.RecreateTarget(); + + regtoken = Widgets::Registry::Changed.Register(*this, &Window::updateregistry); } UI::Window &Window::operator= (UI::Window &&other) { + Widgets::Registry::Changed.Unregister(regtoken); + other.KeyEvent.Unregister(other.inputtoken); other.CharacterEvent.Unregister(other.chartoken); @@ -252,6 +271,11 @@ underlayer = other.underlayer; other.Layer::Remove(*underlayer); other.underlayer = nullptr; + + bgimg = other.bgimg; + other.bgimg = nullptr; + autobg = other.autobg; + Gorgon::Window::operator = (std::move(other)); WidgetContainer::operator = (std::move(other)); @@ -296,6 +320,8 @@ Tooltips.SetContainer(*this); Tooltips.RecreateTarget(); + + regtoken = Widgets::Registry::Changed.Register(*this, &Window::updateregistry); return *this; } @@ -318,4 +344,12 @@ return GetSize() == sz; } + + Window::~Window() { + KeyEvent.Unregister(inputtoken); + CharacterEvent.Unregister(chartoken); + Widgets::Registry::Changed.Unregister(regtoken); + delete extenderlayer; + } + } }
--- a/Source/Gorgon/UI/Window.h Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/UI/Window.h Thu Nov 04 16:55:16 2021 +0200 @@ -12,6 +12,7 @@ #include "WidgetContainer.h" #include "TooltipManager.h" +#include "../Graphics/BlankImage.h" #include <stdexcept> @@ -140,11 +141,7 @@ /// Copy constructor is not allowed Window(const Window &) = delete; - virtual ~Window() { - KeyEvent.Unregister(inputtoken); - CharacterEvent.Unregister(chartoken); - delete extenderlayer; - } + virtual ~Window(); Window(Window &&other); @@ -255,6 +252,13 @@ virtual void Destroy() override; + using Gorgon::Window::SetBackground; + + void SetBackground(const Graphics::RectangularAnimation &bg) override { + Gorgon::Window::SetBackground(bg); + autobg = false; + } + TooltipManager Tooltips = TooltipManager{*this}; using WidgetContainer::Add; @@ -266,6 +270,8 @@ virtual Gorgon::Layer &getlayer() override { return *widgetlayer; } + + void updateregistry(); decltype(KeyEvent)::Token keyinit(); @@ -285,6 +291,8 @@ UnitSize interiorsize; private: + bool autobg = true; + Graphics::BlankImage *bgimg = nullptr; bool quiting = false; LayerAdapter extenderadapter, windowadapter, baradapter, dialogadapter, underadapter; Graphics::Layer *extenderlayer = nullptr; @@ -298,6 +306,7 @@ decltype(KeyEvent)::Token inputtoken = keyinit(); //to initialize token after window got constructed decltype(CharacterEvent)::Token chartoken = charinit(); //to initialize token after window got constructed + EventToken regtoken; //to initialize token after window got constructed int spacing = 0; int unitwidth = 0;
--- a/Source/Gorgon/Widgets/Generator.h Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/Widgets/Generator.h Thu Nov 04 16:55:16 2021 +0200 @@ -736,6 +736,7 @@ {Graphics::Color::Active, {Graphics::Color::Ivory, {Graphics::Color::Charcoal, 0.8}}}, {Graphics::Color::Error, {Graphics::Color::DarkRed, {Graphics::Color::White, 0.2}}}, {Graphics::Color::Title, {Graphics::Color::DarkGreen, Graphics::Color::Transparent}}, + {Graphics::Color::Workspace, {Graphics::Color::Charcoal, {Graphics::Color::LightGrey, Graphics::Color::ElectricBlue, 0.3}}}, }; void initfontrelated();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Source/Gorgon/Widgets/Registry.cpp Thu Nov 04 16:55:16 2021 +0200 @@ -0,0 +1,8 @@ +#include "Registry.h" + +namespace Gorgon { namespace Widgets { + + + Event<void> Registry::Changed = {}; + +} }
--- a/Source/Gorgon/Widgets/Registry.h Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/Widgets/Registry.h Thu Nov 04 16:55:16 2021 +0200 @@ -86,7 +86,11 @@ /// Activates this registry to be used to provide templates void Activate() { + if(active == this) + return; + active = this; + Changed(); } static Registry &Active() { @@ -135,6 +139,9 @@ int GetUnitSize(int n) const { return n * GetUnitSize() + (n-1) * GetSpacing(); } + + /// Fired when the active registry is changed. + static Event<void> Changed; // defined in protected: /// This function should return a template for the given type. Due to
--- a/Source/Gorgon/Widgets/dir.cmake Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/Widgets/dir.cmake Thu Nov 04 16:55:16 2021 +0200 @@ -44,6 +44,7 @@ RadioButtons.h Registry.h + Registry.cpp Slider.h Scrollbar.h
--- a/Source/Gorgon/Window.cpp Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/Window.cpp Thu Nov 04 16:55:16 2021 +0200 @@ -5,6 +5,7 @@ #include "Graphics/Color.h" #include "GL/FrameBuffer.h" #include "Input/DnD.h" +#include "Graphics/BlankImage.h" #include "Config.h" @@ -290,17 +291,16 @@ SetBackground(static_cast<const Graphics::RectangularAnimation&>(value)); } + void Window::SetBackground(const Graphics::RGBAf &value) { + OwnBackground(static_cast<const Graphics::RectangularAnimation&>(*new Graphics::BlankImage(value))); + } + void Window::SetBackground(const Graphics::RectangularAnimationProvider &value) { - if(ownbg) - delete bganim; - - bganim = &value.CreateAnimation(); - ownbg = true; - redrawbg(); + OwnBackground(value.CreateAnimation()); } void Window::SetBackground(const Graphics::RectangularAnimation &value) { - if(ownbg) + if(&value != bganim && ownbg) delete bganim; bganim = &value; @@ -309,12 +309,13 @@ } void Window::OwnBackground(const Graphics::RectangularAnimation &value) { - if(ownbg) - delete bganim; + SetBackground(value); - bganim = &value; ownbg = true; - redrawbg(); + } + + void Window::OwnBackground(const Graphics::Bitmap &value) { + OwnBackground(static_cast<const Graphics::RectangularAnimation&>(value)); } void Window::RemoveBackground() { @@ -354,7 +355,6 @@ contentslayer->Remove(layer); } - void Window::deleting(Gorgon::Layer *layer) { if(layer == down) down = MouseHandler{};
--- a/Source/Gorgon/Window.h Wed Nov 03 07:09:46 2021 +0200 +++ b/Source/Gorgon/Window.h Thu Nov 04 16:55:16 2021 +0200 @@ -328,6 +328,9 @@ return pressed&&Input::Mouse::Button::X2; } + /// Sets the background color of the window. + void SetBackground(const Graphics::RGBAf &color); + /// Sets the background of the window. This background image /// will be scaled with the window automatically. void SetBackground(const Graphics::Bitmap &bg); @@ -338,14 +341,18 @@ /// Sets the background of the window. This background image /// will be scaled with the window automatically. - void SetBackground(const Graphics::RectangularAnimation &bg); + virtual void SetBackground(const Graphics::RectangularAnimation &bg); /// Sets the background of the window. This background image /// will be scaled with the window automatically. void OwnBackground(const Graphics::RectangularAnimation &bg); + /// Sets the background of the window. This background image + /// will be scaled with the window automatically. + void OwnBackground(const Graphics::Bitmap &bg); + /// Removes the background of the window. - void RemoveBackground(); + virtual void RemoveBackground(); /// Returns if the window has a background image bool HasBackground() const {
--- a/Testing/Source/Manual/GraphicsHelper.h Wed Nov 03 07:09:46 2021 +0200 +++ b/Testing/Source/Manual/GraphicsHelper.h Thu Nov 04 16:55:16 2021 +0200 @@ -64,7 +64,7 @@ bgimage = BGImage(tilesize, tilesize, colmod, colmod*3); bgimage.Prepare(); bgimage.DrawIn(l); - + int sz = 13; #ifdef WIN32 fnt.LoadFile("C:/Windows/Fonts/tahoma.ttf", sz);