2
// ClutterFlowBaseActor.cs
5
// Mathijs Dumon <mathijsken@hotmail.com>
7
// Copyright (c) 2010 Mathijs Dumon
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33
public interface IIndexable : IComparable<IIndexable>
36
event IndexChangedEventHandler IndexChanged;
39
public delegate void IndexChangedEventHandler (IIndexable item, int old_index, int new_index);
41
public abstract class ClutterFlowBaseActor : Clutter.Group, IIndexable
44
private CoverManager cover_manager;
45
public CoverManager CoverManager {
46
get { return cover_manager; }
47
set { cover_manager = value ; }
50
protected string cache_key = "";
51
public virtual string CacheKey {
52
get { return cache_key; }
55
protected string label = "";
56
public virtual string Label {
60
protected string sort_label = "";
61
public virtual string SortLabel {
62
get { return sort_label; }
63
set { sort_label = value; }
66
public virtual event IndexChangedEventHandler IndexChanged;
68
protected int index = -1; //-1 = not visible
69
public virtual int Index {
73
int old_index = index;
75
IsReactive = !(index < 0);
76
if (IndexChanged != null) {
77
IndexChanged (this, old_index, index);
83
public virtual int CompareTo (IIndexable obj) {
84
if (obj.Index == -1 && this.Index != -1) {
87
return obj.Index - this.Index;
91
public ClutterFlowBaseActor () : base ()
94
public ClutterFlowBaseActor (CoverManager cover_manager) : base ()
96
this.cover_manager = cover_manager;
97
this.cover_manager.Add (this);
100
private bool disposed = false;
101
public override void Dispose ()
108
cover_manager.Remove (this);
113
#region Texture Handling
114
public static void MakeReflection (Cairo.ImageSurface source, CairoTexture dest)
116
int w = source.Width + 4;
117
int h = source.Height * 2 + 4;
119
dest.SetSurfaceSize ((uint) w, (uint) h);
121
Cairo.Context context = dest.Create ();
123
MakeReflection (context, source, w, h);
125
//((IDisposable) context.Target).Dispose ();
126
((IDisposable) context).Dispose ();
129
public static Cairo.ImageSurface MakeReflection (Cairo.ImageSurface source)
131
int w = source.Width + 4;
132
int h = source.Height * 2 + 4;
134
Cairo.ImageSurface dest = new Cairo.ImageSurface(Cairo.Format.ARGB32, w, h);
135
Cairo.Context context = new Cairo.Context(dest);
137
MakeReflection (context, source, w, h);
139
//((IDisposable) context.Target).Dispose ();
140
((IDisposable) context).Dispose ();
145
private static void MakeReflection (Cairo.Context context, Cairo.ImageSurface source, int w, int h)
147
context.ResetClip ();
148
context.SetSourceSurface (source, 2, 2);
152
double step = 1.0 / (double) source.Height;
154
context.Translate (0, h);
155
context.Scale (1, -1);
156
context.SetSourceSurface (source, 2, 2);
157
for (int i = 0; i < source.Height; i++) {
158
context.Rectangle (0, i+2, w, 1);
161
context.PaintWithAlpha (Math.Max (Math.Min (alpha, 0.7), 0.0));
162
context.ResetClip ();