~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do.Interface.Windows.AnimationBase/src/Do.Interface/Do.Interface.AnimationBase/BezelGlassRenderClasses.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 04:22:47 UTC
  • Revision ID: ootz0rz@gmail.com-20090623042247-ciyax78ykbtlx4ee
added Do.Interface.Windows.AnimationBase and Do.Interface.Windows.Classic

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// BezelGlassRenderClasses.cs
 
2
// 
 
3
// Copyright (C) 2008 GNOME Do
 
4
//
 
5
// This program is free software: you can redistribute it and/or modify
 
6
// it under the terms of the GNU General Public License as published by
 
7
// the Free Software Foundation, either version 3 of the License, or
 
8
// (at your option) any later version.
 
9
//
 
10
// This program is distributed in the hope that it will be useful,
 
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
// GNU General Public License for more details.
 
14
//
 
15
// You should have received a copy of the GNU General Public License
 
16
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
 
 
22
using Gdk;
 
23
using Gtk;
 
24
using Cairo;
 
25
 
 
26
using Do.Interface;
 
27
using Do.Interface.CairoUtils;
 
28
using Do.Universe;
 
29
using Do.Platform;
 
30
 
 
31
namespace Do.Interface.AnimationBase
 
32
{
 
33
        
 
34
        public interface IBezelResultItemRenderer
 
35
        {
 
36
                int Height { get; }
 
37
                void RenderItem (Context cr, Gdk.Point renderAnchor, int width, Do.Universe.Item item, bool drawArrow);
 
38
        }
 
39
        
 
40
        public class BezelFullResultItemRenderer : IBezelResultItemRenderer
 
41
        {
 
42
                BezelGlassResults parent;
 
43
                
 
44
                public int Height { get { return 36; } }
 
45
                
 
46
                public int IconSize { get { return 32; } }
 
47
 
 
48
                public BezelFullResultItemRenderer (BezelGlassResults parent)
 
49
                {
 
50
                        this.parent = parent;
 
51
                }
 
52
                
 
53
                public void RenderItem (Context cr, Gdk.Point renderAnchor, int width, Do.Universe.Item item, bool drawArrow)
 
54
                {
 
55
                        cr.Rectangle (renderAnchor.X, renderAnchor.Y, width, Height);
 
56
                        cr.Color = new Cairo.Color (0, 0, 0, 0);
 
57
                        cr.Operator = Operator.Source;
 
58
                        cr.Fill ();
 
59
                        cr.Operator = Operator.Over;
 
60
                        
 
61
                        Gdk.Pixbuf pixbuf = IconProvider.PixbufFromIconName (item.Icon, IconSize);
 
62
                        Gdk.CairoHelper.SetSourcePixbuf (cr, pixbuf, 2, 2);
 
63
                        cr.Paint ();
 
64
                        
 
65
                        pixbuf.Dispose ();
 
66
                        
 
67
                        foreach (int i in parent.Secondary) {
 
68
                                if (parent.Results[i] == item) {
 
69
                                        pixbuf = IconProvider.PixbufFromIconName ("gtk-add", IconSize);
 
70
                                        Gdk.CairoHelper.SetSourcePixbuf (cr, pixbuf, 2, 2);
 
71
                                        cr.PaintWithAlpha (.7);
 
72
                                        pixbuf.Dispose ();
 
73
                                }
 
74
                        }
 
75
                                
 
76
                        Pango.Layout layout = new Pango.Layout (parent.PangoContext);
 
77
                        layout.Width = Pango.Units.FromPixels (width - IconSize - 25);
 
78
                        layout.Ellipsize = Pango.EllipsizeMode.End;
 
79
                        layout.SetMarkup ("<span foreground=\"#" + parent.ItemTextColor + "\">"+GLib.Markup.EscapeText (item.Name)+"</span>");
 
80
                        layout.FontDescription = Pango.FontDescription.FromString ("normal bold");
 
81
                        layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (10);
 
82
                                
 
83
                        cr.MoveTo (IconSize + 6, 4);
 
84
                        Pango.CairoHelper.ShowLayout (cr, layout);
 
85
                        
 
86
                        layout.SetMarkup ("<span foreground=\"#" + parent.ItemTextColor + "\">"+GLib.Markup.EscapeText (item.Description)+"</span>");
 
87
                        layout.FontDescription.Dispose ();
 
88
                        layout.FontDescription = Pango.FontDescription.FromString ("normal");
 
89
                        layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (10);
 
90
                        cr.MoveTo (IconSize + 8, 19);
 
91
                        Pango.CairoHelper.ShowLayout (cr, layout);
 
92
                        
 
93
                        if (drawArrow) {
 
94
                                cr.MoveTo (width - 15, 13);
 
95
                                cr.LineTo (width - 15+7, 17);
 
96
                                cr.LineTo (width - 15, 21);
 
97
                                Gdk.Color gc = new Gdk.Color ();
 
98
                                Gdk.Color.Parse ("#" + parent.ItemTextColor, ref gc);
 
99
                                cr.Color = gc.ConvertToCairo (1);
 
100
                                cr.Fill ();
 
101
                        }
 
102
                        
 
103
                        
 
104
                        layout.FontDescription.Dispose ();
 
105
                        layout.Dispose ();
 
106
                        (cr as IDisposable).Dispose ();
 
107
                }
 
108
        }
 
109
        
 
110
        public class BezelHalfResultItemRenderer : IBezelResultItemRenderer
 
111
        {
 
112
                BezelGlassResults parent;
 
113
                
 
114
                public int Height { get { return 20; } }
 
115
                
 
116
                public int IconSize { get { return 16; } }
 
117
 
 
118
                public BezelHalfResultItemRenderer (BezelGlassResults parent)
 
119
                {
 
120
                        this.parent = parent;
 
121
                }
 
122
                
 
123
                public void RenderItem (Context cr, Gdk.Point renderAnchor, int width, Do.Universe.Item item, bool drawArrow)
 
124
                {
 
125
                        cr.Rectangle (renderAnchor.X, renderAnchor.Y, width, Height);
 
126
                        cr.Color = new Cairo.Color (0, 0, 0, 0);
 
127
                        cr.Operator = Operator.Source;
 
128
                        cr.Fill ();
 
129
                        cr.Operator = Operator.Over;
 
130
                        
 
131
                        Gdk.Pixbuf pixbuf = IconProvider.PixbufFromIconName (item.Icon, IconSize);
 
132
                        Gdk.CairoHelper.SetSourcePixbuf (cr, pixbuf, 2, 2);
 
133
                        cr.Paint ();
 
134
                        
 
135
                        pixbuf.Dispose ();
 
136
                        
 
137
                        foreach (int i in parent.Secondary) {
 
138
                                if (parent.Results[i] == item) {
 
139
                                        pixbuf = IconProvider.PixbufFromIconName ("gtk-add", IconSize);
 
140
                                        Gdk.CairoHelper.SetSourcePixbuf (cr, pixbuf, 2, 2);
 
141
                                        cr.PaintWithAlpha (.7);
 
142
                                        pixbuf.Dispose ();
 
143
                                }
 
144
                        }
 
145
                                
 
146
                        Pango.Layout layout = new Pango.Layout (parent.PangoContext);
 
147
                        layout.Width = Pango.Units.FromPixels (width - IconSize - 25);
 
148
                        layout.Ellipsize = Pango.EllipsizeMode.End;
 
149
                        layout.SetMarkup ("<span foreground=\"#" + parent.ItemTextColor + "\">"+GLib.Markup.EscapeText (item.Name)+"</span>");
 
150
                        layout.FontDescription = Pango.FontDescription.FromString ("normal bold");
 
151
                        layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels (10);
 
152
                                
 
153
                        cr.MoveTo (IconSize + 6, 4);
 
154
                        Pango.CairoHelper.ShowLayout (cr, layout);
 
155
                        
 
156
                        if (drawArrow) {
 
157
                                cr.MoveTo (width - IconSize+6, 5);
 
158
                                cr.LineTo (width - IconSize+10, 10);
 
159
                                cr.LineTo (width - IconSize+6, 15);
 
160
                                
 
161
                                cr.MoveTo (width - IconSize+2, 5);
 
162
                                cr.LineTo (width - IconSize+6, 10);
 
163
                                cr.LineTo (width - IconSize+2, 15);
 
164
                                Gdk.Color gc = new Gdk.Color ();
 
165
                                Gdk.Color.Parse ("#" + parent.ItemTextColor, ref gc);
 
166
                                cr.Color = gc.ConvertToCairo (1);
 
167
                                cr.Stroke ();
 
168
                        }
 
169
                        
 
170
                        layout.FontDescription.Dispose ();
 
171
                        layout.Dispose ();
 
172
                        (cr as IDisposable).Dispose ();
 
173
                }
 
174
        }
 
175
}