/*
* GUIRadioContainer.cs
* Authors: Bradley R. 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 Util;
namespace tAC_Engine.GUI
{
///
/// This panel stores a set of GUIButtons and other components.
/// However, what it does is it allows for the selection of
/// only a single button at a time on the panel, while making
/// sure the other buttons are properly updated off.
///
public abstract class GUIRadioContainer : GUIContainer
{
#region Event Handling
///
/// Handle the mouse events by propegating them to the correct
/// button. All other buttons should be disabled (reinitialized).
///
///
public override bool HandleMouseEvent(MouseInputEvent e)
{
// The return value
bool retVal = false;
// If it's visible and enabled
if (Visible)
{
// Only do this for the left mouse click
if (e.EventCode == (int)GUIEventCodes.LEFT_MOUSE_CLICKED)
{
// The selected component
GUIComponent selected = null;
// Go through each of the components
foreach (GUIComponent component in Components)
{
// Go through till we handle the event
if (component.HandleMouseEvent(e))
{
// The return value is true
retVal = true;
// Set the selected value
selected = component;
// Set the event args
e.EventArgs = component;
// Break out
break;
}
}
// Do this if selected is not null
if (selected != null && selected is GUIButton)
{
// Go through each of the components and set the other non-selected's up
foreach (GUIComponent component in Components)
{
// See if the component is not a selected one
if (component != selected && component is GUIButton)
{
// If not, put its state down
((GUIButton)component).State = GUIButton.ButtonState.UP;
}
}
}
}
}
// Return
return retVal;
}
#endregion
#region Utility
///
/// Deselects all buttons on the panel.
///
public void DeselectAll()
{
// Deselect all buttons in the panel
foreach (GUIComponent component in Components)
{
// Cast it
GUIButton button = component as GUIButton;
// If it's not null
if (button != null)
{
// Set it to up
button.State = GUIButton.ButtonState.UP;
}
}
}
#endregion
}
}