/*
* GUIToggleButton.cs
* Authors: Bradley Blankenship
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using tAC_Engine.GUI;
using Util;
namespace tAC_Engine.GUI
{
///
/// This button maintains state after being clicked
///
public class GUIToggleButton : GUIButton
{
#region Fields
///
/// Event for when the button has been toggled on/off
///
public event EventHandler ButtonToggled;
#endregion
#region Event Handles
///
/// Handle the given event.
///
/// The event to handle.
public override bool HandleMouseEvent(MouseInputEvent e)
{
// The return value
bool retVal = false;
// If we're visible
if (Visible && Enabled)
{
// Check to see if it's within our bounds
if (Bounds.Contains(e.X, e.Y))
{
// Switch on the given codes
switch (e.EventCode)
{
// Evaluate for a left mouse button press
case (int)GUIEventCodes.LEFT_MOUSE_CLICKED:
// Toggle the state
switch (State)
{
case ButtonState.DOWN:
State = ButtonState.UP;
break;
case ButtonState.UP:
State = ButtonState.DOWN;
break;
}
// Invoke Event
if (ButtonToggled != null)
ButtonToggled.Invoke(this, EventArgs.Empty);
break;
}
// Set the event args if they're null
if (e.EventArgs == null)
{
// Set the event args to us
e.EventArgs = this;
}
// Set the ret val to true
retVal = true;
}
}
// Return
return retVal;
}
#endregion
}
}