@ -26,490 +26,495 @@
using namespace std ;
using namespace NLMISC ;
// ***************************************************************************
static const uint KEY_REPEAT_MIN = 100 ;
static const uint KEY_REPEAT_MAX = 750 ;
sint64 CCtrlBaseButton : : _LastLeftClickDate = 0 ;
NLMISC : : CRefPtr < CCtrlBaseButton > CCtrlBaseButton : : _LastLeftClickButton ;
// ***************************************************************************
CCtrlBaseButton : : CCtrlBaseButton ( const TCtorParam & param ) : CCtrlBase ( param ) , _Type ( ToggleButton )
namespace
{
_Pushed = _Over = false ;
_Frozen = false ;
_FrozenHalfTone = true ;
_OverWhenPushed = true ;
_ColorOver = _ColorPushed = _ColorNormal = NLMISC : : CRGBA ( 255 , 255 , 255 , 255 ) ;
_ModulateGlobalColorNormal = _ModulateGlobalColorPushed = _ModulateGlobalColorOver = true ;
_LeftLongClickHandled = true ;
_LeftDblClickHandled = false ;
_ClickWhenPushed = false ;
_RBRefBut = NULL ;
_RBRef = NULL ;
_AHOnOver = NULL ;
_AHOnLeftClick = NULL ;
_AHOnRightClick = NULL ;
_AHOnClockTick = NULL ;
_AHOnLeftLongClick = NULL ;
_AHOnLeftDblClick = NULL ;
const uint KEY_REPEAT_MIN = 100 ;
const uint KEY_REPEAT_MAX = 750 ;
}
// ***************************************************************************
bool CCtrlBaseButton : : parse ( xmlNodePtr cur , CInterfaceGroup * parentGroup )
namespace NLGUI
{
CXMLAutoPtr prop ;
//try to get props that can be inherited from groups
//if a property is not defined, try to find it in the parent group.
//if it is undefined, set it to zero
if ( ! CCtrlBase : : parse ( cur , parentGroup ) )
return false ;
sint64 CCtrlBaseButton : : _LastLeftClickDate = 0 ;
NLMISC : : CRefPtr < CCtrlBaseButton > CCtrlBaseButton : : _LastLeftClickButton ;
_Over = false ;
// *** try to get the NEEDED specific props
prop = xmlGetProp ( cur , ( xmlChar * ) " button_type " ) ;
string type ;
if ( prop ) type = ( const char * ) prop ;
if ( type . empty ( ) | | type = = " toggle_button " )
// ***************************************************************************
CCtrlBaseButton : : CCtrlBaseButton ( const TCtorParam & param ) : CCtrlBase ( param ) , _Type ( ToggleButton )
{
_Type = ToggleButton ;
_Pushed = _Over = false ;
_Frozen = false ;
_FrozenHalfTone = true ;
_OverWhenPushed = true ;
_ColorOver = _ColorPushed = _ColorNormal = NLMISC : : CRGBA ( 255 , 255 , 255 , 255 ) ;
_ModulateGlobalColorNormal = _ModulateGlobalColorPushed = _ModulateGlobalColorOver = true ;
_LeftLongClickHandled = true ;
_LeftDblClickHandled = false ;
_ClickWhenPushed = false ;
_RBRefBut = NULL ;
_RBRef = NULL ;
_AHOnOver = NULL ;
_AHOnLeftClick = NULL ;
_AHOnRightClick = NULL ;
_AHOnClockTick = NULL ;
_AHOnLeftLongClick = NULL ;
_AHOnLeftDblClick = NULL ;
}
else if ( type = = " push_button " )
{
_Type = PushButton ;
}
else if ( type = = " radio_button " )
{
_Type = RadioButton ;
initRBRef ( ) ;
if ( _Pushed )
* _RBRef = this ;
}
else
{
nlinfo ( ( " cannot parse button type for button " + getId ( ) ) . c_str ( ) ) ;
}
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " pushed " ) ;
_Pushed = false ;
if ( prop )
_Pushed = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " over_when_pushed " ) ;
_OverWhenPushed = true ;
if ( prop )
_OverWhenPushed = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " click_when_pushed " ) ;
_ClickWhenPushed = false ;
if ( prop )
_ClickWhenPushed = convertBool ( prop ) ;
// *** Read Colors
// get color normal
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " color " ) ;
_ColorNormal = CRGBA ( 255 , 255 , 255 , 255 ) ;
if ( prop )
_ColorNormal = convertColor ( prop ) ;
// Get ColorPushed
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " col_pushed " ) ;
_ColorPushed = CRGBA ( 255 , 255 , 255 , 255 ) ;
if ( prop )
_ColorPushed = convertColor ( prop ) ;
// Get ColorOver
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " col_over " ) ;
_ColorOver = CRGBA ( 255 , 255 , 255 , 255 ) ;
if ( prop )
_ColorOver = convertColor ( prop ) ;
// Default: take "global_color" param interface_element option.
_ModulateGlobalColorNormal = _ModulateGlobalColorPushed = _ModulateGlobalColorOver = getModulateGlobalColor ( ) ;
// Read special global_color for each state
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " global_color_normal " ) ;
if ( prop ) _ModulateGlobalColorNormal = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " global_color_pushed " ) ;
if ( prop ) _ModulateGlobalColorPushed = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " global_color_over " ) ;
if ( prop ) _ModulateGlobalColorOver = convertBool ( prop ) ;
// *** Read Action handlers
CAHManager : : getInstance ( ) - > parseAH ( cur , " onover " , " params_over " , _AHOnOver , _AHOverParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onclick_l " , " params_l " , _AHOnLeftClick , _AHLeftClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " ondblclick_l " , " params_dblclick_l " , _AHOnLeftDblClick , _AHLeftDblClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onclick_r " , " params_r " , _AHOnRightClick , _AHRightClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onlongclick_l " , " params_longclick_l " , _AHOnLeftLongClick , _AHLeftLongClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onclock_tick " , " params_clock_tick " , _AHOnClockTick , _AHClockTickParams ) ;
// Context menu association
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " menu_l " ) ;
if ( prop )
{
_ListMenuLeft = NLMISC : : toLower ( std : : string ( ( const char * ) prop ) ) ;
}
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " menu_r " ) ;
if ( prop )
{
_ListMenuRight = NLMISC : : toLower ( std : : string ( ( const char * ) prop ) ) ;
}
// list menu on both clicks
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " menu_b " ) ;
if ( prop )
// ***************************************************************************
bool CCtrlBaseButton : : parse ( xmlNodePtr cur , CInterfaceGroup * parentGroup )
{
setListMenuBoth ( NLMISC : : toLower ( std : : string ( ( const char * ) prop ) ) ) ;
}
CXMLAutoPtr prop ;
//try to get props that can be inherited from groups
//if a property is not defined, try to find it in the parent group.
//if it is undefined, set it to zero
if ( ! CCtrlBase : : parse ( cur , parentGroup ) )
return false ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " frozen " ) ;
_Frozen = false ;
if ( prop )
_Frozen = convertBool ( prop ) ;
_Over = false ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " frozen_half_tone " ) ;
_FrozenHalfTone = true ;
if ( prop )
_FrozenHalfTone = convertBool ( prop ) ;
// *** try to get the NEEDED specific props
prop = xmlGetProp ( cur , ( xmlChar * ) " button_type " ) ;
string type ;
if ( prop ) type = ( const char * ) prop ;
if ( type . empty ( ) | | type = = " toggle_button " )
{
_Type = ToggleButton ;
}
else if ( type = = " push_button " )
{
_Type = PushButton ;
}
else if ( type = = " radio_button " )
{
_Type = RadioButton ;
return true ;
}
initRBRef ( ) ;
if ( _Pushed )
* _RBRef = this ;
}
else
{
nlinfo ( ( " cannot parse button type for button " + getId ( ) ) . c_str ( ) ) ;
}
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " pushed " ) ;
_Pushed = false ;
if ( prop )
_Pushed = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " over_when_pushed " ) ;
_OverWhenPushed = true ;
if ( prop )
_OverWhenPushed = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " click_when_pushed " ) ;
_ClickWhenPushed = false ;
if ( prop )
_ClickWhenPushed = convertBool ( prop ) ;
// *** Read Colors
// get color normal
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " color " ) ;
_ColorNormal = CRGBA ( 255 , 255 , 255 , 255 ) ;
if ( prop )
_ColorNormal = convertColor ( prop ) ;
// Get ColorPushed
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " col_pushed " ) ;
_ColorPushed = CRGBA ( 255 , 255 , 255 , 255 ) ;
if ( prop )
_ColorPushed = convertColor ( prop ) ;
// Get ColorOver
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " col_over " ) ;
_ColorOver = CRGBA ( 255 , 255 , 255 , 255 ) ;
if ( prop )
_ColorOver = convertColor ( prop ) ;
// Default: take "global_color" param interface_element option.
_ModulateGlobalColorNormal = _ModulateGlobalColorPushed = _ModulateGlobalColorOver = getModulateGlobalColor ( ) ;
// Read special global_color for each state
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " global_color_normal " ) ;
if ( prop ) _ModulateGlobalColorNormal = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " global_color_pushed " ) ;
if ( prop ) _ModulateGlobalColorPushed = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " global_color_over " ) ;
if ( prop ) _ModulateGlobalColorOver = convertBool ( prop ) ;
// *** Read Action handlers
CAHManager : : getInstance ( ) - > parseAH ( cur , " onover " , " params_over " , _AHOnOver , _AHOverParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onclick_l " , " params_l " , _AHOnLeftClick , _AHLeftClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " ondblclick_l " , " params_dblclick_l " , _AHOnLeftDblClick , _AHLeftDblClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onclick_r " , " params_r " , _AHOnRightClick , _AHRightClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onlongclick_l " , " params_longclick_l " , _AHOnLeftLongClick , _AHLeftLongClickParams ) ;
CAHManager : : getInstance ( ) - > parseAH ( cur , " onclock_tick " , " params_clock_tick " , _AHOnClockTick , _AHClockTickParams ) ;
// Context menu association
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " menu_l " ) ;
if ( prop )
{
_ListMenuLeft = NLMISC : : toLower ( std : : string ( ( const char * ) prop ) ) ;
}
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " menu_r " ) ;
if ( prop )
{
_ListMenuRight = NLMISC : : toLower ( std : : string ( ( const char * ) prop ) ) ;
}
// list menu on both clicks
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " menu_b " ) ;
if ( prop )
{
setListMenuBoth ( NLMISC : : toLower ( std : : string ( ( const char * ) prop ) ) ) ;
}
// ***************************************************************************
void CCtrlBaseButton : : setModulateGlobalColorAll ( bool state )
{
setModulateGlobalColor ( state ) ;
setModulateGlobalColorNormal ( state ) ;
setModulateGlobalColorPushed ( state ) ;
setModulateGlobalColorOver ( state ) ;
}
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " frozen " ) ;
_Frozen = false ;
if ( prop )
_Frozen = convertBool ( prop ) ;
prop = ( char * ) xmlGetProp ( cur , ( xmlChar * ) " frozen_half_tone " ) ;
_FrozenHalfTone = true ;
if ( prop )
_FrozenHalfTone = convertBool ( prop ) ;
// ***************************************************************************
bool CCtrlBaseButton : : handleEvent ( const NLGUI : : CEventDescriptor & event )
{
if ( CCtrlBase : : handleEvent ( event ) ) return true ;
if ( ! _Active | | _Frozen )
return false ;
return true ;
}
sint64 T1 = NLMISC : : CTime : : getLocalTime ( ) ;
if ( event . getType ( ) = = NLGUI : : CEventDescriptor : : mouse )
// ***************************************************************************
void CCtrlBaseButton : : setModulateGlobalColorAll ( bool state )
{
const NLGUI : : CEventDescriptorMouse & eventDesc = ( const NLGUI : : CEventDescriptorMouse & ) event ;
setModulateGlobalColor ( state ) ;
setModulateGlobalColorNormal ( state ) ;
setModulateGlobalColorPushed ( state ) ;
setModulateGlobalColorOver ( state ) ;
}
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouseleftup )
{
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = this )
return false ;
_LeftLongClickHandled = true ;
}
if ( ! ( ( eventDesc . getX ( ) > = _XReal ) & &
( eventDesc . getX ( ) < ( _XReal + _WReal ) ) & &
( eventDesc . getY ( ) > _YReal ) & &
( eventDesc . getY ( ) < = ( _YReal + _HReal ) ) ) )
// ***************************************************************************
bool CCtrlBaseButton : : handleEvent ( const NLGUI : : CEventDescriptor & event )
{
if ( CCtrlBase : : handleEvent ( event ) ) return true ;
if ( ! _Active | | _Frozen )
return false ;
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouseleftdown )
sint64 T1 = NLMISC : : CTime : : getLocalTime ( ) ;
if ( event . getType ( ) = = NLGUI : : CEventDescriptor : : mouse )
{
if ( _AHOnLeftDblClick )
{
if ( ( CCtrlBaseButton * ) _LastLeftClickButton = = this & & ( T1 - _LastLeftClickDate ) < CWidgetManager : : getInstance ( ) - > getUserDblClickDelay ( ) )
{
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftDblClick , this , _AHLeftDblClickParams ) ;
_LeftDblClickHandled = true ;
_LastLeftClickButton = NULL ;
return true ;
}
}
const NLGUI : : CEventDescriptorMouse & eventDesc = ( const NLGUI : : CEventDescriptorMouse & ) event ;
if ( _AHOnLeftLongClick ! = NULL )
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouseleftup )
{
_LeftLongClickHandled = false ;
_LeftLongClickDate = T1 ;
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = this )
return false ;
_LeftLongClickHandled = true ;
}
_LeftDblClickHandled = false ;
_LastLeftClickButton = NULL ;
return true ;
}
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouseleftup )
{
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = this )
if ( ! ( ( eventDesc . getX ( ) > = _XReal ) & &
( eventDesc . getX ( ) < ( _XReal + _WReal ) ) & &
( eventDesc . getY ( ) > _YReal ) & &
( eventDesc . getY ( ) < = ( _YReal + _HReal ) ) ) )
return false ;
if ( _LeftDblClickHandled ) // no effect on mouse up after double click has been handled
if ( eventDesc. getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouseleftdown )
{
if ( _AHOnLeftDblClick )
{
if ( ( CCtrlBaseButton * ) _LastLeftClickButton = = this & & ( T1 - _LastLeftClickDate ) < CWidgetManager : : getInstance ( ) - > getUserDblClickDelay ( ) )
{
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftDblClick , this , _AHLeftDblClickParams ) ;
_LeftDblClickHandled = true ;
_LastLeftClickButton = NULL ;
return true ;
}
}
if ( _AHOnLeftLongClick ! = NULL )
{
_LeftLongClickHandled = false ;
_LeftLongClickDate = T1 ;
}
_LeftDblClickHandled = false ;
_LastLeftClickButton = NULL ;
return true ;
}
// Do not launch 2 times action handler if we are already pushed ! except if we want.
if ( ! _ClickWhenPushed )
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouseleftup )
{
if ( ( _Type = = RadioButton ) & & _RBRef & & ( * _RBRef = = this ) )
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = this )
return false ;
if ( _LeftDblClickHandled ) // no effect on mouse up after double click has been handled
{
_LeftDblClickHandled = false ;
return true ;
}
}
if ( _Type = = RadioButton )
{
_Pushed = true ;
if ( _RBRef ) * _RBRef = this ;
}
// Do not launch 2 times action handler if we are already pushed ! except if we want.
if ( ! _ClickWhenPushed )
{
if ( ( _Type = = RadioButton ) & & _RBRef & & ( * _RBRef = = this ) )
return true ;
}
if ( _Type = = ToggleButton )
_Pushed = ! _Pushed ;
if ( _Type = = RadioButton )
{
_Pushed = true ;
if ( _RBRef ) * _RBRef = this ;
}
/*
// RunAction
if ( _AHOnLeftClick ! = NULL )
{
//nlinfo("clicked on %s", _Id.c_str());
pIM - > submitEvent ( " button_click: " + getId ( ) ) ; //TEMP
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftClick , this , _AHLeftClickParams ) ;
//pIM->submitEvent ("button_click:"+getId());
}
*/
runLeftClickAction ( ) ;
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) = = NULL ) return true ; // event handler may release cpature from this object (if it is removed for example)
if ( _Type = = ToggleButton )
_Pushed = ! _Pushed ;
// Run Menu
if ( ! _ListMenuLeft . empty ( ) )
CWidgetManager : : getInstance ( ) - > enableModalWindow ( this , _ListMenuLeft ) ;
/*
// RunAction
if ( _AHOnLeftClick ! = NULL )
{
//nlinfo("clicked on %s", _Id.c_str());
pIM - > submitEvent ( " button_click: " + getId ( ) ) ; //TEMP
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftClick , this , _AHLeftClickParams ) ;
//pIM->submitEvent ("button_click:"+getId());
}
*/
runLeftClickAction ( ) ;
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) = = NULL ) return true ; // event handler may release cpature from this object (if it is removed for example)
if ( _AHOnLeftDblClick ! = NULL )
{
_LastLeftClickDate = T1 ;
_LastLeftClickButton = this ;
}
// Run Menu
if ( ! _ListMenuLeft . empty ( ) )
CWidgetManager : : getInstance ( ) - > enableModalWindow ( this , _ListMenuLeft ) ;
// Always return true on LeftClick.
return true ;
}
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouserightdown )
{
_LastLeftClickButton = NULL ;
return true ;
}
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouserightup )
{
_LastLeftClickButton = NULL ;
bool handled = false ;
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerRight ( ) ! = this )
return false ;
if ( _AHOnLeftDblClick ! = NULL )
{
_LastLeftClickDate = T1 ;
_LastLeftClickButton = this ;
}
// RunAction
if ( _AHOnRightClick ! = NULL )
// Always return true on LeftClick.
return true ;
}
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouserightdown )
{
handled = true ;
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnRightClick , this , _AHRightClickParams ) ;
_LastLeftClickButton = NULL ;
return true ;
}
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerRight ( ) = = NULL ) return true ; // if this become NULL, this ctrl has been deleted
// Run Menu
if ( ! _ListMenuRight . empty ( ) )
if ( eventDesc . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorMouse : : mouserightup )
{
handled = true ;
CWidgetManager : : getInstance ( ) - > enableModalWindow ( this , _ListMenuRight ) ;
_LastLeftClickButton = NULL ;
bool handled = false ;
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerRight ( ) ! = this )
return false ;
// RunAction
if ( _AHOnRightClick ! = NULL )
{
handled = true ;
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnRightClick , this , _AHRightClickParams ) ;
}
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerRight ( ) = = NULL ) return true ; // if this become NULL, this ctrl has been deleted
// Run Menu
if ( ! _ListMenuRight . empty ( ) )
{
handled = true ;
CWidgetManager : : getInstance ( ) - > enableModalWindow ( this , _ListMenuRight ) ;
}
// If not handled here, ret to parent
return handled ;
}
// If not handled here, ret to parent
return handled ;
}
}
else if ( event . getType ( ) = = NLGUI : : CEventDescriptor : : system )
{
const NLGUI : : CEventDescriptorSystem & systemEvent = ( const NLGUI : : CEventDescriptorSystem & ) event ;
if ( systemEvent . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorSystem : : clocktick )
}
else if ( event . getType ( ) = = NLGUI : : CEventDescriptor : : system )
{
if ( _AHOnClockTick ! = NULL )
const NLGUI : : CEventDescriptorSystem & systemEvent = ( const NLGUI : : CEventDescriptorSystem & ) event ;
if ( systemEvent . getEventTypeExtended ( ) = = NLGUI : : CEventDescriptorSystem : : clocktick )
{
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnClockTick , this , _AHClockTickParams ) ;
}
if ( _AHOnClockTick ! = NULL )
{
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnClockTick , this , _AHClockTickParams ) ;
}
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) = = this )
{
if ( ! _LeftLongClickHandled )
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) = = this )
{
uint nVal = 50 ;
CCDBNodeLeaf * pNL = NLGUI : : CDBManager : : getInstance ( ) - > getDbProp ( " UI:SAVE:KEY_REPEAT_SPEED " ) ;
if ( pNL ! = NULL )
nVal = pNL - > getValue32 ( ) ;
uint repeatDelay = ( uint ) ( KEY_REPEAT_MIN + ( KEY_REPEAT_MAX - KEY_REPEAT_MIN ) * ( float ) nVal / 100.0f ) ;
if ( ( T1 - _LeftLongClickDate ) > repeatDelay )
if ( ! _LeftLongClickHandled )
{
_LeftLongClickHandled = true ;
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftLongClick , this , _AHLeftLongClickParams ) ;
uint nVal = 50 ;
CCDBNodeLeaf * pNL = NLGUI : : CDBManager : : getInstance ( ) - > getDbProp ( " UI:SAVE:KEY_REPEAT_SPEED " ) ;
if ( pNL ! = NULL )
nVal = pNL - > getValue32 ( ) ;
uint repeatDelay = ( uint ) ( KEY_REPEAT_MIN + ( KEY_REPEAT_MAX - KEY_REPEAT_MIN ) * ( float ) nVal / 100.0f ) ;
if ( ( T1 - _LeftLongClickDate ) > repeatDelay )
{
_LeftLongClickHandled = true ;
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftLongClick , this , _AHLeftLongClickParams ) ;
}
}
}
}
}
return false ;
}
return false ;
}
// ***************************************************************************
void CCtrlBaseButton : : initRBRef ( )
{
if ( _RBRef ! = NULL ) return ;
nlassert ( _Parent ) ;
const vector < CCtrlBase * > & vCB = _Parent - > getControls ( ) ;
uint i = 0 ;
for ( i = 0 ; i < vCB . size ( ) ; + + i )
// ***************************************************************************
void CCtrlBaseButton : : initRBRef ( )
{
CCtrlBaseButton * pBut = dynamic_cast < CCtrlBaseButton * > ( vCB [ i ] ) ;
if ( pBut & & pBut - > _Type = = RadioButton )
if ( _RBRef ! = NULL ) return ;
nlassert ( _Parent ) ;
const vector < CCtrlBase * > & vCB = _Parent - > getControls ( ) ;
uint i = 0 ;
for ( i = 0 ; i < vCB . size ( ) ; + + i )
{
_RBRef = & pBut - > _RBRefBut ;
break ;
CCtrlBaseButton * pBut = dynamic_cast < CCtrlBaseButton * > ( vCB [ i ] ) ;
if ( pBut & & pBut - > _Type = = RadioButton )
{
_RBRef = & pBut - > _RBRefBut ;
break ;
}
}
// If we are the first radio button of the group and not added
if ( i = = vCB . size ( ) )
_RBRef = & this - > _RBRefBut ;
}
// If we are the first radio button of the group and not added
if ( i = = vCB . size ( ) )
_RBRef = & this - > _RBRefBut ;
}
// ***************************************************************************
void CCtrlBaseButton : : initRBRefFromRadioButton ( CCtrlBaseButton * pBut )
{
if ( pBut & & pBut - > _Type = = RadioButton )
// ***************************************************************************
void CCtrlBaseButton : : initRBRefFromRadioButton ( CCtrlBaseButton * pBut )
{
_RBRef = & ( pBut - > _RBRefBut ) ;
_RBRefBut = NULL ;
if ( pBut & & pBut - > _Type = = RadioButton )
{
_RBRef = & ( pBut - > _RBRefBut ) ;
_RBRefBut = NULL ;
}
}
}
// ***************************************************************************
void CCtrlBaseButton : : setPushed ( bool state )
{
_Pushed = state ;
if ( _Type = = RadioButton & & _RBRef )
// ***************************************************************************
void CCtrlBaseButton : : setPushed ( bool state )
{
if ( state = = true )
{
* _RBRef = this ;
}
else
_Pushed = state ;
if ( _Type = = RadioButton & & _RBRef )
{
if ( * _RBRef = = this ) // I have to be pushed to unpush me
* _RBRef = NULL ; // After that : All radio buttons are NOT pushed
if ( state = = true )
{
* _RBRef = this ;
}
else
{
if ( * _RBRef = = this ) // I have to be pushed to unpush me
* _RBRef = NULL ; // After that : All radio buttons are NOT pushed
}
}
}
}
// ***************************************************************************
void CCtrlBaseButton : : setFrozen ( bool state )
{
_Frozen = state ;
if ( _Frozen )
// ***************************************************************************
void CCtrlBaseButton : : setFrozen ( bool state )
{
_Pushed = false ;
_Over = false ;
_Frozen = state ;
if ( _Frozen )
{
_Pushed = false ;
_Over = false ;
}
}
}
// ***************************************************************************
void CCtrlBaseButton : : setFrozenHalfTone ( bool enabled )
{
_FrozenHalfTone = enabled ;
}
// ***************************************************************************
void CCtrlBaseButton : : unselect ( )
{
if ( _Type = = RadioButton )
// ***************************************************************************
void CCtrlBaseButton : : setFrozenHalfTone ( bool enabled )
{
if ( _RBRef ) * _RBRef = NULL ;
_FrozenHalfTone = enabled ;
}
}
// ***************************************************************************
void CCtrlBaseButton : : updateOver ( bool & lastOver )
{
if ( ! CWidgetManager : : getInstance ( ) - > isMouseHandlingEnabled ( ) )
// ***************************************************************************
void CCtrlBaseButton : : unselect ( )
{
_Over = false ;
return ;
if ( _Type = = RadioButton )
{
if ( _RBRef ) * _RBRef = NULL ;
}
}
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = NULL )
// ***************************************************************************
void CCtrlBaseButton : : updateOver ( bool & lastOver )
{
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = this )
if ( ! CWidgetManager : : getInstance ( ) - > isMouseHandlingEnabled( ) )
{
_Over = false ;
return ;
}
return ;
}
const vector < CCtrlBase * > & rVB = CWidgetManager : : getInstance ( ) - > getCtrlsUnderPointer ( ) ;
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = NULL )
{
if ( CWidgetManager : : getInstance ( ) - > getCapturePointerLeft ( ) ! = this )
{
_Over = false ;
}
return ;
}
if ( ! _Frozen )
{
uint32 i ;
lastOver = _Over ;
// show over if it is the last control that has the same father
CCtrlBase * candidate = NULL ;
for ( i = 0 ; i < rVB . size ( ) ; + + i )
const vector < CCtrlBase * > & rVB = CWidgetManager : : getInstance ( ) - > getCtrlsUnderPointer ( ) ;
if ( ! _Frozen )
{
if ( rVB [ i ] - > getParent ( ) = = this - > getParent ( ) )
uint32 i ;
lastOver = _Over ;
// show over if it is the last control that has the same father
CCtrlBase * candidate = NULL ;
for ( i = 0 ; i < rVB . size ( ) ; + + i )
{
candidate = rVB [ i ] ;
if ( rVB [ i ] - > getParent ( ) = = this - > getParent ( ) )
{
candidate = rVB [ i ] ;
}
}
_Over = ( candidate = = this ) ;
}
_Over = ( candidate = = this ) ;
}
else
_Over = false ;
else
_Over = false ;
}
}
// ***************************************************************************
void CCtrlBaseButton : : elementCaptured ( CCtrlBase * capturedElement )
{
// if not me, then reset my '_Over'
if ( capturedElement ! = this )
// ***************************************************************************
void CCtrlBaseButton : : elementCaptured ( CCtrlBase * capturedElement )
{
_Over = false ;
// if not me, then reset my '_Over'
if ( capturedElement ! = this )
{
_Over = false ;
}
}
}
// ***************************************************************************
void CCtrlBaseButton : : runLeftClickAction ( )
{
if ( _AHOnLeftClick ! = NULL )
// ***************************************************************************
void CCtrlBaseButton : : runLeftClickAction ( )
{
if ( _AHOnLeftClick ! = NULL )
{
//nlinfo("clicked on %s", _Id.c_str());
CAHManager : : getInstance ( ) - > submitEvent ( " button_click: " + getId ( ) ) ;
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftClick , this , _AHLeftClickParams ) ;
//pIM->submitEvent ("button_click:"+getId());
//nlinfo("clicked on %s", _Id.c_str());
CAHManager : : getInstance ( ) - > submitEvent ( " button_click: " + getId ( ) ) ;
CAHManager : : getInstance ( ) - > runActionHandler ( _AHOnLeftClick , this , _AHLeftClickParams ) ;
//pIM->submitEvent ("button_click:"+getId());
}
}
}
// ***************************************************************************
int CCtrlBaseButton : : luaRunLeftClickAction ( CLuaState & ls )
{
const char * funcName = " onLeftClick " ;
CLuaIHM : : checkArgCount ( ls , funcName , 0 ) ;
// ***************************************************************************
int CCtrlBaseButton : : luaRunLeftClickAction ( CLuaState & ls )
{
const char * funcName = " onLeftClick " ;
CLuaIHM : : checkArgCount ( ls , funcName , 0 ) ;
runLeftClickAction ( ) ;
runLeftClickAction ( ) ;
return 0 ;
}
return 0 ;
}