summaryrefslogtreecommitdiff
path: root/shutdown
diff options
authorBrandon Schaefer <brandontschaefer@gmail.com>2014-04-24 13:00:27 -0700
committerBrandon Schaefer <brandontschaefer@gmail.com>2014-04-24 13:00:27 -0700
commit80a1c0f4b82dd81561b2a55ae6d9cb87caafc8a8 (patch)
treef33b37d0a17f1b7f972768b7b0d02f67b41d6bad /shutdown
parentda115448947ed6c5c6caf6ba2ee491826bb653a7 (diff)
parente884c75f4b2dce2f8ef74cc91e19c4fc781114ce (diff)
* First stage of Shutdown Dialog HiDPI Support
(bzr r3788.4.1)
Diffstat (limited to 'shutdown')
-rw-r--r--shutdown/SessionButton.cpp16
-rw-r--r--shutdown/SessionButton.h1
-rw-r--r--shutdown/SessionView.cpp82
-rw-r--r--shutdown/SessionView.h6
4 files changed, 84 insertions, 21 deletions
diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp
index 2b24bd1a9..d7d0ebc05 100644
--- a/shutdown/SessionButton.cpp
+++ b/shutdown/SessionButton.cpp
@@ -23,6 +23,8 @@
#include <Nux/VLayout.h>
#include <glib/gi18n-lib.h>
+#include "unity-shared/RawPixel.h"
+
namespace unity
{
namespace session
@@ -30,9 +32,10 @@ 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);
@@ -86,6 +89,15 @@ Button::Button(Action action, NUX_FILE_LINE_DECL)
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);
+
+ normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), style::DEFAULT_TEXTURE_SIZE.CP(new_scale), true));
+ highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), style::DEFAULT_TEXTURE_SIZE.CP(new_scale), true));
+ 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);
diff --git a/shutdown/SessionButton.h b/shutdown/SessionButton.h
index 3dbd2f93c..cc5abe976 100644
--- a/shutdown/SessionButton.h
+++ b/shutdown/SessionButton.h
@@ -49,6 +49,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;
diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp
index d824f445e..43ff7edc2 100644
--- a/shutdown/SessionView.cpp
+++ b/shutdown/SessionView.cpp
@@ -20,10 +20,12 @@
#include "SessionView.h"
#include "SessionButton.h"
-#include <Nux/VLayout.h>
#include <UnityCore/GLibWrapper.h>
#include <glib/gi18n-lib.h>
+#include <unity-shared/RawPixel.h>
+#include <unity-shared/UScreen.h>
+
namespace unity
{
namespace session
@@ -31,15 +33,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 +53,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 +69,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(); });
@@ -84,6 +82,8 @@ View::View(Manager::Ptr const& manager)
if (new_mode == Mode::SHUTDOWN && !manager_->CanShutdown())
new_mode = Mode::LOGOUT;
+ UpdateEMConverter();
+
if (target != new_mode)
{
target = new_mode;
@@ -94,14 +94,50 @@ View::View(Manager::Ptr const& manager)
});
mode.changed.connect([this] (Mode m) {
+ UpdateEMConverter();
UpdateText();
Populate();
});
+ monitor.changed.connect([this] (bool changed) {
+ UpdateEMConverter();
+ });
+
+ Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &View::UpdateEMConverter));
+
+ UpdateViewSize();
UpdateText();
Populate();
}
+void View::UpdateEMConverter()
+{
+ int mouse_monitor = UScreen::GetDefault()->GetMonitorWithMouse();
+ if (monitor != mouse_monitor)
+ {
+ monitor = mouse_monitor;
+ UpdateViewSize();
+ }
+}
+
+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());
+
+ buttons_layout_->SetSpaceBetweenChildren(cv_->CP(style::BUTTONS_SPACE));
+
+ for (auto* area : buttons_layout_->GetChildren())
+ {
+ auto* button = (Button*)area;
+ button->scale = cv_->DPIScale();
+ }
+}
+
void View::UpdateText()
{
const char* message = nullptr;
@@ -176,6 +212,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 +226,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 +241,8 @@ void View::Populate()
if (manager_->CanHibernate())
{
button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);
+ button->scale = cv_->DPIScale();
+ button->scale = cv_->DPIScale();
button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));
AddButton(button);
}
@@ -210,10 +251,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 +264,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..dd7d0e6fd 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,9 @@ protected:
private:
friend class TestSessionView;
+ void UpdateEMConverter();
+ void UpdateViewSize();
+
void UpdateText();
void Populate();
void AddButton(Button*);
@@ -78,6 +83,7 @@ private:
Manager::Ptr manager_;
StaticCairoText* title_;
StaticCairoText* subtitle_;
+ nux::VLayout* main_layout_;
nux::HLayout* buttons_layout_;
nux::InputArea* key_focus_area_;
};