34
34
namespace ClutterFlow.Buttons
38
public abstract class ClutterToggleButton : ClutterButtonState
41
public event EventHandler Toggled;
42
protected void InvokeToggled () {
43
if (Toggled!=null) Toggled (this, EventArgs.Empty);
47
/// MaxBits represents the toggle buttons maximal bit-states to be set:
52
protected override int MaxState {
56
private bool freeze_state = false;
57
public virtual bool IsActive {
58
get { return (state & 4) > 0; }
61
if (value && (state & 4)==0) {
64
} else if (!value && (state & 4)>0) {
71
public virtual void SetSilent (bool value)
74
if (value && (state & 4)==0) {
76
} else if (!value && (state & 4)>0) {
82
public virtual CairoTexture StateTexture {
83
get { return (IsActive) ? active_button.StateTexture : passive_button.StateTexture; }
86
protected ClutterGenericButton passive_button;
87
protected ClutterGenericButton active_button;
89
public ClutterToggleButton (uint width, uint height, bool toggled) : this (width, height, toggled ? 0x04 : 0x00)
93
public ClutterToggleButton (uint width, uint height, int state) : base ()
95
this.SetSize (width, height);
98
passive_button = new ClutterGenericButton(width, height, state, CreatePassiveTexture);
99
passive_button.BubbleEvents = true;
100
active_button = new ClutterGenericButton(width, height, state, CreateActiveTexture);
101
active_button.BubbleEvents = true;
106
protected override void Initialise () {
107
Add (passive_button);
112
active_button.Update ();
113
passive_button.Update ();
118
#region Event Handling
119
protected override void HandleButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
121
State = (state^4) & ~2;
122
freeze_state = true; //freeze the state untill after the event has finished handling
124
freeze_state = false; //thaw the state
125
args.RetVal = !bubble;
129
public override void Update () {
130
if ((state & 4) > 0) {
131
passive_button.Hide ();
132
active_button.State = state;
133
active_button.Show ();
135
active_button.Hide ();
136
passive_button.State = state;
137
passive_button.Show ();
142
protected abstract void CreatePassiveTexture (Clutter.CairoTexture texture, int with_state);
143
protected abstract void CreateActiveTexture (Clutter.CairoTexture texture, int with_state);
38
public abstract class ClutterToggleButton : ClutterButtonState
41
public event EventHandler Toggled;
42
protected void InvokeToggled () {
43
if (Toggled!=null) Toggled (this, EventArgs.Empty);
47
/// MaxBits represents the toggle buttons maximal bit-states to be set:
52
protected override int MaxState {
56
private bool freeze_state = false;
57
public virtual bool IsActive {
58
get { return (state & 4) > 0; }
61
if (value && (state & 4)==0) {
64
} else if (!value && (state & 4)>0) {
71
public virtual void SetSilent (bool value)
74
if (value && (state & 4)==0) {
76
} else if (!value && (state & 4)>0) {
82
public virtual CairoTexture StateTexture {
83
get { return (IsActive) ? active_button.StateTexture : passive_button.StateTexture; }
86
protected ClutterGenericButton passive_button;
87
protected ClutterGenericButton active_button;
89
public ClutterToggleButton (uint width, uint height, bool toggled) : this (width, height, toggled ? 0x04 : 0x00)
93
public ClutterToggleButton (uint width, uint height, int state) : base ()
95
this.SetSize (width, height);
98
passive_button = new ClutterGenericButton(width, height, state, CreatePassiveTexture);
99
passive_button.BubbleEvents = true;
100
active_button = new ClutterGenericButton(width, height, state, CreateActiveTexture);
101
active_button.BubbleEvents = true;
106
protected override void Initialise () {
107
Add (passive_button);
112
active_button.Update ();
113
passive_button.Update ();
118
#region Event Handling
119
protected override void HandleButtonReleaseEvent(object o, ButtonReleaseEventArgs args)
121
State = (state^4) & ~2;
122
freeze_state = true; //freeze the state untill after the event has finished handling
124
freeze_state = false; //thaw the state
125
args.RetVal = !bubble;
129
public override void Update () {
130
if ((state & 4) > 0) {
131
passive_button.Hide ();
132
active_button.State = state;
133
active_button.Show ();
135
active_button.Hide ();
136
passive_button.State = state;
137
passive_button.Show ();
142
protected abstract void CreatePassiveTexture (Clutter.CairoTexture texture, int with_state);
143
protected abstract void CreateActiveTexture (Clutter.CairoTexture texture, int with_state);