Merge lp:~mhr3/unity/icon-loader-width-and-height into lp:unity

Proposed by Michal Hruby
Status: Merged
Approved by: Omer Akram
Approved revision: no longer in the source branch.
Merged at revision: 2690
Proposed branch: lp:~mhr3/unity/icon-loader-width-and-height
Merge into: lp:unity
Prerequisite: lp:~nick-dedekind/unity/dash-results.focus+size
Diff against target: 1235 lines (+416/-178)
15 files modified
dash/ResultRendererTile.cpp (+11/-17)
dash/ResultRendererTile.h (+1/-1)
launcher/DeviceNotificationDisplayImp.cpp (+4/-3)
plugins/unityshell/resources/emblem_apps.svg (+19/-0)
plugins/unityshell/resources/emblem_books.svg (+9/-0)
plugins/unityshell/resources/emblem_clothes.svg (+8/-0)
plugins/unityshell/resources/emblem_music.svg (+15/-0)
plugins/unityshell/resources/emblem_video.svg (+17/-0)
tests/test_icon_loader.cpp (+6/-6)
unity-shared/CoverArt.cpp (+16/-10)
unity-shared/CoverArt.h (+3/-3)
unity-shared/IconLoader.cpp (+290/-127)
unity-shared/IconLoader.h (+9/-5)
unity-shared/IconTexture.cpp (+7/-5)
unity-shared/IconTexture.h (+1/-1)
To merge this branch: bzr merge lp:~mhr3/unity/icon-loader-width-and-height
Reviewer Review Type Date Requested Status
Omer Akram (community) Approve
John Lea (community) design Approve
Nick Dedekind (community) Approve
Review via email: mp+124013@code.launchpad.net

Commit message

Change the IconLoader methods to allow specifying both maximum width and height. Updated rendering of the icon ribbons.

Description of the change

Change the IconLoader methods to allow specifying both maximum width and height. Also updated rendering of the icon ribbons.

To post a comment you must log in.
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

502 + int size = max_height < 0 ? max_width : max_height;
510 + int size = max_height < 0 ? max_width : max_height;

I think it should use the minimum of the values if max_height < 0. so.
int size = max_height < 0 ? max_width : (max_width < 0 ? max_height : MIN(max_height, max_width));

784 switch (category)
785 {
786 + case UNITY_PROTOCOL_CATEGORY_TYPE_BOOK:
787 + helper_handle =
788 + impl->LoadFromFilename(PKGDATADIR"/emblem_books.svg", -1, cat_size, helper_slot);
789 + break;
790 case UNITY_PROTOCOL_CATEGORY_TYPE_MUSIC:

Could we put the category->resource mapping in the Dash Style?

Other than these the code looks good. I trust it meets visual design requirements :)

Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

LGTM

review: Approve
Revision history for this message
John Lea (johnlea) :
review: Approve (design)
Revision history for this message
Unity Merger (unity-merger) wrote :

The prerequisite lp:~nick-dedekind/unity/dash-results.focus+size has not yet been merged into lp:unity.

Revision history for this message
Unity Merger (unity-merger) wrote :

No proposals found for merge of lp:~nick-dedekind/unity/dash-results.focus+size into lp:unity.

Revision history for this message
Omer Akram (om26er) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'dash/ResultRendererTile.cpp'
--- dash/ResultRendererTile.cpp 2012-09-13 10:12:22 +0000
+++ dash/ResultRendererTile.cpp 2012-09-13 10:12:22 +0000
@@ -204,7 +204,7 @@
204void ResultRendererTile::LoadIcon(Result& row)204void ResultRendererTile::LoadIcon(Result& row)
205{205{
206 Style& style = Style::Instance();206 Style& style = Style::Instance();
207 std::string const& icon_hint = row.icon_hint;207 std::string icon_hint(row.icon_hint);
208#define DEFAULT_GICON ". GThemedIcon text-x-preview"208#define DEFAULT_GICON ". GThemedIcon text-x-preview"
209 std::string icon_name;209 std::string icon_name;
210 if (G_UNLIKELY(neko))210 if (G_UNLIKELY(neko))
@@ -222,26 +222,20 @@
222 icon_name = !icon_hint.empty() ? icon_hint : DEFAULT_GICON;222 icon_name = !icon_hint.empty() ? icon_hint : DEFAULT_GICON;
223 }223 }
224224
225 GIcon* icon = g_icon_new_for_string(icon_name.c_str(), NULL);225 glib::Object<GIcon> icon(g_icon_new_for_string(icon_name.c_str(), NULL));
226 TextureContainer* container = row.renderer<TextureContainer*>();226 TextureContainer* container = row.renderer<TextureContainer*>();
227227
228 IconLoader::IconLoaderCallback slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_hint, row);228 IconLoader::IconLoaderCallback slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_hint, row);
229229
230 if (g_strrstr(icon_name.c_str(), "://"))230 if (icon.IsType(G_TYPE_ICON))
231 {231 {
232 container->slot_handle = IconLoader::GetDefault().LoadFromURI(icon_name, style.GetTileImageSize(), slot);232 bool use_large_icon = icon.IsType(G_TYPE_FILE_ICON) || !icon.IsType(G_TYPE_THEMED_ICON);
233 }233 container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name, style.GetTileImageSize(), use_large_icon ? style.GetTileImageSize() : style.GetTileGIconSize(), slot);
234 else if (G_IS_ICON(icon))
235 {
236 container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(icon_name, g_str_has_prefix(icon_name.c_str(), "/") ? style.GetTileImageSize() : style.GetTileGIconSize(), slot);
237 }234 }
238 else235 else
239 {236 {
240 container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name, style.GetTileGIconSize(), slot);237 container->slot_handle = IconLoader::GetDefault().LoadFromIconName(icon_name, -1, style.GetTileGIconSize(), slot);
241 }238 }
242
243 if (icon != NULL)
244 g_object_unref(icon);
245}239}
246240
247nux::BaseTexture* ResultRendererTile::CreateTextureCallback(std::string const& texid,241nux::BaseTexture* ResultRendererTile::CreateTextureCallback(std::string const& texid,
@@ -321,7 +315,8 @@
321315
322316
323void ResultRendererTile::IconLoaded(std::string const& texid,317void ResultRendererTile::IconLoaded(std::string const& texid,
324 unsigned size,318 int max_width,
319 int max_height,
325 glib::Object<GdkPixbuf> const& pixbuf,320 glib::Object<GdkPixbuf> const& pixbuf,
326 std::string icon_name,321 std::string icon_name,
327 Result& row)322 Result& row)
@@ -333,7 +328,7 @@
333 if (pixbuf && container)328 if (pixbuf && container)
334 {329 {
335 TextureCache& cache = TextureCache::GetDefault();330 TextureCache& cache = TextureCache::GetDefault();
336 BaseTexturePtr texture(cache.FindTexture(icon_name, size, size,331 BaseTexturePtr texture(cache.FindTexture(icon_name, max_width, max_height,
337 sigc::bind(sigc::mem_fun(this, &ResultRendererTile::CreateTextureCallback), pixbuf)));332 sigc::bind(sigc::mem_fun(this, &ResultRendererTile::CreateTextureCallback), pixbuf)));
338333
339 BaseTexturePtr texture_prelight(cache.FindTexture("resultview_prelight", style.GetTileIconHightlightWidth(), style.GetTileIconHightlightHeight(), sigc::mem_fun(this, &ResultRendererTile::DrawHighlight)));334 BaseTexturePtr texture_prelight(cache.FindTexture("resultview_prelight", style.GetTileIconHightlightWidth(), style.GetTileIconHightlightHeight(), sigc::mem_fun(this, &ResultRendererTile::DrawHighlight)));
@@ -350,9 +345,8 @@
350 {345 {
351 // we need to load a missing icon346 // we need to load a missing icon
352 IconLoader::IconLoaderCallback slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_name, row);347 IconLoader::IconLoaderCallback slot = sigc::bind(sigc::mem_fun(this, &ResultRendererTile::IconLoaded), icon_name, row);
353 container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(". GThemedIcon text-x-preview", size, slot);348 container->slot_handle = IconLoader::GetDefault().LoadFromGIconString(". GThemedIcon text-x-preview", max_width, max_height, slot);
354 }349 }
355
356}350}
357351
358352
359353
=== modified file 'dash/ResultRendererTile.h'
--- dash/ResultRendererTile.h 2012-09-13 10:12:22 +0000
+++ dash/ResultRendererTile.h 2012-09-13 10:12:22 +0000
@@ -90,7 +90,7 @@
90 nux::ObjectPtr<nux::BaseTexture> normal_cache_;90 nux::ObjectPtr<nux::BaseTexture> normal_cache_;
91private:91private:
92 //icon loading callbacks92 //icon loading callbacks
93 void IconLoaded(std::string const& texid, unsigned size,93 void IconLoaded(std::string const& texid, int max_width, int max_height,
94 glib::Object<GdkPixbuf> const& pixbuf,94 glib::Object<GdkPixbuf> const& pixbuf,
95 std::string icon_name, Result& row);95 std::string icon_name, Result& row);
96 nux::BaseTexture* CreateTextureCallback(std::string const& texid,96 nux::BaseTexture* CreateTextureCallback(std::string const& texid,
9797
=== modified file 'launcher/DeviceNotificationDisplayImp.cpp'
--- launcher/DeviceNotificationDisplayImp.cpp 2012-08-22 09:03:25 +0000
+++ launcher/DeviceNotificationDisplayImp.cpp 2012-09-13 10:12:22 +0000
@@ -40,12 +40,13 @@
40 void Show(std::string const& icon_name, std::string const& volume_name)40 void Show(std::string const& icon_name, std::string const& volume_name)
41 {41 {
42 int icon_size = 48;42 int icon_size = 48;
43 IconLoader::GetDefault().LoadFromGIconString(icon_name, icon_size,43 IconLoader::GetDefault().LoadFromGIconString(icon_name, -1, icon_size,
44 sigc::bind(sigc::mem_fun(this, &Impl::ShowNotificationWhenIconIsReady), volume_name));44 sigc::bind(sigc::mem_fun(this, &Impl::ShowNotificationWhenIconIsReady), volume_name));
45 }45 }
4646
47 void ShowNotificationWhenIconIsReady(std::string const& icon_name,47 void ShowNotificationWhenIconIsReady(std::string const& icon_name,
48 unsigned size,48 int max_width,
49 int max_height,
49 glib::Object<GdkPixbuf> const& pixbuf,50 glib::Object<GdkPixbuf> const& pixbuf,
50 std::string const& volume_name)51 std::string const& volume_name)
51 {52 {
@@ -55,7 +56,7 @@
5556
56 notify_notification_set_hint(notification, "x-canonical-private-synchronous", g_variant_new_boolean(TRUE));57 notify_notification_set_hint(notification, "x-canonical-private-synchronous", g_variant_new_boolean(TRUE));
5758
58 if (GDK_IS_PIXBUF(pixbuf.RawPtr()))59 if (pixbuf)
59 notify_notification_set_image_from_pixbuf(notification, pixbuf);60 notify_notification_set_image_from_pixbuf(notification, pixbuf);
6061
61 notify_notification_show(notification, nullptr);62 notify_notification_show(notification, nullptr);
6263
=== added file 'plugins/unityshell/resources/emblem_apps.svg'
--- plugins/unityshell/resources/emblem_apps.svg 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/resources/emblem_apps.svg 2012-09-13 10:12:22 +0000
@@ -0,0 +1,19 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="14px" height="14px" viewBox="0 0 14 14" enable-background="new 0 0 14 14" xml:space="preserve">
6<path fill="#DC4A26" d="M8.5,4.504v7.997c0,0.55-0.469,0.999-1.018,0.999H6.498c-0.55,0-0.998-0.449-0.998-0.999V4.504H8.5z"/>
7<g>
8 <path fill="#DC4A26" d="M4.5,4.504h-2v-1h2V1.505c0-0.55-0.45-1-1-1H1.501c-0.55,0-1,0.45-1,1L0.5,12.501
9 c0,0.55,0.45,0.999,1,0.999h1.999c0.55,0,1-0.449,1-0.999V10.5L2.5,10.502v-1L4.499,9.5V7.503H2.5v-1h2"/>
10</g>
11<path fill="#DC4A26" d="M4.5,6.503v-1l0,0V6.503L4.5,6.503z"/>
12<path fill="#DC4A26" d="M4.5,9.502v-1h0L4.5,9.502L4.5,9.502z"/>
13<path fill="#DC4A26" d="M4.5,12.499L4.5,12.499L4.5,12.499L4.5,12.499L4.5,12.499z"/>
14<path fill="#DC4A26" d="M11.866,0.508v1.237C12.102,1.856,12.3,2.052,12.3,2.286c0,0.354-0.358,0.64-0.8,0.64s-0.8-0.286-0.8-0.64
15 c0-0.234,0.198-0.43,0.433-0.541V0.508C10.66,0.972,9.5,2.321,9.5,2.917c0,0.884,1.116,1.6,2,1.6s2-0.716,2-1.6
16 C13.5,2.321,12.34,0.972,11.866,0.508z"/>
17<path fill="#DC4A26" d="M5.501,3.499L7.047,0.5L8.5,3.499H5.501z"/>
18<path fill="#DC4A26" d="M13.5,5.503v6.998c0,0.55-0.45,0.999-1,0.999h-2c-0.55,0-1-0.449-1-0.999V5.503H13.5z"/>
19</svg>
020
=== added file 'plugins/unityshell/resources/emblem_books.svg'
--- plugins/unityshell/resources/emblem_books.svg 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/resources/emblem_books.svg 2012-09-13 10:12:22 +0000
@@ -0,0 +1,9 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="14px" height="14px" viewBox="0 0 14 14" enable-background="new 0 0 14 14" xml:space="preserve">
6<path fill="#DC4A26" d="M7,1.879C6.961,1.473,6.427,0.227,1,1.5c0,3.222,0,7.449,0,11C7.009,10.945,7,13,7,13s-0.009-2.055,6-0.5
7 c0-3.551,0-7.778,0-11C7.574,0.227,7.039,1.473,7,1.879z M5,9H2V8h3V9z M5,7H2V6h3V7z M5,5H2V4h3V5z M7.5,12h-1V2h1V12z M12,9H9V8h3
8 V9z M12,7H9V6h3V7z M12,5H9V4h3V5z"/>
9</svg>
010
=== added file 'plugins/unityshell/resources/emblem_clothes.svg'
--- plugins/unityshell/resources/emblem_clothes.svg 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/resources/emblem_clothes.svg 2012-09-13 10:12:22 +0000
@@ -0,0 +1,8 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="14px" height="14px" viewBox="0 0 14 14" enable-background="new 0 0 14 14" xml:space="preserve">
6<path fill="#DC4A26" d="M10.997,13V5.013l1.505,0.772L14,2.942L10.974,1L8.988,1.002c0,1.121-0.916,2.029-2.046,2.029
7 S5.012,2.123,5.012,1.002L2.969,1L0,2.942l1.498,2.843l1.447-0.772V13H10.997z"/>
8</svg>
09
=== added file 'plugins/unityshell/resources/emblem_music.svg'
--- plugins/unityshell/resources/emblem_music.svg 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/resources/emblem_music.svg 2012-09-13 10:12:22 +0000
@@ -0,0 +1,15 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="14px" height="14px" viewBox="0 0 14 14" enable-background="new 0 0 14 14" xml:space="preserve">
6<g>
7 <g>
8 <path fill="#DC4A26" d="M13,0.598c0-0.386-0.307-0.651-0.683-0.588L5.672,1.186C5.296,1.249,5,1.617,5,2.005v7.249
9 C4.228,8.862,3.14,8.925,2.157,9.52c-1.393,0.841-2.033,2.413-1.43,3.506c0.603,1.094,2.223,1.299,3.615,0.455
10 c1.078-0.65,1.697-1.735,1.648-2.699L6,10.789V3.624c0-0.386,0.277-0.756,0.653-0.818l4.684-0.823C11.712,1.919,12,2.184,12,2.57
11 v4.684c-0.771-0.393-1.86-0.329-2.843,0.265C7.764,8.36,7.123,9.931,7.727,11.024c0.603,1.094,2.222,1.3,3.615,0.456
12 c1.069-0.646,1.689-1.721,1.649-2.68L13,8.808V0.598z"/>
13 </g>
14</g>
15</svg>
016
=== added file 'plugins/unityshell/resources/emblem_video.svg'
--- plugins/unityshell/resources/emblem_video.svg 1970-01-01 00:00:00 +0000
+++ plugins/unityshell/resources/emblem_video.svg 2012-09-13 10:12:22 +0000
@@ -0,0 +1,17 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- Generator: Adobe Illustrator 15.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
4<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5 width="14px" height="14px" viewBox="0 0 14 14" enable-background="new 0 0 14 14" xml:space="preserve">
6<g>
7 <g>
8 <path fill="#DC4A26" d="M12.301,2.5H1.7C1.315,2.5,1,2.813,1,3.196v7.608C1,11.188,1.315,11.5,1.7,11.5h10.601
9 c0.385,0,0.699-0.312,0.699-0.696V3.196C13,2.813,12.686,2.5,12.301,2.5z M2.989,10.455H1.994V9.498h0.996V10.455z M2.989,8.49
10 H1.994V7.5h0.996V8.49z M2.989,6.494H1.994V5.535h0.996V6.494z M2.989,4.496H1.994V3.538h0.996V4.496z M8.006,7.841
11 C7.659,8.126,7.308,8.404,6.954,8.677C6.6,8.947,6.255,9.197,5.92,9.426c-0.335,0.229-0.64,0.422-0.913,0.579V4.026
12 c0.261,0.158,0.559,0.35,0.894,0.578c0.335,0.229,0.68,0.476,1.034,0.74c0.354,0.265,0.708,0.54,1.061,0.825
13 c0.355,0.286,0.687,0.565,0.998,0.836C8.684,7.276,8.354,7.555,8.006,7.841z M11.992,10.455h-0.996V9.498h0.996V10.455z
14 M11.992,8.49h-0.996V7.5h0.996V8.49z M11.992,6.494h-0.996V5.535h0.996V6.494z M11.992,4.496h-0.996V3.538h0.996V4.496z"/>
15 </g>
16</g>
17</svg>
018
=== modified file 'tests/test_icon_loader.cpp'
--- tests/test_icon_loader.cpp 2012-08-20 18:41:49 +0000
+++ tests/test_icon_loader.cpp 2012-09-13 10:12:22 +0000
@@ -47,7 +47,7 @@
47 bool got_callback;47 bool got_callback;
4848
49 LoadResult() : pixbuf(NULL), got_callback(false) {}49 LoadResult() : pixbuf(NULL), got_callback(false) {}
50 void IconLoaded(std::string const& icon_name, unsigned size,50 void IconLoaded(std::string const& icon_name, int max_width, int max_height,
51 glib::Object<GdkPixbuf> const& buf)51 glib::Object<GdkPixbuf> const& buf)
52 {52 {
53 pixbuf = buf;53 pixbuf = buf;
@@ -71,7 +71,7 @@
71 IconLoader& icon_loader = IconLoader::GetDefault();71 IconLoader& icon_loader = IconLoader::GetDefault();
72 volatile bool timeout_reached = false;72 volatile bool timeout_reached = false;
7373
74 icon_loader.LoadFromIconName("gedit-icon", 48, sigc::mem_fun(load_result,74 icon_loader.LoadFromIconName("gedit-icon", -1, 48, sigc::mem_fun(load_result,
75 &LoadResult::IconLoaded));75 &LoadResult::IconLoaded));
7676
77 guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));77 guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));
@@ -93,7 +93,7 @@
93 volatile bool timeout_reached = false;93 volatile bool timeout_reached = false;
9494
95 95
96 icon_loader.LoadFromGIconString(". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'gedit-icon'%3E,%20'ribbon':%20%3C'foo'%3E%7D", 48, sigc::mem_fun(load_result,96 icon_loader.LoadFromGIconString(". UnityProtocolAnnotatedIcon %7B'base-icon':%20%3C'gedit-icon'%3E,%20'ribbon':%20%3C'foo'%3E%7D", -1, 48, sigc::mem_fun(load_result,
97 &LoadResult::IconLoaded));97 &LoadResult::IconLoaded));
9898
99 guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));99 guint tid = g_timeout_add (10000, TimeoutReached, (gpointer)(&timeout_reached));
@@ -125,7 +125,7 @@
125 // be cached already!125 // be cached already!
126 for (int i = 0; i < load_count; i++)126 for (int i = 0; i < load_count; i++)
127 {127 {
128 handles[i] = icon_loader.LoadFromIconName("web-browser", 48,128 handles[i] = icon_loader.LoadFromIconName("web-browser", -1, 48,
129 sigc::mem_fun(results[i], &LoadResult::IconLoaded));129 sigc::mem_fun(results[i], &LoadResult::IconLoaded));
130 }130 }
131131
@@ -190,7 +190,7 @@
190 for (GList *it = icons; it != NULL; it = it->next)190 for (GList *it = icons; it != NULL; it = it->next)
191 {191 {
192 const char *icon_name = static_cast<char*>(it->data);192 const char *icon_name = static_cast<char*>(it->data);
193 icon_loader.LoadFromIconName(icon_name, 48, sigc::mem_fun(results[i++],193 icon_loader.LoadFromIconName(icon_name, -1, 48, sigc::mem_fun(results[i++],
194 &LoadResult::IconLoaded));194 &LoadResult::IconLoaded));
195 if (i >= icon_count) break;195 if (i >= icon_count) break;
196 }196 }
@@ -235,7 +235,7 @@
235 for (GList *it = icons; it != NULL; it = it->next)235 for (GList *it = icons; it != NULL; it = it->next)
236 {236 {
237 const char *icon_name = static_cast<char*>(it->data);237 const char *icon_name = static_cast<char*>(it->data);
238 int handle = icon_loader.LoadFromIconName(icon_name, 48, sigc::mem_fun(238 int handle = icon_loader.LoadFromIconName(icon_name, -1, 48, sigc::mem_fun(
239 results[i], &LoadResult::IconLoaded));239 results[i], &LoadResult::IconLoaded));
240 handles[i++] = handle;240 handles[i++] = handle;
241 if (i >= icon_count) break;241 if (i >= icon_count) break;
242242
=== modified file 'unity-shared/CoverArt.cpp'
--- unity-shared/CoverArt.cpp 2012-09-03 22:45:44 +0000
+++ unity-shared/CoverArt.cpp 2012-09-13 10:12:22 +0000
@@ -41,7 +41,7 @@
41{41{
42nux::logging::Logger logger("unity.dash.previews.coverart");42nux::logging::Logger logger("unity.dash.previews.coverart");
4343
44const int icon_width = 256;44const int ICON_SIZE = 256;
45}45}
4646
47NUX_IMPLEMENT_OBJECT_TYPE(CoverArt);47NUX_IMPLEMENT_OBJECT_TYPE(CoverArt);
@@ -109,9 +109,9 @@
109109
110 // texture from file.110 // texture from file.
111 if (bLoadTexture)111 if (bLoadTexture)
112 { 112 {
113 StartWaiting();113 StartWaiting();
114 slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ~0, sigc::mem_fun(this, &CoverArt::TextureLoaded));114 slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, -1, -1, sigc::mem_fun(this, &CoverArt::TextureLoaded));
115 }115 }
116 else if (!image_hint.empty())116 else if (!image_hint.empty())
117 {117 {
@@ -121,12 +121,12 @@
121 if (G_IS_ICON(icon))121 if (G_IS_ICON(icon))
122 {122 {
123 StartWaiting();123 StartWaiting();
124 slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded));124 slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ICON_SIZE, ICON_SIZE, sigc::mem_fun(this, &CoverArt::IconLoaded));
125 }125 }
126 else126 else
127 {127 {
128 StartWaiting();128 StartWaiting();
129 slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded));129 slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, ICON_SIZE, ICON_SIZE, sigc::mem_fun(this, &CoverArt::IconLoaded));
130 }130 }
131 }131 }
132 else132 else
@@ -195,7 +195,10 @@
195 }195 }
196}196}
197197
198void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf)198void CoverArt::IconLoaded(std::string const& texid,
199 int max_width,
200 int max_height,
201 glib::Object<GdkPixbuf> const& pixbuf)
199{202{
200 // Finished waiting203 // Finished waiting
201 StopWaiting();204 StopWaiting();
@@ -207,7 +210,7 @@
207 return;210 return;
208 }211 }
209212
210 int height = size;213 int height = max_height;
211214
212 int pixbuf_width, pixbuf_height;215 int pixbuf_width, pixbuf_height;
213 pixbuf_width = gdk_pixbuf_get_width(pixbuf);216 pixbuf_width = gdk_pixbuf_get_width(pixbuf);
@@ -232,7 +235,7 @@
232 float aspect = static_cast<float>(pixbuf_height) / pixbuf_width; // already sanitized width/height so can not be 0.0235 float aspect = static_cast<float>(pixbuf_height) / pixbuf_width; // already sanitized width/height so can not be 0.0
233 if (aspect < 1.0f)236 if (aspect < 1.0f)
234 {237 {
235 pixbuf_width = icon_width;238 pixbuf_width = ICON_SIZE;
236 pixbuf_height = pixbuf_width * aspect;239 pixbuf_height = pixbuf_width * aspect;
237240
238 if (pixbuf_height > height)241 if (pixbuf_height > height)
@@ -274,7 +277,10 @@
274 }277 }
275}278}
276279
277void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf)280void CoverArt::TextureLoaded(std::string const& texid,
281 int max_width,
282 int max_height,
283 glib::Object<GdkPixbuf> const& pixbuf)
278{284{
279 // Finished waiting285 // Finished waiting
280 StopWaiting();286 StopWaiting();
@@ -489,4 +495,4 @@
489495
490}496}
491}497}
492}
493\ No newline at end of file498\ No newline at end of file
499}
494500
=== modified file 'unity-shared/CoverArt.h'
--- unity-shared/CoverArt.h 2012-08-28 10:15:19 +0000
+++ unity-shared/CoverArt.h 2012-09-13 10:12:22 +0000
@@ -70,8 +70,8 @@
70 void OnThumbnailError(std::string const& error_hint);70 void OnThumbnailError(std::string const& error_hint);
71 bool OnFrameTimeout();71 bool OnFrameTimeout();
7272
73 void IconLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf);73 void IconLoaded(std::string const& texid, int max_width, int max_height, glib::Object<GdkPixbuf> const& pixbuf);
74 void TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf);74 void TextureLoaded(std::string const& texid, int max_width, int max_height, glib::Object<GdkPixbuf> const& pixbuf);
7575
76 void StartWaiting();76 void StartWaiting();
77 void StopWaiting();77 void StopWaiting();
@@ -105,4 +105,4 @@
105}105}
106}106}
107107
108#endif // APPLICATIONSCREENSHOT_H
109\ No newline at end of file108\ No newline at end of file
109#endif // APPLICATIONSCREENSHOT_H
110110
=== modified file 'unity-shared/IconLoader.cpp'
--- unity-shared/IconLoader.cpp 2012-08-20 18:41:49 +0000
+++ unity-shared/IconLoader.cpp 2012-09-13 10:12:22 +0000
@@ -18,6 +18,7 @@
18*/18*/
1919
20#include "IconLoader.h"20#include "IconLoader.h"
21#include "config.h"
2122
22#include <queue>23#include <queue>
23#include <sstream>24#include <sstream>
@@ -39,7 +40,8 @@
39namespace40namespace
40{41{
41nux::logging::Logger logger("unity.iconloader");42nux::logging::Logger logger("unity.iconloader");
42const unsigned MIN_ICON_SIZE = 2;43const int MIN_ICON_SIZE = 2;
44const int RIBBON_PADDING = 2;
43}45}
4446
45class IconLoader::Impl47class IconLoader::Impl
@@ -48,25 +50,29 @@
48 // The Handle typedef is used to explicitly indicate which integers are50 // The Handle typedef is used to explicitly indicate which integers are
49 // infact our opaque handles.51 // infact our opaque handles.
50 typedef int Handle;52 typedef int Handle;
51 static const int FONT_SIZE = 10;53 static const int FONT_SIZE = 8;
52 static const int MIN_FONT_SIZE = 6;54 static const int MIN_FONT_SIZE = 5;
5355
54 Impl();56 Impl();
5557
56 Handle LoadFromIconName(std::string const& icon_name,58 Handle LoadFromIconName(std::string const& icon_name,
57 unsigned size,59 int max_width,
60 int max_height,
58 IconLoaderCallback slot);61 IconLoaderCallback slot);
5962
60 Handle LoadFromGIconString(std::string const& gicon_string,63 Handle LoadFromGIconString(std::string const& gicon_string,
61 unsigned size,64 int max_width,
65 int max_height,
62 IconLoaderCallback slot);66 IconLoaderCallback slot);
6367
64 Handle LoadFromFilename(std::string const& filename,68 Handle LoadFromFilename(std::string const& filename,
65 unsigned size,69 int max_width,
70 int max_height,
66 IconLoaderCallback slot);71 IconLoaderCallback slot);
6772
68 Handle LoadFromURI(std::string const& uri,73 Handle LoadFromURI(std::string const& uri,
69 unsigned size,74 int max_width,
75 int max_height,
70 IconLoaderCallback slot);76 IconLoaderCallback slot);
7177
72 void DisconnectHandle(Handle handle);78 void DisconnectHandle(Handle handle);
@@ -88,7 +94,8 @@
8894
89 IconLoaderRequestType type;95 IconLoaderRequestType type;
90 std::string data;96 std::string data;
91 unsigned int size;97 int max_width;
98 int max_height;
92 std::string key;99 std::string key;
93 IconLoaderCallback slot;100 IconLoaderCallback slot;
94 Handle handle;101 Handle handle;
@@ -103,12 +110,14 @@
103110
104 IconLoaderTask(IconLoaderRequestType type_,111 IconLoaderTask(IconLoaderRequestType type_,
105 std::string const& data_,112 std::string const& data_,
106 unsigned size_,113 int max_width_,
114 int max_height_,
107 std::string const& key_,115 std::string const& key_,
108 IconLoaderCallback slot_,116 IconLoaderCallback slot_,
109 Handle handle_,117 Handle handle_,
110 Impl* self_)118 Impl* self_)
111 : type(type_), data(data_), size(size_), key(key_)119 : type(type_), data(data_), max_width(max_width_)
120 , max_height(max_height_), key(key_)
112 , slot(slot_), handle(handle_), impl(self_)121 , slot(slot_), handle(handle_), impl(self_)
113 , icon_info(nullptr), no_cache(false), helper_handle(0), idle_id(0)122 , icon_info(nullptr), no_cache(false), helper_handle(0), idle_id(0)
114 {}123 {}
@@ -126,13 +135,16 @@
126 void InvokeSlot()135 void InvokeSlot()
127 {136 {
128 if (slot)137 if (slot)
129 slot(data, size, result);138 slot(data, max_width, max_height, result);
130139
131 // notify shadow tasks140 // notify shadow tasks
132 for (auto shadow_task : shadow_tasks)141 for (auto shadow_task : shadow_tasks)
133 {142 {
134 if (shadow_task->slot)143 if (shadow_task->slot)
135 shadow_task->slot(shadow_task->data, shadow_task->size, result);144 shadow_task->slot(shadow_task->data,
145 shadow_task->max_width,
146 shadow_task->max_height,
147 result);
136148
137 impl->task_map_.erase(shadow_task->handle);149 impl->task_map_.erase(shadow_task->handle);
138 }150 }
@@ -143,10 +155,10 @@
143 bool Process()155 bool Process()
144 {156 {
145 // Check the cache again, as previous tasks might have wanted the same157 // Check the cache again, as previous tasks might have wanted the same
146 if (impl->CacheLookup(key, data, size, slot))158 if (impl->CacheLookup(key, data, max_width, max_height, slot))
147 return true;159 return true;
148160
149 LOG_DEBUG(logger) << "Processing " << data << " at size " << size;161 LOG_DEBUG(logger) << "Processing " << data << " at size " << max_height;
150162
151 // Rely on the compiler to tell us if we miss a new type163 // Rely on the compiler to tell us if we miss a new type
152 switch (type)164 switch (type)
@@ -161,7 +173,7 @@
161173
162 LOG_WARNING(logger) << "Request type " << type174 LOG_WARNING(logger) << "Request type " << type
163 << " is not supported (" << data175 << " is not supported (" << data
164 << " " << size << ")";176 << " " << max_width << "x" << max_height << ")";
165 result = nullptr;177 result = nullptr;
166 InvokeSlot();178 InvokeSlot();
167179
@@ -170,6 +182,7 @@
170182
171 bool ProcessIconNameTask()183 bool ProcessIconNameTask()
172 {184 {
185 int size = max_height < 0 ? max_width : (max_width < 0 ? max_height : MIN(max_height, max_width));
173 GtkIconInfo* info = ::gtk_icon_theme_lookup_icon(impl->theme_, data.c_str(),186 GtkIconInfo* info = ::gtk_icon_theme_lookup_icon(impl->theme_, data.c_str(),
174 size, static_cast<GtkIconLookupFlags>(0));187 size, static_cast<GtkIconLookupFlags>(0));
175 if (info)188 if (info)
@@ -195,6 +208,7 @@
195 {208 {
196 glib::Error error;209 glib::Error error;
197 glib::Object<GIcon> icon(::g_icon_new_for_string(data.c_str(), &error));210 glib::Object<GIcon> icon(::g_icon_new_for_string(data.c_str(), &error));
211 int size = max_height < 0 ? max_width : (max_width < 0 ? max_height : MIN(max_height, max_width));
198212
199 if (icon.IsType(UNITY_PROTOCOL_TYPE_ANNOTATED_ICON))213 if (icon.IsType(UNITY_PROTOCOL_TYPE_ANNOTATED_ICON))
200 {214 {
@@ -205,8 +219,12 @@
205219
206 no_cache = true;220 no_cache = true;
207 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::BaseIconLoaded), glib::object_cast<UnityProtocolAnnotatedIcon>(icon));221 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::BaseIconLoaded), glib::object_cast<UnityProtocolAnnotatedIcon>(icon));
222 int base_icon_width = max_width > 0 ? max_width - RIBBON_PADDING * 2 : -1;
223 int base_icon_height = base_icon_width < 0 ? max_height - RIBBON_PADDING *2 : max_height;
208 helper_handle = impl->LoadFromGIconString(gicon_string.Str(),224 helper_handle = impl->LoadFromGIconString(gicon_string.Str(),
209 size, helper_slot);225 base_icon_width,
226 base_icon_height,
227 helper_slot);
210228
211 return false;229 return false;
212 }230 }
@@ -271,40 +289,32 @@
271 return false;289 return false;
272 }290 }
273291
274 void CategoryIconLoaded(std::string const& base_icon_string, unsigned size,292 void CategoryIconLoaded(std::string const& base_icon_string,
293 int max_width, int max_height,
275 glib::Object<GdkPixbuf> const& category_pixbuf,294 glib::Object<GdkPixbuf> const& category_pixbuf,
276 glib::Object<UnityProtocolAnnotatedIcon> const& anno_icon)295 glib::Object<UnityProtocolAnnotatedIcon> const& anno_icon)
277 {296 {
278 helper_handle = 0;297 helper_handle = 0;
279 if (category_pixbuf)298 bool has_emblem = category_pixbuf;
280 {
281 // assuming the category pixbuf is smaller than result
282 gdk_pixbuf_composite(category_pixbuf, result, // src, dest
283 0, 0, // dest_x, dest_y
284 gdk_pixbuf_get_width(category_pixbuf), // dest_w
285 gdk_pixbuf_get_height(category_pixbuf), // dest_h
286 0.0, 0.0, // offset_x, offset_y
287 1.0, 1.0, // scale_x, scale_y
288 GDK_INTERP_NEAREST, // interpolation
289 255); // src_alpha
290 }
291299
292 const gchar* detail_text = unity_protocol_annotated_icon_get_ribbon(anno_icon);300 const gchar* detail_text = unity_protocol_annotated_icon_get_ribbon(anno_icon);
293 if (detail_text)301 if (detail_text)
294 {302 {
303 const int SHADOW_BOTTOM_PADDING = 2;
304 const int SHADOW_SIDE_PADDING = 1;
295 int icon_w = gdk_pixbuf_get_width(result);305 int icon_w = gdk_pixbuf_get_width(result);
296 int icon_h = gdk_pixbuf_get_height(result);306 int icon_h = gdk_pixbuf_get_height(result);
297307
298 int max_font_height;308 int max_font_height;
299 CalculateTextHeight(nullptr, &max_font_height);309 CalculateTextHeight(nullptr, &max_font_height);
300310
301 max_font_height = max_font_height * 9 / 8; // let's have some padding on the stripe311 // FIXME: design wants the tags 2px wider than the original icon
302 int pixbuf_size = static_cast<int>(312 int pixbuf_width = icon_w;
303 sqrt(max_font_height*max_font_height*8));313 int pixbuf_height = max_font_height * 5 / 4 + SHADOW_BOTTOM_PADDING;
304 if (pixbuf_size > icon_w) pixbuf_size = icon_w;314 if (pixbuf_height > icon_h) pixbuf_height = icon_h;
305315
306 nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32,316 nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32,
307 pixbuf_size, pixbuf_size);317 pixbuf_width, pixbuf_height);
308 std::shared_ptr<cairo_t> cr(cairo_graphics.GetContext(), cairo_destroy);318 std::shared_ptr<cairo_t> cr(cairo_graphics.GetContext(), cairo_destroy);
309319
310 glib::Object<PangoLayout> layout;320 glib::Object<PangoLayout> layout;
@@ -325,10 +335,9 @@
325 pango_layout_set_font_description(layout, desc.get());335 pango_layout_set_font_description(layout, desc.get());
326 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);336 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
327337
328 double size_dbl = static_cast<double>(pixbuf_size);338 // magic constant for the text width based on the white curve
329 // we'll allow tiny bit of overflow since the text is rotated and there339 double max_text_width = has_emblem ?
330 // is some space left... FIXME: 10/9? / 11/10?340 pixbuf_width * 0.72 : pixbuf_width;
331 double max_text_width = sqrt(size_dbl*size_dbl / 2) * 9/8;
332341
333 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);342 pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
334 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);343 pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
@@ -337,9 +346,8 @@
337 pango_layout_set_markup(layout, escaped_text, -1);346 pango_layout_set_markup(layout, escaped_text, -1);
338347
339 pango_context = pango_layout_get_context(layout); // is not ref'ed348 pango_context = pango_layout_get_context(layout); // is not ref'ed
340 // FIXME: for reasons unknown, it looks better without this349 pango_cairo_context_set_font_options(pango_context,
341 //pango_cairo_context_set_font_options(pango_context,350 gdk_screen_get_font_options(screen));
342 // gdk_screen_get_font_options(screen));
343 pango_cairo_context_set_resolution(pango_context,351 pango_cairo_context_set_resolution(pango_context,
344 dpi == -1 ? 96.0f : dpi/(float) PANGO_SCALE);352 dpi == -1 ? 96.0f : dpi/(float) PANGO_SCALE);
345 pango_layout_context_changed(layout);353 pango_layout_context_changed(layout);
@@ -361,32 +369,117 @@
361369
362 cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER);370 cairo_set_operator(cr.get(), CAIRO_OPERATOR_OVER);
363371
364 // draw the trapezoid
365 cairo_move_to(cr.get(), 0.0, size_dbl);
366 cairo_line_to(cr.get(), size_dbl, 0.0);
367 cairo_line_to(cr.get(), size_dbl, size_dbl / 2.0);
368 cairo_line_to(cr.get(), size_dbl / 2.0, size_dbl);
369 cairo_close_path(cr.get());
370
371 // this should be #dd4814372 // this should be #dd4814
372 cairo_set_source_rgba(cr.get(), 0.86666f, 0.28235f, 0.07843f, 1.0f);373 const double ORANGE_R = 0.86666;
374 const double ORANGE_G = 0.28235;
375 const double ORANGE_B = 0.07843;
376
377 double belt_w = static_cast<double>(pixbuf_width - SHADOW_SIDE_PADDING * 2);
378 double belt_h = static_cast<double>(pixbuf_height - SHADOW_BOTTOM_PADDING);
379
380 // translate to make space for the shadow
381 cairo_save(cr.get());
382 cairo_translate(cr.get(), 1.0, 1.0);
383
384 cairo_set_source_rgba(cr.get(), ORANGE_R, ORANGE_G, ORANGE_B, 1.0);
385
386 cairo_rectangle(cr.get(), 0.0, 0.0, belt_w, belt_h);
387 cairo_fill_preserve(cr.get());
388
389 std::shared_ptr<cairo_pattern_t> pattern(
390 cairo_pattern_create_linear(0.0, 0.0, belt_w, 0.0),
391 cairo_pattern_destroy);
392 cairo_pattern_add_color_stop_rgba(pattern.get(), 0.0, 1.0, 1.0, 1.0, 0.235294);
393 cairo_pattern_add_color_stop_rgba(pattern.get(), 0.02, 1.0, 1.0, 1.0, 0.0);
394 if (!has_emblem)
395 {
396 cairo_pattern_add_color_stop_rgba(pattern.get(), 0.98, 1.0, 1.0, 1.0, 0.0);
397 cairo_pattern_add_color_stop_rgba(pattern.get(), 1.0, 1.0, 1.0, 1.0, 0.235294);
398 }
399 cairo_pattern_add_color_stop_rgba(pattern.get(), 1.0, 1.0, 1.0, 1.0, 0.0);
400
401 cairo_set_source(cr.get(), pattern.get());
373 cairo_fill(cr.get());402 cairo_fill(cr.get());
374403
375 // draw the text (rotated!)404 if (has_emblem)
376 cairo_set_source_rgba(cr.get(), 1.0f, 1.0f, 1.0f, 1.0f);405 {
377 cairo_move_to(cr.get(), size_dbl * 0.25, size_dbl);406 // paint the curve
378 cairo_rotate(cr.get(), -G_PI_4); // rotate by -45 degrees407 const double CURVE_START_XPOS = 0.631163; // 0.651163
379408 const double CURVE_CP1_XPOS = CURVE_START_XPOS + 0.068023;
380 pango_cairo_update_layout(cr.get(), layout);409 const double CURVE_CP2_XPOS = CURVE_START_XPOS + 0.07;
410 const double CURVE_CP3_XPOS = CURVE_START_XPOS + 0.102965;
411 const double CURVE_CP4_XPOS = CURVE_START_XPOS + 0.161511;
412 const double CURVE_CP5_XPOS = CURVE_START_XPOS + 0.197093;
413 const double CURVE_END_XPOS = CURVE_START_XPOS + 0.265779;
414
415 const double CURVE_START_X = CURVE_START_XPOS * belt_w;
416
417 cairo_set_source_rgba(cr.get(), 1.0, 1.0, 1.0, 1.0);
418
419 cairo_move_to(cr.get(), CURVE_START_XPOS * belt_w, belt_h);
420 cairo_curve_to(cr.get(), CURVE_CP1_XPOS * belt_w, belt_h,
421 CURVE_CP2_XPOS * belt_w, 0.9825 * belt_h,
422 CURVE_CP3_XPOS * belt_w, 0.72725 * belt_h);
423 cairo_line_to(cr.get(), CURVE_CP4_XPOS * belt_w, 0.27275 * belt_h);
424 cairo_curve_to(cr.get(), CURVE_CP5_XPOS * belt_w, 0.0,
425 CURVE_CP5_XPOS * belt_w, 0.0,
426 CURVE_END_XPOS * belt_w, 0.0);
427 cairo_line_to(cr.get(), belt_w, 0.0);
428 cairo_line_to(cr.get(), belt_w, belt_h);
429 cairo_close_path(cr.get());
430 cairo_fill(cr.get());
431
432 // and the highlight
433 pattern.reset(cairo_pattern_create_linear(CURVE_START_X, 0.0, belt_w, 0.0),
434 cairo_pattern_destroy);
435 cairo_pattern_add_color_stop_rgba(pattern.get(), 0.0, 1.0, 1.0, 1.0, 0.0);
436 cairo_pattern_add_color_stop_rgba(pattern.get(), 0.95, 1.0, 1.0, 1.0, 0.0);
437 cairo_pattern_add_color_stop_rgba(pattern.get(), 1.0, 0.0, 0.0, 0.0, 0.235294);
438 cairo_set_source(cr.get(), pattern.get());
439 cairo_rectangle(cr.get(), CURVE_START_X, 0.0, belt_w - CURVE_START_X, belt_h);
440 cairo_fill(cr.get());
441
442 // paint the emblem
443 int category_pb_w = gdk_pixbuf_get_width(category_pixbuf);
444 int category_pb_h = gdk_pixbuf_get_height(category_pixbuf);
445 double category_pb_x =
446 belt_w - category_pb_w > CURVE_CP4_XPOS * belt_w ?
447 CURVE_CP4_XPOS * belt_w + ((1 - CURVE_CP4_XPOS) * belt_w - category_pb_w) / 2 : CURVE_CP4_XPOS * belt_w;
448 gdk_cairo_set_source_pixbuf(cr.get(), category_pixbuf,
449 category_pb_x, (belt_h - category_pb_h) / 2);
450 cairo_paint(cr.get());
451 }
452
453 cairo_set_source_rgba(cr.get(), 1.0, 1.0, 1.0, 1.0);
454 cairo_move_to(cr.get(), 0.0, belt_h / 2);
381 pango_layout_get_pixel_size(layout, nullptr, &text_height);455 pango_layout_get_pixel_size(layout, nullptr, &text_height);
382 // current point is now in the middle of the stripe, need to translate456 // current point is now in the middle of the stripe, need to translate
383 // it, so that the text is centered457 // it, so that the text is centered
384 cairo_rel_move_to(cr.get(), 0.0, text_height / -2.0);458 cairo_rel_move_to(cr.get(), 0.0, text_height / -2.0);
385 double diagonal = sqrt(size_dbl*size_dbl*2);
386 // x coordinate also needs to be shifted
387 cairo_rel_move_to(cr.get(), (diagonal - max_text_width) / 4, 0.0);
388 pango_cairo_show_layout(cr.get(), layout);459 pango_cairo_show_layout(cr.get(), layout);
389460
461 // paint the shadow
462 cairo_restore(cr.get());
463
464 pattern.reset(cairo_pattern_create_linear(0.0, belt_h, 0.0, belt_h + SHADOW_BOTTOM_PADDING),
465 cairo_pattern_destroy);
466 cairo_pattern_add_color_stop_rgba(pattern.get(), 0.0, 0.0, 0.0, 0.0, 0.2);
467 cairo_pattern_add_color_stop_rgba(pattern.get(), 1.0, 0.0, 0.0, 0.0, 0.0);
468
469 cairo_set_source(cr.get(), pattern.get());
470
471 cairo_rectangle(cr.get(), 0.0, belt_h, belt_w, SHADOW_BOTTOM_PADDING);
472 cairo_fill(cr.get());
473
474 cairo_set_source_rgba(cr.get(), 0.0, 0.0, 0.0, 0.1);
475 cairo_move_to(cr.get(), 0.0, 1.0);
476 cairo_line_to(cr.get(), 0.0, belt_h);
477 cairo_stroke(cr.get());
478
479 cairo_move_to(cr.get(), belt_w, 1.0);
480 cairo_line_to(cr.get(), belt_w, belt_h);
481 cairo_stroke(cr.get());
482
390 // FIXME: going from image_surface to pixbuf, and then to texture :(483 // FIXME: going from image_surface to pixbuf, and then to texture :(
391 glib::Object<GdkPixbuf> detail_pb(484 glib::Object<GdkPixbuf> detail_pb(
392 gdk_pixbuf_get_from_surface(cairo_graphics.GetSurface(),485 gdk_pixbuf_get_from_surface(cairo_graphics.GetSurface(),
@@ -394,13 +487,14 @@
394 cairo_graphics.GetWidth(),487 cairo_graphics.GetWidth(),
395 cairo_graphics.GetHeight()));488 cairo_graphics.GetHeight()));
396489
490 int y_pos = icon_h - pixbuf_height - max_font_height / 2;
397 gdk_pixbuf_composite(detail_pb, result, // src, dest491 gdk_pixbuf_composite(detail_pb, result, // src, dest
398 icon_w - pixbuf_size, // dest_x492 0, // dest_x
399 icon_h - pixbuf_size, // dest_y493 y_pos, // dest_y
400 pixbuf_size, // dest_w494 pixbuf_width, // dest_w
401 pixbuf_size, // dest_h495 pixbuf_height, // dest_h
402 icon_w - pixbuf_size, // offset_x496 0, // offset_x
403 icon_h - pixbuf_size, // offset_y497 y_pos, // offset_y
404 1.0, 1.0, // scale_x, scale_y498 1.0, 1.0, // scale_x, scale_y
405 GDK_INTERP_NEAREST, // interpolation499 GDK_INTERP_NEAREST, // interpolation
406 255); // src_alpha500 255); // src_alpha
@@ -409,29 +503,76 @@
409 idle_id = g_idle_add(LoadIconComplete, this);503 idle_id = g_idle_add(LoadIconComplete, this);
410 }504 }
411505
412 void BaseIconLoaded(std::string const& base_icon_string, unsigned size,506 void BaseIconLoaded(std::string const& base_icon_string,
507 int max_width, int max_height,
413 glib::Object<GdkPixbuf> const& base_pixbuf,508 glib::Object<GdkPixbuf> const& base_pixbuf,
414 glib::Object<UnityProtocolAnnotatedIcon> const& anno_icon)509 glib::Object<UnityProtocolAnnotatedIcon> const& anno_icon)
415 {510 {
416 helper_handle = 0;511 helper_handle = 0;
417 if (base_pixbuf)512 if (base_pixbuf)
418 {513 {
419 result = gdk_pixbuf_copy(base_pixbuf);514 LOG_DEBUG(logger) << "Base icon loaded: '" << base_icon_string <<
515 "' size: " << gdk_pixbuf_get_width(base_pixbuf) << 'x' <<
516 gdk_pixbuf_get_height(base_pixbuf);
517
518 // we need extra space for the ribbon
519 result = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
520 gdk_pixbuf_get_width(base_pixbuf) + RIBBON_PADDING * 2,
521 gdk_pixbuf_get_height(base_pixbuf));
522 gdk_pixbuf_fill(result, 0x0);
523 gdk_pixbuf_copy_area(base_pixbuf, 0, 0,
524 gdk_pixbuf_get_width(base_pixbuf),
525 gdk_pixbuf_get_height(base_pixbuf),
526 result,
527 RIBBON_PADDING, 0);
420 // FIXME: can we composite the pixbuf in helper thread?528 // FIXME: can we composite the pixbuf in helper thread?
421 UnityProtocolCategoryType category = unity_protocol_annotated_icon_get_category(anno_icon);529 UnityProtocolCategoryType category = unity_protocol_annotated_icon_get_category(anno_icon);
422 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::CategoryIconLoaded), anno_icon);530 auto helper_slot = sigc::bind(sigc::mem_fun(this, &IconLoaderTask::CategoryIconLoaded), anno_icon);
423 unsigned cat_size = size / 4;531 int max_font_height;
424 // FIXME: we still don't have the category assets532 CalculateTextHeight(nullptr, &max_font_height);
533 unsigned cat_size = max_font_height * 9 / 8;
425 switch (category)534 switch (category)
426 {535 {
536 case UNITY_PROTOCOL_CATEGORY_TYPE_BOOK:
537 helper_handle =
538 impl->LoadFromFilename(PKGDATADIR"/emblem_books.svg", -1, cat_size, helper_slot);
539 break;
427 case UNITY_PROTOCOL_CATEGORY_TYPE_MUSIC:540 case UNITY_PROTOCOL_CATEGORY_TYPE_MUSIC:
428 helper_handle =541 helper_handle =
429 impl->LoadFromIconName("emblem-favorite", cat_size, helper_slot);542 impl->LoadFromFilename(PKGDATADIR"/emblem_music.svg", -1, cat_size, helper_slot);
430 break;543 break;
544 case UNITY_PROTOCOL_CATEGORY_TYPE_MOVIE:
545 helper_handle =
546 impl->LoadFromFilename(PKGDATADIR"/emblem_video.svg", -1, cat_size, helper_slot);
547 break;
548 case UNITY_PROTOCOL_CATEGORY_TYPE_CLOTHES:
549 case UNITY_PROTOCOL_CATEGORY_TYPE_SHOES:
550 helper_handle =
551 impl->LoadFromFilename(PKGDATADIR"/emblem_clothes.svg", -1, cat_size, helper_slot);
552 break;
553 case UNITY_PROTOCOL_CATEGORY_TYPE_GAMES:
554 case UNITY_PROTOCOL_CATEGORY_TYPE_ELECTRONICS:
555 case UNITY_PROTOCOL_CATEGORY_TYPE_COMPUTERS:
556 case UNITY_PROTOCOL_CATEGORY_TYPE_OFFICE:
557 case UNITY_PROTOCOL_CATEGORY_TYPE_HOME:
558 case UNITY_PROTOCOL_CATEGORY_TYPE_GARDEN:
559 case UNITY_PROTOCOL_CATEGORY_TYPE_PETS:
560 case UNITY_PROTOCOL_CATEGORY_TYPE_TOYS:
561 case UNITY_PROTOCOL_CATEGORY_TYPE_CHILDREN:
562 case UNITY_PROTOCOL_CATEGORY_TYPE_BABY:
563 case UNITY_PROTOCOL_CATEGORY_TYPE_WATCHES:
564 case UNITY_PROTOCOL_CATEGORY_TYPE_SPORTS:
565 case UNITY_PROTOCOL_CATEGORY_TYPE_OUTDOORS:
566 case UNITY_PROTOCOL_CATEGORY_TYPE_GROCERY:
567 case UNITY_PROTOCOL_CATEGORY_TYPE_HEALTH:
568 case UNITY_PROTOCOL_CATEGORY_TYPE_BEAUTY:
569 case UNITY_PROTOCOL_CATEGORY_TYPE_DIY:
570 case UNITY_PROTOCOL_CATEGORY_TYPE_TOOLS:
571 case UNITY_PROTOCOL_CATEGORY_TYPE_CAR:
431 default:572 default:
432 // rest of the processing is the CategoryIconLoaded, lets invoke it573 // rest of the processing is the CategoryIconLoaded, lets invoke it
433 glib::Object<GdkPixbuf> null_pixbuf;574 glib::Object<GdkPixbuf> null_pixbuf;
434 helper_slot("", cat_size, null_pixbuf);575 helper_slot("", -1, cat_size, null_pixbuf);
435 break;576 break;
436 }577 }
437 }578 }
@@ -463,32 +604,23 @@
463 glib::String contents;604 glib::String contents;
464 gsize length = 0;605 gsize length = 0;
465606
466 if (::g_file_load_contents(file, canc, &contents, &length,607 if (g_file_load_contents(file, canc, &contents, &length,
467 nullptr, &task->error))608 nullptr, &task->error))
468 {609 {
469 glib::Object<GInputStream> stream(610 glib::Object<GInputStream> stream(
470 ::g_memory_input_stream_new_from_data(contents.Value(), length, nullptr));611 g_memory_input_stream_new_from_data(contents.Value(), length, nullptr));
471612
472 if (task->size != static_cast<unsigned int>(~0))613 task->result = gdk_pixbuf_new_from_stream_at_scale(stream,
473 {614 task->max_width,
474 task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream,615 task->max_height,
475 -1,616 TRUE,
476 task->size,617 canc,
477 TRUE,618 &task->error);
478 canc,619 g_input_stream_close(stream, canc, nullptr);
479 &task->error);
480 }
481 else
482 {
483 task->result = ::gdk_pixbuf_new_from_stream(stream,
484 canc,
485 &task->error);
486 }
487 ::g_input_stream_close(stream, canc, nullptr);
488 }620 }
489 }621 }
490622
491 ::g_io_scheduler_job_send_to_mainloop_async (job, LoadIconComplete, task, nullptr);623 g_io_scheduler_job_send_to_mainloop_async (job, LoadIconComplete, task, nullptr);
492624
493 return FALSE;625 return FALSE;
494 }626 }
@@ -509,7 +641,9 @@
509 task->result = nullptr;641 task->result = nullptr;
510642
511 LOG_WARNING(logger) << "Unable to load icon " << task->data643 LOG_WARNING(logger) << "Unable to load icon " << task->data
512 << " at size " << task->size << ": " << task->error;644 << " at size "
645 << task->max_width << "x" << task->max_height
646 << ": " << task->error;
513 }647 }
514648
515 impl->finished_tasks_.push_back(task);649 impl->finished_tasks_.push_back(task);
@@ -528,21 +662,24 @@
528 };662 };
529663
530 Handle ReturnCachedOrQueue(std::string const& data,664 Handle ReturnCachedOrQueue(std::string const& data,
531 unsigned size,665 int max_width,
666 int max_height,
532 IconLoaderCallback slot,667 IconLoaderCallback slot,
533 IconLoaderRequestType type);668 IconLoaderRequestType type);
534669
535 Handle QueueTask(std::string const& key,670 Handle QueueTask(std::string const& key,
536 std::string const& data,671 std::string const& data,
537 unsigned size,672 int max_width,
673 int max_height,
538 IconLoaderCallback slot,674 IconLoaderCallback slot,
539 IconLoaderRequestType type);675 IconLoaderRequestType type);
540676
541 std::string Hash(std::string const& data, unsigned size);677 std::string Hash(std::string const& data, int max_width, int max_height);
542678
543 bool CacheLookup(std::string const& key,679 bool CacheLookup(std::string const& key,
544 std::string const& data,680 std::string const& data,
545 unsigned size,681 int max_width,
682 int max_height,
546 IconLoaderCallback slot);683 IconLoaderCallback slot);
547684
548 // Looping idle callback function685 // Looping idle callback function
@@ -600,52 +737,67 @@
600}737}
601738
602int IconLoader::Impl::LoadFromIconName(std::string const& icon_name,739int IconLoader::Impl::LoadFromIconName(std::string const& icon_name,
603 unsigned size,740 int max_width,
741 int max_height,
604 IconLoaderCallback slot)742 IconLoaderCallback slot)
605{743{
606 if (no_load_ || icon_name.empty() || size < MIN_ICON_SIZE || !slot)744 if (no_load_ || icon_name.empty() || !slot ||
745 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
746 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
607 return 0;747 return 0;
608748
609 // We need to check this because of legacy desktop files749 // We need to check this because of legacy desktop files
610 if (icon_name[0] == '/')750 if (icon_name[0] == '/')
611 {751 {
612 return LoadFromFilename(icon_name, size, slot);752 return LoadFromFilename(icon_name, max_width, max_height, slot);
613 }753 }
614754
615 return ReturnCachedOrQueue(icon_name, size, slot, REQUEST_TYPE_ICON_NAME);755 return ReturnCachedOrQueue(icon_name, max_width, max_height, slot,
756 REQUEST_TYPE_ICON_NAME);
616}757}
617758
618int IconLoader::Impl::LoadFromGIconString(std::string const& gicon_string,759int IconLoader::Impl::LoadFromGIconString(std::string const& gicon_string,
619 unsigned size,760 int max_width,
761 int max_height,
620 IconLoaderCallback slot)762 IconLoaderCallback slot)
621{763{
622 if (no_load_ || gicon_string.empty() || size < MIN_ICON_SIZE || !slot)764 if (no_load_ || gicon_string.empty() || !slot ||
765 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
766 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
623 return 0;767 return 0;
624768
625 return ReturnCachedOrQueue(gicon_string, size, slot, REQUEST_TYPE_GICON_STRING);769 return ReturnCachedOrQueue(gicon_string, max_width, max_height, slot,
770 REQUEST_TYPE_GICON_STRING);
626}771}
627772
628int IconLoader::Impl::LoadFromFilename(std::string const& filename,773int IconLoader::Impl::LoadFromFilename(std::string const& filename,
629 unsigned size,774 int max_width,
775 int max_height,
630 IconLoaderCallback slot)776 IconLoaderCallback slot)
631{777{
632 if (no_load_ || filename.empty() || size < MIN_ICON_SIZE || !slot)778 if (no_load_ || filename.empty() || !slot ||
779 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
780 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
633 return 0;781 return 0;
634782
635 glib::Object<GFile> file(::g_file_new_for_path(filename.c_str()));783 glib::Object<GFile> file(::g_file_new_for_path(filename.c_str()));
636 glib::String uri(::g_file_get_uri(file));784 glib::String uri(::g_file_get_uri(file));
637785
638 return LoadFromURI(uri.Str(), size, slot);786 return LoadFromURI(uri.Str(), max_width, max_height, slot);
639}787}
640788
641int IconLoader::Impl::LoadFromURI(std::string const& uri,789int IconLoader::Impl::LoadFromURI(std::string const& uri,
642 unsigned size,790 int max_width,
791 int max_height,
643 IconLoaderCallback slot)792 IconLoaderCallback slot)
644{793{
645 if (no_load_ || uri.empty() || size < MIN_ICON_SIZE || !slot)794 if (no_load_ || uri.empty() || !slot ||
795 ((max_width >= 0 && max_width < MIN_ICON_SIZE) ||
796 (max_height >= 0 && max_height < MIN_ICON_SIZE)))
646 return 0;797 return 0;
647798
648 return ReturnCachedOrQueue(uri, size, slot, REQUEST_TYPE_URI);799 return ReturnCachedOrQueue(uri, max_width, max_height, slot,
800 REQUEST_TYPE_URI);
649}801}
650802
651void IconLoader::Impl::DisconnectHandle(Handle handle)803void IconLoader::Impl::DisconnectHandle(Handle handle)
@@ -699,16 +851,17 @@
699//851//
700852
701int IconLoader::Impl::ReturnCachedOrQueue(std::string const& data,853int IconLoader::Impl::ReturnCachedOrQueue(std::string const& data,
702 unsigned size,854 int max_width,
855 int max_height,
703 IconLoaderCallback slot,856 IconLoaderCallback slot,
704 IconLoaderRequestType type)857 IconLoaderRequestType type)
705{858{
706 Handle result = 0;859 Handle result = 0;
707 std::string key(Hash(data, size));860 std::string key(Hash(data, max_width, max_height));
708861
709 if (!CacheLookup(key, data, size, slot))862 if (!CacheLookup(key, data, max_width, max_height, slot))
710 {863 {
711 result = QueueTask(key, data, size, slot, type);864 result = QueueTask(key, data, max_width, max_height, slot, type);
712 }865 }
713 return result;866 return result;
714}867}
@@ -716,11 +869,15 @@
716869
717int IconLoader::Impl::QueueTask(std::string const& key,870int IconLoader::Impl::QueueTask(std::string const& key,
718 std::string const& data,871 std::string const& data,
719 unsigned size,872 int max_width,
873 int max_height,
720 IconLoaderCallback slot,874 IconLoaderCallback slot,
721 IconLoaderRequestType type)875 IconLoaderRequestType type)
722{876{
723 auto task = std::make_shared<IconLoaderTask>(type, data, size, key, slot, ++handle_counter_, this);877 auto task = std::make_shared<IconLoaderTask>(type, data,
878 max_width, max_height,
879 key, slot,
880 ++handle_counter_, this);
724 auto iter = queued_tasks_.find(key);881 auto iter = queued_tasks_.find(key);
725882
726 if (iter != queued_tasks_.end())883 if (iter != queued_tasks_.end())
@@ -744,7 +901,8 @@
744 tasks_.push(task);901 tasks_.push(task);
745 task_map_[task->handle] = task;902 task_map_[task->handle] = task;
746903
747 LOG_DEBUG(logger) << "Pushing task " << data << " at size " << size904 LOG_DEBUG(logger) << "Pushing task " << data << " at size "
905 << max_width << "x" << max_height
748 << ", queue size now at " << tasks_.size();906 << ", queue size now at " << tasks_.size();
749907
750 if (!idle_)908 if (!idle_)
@@ -754,16 +912,17 @@
754 return task->handle;912 return task->handle;
755}913}
756914
757std::string IconLoader::Impl::Hash(std::string const& data, unsigned size)915std::string IconLoader::Impl::Hash(std::string const& data, int max_width, int max_height)
758{916{
759 std::ostringstream sout;917 std::ostringstream sout;
760 sout << data << ":" << size;918 sout << data << ":" << max_width << "x" << max_height;
761 return sout.str();919 return sout.str();
762}920}
763921
764bool IconLoader::Impl::CacheLookup(std::string const& key,922bool IconLoader::Impl::CacheLookup(std::string const& key,
765 std::string const& data,923 std::string const& data,
766 unsigned size,924 int max_width,
925 int max_height,
767 IconLoaderCallback slot)926 IconLoaderCallback slot)
768{927{
769 auto iter = cache_.find(key);928 auto iter = cache_.find(key);
@@ -772,7 +931,7 @@
772 if (found && slot)931 if (found && slot)
773 {932 {
774 glib::Object<GdkPixbuf> const& pixbuf = iter->second;933 glib::Object<GdkPixbuf> const& pixbuf = iter->second;
775 slot(data, size, pixbuf);934 slot(data, max_width, max_height, pixbuf);
776 }935 }
777936
778 return found;937 return found;
@@ -848,31 +1007,35 @@
848}1007}
8491008
850int IconLoader::LoadFromIconName(std::string const& icon_name,1009int IconLoader::LoadFromIconName(std::string const& icon_name,
851 unsigned size,1010 int max_width,
1011 int max_height,
852 IconLoaderCallback slot)1012 IconLoaderCallback slot)
853{1013{
854 return pimpl->LoadFromIconName(icon_name, size, slot);1014 return pimpl->LoadFromIconName(icon_name, max_width, max_height, slot);
855}1015}
8561016
857int IconLoader::LoadFromGIconString(std::string const& gicon_string,1017int IconLoader::LoadFromGIconString(std::string const& gicon_string,
858 unsigned size,1018 int max_width,
1019 int max_height,
859 IconLoaderCallback slot)1020 IconLoaderCallback slot)
860{1021{
861 return pimpl->LoadFromGIconString(gicon_string, size, slot);1022 return pimpl->LoadFromGIconString(gicon_string, max_width, max_height, slot);
862}1023}
8631024
864int IconLoader::LoadFromFilename(std::string const& filename,1025int IconLoader::LoadFromFilename(std::string const& filename,
865 unsigned size,1026 int max_width,
1027 int max_height,
866 IconLoaderCallback slot)1028 IconLoaderCallback slot)
867{1029{
868 return pimpl->LoadFromFilename(filename, size, slot);1030 return pimpl->LoadFromFilename(filename, max_width, max_height, slot);
869}1031}
8701032
871int IconLoader::LoadFromURI(std::string const& uri,1033int IconLoader::LoadFromURI(std::string const& uri,
872 unsigned size,1034 int max_width,
1035 int max_height,
873 IconLoaderCallback slot)1036 IconLoaderCallback slot)
874{1037{
875 return pimpl->LoadFromURI(uri, size, slot);1038 return pimpl->LoadFromURI(uri, max_width, max_height, slot);
876}1039}
8771040
878void IconLoader::DisconnectHandle(int handle)1041void IconLoader::DisconnectHandle(int handle)
8791042
=== modified file 'unity-shared/IconLoader.h'
--- unity-shared/IconLoader.h 2012-07-16 11:03:32 +0000
+++ unity-shared/IconLoader.h 2012-09-13 10:12:22 +0000
@@ -32,7 +32,7 @@
32class IconLoader : public boost::noncopyable32class IconLoader : public boost::noncopyable
33{33{
34public:34public:
35 typedef std::function<void(std::string const&, unsigned, glib::Object<GdkPixbuf> const&)> IconLoaderCallback;35 typedef std::function<void(std::string const&, int, int, glib::Object<GdkPixbuf> const&)> IconLoaderCallback;
3636
37 IconLoader();37 IconLoader();
38 ~IconLoader();38 ~IconLoader();
@@ -45,19 +45,23 @@
45 */45 */
4646
47 int LoadFromIconName(std::string const& icon_name,47 int LoadFromIconName(std::string const& icon_name,
48 unsigned size,48 int max_width,
49 int max_height,
49 IconLoaderCallback slot);50 IconLoaderCallback slot);
5051
51 int LoadFromGIconString(std::string const& gicon_string,52 int LoadFromGIconString(std::string const& gicon_string,
52 unsigned size,53 int max_width,
54 int max_height,
53 IconLoaderCallback slot);55 IconLoaderCallback slot);
5456
55 int LoadFromFilename(std::string const& filename,57 int LoadFromFilename(std::string const& filename,
56 unsigned size,58 int max_width,
59 int max_height,
57 IconLoaderCallback slot);60 IconLoaderCallback slot);
5861
59 int LoadFromURI(std::string const& uri,62 int LoadFromURI(std::string const& uri,
60 unsigned size,63 int max_width,
64 int max_height,
61 IconLoaderCallback slot);65 IconLoaderCallback slot);
6266
63 void DisconnectHandle(int handle);67 void DisconnectHandle(int handle);
6468
=== modified file 'unity-shared/IconTexture.cpp'
--- unity-shared/IconTexture.cpp 2012-08-07 15:46:38 +0000
+++ unity-shared/IconTexture.cpp 2012-09-13 10:12:22 +0000
@@ -111,21 +111,21 @@
111111
112 glib::Object<GIcon> icon(g_icon_new_for_string(_icon_name.empty() ? DEFAULT_GICON : _icon_name.c_str(), NULL));112 glib::Object<GIcon> icon(g_icon_new_for_string(_icon_name.empty() ? DEFAULT_GICON : _icon_name.c_str(), NULL));
113113
114 if (G_IS_ICON(icon.RawPtr()))114 if (icon.IsType(G_TYPE_ICON))
115 {115 {
116 _handle = IconLoader::GetDefault().LoadFromGIconString(_icon_name.empty() ? DEFAULT_GICON : _icon_name.c_str(),116 _handle = IconLoader::GetDefault().LoadFromGIconString(_icon_name.empty() ? DEFAULT_GICON : _icon_name.c_str(),
117 _size,117 -1, _size,
118 sigc::mem_fun(this, &IconTexture::IconLoaded));118 sigc::mem_fun(this, &IconTexture::IconLoaded));
119 }119 }
120 else if (_icon_name.find("http://") == 0)120 else if (_icon_name.find("http://") == 0)
121 {121 {
122 _handle = IconLoader::GetDefault().LoadFromURI(_icon_name,122 _handle = IconLoader::GetDefault().LoadFromURI(_icon_name,
123 _size, sigc::mem_fun(this, &IconTexture::IconLoaded));123 -1, _size, sigc::mem_fun(this, &IconTexture::IconLoaded));
124 }124 }
125 else125 else
126 {126 {
127 _handle = IconLoader::GetDefault().LoadFromIconName(_icon_name,127 _handle = IconLoader::GetDefault().LoadFromIconName(_icon_name,
128 _size,128 -1, _size,
129 sigc::mem_fun(this, &IconTexture::IconLoaded));129 sigc::mem_fun(this, &IconTexture::IconLoaded));
130 }130 }
131}131}
@@ -153,7 +153,9 @@
153 _loading = false;153 _loading = false;
154}154}
155155
156void IconTexture::IconLoaded(std::string const& icon_name, unsigned size,156void IconTexture::IconLoaded(std::string const& icon_name,
157 int max_width,
158 int max_height,
157 glib::Object<GdkPixbuf> const& pixbuf)159 glib::Object<GdkPixbuf> const& pixbuf)
158{160{
159 _handle = 0;161 _handle = 0;
160162
=== modified file 'unity-shared/IconTexture.h'
--- unity-shared/IconTexture.h 2012-08-07 15:46:38 +0000
+++ unity-shared/IconTexture.h 2012-09-13 10:12:22 +0000
@@ -79,7 +79,7 @@
79private:79private:
80 nux::BaseTexture* CreateTextureCallback(std::string const& texid, int width, int height);80 nux::BaseTexture* CreateTextureCallback(std::string const& texid, int width, int height);
81 void Refresh(glib::Object<GdkPixbuf> const& pixbuf);81 void Refresh(glib::Object<GdkPixbuf> const& pixbuf);
82 void IconLoaded(std::string const& icon_name, unsigned size, glib::Object<GdkPixbuf> const& pixbuf);82 void IconLoaded(std::string const& icon_name, int max_width, int max_height, glib::Object<GdkPixbuf> const& pixbuf);
8383
84 std::string _icon_name;84 std::string _icon_name;
85 unsigned int _size;85 unsigned int _size;