From 84a27086bbd9f493128b354300f9c77ccb32a56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sat, 18 Apr 2015 15:42:59 +0200 Subject: Imported Upstream version 0.6.0 --- src/images/icon.vala | 82 +++++++++++++++--------------- src/images/image.vala | 38 +++++++------- src/images/renderedText.vala | 118 +++++++++++++++++++++---------------------- src/images/themedIcon.vala | 82 +++++++++++++++--------------- 4 files changed, 160 insertions(+), 160 deletions(-) (limited to 'src/images') diff --git a/src/images/icon.vala b/src/images/icon.vala index 6dfb53b..9cfccf8 100644 --- a/src/images/icon.vala +++ b/src/images/icon.vala @@ -1,23 +1,23 @@ -/* -Copyright (c) 2011 by Simon Schneegans - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation, either version 3 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -*/ +///////////////////////////////////////////////////////////////////////// +// Copyright (c) 2011-2015 by Simon Schneegans +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +///////////////////////////////////////////////////////////////////////// namespace GnomePie { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// A class representing a square-shaped icon, loaded from the users /// icon theme. ///////////////////////////////////////////////////////////////////////// @@ -30,34 +30,34 @@ public class Icon : Image { ///////////////////////////////////////////////////////////////////// private static Gee.HashMap cache { private get; private set; } - + ///////////////////////////////////////////////////////////////////// /// Initializes the cache. ///////////////////////////////////////////////////////////////////// - + public static void init() { clear_cache(); - + Gtk.IconTheme.get_default().changed.connect(() => { clear_cache(); }); } - + ///////////////////////////////////////////////////////////////////// /// Clears the cache. ///////////////////////////////////////////////////////////////////// - + public static void clear_cache() { cache = new Gee.HashMap(); } - + ///////////////////////////////////////////////////////////////////// /// Loads an icon from the current icon theme of the user. ///////////////////////////////////////////////////////////////////// - + public Icon(string icon_name, int size) { var cached = Icon.cache.get("%s@%u".printf(icon_name, size)); - + if (cached == null) { this.load_file_at_size(Icon.get_icon_file(icon_name, size), size, size); Icon.cache.set("%s@%u".printf(icon_name, size), this.surface); @@ -65,56 +65,56 @@ public class Icon : Image { this.surface = cached; } } - + ///////////////////////////////////////////////////////////////////// /// Returns the size of the icon in pixels. Greetings to Liskov. ///////////////////////////////////////////////////////////////////// - + public int size() { return base.width(); } - + ///////////////////////////////////////////////////////////////////// /// Returns the icon name for a given GLib.Icon. ///////////////////////////////////////////////////////////////////// - + public static string get_icon_name(GLib.Icon? icon) { if (icon != null) { var icon_names = icon.to_string().split(" "); - + foreach (var icon_name in icon_names) { if (Gtk.IconTheme.get_default().has_icon(icon_name)) { return icon_name; } } } - + return ""; } - + ///////////////////////////////////////////////////////////////////// /// Returns the filename for a given system icon. ///////////////////////////////////////////////////////////////////// - + public static string get_icon_file(string icon_name, int size) { string result = ""; - + if (icon_name.contains("/")) { var file = GLib.File.new_for_path(icon_name); if(file.query_exists()) return icon_name; - + warning("Icon \"" + icon_name + "\" not found! Using default icon..."); } - - + + var icon_theme = Gtk.IconTheme.get_default(); var file = icon_theme.lookup_icon(icon_name, size, 0); if (file != null) result = file.get_filename(); - + if (result == "") { warning("Icon \"" + icon_name + "\" not found! Using default icon..."); - + string[] default_icons = {"application-default-icon", "stock_unknown"}; foreach (var icon in default_icons) { file = icon_theme.lookup_icon(icon, size, 0); @@ -123,11 +123,11 @@ public class Icon : Image { break; } } - + if (result == "") warning("No default icon found! Will be ugly..."); } - + return result; } } diff --git a/src/images/image.vala b/src/images/image.vala index e65e34a..a903493 100644 --- a/src/images/image.vala +++ b/src/images/image.vala @@ -1,19 +1,19 @@ -/* -Copyright (c) 2011 by Simon Schneegans - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation, either version 3 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -*/ +///////////////////////////////////////////////////////////////////////// +// Copyright (c) 2011-2015 by Simon Schneegans +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +///////////////////////////////////////////////////////////////////////// namespace GnomePie { @@ -163,10 +163,10 @@ public class Image : GLib.Object { ///////////////////////////////////////////////////////////////////// public Gdk.Pixbuf to_pixbuf() { - if (this.surface == null || this.surface.get_data().length <= 0) + if (this.surface == null || this.surface.get_data() == null) return new Gdk.Pixbuf(Gdk.Colorspace.RGB, true, 8, 1, 1); - var pixbuf = new Gdk.Pixbuf.from_data(this.surface.get_data(), Gdk.Colorspace.RGB, true, 8, + var pixbuf = new Gdk.Pixbuf.with_unowned_data(this.surface.get_data(), Gdk.Colorspace.RGB, true, 8, width(), height(), this.surface.get_stride(), null); pixbuf = pixbuf.copy(); @@ -180,7 +180,7 @@ public class Image : GLib.Object { *(p + i + 2) = tmp; } - return pixbuf; + return pixbuf; } ///////////////////////////////////////////////////////////////////// diff --git a/src/images/renderedText.vala b/src/images/renderedText.vala index 544af1f..2f4b82f 100644 --- a/src/images/renderedText.vala +++ b/src/images/renderedText.vala @@ -1,149 +1,149 @@ -/* -Copyright (c) 2011 by Simon Schneegans - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation, either version 3 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -*/ +///////////////////////////////////////////////////////////////////////// +// Copyright (c) 2011-2015 by Simon Schneegans +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +///////////////////////////////////////////////////////////////////////// namespace GnomePie { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// A class representing string, rendered on an Image. ///////////////////////////////////////////////////////////////////////// public class RenderedText : Image { - + ///////////////////////////////////////////////////////////////////// /// C'tor, creates a new image representation of a string. ///////////////////////////////////////////////////////////////////// - + public RenderedText(string text, int width, int height, string font, Color color, double scale) { - + this.render_text(text, width, height, font, color, scale); } - + ///////////////////////////////////////////////////////////////////// /// C'tor, creates a new image representation of a string. This /// string may contain markup information. ///////////////////////////////////////////////////////////////////// - + public RenderedText.with_markup(string text, int width, int height, string font, Color color, double scale) { this.render_markup(text, width, height, font, color, scale); } - + ///////////////////////////////////////////////////////////////////// /// Creates a new transparent image, with text written onto. ///////////////////////////////////////////////////////////////////// - - public void render_text(string text, int width, int height, string font, + + public void render_text(string text, int width, int height, string font, Color color, double scale) { - + this.surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height); if (text != "") { var ctx = this.context(); - + // set the color ctx.set_source_rgb(color.r, color.g, color.g); - - var layout = Pango.cairo_create_layout(ctx); + + var layout = Pango.cairo_create_layout(ctx); layout.set_width(Pango.units_from_double(width)); - + var font_description = Pango.FontDescription.from_string(font); font_description.set_size((int)(font_description.get_size() * scale)); - + layout.set_font_description(font_description); layout.set_text(text, -1); - + // add newlines at the end of each line, in order to allow ellipsizing string broken_string = ""; - + for (int i=0; i height) broken_string = broken_string + next_line; else broken_string = broken_string_tmp; } } - + layout.set_text(broken_string, -1); - + layout.set_ellipsize(Pango.EllipsizeMode.END); layout.set_alignment(Pango.Alignment.CENTER); - + Pango.Rectangle extents; layout.get_pixel_extents(null, out extents); ctx.move_to(0, (int)(0.5*(height - extents.height))); - + Pango.cairo_update_layout(ctx, layout); Pango.cairo_show_layout(ctx, layout); } } - + ///////////////////////////////////////////////////////////////////// /// Creates a new transparent image, with text written onto. ///////////////////////////////////////////////////////////////////// - - public void render_markup(string text, int width, int height, string font, + + public void render_markup(string text, int width, int height, string font, Color color, double scale) { - + this.surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height); var ctx = this.context(); - - // set the color + + // set the color ctx.set_source_rgb(color.r, color.g, color.g); - - var layout = Pango.cairo_create_layout(ctx); + + var layout = Pango.cairo_create_layout(ctx); layout.set_width(Pango.units_from_double(width)); - + var font_description = Pango.FontDescription.from_string(font); font_description.set_size((int)(font_description.get_size() * scale)); - + layout.set_font_description(font_description); layout.set_markup(text, -1); - + layout.set_ellipsize(Pango.EllipsizeMode.END); layout.set_alignment(Pango.Alignment.CENTER); - + Pango.Rectangle extents; layout.get_pixel_extents(null, out extents); ctx.move_to(0, (int)(0.5*(height - extents.height))); - + Pango.cairo_update_layout(ctx, layout); Pango.cairo_show_layout(ctx, layout); } diff --git a/src/images/themedIcon.vala b/src/images/themedIcon.vala index f816e0f..b7b6f74 100644 --- a/src/images/themedIcon.vala +++ b/src/images/themedIcon.vala @@ -1,96 +1,96 @@ -/* -Copyright (c) 2011 by Simon Schneegans - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by the Free -Software Foundation, either version 3 of the License, or (at your option) -any later version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -more details. - -You should have received a copy of the GNU General Public License along with -this program. If not, see . -*/ +///////////////////////////////////////////////////////////////////////// +// Copyright (c) 2011-2015 by Simon Schneegans +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +///////////////////////////////////////////////////////////////////////// namespace GnomePie { -///////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// /// A class representing a square-shaped icon, themed according to the /// current theme of Gnome-Pie. ///////////////////////////////////////////////////////////////////////// public class ThemedIcon : Image { - + ///////////////////////////////////////////////////////////////////// /// Paint a slice icon according to the current theme. ///////////////////////////////////////////////////////////////////// - + 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; - + // get max size int size = 1; foreach (var layer in layers) { - if (layer.image != null && layer.image.width() > size) + if (layer.image != null && layer.image.width() > size) size = layer.image.width(); } - + this.surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, size, size); - + // get size of icon layer int icon_size = size; foreach (var layer in layers) { if (layer.image != null && layer.layer_type == SliceLayer.Type.ICON) icon_size = layer.image.width(); } - + Image icon; if (icon_name.contains("/")) icon = new Image.from_file_at_size(icon_name, icon_size, icon_size); else icon = new Icon(icon_name, icon_size); - + var color = new Color.from_icon(icon); var ctx = this.context(); - + ctx.translate(size/2, size/2); ctx.set_operator(Cairo.Operator.OVER); - + // now render all layers on top of each other foreach (var layer in layers) { - - if (layer.visibility == SliceLayer.Visibility.ANY || + + if (layer.visibility == SliceLayer.Visibility.ANY || (Config.global.show_captions == (layer.visibility == SliceLayer.Visibility.WITH_CAPTION))) { - + if (layer.colorize) { ctx.push_group(); } - + 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 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); @@ -99,13 +99,13 @@ public class ThemedIcon : Image { } else if (layer.layer_type == SliceLayer.Type.FILE) { 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.set_operator(Cairo.Operator.OVER); ctx.pop_group_to_source(); ctx.paint(); @@ -113,11 +113,11 @@ public class ThemedIcon : Image { } } } - + ///////////////////////////////////////////////////////////////////// /// Returns the size of the icon in pixels. Greetings to Liskov. ///////////////////////////////////////////////////////////////////// - + public int size() { return base.width(); } -- cgit v1.2.3