~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do.Interface.Windows/src/Do.Interface/Do.Interface.Widgets/TextFrame.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 03:53:12 UTC
  • Revision ID: ootz0rz@gmail.com-20090623035312-it8tb5wkha6nf31p
Added Do.Interface.Windows, and a bunch of cleanup with old MonoDevelop files elsewhere

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// TextFrame.cs
 
2
//
 
3
//  Copyright (C) 2008 Jason Smith
 
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 2 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, write to the Free Software
 
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
//
 
19
//
 
20
 
 
21
using System;
 
22
using Gtk;
 
23
using Gdk;
 
24
 
 
25
namespace Do.Interface.Widgets
 
26
{
 
27
        
 
28
        
 
29
        public class TextFrame : Frame
 
30
        {
 
31
                protected Label label;
 
32
                protected string labelText;
 
33
                protected bool isFocused;
 
34
                
 
35
                protected float focused_fill_transparency = 0.4f;
 
36
                protected float unfocused_fill_transparency = 0.1f;
 
37
                protected float focused_frame_transparency = 0.3f;
 
38
                protected float unfocused_frame_transparency = 0.075f;
 
39
                
 
40
                public string LabelText
 
41
                {
 
42
                        get { return labelText; }
 
43
                        set { 
 
44
                                labelText = value;
 
45
                                label.Markup = string.Format("<b>{0}</b>", value);
 
46
                        }
 
47
                }
 
48
                
 
49
                public TextFrame ()
 
50
                {
 
51
                        Build ();
 
52
                        this.LabelText = "";
 
53
                        drawGradient = true;
 
54
                }
 
55
                
 
56
                protected virtual void Build ()
 
57
                {
 
58
                        label = new Label ();
 
59
                        label.Ellipsize = Pango.EllipsizeMode.End;
 
60
                        label.ModifyFg (StateType.Normal, Style.White);
 
61
                        
 
62
                        Add (label);
 
63
                        label.Show ();
 
64
                }
 
65
                
 
66
                public bool IsFocused
 
67
                {
 
68
                        get { return isFocused; }
 
69
                        set {
 
70
                                isFocused = value;
 
71
                                UpdateFocus ();
 
72
                        }
 
73
                }
 
74
                
 
75
                protected override Cairo.LinearGradient GetGradient ()
 
76
                {
 
77
                        double r, g, b;
 
78
                        
 
79
                        r = (double) frameColor.Red / ushort.MaxValue;
 
80
                        g = (double) frameColor.Green / ushort.MaxValue;
 
81
                        b = (double) frameColor.Blue / ushort.MaxValue;
 
82
                        
 
83
                        Cairo.LinearGradient grad = new Cairo.LinearGradient (0, 0, x+width, 0);
 
84
                        grad.AddColorStop (.1,  new Cairo.Color (r, g, b, 0));
 
85
                        grad.AddColorStop (.35, new Cairo.Color (r, g, b, fillAlpha));
 
86
                        grad.AddColorStop (.65, new Cairo.Color (r, g, b, fillAlpha));
 
87
                        grad.AddColorStop (.9,  new Cairo.Color (r, g, b, 0));
 
88
                        
 
89
                        return grad;
 
90
                }
 
91
 
 
92
                
 
93
                protected virtual void UpdateFocus ()
 
94
                {
 
95
                        FillAlpha = (IsFocused ? focused_fill_transparency : unfocused_fill_transparency);
 
96
                        FrameAlpha = (IsFocused ? focused_frame_transparency : unfocused_frame_transparency);
 
97
                }
 
98
        }
 
99
}