Merge lp:~brandontschaefer/unity/shutdown-dialog-hi-dpi into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3810
Proposed branch: lp:~brandontschaefer/unity/shutdown-dialog-hi-dpi
Merge into: lp:unity
Diff against target: 1114 lines (+357/-166)
16 files modified
launcher/SwitcherView.cpp (+22/-15)
launcher/SwitcherView.h (+3/-3)
shortcuts/ShortcutController.cpp (+3/-5)
shutdown/SessionButton.cpp (+30/-5)
shutdown/SessionButton.h (+5/-0)
shutdown/SessionController.cpp (+2/-0)
shutdown/SessionView.cpp (+45/-18)
shutdown/SessionView.h (+5/-0)
tests/test_switcher_view.cpp (+1/-1)
tests/test_unity_window_view.cpp (+9/-9)
unity-shared/EMConverter.cpp (+2/-2)
unity-shared/RawPixel.cpp (+1/-1)
unity-shared/UnityWindowStyle.cpp (+135/-62)
unity-shared/UnityWindowStyle.h (+35/-20)
unity-shared/UnityWindowView.cpp (+53/-25)
unity-shared/UnityWindowView.h (+6/-0)
To merge this branch: bzr merge lp:~brandontschaefer/unity/shutdown-dialog-hi-dpi
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+217144@code.launchpad.net

Commit message

ShutdownView: Scale up the Buttons and Text plus Borders of the UnityWindowView.

Description of the change

Scale up the Buttons/Text of the shutdown dialog. Still need to do the border it self.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

22 + RawPixel const DEFAULT_TEXTURE_SIZE = 168_em;

Mh, I don't like much the texture size defined here, considering they might change, but you can just do (without adding extra computation cost, since this will happen anyway)

nux::Size size;
auto const& texture_name = (texture_prefix + ".png");
gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height);
int max_size = std::max(std::round(size.width * scale), std::round(size.height * scale));
normal_tex_.Adopt(nux::CreateTexture2DFromFile(texture_name.c_str(), max_size, true));

Make sure you intialize the scale in SessionButton.

184 + auto* button = (Button*)area;

A static_cast would be nicer

145 + UpdateEMConverter();

I think you only need UpdateViewSize there, since the mode don't affect the monitor, but indeed might change the contents.

161 +void View::UpdateEMConverter()
162 +{
163 + int mouse_monitor = UScreen::GetDefault()->GetMonitorWithMouse();
164 + if (monitor != mouse_monitor)
165 + {
166 + monitor = mouse_monitor;
167 + UpdateViewSize();
168 + }
169 +}

I think you should get rid of this, just calling UpdateViewSize when the em converter changes.

Also, monitor variable should not be set by SessionView but by SessionController.
The view should not care about positioning itself.

219 + button->scale = cv_->DPIScale();
220 + button->scale = cv_->DPIScale();

Duplicated?

Finally, from a test run I'm getting these issues:
1) the title/subtitle text is not resized here (I don't see why, since it seems you're setting the scale properly)
2) Changing the scale value, when the view is hidden doesn't make it to be update once I request a new shutdown.

review: Needs Fixing
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

> 22 + RawPixel const DEFAULT_TEXTURE_SIZE = 168_em;
>
> Mh, I don't like much the texture size defined here, considering they might
> change, but you can just do (without adding extra computation cost, since this
> will happen anyway)

Done.

>
> nux::Size size;
> auto const& texture_name = (texture_prefix + ".png");
> gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height);
> int max_size = std::max(std::round(size.width * scale), std::round(size.height
> * scale));
> normal_tex_.Adopt(nux::CreateTexture2DFromFile(texture_name.c_str(), max_size,
> true));
>

Done.

> Make sure you intialize the scale in SessionButton.
>
> 184 + auto* button = (Button*)area;
>
> A static_cast would be nicer
>

Done.

> 145 + UpdateEMConverter();
>
> I think you only need UpdateViewSize there, since the mode don't affect the
> monitor, but indeed might change the contents.
>
> 161 +void View::UpdateEMConverter()
> 162 +{
> 163 + int mouse_monitor = UScreen::GetDefault()->GetMonitorWithMouse();
> 164 + if (monitor != mouse_monitor)
> 165 + {
> 166 + monitor = mouse_monitor;
> 167 + UpdateViewSize();
> 168 + }
> 169 +}
>
> I think you should get rid of this, just calling UpdateViewSize when the em
> converter changes.
>

Done.

> Also, monitor variable should not be set by SessionView but by
> SessionController.
> The view should not care about positioning itself.
>

Done.

> 219 + button->scale = cv_->DPIScale();
> 220 + button->scale = cv_->DPIScale();
>
> Duplicated?
>

Yup, fixed.

> Finally, from a test run I'm getting these issues:
> 1) the title/subtitle text is not resized here (I don't see why, since it
> seems you're setting the scale properly)
> 2) Changing the scale value, when the view is hidden doesn't make it to be
> update once I request a new shutdown.

Tests are passing here, if you could give those another go... Ill attempt a few more times. Thanks!

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ops, it seems you're touching also ApplicationLauncherIcon.cpp, due to mergig with other fix... :)

26 + std::string const FONT = "Ubuntu Light 12";

I would have preferred if you left the const TYPE as discussed...

42 + , texture_size_(-1)
 GetDefaultMaxTextureSize(texture_prefix);

The gdk_pixbuf_get_file_info is cached anyway, so imho you don't need to track the texture_size_... I'd just make GetDefaultMaxTextureSize to return a RawPixel. Otherwise, change the Get prefix, as it might imply it would return something.

156 +#include <unity-shared/UScreen.h>

I guess you don't need that anymore, right?

155 +#include <unity-shared/RawPixel.h>
Also this one is now implicit by including the SessionButton

225 + monitor.changed.connect([this] (bool changed) {

Not really a bug as bool's are int's, but that should be an (int monitor) :)

Running it, now works properly, but I think that at this point we should also scale the Close button, as it might be very tiny on HiDpi monitors (and at this point borders as well).

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ah, I just recalled... Can you ensure that this merges cleanly with lp:~andyrock/unity/lp-1281058/+merge/215331?

If it doesn't I guess it's better if you resubmit the proposal with that branch as prerequisite...

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

> Ops, it seems you're touching also ApplicationLauncherIcon.cpp, due to mergig
> with other fix... :)
>
> 26 + std::string const FONT = "Ubuntu Light 12";
>
> I would have preferred if you left the const TYPE as discussed...
>
>
> 42 + , texture_size_(-1)
> GetDefaultMaxTextureSize(texture_prefix);
>
> The gdk_pixbuf_get_file_info is cached anyway, so imho you don't need to track
> the texture_size_... I'd just make GetDefaultMaxTextureSize to return a
> RawPixel. Otherwise, change the Get prefix, as it might imply it would return
> something.
>

Fixed.

> 156 +#include <unity-shared/UScreen.h>
>
> I guess you don't need that anymore, right?

Fixed.

>
> 155 +#include <unity-shared/RawPixel.h>
> Also this one is now implicit by including the SessionButton

Still best to keep the header there.

>
> 225 + monitor.changed.connect([this] (bool changed) {
>
> Not really a bug as bool's are int's, but that should be an (int monitor) :)
>

Fixed.

> Running it, now works properly, but I think that at this point we should also
> scale the Close button, as it might be very tiny on HiDpi monitors (and at
> this point borders as well).

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

And it merges cleanly with andyrocks branch

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ok, I think we're done :)

You know, I would have loved to get also the invalidated textures to be cleaned up, but that's still a corner case, that won't hit most of people (unless they don't change the scale settings), so I'm fine with this.
Thanks!

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Even better! :)

Approve²

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/SwitcherView.cpp'
--- launcher/SwitcherView.cpp 2014-03-25 19:07:36 +0000
+++ launcher/SwitcherView.cpp 2014-05-14 15:52:49 +0000
@@ -37,7 +37,7 @@
3737
38namespace38namespace
39{39{
40 unsigned int const VERTICAL_PADDING = 45;40 RawPixel const VERTICAL_PADDING = 45_em;
41 unsigned int const SPREAD_OFFSET = 100;41 unsigned int const SPREAD_OFFSET = 100;
42 unsigned int const EXTRA_ICON_SPACE = 10;42 unsigned int const EXTRA_ICON_SPACE = 10;
43 unsigned int const MAX_DIRECTIONS_CHANGED = 3;43 unsigned int const MAX_DIRECTIONS_CHANGED = 3;
@@ -52,10 +52,9 @@
52 , icon_size(128)52 , icon_size(128)
53 , minimum_spacing(10)53 , minimum_spacing(10)
54 , tile_size(150)54 , tile_size(150)
55 , vertical_size(tile_size + VERTICAL_PADDING * 2)55 , vertical_size(tile_size + VERTICAL_PADDING.CP(scale()) * 2)
56 , text_size(15)56 , text_size(15)
57 , animation_length(250)57 , animation_length(250)
58 , monitor(-1)
59 , spread_size(3.5f)58 , spread_size(3.5f)
60 , icon_renderer_(renderer)59 , icon_renderer_(renderer)
61 , text_view_(new StaticCairoText(""))60 , text_view_(new StaticCairoText(""))
@@ -73,8 +72,9 @@
73 text_view_->SetTextColor(nux::color::White);72 text_view_->SetTextColor(nux::color::White);
74 text_view_->SetFont("Ubuntu Bold 10");73 text_view_->SetFont("Ubuntu Bold 10");
7574
76 icon_size.changed.connect (sigc::mem_fun (this, &SwitcherView::OnIconSizeChanged));75 icon_size.changed.connect(sigc::mem_fun(this, &SwitcherView::OnIconSizeChanged));
77 tile_size.changed.connect (sigc::mem_fun (this, &SwitcherView::OnTileSizeChanged));76 tile_size.changed.connect(sigc::mem_fun(this, &SwitcherView::OnTileSizeChanged));
77 scale.changed.connect(sigc::mem_fun(this, &SwitcherView::OnScaleChanged));
7878
79 mouse_move.connect (sigc::mem_fun(this, &SwitcherView::RecvMouseMove));79 mouse_move.connect (sigc::mem_fun(this, &SwitcherView::RecvMouseMove));
80 mouse_down.connect (sigc::mem_fun(this, &SwitcherView::RecvMouseDown));80 mouse_down.connect (sigc::mem_fun(this, &SwitcherView::RecvMouseDown));
@@ -164,15 +164,20 @@
164 text_view_->SetText(model->Selection()->tooltip_text(), true);164 text_view_->SetText(model->Selection()->tooltip_text(), true);
165}165}
166166
167void SwitcherView::OnIconSizeChanged (int size)167void SwitcherView::OnIconSizeChanged(int size)
168{168{
169 icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);169 icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);
170}170}
171171
172void SwitcherView::OnTileSizeChanged (int size)172void SwitcherView::OnTileSizeChanged(int size)
173{173{
174 icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);174 icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);
175 vertical_size = tile_size + VERTICAL_PADDING * 2;175 vertical_size = tile_size + VERTICAL_PADDING.CP(scale()) * 2;
176}
177
178void SwitcherView::OnScaleChanged(double scale)
179{
180 vertical_size = tile_size + VERTICAL_PADDING.CP(scale) * 2;
176}181}
177182
178void SwitcherView::StartAnimation()183void SwitcherView::StartAnimation()
@@ -699,7 +704,10 @@
699 background_geo.height = vertical_size;704 background_geo.height = vertical_size;
700705
701 if (text_view_->IsVisible())706 if (text_view_->IsVisible())
707 {
702 background_geo.height += text_size;708 background_geo.height += text_size;
709 text_view_->SetBaseY(background_geo.y + background_geo.height - VERTICAL_PADDING.CP(scale()));
710 }
703711
704 if (model_)712 if (model_)
705 {713 {
@@ -953,7 +961,6 @@
953 if (text_view_->IsVisible())961 if (text_view_->IsVisible())
954 {962 {
955 nux::GetPainter().PushPaintLayerStack();963 nux::GetPainter().PushPaintLayerStack();
956 text_view_->SetBaseY(last_background_.y + last_background_.height - 45);
957 text_view_->Draw(GfxContext, force_draw);964 text_view_->Draw(GfxContext, force_draw);
958 nux::GetPainter().PopPaintLayerStack();965 nux::GetPainter().PopPaintLayerStack();
959 }966 }
960967
=== modified file 'launcher/SwitcherView.h'
--- launcher/SwitcherView.h 2014-03-25 19:07:36 +0000
+++ launcher/SwitcherView.h 2014-05-14 15:52:49 +0000
@@ -65,7 +65,6 @@
65 nux::Property<int> vertical_size;65 nux::Property<int> vertical_size;
66 nux::Property<int> text_size;66 nux::Property<int> text_size;
67 nux::Property<int> animation_length;67 nux::Property<int> animation_length;
68 nux::Property<int> monitor;
69 nux::Property<double> spread_size;68 nux::Property<double> spread_size;
7069
71 void SkipAnimation();70 void SkipAnimation();
@@ -135,8 +134,9 @@
135 void OnDetailSelectionChanged (bool detail);134 void OnDetailSelectionChanged (bool detail);
136 void OnDetailSelectionIndexChanged (unsigned int index);135 void OnDetailSelectionIndexChanged (unsigned int index);
137136
138 void OnIconSizeChanged (int size);137 void OnIconSizeChanged(int size);
139 void OnTileSizeChanged (int size);138 void OnTileSizeChanged(int size);
139 void OnScaleChanged(double scale);
140140
141 nux::Geometry UpdateRenderTargets(float progress);141 nux::Geometry UpdateRenderTargets(float progress);
142 void ResizeRenderTargets(nux::Geometry const& layout_geo, float progress);142 void ResizeRenderTargets(nux::Geometry const& layout_geo, float progress);
143143
=== modified file 'shortcuts/ShortcutController.cpp'
--- shortcuts/ShortcutController.cpp 2014-04-05 20:09:17 +0000
+++ shortcuts/ShortcutController.cpp 2014-05-14 15:52:49 +0000
@@ -75,9 +75,7 @@
75 if (Visible())75 if (Visible())
76 {76 {
77 model->Fill();77 model->Fill();
78 auto uscreen = UScreen::GetDefault();78 auto const& offset = GetOffsetPerMonitor(view_->monitor());
79 int monitor = uscreen->GetMonitorAtPosition(view_window_->GetX(), view_window_->GetX());
80 auto const& offset = GetOffsetPerMonitor(monitor);
8179
82 if (offset.x < 0 || offset.y < 0)80 if (offset.x < 0 || offset.y < 0)
83 {81 {
@@ -110,8 +108,8 @@
110 modeller_->GetCurrentModel()->Fill();108 modeller_->GetCurrentModel()->Fill();
111 EnsureView();109 EnsureView();
112110
113 int monitor = UScreen::GetDefault()->GetMonitorWithMouse();111 view_->monitor = UScreen::GetDefault()->GetMonitorWithMouse();
114 auto const& offset = GetOffsetPerMonitor(monitor);112 auto const& offset = GetOffsetPerMonitor(view_->monitor());
115113
116 if (offset.x < 0 || offset.y < 0)114 if (offset.x < 0 || offset.y < 0)
117 return false;115 return false;
118116
=== modified file 'shutdown/SessionButton.cpp'
--- shutdown/SessionButton.cpp 2014-02-25 01:07:06 +0000
+++ shutdown/SessionButton.cpp 2014-05-14 15:52:49 +0000
@@ -30,15 +30,15 @@
3030
31namespace style31namespace style
32{32{
33 const std::string FONT = "Ubuntu Light 12";33 std::string const FONT = "Ubuntu Light 12";
3434 RawPixel const BUTTON_SPACE = 9_em;
35 const unsigned BUTTON_SPACE = 9;
36}35}
3736
38NUX_IMPLEMENT_OBJECT_TYPE(Button);37NUX_IMPLEMENT_OBJECT_TYPE(Button);
3938
40Button::Button(Action action, NUX_FILE_LINE_DECL)39Button::Button(Action action, NUX_FILE_LINE_DECL)
41 : nux::View(NUX_FILE_LINE_PARAM)40 : nux::View(NUX_FILE_LINE_PARAM)
41 , scale(1.0)
42 , highlighted(false)42 , highlighted(false)
43 , action([this] { return action_; })43 , action([this] { return action_; })
44 , label([this] { return label_view_->GetText(); })44 , label([this] { return label_view_->GetText(); })
@@ -78,14 +78,21 @@
78 break;78 break;
79 }79 }
8080
81 normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), -1, true));81 UpdateTextures(texture_prefix);
82 highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), -1, true));
8382
84 auto main_layout = new nux::VLayout();83 auto main_layout = new nux::VLayout();
85 main_layout->SetContentDistribution(nux::MAJOR_POSITION_CENTER);84 main_layout->SetContentDistribution(nux::MAJOR_POSITION_CENTER);
86 main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE);85 main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE);
87 SetLayout(main_layout);86 SetLayout(main_layout);
8887
88 scale.changed.connect([this, main_layout, texture_prefix] (double new_scale) {
89 main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE.CP(new_scale));
90 label_view_->SetScale(new_scale);
91
92 UpdateTextures(texture_prefix);
93 image_view_->SetTexture(highlighted ? highlight_tex_ : normal_tex_);
94 });
95
89 image_view_ = new IconTexture(normal_tex_);96 image_view_ = new IconTexture(normal_tex_);
90 image_view_->SetInputEventSensitivity(false);97 image_view_->SetInputEventSensitivity(false);
91 main_layout->AddView(image_view_, 1, nux::MINOR_POSITION_CENTER);98 main_layout->AddView(image_view_, 1, nux::MINOR_POSITION_CENTER);
@@ -111,6 +118,24 @@
111 });118 });
112}119}
113120
121void Button::UpdateTextures(std::string const& texture_prefix)
122{
123 RawPixel const texture_size = GetDefaultMaxTextureSize(texture_prefix);
124
125 normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), texture_size.CP(scale), true));
126 highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), texture_size.CP(scale), true));
127}
128
129RawPixel Button::GetDefaultMaxTextureSize(std::string const& texture_prefix) const
130{
131 nux::Size size;
132 auto const& texture_name = (texture_prefix + ".png");
133 gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height);
134 RawPixel max_size = std::max(size.width, size.height);
135
136 return max_size;
137}
138
114void Button::Draw(nux::GraphicsEngine& ctx, bool force)139void Button::Draw(nux::GraphicsEngine& ctx, bool force)
115{140{
116 GetLayout()->ProcessDraw(ctx, force);141 GetLayout()->ProcessDraw(ctx, force);
117142
=== modified file 'shutdown/SessionButton.h'
--- shutdown/SessionButton.h 2014-02-25 01:07:06 +0000
+++ shutdown/SessionButton.h 2014-05-14 15:52:49 +0000
@@ -26,6 +26,7 @@
2626
27#include "unity-shared/IconTexture.h"27#include "unity-shared/IconTexture.h"
28#include "unity-shared/Introspectable.h"28#include "unity-shared/Introspectable.h"
29#include "unity-shared/RawPixel.h"
29#include "unity-shared/StaticCairoText.h"30#include "unity-shared/StaticCairoText.h"
3031
31namespace unity32namespace unity
@@ -49,6 +50,7 @@
4950
50 Button(Action, NUX_FILE_LINE_PROTO);51 Button(Action, NUX_FILE_LINE_PROTO);
5152
53 nux::Property<double> scale;
52 nux::Property<bool> highlighted;54 nux::Property<bool> highlighted;
53 nux::ROProperty<Action> action;55 nux::ROProperty<Action> action;
54 nux::ROProperty<std::string> label;56 nux::ROProperty<std::string> label;
@@ -65,6 +67,9 @@
65private:67private:
66 friend class TestSessionButton;68 friend class TestSessionButton;
6769
70 void UpdateTextures(std::string const& texture_prefix);
71 RawPixel GetDefaultMaxTextureSize(std::string const& texture_prefix) const;
72
68 Action action_;73 Action action_;
69 IconTexture* image_view_;74 IconTexture* image_view_;
70 StaticCairoText* label_view_;75 StaticCairoText* label_view_;
7176
=== modified file 'shutdown/SessionController.cpp'
--- shutdown/SessionController.cpp 2014-04-30 14:59:29 +0000
+++ shutdown/SessionController.cpp 2014-05-14 15:52:49 +0000
@@ -151,6 +151,8 @@
151 {151 {
152 view_->size_changed.connect([this] (nux::Area*, int, int) {152 view_->size_changed.connect([this] (nux::Area*, int, int) {
153 int monitor = UScreen::GetDefault()->GetMonitorWithMouse();153 int monitor = UScreen::GetDefault()->GetMonitorWithMouse();
154 view_->monitor = monitor;
155
154 auto const& offset = GetOffsetPerMonitor(monitor);156 auto const& offset = GetOffsetPerMonitor(monitor);
155 view_window_->SetXY(offset.x, offset.y);157 view_window_->SetXY(offset.x, offset.y);
156 });158 });
157159
=== modified file 'shutdown/SessionView.cpp'
--- shutdown/SessionView.cpp 2014-05-09 16:08:36 +0000
+++ shutdown/SessionView.cpp 2014-05-14 15:52:49 +0000
@@ -20,10 +20,11 @@
20#include "SessionView.h"20#include "SessionView.h"
21#include "SessionButton.h"21#include "SessionButton.h"
2222
23#include <Nux/VLayout.h>
24#include <UnityCore/GLibWrapper.h>23#include <UnityCore/GLibWrapper.h>
25#include <glib/gi18n-lib.h>24#include <glib/gi18n-lib.h>
2625
26#include "unity-shared/RawPixel.h"
27
27namespace unity28namespace unity
28{29{
29namespace session30namespace session
@@ -31,15 +32,15 @@
3132
32namespace style33namespace style
33{34{
34 const std::string FONT = "Ubuntu Light";35 std::string const FONT = "Ubuntu Light";
35 const std::string TITLE_FONT = FONT+" 15";36 std::string const TITLE_FONT = FONT+" 15";
36 const std::string SUBTITLE_FONT = FONT+" 12";37 std::string const SUBTITLE_FONT = FONT+" 12";
3738
38 const unsigned LEFT_RIGHT_PADDING = 30;39 RawPixel const LEFT_RIGHT_PADDING = 30_em;
39 const unsigned TOP_PADDING = 19;40 RawPixel const TOP_PADDING = 19_em;
40 const unsigned BOTTOM_PADDING = 12;41 RawPixel const BOTTOM_PADDING = 12_em;
41 const unsigned MAIN_SPACE = 10;42 RawPixel const MAIN_SPACE = 10_em;
42 const unsigned BUTTONS_SPACE = 20;43 RawPixel const BUTTONS_SPACE = 20_em;
43}44}
4445
45NUX_IMPLEMENT_OBJECT_TYPE(View);46NUX_IMPLEMENT_OBJECT_TYPE(View);
@@ -51,18 +52,15 @@
51 , key_focus_area_(this)52 , key_focus_area_(this)
52{53{
53 closable = true;54 closable = true;
54 auto main_layout = new nux::VLayout();55 main_layout_ = new nux::VLayout();
55 main_layout->SetTopAndBottomPadding(style::TOP_PADDING, style::BOTTOM_PADDING);56 SetLayout(main_layout_);
56 main_layout->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING);
57 main_layout->SetSpaceBetweenChildren(style::MAIN_SPACE);
58 SetLayout(main_layout);
5957
60 title_ = new StaticCairoText("");58 title_ = new StaticCairoText("");
61 title_->SetFont(style::TITLE_FONT);59 title_->SetFont(style::TITLE_FONT);
62 title_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);60 title_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
63 title_->SetInputEventSensitivity(false);61 title_->SetInputEventSensitivity(false);
64 title_->SetVisible(false);62 title_->SetVisible(false);
65 main_layout->AddView(title_);63 main_layout_->AddView(title_);
6664
67 subtitle_ = new StaticCairoText("");65 subtitle_ = new StaticCairoText("");
68 subtitle_->SetFont(style::SUBTITLE_FONT);66 subtitle_->SetFont(style::SUBTITLE_FONT);
@@ -70,11 +68,10 @@
70 subtitle_->SetInputEventSensitivity(false);68 subtitle_->SetInputEventSensitivity(false);
71 subtitle_->SetLines(std::numeric_limits<int>::min());69 subtitle_->SetLines(std::numeric_limits<int>::min());
72 subtitle_->SetLineSpacing(2);70 subtitle_->SetLineSpacing(2);
73 main_layout->AddView(subtitle_);71 main_layout_->AddView(subtitle_);
7472
75 buttons_layout_ = new nux::HLayout();73 buttons_layout_ = new nux::HLayout();
76 buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE);74 main_layout_->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
77 main_layout->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
7875
79 GetBoundingArea()->mouse_click.connect([this] (int, int, unsigned long, unsigned long) { request_close.emit(); });76 GetBoundingArea()->mouse_click.connect([this] (int, int, unsigned long, unsigned long) { request_close.emit(); });
8077
@@ -99,10 +96,33 @@
99 Populate();96 Populate();
100 });97 });
10198
99 scale.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateViewSize)));
100
101 UpdateViewSize();
102 UpdateText();102 UpdateText();
103 Populate();103 Populate();
104}104}
105105
106void View::UpdateViewSize()
107{
108 main_layout_->SetTopAndBottomPadding(style::TOP_PADDING.CP(scale()), style::BOTTOM_PADDING.CP(scale()));
109 main_layout_->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING.CP(scale()));
110 main_layout_->SetSpaceBetweenChildren(style::MAIN_SPACE.CP(scale()));
111
112 title_->SetScale(scale());
113 subtitle_->SetScale(scale());
114
115 ReloadCloseButtonTexture();
116
117 buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE.CP(scale()));
118
119 for (auto* area : buttons_layout_->GetChildren())
120 {
121 auto* button = static_cast<Button*>(area);
122 button->scale = scale();
123 }
124}
125
106void View::UpdateText()126void View::UpdateText()
107{127{
108 std::string message;128 std::string message;
@@ -190,6 +210,7 @@
190 if (mode() == Mode::LOGOUT)210 if (mode() == Mode::LOGOUT)
191 {211 {
192 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);212 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
213 button->scale = scale();
193 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));214 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
194 AddButton(button);215 AddButton(button);
195216
@@ -203,12 +224,14 @@
203 if (mode() == Mode::FULL)224 if (mode() == Mode::FULL)
204 {225 {
205 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);226 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
227 button->scale = scale();
206 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));228 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
207 AddButton(button);229 AddButton(button);
208230
209 if (manager_->CanSuspend())231 if (manager_->CanSuspend())
210 {232 {
211 button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);233 button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);
234 button->scale = scale();
212 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));235 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));
213 AddButton(button);236 AddButton(button);
214 }237 }
@@ -216,6 +239,7 @@
216 if (manager_->CanHibernate())239 if (manager_->CanHibernate())
217 {240 {
218 button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);241 button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);
242 button->scale = scale();
219 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));243 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));
220 AddButton(button);244 AddButton(button);
221 }245 }
@@ -224,10 +248,12 @@
224 if (manager_->CanShutdown())248 if (manager_->CanShutdown())
225 {249 {
226 auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);250 auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);
251 button->scale = scale();
227 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));252 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));
228 AddButton(button);253 AddButton(button);
229254
230 button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);255 button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);
256 button->scale = scale();
231 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));257 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));
232 key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_;258 key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_;
233 AddButton(button);259 AddButton(button);
@@ -235,6 +261,7 @@
235 else if (mode() == Mode::FULL)261 else if (mode() == Mode::FULL)
236 {262 {
237 auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);263 auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
264 button->scale = scale();
238 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));265 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
239 AddButton(button);266 AddButton(button);
240 }267 }
241268
=== modified file 'shutdown/SessionView.h'
--- shutdown/SessionView.h 2013-11-20 21:39:40 +0000
+++ shutdown/SessionView.h 2014-05-14 15:52:49 +0000
@@ -22,9 +22,11 @@
2222
23#include <Nux/Nux.h>23#include <Nux/Nux.h>
24#include <Nux/View.h>24#include <Nux/View.h>
25#include <Nux/VLayout.h>
25#include <Nux/HLayout.h>26#include <Nux/HLayout.h>
2627
27#include "UnityCore/SessionManager.h"28#include "UnityCore/SessionManager.h"
29#include "unity-shared/EMConverter.h"
28#include "unity-shared/UnityWindowView.h"30#include "unity-shared/UnityWindowView.h"
29#include "UnityCore/SessionManager.h"31#include "UnityCore/SessionManager.h"
3032
@@ -71,6 +73,8 @@
71private:73private:
72 friend class TestSessionView;74 friend class TestSessionView;
7375
76 void UpdateViewSize();
77
74 void UpdateText();78 void UpdateText();
75 void Populate();79 void Populate();
76 void AddButton(Button*);80 void AddButton(Button*);
@@ -78,6 +82,7 @@
78 Manager::Ptr manager_;82 Manager::Ptr manager_;
79 StaticCairoText* title_;83 StaticCairoText* title_;
80 StaticCairoText* subtitle_;84 StaticCairoText* subtitle_;
85 nux::VLayout* main_layout_;
81 nux::HLayout* buttons_layout_;86 nux::HLayout* buttons_layout_;
82 nux::InputArea* key_focus_area_;87 nux::InputArea* key_focus_area_;
83};88};
8489
=== modified file 'tests/test_switcher_view.cpp'
--- tests/test_switcher_view.cpp 2014-03-25 19:07:36 +0000
+++ tests/test_switcher_view.cpp 2014-05-14 15:52:49 +0000
@@ -117,7 +117,7 @@
117 EXPECT_EQ(switcher.vertical_size, switcher.tile_size + VERTICAL_PADDING * 2);117 EXPECT_EQ(switcher.vertical_size, switcher.tile_size + VERTICAL_PADDING * 2);
118 EXPECT_EQ(switcher.text_size, 15);118 EXPECT_EQ(switcher.text_size, 15);
119 EXPECT_EQ(switcher.animation_length, 250);119 EXPECT_EQ(switcher.animation_length, 250);
120 EXPECT_EQ(switcher.monitor, -1);120 EXPECT_EQ(switcher.monitor, 0);
121 EXPECT_EQ(switcher.spread_size, 3.5f);121 EXPECT_EQ(switcher.spread_size, 3.5f);
122 ASSERT_NE(switcher.text_view_, nullptr);122 ASSERT_NE(switcher.text_view_, nullptr);
123 ASSERT_NE(switcher.icon_renderer_, nullptr);123 ASSERT_NE(switcher.icon_renderer_, nullptr);
124124
=== modified file 'tests/test_unity_window_view.cpp'
--- tests/test_unity_window_view.cpp 2014-03-21 04:40:12 +0000
+++ tests/test_unity_window_view.cpp 2014-05-14 15:52:49 +0000
@@ -82,10 +82,10 @@
82 view.closable = true;82 view.closable = true;
83 ASSERT_NE(view.close_button_, nullptr);83 ASSERT_NE(view.close_button_, nullptr);
8484
85 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());85 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
86 EXPECT_EQ(view.close_button_->GetParentObject(), &view);86 EXPECT_EQ(view.close_button_->GetParentObject(), &view);
8787
88 int padding = view.style()->GetCloseButtonPadding();88 int padding = view.style()->GetCloseButtonPadding(view.scale);
89 EXPECT_EQ(view.close_button_->GetBaseX(), padding);89 EXPECT_EQ(view.close_button_->GetBaseX(), padding);
90 EXPECT_EQ(view.close_button_->GetBaseY(), padding);90 EXPECT_EQ(view.close_button_->GetBaseY(), padding);
91}91}
@@ -96,16 +96,16 @@
96 ASSERT_NE(view.close_button_, nullptr);96 ASSERT_NE(view.close_button_, nullptr);
9797
98 view.close_button_->mouse_enter.emit(0, 0, 0, 0);98 view.close_button_->mouse_enter.emit(0, 0, 0, 0);
99 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIconHighligted());99 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON_HIGHLIGHTED));
100100
101 view.close_button_->mouse_leave.emit(0, 0, 0, 0);101 view.close_button_->mouse_leave.emit(0, 0, 0, 0);
102 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());102 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
103103
104 view.close_button_->mouse_down.emit(0, 0, 0, 0);104 view.close_button_->mouse_down.emit(0, 0, 0, 0);
105 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIconPressed());105 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON_PRESSED));
106106
107 view.close_button_->mouse_up.emit(0, 0, 0, 0);107 view.close_button_->mouse_up.emit(0, 0, 0, 0);
108 EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());108 EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
109}109}
110110
111TEST_F(TestUnityWindowView, CloseButtonClicksRequestsClose)111TEST_F(TestUnityWindowView, CloseButtonClicksRequestsClose)
@@ -185,7 +185,7 @@
185 view.SetLayout(layout);185 view.SetLayout(layout);
186 view.ComputeContentSize();186 view.ComputeContentSize();
187187
188 int offset = view.style()->GetInternalOffset();188 int offset = view.style()->GetInternalOffset(view.scale);
189 EXPECT_EQ(layout->GetBaseX(), offset);189 EXPECT_EQ(layout->GetBaseX(), offset);
190 EXPECT_EQ(layout->GetBaseY(), offset);190 EXPECT_EQ(layout->GetBaseY(), offset);
191}191}
@@ -199,7 +199,7 @@
199199
200TEST_F(TestUnityWindowView, GetInternalBackground)200TEST_F(TestUnityWindowView, GetInternalBackground)
201{201{
202 int offset = view.style()->GetInternalOffset();202 int offset = view.style()->GetInternalOffset(view.scale);
203 view.background_geo_.Set(g_random_int(), g_random_int(), g_random_int(), g_random_int());203 view.background_geo_.Set(g_random_int(), g_random_int(), g_random_int(), g_random_int());
204 EXPECT_EQ(view.GetInternalBackground(), view.background_geo_.GetExpand(-offset, -offset));204 EXPECT_EQ(view.GetInternalBackground(), view.background_geo_.GetExpand(-offset, -offset));
205}205}
@@ -240,4 +240,4 @@
240}240}
241241
242} // ui242} // ui
243} // unity
244\ No newline at end of file243\ No newline at end of file
244} // unity
245245
=== modified file 'unity-shared/EMConverter.cpp'
--- unity-shared/EMConverter.cpp 2014-02-27 04:54:19 +0000
+++ unity-shared/EMConverter.cpp 2014-05-14 15:52:49 +0000
@@ -17,6 +17,7 @@
17 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>17 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
18 */18 */
1919
20#include <cmath>
20#include "EMConverter.h"21#include "EMConverter.h"
2122
22namespace unity23namespace unity
@@ -104,8 +105,7 @@
104105
105double EMConverter::CP(int pixels) const106double EMConverter::CP(int pixels) const
106{107{
107 double pixels_em = PixelsToBaseEM(pixels);108 return std::round(pixels * DPIScale());
108 return EMToPixels(pixels_em);
109}109}
110110
111double EMConverter::DPIScale() const111double EMConverter::DPIScale() const
112112
=== modified file 'unity-shared/RawPixel.cpp'
--- unity-shared/RawPixel.cpp 2014-02-26 00:01:21 +0000
+++ unity-shared/RawPixel.cpp 2014-05-14 15:52:49 +0000
@@ -39,7 +39,7 @@
3939
40int RawPixel::CP(EMConverter::Ptr const& converter) const40int RawPixel::CP(EMConverter::Ptr const& converter) const
41{41{
42 return std::round(converter->CP(raw_pixel_));42 return converter->CP(raw_pixel_);
43}43}
4444
45int RawPixel::CP(double scale) const45int RawPixel::CP(double scale) const
4646
=== modified file 'unity-shared/UnityWindowStyle.cpp'
--- unity-shared/UnityWindowStyle.cpp 2013-12-11 02:24:29 +0000
+++ unity-shared/UnityWindowStyle.cpp 2014-05-14 15:52:49 +0000
@@ -16,19 +16,114 @@
16 *16 *
17 * Authored by: Jason Smith <jason.smith@canonical.com>17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>18 * Marco Trevisan <marco.trevisan@canonical.com>
19 * Brandon Schaefer <brandon.schaefer@canonical.com>
19 */20 */
2021
22#include <NuxCore/Logger.h>
23
24#include "UnitySettings.h"
21#include "UnityWindowStyle.h"25#include "UnityWindowStyle.h"
26#include "UScreen.h"
22#include "config.h"27#include "config.h"
2328
24namespace unity {29#include <unordered_set>
25namespace ui {30
31namespace unity
32{
33namespace ui
34{
35namespace
36{
37 const char* const SWITCHER_TOP = PKGDATADIR"/switcher_top.png";
38 const char* const SWITCHER_LEFT = PKGDATADIR"/switcher_left.png";
39 const char* const SWITCHER_CORNER = PKGDATADIR"/switcher_corner.png";
40
41 const char* const DIALOG_CLOSE = PKGDATADIR"/dialog_close.png";
42 const char* const DIALOG_HIGHLIGHT = PKGDATADIR"/dialog_close_highlight.png";
43 const char* const DIALOG_PRESS = PKGDATADIR"/dialog_close_press.png";
44
45
46 RawPixel const INTERNAL_OFFSET = 20_em;
47 RawPixel const BORDER_SIZE = 30_em;
48 RawPixel const CLOSE_PADDING = 3_em;
49}
50
51DECLARE_LOGGER(logger, "unity.ui.unity.window.style");
52
2653
27UnityWindowStyle::UnityWindowStyle()54UnityWindowStyle::UnityWindowStyle()
28{55{
29 background_top_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_top.png", -1, true));56 unsigned monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
30 background_left_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_left.png", -1, true));57 auto& settings = Settings::Instance();
31 background_corner_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_corner.png", -1, true));58
59 // Pre-load scale values per monitor
60 for (unsigned i = 0; i < monitors; ++i)
61 {
62 double scale = settings.Instance().em(i)->DPIScale();
63
64 if (unity_window_textures_.find(scale) == unity_window_textures_.end())
65 LoadAllTextureInScale(scale);
66 }
67
68 settings.Instance().dpi_changed.connect(sigc::mem_fun(this, &UnityWindowStyle::CleanUpUnusedTextures));
69 UScreen::GetDefault()->changed.connect(sigc::mem_fun(this, &UnityWindowStyle::OnMonitorChanged));
70}
71
72void UnityWindowStyle::LoadAllTextureInScale(double scale)
73{
74 auto& window_textures = unity_window_textures_[scale];
75
76 window_textures[unsigned(WindowTextureType::BACKGROUND_TOP)] = LoadTexture(scale, SWITCHER_TOP);
77 window_textures[unsigned(WindowTextureType::BACKGROUND_LEFT)] = LoadTexture(scale, SWITCHER_LEFT);
78 window_textures[unsigned(WindowTextureType::BACKGROUND_CORNER)] = LoadTexture(scale, SWITCHER_CORNER);
79
80 window_textures[unsigned(WindowTextureType::CLOSE_ICON)] = LoadTexture(scale, DIALOG_CLOSE);
81 window_textures[unsigned(WindowTextureType::CLOSE_ICON_HIGHLIGHTED)] = LoadTexture(scale, DIALOG_HIGHLIGHT);
82 window_textures[unsigned(WindowTextureType::CLOSE_ICON_PRESSED)] = LoadTexture(scale, DIALOG_PRESS);
83}
84
85nux::BaseTexture* UnityWindowStyle::LoadTexture(double scale, const char* const texture_name) const
86{
87 RawPixel max_size = GetDefaultMaxTextureSize(texture_name);
88 return nux::CreateTexture2DFromFile(texture_name, max_size.CP(scale), true);
89}
90
91RawPixel UnityWindowStyle::GetDefaultMaxTextureSize(const char* const texture_name) const
92{
93 nux::Size size;
94 gdk_pixbuf_get_file_info(texture_name, &size.width, &size.height);
95 RawPixel max_size = std::max(std::round(size.width), std::round(size.height));
96
97 return max_size;
98}
99
100void UnityWindowStyle::OnMonitorChanged(int primary, std::vector<nux::Geometry> const& monitors)
101{
102 CleanUpUnusedTextures();
103}
104
105// Get current in use scale values, if a scaled value is allocated, but
106// not in use clean up the scaled textures in unity_window_textures
107void UnityWindowStyle::CleanUpUnusedTextures()
108{
109 unsigned monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
110 auto& settings = Settings::Instance();
111 std::unordered_set<double> used_scales;
112
113 for (unsigned i = 0; i < monitors; ++i)
114 used_scales.insert(settings.em(i)->DPIScale());
115
116 for (auto it = unity_window_textures_.begin(); it != unity_window_textures_.end();)
117 {
118 if (used_scales.find(it->first) == used_scales.end())
119 {
120 it = unity_window_textures_.erase(it);
121 }
122 else
123 {
124 ++it;
125 }
126 }
32}127}
33128
34UnityWindowStyle::Ptr const& UnityWindowStyle::Get()129UnityWindowStyle::Ptr const& UnityWindowStyle::Get()
@@ -38,60 +133,38 @@
38 return instance;133 return instance;
39}134}
40135
41int UnityWindowStyle::GetBorderSize() const136int UnityWindowStyle::GetBorderSize(double scale) const
42{137{
43 return 30; // as measured from textures138 return BORDER_SIZE.CP(scale); // as measured from textures
44}139}
45140
46int UnityWindowStyle::GetInternalOffset() const141int UnityWindowStyle::GetInternalOffset(double scale) const
47{142{
48 return 20;143 return INTERNAL_OFFSET.CP(scale);
49}144}
50145
51int UnityWindowStyle::GetCloseButtonPadding() const146int UnityWindowStyle::GetCloseButtonPadding(double scale) const
52{147{
53 return 3;148 return CLOSE_PADDING.CP(scale);
54}149}
55150
56UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIcon()151UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetTexture(double scale, WindowTextureType const& type)
57{152{
58 if (!close_icon_)153 auto it = unity_window_textures_.find(scale);
59 close_icon_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close.png", -1, true));154 if (it == unity_window_textures_.end())
60155 {
61 return close_icon_;156 LoadAllTextureInScale(scale);
62}157
63158 it = unity_window_textures_.find(scale);
64UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIconHighligted()159 if (it == unity_window_textures_.end())
65{160 {
66 if (!close_icon_highlighted_)161 LOG_ERROR(logger) << "Failed to create unity window style textures, for scale size: " << scale;
67 close_icon_highlighted_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close_highlight.png", -1, true));162 return BaseTexturePtr(nullptr);
68163 }
69 return close_icon_highlighted_;164 }
70}165
71166 return it->second[unsigned(type)];
72UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIconPressed()167}
73{168
74 if (!close_icon_pressed_)169} // namespace ui
75 close_icon_pressed_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close_press.png", -1, true));170} // namespace unity
76
77 return close_icon_pressed_;
78}
79
80UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundTop() const
81{
82 return background_top_;
83}
84
85UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundLeft() const
86{
87 return background_left_;
88}
89
90UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundCorner() const
91{
92 return background_corner_;
93}
94
95
96}
97}
98171
=== modified file 'unity-shared/UnityWindowStyle.h'
--- unity-shared/UnityWindowStyle.h 2013-12-11 02:24:29 +0000
+++ unity-shared/UnityWindowStyle.h 2014-05-14 15:52:49 +0000
@@ -16,6 +16,7 @@
16 *16 *
17 * Authored by: Jason Smith <jason.smith@canonical.com>17 * Authored by: Jason Smith <jason.smith@canonical.com>
18 * Marco Trevisan <marco.trevisan@canonical.com>18 * Marco Trevisan <marco.trevisan@canonical.com>
19 * Brandon Schaefer <brandon.schaefer@canonical.com>
19 */20 */
2021
21#ifndef UNITYWINDOWSTYLE_H22#ifndef UNITYWINDOWSTYLE_H
@@ -24,8 +25,23 @@
24#include <sigc++/sigc++.h>25#include <sigc++/sigc++.h>
25#include <Nux/Nux.h>26#include <Nux/Nux.h>
2627
27namespace unity {28#include "RawPixel.h"
28namespace ui {29
30namespace unity
31{
32namespace ui
33{
34
35enum class WindowTextureType : unsigned
36{
37 BACKGROUND_TOP,
38 BACKGROUND_LEFT,
39 BACKGROUND_CORNER,
40 CLOSE_ICON,
41 CLOSE_ICON_HIGHLIGHTED,
42 CLOSE_ICON_PRESSED,
43 Size
44};
2945
30class UnityWindowStyle46class UnityWindowStyle
31{47{
@@ -35,29 +51,28 @@
3551
36 static UnityWindowStyle::Ptr const& Get();52 static UnityWindowStyle::Ptr const& Get();
3753
38 BaseTexturePtr GetCloseIcon();54 BaseTexturePtr GetTexture(double scale, WindowTextureType const& type);
39 BaseTexturePtr GetCloseIconHighligted();55 int GetCloseButtonPadding(double scale) const;
40 BaseTexturePtr GetCloseIconPressed();56 int GetBorderSize(double scale) const;
41 int GetCloseButtonPadding() const;57 int GetInternalOffset(double scale) const;
42
43 BaseTexturePtr GetBackgroundTop() const;
44 BaseTexturePtr GetBackgroundLeft() const;
45 BaseTexturePtr GetBackgroundCorner() const;
46 int GetBorderSize() const;
47 int GetInternalOffset() const;
4858
49private:59private:
50 UnityWindowStyle();60 UnityWindowStyle();
5161
52 BaseTexturePtr background_top_;62 void ReloadIcons();
53 BaseTexturePtr background_left_;63 void LoadAllTextureInScale(double scale);
54 BaseTexturePtr background_corner_;64 nux::BaseTexture* LoadTexture(double scale, const char* const texture_name) const;
55 BaseTexturePtr close_icon_;65 RawPixel GetDefaultMaxTextureSize(const char* const texture_name) const;
56 BaseTexturePtr close_icon_highlighted_;66
57 BaseTexturePtr close_icon_pressed_;67 void OnMonitorChanged(int primary, std::vector<nux::Geometry> const& monitors);
68 void CleanUpUnusedTextures();
69
70 typedef std::array<BaseTexturePtr, size_t(WindowTextureType::Size)> UnityWindowTextures;
71 std::unordered_map<double, UnityWindowTextures> unity_window_textures_;
72
58};73};
5974
60}75} // namespace ui
61}76} // namespace unity
6277
63#endif78#endif
6479
=== modified file 'unity-shared/UnityWindowView.cpp'
--- unity-shared/UnityWindowView.cpp 2014-02-05 12:19:45 +0000
+++ unity-shared/UnityWindowView.cpp 2014-05-14 15:52:49 +0000
@@ -32,6 +32,8 @@
32 : View(NUX_FILE_LINE_PARAM)32 : View(NUX_FILE_LINE_PARAM)
33 , style(UnityWindowStyle::Get())33 , style(UnityWindowStyle::Get())
34 , closable(false)34 , closable(false)
35 , monitor(0)
36 , scale(Settings::Instance().em()->DPIScale())
35 , internal_layout_(nullptr)37 , internal_layout_(nullptr)
36 , bg_helper_(this)38 , bg_helper_(this)
37{39{
@@ -47,6 +49,8 @@
4749
48 live_background = false;50 live_background = false;
4951
52 monitor.changed.connect(sigc::hide(sigc::mem_fun(this, &UnityWindowView::OnDPIChanged)));
53 Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &UnityWindowView::OnDPIChanged));
50 closable.changed.connect(sigc::mem_fun(this, &UnityWindowView::OnClosableChanged));54 closable.changed.connect(sigc::mem_fun(this, &UnityWindowView::OnClosableChanged));
51 background_color.changed.connect(sigc::hide(sigc::mem_fun(this, &View::QueueDraw)));55 background_color.changed.connect(sigc::hide(sigc::mem_fun(this, &View::QueueDraw)));
52}56}
@@ -60,6 +64,17 @@
60 bounding_area_->UnParentObject();64 bounding_area_->UnParentObject();
61}65}
6266
67void UnityWindowView::OnDPIChanged()
68{
69 scale = Settings::Instance().em(monitor())->DPIScale();
70
71 if (internal_layout_)
72 {
73 int offset = style()->GetInternalOffset(scale);
74 view_layout_->SetPadding(offset, offset);
75 }
76}
77
63void UnityWindowView::SetBackgroundHelperGeometryGetter(BackgroundEffectHelper::GeometryGetterFunc const& func)78void UnityWindowView::SetBackgroundHelperGeometryGetter(BackgroundEffectHelper::GeometryGetterFunc const& func)
64{79{
65 bg_helper_.SetGeometryGetter(func);80 bg_helper_.SetGeometryGetter(func);
@@ -109,6 +124,11 @@
109 return View::FindKeyFocusArea(etype, key_code, modifiers);124 return View::FindKeyFocusArea(etype, key_code, modifiers);
110}125}
111126
127void UnityWindowView::ReloadCloseButtonTexture()
128{
129 OnClosableChanged(closable);
130}
131
112void UnityWindowView::OnClosableChanged(bool closable)132void UnityWindowView::OnClosableChanged(bool closable)
113{133{
114 if (!closable)134 if (!closable)
@@ -117,34 +137,38 @@
117 return;137 return;
118 }138 }
119139
120 auto const& texture = style()->GetCloseIcon();140 auto const& texture = style()->GetTexture(scale, WindowTextureType::CLOSE_ICON);
121 int padding = style()->GetCloseButtonPadding();141 int padding = style()->GetCloseButtonPadding(scale);
142
122 close_button_ = new IconTexture(texture);143 close_button_ = new IconTexture(texture);
123 close_button_->SetBaseXY(padding, padding);144 close_button_->SetBaseXY(padding, padding);
124 close_button_->SetParentObject(this);145 close_button_->SetParentObject(this);
125146
126 close_button_->mouse_enter.connect([this](int, int, unsigned long, unsigned long) {147 close_button_->mouse_enter.connect([this](int, int, unsigned long, unsigned long) {
127 if (close_button_->IsMouseOwner())148 if (close_button_->IsMouseOwner())
128 close_button_->SetTexture(style()->GetCloseIconPressed());149 close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_PRESSED));
129 else150 else
130 close_button_->SetTexture(style()->GetCloseIconHighligted());151 close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_HIGHLIGHTED));
131 });152 });
132153
133 close_button_->mouse_leave.connect([this](int, int, unsigned long, unsigned long) {154 close_button_->mouse_leave.connect([this](int, int, unsigned long, unsigned long) {
134 close_button_->SetTexture(style()->GetCloseIcon());155 close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON));
135 });156 });
136157
137 close_button_->mouse_down.connect([this](int, int, unsigned long, unsigned long) {158 close_button_->mouse_down.connect([this](int, int, unsigned long, unsigned long) {
138 close_button_->SetTexture(style()->GetCloseIconPressed());159 close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_PRESSED));
139 });160 });
140161
141 close_button_->mouse_up.connect([this](int, int, unsigned long, unsigned long) {162 close_button_->mouse_up.connect([this](int, int, unsigned long, unsigned long) {
142 bool inside = close_button_->IsMouseInside();163 bool inside = close_button_->IsMouseInside();
143 close_button_->SetTexture(inside ? style()->GetCloseIconHighligted() : style()->GetCloseIcon());164 if (inside)
165 close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_HIGHLIGHTED));
166 else
167 close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON));
144 });168 });
145169
146 close_button_->mouse_click.connect([this](int, int, unsigned long, unsigned long) {170 close_button_->mouse_click.connect([this](int, int, unsigned long, unsigned long) {
147 close_button_->SetTexture(style()->GetCloseIcon());171 close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON));
148 request_close.emit();172 request_close.emit();
149 });173 });
150174
@@ -155,7 +179,7 @@
155{179{
156 if (layout && layout->IsLayout())180 if (layout && layout->IsLayout())
157 {181 {
158 int offset = style()->GetInternalOffset();182 int offset = style()->GetInternalOffset(scale);
159183
160 // We wrap the internal layout adding some padding, so that inherited classes184 // We wrap the internal layout adding some padding, so that inherited classes
161 // can ignore the offsets we define here.185 // can ignore the offsets we define here.
@@ -180,7 +204,8 @@
180204
181nux::Geometry UnityWindowView::GetInternalBackground()205nux::Geometry UnityWindowView::GetInternalBackground()
182{206{
183 int offset = style()->GetInternalOffset();207 int offset = style()->GetInternalOffset(scale);
208
184 return GetBackgroundGeometry().GetExpand(-offset, -offset);209 return GetBackgroundGeometry().GetExpand(-offset, -offset);
185}210}
186211
@@ -330,7 +355,9 @@
330355
331void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)356void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)
332{357{
333 int border = style()->GetBorderSize();358 int border = style()->GetBorderSize(scale);
359
360 auto background_corner_textrue = style()->GetTexture(scale, WindowTextureType::BACKGROUND_CORNER)->GetDeviceTexture();
334361
335 GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);362 GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
336363
@@ -344,7 +371,7 @@
344 texxform.u1 = border;371 texxform.u1 = border;
345 texxform.v1 = border;372 texxform.v1 = border;
346 GfxContext.QRP_1Tex (geo.x, geo.y,373 GfxContext.QRP_1Tex (geo.x, geo.y,
347 border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);374 border, border, background_corner_textrue, texxform, nux::color::White);
348375
349 // Draw TOP-RIGHT CORNER376 // Draw TOP-RIGHT CORNER
350 texxform.u0 = 0;377 texxform.u0 = 0;
@@ -354,7 +381,7 @@
354 texxform.flip_u_coord = true;381 texxform.flip_u_coord = true;
355 texxform.flip_v_coord = false;382 texxform.flip_v_coord = false;
356 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y,383 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y,
357 border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);384 border, border, background_corner_textrue, texxform, nux::color::White);
358385
359 // Draw BOTTOM-LEFT CORNER386 // Draw BOTTOM-LEFT CORNER
360 texxform.u0 = 0;387 texxform.u0 = 0;
@@ -364,7 +391,7 @@
364 texxform.flip_u_coord = false;391 texxform.flip_u_coord = false;
365 texxform.flip_v_coord = true;392 texxform.flip_v_coord = true;
366 GfxContext.QRP_1Tex (geo.x, geo.y + geo.height - border,393 GfxContext.QRP_1Tex (geo.x, geo.y + geo.height - border,
367 border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);394 border, border, background_corner_textrue, texxform, nux::color::White);
368395
369 // Draw BOTTOM-RIGHT CORNER396 // Draw BOTTOM-RIGHT CORNER
370 texxform.u0 = 0;397 texxform.u0 = 0;
@@ -374,10 +401,11 @@
374 texxform.flip_u_coord = true;401 texxform.flip_u_coord = true;
375 texxform.flip_v_coord = true;402 texxform.flip_v_coord = true;
376 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + geo.height - border,403 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + geo.height - border,
377 border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);404 border, border, background_corner_textrue, texxform, nux::color::White);
378405
379 int top_width = style()->GetBackgroundTop()->GetWidth();406 auto background_top = style()->GetTexture(scale, WindowTextureType::BACKGROUND_TOP);
380 int top_height = style()->GetBackgroundTop()->GetHeight();407 int top_width = background_top->GetWidth();
408 int top_height = background_top->GetHeight();
381409
382 // Draw TOP BORDER410 // Draw TOP BORDER
383 texxform.u0 = 0;411 texxform.u0 = 0;
@@ -386,7 +414,7 @@
386 texxform.v1 = top_height;414 texxform.v1 = top_height;
387 texxform.flip_u_coord = false;415 texxform.flip_u_coord = false;
388 texxform.flip_v_coord = false;416 texxform.flip_v_coord = false;
389 GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);417 GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, background_top->GetDeviceTexture(), texxform, nux::color::White);
390418
391 // Draw BOTTOM BORDER419 // Draw BOTTOM BORDER
392 texxform.u0 = 0;420 texxform.u0 = 0;
@@ -395,11 +423,11 @@
395 texxform.v1 = top_height;423 texxform.v1 = top_height;
396 texxform.flip_u_coord = false;424 texxform.flip_u_coord = false;
397 texxform.flip_v_coord = true;425 texxform.flip_v_coord = true;
398 GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);426 GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, background_top->GetDeviceTexture(), texxform, nux::color::White);
399427
400428 auto background_left = style()->GetTexture(scale, WindowTextureType::BACKGROUND_LEFT);
401 int left_width = style()->GetBackgroundLeft()->GetWidth();429 int left_width = background_left->GetWidth();
402 int left_height = style()->GetBackgroundLeft()->GetHeight();430 int left_height = background_left->GetHeight();
403431
404 // Draw LEFT BORDER432 // Draw LEFT BORDER
405 texxform.u0 = 0;433 texxform.u0 = 0;
@@ -408,7 +436,7 @@
408 texxform.v1 = left_height;436 texxform.v1 = left_height;
409 texxform.flip_u_coord = false;437 texxform.flip_u_coord = false;
410 texxform.flip_v_coord = false;438 texxform.flip_v_coord = false;
411 GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);439 GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, background_left->GetDeviceTexture(), texxform, nux::color::White);
412440
413 // Draw RIGHT BORDER441 // Draw RIGHT BORDER
414 texxform.u0 = 0;442 texxform.u0 = 0;
@@ -417,7 +445,7 @@
417 texxform.v1 = left_height;445 texxform.v1 = left_height;
418 texxform.flip_u_coord = true;446 texxform.flip_u_coord = true;
419 texxform.flip_v_coord = false;447 texxform.flip_v_coord = false;
420 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);448 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, background_left->GetDeviceTexture(), texxform, nux::color::White);
421449
422 GfxContext.GetRenderStates().SetBlend(false);450 GfxContext.GetRenderStates().SetBlend(false);
423}451}
424452
=== modified file 'unity-shared/UnityWindowView.h'
--- unity-shared/UnityWindowView.h 2013-11-21 16:06:58 +0000
+++ unity-shared/UnityWindowView.h 2014-05-14 15:52:49 +0000
@@ -23,6 +23,7 @@
2323
24#include "unity-shared/BackgroundEffectHelper.h"24#include "unity-shared/BackgroundEffectHelper.h"
25#include "unity-shared/IconTexture.h"25#include "unity-shared/IconTexture.h"
26
26#include "Introspectable.h"27#include "Introspectable.h"
27#include "UnityWindowStyle.h"28#include "UnityWindowStyle.h"
28#include <sigc++/sigc++.h>29#include <sigc++/sigc++.h>
@@ -41,6 +42,8 @@
41 nux::Property<nux::Color> background_color;42 nux::Property<nux::Color> background_color;
42 nux::Property<UnityWindowStyle::Ptr> style;43 nux::Property<UnityWindowStyle::Ptr> style;
43 nux::Property<bool> closable;44 nux::Property<bool> closable;
45 nux::Property<int> monitor;
46 nux::Property<double> scale;
4447
45 UnityWindowView(NUX_FILE_LINE_PROTO);48 UnityWindowView(NUX_FILE_LINE_PROTO);
46 virtual ~UnityWindowView();49 virtual ~UnityWindowView();
@@ -64,6 +67,8 @@
64 virtual nux::Geometry GetBlurredBackgroundGeometry();67 virtual nux::Geometry GetBlurredBackgroundGeometry();
65 void SetBackgroundHelperGeometryGetter(BackgroundEffectHelper::GeometryGetterFunc const&);68 void SetBackgroundHelperGeometryGetter(BackgroundEffectHelper::GeometryGetterFunc const&);
6669
70 void ReloadCloseButtonTexture();
71
67 // Introspectable methods72 // Introspectable methods
68 std::string GetName() const;73 std::string GetName() const;
69 void AddProperties(debug::IntrospectionData&);74 void AddProperties(debug::IntrospectionData&);
@@ -71,6 +76,7 @@
71private:76private:
72 friend class TestUnityWindowView;77 friend class TestUnityWindowView;
7378
79 void OnDPIChanged();
74 void OnClosableChanged(bool closable);80 void OnClosableChanged(bool closable);
75 void DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo);81 void DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo);
7682