~noskcaj/ubuntu/vivid/banshee-community-extensions/merge

« back to all changes in this revision

Viewing changes to src/ClutterFlow/ClutterFlow/AlphabetBar.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2011-06-26 13:31:44 UTC
  • mfrom: (4.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110626133144-62h4ohgg03p5y9nl
Tags: 2.1.1-2ubuntu1
* [c0b3875] Merge from Debian Unstable, remaining changes:
  + Enable LIRC and AppIndicator extensions

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
namespace ClutterFlow.Alphabet
8
8
{
9
9
 
10
 
        public class AlphabetEventArgs : EventArgs
11
 
        {
12
 
                protected AlphabetChars letter = AlphabetChars.unknown;
13
 
                public AlphabetChars Letter {
14
 
                        get { return letter; }
15
 
                }
16
 
                
17
 
                public AlphabetEventArgs (AlphabetChars letter) : base ()
18
 
                {
19
 
                        this.letter = letter;
20
 
                }
21
 
        }
22
 
        
23
 
        
24
 
        public class AlphabetBar : Clutter.Group
25
 
        {
26
 
 
27
 
                #region Events
28
 
                public event EventHandler<AlphabetEventArgs> LetterClicked;
29
 
                protected void InvokeLetterClicked (AlphabetChars letter)
30
 
                {
31
 
                        if (LetterClicked!=null) LetterClicked (this, new AlphabetEventArgs (letter));
32
 
                }
33
 
                #endregion
34
 
                
35
 
                #region Fields
36
 
                protected CairoTexture background;
37
 
                
38
 
                protected Dictionary<AlphabetChars, AlphabetButton> buttons = new Dictionary<AlphabetChars, AlphabetButton>(Enum.GetValues(typeof(AlphabetChars)).Length);
39
 
                public AlphabetButton this [AlphabetChars index] {
40
 
                        get { return buttons[index]; }
41
 
                }
42
 
                
43
 
                protected double Margin {
44
 
                        get { return Width * 0.075; }
45
 
                }
46
 
                
47
 
                #endregion Fields
48
 
                
49
 
                #region Initialisation
50
 
                public AlphabetBar (uint width, uint height)
51
 
                {
52
 
                        this.SetSize (width, height);
53
 
                        
54
 
                        InitBackground ();
55
 
                        InitButtons ();
56
 
                        
57
 
                        ShowAll ();
58
 
                }
59
 
                
60
 
                protected virtual void InitBackground ()
61
 
                {
62
 
                        background = new CairoTexture ((uint) Width,(uint) Height);
63
 
                        Add (background);
64
 
                        
65
 
                        SetupBackground ();
66
 
                        background.Show ();
67
 
                }
68
 
                
69
 
                protected virtual void SetupBackground ()
70
 
                {
71
 
                        background.Clear();
72
 
                        Cairo.Context context = background.Create();
73
 
                        
74
 
                        double lwidth = 1;
75
 
                        double hlwidth = lwidth*0.5;
76
 
                        
77
 
                        double margin = Margin;
78
 
                        
79
 
                        //left curvature:
80
 
                        context.MoveTo (-hlwidth, -hlwidth);
81
 
                        context.CurveTo (margin*0.33, -hlwidth,
82
 
                                         margin*0.5, Height*0.4,
83
 
                                         margin*0.5, Height*0.5);
84
 
                        context.CurveTo (margin*0.5, Height*0.6,
85
 
                                         margin*0.66, Height-hlwidth,
86
 
                                         margin-hlwidth, Height-hlwidth);
87
 
                        
88
 
                        
89
 
                        //straight bottom:
90
 
                        context.LineTo (Width-margin-hlwidth, Height-hlwidth);
91
 
                        
92
 
                        //right curvature:
93
 
                        context.CurveTo (Width-margin*0.66, Height - hlwidth,
94
 
                                         Width-margin*0.5, Height*0.6,
95
 
                                         Width-margin*0.5, Height*0.5);
96
 
                        context.CurveTo (Width-margin*0.5, Height*0.4,
97
 
                                         Width-margin*0.33, -hlwidth,
98
 
                                         Width-hlwidth, -hlwidth);
99
 
                        
100
 
                        //straight top:
101
 
                        context.LineTo (-hlwidth, -hlwidth);
102
 
                        context.ClosePath ();
103
 
                        
104
 
                        context.LineWidth = lwidth;
105
 
                        context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0);
106
 
                        context.StrokePreserve ();
107
 
                        context.SetSourceRGBA (1.0, 1.0, 1.0, 0.10);
108
 
                        context.Fill ();
109
 
                        
110
 
                        ((IDisposable) context.Target).Dispose();
111
 
                        ((IDisposable) context).Dispose();
112
 
                }
113
 
                
114
 
                protected virtual void InitButtons ()
115
 
                {
116
 
                        Array values = Enum.GetValues(typeof(AlphabetChars));
117
 
                        
118
 
                        int x_step = (int) ((Width * 0.950) / values.Length);
119
 
                        uint b_width = (uint) x_step;
120
 
                        uint b_height = (uint) (Height - 2);
121
 
                        
122
 
                        int x = (int) (Margin*0.5f + x_step);
123
 
                        int y = (int) (Height * 0.5)+2;
124
 
                        
125
 
                        foreach (AlphabetChars key in values) {
126
 
                                buttons[key] = new AlphabetButton (b_width, b_height, key);
127
 
                                buttons[key].ButtonReleaseEvent += HandleButtonReleaseEvent;
128
 
                                Add (buttons[key]);
129
 
                                buttons[key].SetAnchorPoint ((float) buttons[key].Width*0.5f, (float) buttons[key].Height*0.5f);
130
 
                                buttons[key].SetPosition (x, y);
131
 
                                x += x_step;
132
 
                        }
133
 
                }
134
 
                #endregion
135
 
                
136
 
                #region Event Handling
137
 
                protected void HandleButtonReleaseEvent (object o, ButtonReleaseEventArgs args)
138
 
                {
139
 
                        if (o is  AlphabetButton) {
140
 
                                InvokeLetterClicked ((o as AlphabetButton).Letter);
141
 
                        }
142
 
                }               
143
 
                #endregion
144
 
        }
 
10
    public class AlphabetEventArgs : EventArgs
 
11
    {
 
12
        protected AlphabetChars letter = AlphabetChars.unknown;
 
13
        public AlphabetChars Letter {
 
14
            get { return letter; }
 
15
        }
 
16
 
 
17
        public AlphabetEventArgs (AlphabetChars letter) : base ()
 
18
        {
 
19
            this.letter = letter;
 
20
        }
 
21
    }
 
22
 
 
23
 
 
24
    public class AlphabetBar : Clutter.Group
 
25
    {
 
26
 
 
27
        #region Events
 
28
        public event EventHandler<AlphabetEventArgs> LetterClicked;
 
29
        protected void InvokeLetterClicked (AlphabetChars letter)
 
30
        {
 
31
            if (LetterClicked!=null) LetterClicked (this, new AlphabetEventArgs (letter));
 
32
        }
 
33
        #endregion
 
34
 
 
35
        #region Fields
 
36
        protected CairoTexture background;
 
37
 
 
38
        protected Dictionary<AlphabetChars, AlphabetButton> buttons = new Dictionary<AlphabetChars, AlphabetButton>(Enum.GetValues(typeof(AlphabetChars)).Length);
 
39
        public AlphabetButton this [AlphabetChars index] {
 
40
            get { return buttons[index]; }
 
41
        }
 
42
 
 
43
        protected double Margin {
 
44
            get { return Width * 0.075; }
 
45
        }
 
46
 
 
47
        #endregion Fields
 
48
 
 
49
        #region Initialisation
 
50
        public AlphabetBar (uint width, uint height)
 
51
        {
 
52
            this.SetSize (width, height);
 
53
 
 
54
            InitBackground ();
 
55
            InitButtons ();
 
56
 
 
57
            ShowAll ();
 
58
        }
 
59
 
 
60
        protected virtual void InitBackground ()
 
61
        {
 
62
            background = new CairoTexture ((uint) Width,(uint) Height);
 
63
            Add (background);
 
64
 
 
65
            SetupBackground ();
 
66
            background.Show ();
 
67
        }
 
68
 
 
69
        protected virtual void SetupBackground ()
 
70
        {
 
71
            background.Clear();
 
72
            Cairo.Context context = background.Create ();
 
73
 
 
74
            double lwidth = 1;
 
75
            double hlwidth = lwidth*0.5;
 
76
 
 
77
            double margin = Margin;
 
78
 
 
79
            //left curvature:
 
80
            context.MoveTo (-hlwidth, -hlwidth);
 
81
            context.CurveTo (margin*0.33, -hlwidth,
 
82
                             margin*0.5, Height*0.4,
 
83
                             margin*0.5, Height*0.5);
 
84
            context.CurveTo (margin*0.5, Height*0.6,
 
85
                             margin*0.66, Height-hlwidth,
 
86
                             margin-hlwidth, Height-hlwidth);
 
87
 
 
88
 
 
89
            //straight bottom:
 
90
            context.LineTo (Width-margin-hlwidth, Height-hlwidth);
 
91
 
 
92
            //right curvature:
 
93
            context.CurveTo (Width-margin*0.66, Height - hlwidth,
 
94
                             Width-margin*0.5, Height*0.6,
 
95
                             Width-margin*0.5, Height*0.5);
 
96
            context.CurveTo (Width-margin*0.5, Height*0.4,
 
97
                             Width-margin*0.33, -hlwidth,
 
98
                             Width-hlwidth, -hlwidth);
 
99
 
 
100
            //straight top:
 
101
            context.LineTo (-hlwidth, -hlwidth);
 
102
            context.ClosePath ();
 
103
 
 
104
            context.LineWidth = lwidth;
 
105
            context.SetSourceRGBA (1.0, 1.0, 1.0, 1.0);
 
106
            context.StrokePreserve ();
 
107
            context.SetSourceRGBA (1.0, 1.0, 1.0, 0.10);
 
108
            context.Fill ();
 
109
 
 
110
            ((IDisposable) context.Target).Dispose();
 
111
            ((IDisposable) context).Dispose();
 
112
        }
 
113
 
 
114
        protected virtual void InitButtons ()
 
115
        {
 
116
            Array values = Enum.GetValues(typeof(AlphabetChars));
 
117
 
 
118
            int x_step = (int) ((Width * 0.950) / values.Length);
 
119
            uint b_width = (uint) x_step;
 
120
            uint b_height = (uint) (Height - 2);
 
121
 
 
122
            int x = (int) (Margin*0.5f + x_step);
 
123
            int y = (int) (Height * 0.5)+2;
 
124
 
 
125
            foreach (AlphabetChars key in values) {
 
126
                buttons[key] = new AlphabetButton (b_width, b_height, key);
 
127
                buttons[key].ButtonReleaseEvent += HandleButtonReleaseEvent;
 
128
                Add (buttons[key]);
 
129
                buttons[key].SetAnchorPoint ((float) buttons[key].Width*0.5f, (float) buttons[key].Height*0.5f);
 
130
                buttons[key].SetPosition (x, y);
 
131
                x += x_step;
 
132
            }
 
133
        }
 
134
        #endregion
 
135
 
 
136
        #region Event Handling
 
137
        protected void HandleButtonReleaseEvent (object o, ButtonReleaseEventArgs args)
 
138
        {
 
139
            if (o is  AlphabetButton) {
 
140
                InvokeLetterClicked ((o as AlphabetButton).Letter);
 
141
            }
 
142
        }
 
143
        #endregion
 
144
    }
145
145
}