summaryrefslogtreecommitdiff
path: root/src/images/themedIcon.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/images/themedIcon.vala')
-rw-r--r--src/images/themedIcon.vala129
1 files changed, 47 insertions, 82 deletions
diff --git a/src/images/themedIcon.vala b/src/images/themedIcon.vala
index 6c904a6..f816e0f 100644
--- a/src/images/themedIcon.vala
+++ b/src/images/themedIcon.vala
@@ -23,54 +23,12 @@ namespace GnomePie {
/////////////////////////////////////////////////////////////////////////
public class ThemedIcon : Image {
-
- /////////////////////////////////////////////////////////////////////
- /// A cache which stores loaded icon. The key is the icon name. When
- /// the users icon theme or the theme of Gnome-Pie changes, these
- /// cahces are cleared.
- /////////////////////////////////////////////////////////////////////
-
- private static Gee.HashMap<string, Cairo.ImageSurface?> active_cache { private get; private set; }
- private static Gee.HashMap<string, Cairo.ImageSurface?> inactive_cache { private get; private set; }
-
- /////////////////////////////////////////////////////////////////////
- /// Initializes the caches.
- /////////////////////////////////////////////////////////////////////
-
- public static void init() {
- clear_cache();
-
- Config.global.notify["theme"].connect(() => {
- clear_cache();
- });
-
- Gtk.IconTheme.get_default().changed.connect(() => {
- clear_cache();
- });
- }
-
- /////////////////////////////////////////////////////////////////////
- /// Clears the cache.
- /////////////////////////////////////////////////////////////////////
-
- public static void clear_cache() {
- active_cache = new Gee.HashMap<string, Cairo.ImageSurface?>();
- inactive_cache = new Gee.HashMap<string, Cairo.ImageSurface?>();
- }
/////////////////////////////////////////////////////////////////////
/// Paint a slice icon according to the current theme.
/////////////////////////////////////////////////////////////////////
- public ThemedIcon(string icon_name, bool active) {
- // check cache
- var current_cache = active ? active_cache : inactive_cache;
- var cached = current_cache.get(icon_name);
-
- if (cached != null) {
- this.surface = cached;
- return;
- }
+ public ThemedIcon(string caption, string icon_name, bool active) {
// get layers for the desired slice type
var layers = active ? Config.global.theme.active_slice_layers : Config.global.theme.inactive_slice_layers;
@@ -78,7 +36,8 @@ public class ThemedIcon : Image {
// get max size
int size = 1;
foreach (var layer in layers) {
- if (layer.image.width() > size) size = layer.image.width();
+ if (layer.image != null && layer.image.width() > size)
+ size = layer.image.width();
}
this.surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, size, size);
@@ -86,7 +45,8 @@ public class ThemedIcon : Image {
// get size of icon layer
int icon_size = size;
foreach (var layer in layers) {
- if (layer.is_icon) icon_size = layer.image.width();
+ if (layer.image != null && layer.layer_type == SliceLayer.Type.ICON)
+ icon_size = layer.image.width();
}
Image icon;
@@ -104,49 +64,54 @@ public class ThemedIcon : Image {
// now render all layers on top of each other
foreach (var layer in layers) {
- if (layer.colorize) {
- ctx.push_group();
- }
-
- if (layer.is_icon) {
+ if (layer.visibility == SliceLayer.Visibility.ANY ||
+ (Config.global.show_captions == (layer.visibility == SliceLayer.Visibility.WITH_CAPTION))) {
- ctx.push_group();
-
- layer.image.paint_on(ctx);
-
- ctx.set_operator(Cairo.Operator.IN);
-
- if (layer.image.width() != icon_size) {
- if (icon_name.contains("/"))
- icon = new Image.from_file_at_size(icon_name, layer.image.width(), layer.image.width());
- else
- icon = new Icon(icon_name,layer.image.width());
+ if (layer.colorize) {
+ ctx.push_group();
}
-
- icon.paint_on(ctx);
+
+ if (layer.layer_type == SliceLayer.Type.ICON) {
+ ctx.push_group();
+
+ layer.image.paint_on(ctx);
+
+ ctx.set_operator(Cairo.Operator.IN);
+
+ if (layer.image.width() != icon_size) {
+ if (icon_name.contains("/"))
+ icon = new Image.from_file_at_size(icon_name, layer.image.width(), layer.image.width());
+ else
+ icon = new Icon(icon_name,layer.image.width());
+ }
+
+ icon.paint_on(ctx);
- ctx.pop_group_to_source();
- ctx.paint();
- ctx.set_operator(Cairo.Operator.OVER);
-
- } else {
- layer.image.paint_on(ctx);
- }
-
- // colorize the whole layer if neccasary
- if (layer.colorize) {
- ctx.set_operator(Cairo.Operator.ATOP);
- ctx.set_source_rgb(color.r, color.g, color.b);
- ctx.paint();
+ ctx.pop_group_to_source();
+ ctx.paint();
+ ctx.set_operator(Cairo.Operator.OVER);
+
+ } else if (layer.layer_type == SliceLayer.Type.CAPTION) {
+ Image text = new RenderedText(caption, layer.width, layer.height, layer.font, layer.color, Config.global.global_scale);
+ ctx.translate(0, layer.position);
+ text.paint_on(ctx);
+ ctx.translate(0, -layer.position);
+ } else if (layer.layer_type == SliceLayer.Type.FILE) {
+ layer.image.paint_on(ctx);
+ }
- ctx.set_operator(Cairo.Operator.OVER);
- ctx.pop_group_to_source();
- ctx.paint();
+ // colorize the whole layer if neccasary
+ if (layer.colorize) {
+ ctx.set_operator(Cairo.Operator.ATOP);
+ ctx.set_source_rgb(color.r, color.g, color.b);
+ ctx.paint();
+
+ ctx.set_operator(Cairo.Operator.OVER);
+ ctx.pop_group_to_source();
+ ctx.paint();
+ }
}
}
-
- // store the surface in cache
- current_cache.set(icon_name, this.surface);
}
/////////////////////////////////////////////////////////////////////