diff options
| -rw-r--r-- | shutdown/SessionButton.cpp | 35 | ||||
| -rw-r--r-- | shutdown/SessionButton.h | 5 | ||||
| -rw-r--r-- | shutdown/SessionController.cpp | 2 | ||||
| -rw-r--r-- | shutdown/SessionView.cpp | 69 | ||||
| -rw-r--r-- | shutdown/SessionView.h | 5 | ||||
| -rw-r--r-- | unity-shared/UnityWindowStyle.cpp | 107 | ||||
| -rw-r--r-- | unity-shared/UnityWindowStyle.h | 46 | ||||
| -rw-r--r-- | unity-shared/UnityWindowView.cpp | 76 | ||||
| -rw-r--r-- | unity-shared/UnityWindowView.h | 7 |
9 files changed, 246 insertions, 106 deletions
diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp index 2b24bd1a9..af1f2b3f3 100644 --- a/shutdown/SessionButton.cpp +++ b/shutdown/SessionButton.cpp @@ -30,15 +30,17 @@ namespace session namespace style { - const std::string FONT = "Ubuntu Light 12"; + std::string const FONT = "Ubuntu Light 12"; - const unsigned BUTTON_SPACE = 9; + RawPixel const BUTTON_SPACE = 9_em; + RawPixel const DEFAULT_TEXTURE_SIZE = 168_em; } NUX_IMPLEMENT_OBJECT_TYPE(Button); Button::Button(Action action, NUX_FILE_LINE_DECL) : nux::View(NUX_FILE_LINE_PARAM) + , scale(1.0) , highlighted(false) , action([this] { return action_; }) , label([this] { return label_view_->GetText(); }) @@ -78,14 +80,21 @@ Button::Button(Action action, NUX_FILE_LINE_DECL) break; } - normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), -1, true)); - highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), -1, true)); + UpdateTextures(texture_prefix); auto main_layout = new nux::VLayout(); main_layout->SetContentDistribution(nux::MAJOR_POSITION_CENTER); main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE); SetLayout(main_layout); + scale.changed.connect([this, main_layout, texture_prefix] (double new_scale) { + main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE.CP(new_scale)); + label_view_->SetScale(new_scale); + + UpdateTextures(texture_prefix); + image_view_->SetTexture(highlighted ? highlight_tex_ : normal_tex_); + }); + image_view_ = new IconTexture(normal_tex_); image_view_->SetInputEventSensitivity(false); main_layout->AddView(image_view_, 1, nux::MINOR_POSITION_CENTER); @@ -111,6 +120,24 @@ Button::Button(Action action, NUX_FILE_LINE_DECL) }); } +void Button::UpdateTextures(std::string const& texture_prefix) +{ + RawPixel const texture_size = GetDefaultMaxTextureSize(texture_prefix); + + normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), texture_size.CP(scale), true)); + highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), texture_size.CP(scale), true)); +} + +RawPixel Button::GetDefaultMaxTextureSize(std::string const& texture_prefix) const +{ + nux::Size size; + auto const& texture_name = (texture_prefix + ".png"); + gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height); + RawPixel max_size = std::max(std::round(size.width * scale), std::round(size.height * scale)); + + return max_size; +} + void Button::Draw(nux::GraphicsEngine& ctx, bool force) { GetLayout()->ProcessDraw(ctx, force); diff --git a/shutdown/SessionButton.h b/shutdown/SessionButton.h index 3dbd2f93c..a25a65cdc 100644 --- a/shutdown/SessionButton.h +++ b/shutdown/SessionButton.h @@ -26,6 +26,7 @@ #include "unity-shared/IconTexture.h" #include "unity-shared/Introspectable.h" +#include "unity-shared/RawPixel.h" #include "unity-shared/StaticCairoText.h" namespace unity @@ -49,6 +50,7 @@ public: Button(Action, NUX_FILE_LINE_PROTO); + nux::Property<double> scale; nux::Property<bool> highlighted; nux::ROProperty<Action> action; nux::ROProperty<std::string> label; @@ -65,6 +67,9 @@ protected: private: friend class TestSessionButton; + void UpdateTextures(std::string const& texture_prefix); + RawPixel GetDefaultMaxTextureSize(std::string const& texture_prefix) const; + Action action_; IconTexture* image_view_; StaticCairoText* label_view_; diff --git a/shutdown/SessionController.cpp b/shutdown/SessionController.cpp index 0aa8026a3..f465a8022 100644 --- a/shutdown/SessionController.cpp +++ b/shutdown/SessionController.cpp @@ -151,6 +151,8 @@ void Controller::ConstructView() { view_->size_changed.connect([this] (nux::Area*, int, int) { int monitor = UScreen::GetDefault()->GetMonitorWithMouse(); + view_->monitor = monitor; + auto const& offset = GetOffsetPerMonitor(monitor); view_window_->SetXY(offset.x, offset.y); }); diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp index d824f445e..3414ec042 100644 --- a/shutdown/SessionView.cpp +++ b/shutdown/SessionView.cpp @@ -20,10 +20,11 @@ #include "SessionView.h" #include "SessionButton.h" -#include <Nux/VLayout.h> #include <UnityCore/GLibWrapper.h> #include <glib/gi18n-lib.h> +#include <unity-shared/RawPixel.h> + namespace unity { namespace session @@ -31,15 +32,15 @@ namespace session namespace style { - const std::string FONT = "Ubuntu Light"; - const std::string TITLE_FONT = FONT+" 15"; - const std::string SUBTITLE_FONT = FONT+" 12"; - - const unsigned LEFT_RIGHT_PADDING = 30; - const unsigned TOP_PADDING = 19; - const unsigned BOTTOM_PADDING = 12; - const unsigned MAIN_SPACE = 10; - const unsigned BUTTONS_SPACE = 20; + std::string const FONT = "Ubuntu Light"; + std::string const TITLE_FONT = FONT+" 15"; + std::string const SUBTITLE_FONT = FONT+" 12"; + + RawPixel const LEFT_RIGHT_PADDING = 30_em; + RawPixel const TOP_PADDING = 19_em; + RawPixel const BOTTOM_PADDING = 12_em; + RawPixel const MAIN_SPACE = 10_em; + RawPixel const BUTTONS_SPACE = 20_em; } NUX_IMPLEMENT_OBJECT_TYPE(View); @@ -51,18 +52,15 @@ View::View(Manager::Ptr const& manager) , key_focus_area_(this) { closable = true; - auto main_layout = new nux::VLayout(); - main_layout->SetTopAndBottomPadding(style::TOP_PADDING, style::BOTTOM_PADDING); - main_layout->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING); - main_layout->SetSpaceBetweenChildren(style::MAIN_SPACE); - SetLayout(main_layout); + main_layout_ = new nux::VLayout(); + SetLayout(main_layout_); title_ = new StaticCairoText(""); title_->SetFont(style::TITLE_FONT); title_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT); title_->SetInputEventSensitivity(false); title_->SetVisible(false); - main_layout->AddView(title_); + main_layout_->AddView(title_); subtitle_ = new StaticCairoText(""); subtitle_->SetFont(style::SUBTITLE_FONT); @@ -70,11 +68,10 @@ View::View(Manager::Ptr const& manager) subtitle_->SetInputEventSensitivity(false); subtitle_->SetLines(std::numeric_limits<int>::min()); subtitle_->SetLineSpacing(2); - main_layout->AddView(subtitle_); + main_layout_->AddView(subtitle_); buttons_layout_ = new nux::HLayout(); - buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE); - main_layout->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f); + main_layout_->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f); GetBoundingArea()->mouse_click.connect([this] (int, int, unsigned long, unsigned long) { request_close.emit(); }); @@ -98,10 +95,37 @@ View::View(Manager::Ptr const& manager) Populate(); }); + monitor.changed.connect([this] (int monitor) { + UpdateViewSize(); + }); + + Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &View::UpdateViewSize)); + + UpdateViewSize(); UpdateText(); Populate(); } +void View::UpdateViewSize() +{ + main_layout_->SetTopAndBottomPadding(cv_->CP(style::TOP_PADDING), cv_->CP(style::BOTTOM_PADDING)); + main_layout_->SetLeftAndRightPadding(cv_->CP(style::LEFT_RIGHT_PADDING)); + main_layout_->SetSpaceBetweenChildren(cv_->CP(style::MAIN_SPACE)); + + title_->SetScale(cv_->DPIScale()); + subtitle_->SetScale(cv_->DPIScale()); + + ReloadCloseButtonTexture(); + + buttons_layout_->SetSpaceBetweenChildren(cv_->CP(style::BUTTONS_SPACE)); + + for (auto* area : buttons_layout_->GetChildren()) + { + auto* button = static_cast<Button*>(area); + button->scale = cv_->DPIScale(); + } +} + void View::UpdateText() { const char* message = nullptr; @@ -176,6 +200,7 @@ void View::Populate() if (mode() == Mode::LOGOUT) { auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION); + button->scale = cv_->DPIScale(); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen)); AddButton(button); @@ -189,12 +214,14 @@ void View::Populate() if (mode() == Mode::FULL) { auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION); + button->scale = cv_->DPIScale(); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen)); AddButton(button); if (manager_->CanSuspend()) { button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION); + button->scale = cv_->DPIScale(); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend)); AddButton(button); } @@ -202,6 +229,7 @@ void View::Populate() if (manager_->CanHibernate()) { button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION); + button->scale = cv_->DPIScale(); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate)); AddButton(button); } @@ -210,10 +238,12 @@ void View::Populate() if (manager_->CanShutdown()) { auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION); + button->scale = cv_->DPIScale(); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot)); AddButton(button); button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION); + button->scale = cv_->DPIScale(); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown)); key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_; AddButton(button); @@ -221,6 +251,7 @@ void View::Populate() else if (mode() == Mode::FULL) { auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION); + button->scale = cv_->DPIScale(); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout)); AddButton(button); } diff --git a/shutdown/SessionView.h b/shutdown/SessionView.h index d91c7e2c2..3373c312c 100644 --- a/shutdown/SessionView.h +++ b/shutdown/SessionView.h @@ -22,9 +22,11 @@ #include <Nux/Nux.h> #include <Nux/View.h> +#include <Nux/VLayout.h> #include <Nux/HLayout.h> #include "UnityCore/SessionManager.h" +#include "unity-shared/EMConverter.h" #include "unity-shared/UnityWindowView.h" #include "UnityCore/SessionManager.h" @@ -71,6 +73,8 @@ protected: private: friend class TestSessionView; + void UpdateViewSize(); + void UpdateText(); void Populate(); void AddButton(Button*); @@ -78,6 +82,7 @@ private: Manager::Ptr manager_; StaticCairoText* title_; StaticCairoText* subtitle_; + nux::VLayout* main_layout_; nux::HLayout* buttons_layout_; nux::InputArea* key_focus_area_; }; diff --git a/unity-shared/UnityWindowStyle.cpp b/unity-shared/UnityWindowStyle.cpp index b7953f4fa..9fbccbe75 100644 --- a/unity-shared/UnityWindowStyle.cpp +++ b/unity-shared/UnityWindowStyle.cpp @@ -16,82 +16,105 @@ * * Authored by: Jason Smith <jason.smith@canonical.com> * Marco Trevisan <marco.trevisan@canonical.com> + * Brandon Schaefer <brandon.schaefer@canonical.com> */ +#include <NuxCore/Logger.h> + #include "UnityWindowStyle.h" #include "config.h" -namespace unity { -namespace ui { - -UnityWindowStyle::UnityWindowStyle() +namespace unity { - background_top_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_top.png", -1, true)); - background_left_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_left.png", -1, true)); - background_corner_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_corner.png", -1, true)); -} - -UnityWindowStyle::Ptr const& UnityWindowStyle::Get() +namespace ui { - // This is set only the first time; - static UnityWindowStyle::Ptr instance(new UnityWindowStyle()); - return instance; +namespace +{ + const char* const SWITCHER_TOP = PKGDATADIR"/switcher_top.png"; + const char* const SWITCHER_LEFT = PKGDATADIR"/switcher_left.png"; + const char* const SWITCHER_CORNER = PKGDATADIR"/switcher_corner.png"; + + const char* const DIALOG_CLOSE = PKGDATADIR"/dialog_close.png"; + const char* const DIALOG_HIGHLIGHT = PKGDATADIR"/dialog_close_highlight.png"; + const char* const DIALOG_PRESS = PKGDATADIR"/dialog_close_press.png"; + + double const DEFAULT_SCALE = 1.0; } -int UnityWindowStyle::GetBorderSize() const +DECLARE_LOGGER(logger, "unity.ui.unity.window.style"); + +UnityWindowStyle::UnityWindowStyle() { - return 30; // as measured from textures + LoadAllTextureInScale(DEFAULT_SCALE); } -int UnityWindowStyle::GetInternalOffset() const +void UnityWindowStyle::LoadAllTextureInScale(double scale) { - return 20; + auto& window_textures = unity_window_textures_[scale]; + + window_textures[unsigned(WindowTextureType::BACKGROUND_TOP)] = LoadTexture(scale, SWITCHER_TOP); + window_textures[unsigned(WindowTextureType::BACKGROUND_LEFT)] = LoadTexture(scale, SWITCHER_LEFT); + window_textures[unsigned(WindowTextureType::BACKGROUND_CORNER)] = LoadTexture(scale, SWITCHER_CORNER); + + window_textures[unsigned(WindowTextureType::CLOSE_ICON)] = LoadTexture(scale, DIALOG_CLOSE); + window_textures[unsigned(WindowTextureType::CLOSE_ICON_HIGHLIGHTED)] = LoadTexture(scale, DIALOG_HIGHLIGHT); + window_textures[unsigned(WindowTextureType::CLOSE_ICON_PRESSED)] = LoadTexture(scale, DIALOG_PRESS); } -int UnityWindowStyle::GetCloseButtonPadding() const +nux::BaseTexture* UnityWindowStyle::LoadTexture(double scale, const char* const texture_name) const { - return 3; + RawPixel max_size = GetDefaultMaxTextureSize(texture_name); + return nux::CreateTexture2DFromFile(texture_name, max_size.CP(scale), true); } -UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIcon() +RawPixel UnityWindowStyle::GetDefaultMaxTextureSize(const char* const texture_name) const { - if (!close_icon_) - close_icon_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close.png", -1, true)); + nux::Size size; + gdk_pixbuf_get_file_info(texture_name, &size.width, &size.height); + RawPixel max_size = std::max(std::round(size.width), std::round(size.height)); - return close_icon_; + return max_size; } -UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIconHighligted() +UnityWindowStyle::Ptr const& UnityWindowStyle::Get() { - if (!close_icon_highlighted_) - close_icon_highlighted_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close_highlight.png", -1, true)); - - return close_icon_highlighted_; + // This is set only the first time; + static UnityWindowStyle::Ptr instance(new UnityWindowStyle()); + return instance; } -UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIconPressed() +int UnityWindowStyle::GetBorderSize() const { - if (!close_icon_pressed_) - close_icon_pressed_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close_press.png", -1, true)); - - return close_icon_pressed_; + return 30; // as measured from textures } -UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundTop() const +int UnityWindowStyle::GetInternalOffset() const { - return background_top_; + return 20; } -UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundLeft() const +int UnityWindowStyle::GetCloseButtonPadding() const { - return background_left_; + return 3; } -UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundCorner() const +UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetTexture(double scale, WindowTextureType const& type) { - return background_corner_; + auto it = unity_window_textures_.find(scale); + if (it == unity_window_textures_.end()) + { + LoadAllTextureInScale(scale); + + it = unity_window_textures_.find(scale); + if (it == unity_window_textures_.end()) + { + LOG_ERROR(logger) << "Failed to create unity window style textures, for scale size: " << scale; + return BaseTexturePtr(nullptr); + } + } + + return it->second[unsigned(type)]; } - -} -} +} // namespace ui +} // namespace unity diff --git a/unity-shared/UnityWindowStyle.h b/unity-shared/UnityWindowStyle.h index 22c0b1e14..cc04f7d5e 100644 --- a/unity-shared/UnityWindowStyle.h +++ b/unity-shared/UnityWindowStyle.h @@ -16,6 +16,7 @@ * * Authored by: Jason Smith <jason.smith@canonical.com> * Marco Trevisan <marco.trevisan@canonical.com> + * Brandon Schaefer <brandon.schaefer@canonical.com> */ #ifndef UNITYWINDOWSTYLE_H @@ -24,8 +25,23 @@ #include <sigc++/sigc++.h> #include <Nux/Nux.h> -namespace unity { -namespace ui { +#include "RawPixel.h" + +namespace unity +{ +namespace ui +{ + +enum class WindowTextureType : unsigned +{ + BACKGROUND_TOP, + BACKGROUND_LEFT, + BACKGROUND_CORNER, + CLOSE_ICON, + CLOSE_ICON_HIGHLIGHTED, + CLOSE_ICON_PRESSED, + Size +}; class UnityWindowStyle { @@ -35,29 +51,25 @@ public: static UnityWindowStyle::Ptr const& Get(); - BaseTexturePtr GetCloseIcon(); - BaseTexturePtr GetCloseIconHighligted(); - BaseTexturePtr GetCloseIconPressed(); + BaseTexturePtr GetTexture(double scale, WindowTextureType const& type); int GetCloseButtonPadding() const; - - BaseTexturePtr GetBackgroundTop() const; - BaseTexturePtr GetBackgroundLeft() const; - BaseTexturePtr GetBackgroundCorner() const; int GetBorderSize() const; int GetInternalOffset() const; private: UnityWindowStyle(); - BaseTexturePtr background_top_; - BaseTexturePtr background_left_; - BaseTexturePtr background_corner_; - BaseTexturePtr close_icon_; - BaseTexturePtr close_icon_highlighted_; - BaseTexturePtr close_icon_pressed_; + void ReloadIcons(); + void LoadAllTextureInScale(double scale); + nux::BaseTexture* LoadTexture(double scale, const char* const texture_name) const; + RawPixel GetDefaultMaxTextureSize(const char* const texture_name) const; + + typedef std::array<BaseTexturePtr, size_t(WindowTextureType::Size)> UnityWindowTextures; + std::unordered_map<double, UnityWindowTextures> unity_window_textures_; + }; -} -} +} // namespace ui +} // namespace unity #endif diff --git a/unity-shared/UnityWindowView.cpp b/unity-shared/UnityWindowView.cpp index 61124578f..c2bf758e2 100644 --- a/unity-shared/UnityWindowView.cpp +++ b/unity-shared/UnityWindowView.cpp @@ -32,6 +32,8 @@ UnityWindowView::UnityWindowView(NUX_FILE_LINE_DECL) : View(NUX_FILE_LINE_PARAM) , style(UnityWindowStyle::Get()) , closable(false) + , monitor(0) + , cv_(Settings::Instance().em()) , internal_layout_(nullptr) , bg_helper_(this) { @@ -45,6 +47,10 @@ UnityWindowView::UnityWindowView(NUX_FILE_LINE_DECL) return false; }); + monitor.changed.connect([this] (int new_monitor){ + cv_ = Settings::Instance().em(new_monitor); + }); + live_background = false; closable.changed.connect(sigc::mem_fun(this, &UnityWindowView::OnClosableChanged)); @@ -109,6 +115,11 @@ nux::Area* UnityWindowView::FindKeyFocusArea(unsigned etype, unsigned long key_c return View::FindKeyFocusArea(etype, key_code, modifiers); } +void UnityWindowView::ReloadCloseButtonTexture() +{ + OnClosableChanged(closable); +} + void UnityWindowView::OnClosableChanged(bool closable) { if (!closable) @@ -117,34 +128,39 @@ void UnityWindowView::OnClosableChanged(bool closable) return; } - auto const& texture = style()->GetCloseIcon(); - int padding = style()->GetCloseButtonPadding(); + auto const& texture = style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON); + int padding_raw = style()->GetCloseButtonPadding(); + int padding = cv_->CP(padding_raw); + close_button_ = new IconTexture(texture); close_button_->SetBaseXY(padding, padding); close_button_->SetParentObject(this); close_button_->mouse_enter.connect([this](int, int, unsigned long, unsigned long) { if (close_button_->IsMouseOwner()) - close_button_->SetTexture(style()->GetCloseIconPressed()); + close_button_->SetTexture(style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON_PRESSED)); else - close_button_->SetTexture(style()->GetCloseIconHighligted()); + close_button_->SetTexture(style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON_HIGHLIGHTED)); }); close_button_->mouse_leave.connect([this](int, int, unsigned long, unsigned long) { - close_button_->SetTexture(style()->GetCloseIcon()); + close_button_->SetTexture(style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON)); }); close_button_->mouse_down.connect([this](int, int, unsigned long, unsigned long) { - close_button_->SetTexture(style()->GetCloseIconPressed()); + close_button_->SetTexture(style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON_PRESSED)); }); close_button_->mouse_up.connect([this](int, int, unsigned long, unsigned long) { bool inside = close_button_->IsMouseInside(); - close_button_->SetTexture(inside ? style()->GetCloseIconHighligted() : style()->GetCloseIcon()); + if (inside) + close_button_->SetTexture(style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON_HIGHLIGHTED)); + else + close_button_->SetTexture(style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON)); }); close_button_->mouse_click.connect([this](int, int, unsigned long, unsigned long) { - close_button_->SetTexture(style()->GetCloseIcon()); + close_button_->SetTexture(style()->GetTexture(cv_->DPIScale(), WindowTextureType::CLOSE_ICON)); request_close.emit(); }); @@ -155,7 +171,8 @@ bool UnityWindowView::SetLayout(nux::Layout* layout) { if (layout && layout->IsLayout()) { - int offset = style()->GetInternalOffset(); + int offset_raw = style()->GetInternalOffset(); + int offset = cv_->CP(offset_raw); // We wrap the internal layout adding some padding, so that inherited classes // can ignore the offsets we define here. @@ -180,7 +197,9 @@ nux::Layout* UnityWindowView::GetLayout() nux::Geometry UnityWindowView::GetInternalBackground() { - int offset = style()->GetInternalOffset(); + int offset_raw = style()->GetInternalOffset(); + int offset = cv_->CP(offset_raw); + return GetBackgroundGeometry().GetExpand(-offset, -offset); } @@ -330,7 +349,11 @@ void UnityWindowView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo) { - int border = style()->GetBorderSize(); + int border_raw = style()->GetBorderSize(); + int border = cv_->CP(border_raw); + float scale = cv_->DPIScale(); + + auto background_corner_textrue = style()->GetTexture(scale, WindowTextureType::BACKGROUND_CORNER)->GetDeviceTexture(); GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); @@ -344,7 +367,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.u1 = border; texxform.v1 = border; GfxContext.QRP_1Tex (geo.x, geo.y, - border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White); + border, border, background_corner_textrue, texxform, nux::color::White); // Draw TOP-RIGHT CORNER texxform.u0 = 0; @@ -354,7 +377,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.flip_u_coord = true; texxform.flip_v_coord = false; GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y, - border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White); + border, border, background_corner_textrue, texxform, nux::color::White); // Draw BOTTOM-LEFT CORNER texxform.u0 = 0; @@ -364,7 +387,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.flip_u_coord = false; texxform.flip_v_coord = true; GfxContext.QRP_1Tex (geo.x, geo.y + geo.height - border, - border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White); + border, border, background_corner_textrue, texxform, nux::color::White); // Draw BOTTOM-RIGHT CORNER texxform.u0 = 0; @@ -374,10 +397,13 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.flip_u_coord = true; texxform.flip_v_coord = true; GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + geo.height - border, - border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White); + border, border, background_corner_textrue, texxform, nux::color::White); - int top_width = style()->GetBackgroundTop()->GetWidth(); - int top_height = style()->GetBackgroundTop()->GetHeight(); + auto background_top = style()->GetTexture(scale, WindowTextureType::BACKGROUND_TOP); + int top_width_raw = background_top->GetWidth(); + int top_height_raw = background_top->GetHeight(); + int top_width = cv_->CP(top_width_raw); + int top_height = cv_->CP(top_height_raw); // Draw TOP BORDER texxform.u0 = 0; @@ -386,7 +412,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.v1 = top_height; texxform.flip_u_coord = false; texxform.flip_v_coord = false; - GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White); + GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, background_top->GetDeviceTexture(), texxform, nux::color::White); // Draw BOTTOM BORDER texxform.u0 = 0; @@ -395,11 +421,13 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.v1 = top_height; texxform.flip_u_coord = false; texxform.flip_v_coord = true; - GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White); - + GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, background_top->GetDeviceTexture(), texxform, nux::color::White); - int left_width = style()->GetBackgroundLeft()->GetWidth(); - int left_height = style()->GetBackgroundLeft()->GetHeight(); + auto background_left = style()->GetTexture(scale, WindowTextureType::BACKGROUND_LEFT); + int left_width_raw = background_left->GetWidth(); + int left_height_raw = background_left->GetHeight(); + int left_width = cv_->CP(left_width_raw); + int left_height = cv_->CP(left_height_raw); // Draw LEFT BORDER texxform.u0 = 0; @@ -408,7 +436,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.v1 = left_height; texxform.flip_u_coord = false; texxform.flip_v_coord = false; - GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White); + GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, background_left->GetDeviceTexture(), texxform, nux::color::White); // Draw RIGHT BORDER texxform.u0 = 0; @@ -417,7 +445,7 @@ void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geome texxform.v1 = left_height; texxform.flip_u_coord = true; texxform.flip_v_coord = false; - GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White); + GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, background_left->GetDeviceTexture(), texxform, nux::color::White); GfxContext.GetRenderStates().SetBlend(false); } diff --git a/unity-shared/UnityWindowView.h b/unity-shared/UnityWindowView.h index 9e2042a09..f0219bbef 100644 --- a/unity-shared/UnityWindowView.h +++ b/unity-shared/UnityWindowView.h @@ -23,6 +23,8 @@ #include "unity-shared/BackgroundEffectHelper.h" #include "unity-shared/IconTexture.h" +#include "unity-shared/UnitySettings.h" + #include "Introspectable.h" #include "UnityWindowStyle.h" #include <sigc++/sigc++.h> @@ -41,6 +43,7 @@ public: nux::Property<nux::Color> background_color; nux::Property<UnityWindowStyle::Ptr> style; nux::Property<bool> closable; + nux::Property<int> monitor; UnityWindowView(NUX_FILE_LINE_PROTO); virtual ~UnityWindowView(); @@ -64,10 +67,14 @@ protected: virtual nux::Geometry GetBlurredBackgroundGeometry(); void SetBackgroundHelperGeometryGetter(BackgroundEffectHelper::GeometryGetterFunc const&); + void ReloadCloseButtonTexture(); + // Introspectable methods std::string GetName() const; void AddProperties(debug::IntrospectionData&); + EMConverter::Ptr cv_; + private: friend class TestUnityWindowView; |
