~ubuntu-branches/debian/jessie/banshee-community-extensions/jessie

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2011-09-20 18:45:46 UTC
  • mfrom: (1.2.9 upstream) (5.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20110920184546-3ahue2qplydc4t0e
Tags: 2.2.0-1
* [4940fab] Imported Upstream version 2.2.0
  + Notable bug fixes:
    - Karaoke: Fix crash when switching to Now Playing
    - Lyrics: Fix crash when switching to Now Playing

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
namespace ClutterFlow.Slider
35
35
{
36
 
        
37
 
        public class ClutterSlider : Group
38
 
        {       
39
 
                #region Events
40
 
                public event EventHandler<System.EventArgs> SliderHasMoved;
41
 
                void HandleSliderHasMoved(object sender, EventArgs e)
42
 
                {
43
 
                        if (SliderHasMoved!=null) SliderHasMoved(this, System.EventArgs.Empty);
44
 
                }
45
 
                public event EventHandler<System.EventArgs> SliderHasChanged;
46
 
                private void HandleSliderHasChanged(object sender, EventArgs e)
47
 
                {
48
 
                        SetPostionFromIndexSilently(HandlePostionFromIndex);
49
 
                        if (SliderHasChanged!=null) SliderHasChanged(this, System.EventArgs.Empty);
50
 
                }
51
 
                #endregion
52
 
                
53
 
                #region Fields
54
 
                protected CairoTexture outline;
55
 
                protected ClutterArrowButton arrow_left;
56
 
                protected ClutterArrowButton arrow_right;
57
 
                protected ClutterSliderHandle handle;
58
 
                
59
 
                //Count is 1-based
60
 
                protected int count = 1;
61
 
                public int Count {
62
 
                        get {
63
 
                                return count;
64
 
                        }
65
 
                        set {
66
 
                                if (count!=value) {
67
 
                                        int index = HandlePostionFromIndex;
68
 
                                        count = value;
69
 
                                        HandlePostionFromIndex = index;
70
 
                                }
71
 
                        }
72
 
                }
73
 
                
74
 
                public string Label {
75
 
                        get { return handle.Button.Label; }
76
 
                        set { handle.Button.Label = value; }
77
 
                }
78
 
                
79
 
                public uint SliderWidth {
80
 
                        get { return (uint) (Width - Height*1.5f); }
81
 
                }
82
 
                #endregion
83
 
                
84
 
                #region Initialisation
85
 
                public ClutterSlider (float width, float height) : base()
86
 
                {
87
 
                        //this.IsReactive = true;
88
 
                        this.SetSize(width, height);
89
 
                        
90
 
                        handle = new ClutterSliderHandle((float) arrow_width*0.5f + line_width*2, 0, (float) SliderWidth, (float) Height, 0);
91
 
                        handle.SliderHasChanged += HandleSliderHasChanged;
92
 
                        handle.SliderHasMoved += HandleSliderHasMoved;
93
 
                        handle.BubbleEvents = true;
94
 
                        Add(handle);
95
 
                        
96
 
                        outline = new CairoTexture (SliderWidth, (uint) Height);
97
 
                        Add(outline);
98
 
                        outline.SetAnchorPoint (outline.Width*0.5f, outline.Height*0.5f);
99
 
                        outline.SetPosition (Width*0.5f, Height*0.5f);
100
 
                        
101
 
                        arrow_left = new ClutterArrowButton((uint) arrow_width,(uint) arrow_height, 0, 0x03);
102
 
                        arrow_left.ButtonPressEvent += HandleLeftArrowButtonPressEvent;
103
 
                        Add (arrow_left);
104
 
                        arrow_left.SetPosition (0,0);
105
 
                        
106
 
                        arrow_right = new ClutterArrowButton ((uint) arrow_width,(uint) arrow_height, 0, 0x01);
107
 
                        arrow_right.ButtonPressEvent += HandleRightArrowButtonPressEvent;
108
 
                        Add (arrow_right);
109
 
                        arrow_right.SetPosition ((float) (Width-arrow_width),0);
110
 
                                        
111
 
                        Update ();
112
 
                        ShowAll ();
113
 
                }
114
 
                #endregion
115
 
                
116
 
                #region Index & Bounds methods
117
 
                public void UpdateBounds(int count, int index)
118
 
                {
119
 
                        this.count = count;
120
 
                        HandlePostionFromIndex = index;
121
 
                }
122
 
                
123
 
                public int HandlePostionFromIndex
124
 
                {
125
 
                        get {
126
 
                                return (int) Math.Round(handle.Value * (float)(count-1));
127
 
                        }
128
 
                        set {
129
 
                                int retval = value;
130
 
                                if (retval >= count) retval = count-1;
131
 
                                if (retval < 0) retval = 0;
132
 
                                handle.Value = (float) retval / (float) (count-1);
133
 
                        }
134
 
                }
135
 
 
136
 
                protected void SetPostionFromIndexSilently (int value)
137
 
                {
138
 
                        if (value >= count) value = count-1;
139
 
                        if (value < 0) value = 0;
140
 
                        handle.SetValueSilently ((float) value / (float) (count-1));
141
 
                }
142
 
                #endregion              
143
 
                
144
 
                #region Events
145
 
                protected void HandleLeftArrowButtonPressEvent(object o, ButtonPressEventArgs args)
146
 
                {
147
 
                        if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
148
 
                                HandlePostionFromIndex -= 1;
149
 
                        args.RetVal = true;
150
 
                }
151
 
                
152
 
                protected void HandleRightArrowButtonPressEvent(object o, ButtonPressEventArgs args)
153
 
                {
154
 
                        if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
155
 
                                HandlePostionFromIndex += 1;
156
 
                        args.RetVal = true;
157
 
                }
158
 
                #endregion
159
 
                
160
 
                #region Rendering
161
 
                private double arrow_height {
162
 
                        get { return Height; }
163
 
                }
164
 
                private double arrow_width {
165
 
                        get { return arrow_height*1.25; }
166
 
                }
167
 
                private int line_width {
168
 
                        get { return 1; }
169
 
                }
170
 
                
171
 
                public virtual void Update() {
172
 
                        outline.Clear();
173
 
                        Cairo.Context context = outline.Create();
174
 
                        
 
36
 
 
37
    public class ClutterSlider : Group
 
38
    {
 
39
        #region Events
 
40
        public event EventHandler<System.EventArgs> SliderHasMoved;
 
41
        void HandleSliderHasMoved(object sender, EventArgs e)
 
42
        {
 
43
            if (SliderHasMoved!=null) SliderHasMoved(this, System.EventArgs.Empty);
 
44
        }
 
45
        public event EventHandler<System.EventArgs> SliderHasChanged;
 
46
        private void HandleSliderHasChanged(object sender, EventArgs e)
 
47
        {
 
48
            SetPostionFromIndexSilently(HandlePostionFromIndex);
 
49
            if (SliderHasChanged!=null) SliderHasChanged(this, System.EventArgs.Empty);
 
50
        }
 
51
        #endregion
 
52
 
 
53
        #region Fields
 
54
        protected CairoTexture outline;
 
55
        protected ClutterArrowButton arrow_left;
 
56
        protected ClutterArrowButton arrow_right;
 
57
        protected ClutterSliderHandle handle;
 
58
 
 
59
        //Count is 1-based
 
60
        protected int count = 1;
 
61
        public int Count {
 
62
            get {
 
63
                return count;
 
64
            }
 
65
            set {
 
66
                if (count!=value) {
 
67
                    int index = HandlePostionFromIndex;
 
68
                    count = value;
 
69
                    HandlePostionFromIndex = index;
 
70
                }
 
71
            }
 
72
        }
 
73
 
 
74
        public string Label {
 
75
            get { return handle.Button.Label; }
 
76
            set { handle.Button.Label = value; }
 
77
        }
 
78
 
 
79
        public uint SliderWidth {
 
80
            get { return (uint) (Width - Height*1.5f); }
 
81
        }
 
82
        #endregion
 
83
 
 
84
        #region Initialisation
 
85
        public ClutterSlider (float width, float height) : base()
 
86
        {
 
87
            //this.IsReactive = true;
 
88
            this.SetSize(width, height);
 
89
 
 
90
            handle = new ClutterSliderHandle((float) arrow_width*0.5f + line_width*2, 0, (float) SliderWidth, (float) Height, 0);
 
91
            handle.SliderHasChanged += HandleSliderHasChanged;
 
92
            handle.SliderHasMoved += HandleSliderHasMoved;
 
93
            handle.BubbleEvents = true;
 
94
            Add(handle);
 
95
 
 
96
            outline = new CairoTexture (SliderWidth, (uint) Height);
 
97
            Add(outline);
 
98
            outline.SetAnchorPoint (outline.Width*0.5f, outline.Height*0.5f);
 
99
            outline.SetPosition (Width*0.5f, Height*0.5f);
 
100
 
 
101
            arrow_left = new ClutterArrowButton((uint) arrow_width,(uint) arrow_height, 0, 0x03);
 
102
            arrow_left.ButtonPressEvent += HandleLeftArrowButtonPressEvent;
 
103
            Add (arrow_left);
 
104
            arrow_left.SetPosition (0,0);
 
105
 
 
106
            arrow_right = new ClutterArrowButton ((uint) arrow_width,(uint) arrow_height, 0, 0x01);
 
107
            arrow_right.ButtonPressEvent += HandleRightArrowButtonPressEvent;
 
108
            Add (arrow_right);
 
109
            arrow_right.SetPosition ((float) (Width-arrow_width),0);
 
110
 
 
111
            Update ();
 
112
            ShowAll ();
 
113
        }
 
114
        #endregion
 
115
 
 
116
        #region Index & Bounds methods
 
117
        public void UpdateBounds(int count, int index)
 
118
        {
 
119
            this.count = count;
 
120
            HandlePostionFromIndex = index;
 
121
        }
 
122
 
 
123
        public int HandlePostionFromIndex
 
124
        {
 
125
            get {
 
126
                return (int) Math.Round(handle.Value * (float)(count-1));
 
127
            }
 
128
            set {
 
129
                int retval = value;
 
130
                if (retval >= count) retval = count-1;
 
131
                if (retval < 0) retval = 0;
 
132
                handle.Value = (float) retval / (float) (count-1);
 
133
            }
 
134
        }
 
135
 
 
136
        protected void SetPostionFromIndexSilently (int value)
 
137
        {
 
138
            if (value >= count) value = count-1;
 
139
            if (value < 0) value = 0;
 
140
            handle.SetValueSilently ((float) value / (float) (count-1));
 
141
        }
 
142
        #endregion
 
143
 
 
144
        #region Events
 
145
        protected void HandleLeftArrowButtonPressEvent(object o, ButtonPressEventArgs args)
 
146
        {
 
147
            if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
 
148
                HandlePostionFromIndex -= 1;
 
149
            args.RetVal = true;
 
150
        }
 
151
 
 
152
        protected void HandleRightArrowButtonPressEvent(object o, ButtonPressEventArgs args)
 
153
        {
 
154
            if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
 
155
                HandlePostionFromIndex += 1;
 
156
            args.RetVal = true;
 
157
        }
 
158
        #endregion
 
159
 
 
160
        #region Rendering
 
161
        private double arrow_height {
 
162
            get { return Height; }
 
163
        }
 
164
        private double arrow_width {
 
165
            get { return arrow_height*1.25; }
 
166
        }
 
167
        private int line_width {
 
168
            get { return 1; }
 
169
        }
 
170
 
 
171
        public virtual void Update() {
 
172
            outline.Clear();
 
173
            Cairo.Context context = outline.Create ();
 
174
 
175
175
            context.LineWidth = line_width;
176
 
                        context.MoveTo(outline.Height*0.5, 0.5);
177
 
                        context.Arc(outline.Width-outline.Height*0.5,outline.Height*0.5,(outline.Height-line_width)*0.5,1.5*Math.PI,0.5*Math.PI);
178
 
                        context.Arc(outline.Height*0.5,outline.Height*0.5,(outline.Height-line_width)*0.5,0.5*Math.PI,1.5*Math.PI);
179
 
                        context.ClosePath();
180
 
                        context.SetSourceRGBA(1.0,1.0,1.0,0.2);
181
 
                        context.FillPreserve();
182
 
                        context.SetSourceRGB(1.0,1.0,1.0);
183
 
                        context.Stroke();
184
 
                        
185
 
                        ((IDisposable) context.Target).Dispose();
186
 
                        ((IDisposable) context).Dispose();
187
 
                        
188
 
                        handle.Update();
189
 
                        handle.RaiseTop();
190
 
                        arrow_left.Update();
191
 
                        arrow_right.Update();
192
 
                }
193
 
                #endregion              
194
 
        }
 
176
            context.MoveTo(outline.Height*0.5, 0.5);
 
177
            context.Arc(outline.Width-outline.Height*0.5,outline.Height*0.5,(outline.Height-line_width)*0.5,1.5*Math.PI,0.5*Math.PI);
 
178
            context.Arc(outline.Height*0.5,outline.Height*0.5,(outline.Height-line_width)*0.5,0.5*Math.PI,1.5*Math.PI);
 
179
            context.ClosePath();
 
180
            context.SetSourceRGBA(1.0,1.0,1.0,0.2);
 
181
            context.FillPreserve();
 
182
            context.SetSourceRGB(1.0,1.0,1.0);
 
183
            context.Stroke();
 
184
 
 
185
            ((IDisposable) context.Target).Dispose();
 
186
            ((IDisposable) context).Dispose();
 
187
 
 
188
            handle.Update();
 
189
            handle.RaiseTop();
 
190
            arrow_left.Update();
 
191
            arrow_right.Update();
 
192
        }
 
193
        #endregion
 
194
    }
195
195
}
 
 
b'\\ No newline at end of file'