[gnome-boxes] machine-thumbnailer: Make style customizable
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] machine-thumbnailer: Make style customizable
- Date: Sat, 22 Aug 2015 12:11:18 +0000 (UTC)
commit 667108db0b23f0eeb9eea1b84d63b7f38234fc5f
Author: Adrien Plazas <kekun plazas laposte net>
Date: Wed Aug 12 14:27:25 2015 +0200
machine-thumbnailer: Make style customizable
Makes the colors and sizes of the produced thumbnail customizable.
This allows to have a different style for the list view's thumbnails
which will be added in a subsequent commit.
https://bugzilla.gnome.org/show_bug.cgi?id=733252
src/machine-thumbnailer.vala | 67 ++++++++++++++++++++++++++---------------
src/machine.vala | 9 +++++-
2 files changed, 50 insertions(+), 26 deletions(-)
---
diff --git a/src/machine-thumbnailer.vala b/src/machine-thumbnailer.vala
index b1137c7..c22bd7e 100644
--- a/src/machine-thumbnailer.vala
+++ b/src/machine-thumbnailer.vala
@@ -4,22 +4,34 @@ private class Boxes.MachineThumbnailer: Object {
private const Gtk.CornerType[] right_corners = { Gtk.CornerType.TOP_RIGHT, Gtk.CornerType.BOTTOM_RIGHT };
private const Gtk.CornerType[] bottom_corners = { Gtk.CornerType.BOTTOM_LEFT,
Gtk.CornerType.BOTTOM_RIGHT };
- public const Gdk.RGBA FRAME_BORDER_COLOR = { 0x3b / 255.0, 0x3c / 255.0, 0x38 / 255.0, 1.0 };
- public const Gdk.RGBA FRAME_BACKGROUND_COLOR = { 0x2d / 255.0, 0x2d / 255.0, 0x2d / 255.0, 1.0 };
public const double FRAME_RADIUS = 2.0;
-
public const Gdk.RGBA CENTERED_EMBLEM_COLOR = { 0xbe / 255.0, 0xbe / 255.0, 0xbe / 255.0, 1.0 };
public const Gdk.RGBA SMALL_EMBLEM_COLOR = { 1.0, 1.0, 1.0, 1.0 };
- public const int BIG_EMBLEM_SIZE = 32;
- public const int SMALL_EMBLEM_SIZE = 16;
public const int EMBLEM_PADDING = 8;
public weak Machine machine { get; private set; }
+ public int width { get; set; }
+ public int height { get; set; }
+ public int centred_emblem_size { get; set; }
+ public int emblem_size { get; set; }
+ public Gdk.RGBA border_color { get; set; }
+ public Gdk.RGBA background_color { get; set; }
public Gdk.Pixbuf thumbnail { get; private set; }
- public MachineThumbnailer (Machine machine) {
+ public bool favorite_emblem_enabled { get; set; default = true; }
+
+ public MachineThumbnailer (Machine machine,
+ int width, int height,
+ int centred_emblem_size, int emblem_size,
+ Gdk.RGBA border_color, Gdk.RGBA background_color) {
this.machine = machine;
+ this.width = width;
+ this.height = height;
+ this.centred_emblem_size = centred_emblem_size;
+ this.emblem_size = emblem_size;
+ this.border_color = border_color;
+ this.background_color = background_color;
machine.notify["pixbuf"].connect (() => {
update_thumbnail ();
@@ -33,67 +45,72 @@ private class Boxes.MachineThumbnailer: Object {
update_thumbnail ();
});
+ notify["width"].connect (update_thumbnail);
+ notify["height"].connect (update_thumbnail);
+ notify["border-color"].connect (update_thumbnail);
+ notify["favorite-emblem-enabled"].connect (update_thumbnail);
+ notify["construction-spinner-enabled"].connect (update_thumbnail);
+
update_thumbnail ();
}
private void update_thumbnail () {
- Gdk.Pixbuf new_thumbnail;
+ Gdk.Pixbuf? new_thumbnail = null;
if (machine.is_stopped)
new_thumbnail = machine.under_construction ? get_under_construction_thumbnail () :
get_stopped_thumbnail ();
- else
- new_thumbnail = machine.pixbuf;
+ else if (machine.pixbuf != null)
+ new_thumbnail = machine.pixbuf.scale_simple (width, height, Gdk.InterpType.BILINEAR);
// Use the default thumbnail if no thumbnail have been chosen
if (new_thumbnail == null)
new_thumbnail = get_default_thumbnail ();
- if ("favorite" in machine.config.categories)
+ if (favorite_emblem_enabled && "favorite" in machine.config.categories)
new_thumbnail = add_emblem_icon (new_thumbnail, "starred-symbolic", Gtk.CornerType.BOTTOM_LEFT);
thumbnail = new_thumbnail;
}
- private static Gdk.Pixbuf? empty_thumbnail;
- private static Gdk.Pixbuf get_empty_thumbnail () {
+ private Gdk.Pixbuf? empty_thumbnail;
+ private Gdk.Pixbuf get_empty_thumbnail () {
if (empty_thumbnail != null)
return empty_thumbnail;
- empty_thumbnail = paint_empty_frame (Machine.SCREENSHOT_WIDTH, Machine.SCREENSHOT_HEIGHT,
FRAME_RADIUS,
- FRAME_BORDER_COLOR, FRAME_BACKGROUND_COLOR);
+ empty_thumbnail = paint_empty_frame (width, height, FRAME_RADIUS, border_color, background_color);
return empty_thumbnail;
}
- private static Gdk.Pixbuf? default_thumbnail;
- private static Gdk.Pixbuf get_default_thumbnail () {
+ private Gdk.Pixbuf? default_thumbnail;
+ private Gdk.Pixbuf get_default_thumbnail () {
if (default_thumbnail != null)
return default_thumbnail;
var frame = get_empty_thumbnail ();
- default_thumbnail = add_centered_emblem_icon (frame, "computer-symbolic", BIG_EMBLEM_SIZE);
+ default_thumbnail = add_centered_emblem_icon (frame, "computer-symbolic", centred_emblem_size);
return default_thumbnail;
}
- private static Gdk.Pixbuf? stopped_thumbnail;
- private static Gdk.Pixbuf get_stopped_thumbnail () {
+ private Gdk.Pixbuf? stopped_thumbnail;
+ private Gdk.Pixbuf get_stopped_thumbnail () {
if (stopped_thumbnail != null)
return stopped_thumbnail;
var frame = get_empty_thumbnail ();
- stopped_thumbnail = add_centered_emblem_icon (frame, "system-shutdown-symbolic", BIG_EMBLEM_SIZE);
+ stopped_thumbnail = add_centered_emblem_icon (frame, "system-shutdown-symbolic",
centred_emblem_size);
return stopped_thumbnail;
}
- private static Gdk.Pixbuf get_under_construction_thumbnail () {
+ private Gdk.Pixbuf get_under_construction_thumbnail () {
// If the machine is being constructed, it will draw a spinner itself, so we only need to draw an
empty frame.
return get_empty_thumbnail ();
}
- private static Gdk.Pixbuf add_centered_emblem_icon (Gdk.Pixbuf pixbuf, string icon_name, int size) {
+ private Gdk.Pixbuf add_centered_emblem_icon (Gdk.Pixbuf pixbuf, string icon_name, int size) {
Gdk.Pixbuf? emblem = null;
var theme = Gtk.IconTheme.get_default ();
@@ -119,12 +136,12 @@ private class Boxes.MachineThumbnailer: Object {
}
- private static Gdk.Pixbuf add_emblem_icon (Gdk.Pixbuf pixbuf, string icon_name, Gtk.CornerType
corner_type) {
+ private Gdk.Pixbuf add_emblem_icon (Gdk.Pixbuf pixbuf, string icon_name, Gtk.CornerType corner_type) {
Gdk.Pixbuf? emblem = null;
var theme = Gtk.IconTheme.get_default ();
try {
- var icon_info = theme.lookup_icon (icon_name, SMALL_EMBLEM_SIZE, Gtk.IconLookupFlags.FORCE_SIZE);
+ var icon_info = theme.lookup_icon (icon_name, emblem_size, Gtk.IconLookupFlags.FORCE_SIZE);
emblem = icon_info.load_symbolic (SMALL_EMBLEM_COLOR);
} catch (GLib.Error error) {
warning (@"Unable to get icon '$icon_name': $(error.message)");
@@ -141,7 +158,7 @@ private class Boxes.MachineThumbnailer: Object {
EMBLEM_PADDING;
var emblemed = pixbuf.copy ();
- emblem.composite (emblemed, offset_x, offset_y, SMALL_EMBLEM_SIZE, SMALL_EMBLEM_SIZE,
+ emblem.composite (emblemed, offset_x, offset_y, emblem_size, emblem_size,
offset_x, offset_y, 1.0, 1.0, Gdk.InterpType.BILINEAR, 255);
return emblemed;
diff --git a/src/machine.vala b/src/machine.vala
index 1c1a6ff..b60c4a4 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -75,6 +75,10 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
private uint screenshot_id;
public static const int SCREENSHOT_WIDTH = 180;
public static const int SCREENSHOT_HEIGHT = 134;
+ public const int CENTERED_EMBLEM_SIZE = 32;
+ public const int EMBLEM_SIZE = 16;
+ public const Gdk.RGBA FRAME_BORDER_COLOR = { 0x3b / 255.0, 0x3c / 255.0, 0x38 / 255.0, 1.0 };
+ public const Gdk.RGBA FRAME_BACKGROUND_COLOR = { 0x2d / 255.0, 0x2d / 255.0, 0x2d / 255.0, 1.0 };
private static Cairo.Surface grid_surface;
private bool updating_screenshot;
private string username;
@@ -259,7 +263,10 @@ private abstract class Boxes.Machine: Boxes.CollectionItem, Boxes.IPropertiesPro
create_display_config (uuid);
// This needs to be set after the 'config' prop has been set.
- thumbnailer = new MachineThumbnailer (this);
+ thumbnailer = new MachineThumbnailer (this,
+ SCREENSHOT_WIDTH, SCREENSHOT_HEIGHT,
+ CENTERED_EMBLEM_SIZE, EMBLEM_SIZE,
+ FRAME_BORDER_COLOR, FRAME_BACKGROUND_COLOR);
}
protected void load_screenshot () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]