using System; namespace Gwen.Control { /// /// CheckBox control. /// public class CheckBox : Button { private bool m_Checked; /// /// Indicates whether the checkbox is checked. /// public bool IsChecked { get { return m_Checked; } set { if (m_Checked == value) return; m_Checked = value; OnCheckChanged(); } } /// /// Initializes a new instance of the class. /// /// Parent control. public CheckBox(Base parent) : base(parent) { SetSize(15, 15); //m_Checked = true; // [omeg] why?! //Toggle(); } /// /// Toggles the checkbox. /// public override void Toggle() { base.Toggle(); IsChecked = !IsChecked; } /// /// Invoked when the checkbox has been checked. /// public event GwenEventHandler Checked; /// /// Invoked when the checkbox has been unchecked. /// public event GwenEventHandler UnChecked; /// /// Invoked when the checkbox state has been changed. /// public event GwenEventHandler CheckChanged; /// /// Determines whether unchecking is allowed. /// protected virtual bool AllowUncheck { get { return true; } } /// /// Handler for CheckChanged event. /// protected virtual void OnCheckChanged() { if (IsChecked) { if (Checked != null) Checked.Invoke(this); } else { if (UnChecked != null) UnChecked.Invoke(this); } if (CheckChanged != null) CheckChanged.Invoke(this); } /// /// Renders the control using specified skin. /// /// Skin to use. protected override void Render(Skin.Base skin) { base.Render(skin); skin.DrawCheckBox(this, m_Checked, IsDepressed); } /// /// Internal OnPressed implementation. /// protected override void OnClicked() { if (IsDisabled) return; if (IsChecked && !AllowUncheck) { return; } Toggle(); } } }