[mistelix] Some refactoring. Separate the CairoImageCellRenderer class
- From: Jordi Mas <jmas src gnome org>
- To: svn-commits-list gnome org
- Subject: [mistelix] Some refactoring. Separate the CairoImageCellRenderer class
- Date: Thu, 2 Jul 2009 08:30:10 +0000 (UTC)
commit 821ddc9f6665ed9efd2f01b162029e8fd75a61e2
Author: Jordi Mas <jmas softcatala org>
Date: Thu Jul 2 10:29:53 2009 +0200
Some refactoring. Separate the CairoImageCellRenderer class
src/Makefile.am | 3 +-
src/widgets/CairoImageCellRenderer.cs | 91 +++++++++++++++++++++++++++++++++
src/widgets/SlideShowImageView.cs | 59 ++-------------------
3 files changed, 99 insertions(+), 54 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index f1004c5..5cb895c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,7 +69,8 @@ MISTELIX_CSDISTFILES = \
$(srcdir)/core/EffectManager.cs \
$(srcdir)/widgets/DataImageSurface.cs \
$(srcdir)/core/ResolutionManager.cs \
- $(srcdir)/dialogs/AudioSelectionDialog.cs
+ $(srcdir)/dialogs/AudioSelectionDialog.cs \
+ $(srcdir)/widgets/CairoImageCellRenderer.cs
ASSEMBLIES = \
$(MISTELIX_LIBS) \
diff --git a/src/widgets/CairoImageCellRenderer.cs b/src/widgets/CairoImageCellRenderer.cs
new file mode 100644
index 0000000..0f73b5e
--- /dev/null
+++ b/src/widgets/CairoImageCellRenderer.cs
@@ -0,0 +1,91 @@
+//
+// 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
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using Gtk;
+using Cairo;
+
+namespace Mistelix.Widgets
+{
+ public class RequestThumbnailEventArgs: EventArgs
+ {
+ Gtk.TreeIter iter;
+
+ public RequestThumbnailEventArgs (Gtk.TreeIter iter)
+ {
+ this.iter = iter;
+ }
+
+ public Gtk.TreeIter Iter {
+ get { return iter; }
+ }
+ }
+
+ public delegate void RequestThumbnailEventHandler (object sender, RequestThumbnailEventArgs e);
+
+ // Renders a Cairo Image into a tree Cell
+ public class CairoImageCellRenderer : CellRenderer
+ {
+ int width, height;
+ Cairo.ImageSurface surface, default_surface;
+ Gtk.TreeIter iter;
+ RequestThumbnailEventHandler request_thumbnail;
+
+ public CairoImageCellRenderer (int width, int height, Cairo.ImageSurface default_surface, RequestThumbnailEventHandler request_thumbnail)
+ {
+ this.width = width;
+ this.height = height;
+ this.default_surface = default_surface;
+ this.request_thumbnail = request_thumbnail;
+ }
+
+ public Gtk.TreeIter Iter {
+ get { return iter; }
+ set { iter = value; }
+ }
+
+ public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int w, out int h)
+ {
+ x_offset = 0;
+ y_offset = 0;
+ w = width + ((int) Xpad) * 2;
+ h = height + ((int) Ypad) * 2;
+ }
+
+ protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background, Gdk.Rectangle cell, Gdk.Rectangle expose, CellRendererState flags)
+ {
+ Cairo.Context cr = Gdk.CairoHelper.Create (window);
+ TreeView parent = (TreeView) widget;
+
+ surface = (DataImageSurface) parent.Model.GetValue (iter, SlideShowImageView.COL_CAIROIMAGE);
+
+ if (surface == null)
+ request_thumbnail (this, new RequestThumbnailEventArgs (iter));
+
+ cr.Rectangle (cell.X, cell.Y, cell.Width, cell.Height);
+ cr.SetSourceSurface (surface != null ? surface : default_surface, cell.X, cell.Y);
+ cr.Paint ();
+ (cr as System.IDisposable).Dispose ();
+ }
+ }
+}
diff --git a/src/widgets/SlideShowImageView.cs b/src/widgets/SlideShowImageView.cs
index ad788e5..63c4f47 100644
--- a/src/widgets/SlideShowImageView.cs
+++ b/src/widgets/SlideShowImageView.cs
@@ -24,9 +24,7 @@
using System;
using Gtk;
using System.IO;
-using System.Text;
using System.Collections.Generic;
-using System.Collections;
using System.ComponentModel;
using Gdk;
using Cairo;
@@ -53,52 +51,6 @@ namespace Mistelix.Widgets
public delegate void ShowImageUpdatedElementsEventHandler (object sender, EventArgs e);
- // Renders a Cairo Image into a tree Cell
- public class CellRendererCairoImage : CellRenderer
- {
- int width, height;
- Cairo.ImageSurface surface, default_surface;
- Gtk.TreeIter iter;
- SlideShowImageView parent;
-
- public CellRendererCairoImage (int width, int height, Cairo.ImageSurface default_surface, SlideShowImageView parent)
- {
- this.width = width;
- this.height = height;
- this.default_surface = default_surface;
- this.parent = parent;
- }
-
- public Gtk.TreeIter Iter {
- get { return iter; }
- set { iter = value; }
- }
-
- public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area, out int x_offset, out int y_offset, out int w, out int h)
- {
- x_offset = 0;
- y_offset = 0;
- w = width + ((int) Xpad) * 2;
- h = height + ((int) Ypad) * 2;
- }
-
- protected override void Render (Gdk.Drawable window, Widget widget, Gdk.Rectangle background, Gdk.Rectangle cell, Gdk.Rectangle expose, CellRendererState flags)
- {
- Cairo.Context cr = Gdk.CairoHelper.Create (window);
-
- surface = (DataImageSurface) parent.ListStore.GetValue (iter, SlideShowImageView.COL_CAIROIMAGE);
-
- if (surface == null) {
- parent.RequestThumbnail (iter);
- }
-
- cr.Rectangle (cell.X, cell.Y, cell.Width, cell.Height);
- cr.SetSourceSurface (surface != null ? surface : default_surface, cell.X, cell.Y);
- cr.Paint ();
- (cr as System.IDisposable).Dispose ();
- }
- }
-
//
// Displays the images selected by the user when creating a slideshow. Drop target.
//
@@ -222,7 +174,8 @@ namespace Mistelix.Widgets
AppendColumn (Catalog.GetString ("#"), new CellRendererText (), "text", COL_INDEX);
AppendColumn (Catalog.GetString ("Image"),
- new CellRendererCairoImage (thumbnail_width, thumbnail_height, def_image, this),
+ new CairoImageCellRenderer (thumbnail_width, thumbnail_height, def_image,
+ RequestThumbnail),
new TreeCellDataFunc (SetTreeIter));
AppendColumn (Catalog.GetString ("Description"), title_cell, "text", COL_DESCRIPTION);
@@ -249,16 +202,16 @@ namespace Mistelix.Widgets
}
}
- // Sets the Iter element to paint into the CellRendererCairoImage (shared by all cells)
+ // Sets the Iter element to paint into the CairoImageCellRenderer (shared by all cells)
void SetTreeIter (Gtk.TreeViewColumn tree_column, Gtk.CellRenderer c, Gtk.TreeModel tree_model, Gtk.TreeIter iter)
{
- ((CellRendererCairoImage)c).Iter = iter;
+ ((CairoImageCellRenderer)c).Iter = iter;
}
- public void RequestThumbnail (Gtk.TreeIter iter)
+ void RequestThumbnail (object sender, RequestThumbnailEventArgs args)
{
lock (iters_list) {
- iters_list.Add (iter);
+ iters_list.Add (args.Iter);
}
if (thumbnailing.IsBusy == false)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]