Merge lp:~nick-dedekind/unity/lp765715.launcher-icon-shadow into lp:unity

Proposed by Nick Dedekind
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 2878
Proposed branch: lp:~nick-dedekind/unity/lp765715.launcher-icon-shadow
Merge into: lp:unity
Diff against target: 481 lines (+149/-100)
10 files modified
launcher/Launcher.cpp (+12/-44)
launcher/Launcher.h (+0/-3)
launcher/LauncherDragWindow.cpp (+20/-18)
launcher/LauncherDragWindow.h (+4/-4)
launcher/SoftwareCenterLauncherIcon.cpp (+2/-2)
unity-shared/CMakeLists.txt (+1/-0)
unity-shared/GraphicsUtils.cpp (+71/-0)
unity-shared/GraphicsUtils.h (+36/-0)
unity-shared/IconRenderer.cpp (+3/-25)
unity-shared/IconRenderer.h (+0/-4)
To merge this branch: bzr merge lp:~nick-dedekind/unity/lp765715.launcher-icon-shadow
Reviewer Review Type Date Requested Status
John Lea (community) design Approve
Andrea Azzarone (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+132461@code.launchpad.net

Commit message

Increase the size of the launcher icon drag window so the shadow is not cut off.

Description of the change

= Problem description =

https://bugs.launchpad.net/unity/+bug/765715
A shadow should appear on the right and bottom sides of a dragged launcher icon.

= The fix =

Increase the size of the launcher icon drag window so the shadow is not cut off.
Refactored drag launcher window to conform to unity variable naming conventions.

= Test coverage =

No test. Visual change.

https://bugs.launchpad.net/unity/+bug/765715/+attachment/3424675/+files/shadow.png

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

17 - , _render_drag_window(false)

Do we need to remove it from Launcher.h too?

295 + * Copyright (C) 2010 Canonical Ltd

2010? :)

348 + g_assert(rendering_stack.size() > 0);
351 + if (rendering_stack.size() > 0)

Please use std::stack::empty here.

review: Approve
Revision history for this message
John Lea (johnlea) :
review: Approve (design)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/Launcher.cpp'
2--- launcher/Launcher.cpp 2012-10-31 20:34:34 +0000
3+++ launcher/Launcher.cpp 2012-11-01 08:29:20 +0000
4@@ -49,6 +49,8 @@
5 #include "unity-shared/UScreen.h"
6 #include "unity-shared/UBusMessages.h"
7 #include "unity-shared/UnitySettings.h"
8+#include "unity-shared/GraphicsUtils.h"
9+
10
11 #include <UnityCore/GLibWrapper.h>
12 #include <UnityCore/Variant.h>
13@@ -114,7 +116,6 @@
14 , _active_quicklist(nullptr)
15 , _hovered(false)
16 , _hidden(false)
17- , _render_drag_window(false)
18 , _shortcuts_shown(false)
19 , _data_checked(false)
20 , _steal_drag(false)
21@@ -152,8 +153,6 @@
22
23 _collection_window->collected.connect(sigc::mem_fun(this, &Launcher::OnDNDDataCollected));
24
25- _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8);
26-
27 bg_effect_helper_.owner = this;
28 bg_effect_helper_.enabled = false;
29
30@@ -1757,13 +1756,6 @@
31 nux::Geometry const& geo_absolute = GetAbsoluteGeometry();
32 RenderArgs(args, bkg_box, &launcher_alpha, geo_absolute);
33 bkg_box.width -= RIGHT_LINE_WIDTH;
34-
35- if (_drag_icon && _render_drag_window)
36- {
37- RenderIconToTexture(GfxContext, _drag_icon, _offscreen_drag_texture);
38- _render_drag_window = false;
39- ShowDragWindow();
40- }
41
42 nux::Color clear_colour = nux::Color(0x00000000);
43
44@@ -2030,10 +2022,10 @@
45 _drag_icon_position = _model->IconIndex(icon);
46
47 HideDragWindow();
48- _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(_icon_size, _icon_size, 1, nux::BITFMT_R8G8B8A8);
49+ _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(GetWidth(), GetWidth(), 1, nux::BITFMT_R8G8B8A8);
50 _drag_window = new LauncherDragWindow(_offscreen_drag_texture);
51-
52- _render_drag_window = true;
53+ RenderIconToTexture(nux::GetWindowThread()->GetGraphicsEngine(), _drag_icon, _offscreen_drag_texture);
54+ ShowDragWindow();
55
56 ubus_.SendMessage(UBUS_LAUNCHER_ICON_START_DND);
57 }
58@@ -2077,8 +2069,6 @@
59 if (MouseBeyondDragThreshold())
60 TimeUtil::SetTimeStruct(&_times[TIME_DRAG_THRESHOLD], &_times[TIME_DRAG_THRESHOLD], ANIM_DURATION_SHORT);
61
62- _render_drag_window = false;
63-
64 _hide_machine.SetQuirk(LauncherHideMachine::INTERNAL_DND_ACTIVE, false);
65 ubus_.SendMessage(UBUS_LAUNCHER_ICON_END_DND);
66 }
67@@ -2503,7 +2493,7 @@
68 clock_gettime(CLOCK_MONOTONIC, &current);
69
70 SetupRenderArg(icon, current, arg);
71- arg.render_center = nux::Point3(roundf(_icon_size / 2.0f), roundf(_icon_size / 2.0f), 0.0f);
72+ arg.render_center = nux::Point3(roundf(texture->GetWidth() / 2.0f), roundf(texture->GetHeight() / 2.0f), 0.0f);
73 arg.logical_center = arg.render_center;
74 arg.x_rotation = 0.0f;
75 arg.running_arrow = false;
76@@ -2515,7 +2505,7 @@
77 std::list<RenderArg> drag_args;
78 drag_args.push_front(arg);
79
80- SetOffscreenRenderTarget(texture);
81+ graphics::PushOffscreenRenderTarget(texture);
82
83 unsigned int alpha = 0, src = 0, dest = 0;
84 GfxContext.GetRenderStates().GetBlend(alpha, src, dest);
85@@ -2529,9 +2519,11 @@
86
87 GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
88
89- icon_renderer->PreprocessIcons(drag_args, nux::Geometry(0, 0, _icon_size, _icon_size));
90- icon_renderer->RenderIcon(nux::GetWindowThread()->GetGraphicsEngine(), arg, nux::Geometry(0, 0, _icon_size, _icon_size), nux::Geometry(0, 0, _icon_size, _icon_size));
91- RestoreSystemRenderTarget();
92+ nux::Geometry geo(0, 0, texture->GetWidth(), texture->GetWidth());
93+
94+ icon_renderer->PreprocessIcons(drag_args, geo);
95+ icon_renderer->RenderIcon(GfxContext, arg, geo, geo);
96+ unity::graphics::PopOffscreenRenderTarget();
97 }
98
99 nux::GestureDeliveryRequest Launcher::GestureEvent(const nux::GestureEvent &event)
100@@ -2552,30 +2544,6 @@
101 return nux::GestureDeliveryRequest::NONE;
102 }
103
104-void
105-Launcher::SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture)
106-{
107- int width = texture->GetWidth();
108- int height = texture->GetHeight();
109-
110- auto graphics_display = nux::GetGraphicsDisplay();
111- auto gpu_device = graphics_display->GetGpuDevice();
112- gpu_device->FormatFrameBufferObject(width, height, nux::BITFMT_R8G8B8A8);
113- gpu_device->SetColorRenderTargetSurface(0, texture->GetSurfaceLevel(0));
114- gpu_device->ActivateFrameBuffer();
115-
116- auto graphics_engine = graphics_display->GetGraphicsEngine();
117- graphics_engine->SetContext(0, 0, width, height);
118- graphics_engine->SetViewport(0, 0, width, height);
119- graphics_engine->Push2DWindow(width, height);
120- graphics_engine->EmptyClippingRegion();
121-}
122-
123-void Launcher::RestoreSystemRenderTarget()
124-{
125- nux::GetWindowCompositor().RestoreRenderingSurface();
126-}
127-
128 bool Launcher::DndIsSpecialRequest(std::string const& uri) const
129 {
130 return (boost::algorithm::ends_with(uri, ".desktop") || uri.find("device://") == 0);
131
132=== modified file 'launcher/Launcher.h'
133--- launcher/Launcher.h 2012-10-29 09:34:54 +0000
134+++ launcher/Launcher.h 2012-11-01 08:29:20 +0000
135@@ -317,9 +317,6 @@
136
137 virtual long PostLayoutManagement(long LayoutResult);
138
139- void SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
140- void RestoreSystemRenderTarget();
141-
142 void OnDisplayChanged(Display* display);
143 void OnDNDDataCollected(const std::list<char*>& mimes);
144
145
146=== modified file 'launcher/LauncherDragWindow.cpp'
147--- launcher/LauncherDragWindow.cpp 2012-10-11 01:44:15 +0000
148+++ launcher/LauncherDragWindow.cpp 2012-11-01 08:29:20 +0000
149@@ -35,17 +35,19 @@
150 {
151 const float QUICK_ANIMATION_SPEED = 0.3f;
152 const float SLOW_ANIMATION_SPEED = 0.05f;
153+
154+ const int ANIMATION_THRESHOLD = 5;
155 }
156
157 NUX_IMPLEMENT_OBJECT_TYPE(LauncherDragWindow);
158
159-LauncherDragWindow::LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> icon)
160+LauncherDragWindow::LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture)
161 : nux::BaseWindow("")
162 , animation_speed_(QUICK_ANIMATION_SPEED)
163- , _cancelled(false)
164- , _icon(icon)
165+ , cancelled_(false)
166+ , texture_(texture)
167 {
168- SetBaseSize(_icon->GetWidth(), _icon->GetHeight());
169+ SetBaseSize(texture_->GetWidth(), texture_->GetHeight());
170
171 key_down.connect([this] (unsigned long, unsigned long keysym, unsigned long, const char*, unsigned short) {
172 if (keysym == NUX_VK_ESCAPE)
173@@ -72,18 +74,18 @@
174
175 bool LauncherDragWindow::Cancelled() const
176 {
177- return _cancelled;
178+ return cancelled_;
179 }
180
181 void LauncherDragWindow::CancelDrag()
182 {
183- _cancelled = true;
184+ cancelled_ = true;
185 drag_cancel_request.emit();
186 }
187
188 void LauncherDragWindow::SetAnimationTarget(int x, int y)
189 {
190- _animation_target = nux::Point2(x, y);
191+ animation_target_ = nux::Point2(x, y);
192 }
193
194 void LauncherDragWindow::StartQuickAnimation()
195@@ -113,16 +115,16 @@
196
197 int half_size = geo.width / 2;
198
199- int target_x = static_cast<int>(_animation_target.x) - half_size;
200- int target_y = static_cast<int>(_animation_target.y) - half_size;
201+ int target_x = static_cast<int>(animation_target_.x) - half_size;
202+ int target_y = static_cast<int>(animation_target_.y) - half_size;
203
204 int x_delta = static_cast<int>(static_cast<float>(target_x - geo.x) * animation_speed_);
205- if (std::abs(x_delta) < 5)
206- x_delta = (x_delta >= 0) ? std::min(5, target_x - geo.x) : std::max(-5, target_x - geo.x);
207+ if (std::abs(x_delta) < ANIMATION_THRESHOLD)
208+ x_delta = (x_delta >= 0) ? std::min(ANIMATION_THRESHOLD, target_x - geo.x) : std::max(-ANIMATION_THRESHOLD, target_x - geo.x);
209
210 int y_delta = static_cast<int>(static_cast<float>(target_y - geo.y) * animation_speed_);
211- if (std::abs(y_delta) < 5)
212- y_delta = (y_delta >= 0) ? std::min(5, target_y - geo.y) : std::max(-5, target_y - geo.y);
213+ if (std::abs(y_delta) < ANIMATION_THRESHOLD)
214+ y_delta = (y_delta >= 0) ? std::min(ANIMATION_THRESHOLD, target_y - geo.y) : std::max(-ANIMATION_THRESHOLD, target_y - geo.y);
215
216 SetBaseXY(geo.x + x_delta, geo.y + y_delta);
217
218@@ -151,11 +153,11 @@
219 nux::TexCoordXForm texxform;
220 texxform.FlipVCoord(true);
221
222- GfxContext.QRP_1Tex(0,
223- 0,
224- _icon->GetWidth(),
225- _icon->GetHeight(),
226- _icon,
227+ GfxContext.QRP_1Tex(geo.x,
228+ geo.y,
229+ texture_->GetWidth(),
230+ texture_->GetHeight(),
231+ texture_,
232 texxform,
233 nux::color::White);
234
235
236=== modified file 'launcher/LauncherDragWindow.h'
237--- launcher/LauncherDragWindow.h 2012-09-13 00:48:06 +0000
238+++ launcher/LauncherDragWindow.h 2012-11-01 08:29:20 +0000
239@@ -36,7 +36,7 @@
240 {
241 NUX_DECLARE_OBJECT_TYPE(LauncherDragWindow, nux::BaseWindow);
242 public:
243- LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> icon);
244+ LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
245 ~LauncherDragWindow();
246
247 void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
248@@ -62,9 +62,9 @@
249 void CancelDrag();
250
251 float animation_speed_;
252- bool _cancelled;
253- nux::ObjectPtr<nux::IOpenGLBaseTexture> _icon;
254- nux::Point2 _animation_target;
255+ bool cancelled_;
256+ nux::ObjectPtr<nux::IOpenGLBaseTexture> texture_;
257+ nux::Point2 animation_target_;
258 glib::Source::UniquePtr animation_timer_;
259 };
260
261
262=== modified file 'launcher/SoftwareCenterLauncherIcon.cpp'
263--- launcher/SoftwareCenterLauncherIcon.cpp 2012-10-17 11:08:05 +0000
264+++ launcher/SoftwareCenterLauncherIcon.cpp 2012-11-01 08:29:20 +0000
265@@ -68,8 +68,8 @@
266 launcher_ = launcher;
267
268 icon_texture_ = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(
269- launcher->GetIconSize(),
270- launcher->GetIconSize(),
271+ launcher->GetWidth(),
272+ launcher->GetWidth(),
273 1,
274 nux::BITFMT_R8G8B8A8);
275
276
277=== modified file 'unity-shared/CMakeLists.txt'
278--- unity-shared/CMakeLists.txt 2012-10-18 10:44:07 +0000
279+++ unity-shared/CMakeLists.txt 2012-11-01 08:29:20 +0000
280@@ -34,6 +34,7 @@
281 DashStyle.cpp
282 DefaultThumbnailProvider.cpp
283 FontSettings.cpp
284+ GraphicsUtils.cpp
285 IMTextEntry.cpp
286 IconLoader.cpp
287 IconRenderer.cpp
288
289=== added file 'unity-shared/GraphicsUtils.cpp'
290--- unity-shared/GraphicsUtils.cpp 1970-01-01 00:00:00 +0000
291+++ unity-shared/GraphicsUtils.cpp 2012-11-01 08:29:20 +0000
292@@ -0,0 +1,71 @@
293+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
294+/*
295+ * Copyright (C) 2010 Canonical Ltd
296+ *
297+ * This program is free software: you can redistribute it and/or modify
298+ * it under the terms of the GNU General Public License version 3 as
299+ * published by the Free Software Foundation.
300+ *
301+ * This program is distributed in the hope that it will be useful,
302+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
303+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304+ * GNU General Public License for more details.
305+ *
306+ * You should have received a copy of the GNU General Public License
307+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
308+ *
309+ * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
310+ */
311+
312+#include "GraphicsUtils.h"
313+#include <NuxGraphics/GLTextureResourceManager.h>
314+
315+namespace unity
316+{
317+namespace graphics
318+{
319+
320+std::stack<nux::ObjectPtr<nux::IOpenGLBaseTexture>> rendering_stack;
321+
322+void PushOffscreenRenderTarget_(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture)
323+{
324+ int width = texture->GetWidth();
325+ int height = texture->GetHeight();
326+
327+ auto graphics_display = nux::GetGraphicsDisplay();
328+ auto gpu_device = graphics_display->GetGpuDevice();
329+ gpu_device->FormatFrameBufferObject(width, height, nux::BITFMT_R8G8B8A8);
330+ gpu_device->SetColorRenderTargetSurface(0, texture->GetSurfaceLevel(0));
331+ gpu_device->ActivateFrameBuffer();
332+
333+ auto graphics_engine = graphics_display->GetGraphicsEngine();
334+ graphics_engine->SetContext(0, 0, width, height);
335+ graphics_engine->SetViewport(0, 0, width, height);
336+ graphics_engine->Push2DWindow(width, height);
337+ graphics_engine->EmptyClippingRegion();
338+}
339+
340+void PushOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture)
341+{
342+ PushOffscreenRenderTarget_(texture);
343+ rendering_stack.push(texture);
344+}
345+
346+void PopOffscreenRenderTarget()
347+{
348+ g_assert(rendering_stack.size() > 0);
349+
350+ rendering_stack.pop();
351+ if (rendering_stack.size() > 0)
352+ {
353+ nux::ObjectPtr<nux::IOpenGLBaseTexture>& texture = rendering_stack.top();
354+ PushOffscreenRenderTarget_(texture);
355+ }
356+ else
357+ {
358+ nux::GetWindowCompositor().RestoreRenderingSurface();
359+ }
360+}
361+
362+}
363+}
364\ No newline at end of file
365
366=== added file 'unity-shared/GraphicsUtils.h'
367--- unity-shared/GraphicsUtils.h 1970-01-01 00:00:00 +0000
368+++ unity-shared/GraphicsUtils.h 2012-11-01 08:29:20 +0000
369@@ -0,0 +1,36 @@
370+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
371+/*
372+ * Copyright (C) 2010 Canonical Ltd
373+ *
374+ * This program is free software: you can redistribute it and/or modify
375+ * it under the terms of the GNU General Public License version 3 as
376+ * published by the Free Software Foundation.
377+ *
378+ * This program is distributed in the hope that it will be useful,
379+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
380+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
381+ * GNU General Public License for more details.
382+ *
383+ * You should have received a copy of the GNU General Public License
384+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
385+ *
386+ * Authored by: Nick Dedekind <nick.dedekind@canonical.com>
387+ */
388+
389+#ifndef UNITY_GRAPHICS_ADAPTER
390+#define UNITY_GRAPHICS_ADAPTER
391+
392+#include <Nux/Nux.h>
393+
394+namespace unity
395+{
396+namespace graphics
397+{
398+
399+void PushOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
400+void PopOffscreenRenderTarget();
401+
402+}
403+}
404+
405+#endif // UNITY_GRAPHICS_ADAPTER
406\ No newline at end of file
407
408=== modified file 'unity-shared/IconRenderer.cpp'
409--- unity-shared/IconRenderer.cpp 2012-10-17 22:13:25 +0000
410+++ unity-shared/IconRenderer.cpp 2012-11-01 08:29:20 +0000
411@@ -26,6 +26,7 @@
412 #include <NuxGraphics/GLTextureResourceManager.h>
413
414 #include <NuxGraphics/CairoGraphics.h>
415+#include "GraphicsUtils.h"
416
417 #include <gtk/gtk.h>
418
419@@ -1010,7 +1011,7 @@
420 int progress_y = fill_y + (fill_height - progress_height) / 2;
421 int half_size = (right_edge - left_edge) / 2;
422
423- SetOffscreenRenderTarget(texture);
424+ unity::graphics::PushOffscreenRenderTarget(texture);
425
426 // FIXME
427 glClear(GL_COLOR_BUFFER_BIT);
428@@ -1041,7 +1042,7 @@
429
430 GfxContext.PopClippingRectangle();
431
432- RestoreSystemRenderTarget();
433+ unity::graphics::PopOffscreenRenderTarget();
434 }
435
436 void IconRenderer::DestroyTextures()
437@@ -1134,29 +1135,6 @@
438 PerspectiveMatrix.Perspective(Fovy, AspectRatio, NearClipPlane, FarClipPlane);
439 }
440
441-void
442-IconRenderer::SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture)
443-{
444- int width = texture->GetWidth();
445- int height = texture->GetHeight();
446-
447- nux::GetGraphicsDisplay()->GetGpuDevice()->FormatFrameBufferObject(width, height, nux::BITFMT_R8G8B8A8);
448- nux::GetGraphicsDisplay()->GetGpuDevice()->SetColorRenderTargetSurface(0, texture->GetSurfaceLevel(0));
449- nux::GetGraphicsDisplay()->GetGpuDevice()->ActivateFrameBuffer();
450-
451- nux::GetGraphicsDisplay()->GetGraphicsEngine()->SetContext(0, 0, width, height);
452- nux::GetGraphicsDisplay()->GetGraphicsEngine()->SetViewport(0, 0, width, height);
453- nux::GetGraphicsDisplay()->GetGraphicsEngine()->Push2DWindow(width, height);
454- nux::GetGraphicsDisplay()->GetGraphicsEngine()->EmptyClippingRegion();
455-}
456-
457-void
458-IconRenderer::RestoreSystemRenderTarget()
459-{
460- nux::GetWindowCompositor().RestoreRenderingSurface();
461-}
462-
463-
464 // The local namespace is purely for namespacing the file local variables below.
465 namespace local
466 {
467
468=== modified file 'unity-shared/IconRenderer.h'
469--- unity-shared/IconRenderer.h 2012-10-11 20:01:44 +0000
470+++ unity-shared/IconRenderer.h 2012-11-01 08:29:20 +0000
471@@ -84,10 +84,6 @@
472 float FarClipPlane,
473 float Fovy);
474
475- void SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
476-
477- void RestoreSystemRenderTarget();
478-
479 private:
480 int icon_size;
481 int image_size;