34
34
namespace ClutterFlow.Slider
37
public class ClutterSlider : Group
40
public event EventHandler<System.EventArgs> SliderHasMoved;
41
void HandleSliderHasMoved(object sender, EventArgs e)
43
if (SliderHasMoved!=null) SliderHasMoved(this, System.EventArgs.Empty);
45
public event EventHandler<System.EventArgs> SliderHasChanged;
46
private void HandleSliderHasChanged(object sender, EventArgs e)
48
SetPostionFromIndexSilently(HandlePostionFromIndex);
49
if (SliderHasChanged!=null) SliderHasChanged(this, System.EventArgs.Empty);
54
protected CairoTexture outline;
55
protected ClutterArrowButton arrow_left;
56
protected ClutterArrowButton arrow_right;
57
protected ClutterSliderHandle handle;
60
protected int count = 1;
67
int index = HandlePostionFromIndex;
69
HandlePostionFromIndex = index;
75
get { return handle.Button.Label; }
76
set { handle.Button.Label = value; }
79
public uint SliderWidth {
80
get { return (uint) (Width - Height*1.5f); }
84
#region Initialisation
85
public ClutterSlider (float width, float height) : base()
87
//this.IsReactive = true;
88
this.SetSize(width, height);
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;
96
outline = new CairoTexture (SliderWidth, (uint) Height);
98
outline.SetAnchorPoint (outline.Width*0.5f, outline.Height*0.5f);
99
outline.SetPosition (Width*0.5f, Height*0.5f);
101
arrow_left = new ClutterArrowButton((uint) arrow_width,(uint) arrow_height, 0, 0x03);
102
arrow_left.ButtonPressEvent += HandleLeftArrowButtonPressEvent;
104
arrow_left.SetPosition (0,0);
106
arrow_right = new ClutterArrowButton ((uint) arrow_width,(uint) arrow_height, 0, 0x01);
107
arrow_right.ButtonPressEvent += HandleRightArrowButtonPressEvent;
109
arrow_right.SetPosition ((float) (Width-arrow_width),0);
116
#region Index & Bounds methods
117
public void UpdateBounds(int count, int index)
120
HandlePostionFromIndex = index;
123
public int HandlePostionFromIndex
126
return (int) Math.Round(handle.Value * (float)(count-1));
130
if (retval >= count) retval = count-1;
131
if (retval < 0) retval = 0;
132
handle.Value = (float) retval / (float) (count-1);
136
protected void SetPostionFromIndexSilently (int value)
138
if (value >= count) value = count-1;
139
if (value < 0) value = 0;
140
handle.SetValueSilently ((float) value / (float) (count-1));
145
protected void HandleLeftArrowButtonPressEvent(object o, ButtonPressEventArgs args)
147
if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
148
HandlePostionFromIndex -= 1;
152
protected void HandleRightArrowButtonPressEvent(object o, ButtonPressEventArgs args)
154
if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
155
HandlePostionFromIndex += 1;
161
private double arrow_height {
162
get { return Height; }
164
private double arrow_width {
165
get { return arrow_height*1.25; }
167
private int line_width {
171
public virtual void Update() {
173
Cairo.Context context = outline.Create();
37
public class ClutterSlider : Group
40
public event EventHandler<System.EventArgs> SliderHasMoved;
41
void HandleSliderHasMoved(object sender, EventArgs e)
43
if (SliderHasMoved!=null) SliderHasMoved(this, System.EventArgs.Empty);
45
public event EventHandler<System.EventArgs> SliderHasChanged;
46
private void HandleSliderHasChanged(object sender, EventArgs e)
48
SetPostionFromIndexSilently(HandlePostionFromIndex);
49
if (SliderHasChanged!=null) SliderHasChanged(this, System.EventArgs.Empty);
54
protected CairoTexture outline;
55
protected ClutterArrowButton arrow_left;
56
protected ClutterArrowButton arrow_right;
57
protected ClutterSliderHandle handle;
60
protected int count = 1;
67
int index = HandlePostionFromIndex;
69
HandlePostionFromIndex = index;
75
get { return handle.Button.Label; }
76
set { handle.Button.Label = value; }
79
public uint SliderWidth {
80
get { return (uint) (Width - Height*1.5f); }
84
#region Initialisation
85
public ClutterSlider (float width, float height) : base()
87
//this.IsReactive = true;
88
this.SetSize(width, height);
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;
96
outline = new CairoTexture (SliderWidth, (uint) Height);
98
outline.SetAnchorPoint (outline.Width*0.5f, outline.Height*0.5f);
99
outline.SetPosition (Width*0.5f, Height*0.5f);
101
arrow_left = new ClutterArrowButton((uint) arrow_width,(uint) arrow_height, 0, 0x03);
102
arrow_left.ButtonPressEvent += HandleLeftArrowButtonPressEvent;
104
arrow_left.SetPosition (0,0);
106
arrow_right = new ClutterArrowButton ((uint) arrow_width,(uint) arrow_height, 0, 0x01);
107
arrow_right.ButtonPressEvent += HandleRightArrowButtonPressEvent;
109
arrow_right.SetPosition ((float) (Width-arrow_width),0);
116
#region Index & Bounds methods
117
public void UpdateBounds(int count, int index)
120
HandlePostionFromIndex = index;
123
public int HandlePostionFromIndex
126
return (int) Math.Round(handle.Value * (float)(count-1));
130
if (retval >= count) retval = count-1;
131
if (retval < 0) retval = 0;
132
handle.Value = (float) retval / (float) (count-1);
136
protected void SetPostionFromIndexSilently (int value)
138
if (value >= count) value = count-1;
139
if (value < 0) value = 0;
140
handle.SetValueSilently ((float) value / (float) (count-1));
145
protected void HandleLeftArrowButtonPressEvent(object o, ButtonPressEventArgs args)
147
if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
148
HandlePostionFromIndex -= 1;
152
protected void HandleRightArrowButtonPressEvent(object o, ButtonPressEventArgs args)
154
if (args.Event.ClickCount==1 || args.Event.ClickCount%2!=1)
155
HandlePostionFromIndex += 1;
161
private double arrow_height {
162
get { return Height; }
164
private double arrow_width {
165
get { return arrow_height*1.25; }
167
private int line_width {
171
public virtual void Update() {
173
Cairo.Context context = outline.Create ();
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);
180
context.SetSourceRGBA(1.0,1.0,1.0,0.2);
181
context.FillPreserve();
182
context.SetSourceRGB(1.0,1.0,1.0);
185
((IDisposable) context.Target).Dispose();
186
((IDisposable) context).Dispose();
191
arrow_right.Update();
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);
180
context.SetSourceRGBA(1.0,1.0,1.0,0.2);
181
context.FillPreserve();
182
context.SetSourceRGB(1.0,1.0,1.0);
185
((IDisposable) context.Target).Dispose();
186
((IDisposable) context).Dispose();
191
arrow_right.Update();
b'\\ No newline at end of file'