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
1=== modified file 'launcher/SwitcherView.cpp'
2--- launcher/SwitcherView.cpp 2014-03-25 19:07:36 +0000
3+++ launcher/SwitcherView.cpp 2014-05-14 15:52:49 +0000
4@@ -37,7 +37,7 @@
5
6 namespace
7 {
8- unsigned int const VERTICAL_PADDING = 45;
9+ RawPixel const VERTICAL_PADDING = 45_em;
10 unsigned int const SPREAD_OFFSET = 100;
11 unsigned int const EXTRA_ICON_SPACE = 10;
12 unsigned int const MAX_DIRECTIONS_CHANGED = 3;
13@@ -52,10 +52,9 @@
14 , icon_size(128)
15 , minimum_spacing(10)
16 , tile_size(150)
17- , vertical_size(tile_size + VERTICAL_PADDING * 2)
18+ , vertical_size(tile_size + VERTICAL_PADDING.CP(scale()) * 2)
19 , text_size(15)
20 , animation_length(250)
21- , monitor(-1)
22 , spread_size(3.5f)
23 , icon_renderer_(renderer)
24 , text_view_(new StaticCairoText(""))
25@@ -73,8 +72,9 @@
26 text_view_->SetTextColor(nux::color::White);
27 text_view_->SetFont("Ubuntu Bold 10");
28
29- icon_size.changed.connect (sigc::mem_fun (this, &SwitcherView::OnIconSizeChanged));
30- tile_size.changed.connect (sigc::mem_fun (this, &SwitcherView::OnTileSizeChanged));
31+ icon_size.changed.connect(sigc::mem_fun(this, &SwitcherView::OnIconSizeChanged));
32+ tile_size.changed.connect(sigc::mem_fun(this, &SwitcherView::OnTileSizeChanged));
33+ scale.changed.connect(sigc::mem_fun(this, &SwitcherView::OnScaleChanged));
34
35 mouse_move.connect (sigc::mem_fun(this, &SwitcherView::RecvMouseMove));
36 mouse_down.connect (sigc::mem_fun(this, &SwitcherView::RecvMouseDown));
37@@ -164,15 +164,20 @@
38 text_view_->SetText(model->Selection()->tooltip_text(), true);
39 }
40
41-void SwitcherView::OnIconSizeChanged (int size)
42-{
43- icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);
44-}
45-
46-void SwitcherView::OnTileSizeChanged (int size)
47-{
48- icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);
49- vertical_size = tile_size + VERTICAL_PADDING * 2;
50+void SwitcherView::OnIconSizeChanged(int size)
51+{
52+ icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);
53+}
54+
55+void SwitcherView::OnTileSizeChanged(int size)
56+{
57+ icon_renderer_->SetTargetSize(tile_size, icon_size, minimum_spacing);
58+ vertical_size = tile_size + VERTICAL_PADDING.CP(scale()) * 2;
59+}
60+
61+void SwitcherView::OnScaleChanged(double scale)
62+{
63+ vertical_size = tile_size + VERTICAL_PADDING.CP(scale) * 2;
64 }
65
66 void SwitcherView::StartAnimation()
67@@ -699,7 +704,10 @@
68 background_geo.height = vertical_size;
69
70 if (text_view_->IsVisible())
71+ {
72 background_geo.height += text_size;
73+ text_view_->SetBaseY(background_geo.y + background_geo.height - VERTICAL_PADDING.CP(scale()));
74+ }
75
76 if (model_)
77 {
78@@ -953,7 +961,6 @@
79 if (text_view_->IsVisible())
80 {
81 nux::GetPainter().PushPaintLayerStack();
82- text_view_->SetBaseY(last_background_.y + last_background_.height - 45);
83 text_view_->Draw(GfxContext, force_draw);
84 nux::GetPainter().PopPaintLayerStack();
85 }
86
87=== modified file 'launcher/SwitcherView.h'
88--- launcher/SwitcherView.h 2014-03-25 19:07:36 +0000
89+++ launcher/SwitcherView.h 2014-05-14 15:52:49 +0000
90@@ -65,7 +65,6 @@
91 nux::Property<int> vertical_size;
92 nux::Property<int> text_size;
93 nux::Property<int> animation_length;
94- nux::Property<int> monitor;
95 nux::Property<double> spread_size;
96
97 void SkipAnimation();
98@@ -135,8 +134,9 @@
99 void OnDetailSelectionChanged (bool detail);
100 void OnDetailSelectionIndexChanged (unsigned int index);
101
102- void OnIconSizeChanged (int size);
103- void OnTileSizeChanged (int size);
104+ void OnIconSizeChanged(int size);
105+ void OnTileSizeChanged(int size);
106+ void OnScaleChanged(double scale);
107
108 nux::Geometry UpdateRenderTargets(float progress);
109 void ResizeRenderTargets(nux::Geometry const& layout_geo, float progress);
110
111=== modified file 'shortcuts/ShortcutController.cpp'
112--- shortcuts/ShortcutController.cpp 2014-04-05 20:09:17 +0000
113+++ shortcuts/ShortcutController.cpp 2014-05-14 15:52:49 +0000
114@@ -75,9 +75,7 @@
115 if (Visible())
116 {
117 model->Fill();
118- auto uscreen = UScreen::GetDefault();
119- int monitor = uscreen->GetMonitorAtPosition(view_window_->GetX(), view_window_->GetX());
120- auto const& offset = GetOffsetPerMonitor(monitor);
121+ auto const& offset = GetOffsetPerMonitor(view_->monitor());
122
123 if (offset.x < 0 || offset.y < 0)
124 {
125@@ -110,8 +108,8 @@
126 modeller_->GetCurrentModel()->Fill();
127 EnsureView();
128
129- int monitor = UScreen::GetDefault()->GetMonitorWithMouse();
130- auto const& offset = GetOffsetPerMonitor(monitor);
131+ view_->monitor = UScreen::GetDefault()->GetMonitorWithMouse();
132+ auto const& offset = GetOffsetPerMonitor(view_->monitor());
133
134 if (offset.x < 0 || offset.y < 0)
135 return false;
136
137=== modified file 'shutdown/SessionButton.cpp'
138--- shutdown/SessionButton.cpp 2014-02-25 01:07:06 +0000
139+++ shutdown/SessionButton.cpp 2014-05-14 15:52:49 +0000
140@@ -30,15 +30,15 @@
141
142 namespace style
143 {
144- const std::string FONT = "Ubuntu Light 12";
145-
146- const unsigned BUTTON_SPACE = 9;
147+ std::string const FONT = "Ubuntu Light 12";
148+ RawPixel const BUTTON_SPACE = 9_em;
149 }
150
151 NUX_IMPLEMENT_OBJECT_TYPE(Button);
152
153 Button::Button(Action action, NUX_FILE_LINE_DECL)
154 : nux::View(NUX_FILE_LINE_PARAM)
155+ , scale(1.0)
156 , highlighted(false)
157 , action([this] { return action_; })
158 , label([this] { return label_view_->GetText(); })
159@@ -78,14 +78,21 @@
160 break;
161 }
162
163- normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), -1, true));
164- highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), -1, true));
165+ UpdateTextures(texture_prefix);
166
167 auto main_layout = new nux::VLayout();
168 main_layout->SetContentDistribution(nux::MAJOR_POSITION_CENTER);
169 main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE);
170 SetLayout(main_layout);
171
172+ scale.changed.connect([this, main_layout, texture_prefix] (double new_scale) {
173+ main_layout->SetSpaceBetweenChildren(style::BUTTON_SPACE.CP(new_scale));
174+ label_view_->SetScale(new_scale);
175+
176+ UpdateTextures(texture_prefix);
177+ image_view_->SetTexture(highlighted ? highlight_tex_ : normal_tex_);
178+ });
179+
180 image_view_ = new IconTexture(normal_tex_);
181 image_view_->SetInputEventSensitivity(false);
182 main_layout->AddView(image_view_, 1, nux::MINOR_POSITION_CENTER);
183@@ -111,6 +118,24 @@
184 });
185 }
186
187+void Button::UpdateTextures(std::string const& texture_prefix)
188+{
189+ RawPixel const texture_size = GetDefaultMaxTextureSize(texture_prefix);
190+
191+ normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), texture_size.CP(scale), true));
192+ highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), texture_size.CP(scale), true));
193+}
194+
195+RawPixel Button::GetDefaultMaxTextureSize(std::string const& texture_prefix) const
196+{
197+ nux::Size size;
198+ auto const& texture_name = (texture_prefix + ".png");
199+ gdk_pixbuf_get_file_info(texture_name.c_str(), &size.width, &size.height);
200+ RawPixel max_size = std::max(size.width, size.height);
201+
202+ return max_size;
203+}
204+
205 void Button::Draw(nux::GraphicsEngine& ctx, bool force)
206 {
207 GetLayout()->ProcessDraw(ctx, force);
208
209=== modified file 'shutdown/SessionButton.h'
210--- shutdown/SessionButton.h 2014-02-25 01:07:06 +0000
211+++ shutdown/SessionButton.h 2014-05-14 15:52:49 +0000
212@@ -26,6 +26,7 @@
213
214 #include "unity-shared/IconTexture.h"
215 #include "unity-shared/Introspectable.h"
216+#include "unity-shared/RawPixel.h"
217 #include "unity-shared/StaticCairoText.h"
218
219 namespace unity
220@@ -49,6 +50,7 @@
221
222 Button(Action, NUX_FILE_LINE_PROTO);
223
224+ nux::Property<double> scale;
225 nux::Property<bool> highlighted;
226 nux::ROProperty<Action> action;
227 nux::ROProperty<std::string> label;
228@@ -65,6 +67,9 @@
229 private:
230 friend class TestSessionButton;
231
232+ void UpdateTextures(std::string const& texture_prefix);
233+ RawPixel GetDefaultMaxTextureSize(std::string const& texture_prefix) const;
234+
235 Action action_;
236 IconTexture* image_view_;
237 StaticCairoText* label_view_;
238
239=== modified file 'shutdown/SessionController.cpp'
240--- shutdown/SessionController.cpp 2014-04-30 14:59:29 +0000
241+++ shutdown/SessionController.cpp 2014-05-14 15:52:49 +0000
242@@ -151,6 +151,8 @@
243 {
244 view_->size_changed.connect([this] (nux::Area*, int, int) {
245 int monitor = UScreen::GetDefault()->GetMonitorWithMouse();
246+ view_->monitor = monitor;
247+
248 auto const& offset = GetOffsetPerMonitor(monitor);
249 view_window_->SetXY(offset.x, offset.y);
250 });
251
252=== modified file 'shutdown/SessionView.cpp'
253--- shutdown/SessionView.cpp 2014-05-09 16:08:36 +0000
254+++ shutdown/SessionView.cpp 2014-05-14 15:52:49 +0000
255@@ -20,10 +20,11 @@
256 #include "SessionView.h"
257 #include "SessionButton.h"
258
259-#include <Nux/VLayout.h>
260 #include <UnityCore/GLibWrapper.h>
261 #include <glib/gi18n-lib.h>
262
263+#include "unity-shared/RawPixel.h"
264+
265 namespace unity
266 {
267 namespace session
268@@ -31,15 +32,15 @@
269
270 namespace style
271 {
272- const std::string FONT = "Ubuntu Light";
273- const std::string TITLE_FONT = FONT+" 15";
274- const std::string SUBTITLE_FONT = FONT+" 12";
275+ std::string const FONT = "Ubuntu Light";
276+ std::string const TITLE_FONT = FONT+" 15";
277+ std::string const SUBTITLE_FONT = FONT+" 12";
278
279- const unsigned LEFT_RIGHT_PADDING = 30;
280- const unsigned TOP_PADDING = 19;
281- const unsigned BOTTOM_PADDING = 12;
282- const unsigned MAIN_SPACE = 10;
283- const unsigned BUTTONS_SPACE = 20;
284+ RawPixel const LEFT_RIGHT_PADDING = 30_em;
285+ RawPixel const TOP_PADDING = 19_em;
286+ RawPixel const BOTTOM_PADDING = 12_em;
287+ RawPixel const MAIN_SPACE = 10_em;
288+ RawPixel const BUTTONS_SPACE = 20_em;
289 }
290
291 NUX_IMPLEMENT_OBJECT_TYPE(View);
292@@ -51,18 +52,15 @@
293 , key_focus_area_(this)
294 {
295 closable = true;
296- auto main_layout = new nux::VLayout();
297- main_layout->SetTopAndBottomPadding(style::TOP_PADDING, style::BOTTOM_PADDING);
298- main_layout->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING);
299- main_layout->SetSpaceBetweenChildren(style::MAIN_SPACE);
300- SetLayout(main_layout);
301+ main_layout_ = new nux::VLayout();
302+ SetLayout(main_layout_);
303
304 title_ = new StaticCairoText("");
305 title_->SetFont(style::TITLE_FONT);
306 title_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
307 title_->SetInputEventSensitivity(false);
308 title_->SetVisible(false);
309- main_layout->AddView(title_);
310+ main_layout_->AddView(title_);
311
312 subtitle_ = new StaticCairoText("");
313 subtitle_->SetFont(style::SUBTITLE_FONT);
314@@ -70,11 +68,10 @@
315 subtitle_->SetInputEventSensitivity(false);
316 subtitle_->SetLines(std::numeric_limits<int>::min());
317 subtitle_->SetLineSpacing(2);
318- main_layout->AddView(subtitle_);
319+ main_layout_->AddView(subtitle_);
320
321 buttons_layout_ = new nux::HLayout();
322- buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE);
323- main_layout->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
324+ main_layout_->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
325
326 GetBoundingArea()->mouse_click.connect([this] (int, int, unsigned long, unsigned long) { request_close.emit(); });
327
328@@ -99,10 +96,33 @@
329 Populate();
330 });
331
332+ scale.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateViewSize)));
333+
334+ UpdateViewSize();
335 UpdateText();
336 Populate();
337 }
338
339+void View::UpdateViewSize()
340+{
341+ main_layout_->SetTopAndBottomPadding(style::TOP_PADDING.CP(scale()), style::BOTTOM_PADDING.CP(scale()));
342+ main_layout_->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING.CP(scale()));
343+ main_layout_->SetSpaceBetweenChildren(style::MAIN_SPACE.CP(scale()));
344+
345+ title_->SetScale(scale());
346+ subtitle_->SetScale(scale());
347+
348+ ReloadCloseButtonTexture();
349+
350+ buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE.CP(scale()));
351+
352+ for (auto* area : buttons_layout_->GetChildren())
353+ {
354+ auto* button = static_cast<Button*>(area);
355+ button->scale = scale();
356+ }
357+}
358+
359 void View::UpdateText()
360 {
361 std::string message;
362@@ -190,6 +210,7 @@
363 if (mode() == Mode::LOGOUT)
364 {
365 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
366+ button->scale = scale();
367 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
368 AddButton(button);
369
370@@ -203,12 +224,14 @@
371 if (mode() == Mode::FULL)
372 {
373 auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
374+ button->scale = scale();
375 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
376 AddButton(button);
377
378 if (manager_->CanSuspend())
379 {
380 button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);
381+ button->scale = scale();
382 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));
383 AddButton(button);
384 }
385@@ -216,6 +239,7 @@
386 if (manager_->CanHibernate())
387 {
388 button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);
389+ button->scale = scale();
390 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));
391 AddButton(button);
392 }
393@@ -224,10 +248,12 @@
394 if (manager_->CanShutdown())
395 {
396 auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);
397+ button->scale = scale();
398 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));
399 AddButton(button);
400
401 button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);
402+ button->scale = scale();
403 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));
404 key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_;
405 AddButton(button);
406@@ -235,6 +261,7 @@
407 else if (mode() == Mode::FULL)
408 {
409 auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
410+ button->scale = scale();
411 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
412 AddButton(button);
413 }
414
415=== modified file 'shutdown/SessionView.h'
416--- shutdown/SessionView.h 2013-11-20 21:39:40 +0000
417+++ shutdown/SessionView.h 2014-05-14 15:52:49 +0000
418@@ -22,9 +22,11 @@
419
420 #include <Nux/Nux.h>
421 #include <Nux/View.h>
422+#include <Nux/VLayout.h>
423 #include <Nux/HLayout.h>
424
425 #include "UnityCore/SessionManager.h"
426+#include "unity-shared/EMConverter.h"
427 #include "unity-shared/UnityWindowView.h"
428 #include "UnityCore/SessionManager.h"
429
430@@ -71,6 +73,8 @@
431 private:
432 friend class TestSessionView;
433
434+ void UpdateViewSize();
435+
436 void UpdateText();
437 void Populate();
438 void AddButton(Button*);
439@@ -78,6 +82,7 @@
440 Manager::Ptr manager_;
441 StaticCairoText* title_;
442 StaticCairoText* subtitle_;
443+ nux::VLayout* main_layout_;
444 nux::HLayout* buttons_layout_;
445 nux::InputArea* key_focus_area_;
446 };
447
448=== modified file 'tests/test_switcher_view.cpp'
449--- tests/test_switcher_view.cpp 2014-03-25 19:07:36 +0000
450+++ tests/test_switcher_view.cpp 2014-05-14 15:52:49 +0000
451@@ -117,7 +117,7 @@
452 EXPECT_EQ(switcher.vertical_size, switcher.tile_size + VERTICAL_PADDING * 2);
453 EXPECT_EQ(switcher.text_size, 15);
454 EXPECT_EQ(switcher.animation_length, 250);
455- EXPECT_EQ(switcher.monitor, -1);
456+ EXPECT_EQ(switcher.monitor, 0);
457 EXPECT_EQ(switcher.spread_size, 3.5f);
458 ASSERT_NE(switcher.text_view_, nullptr);
459 ASSERT_NE(switcher.icon_renderer_, nullptr);
460
461=== modified file 'tests/test_unity_window_view.cpp'
462--- tests/test_unity_window_view.cpp 2014-03-21 04:40:12 +0000
463+++ tests/test_unity_window_view.cpp 2014-05-14 15:52:49 +0000
464@@ -82,10 +82,10 @@
465 view.closable = true;
466 ASSERT_NE(view.close_button_, nullptr);
467
468- EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());
469+ EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
470 EXPECT_EQ(view.close_button_->GetParentObject(), &view);
471
472- int padding = view.style()->GetCloseButtonPadding();
473+ int padding = view.style()->GetCloseButtonPadding(view.scale);
474 EXPECT_EQ(view.close_button_->GetBaseX(), padding);
475 EXPECT_EQ(view.close_button_->GetBaseY(), padding);
476 }
477@@ -96,16 +96,16 @@
478 ASSERT_NE(view.close_button_, nullptr);
479
480 view.close_button_->mouse_enter.emit(0, 0, 0, 0);
481- EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIconHighligted());
482+ EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON_HIGHLIGHTED));
483
484 view.close_button_->mouse_leave.emit(0, 0, 0, 0);
485- EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());
486+ EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
487
488 view.close_button_->mouse_down.emit(0, 0, 0, 0);
489- EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIconPressed());
490+ EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON_PRESSED));
491
492 view.close_button_->mouse_up.emit(0, 0, 0, 0);
493- EXPECT_EQ(view.close_button_->texture(), view.style()->GetCloseIcon());
494+ EXPECT_EQ(view.close_button_->texture(), view.style()->GetTexture(view.scale, WindowTextureType::CLOSE_ICON));
495 }
496
497 TEST_F(TestUnityWindowView, CloseButtonClicksRequestsClose)
498@@ -185,7 +185,7 @@
499 view.SetLayout(layout);
500 view.ComputeContentSize();
501
502- int offset = view.style()->GetInternalOffset();
503+ int offset = view.style()->GetInternalOffset(view.scale);
504 EXPECT_EQ(layout->GetBaseX(), offset);
505 EXPECT_EQ(layout->GetBaseY(), offset);
506 }
507@@ -199,7 +199,7 @@
508
509 TEST_F(TestUnityWindowView, GetInternalBackground)
510 {
511- int offset = view.style()->GetInternalOffset();
512+ int offset = view.style()->GetInternalOffset(view.scale);
513 view.background_geo_.Set(g_random_int(), g_random_int(), g_random_int(), g_random_int());
514 EXPECT_EQ(view.GetInternalBackground(), view.background_geo_.GetExpand(-offset, -offset));
515 }
516@@ -240,4 +240,4 @@
517 }
518
519 } // ui
520-} // unity
521\ No newline at end of file
522+} // unity
523
524=== modified file 'unity-shared/EMConverter.cpp'
525--- unity-shared/EMConverter.cpp 2014-02-27 04:54:19 +0000
526+++ unity-shared/EMConverter.cpp 2014-05-14 15:52:49 +0000
527@@ -17,6 +17,7 @@
528 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
529 */
530
531+#include <cmath>
532 #include "EMConverter.h"
533
534 namespace unity
535@@ -104,8 +105,7 @@
536
537 double EMConverter::CP(int pixels) const
538 {
539- double pixels_em = PixelsToBaseEM(pixels);
540- return EMToPixels(pixels_em);
541+ return std::round(pixels * DPIScale());
542 }
543
544 double EMConverter::DPIScale() const
545
546=== modified file 'unity-shared/RawPixel.cpp'
547--- unity-shared/RawPixel.cpp 2014-02-26 00:01:21 +0000
548+++ unity-shared/RawPixel.cpp 2014-05-14 15:52:49 +0000
549@@ -39,7 +39,7 @@
550
551 int RawPixel::CP(EMConverter::Ptr const& converter) const
552 {
553- return std::round(converter->CP(raw_pixel_));
554+ return converter->CP(raw_pixel_);
555 }
556
557 int RawPixel::CP(double scale) const
558
559=== modified file 'unity-shared/UnityWindowStyle.cpp'
560--- unity-shared/UnityWindowStyle.cpp 2013-12-11 02:24:29 +0000
561+++ unity-shared/UnityWindowStyle.cpp 2014-05-14 15:52:49 +0000
562@@ -16,19 +16,114 @@
563 *
564 * Authored by: Jason Smith <jason.smith@canonical.com>
565 * Marco Trevisan <marco.trevisan@canonical.com>
566+ * Brandon Schaefer <brandon.schaefer@canonical.com>
567 */
568
569+#include <NuxCore/Logger.h>
570+
571+#include "UnitySettings.h"
572 #include "UnityWindowStyle.h"
573+#include "UScreen.h"
574 #include "config.h"
575
576-namespace unity {
577-namespace ui {
578+#include <unordered_set>
579+
580+namespace unity
581+{
582+namespace ui
583+{
584+namespace
585+{
586+ const char* const SWITCHER_TOP = PKGDATADIR"/switcher_top.png";
587+ const char* const SWITCHER_LEFT = PKGDATADIR"/switcher_left.png";
588+ const char* const SWITCHER_CORNER = PKGDATADIR"/switcher_corner.png";
589+
590+ const char* const DIALOG_CLOSE = PKGDATADIR"/dialog_close.png";
591+ const char* const DIALOG_HIGHLIGHT = PKGDATADIR"/dialog_close_highlight.png";
592+ const char* const DIALOG_PRESS = PKGDATADIR"/dialog_close_press.png";
593+
594+
595+ RawPixel const INTERNAL_OFFSET = 20_em;
596+ RawPixel const BORDER_SIZE = 30_em;
597+ RawPixel const CLOSE_PADDING = 3_em;
598+}
599+
600+DECLARE_LOGGER(logger, "unity.ui.unity.window.style");
601+
602
603 UnityWindowStyle::UnityWindowStyle()
604 {
605- background_top_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_top.png", -1, true));
606- background_left_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_left.png", -1, true));
607- background_corner_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/switcher_corner.png", -1, true));
608+ unsigned monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
609+ auto& settings = Settings::Instance();
610+
611+ // Pre-load scale values per monitor
612+ for (unsigned i = 0; i < monitors; ++i)
613+ {
614+ double scale = settings.Instance().em(i)->DPIScale();
615+
616+ if (unity_window_textures_.find(scale) == unity_window_textures_.end())
617+ LoadAllTextureInScale(scale);
618+ }
619+
620+ settings.Instance().dpi_changed.connect(sigc::mem_fun(this, &UnityWindowStyle::CleanUpUnusedTextures));
621+ UScreen::GetDefault()->changed.connect(sigc::mem_fun(this, &UnityWindowStyle::OnMonitorChanged));
622+}
623+
624+void UnityWindowStyle::LoadAllTextureInScale(double scale)
625+{
626+ auto& window_textures = unity_window_textures_[scale];
627+
628+ window_textures[unsigned(WindowTextureType::BACKGROUND_TOP)] = LoadTexture(scale, SWITCHER_TOP);
629+ window_textures[unsigned(WindowTextureType::BACKGROUND_LEFT)] = LoadTexture(scale, SWITCHER_LEFT);
630+ window_textures[unsigned(WindowTextureType::BACKGROUND_CORNER)] = LoadTexture(scale, SWITCHER_CORNER);
631+
632+ window_textures[unsigned(WindowTextureType::CLOSE_ICON)] = LoadTexture(scale, DIALOG_CLOSE);
633+ window_textures[unsigned(WindowTextureType::CLOSE_ICON_HIGHLIGHTED)] = LoadTexture(scale, DIALOG_HIGHLIGHT);
634+ window_textures[unsigned(WindowTextureType::CLOSE_ICON_PRESSED)] = LoadTexture(scale, DIALOG_PRESS);
635+}
636+
637+nux::BaseTexture* UnityWindowStyle::LoadTexture(double scale, const char* const texture_name) const
638+{
639+ RawPixel max_size = GetDefaultMaxTextureSize(texture_name);
640+ return nux::CreateTexture2DFromFile(texture_name, max_size.CP(scale), true);
641+}
642+
643+RawPixel UnityWindowStyle::GetDefaultMaxTextureSize(const char* const texture_name) const
644+{
645+ nux::Size size;
646+ gdk_pixbuf_get_file_info(texture_name, &size.width, &size.height);
647+ RawPixel max_size = std::max(std::round(size.width), std::round(size.height));
648+
649+ return max_size;
650+}
651+
652+void UnityWindowStyle::OnMonitorChanged(int primary, std::vector<nux::Geometry> const& monitors)
653+{
654+ CleanUpUnusedTextures();
655+}
656+
657+// Get current in use scale values, if a scaled value is allocated, but
658+// not in use clean up the scaled textures in unity_window_textures
659+void UnityWindowStyle::CleanUpUnusedTextures()
660+{
661+ unsigned monitors = UScreen::GetDefault()->GetPluggedMonitorsNumber();
662+ auto& settings = Settings::Instance();
663+ std::unordered_set<double> used_scales;
664+
665+ for (unsigned i = 0; i < monitors; ++i)
666+ used_scales.insert(settings.em(i)->DPIScale());
667+
668+ for (auto it = unity_window_textures_.begin(); it != unity_window_textures_.end();)
669+ {
670+ if (used_scales.find(it->first) == used_scales.end())
671+ {
672+ it = unity_window_textures_.erase(it);
673+ }
674+ else
675+ {
676+ ++it;
677+ }
678+ }
679 }
680
681 UnityWindowStyle::Ptr const& UnityWindowStyle::Get()
682@@ -38,60 +133,38 @@
683 return instance;
684 }
685
686-int UnityWindowStyle::GetBorderSize() const
687-{
688- return 30; // as measured from textures
689-}
690-
691-int UnityWindowStyle::GetInternalOffset() const
692-{
693- return 20;
694-}
695-
696-int UnityWindowStyle::GetCloseButtonPadding() const
697-{
698- return 3;
699-}
700-
701-UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIcon()
702-{
703- if (!close_icon_)
704- close_icon_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close.png", -1, true));
705-
706- return close_icon_;
707-}
708-
709-UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIconHighligted()
710-{
711- if (!close_icon_highlighted_)
712- close_icon_highlighted_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close_highlight.png", -1, true));
713-
714- return close_icon_highlighted_;
715-}
716-
717-UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetCloseIconPressed()
718-{
719- if (!close_icon_pressed_)
720- close_icon_pressed_.Adopt(nux::CreateTexture2DFromFile(PKGDATADIR"/dialog_close_press.png", -1, true));
721-
722- return close_icon_pressed_;
723-}
724-
725-UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundTop() const
726-{
727- return background_top_;
728-}
729-
730-UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundLeft() const
731-{
732- return background_left_;
733-}
734-
735-UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetBackgroundCorner() const
736-{
737- return background_corner_;
738-}
739-
740-
741-}
742-}
743+int UnityWindowStyle::GetBorderSize(double scale) const
744+{
745+ return BORDER_SIZE.CP(scale); // as measured from textures
746+}
747+
748+int UnityWindowStyle::GetInternalOffset(double scale) const
749+{
750+ return INTERNAL_OFFSET.CP(scale);
751+}
752+
753+int UnityWindowStyle::GetCloseButtonPadding(double scale) const
754+{
755+ return CLOSE_PADDING.CP(scale);
756+}
757+
758+UnityWindowStyle::BaseTexturePtr UnityWindowStyle::GetTexture(double scale, WindowTextureType const& type)
759+{
760+ auto it = unity_window_textures_.find(scale);
761+ if (it == unity_window_textures_.end())
762+ {
763+ LoadAllTextureInScale(scale);
764+
765+ it = unity_window_textures_.find(scale);
766+ if (it == unity_window_textures_.end())
767+ {
768+ LOG_ERROR(logger) << "Failed to create unity window style textures, for scale size: " << scale;
769+ return BaseTexturePtr(nullptr);
770+ }
771+ }
772+
773+ return it->second[unsigned(type)];
774+}
775+
776+} // namespace ui
777+} // namespace unity
778
779=== modified file 'unity-shared/UnityWindowStyle.h'
780--- unity-shared/UnityWindowStyle.h 2013-12-11 02:24:29 +0000
781+++ unity-shared/UnityWindowStyle.h 2014-05-14 15:52:49 +0000
782@@ -16,6 +16,7 @@
783 *
784 * Authored by: Jason Smith <jason.smith@canonical.com>
785 * Marco Trevisan <marco.trevisan@canonical.com>
786+ * Brandon Schaefer <brandon.schaefer@canonical.com>
787 */
788
789 #ifndef UNITYWINDOWSTYLE_H
790@@ -24,8 +25,23 @@
791 #include <sigc++/sigc++.h>
792 #include <Nux/Nux.h>
793
794-namespace unity {
795-namespace ui {
796+#include "RawPixel.h"
797+
798+namespace unity
799+{
800+namespace ui
801+{
802+
803+enum class WindowTextureType : unsigned
804+{
805+ BACKGROUND_TOP,
806+ BACKGROUND_LEFT,
807+ BACKGROUND_CORNER,
808+ CLOSE_ICON,
809+ CLOSE_ICON_HIGHLIGHTED,
810+ CLOSE_ICON_PRESSED,
811+ Size
812+};
813
814 class UnityWindowStyle
815 {
816@@ -35,29 +51,28 @@
817
818 static UnityWindowStyle::Ptr const& Get();
819
820- BaseTexturePtr GetCloseIcon();
821- BaseTexturePtr GetCloseIconHighligted();
822- BaseTexturePtr GetCloseIconPressed();
823- int GetCloseButtonPadding() const;
824-
825- BaseTexturePtr GetBackgroundTop() const;
826- BaseTexturePtr GetBackgroundLeft() const;
827- BaseTexturePtr GetBackgroundCorner() const;
828- int GetBorderSize() const;
829- int GetInternalOffset() const;
830+ BaseTexturePtr GetTexture(double scale, WindowTextureType const& type);
831+ int GetCloseButtonPadding(double scale) const;
832+ int GetBorderSize(double scale) const;
833+ int GetInternalOffset(double scale) const;
834
835 private:
836 UnityWindowStyle();
837
838- BaseTexturePtr background_top_;
839- BaseTexturePtr background_left_;
840- BaseTexturePtr background_corner_;
841- BaseTexturePtr close_icon_;
842- BaseTexturePtr close_icon_highlighted_;
843- BaseTexturePtr close_icon_pressed_;
844+ void ReloadIcons();
845+ void LoadAllTextureInScale(double scale);
846+ nux::BaseTexture* LoadTexture(double scale, const char* const texture_name) const;
847+ RawPixel GetDefaultMaxTextureSize(const char* const texture_name) const;
848+
849+ void OnMonitorChanged(int primary, std::vector<nux::Geometry> const& monitors);
850+ void CleanUpUnusedTextures();
851+
852+ typedef std::array<BaseTexturePtr, size_t(WindowTextureType::Size)> UnityWindowTextures;
853+ std::unordered_map<double, UnityWindowTextures> unity_window_textures_;
854+
855 };
856
857-}
858-}
859+} // namespace ui
860+} // namespace unity
861
862 #endif
863
864=== modified file 'unity-shared/UnityWindowView.cpp'
865--- unity-shared/UnityWindowView.cpp 2014-02-05 12:19:45 +0000
866+++ unity-shared/UnityWindowView.cpp 2014-05-14 15:52:49 +0000
867@@ -32,6 +32,8 @@
868 : View(NUX_FILE_LINE_PARAM)
869 , style(UnityWindowStyle::Get())
870 , closable(false)
871+ , monitor(0)
872+ , scale(Settings::Instance().em()->DPIScale())
873 , internal_layout_(nullptr)
874 , bg_helper_(this)
875 {
876@@ -47,6 +49,8 @@
877
878 live_background = false;
879
880+ monitor.changed.connect(sigc::hide(sigc::mem_fun(this, &UnityWindowView::OnDPIChanged)));
881+ Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &UnityWindowView::OnDPIChanged));
882 closable.changed.connect(sigc::mem_fun(this, &UnityWindowView::OnClosableChanged));
883 background_color.changed.connect(sigc::hide(sigc::mem_fun(this, &View::QueueDraw)));
884 }
885@@ -60,6 +64,17 @@
886 bounding_area_->UnParentObject();
887 }
888
889+void UnityWindowView::OnDPIChanged()
890+{
891+ scale = Settings::Instance().em(monitor())->DPIScale();
892+
893+ if (internal_layout_)
894+ {
895+ int offset = style()->GetInternalOffset(scale);
896+ view_layout_->SetPadding(offset, offset);
897+ }
898+}
899+
900 void UnityWindowView::SetBackgroundHelperGeometryGetter(BackgroundEffectHelper::GeometryGetterFunc const& func)
901 {
902 bg_helper_.SetGeometryGetter(func);
903@@ -109,6 +124,11 @@
904 return View::FindKeyFocusArea(etype, key_code, modifiers);
905 }
906
907+void UnityWindowView::ReloadCloseButtonTexture()
908+{
909+ OnClosableChanged(closable);
910+}
911+
912 void UnityWindowView::OnClosableChanged(bool closable)
913 {
914 if (!closable)
915@@ -117,34 +137,38 @@
916 return;
917 }
918
919- auto const& texture = style()->GetCloseIcon();
920- int padding = style()->GetCloseButtonPadding();
921+ auto const& texture = style()->GetTexture(scale, WindowTextureType::CLOSE_ICON);
922+ int padding = style()->GetCloseButtonPadding(scale);
923+
924 close_button_ = new IconTexture(texture);
925 close_button_->SetBaseXY(padding, padding);
926 close_button_->SetParentObject(this);
927
928 close_button_->mouse_enter.connect([this](int, int, unsigned long, unsigned long) {
929 if (close_button_->IsMouseOwner())
930- close_button_->SetTexture(style()->GetCloseIconPressed());
931+ close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_PRESSED));
932 else
933- close_button_->SetTexture(style()->GetCloseIconHighligted());
934+ close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_HIGHLIGHTED));
935 });
936
937 close_button_->mouse_leave.connect([this](int, int, unsigned long, unsigned long) {
938- close_button_->SetTexture(style()->GetCloseIcon());
939+ close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON));
940 });
941
942 close_button_->mouse_down.connect([this](int, int, unsigned long, unsigned long) {
943- close_button_->SetTexture(style()->GetCloseIconPressed());
944+ close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_PRESSED));
945 });
946
947 close_button_->mouse_up.connect([this](int, int, unsigned long, unsigned long) {
948 bool inside = close_button_->IsMouseInside();
949- close_button_->SetTexture(inside ? style()->GetCloseIconHighligted() : style()->GetCloseIcon());
950+ if (inside)
951+ close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON_HIGHLIGHTED));
952+ else
953+ close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON));
954 });
955
956 close_button_->mouse_click.connect([this](int, int, unsigned long, unsigned long) {
957- close_button_->SetTexture(style()->GetCloseIcon());
958+ close_button_->SetTexture(style()->GetTexture(scale, WindowTextureType::CLOSE_ICON));
959 request_close.emit();
960 });
961
962@@ -155,7 +179,7 @@
963 {
964 if (layout && layout->IsLayout())
965 {
966- int offset = style()->GetInternalOffset();
967+ int offset = style()->GetInternalOffset(scale);
968
969 // We wrap the internal layout adding some padding, so that inherited classes
970 // can ignore the offsets we define here.
971@@ -180,7 +204,8 @@
972
973 nux::Geometry UnityWindowView::GetInternalBackground()
974 {
975- int offset = style()->GetInternalOffset();
976+ int offset = style()->GetInternalOffset(scale);
977+
978 return GetBackgroundGeometry().GetExpand(-offset, -offset);
979 }
980
981@@ -330,7 +355,9 @@
982
983 void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo)
984 {
985- int border = style()->GetBorderSize();
986+ int border = style()->GetBorderSize(scale);
987+
988+ auto background_corner_textrue = style()->GetTexture(scale, WindowTextureType::BACKGROUND_CORNER)->GetDeviceTexture();
989
990 GfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
991
992@@ -344,7 +371,7 @@
993 texxform.u1 = border;
994 texxform.v1 = border;
995 GfxContext.QRP_1Tex (geo.x, geo.y,
996- border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
997+ border, border, background_corner_textrue, texxform, nux::color::White);
998
999 // Draw TOP-RIGHT CORNER
1000 texxform.u0 = 0;
1001@@ -354,7 +381,7 @@
1002 texxform.flip_u_coord = true;
1003 texxform.flip_v_coord = false;
1004 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y,
1005- border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
1006+ border, border, background_corner_textrue, texxform, nux::color::White);
1007
1008 // Draw BOTTOM-LEFT CORNER
1009 texxform.u0 = 0;
1010@@ -364,7 +391,7 @@
1011 texxform.flip_u_coord = false;
1012 texxform.flip_v_coord = true;
1013 GfxContext.QRP_1Tex (geo.x, geo.y + geo.height - border,
1014- border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
1015+ border, border, background_corner_textrue, texxform, nux::color::White);
1016
1017 // Draw BOTTOM-RIGHT CORNER
1018 texxform.u0 = 0;
1019@@ -374,10 +401,11 @@
1020 texxform.flip_u_coord = true;
1021 texxform.flip_v_coord = true;
1022 GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + geo.height - border,
1023- border, border, style()->GetBackgroundCorner()->GetDeviceTexture(), texxform, nux::color::White);
1024+ border, border, background_corner_textrue, texxform, nux::color::White);
1025
1026- int top_width = style()->GetBackgroundTop()->GetWidth();
1027- int top_height = style()->GetBackgroundTop()->GetHeight();
1028+ auto background_top = style()->GetTexture(scale, WindowTextureType::BACKGROUND_TOP);
1029+ int top_width = background_top->GetWidth();
1030+ int top_height = background_top->GetHeight();
1031
1032 // Draw TOP BORDER
1033 texxform.u0 = 0;
1034@@ -386,7 +414,7 @@
1035 texxform.v1 = top_height;
1036 texxform.flip_u_coord = false;
1037 texxform.flip_v_coord = false;
1038- GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);
1039+ GfxContext.QRP_1Tex (geo.x + border, geo.y, geo.width - border - border, border, background_top->GetDeviceTexture(), texxform, nux::color::White);
1040
1041 // Draw BOTTOM BORDER
1042 texxform.u0 = 0;
1043@@ -395,11 +423,11 @@
1044 texxform.v1 = top_height;
1045 texxform.flip_u_coord = false;
1046 texxform.flip_v_coord = true;
1047- GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, style()->GetBackgroundTop()->GetDeviceTexture(), texxform, nux::color::White);
1048-
1049-
1050- int left_width = style()->GetBackgroundLeft()->GetWidth();
1051- int left_height = style()->GetBackgroundLeft()->GetHeight();
1052+ GfxContext.QRP_1Tex (geo.x + border, geo.y + geo.height - border, geo.width - border - border, border, background_top->GetDeviceTexture(), texxform, nux::color::White);
1053+
1054+ auto background_left = style()->GetTexture(scale, WindowTextureType::BACKGROUND_LEFT);
1055+ int left_width = background_left->GetWidth();
1056+ int left_height = background_left->GetHeight();
1057
1058 // Draw LEFT BORDER
1059 texxform.u0 = 0;
1060@@ -408,7 +436,7 @@
1061 texxform.v1 = left_height;
1062 texxform.flip_u_coord = false;
1063 texxform.flip_v_coord = false;
1064- GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);
1065+ GfxContext.QRP_1Tex (geo.x, geo.y + border, border, geo.height - border - border, background_left->GetDeviceTexture(), texxform, nux::color::White);
1066
1067 // Draw RIGHT BORDER
1068 texxform.u0 = 0;
1069@@ -417,7 +445,7 @@
1070 texxform.v1 = left_height;
1071 texxform.flip_u_coord = true;
1072 texxform.flip_v_coord = false;
1073- GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, style()->GetBackgroundLeft()->GetDeviceTexture(), texxform, nux::color::White);
1074+ GfxContext.QRP_1Tex (geo.x + geo.width - border, geo.y + border, border, geo.height - border - border, background_left->GetDeviceTexture(), texxform, nux::color::White);
1075
1076 GfxContext.GetRenderStates().SetBlend(false);
1077 }
1078
1079=== modified file 'unity-shared/UnityWindowView.h'
1080--- unity-shared/UnityWindowView.h 2013-11-21 16:06:58 +0000
1081+++ unity-shared/UnityWindowView.h 2014-05-14 15:52:49 +0000
1082@@ -23,6 +23,7 @@
1083
1084 #include "unity-shared/BackgroundEffectHelper.h"
1085 #include "unity-shared/IconTexture.h"
1086+
1087 #include "Introspectable.h"
1088 #include "UnityWindowStyle.h"
1089 #include <sigc++/sigc++.h>
1090@@ -41,6 +42,8 @@
1091 nux::Property<nux::Color> background_color;
1092 nux::Property<UnityWindowStyle::Ptr> style;
1093 nux::Property<bool> closable;
1094+ nux::Property<int> monitor;
1095+ nux::Property<double> scale;
1096
1097 UnityWindowView(NUX_FILE_LINE_PROTO);
1098 virtual ~UnityWindowView();
1099@@ -64,6 +67,8 @@
1100 virtual nux::Geometry GetBlurredBackgroundGeometry();
1101 void SetBackgroundHelperGeometryGetter(BackgroundEffectHelper::GeometryGetterFunc const&);
1102
1103+ void ReloadCloseButtonTexture();
1104+
1105 // Introspectable methods
1106 std::string GetName() const;
1107 void AddProperties(debug::IntrospectionData&);
1108@@ -71,6 +76,7 @@
1109 private:
1110 friend class TestUnityWindowView;
1111
1112+ void OnDPIChanged();
1113 void OnClosableChanged(bool closable);
1114 void DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo);
1115