This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
MyGameFramework/lib/gwen/controls/gwen_radiobuttoncontroller.cpp
Gered c5cdddbeaa initial commit
current versions of all of my basic framework sources, build configurations/scripts, and supporting assets
2013-01-31 12:53:05 -05:00

69 lines
1.6 KiB
C++

/*
GWEN
Copyright (c) 2010 Facepunch Studios
See license in Gwen.h
*/
#include "gwen_radiobuttoncontroller.h"
#include "gwen_radiobutton.h"
#include "../gwen_utility.h"
using namespace Gwen;
using namespace Gwen::Controls;
GWEN_CONTROL_CONSTRUCTOR( RadioButtonController )
{
m_Selected = NULL;
SetTabable( false );
SetKeyboardInputEnabled( false );
}
void RadioButtonController::OnRadioClicked( Gwen::Controls::Base* pFromPanel )
{
RadioButton* pCheckedRadioButton = gwen_cast<RadioButton>( pFromPanel );
//Iterate through all other buttons and set them to false;
for (Base::List::iterator iter = Children.begin(); iter != Children.end(); ++iter)
{
Base* pChild = *iter;
LabeledRadioButton* pLRB = gwen_cast<LabeledRadioButton>(pChild);
if ( pLRB )
{
RadioButton* pChildRadioButton = pLRB->GetRadioButton();
if ( pChildRadioButton == pCheckedRadioButton )
{
m_Selected = pLRB;
}
else
{
pLRB->GetRadioButton()->SetChecked( false );
}
}
}
OnChange();
}
void RadioButtonController::OnChange()
{
onSelectionChange.Call( this );
}
LabeledRadioButton* RadioButtonController::AddOption( const Gwen::String& strText, const Gwen::String& strOptionName )
{
LabeledRadioButton* lrb = new LabeledRadioButton( this );
lrb->SetName( strOptionName );
lrb->GetLabel()->SetText( strText );
lrb->GetRadioButton()->onChecked.Add( this, &RadioButtonController::OnRadioClicked );
lrb->Dock( Pos::Top );
lrb->SetMargin( Margin( 0, 1, 0, 1 ) );
lrb->SetKeyboardInputEnabled( false );
lrb->SetTabable( false );
Invalidate();
return lrb;
}