[gnome-boxes] Draw boxes in greyish style if not running
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Draw boxes in greyish style if not running
- Date: Wed, 19 Oct 2011 14:50:19 +0000 (UTC)
commit 0f566c896b4ab6b28fdbfe6134ab014ce1f4f3bd
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Wed Oct 19 16:49:45 2011 +0200
Draw boxes in greyish style if not running
data/icons/Makefile.am | 5 +++-
data/icons/boxes-grid.png | Bin 0 -> 202 bytes
src/machine.vala | 54 +++++++++++++++++++++++++++++++++++++-------
src/topbar.vala | 17 ++++++++-----
4 files changed, 59 insertions(+), 17 deletions(-)
---
diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am
index 64b0c89..d632e2f 100644
--- a/data/icons/Makefile.am
+++ b/data/icons/Makefile.am
@@ -18,7 +18,10 @@ noinst_DATA = \
$(NULL)
imagesdir = $(datadir)/gnome-boxes/pixmaps
-images_DATA = boxes-create.png
+images_DATA = \
+ boxes-create.png \
+ boxes-grid.png \
+ $(NULL)
EXTRA_DIST = \
$(images_DATA) \
diff --git a/data/icons/boxes-grid.png b/data/icons/boxes-grid.png
new file mode 100644
index 0000000..f8d0e13
Binary files /dev/null and b/data/icons/boxes-grid.png differ
diff --git a/src/machine.vala b/src/machine.vala
index 4f2cc32..4c74bfe 100644
--- a/src/machine.vala
+++ b/src/machine.vala
@@ -130,7 +130,7 @@ private class Boxes.Machine: Boxes.CollectionItem {
return get_pkgcache (uuid + "-screenshot." + ext);
}
- private async void update_screenshot () {
+ private async void update_screenshot (int width = 128, int height = 96) {
Gdk.Pixbuf? pixbuf = null;
try {
@@ -142,7 +142,9 @@ private class Boxes.Machine: Boxes.CollectionItem {
}
if (pixbuf == null)
- pixbuf = draw_fallback_vm (128, 96);
+ pixbuf = draw_fallback_vm (width, height);
+ else
+ pixbuf = draw_vm (pixbuf, width, height);
try {
machine_actor.set_screenshot (pixbuf);
@@ -151,6 +153,47 @@ private class Boxes.Machine: Boxes.CollectionItem {
}
}
+ private Gdk.Pixbuf draw_vm (Gdk.Pixbuf pixbuf, int width, int height) {
+ var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
+ var context = new Cairo.Context (surface);
+
+ var pw = (double)pixbuf.get_width ();
+ var ph = (double)pixbuf.get_height ();
+ var sw = width / pw;
+ var sh = height / ph;
+ var x = 0.0;
+ var y = 0.0;
+
+ if (pw > ph) {
+ y = (height - (ph * sw)) / 2;
+ sh = sw;
+ }
+
+ context.rectangle (x, y, width - x * 2, height - y * 2);
+ context.clip ();
+
+ context.scale (sw, sh);
+ Gdk.cairo_set_source_pixbuf (context, pixbuf, x / sw, y / sh);
+ context.get_source ().set_filter (Cairo.Filter.BEST); // FIXME: cairo scaling is crap
+ context.paint ();
+
+ if (state != DomainState.RUNNING) {
+ context.set_source_rgba (1, 1, 1, 1);
+ context.set_operator (Cairo.Operator.HSL_SATURATION);
+ context.paint ();
+
+ context.identity_matrix ();
+ context.scale (0.1875, 0.1875);
+ var grid = new Cairo.Pattern.for_surface (new Cairo.ImageSurface.from_png (get_pixmap ("boxes-grid.png")));
+ grid.set_extend (Cairo.Extend.REPEAT);
+ context.set_source_rgba (1, 1, 1, 1);
+ context.set_operator (Cairo.Operator.OVER);
+ context.mask (grid);
+ }
+
+ return Gdk.pixbuf_get_from_surface (surface, 0, 0, width, height);
+ }
+
private static Gdk.Pixbuf draw_fallback_vm (int width, int height) {
Gdk.Pixbuf pixbuf = null;
@@ -158,13 +201,6 @@ private class Boxes.Machine: Boxes.CollectionItem {
var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
var context = new Cairo.Context (surface);
- // make it take color from theme
- // var pattern = new Cairo.Pattern.linear (0, 0, 0, height);
- // pattern.add_color_stop_rgb (0, 0.260, 0.260, 0.260);
- // pattern.add_color_stop_rgb (1, 0.220, 0.220, 0.220);
- // context.set_source (pattern);
- // context.paint ();
-
int size = (int) (height * 0.5);
var icon_info = IconTheme.get_default ().lookup_icon ("computer-symbolic", size,
IconLookupFlags.GENERIC_FALLBACK);
diff --git a/src/topbar.vala b/src/topbar.vala
index e1bd33b..327170e 100644
--- a/src/topbar.vala
+++ b/src/topbar.vala
@@ -19,7 +19,8 @@ private class Boxes.Topbar: Boxes.UI {
public Notebook notebook;
private Toolbar toolbar_start;
- private ToolButton spinner;
+ private Toolbar toolbar_end;
+ private Gtk.Spinner spinner;
public Topbar (App app) {
this.app = app;
@@ -65,13 +66,15 @@ private class Boxes.Topbar: Boxes.UI {
label.set_halign (Gtk.Align.START);
hbox.pack_start (label, true, true, 0);
- var toolbar_end = new Gtk.Toolbar ();
+ toolbar_end = new Gtk.Toolbar ();
toolbar_end.icon_size = Gtk.IconSize.MENU;
toolbar_end.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUBAR);
- spinner = new Gtk.ToolButton (new Gtk.Spinner (), null);
- spinner.get_style_context ().add_class ("raised");
- toolbar_end.insert (spinner, 0);
+ spinner = new Gtk.Spinner ();
+ spinner.start ();
+ var btn = new Gtk.ToolButton (spinner, null);
+ btn.get_style_context ().add_class ("raised");
+ toolbar_end.insert (btn, 0);
toolbar_end.set_show_arrow (false);
hbox.pack_start (toolbar_end, false, false, 0);
@@ -93,11 +96,11 @@ private class Boxes.Topbar: Boxes.UI {
case UIState.COLLECTION:
notebook.page = TopbarPage.COLLECTION;
toolbar_start.hide ();
- spinner.hide ();
+ toolbar_end.hide ();
break;
case UIState.CREDS:
toolbar_start.show ();
- spinner.show ();
+ toolbar_end.show ();
break;
case UIState.DISPLAY:
actor_pin (gtk_actor);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]