diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-05-08 05:16:53 +0200 | 
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-05-08 05:16:53 +0200 | 
| commit | f948d19664a395780a61ec5311ea93bb13fc7646 (patch) | |
| tree | c419e46aec2d77d74f04192e2aae4bc9dcf0886c /shutdown | |
| parent | 06671de6ad076a8978d990f3436cca4539388909 (diff) | |
| parent | 4e1b9f9de5543cfb7f513bfb42b8a275bd68efd7 (diff) | |
Merging with lp:~brandontschaefer/unity/shutdown-dialog-hi-dpi
(bzr r3794.5.1)
Diffstat (limited to 'shutdown')
| -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 | 
5 files changed, 93 insertions, 23 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_;  }; | 
