Merge lp:~gordallott/unity/fix-horizontal-renderer into lp:unity

Proposed by Gord Allott
Status: Superseded
Proposed branch: lp:~gordallott/unity/fix-horizontal-renderer
Merge into: lp:unity
Diff against target: 527 lines (+135/-95)
6 files modified
plugins/unityshell/src/PlacesStyle.cpp (+2/-2)
plugins/unityshell/src/ResultRendererHorizontalTile.cpp (+36/-31)
plugins/unityshell/src/ResultRendererHorizontalTile.h (+1/-1)
plugins/unityshell/src/ResultRendererTile.cpp (+74/-43)
plugins/unityshell/src/ResultRendererTile.h (+5/-1)
plugins/unityshell/src/ResultViewGrid.cpp (+17/-17)
To merge this branch: bzr merge lp:~gordallott/unity/fix-horizontal-renderer
Reviewer Review Type Date Requested Status
Neil J. Patel Pending
Review via email: mp+75227@code.launchpad.net

This proposal has been superseded by a proposal from 2011-09-14.

Description of the change

fixes the horizontal renderer, a method was not virtual when it should of been so the comment drawing code never got called.

also fixed a slight cutoff issue

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/PlacesStyle.cpp'
2--- plugins/unityshell/src/PlacesStyle.cpp 2011-09-08 02:05:01 +0000
3+++ plugins/unityshell/src/PlacesStyle.cpp 2011-09-13 17:11:25 +0000
4@@ -96,7 +96,7 @@
5
6 int PlacesStyle::GetTileIconSize() const
7 {
8- return 48;
9+ return 64;
10 }
11
12 int PlacesStyle::GetTileWidth() const
13@@ -106,7 +106,7 @@
14
15 int PlacesStyle::GetTileHeight() const
16 {
17- return GetTileIconSize() + (_text_height * 4);
18+ return GetTileIconSize() + (_text_height * 4) + 12;
19 }
20
21 int PlacesStyle::GetHomeTileIconSize() const
22
23=== modified file 'plugins/unityshell/src/ResultRendererHorizontalTile.cpp'
24--- plugins/unityshell/src/ResultRendererHorizontalTile.cpp 2011-09-05 00:46:13 +0000
25+++ plugins/unityshell/src/ResultRendererHorizontalTile.cpp 2011-09-13 17:11:25 +0000
26@@ -53,13 +53,14 @@
27 {
28 PlacesStyle* style = PlacesStyle::GetDefault();
29 width = style->GetTileWidth() * 2;
30- height = style->GetTileIconSize() + 4;
31+ height = style->GetTileIconSize() + (padding * 2);
32
33 // pre-load the highlight texture
34 // try and get a texture from the texture cache
35 TextureCache& cache = TextureCache::GetDefault();
36 prelight_cache_ = cache.FindTexture("ResultRendererHorizontalTile.PreLightTexture",
37- style->GetTileIconSize() + 8, style->GetTileIconSize() + 8,
38+ style->GetTileIconSize() + (highlight_padding * 2),
39+ style->GetTileIconSize() + (highlight_padding * 2),
40 sigc::mem_fun(this, &ResultRendererHorizontalTile::DrawHighlight));
41 }
42
43@@ -73,6 +74,10 @@
44 nux::Geometry& geometry,
45 int x_offset, int y_offset)
46 {
47+ TextureContainer* container = row.renderer<TextureContainer*>();
48+ if (container == nullptr)
49+ return;
50+
51 std::string row_text = row.name;
52 std::string row_iconhint = row.icon_hint;
53 PlacesStyle* style = PlacesStyle::GetDefault();
54@@ -97,14 +102,16 @@
55 geometry.height,
56 col);
57
58- TextureContainer *container = row.renderer<TextureContainer*>();
59+ int icon_left_hand_side = geometry.x + padding;
60+ int icon_top_side = geometry.y + ((geometry.height - style->GetTileIconSize()) / 2);
61+
62
63 if (container->blurred_icon)
64 {
65- GfxContext.QRP_1Tex(geometry.x + 2 - x_offset,
66- geometry.y + ((geometry.height - style->GetTileIconSize()) / 2 - y_offset),
67- style->GetTileIconSize() + 4,
68- style->GetTileIconSize() + 4,
69+ GfxContext.QRP_1Tex(icon_left_hand_side - 5 - x_offset,
70+ icon_top_side - 5 - y_offset,
71+ style->GetTileIconSize() + 10,
72+ style->GetTileIconSize() + 10,
73 container->blurred_icon->GetDeviceTexture(),
74 texxform,
75 nux::Color(0.5f, 0.5f, 0.5f, 0.5f));
76@@ -113,40 +120,38 @@
77 // render highlight if its needed
78 if (state != ResultRendererState::RESULT_RENDERER_NORMAL)
79 {
80- GfxContext.QRP_1Tex(geometry.x,
81- geometry.y + ((geometry.height - style->GetTileIconSize()) / 2) - 4,
82- style->GetTileIconSize() + 8,
83- style->GetTileIconSize() + 8,
84+ GfxContext.QRP_1Tex(icon_left_hand_side - highlight_padding,
85+ icon_top_side - highlight_padding,
86+ style->GetTileIconSize() + (highlight_padding * 2),
87+ style->GetTileIconSize() + (highlight_padding * 2),
88 prelight_cache_->GetDeviceTexture(),
89 texxform,
90 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
91 }
92
93-
94+ // draw the icon
95+ if (container->icon)
96+ {
97+ GfxContext.QRP_1Tex(icon_left_hand_side,
98+ icon_top_side,
99+ style->GetTileIconSize(),
100+ style->GetTileIconSize(),
101+ container->icon->GetDeviceTexture(),
102+ texxform,
103+ nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
104+ }
105
106 if (container->text)
107 {
108- GfxContext.QRP_1Tex(geometry.x + style->GetTileIconSize() + 6,
109- geometry.y + 2,
110+ GfxContext.QRP_1Tex(icon_left_hand_side + style->GetTileIconSize() + spacing,
111+ icon_top_side,
112 width() - style->GetTileIconSize(),
113- style->GetTileIconSize() - 4,
114+ height() - (padding * 2),
115 container->text->GetDeviceTexture(),
116 texxform,
117 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
118 }
119
120- // draw the icon
121- if (container->icon)
122- {
123- GfxContext.QRP_1Tex(geometry.x + 4,
124- geometry.y + ((geometry.height - style->GetTileIconSize()) / 2),
125- style->GetTileIconSize(),
126- style->GetTileIconSize(),
127- container->icon->GetDeviceTexture(),
128- texxform,
129- nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
130- }
131-
132 GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
133
134 }
135@@ -224,8 +229,8 @@
136
137 PlacesStyle* style = PlacesStyle::GetDefault();
138 nux::CairoGraphics _cairoGraphics(CAIRO_FORMAT_ARGB32,
139- width() - style->GetTileIconSize(),
140- height() - 4);
141+ width() - style->GetTileIconSize() + spacing,
142+ height() - (padding * 2));
143
144 cairo_t* cr = _cairoGraphics.GetContext();
145
146@@ -248,8 +253,8 @@
147
148 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
149 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
150- pango_layout_set_width(layout, (width() - style->GetTileIconSize())* PANGO_SCALE);
151- pango_layout_set_height(layout, (height() - 4) * PANGO_SCALE);
152+ pango_layout_set_width(layout, (width() - style->GetTileIconSize() - spacing)* PANGO_SCALE);
153+ pango_layout_set_height(layout, (height() - (padding * 2)) * PANGO_SCALE);
154
155 pango_layout_set_markup(layout, final_text.str().c_str(), -1);
156
157
158=== modified file 'plugins/unityshell/src/ResultRendererHorizontalTile.h'
159--- plugins/unityshell/src/ResultRendererHorizontalTile.h 2011-09-06 18:30:26 +0000
160+++ plugins/unityshell/src/ResultRendererHorizontalTile.h 2011-09-13 17:11:25 +0000
161@@ -54,7 +54,7 @@
162 int x_offset, int y_offset);
163
164 protected:
165- void LoadText(Result& row);
166+ virtual void LoadText(Result& row);
167
168 private:
169 nux::BaseTexture* DrawHighlight(std::string const& texid,
170
171=== modified file 'plugins/unityshell/src/ResultRendererTile.cpp'
172--- plugins/unityshell/src/ResultRendererTile.cpp 2011-09-08 09:32:32 +0000
173+++ plugins/unityshell/src/ResultRendererTile.cpp 2011-09-13 17:11:25 +0000
174@@ -44,6 +44,11 @@
175 //~ nux::logging::Logger logger("unity.dash.ResultRendererTile");
176 //~ }
177
178+namespace
179+{
180+ bool neko;
181+}
182+
183 namespace unity
184 {
185 namespace dash
186@@ -52,16 +57,25 @@
187
188 ResultRendererTile::ResultRendererTile(NUX_FILE_LINE_DECL)
189 : ResultRenderer(NUX_FILE_LINE_PARAM)
190+ , highlight_padding(6)
191+ , spacing(12)
192+ , padding(6)
193 {
194 PlacesStyle* style = PlacesStyle::GetDefault();
195 width = style->GetTileWidth();
196- height = style->GetTileHeight();;
197+ height = style->GetTileHeight();
198+
199+ gsize tmp;
200+ gchar* tmp1 = (gchar*)g_base64_decode("VU5JVFlfTkVLTw==", &tmp);
201+ neko = (g_getenv(tmp1));
202+ g_free (tmp1);
203
204 // pre-load the highlight texture
205 // try and get a texture from the texture cache
206 TextureCache& cache = TextureCache::GetDefault();
207 prelight_cache_ = cache.FindTexture("ResultRendererTile.PreLightTexture",
208- 62, 62,
209+ style->GetTileIconSize() + (highlight_padding * 2),
210+ style->GetTileIconSize() + (highlight_padding * 2),
211 sigc::mem_fun(this, &ResultRendererTile::DrawHighlight));
212 }
213
214@@ -103,12 +117,16 @@
215 geometry.height,
216 col);
217
218+ int icon_left_hand_side = geometry.x + (geometry.width - style->GetTileIconSize()) / 2;
219+ int icon_top_side = geometry.y + padding;
220+
221+
222 if (container->blurred_icon)
223 {
224- GfxContext.QRP_1Tex(geometry.x + ((geometry.width - 58) / 2) - x_offset,
225- geometry.y + 1 - y_offset,
226- 58,
227- 58,
228+ GfxContext.QRP_1Tex(icon_left_hand_side - 5 - x_offset,
229+ icon_top_side - 5 - y_offset,
230+ style->GetTileIconSize() + 10,
231+ style->GetTileIconSize() + 10,
232 container->blurred_icon->GetDeviceTexture(),
233 texxform,
234 nux::Color(0.5f, 0.5f, 0.5f, 0.5f));
235@@ -117,40 +135,40 @@
236 // render highlight if its needed
237 if (state != ResultRendererState::RESULT_RENDERER_NORMAL)
238 {
239- GfxContext.QRP_1Tex(geometry.x + ((geometry.width - 62) / 2),
240- geometry.y + 2,
241- 62,
242- 62,
243+ GfxContext.QRP_1Tex(icon_left_hand_side - highlight_padding,
244+ icon_top_side - highlight_padding,
245+ style->GetTileIconSize() + (highlight_padding * 2),
246+ style->GetTileIconSize() + (highlight_padding * 2),
247 prelight_cache_->GetDeviceTexture(),
248 texxform,
249 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
250 }
251
252- if (container->text)
253- {
254- GfxContext.QRP_1Tex(geometry.x + 6,
255- geometry.y + style->GetTileIconSize() + 14,
256- style->GetTileWidth() - 12,
257- style->GetTileHeight() - style->GetTileIconSize() - 12,
258- container->text->GetDeviceTexture(),
259- texxform,
260- nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
261-
262-
263- }
264-
265 // draw the icon
266 if (container->icon)
267 {
268- GfxContext.QRP_1Tex(geometry.x + ((geometry.width - 48) / 2),
269- geometry.y + 9,
270- 48,
271- 48,
272+ GfxContext.QRP_1Tex(icon_left_hand_side,
273+ icon_top_side,
274+ style->GetTileIconSize(),
275+ style->GetTileIconSize(),
276 container->icon->GetDeviceTexture(),
277 texxform,
278 nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
279 }
280
281+ if (container->text)
282+ {
283+ GfxContext.QRP_1Tex(geometry.x + padding,
284+ geometry.y + style->GetTileIconSize() + spacing,
285+ style->GetTileWidth() - (padding * 2),
286+ style->GetTileHeight() - style->GetTileIconSize() - spacing,
287+ container->text->GetDeviceTexture(),
288+ texxform,
289+ nux::Color(1.0f, 1.0f, 1.0f, 1.0f));
290+
291+
292+ }
293+
294 GfxContext.GetRenderStates().SetBlend(alpha, src, dest);
295
296 }
297@@ -240,43 +258,52 @@
298
299 void ResultRendererTile::LoadIcon(Result& row)
300 {
301+ PlacesStyle* style = PlacesStyle::GetDefault();
302 std::string const& icon_hint = row.icon_hint;
303 #define DEFAULT_GICON ". GThemedIcon text-x-preview"
304 std::string icon_name;
305- gsize tmp4;
306- gchar* tmp5 = (gchar*)g_base64_decode("VU5JVFlfTkVLTw==", &tmp4);
307- if (g_getenv(tmp5))
308+ if (neko)
309 {
310- int tmp1 = 48 + (rand() % 16) - 8;
311+ int tmp1 = style->GetTileIconSize() + (rand() % 16) - 8;
312 gsize tmp3;
313 gchar* tmp2 = (gchar*)g_base64_decode("aHR0cDovL3BsYWNla2l0dGVuLmNvbS8laS8laS8=", &tmp3);
314- // FIXME: this leaks
315- icon_name = g_strdup_printf(tmp2, tmp1, tmp1);
316+ gchar* tmp4 = g_strdup_printf(tmp2, tmp1, tmp1);
317+ icon_name = tmp4;
318+ g_free(tmp4);
319 g_free(tmp2);
320 }
321 else
322 {
323 icon_name = !icon_hint.empty() ? icon_hint : DEFAULT_GICON;
324 }
325- g_free(tmp5);
326+
327+ if (g_str_has_prefix(icon_name.c_str(), "/"))
328+ {
329+ // absolute filename, check to see if it exists first
330+ glib::Object<GFile> file(g_file_new_for_path(icon_name.c_str()));
331+ if (g_file_query_exists(file, NULL) == false)
332+ {
333+ icon_name = DEFAULT_GICON;
334+ }
335+ }
336
337 GIcon* icon = g_icon_new_for_string(icon_name.c_str(), NULL);
338 TextureContainer* container = row.renderer<TextureContainer*>();
339
340 IconLoader::IconLoaderCallback slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_hint, row);
341
342- if (g_str_has_prefix(icon_name.c_str(), "http://"))
343+ if (g_strrstr(icon_name.c_str(), "://"))
344 {
345- container->slot_handle = IconLoader::GetDefault().LoadFromURI(icon_name.c_str(), 48, slot);
346+ container->slot_handle = IconLoader::GetDefault().LoadFromURI(icon_name.c_str(), style->GetTileIconSize(), slot);
347 }
348 else if (G_IS_ICON(icon))
349 {
350- container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name.c_str(), 48, slot);
351+ container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name.c_str(), style->GetTileIconSize(), slot);
352 g_object_unref(icon);
353 }
354 else
355 {
356- container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name.c_str(), 48, slot);
357+ container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name.c_str(), style->GetTileIconSize(), slot);
358 }
359 }
360
361@@ -321,13 +348,17 @@
362 Result& row)
363 {
364 TextureContainer *container = row.renderer<TextureContainer*>();
365+ PlacesStyle* style = PlacesStyle::GetDefault();
366+
367 if (pixbuf && container)
368 {
369 TextureCache& cache = TextureCache::GetDefault();
370- BaseTexturePtr texture(cache.FindTexture(icon_name, 48, 48, sigc::bind(sigc::mem_fun(this, &ResultRendererTile::CreateTextureCallback), pixbuf)));
371+ BaseTexturePtr texture(cache.FindTexture(icon_name, style->GetTileIconSize(), style->GetTileIconSize(),
372+ sigc::bind(sigc::mem_fun(this, &ResultRendererTile::CreateTextureCallback), pixbuf)));
373
374 std::string blur_texid = icon_name + "_blurred";
375- BaseTexturePtr texture_blurred(cache.FindTexture(blur_texid, 48, 48, sigc::bind(sigc::mem_fun(this, &ResultRendererTile::CreateBlurredTextureCallback), pixbuf)));
376+ BaseTexturePtr texture_blurred(cache.FindTexture(blur_texid, style->GetTileIconSize(), style->GetTileIconSize(),
377+ sigc::bind(sigc::mem_fun(this, &ResultRendererTile::CreateBlurredTextureCallback), pixbuf)));
378
379 container->icon = texture;
380 container->blurred_icon = texture_blurred;
381@@ -344,8 +375,8 @@
382 {
383 PlacesStyle* style = PlacesStyle::GetDefault();
384 nux::CairoGraphics _cairoGraphics(CAIRO_FORMAT_ARGB32,
385- style->GetTileWidth(),
386- style->GetTileHeight() - style->GetTileIconSize() - 12);
387+ style->GetTileWidth() - (padding * 2),
388+ style->GetTileHeight() - style->GetTileIconSize() - spacing);
389
390 cairo_t* cr = _cairoGraphics.GetContext();
391
392@@ -368,7 +399,7 @@
393
394 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
395 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_START);
396- pango_layout_set_width(layout, (style->GetTileWidth() - 12)* PANGO_SCALE);
397+ pango_layout_set_width(layout, (style->GetTileWidth() - (padding * 2))* PANGO_SCALE);
398 pango_layout_set_height(layout, -2);
399
400 pango_layout_set_markup(layout, row.name().c_str(), -1);
401
402=== modified file 'plugins/unityshell/src/ResultRendererTile.h'
403--- plugins/unityshell/src/ResultRendererTile.h 2011-09-06 18:30:26 +0000
404+++ plugins/unityshell/src/ResultRendererTile.h 2011-09-13 17:11:25 +0000
405@@ -79,8 +79,12 @@
406 // unload any previous grabbed images
407 virtual void Unload(Result& row);
408
409+ int highlight_padding;
410+ int spacing;
411+ int padding;
412+
413 protected:
414- void LoadText(Result& row);
415+ virtual void LoadText(Result& row);
416 void LoadIcon(Result& row);
417 nux::ObjectPtr<nux::BaseTexture> prelight_cache_;
418
419
420=== modified file 'plugins/unityshell/src/ResultViewGrid.cpp'
421--- plugins/unityshell/src/ResultViewGrid.cpp 2011-09-08 19:14:49 +0000
422+++ plugins/unityshell/src/ResultViewGrid.cpp 2011-09-13 17:11:25 +0000
423@@ -45,8 +45,8 @@
424
425 ResultViewGrid::ResultViewGrid(NUX_FILE_LINE_DECL)
426 : ResultView(NUX_FILE_LINE_PARAM)
427- , horizontal_spacing(6)
428- , vertical_spacing(6)
429+ , horizontal_spacing(0)
430+ , vertical_spacing(0)
431 , padding(6)
432 , mouse_over_index_(-1)
433 , active_index_(-1)
434@@ -691,7 +691,7 @@
435 }
436
437 GdkPixbuf *
438-_icon_hint_get_drag_pixbuf (std::string icon_hint)
439+_icon_hint_get_drag_pixbuf (std::string icon_hint)
440 {
441 GdkPixbuf *pbuf;
442 GtkIconTheme *theme;
443@@ -699,16 +699,16 @@
444 GError *error = NULL;
445 GIcon *icon;
446 int size = 64;
447-
448+
449 if (icon_hint.empty())
450 icon_hint = "application-default-icon";
451-
452+
453 if (g_str_has_prefix(icon_hint.c_str(), "/"))
454 {
455
456- pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
457+ pbuf = gdk_pixbuf_new_from_file_at_scale (icon_hint.c_str(),
458 size, -1, TRUE, &error);
459-
460+
461 if (error != NULL || !pbuf || !GDK_IS_PIXBUF (pbuf))
462 {
463 icon_hint = "application-default-icon";
464@@ -720,7 +720,7 @@
465 }
466 theme = gtk_icon_theme_get_default();
467 icon = g_icon_new_for_string(icon_hint.c_str(), NULL);
468-
469+
470 if (G_IS_ICON(icon))
471 {
472 info = gtk_icon_theme_lookup_by_gicon(theme, icon, size, (GtkIconLookupFlags)0);
473@@ -733,7 +733,7 @@
474 size,
475 (GtkIconLookupFlags) 0);
476 }
477-
478+
479 if (!info)
480 {
481 info = gtk_icon_theme_lookup_icon(theme,
482@@ -741,7 +741,7 @@
483 size,
484 (GtkIconLookupFlags) 0);
485 }
486-
487+
488 if (gtk_icon_info_get_filename(info) == NULL)
489 {
490 gtk_icon_info_free(info);
491@@ -750,21 +750,21 @@
492 size,
493 (GtkIconLookupFlags) 0);
494 }
495-
496+
497 pbuf = gtk_icon_info_load_icon(info, &error);
498-
499-
500+
501+
502 if (error != NULL)
503 {
504 LOG_WARN (logger) << "could not find a pixbuf for " << icon_hint;
505 g_error_free (error);
506 pbuf = NULL;
507 }
508-
509+
510 gtk_icon_info_free(info);
511-
512+
513 return pbuf;
514-
515+
516 }
517
518 nux::NBitmapData*
519@@ -772,7 +772,7 @@
520 {
521 nux::NBitmapData* result = 0;
522 GdkPixbuf* pbuf;
523-
524+
525 pbuf = _icon_hint_get_drag_pixbuf (current_drag_icon_name_);
526
527 if (pbuf && GDK_IS_PIXBUF(pbuf))