[mistelix] Use no preview images when browsing imaages and videos too
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Subject: [mistelix] Use no preview images when browsing imaages and videos too
- Date: Tue, 7 Jul 2009 19:52:58 +0000 (UTC)
commit 1c41029ad895a3890c773a9a6b4df7c2071ec05b
Author: Jordi Mas <jmas softcatala org>
Date: Tue Jul 7 20:52:37 2009 +0100
Use no preview images when browsing imaages and videos too
src/widgets/DataImageSurface.cs | 26 ++++++++++++++++----------
src/widgets/FileView.cs | 22 +++++++++++++++++-----
src/widgets/GtkUtils.cs | 29 +++++++++++++++++++++++++++++
src/widgets/SlideShowImageView.cs | 26 +-------------------------
4 files changed, 63 insertions(+), 40 deletions(-)
---
diff --git a/src/widgets/DataImageSurface.cs b/src/widgets/DataImageSurface.cs
index 3d6cecc..54499cd 100644
--- a/src/widgets/DataImageSurface.cs
+++ b/src/widgets/DataImageSurface.cs
@@ -35,7 +35,7 @@ namespace Mistelix.Widgets
static int user_data_key = 0;
static cairo_destroy_func_t destroy_func;
protected IntPtr data;
- protected bool is_le = BitConverter.IsLittleEndian;
+ static protected bool is_le = BitConverter.IsLittleEndian;
static void DestroyPixelData (IntPtr data)
{
@@ -60,20 +60,19 @@ namespace Mistelix.Widgets
SetDestroyFunc ();
}
- // Converts from Cairo 32-bits to GTK 24 bits (3 channels)
public byte[] Get24bitsPixBuf ()
{
+ return FromCairo32ToPixBuf (Data, Width, Height, 3);
+ }
+
+ // Converts a pixel data array from Cairo 32-bits to GDK 24/32 bits
+ static public byte[] FromCairo32ToPixBuf (byte[] cairo_pixels, int width, int height, int channels)
+ {
int pos_cairo = 0;
int pos_gdk = 0;
- byte [] cairo_pixels;
byte [] pixels;
- int width, height;
- const int channels = 3;
- width = Width;
- height = Height;
- pixels = new byte [height * Width * channels];
- cairo_pixels = Data;
+ pixels = new byte [height * width * channels];
for (int h = 0; h < height; h++)
{
@@ -83,10 +82,18 @@ namespace Mistelix.Widgets
pixels[pos_gdk + 2] = cairo_pixels[pos_cairo + 0];
pixels[pos_gdk + 1] = cairo_pixels[pos_cairo + 1];
pixels[pos_gdk + 0] = cairo_pixels[pos_cairo + 2];
+
+ if (channels == 4)
+ pixels[pos_gdk + 3] = cairo_pixels[pos_cairo + 3];
+
+
} else {
pixels[pos_gdk + 0] = cairo_pixels[pos_cairo + 1];
pixels[pos_gdk + 1] = cairo_pixels[pos_cairo + 2];
pixels[pos_gdk + 2] = cairo_pixels[pos_cairo + 3];
+
+ if (channels == 4)
+ pixels[pos_gdk + 3] = cairo_pixels[pos_cairo + 0];
}
pos_gdk += channels;
@@ -96,7 +103,6 @@ namespace Mistelix.Widgets
return pixels;
}
-
[DllImport ("libcairo.so.2")]
static extern Cairo.Status cairo_surface_set_user_data (IntPtr surface, ref int key, IntPtr userdata, cairo_destroy_func_t destroy);
diff --git a/src/widgets/FileView.cs b/src/widgets/FileView.cs
index aa67345..4447e02 100644
--- a/src/widgets/FileView.cs
+++ b/src/widgets/FileView.cs
@@ -1,5 +1,5 @@
//
-// Copyright (C) 2008 Jordi Mas i Hernandez, jmas softcatala org
+// Copyright (C) 2008-2009 Jordi Mas i Hernandez, jmas softcatala org
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -60,7 +60,6 @@ namespace Mistelix.Widgets
protected FileView ()
{
store = CreateStore ();
- LoadElements ();
SelectionMode = SelectionMode.Multiple;
TextColumn = COL_DISPLAY_NAME;
@@ -69,7 +68,8 @@ namespace Mistelix.Widgets
thumbnail_height = ThumbnailSizeManager.Current.Height;
thumbnail_width = ThumbnailSizeManager.Current.Width;
- def_image = Gtk.IconTheme.Default.LoadIcon ("gtk-new", thumbnail_width, (Gtk.IconLookupFlags) 0);
+ CreateDefaultImage ();
+ LoadElements ();
Model = store;
}
@@ -88,7 +88,7 @@ namespace Mistelix.Widgets
for (int i = 0; i < items.Length; i++)
{
store.GetIter (out iter, items [i]);
- files.Add ((string) store.GetValue (iter, 0));
+ files.Add ((string) store.GetValue (iter, COL_PATH));
}
return files;
}
@@ -112,7 +112,7 @@ namespace Mistelix.Widgets
Logger.Debug ("Fileview.Disposing");
store.Foreach (delegate (TreeModel model, TreePath path, TreeIter iter)
{
- Gdk.Pixbuf im = (Gdk.Pixbuf) store.GetValue (iter, 2);
+ Gdk.Pixbuf im = (Gdk.Pixbuf) store.GetValue (iter, COL_PIXBUF);
im.Dispose ();
return false;
@@ -151,5 +151,17 @@ namespace Mistelix.Widgets
thumbnailing.RunWorkerAsync (store);
}
+
+ void CreateDefaultImage ()
+ {
+ const int channels = 4;
+ Cairo.ImageSurface image;
+
+ image = GtkUtils.CreateNoPreviewImage (thumbnail_width, thumbnail_height);
+ byte[] data = DataImageSurface.FromCairo32ToPixBuf (image.Data, thumbnail_width, thumbnail_height, channels);
+ def_image = new Pixbuf (data, true, 8, thumbnail_width, thumbnail_height, thumbnail_width * channels, null);
+ image.Destroy ();
+ }
+
}
}
diff --git a/src/widgets/GtkUtils.cs b/src/widgets/GtkUtils.cs
index 1593ae2..c4397de 100644
--- a/src/widgets/GtkUtils.cs
+++ b/src/widgets/GtkUtils.cs
@@ -23,10 +23,13 @@
using System;
using Gtk;
+using Cairo;
+using Mono.Posix;
namespace Mistelix.Widgets
{
// General GTK toolbox class
+ // TODO: Rename it to WidgetsUtils
public static class GtkUtils
{
static public void DrawSelectionBox (Cairo.Context cr, double x, double y, double width, double height)
@@ -66,5 +69,31 @@ namespace Mistelix.Widgets
return new Gdk.Color ((byte)r, (byte)g, (byte)b);
}
+
+ // Create the image indicating that there is no preview available yet
+ public static Cairo.ImageSurface CreateNoPreviewImage (int width, int height)
+ {
+ const int min_xpad = 10;
+ Cairo.Context cr;
+ int box_width, box_height;
+ Cairo.ImageSurface image;
+
+ image = new Cairo.ImageSurface (Cairo.Format.Argb32, width, height);
+ cr = new Cairo.Context (image);
+
+ using (Pango.Layout layout = Pango.CairoHelper.CreateLayout (cr))
+ {
+ layout.FontDescription = Pango.FontDescription.FromString ("sans 8");
+ layout.SetMarkup (Catalog.GetString ("No preview available"));
+ layout.Alignment = Pango.Alignment.Center;
+ layout.SingleParagraphMode = false;
+ layout.Width = (int) ((width - min_xpad * 2) * Pango.Scale.PangoScale);
+ layout.GetPixelSize (out box_width, out box_height);
+ cr.MoveTo (min_xpad, (height - box_height) / 2);
+ Pango.CairoHelper.ShowLayout (cr, layout);
+ }
+ ((IDisposable)cr).Dispose ();
+ return image;
+ }
}
}
diff --git a/src/widgets/SlideShowImageView.cs b/src/widgets/SlideShowImageView.cs
index 63c4f47..893688b 100644
--- a/src/widgets/SlideShowImageView.cs
+++ b/src/widgets/SlideShowImageView.cs
@@ -111,7 +111,7 @@ namespace Mistelix.Widgets
ButtonPressEvent += new ButtonPressEventHandler (OnButtonPressed);
KeyPressEvent += OnKeyPressed;
- CreateDefaultImage ();
+ def_image = GtkUtils.CreateNoPreviewImage (thumbnail_width, thumbnail_height);
}
~SlideShowImageView ()
@@ -622,30 +622,6 @@ namespace Mistelix.Widgets
}
}
- // Create the image indicating that there is no preview available yet
- void CreateDefaultImage ()
- {
- const int min_xpad = 10;
- Cairo.Context cr;
- int box_width, box_height;
-
- def_image = new Cairo.ImageSurface (Format.Argb32, thumbnail_width, thumbnail_height);
- cr = new Cairo.Context (def_image);
-
- using (Pango.Layout layout = Pango.CairoHelper.CreateLayout (cr))
- {
- layout.FontDescription = Pango.FontDescription.FromString ("sans 8");
- layout.SetMarkup (Catalog.GetString ("No preview available"));
- layout.Alignment = Pango.Alignment.Center;
- layout.SingleParagraphMode = false;
- layout.Width = (int) ((thumbnail_width - min_xpad * 2) * Pango.Scale.PangoScale);
- layout.GetPixelSize (out box_width, out box_height);
- cr.MoveTo (min_xpad, (thumbnail_height - box_height) / 2);
- Pango.CairoHelper.ShowLayout (cr, layout);
- }
- ((IDisposable)cr).Dispose ();
- }
-
void OnEffect (object sender, Effect.EffectEventArgs e)
{
TreeIter iter;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]