2022-12-04 11:56:12 -08:00
/* Copyright (C) 2022 Wildfire Games.
2023-07-27 13:54:46 -07:00
* This file is part of 0 A . D .
2009-04-18 10:00:33 -07:00
*
2023-07-27 13:54:46 -07:00
* 0 A . D . is free software : you can redistribute it and / or modify
2009-04-18 10:00:33 -07:00
* 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 .
*
2023-07-27 13:54:46 -07:00
* 0 A . D . is distributed in the hope that it will be useful ,
2009-04-18 10:00:33 -07:00
* 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
2023-07-27 13:54:46 -07:00
* along with 0 A . D . If not , see < http : //www.gnu.org/licenses/>.
2009-04-18 10:00:33 -07:00
*/
2004-06-03 11:38:14 -07:00
# include "precompiled.h"
2015-08-21 10:08:41 -07:00
2019-09-30 01:19:56 -07:00
# include "IGUIObject.h"
2019-09-22 16:28:25 -07:00
2019-09-18 13:51:45 -07:00
# include "gui/CGUI.h"
2019-08-29 02:07:29 -07:00
# include "gui/CGUISetting.h"
2021-05-12 06:48:55 -07:00
# include "gui/ObjectBases/IGUIObject.h"
2020-11-21 09:49:06 -08:00
# include "gui/Scripting/JSInterface_GUIProxy.h"
2020-05-10 07:01:00 -07:00
# include "js/Conversions.h"
2009-09-27 08:04:46 -07:00
# include "ps/CLogger.h"
2016-06-21 03:33:11 -07:00
# include "ps/Profile.h"
2021-05-13 10:23:52 -07:00
# include "scriptinterface/Object.h"
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
# include "scriptinterface/ScriptContext.h"
2020-11-30 01:03:20 -08:00
# include "scriptinterface/ScriptExtraHeaders.h"
2021-05-14 03:18:03 -07:00
# include "scriptinterface/ScriptConversions.h"
2019-08-22 15:34:12 -07:00
# include "soundmanager/ISoundManager.h"
2009-09-27 08:04:46 -07:00
2021-01-18 04:16:27 -08:00
# include <algorithm>
2022-12-04 11:56:12 -08:00
# include <string_view>
2021-01-17 07:44:14 -08:00
# include <unordered_map>
2020-01-15 08:00:37 -08:00
const CStr IGUIObject : : EventNameMouseEnter = " MouseEnter " ;
const CStr IGUIObject : : EventNameMouseMove = " MouseMove " ;
const CStr IGUIObject : : EventNameMouseLeave = " MouseLeave " ;
2019-08-21 03:12:33 -07:00
IGUIObject : : IGUIObject ( CGUI & pGUI )
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
: m_pGUI ( pGUI ) ,
m_pParent ( ) ,
m_MouseHovering ( ) ,
m_LastClickTime ( ) ,
2021-05-06 01:22:37 -07:00
m_Enabled ( this , " enabled " , true ) ,
m_Hidden ( this , " hidden " , false ) ,
m_Size ( this , " size " ) ,
m_Style ( this , " style " ) ,
m_Hotkey ( this , " hotkey " ) ,
m_Z ( this , " z " ) ,
m_Absolute ( this , " absolute " , true ) ,
m_Ghost ( this , " ghost " , false ) ,
m_AspectRatio ( this , " aspectratio " ) ,
m_Tooltip ( this , " tooltip " ) ,
m_TooltipStyle ( this , " tooltip_style " )
{
2003-11-23 18:18:41 -08:00
}
IGUIObject : : ~ IGUIObject ( )
{
2019-08-01 13:20:24 -07:00
if ( ! m_ScriptHandlers . empty ( ) )
2021-05-14 04:12:07 -07:00
JS_RemoveExtraGCRootsTracer ( ScriptRequest ( m_pGUI . GetScriptInterface ( ) ) . cx , Trace , this ) ;
2003-11-23 18:18:41 -08:00
2019-10-11 09:20:50 -07:00
// m_Children is deleted along all other GUI Objects in the CGUI destructor
2003-11-23 18:18:41 -08:00
}
2021-05-04 08:17:50 -07:00
void IGUIObject : : RegisterChild ( IGUIObject * child )
2003-11-23 18:18:41 -08:00
{
2021-05-04 08:17:50 -07:00
child - > SetParent ( this ) ;
m_Children . push_back ( child ) ;
}
void IGUIObject : : UnregisterChild ( IGUIObject * child )
{
std : : vector < IGUIObject * > : : iterator it = std : : find ( m_Children . begin ( ) , m_Children . end ( ) , child ) ;
if ( it ! = m_Children . end ( ) )
{
( * it ) - > m_pParent = nullptr ;
m_Children . erase ( it ) ;
}
2003-11-23 18:18:41 -08:00
}
2021-05-06 01:22:37 -07:00
void IGUIObject : : RegisterSetting ( const CStr & Name , IGUISetting * setting )
2003-11-23 18:18:41 -08:00
{
2019-08-03 19:20:08 -07:00
if ( SettingExists ( Name ) )
2019-09-22 15:49:20 -07:00
LOGERROR ( " The setting '%s' already exists on the object '%s'! " , Name . c_str ( ) , GetPresentableName ( ) . c_str ( ) ) ;
else
2021-05-06 01:22:37 -07:00
m_Settings . emplace ( Name , setting ) ;
2019-08-26 05:25:07 -07:00
}
2021-05-06 01:22:37 -07:00
void IGUIObject : : ReregisterSetting ( const CStr & Name , IGUISetting * setting )
2019-08-26 05:25:07 -07:00
{
2021-05-06 01:22:37 -07:00
if ( ! SettingExists ( Name ) )
LOGERROR ( " The setting '%s' must already exist on the object '%s'! " , Name . c_str ( ) , GetPresentableName ( ) . c_str ( ) ) ;
else
m_Settings . at ( Name ) = setting ;
2019-08-26 05:25:07 -07:00
}
2021-05-06 01:22:37 -07:00
bool IGUIObject : : SettingExists ( const CStr & Setting ) const
2019-08-26 05:25:07 -07:00
{
2021-05-06 01:22:37 -07:00
return m_Settings . find ( Setting ) ! = m_Settings . end ( ) ;
2019-08-26 05:25:07 -07:00
}
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
bool IGUIObject : : SetSettingFromString ( const CStr & Setting , const CStrW & Value , const bool SendMessage )
{
2019-09-16 09:13:25 -07:00
const std : : map < CStr , IGUISetting * > : : iterator it = m_Settings . find ( Setting ) ;
if ( it = = m_Settings . end ( ) )
{
LOGERROR ( " GUI object '%s' has no property called '%s', can't set parse and set value '%s' " , GetPresentableName ( ) . c_str ( ) , Setting . c_str ( ) , Value . ToUTF8 ( ) . c_str ( ) ) ;
return false ;
}
return it - > second - > FromString ( Value , SendMessage ) ;
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
}
void IGUIObject : : SettingChanged ( const CStr & Setting , const bool SendMessage )
{
if ( Setting = = " size " )
{
// If setting was "size", we need to re-cache itself and all children
RecurseObject ( nullptr , & IGUIObject : : UpdateCachedSize ) ;
}
else if ( Setting = = " hidden " )
{
// Hiding an object requires us to reset it and all children
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
if ( m_Hidden )
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
RecurseObject ( nullptr , & IGUIObject : : ResetStates ) ;
}
2020-11-26 18:30:42 -08:00
else if ( Setting = = " style " )
2021-05-06 01:22:37 -07:00
m_pGUI . SetObjectStyle ( this , m_Style ) ;
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
if ( SendMessage )
{
SGUIMessage msg ( GUIM_SETTINGS_UPDATED , Setting ) ;
HandleMessage ( msg ) ;
}
}
2019-08-22 16:51:10 -07:00
bool IGUIObject : : IsMouseOver ( ) const
2003-11-23 18:18:41 -08:00
{
2019-08-21 03:12:33 -07:00
return m_CachedActualSize . PointInside ( m_pGUI . GetMousePos ( ) ) ;
2003-11-23 18:18:41 -08:00
}
2015-08-21 10:08:41 -07:00
void IGUIObject : : UpdateMouseOver ( IGUIObject * const & pMouseOver )
2003-11-23 18:18:41 -08:00
{
if ( pMouseOver = = this )
{
if ( ! m_MouseHovering )
2020-01-15 08:00:37 -08:00
SendMouseEvent ( GUIM_MOUSE_ENTER , EventNameMouseEnter ) ;
2003-11-23 18:18:41 -08:00
m_MouseHovering = true ;
2020-01-15 08:00:37 -08:00
SendMouseEvent ( GUIM_MOUSE_OVER , EventNameMouseMove ) ;
2003-11-23 18:18:41 -08:00
}
2016-06-07 05:02:33 -07:00
else
2003-11-23 18:18:41 -08:00
{
if ( m_MouseHovering )
{
m_MouseHovering = false ;
2020-01-15 08:00:37 -08:00
SendMouseEvent ( GUIM_MOUSE_LEAVE , EventNameMouseLeave ) ;
2003-11-23 18:18:41 -08:00
}
}
}
2015-08-21 10:08:41 -07:00
void IGUIObject : : ChooseMouseOverAndClosest ( IGUIObject * & pObject )
2003-11-23 18:18:41 -08:00
{
2019-08-22 16:51:10 -07:00
if ( ! IsMouseOver ( ) )
2015-08-21 10:08:41 -07:00
return ;
// Check if we've got competition at all
2019-09-22 16:28:25 -07:00
if ( pObject = = nullptr )
2003-11-23 18:18:41 -08:00
{
2015-08-21 10:08:41 -07:00
pObject = this ;
return ;
}
2003-11-23 18:18:41 -08:00
2015-08-21 10:08:41 -07:00
// Or if it's closer
if ( GetBufferedZ ( ) > = pObject - > GetBufferedZ ( ) )
{
pObject = this ;
return ;
2003-11-23 18:18:41 -08:00
}
}
2015-08-21 10:08:41 -07:00
IGUIObject * IGUIObject : : GetParent ( ) const
2003-11-23 18:18:41 -08:00
{
// Important, we're not using GetParent() for these
// checks, that could screw it up
2019-09-22 16:28:25 -07:00
if ( m_pParent & & m_pParent - > m_pParent = = nullptr )
return nullptr ;
2003-11-23 18:18:41 -08:00
return m_pParent ;
}
2019-07-27 19:39:52 -07:00
void IGUIObject : : ResetStates ( )
{
// Notify the gui that we aren't hovered anymore
UpdateMouseOver ( nullptr ) ;
}
2003-11-24 09:13:37 -08:00
void IGUIObject : : UpdateCachedSize ( )
{
2003-11-24 18:47:12 -08:00
// If absolute="false" and the object has got a parent,
// use its cached size instead of the screen. Notice
// it must have just been cached for it to work.
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
if ( ! m_Absolute & & m_pParent & & ! IsRootObject ( ) )
2021-05-06 01:22:37 -07:00
m_CachedActualSize = m_Size - > GetSize ( m_pParent - > m_CachedActualSize ) ;
2003-11-24 18:47:12 -08:00
else
2021-05-26 11:52:22 -07:00
m_CachedActualSize = m_Size - > GetSize ( CRect ( m_pGUI . GetWindowSize ( ) ) ) ;
2004-05-28 21:06:50 -07:00
2010-08-10 15:39:00 -07:00
// In a few cases, GUI objects have to resize to fill the screen
// but maintain a constant aspect ratio.
// Adjust the size to be the max possible, centered in the original size:
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
if ( m_AspectRatio )
2010-08-10 15:39:00 -07:00
{
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
if ( m_CachedActualSize . GetWidth ( ) > m_CachedActualSize . GetHeight ( ) * m_AspectRatio )
2010-08-10 15:39:00 -07:00
{
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
float delta = m_CachedActualSize . GetWidth ( ) - m_CachedActualSize . GetHeight ( ) * m_AspectRatio ;
2010-08-10 15:39:00 -07:00
m_CachedActualSize . left + = delta / 2.f ;
m_CachedActualSize . right - = delta / 2.f ;
}
else
{
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
float delta = m_CachedActualSize . GetHeight ( ) - m_CachedActualSize . GetWidth ( ) / m_AspectRatio ;
2010-08-10 15:39:00 -07:00
m_CachedActualSize . bottom - = delta / 2.f ;
m_CachedActualSize . top + = delta / 2.f ;
}
}
2003-11-24 09:13:37 -08:00
}
2021-04-09 11:01:47 -07:00
CRect IGUIObject : : GetComputedSize ( )
{
UpdateCachedSize ( ) ;
return m_CachedActualSize ;
}
2020-11-26 18:30:42 -08:00
bool IGUIObject : : ApplyStyle ( const CStr & StyleName )
2003-12-26 22:26:03 -08:00
{
2019-08-27 09:03:24 -07:00
if ( ! m_pGUI . HasStyle ( StyleName ) )
2020-11-26 18:30:42 -08:00
{
LOGERROR ( " IGUIObject: Trying to use style '%s' that doesn't exist. " , StyleName . c_str ( ) ) ;
return false ;
}
2004-12-13 04:07:12 -08:00
2019-08-27 09:03:24 -07:00
// The default style may specify settings for any GUI object.
// Other styles are reported if they specify a Setting that does not exist,
// so that the XML author is informed and can correct the style.
2004-12-13 04:07:12 -08:00
2020-12-31 06:27:02 -08:00
for ( const std : : pair < const CStr , CStrW > & p : m_pGUI . GetStyle ( StyleName ) . m_SettingsDefaults )
2019-08-27 09:03:24 -07:00
{
if ( SettingExists ( p . first ) )
2021-05-06 01:22:37 -07:00
m_Settings . at ( p . first ) - > FromString ( p . second , true ) ;
2019-08-27 09:03:24 -07:00
else if ( StyleName ! = " default " )
LOGWARNING ( " GUI object has no setting \" %s \" , but the style \" %s \" defines it " , p . first , StyleName . c_str ( ) ) ;
2003-12-26 22:26:03 -08:00
}
2020-11-26 18:30:42 -08:00
return true ;
2003-12-26 22:26:03 -08:00
}
float IGUIObject : : GetBufferedZ ( ) const
{
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
if ( m_Absolute )
return m_Z ;
2004-05-28 21:06:50 -07:00
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
if ( GetParent ( ) )
return GetParent ( ) - > GetBufferedZ ( ) + m_Z ;
2019-08-23 07:43:10 -07:00
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
// In philosophy, a parentless object shouldn't be able to have a relative sizing,
// but we'll accept it so that absolute can be used as default without a complaint.
// Also, you could consider those objects children to the screen resolution.
return m_Z ;
2003-12-26 22:26:03 -08:00
}
2020-01-15 08:00:37 -08:00
void IGUIObject : : RegisterScriptHandler ( const CStr & eventName , const CStr & Code , CGUI & pGUI )
2004-07-08 08:23:47 -07:00
{
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
ScriptRequest rq ( pGUI . GetScriptInterface ( ) ) ;
2015-08-21 10:08:41 -07:00
2004-07-08 08:23:47 -07:00
const int paramCount = 1 ;
const char * paramNames [ paramCount ] = { " mouse " } ;
2004-07-11 11:18:54 -07:00
// Location to report errors from
2020-01-15 08:00:37 -08:00
CStr CodeName = GetName ( ) + " " + eventName ;
2004-07-11 11:18:54 -07:00
2004-12-21 10:41:58 -08:00
// Generate a unique name
2015-08-21 10:08:41 -07:00
static int x = 0 ;
2004-12-21 10:41:58 -08:00
char buf [ 64 ] ;
2020-01-15 08:00:37 -08:00
sprintf_s ( buf , ARRAY_SIZE ( buf ) , " __eventhandler%d (%s) " , x + + , eventName . c_str ( ) ) ;
2004-12-21 10:41:58 -08:00
2020-11-30 01:03:20 -08:00
// TODO: this is essentially the same code as ScriptInterface::LoadScript (with a tweak for the argument).
2020-11-13 05:18:22 -08:00
JS : : CompileOptions options ( rq . cx ) ;
2015-01-24 06:46:52 -08:00
options . setFileAndLine ( CodeName . c_str ( ) , 0 ) ;
2019-08-08 02:05:42 -07:00
options . setIsRunOnce ( false ) ;
2015-01-24 06:46:52 -08:00
2020-11-30 01:03:20 -08:00
JS : : SourceText < mozilla : : Utf8Unit > src ;
ENSURE ( src . init ( rq . cx , Code . c_str ( ) , Code . length ( ) , JS : : SourceOwnership : : Borrowed ) ) ;
JS : : RootedObjectVector emptyScopeChain ( rq . cx ) ;
JS : : RootedFunction func ( rq . cx , JS : : CompileFunction ( rq . cx , emptyScopeChain , options , buf , paramCount , paramNames , src ) ) ;
if ( func = = nullptr )
2016-09-02 09:34:02 -07:00
{
2020-01-15 08:00:37 -08:00
LOGERROR ( " RegisterScriptHandler: Failed to compile the script for %s " , eventName . c_str ( ) ) ;
2016-09-02 09:34:02 -07:00
return ;
}
2015-08-21 10:08:41 -07:00
2020-11-13 05:18:22 -08:00
JS : : RootedObject funcObj ( rq . cx , JS_GetFunctionObject ( func ) ) ;
2020-01-15 08:00:37 -08:00
SetScriptHandler ( eventName , funcObj ) ;
2005-03-30 14:33:10 -08:00
}
2004-12-21 10:41:58 -08:00
2020-01-15 08:00:37 -08:00
void IGUIObject : : SetScriptHandler ( const CStr & eventName , JS : : HandleObject Function )
2005-03-30 14:33:10 -08:00
{
2019-08-01 13:20:24 -07:00
if ( m_ScriptHandlers . empty ( ) )
2021-05-14 04:12:07 -07:00
JS_AddExtraGCRootsTracer ( ScriptRequest ( m_pGUI . GetScriptInterface ( ) ) . cx , Trace , this ) ;
2019-08-01 13:20:24 -07:00
2020-01-15 08:00:37 -08:00
m_ScriptHandlers [ eventName ] = JS : : Heap < JSObject * > ( Function ) ;
2020-11-14 13:54:17 -08:00
2021-01-18 04:16:27 -08:00
if ( std : : find ( m_pGUI . m_EventObjects [ eventName ] . begin ( ) , m_pGUI . m_EventObjects [ eventName ] . end ( ) , this ) = = m_pGUI . m_EventObjects [ eventName ] . end ( ) )
m_pGUI . m_EventObjects [ eventName ] . emplace_back ( this ) ;
2004-07-08 08:23:47 -07:00
}
2020-01-15 08:00:37 -08:00
void IGUIObject : : UnsetScriptHandler ( const CStr & eventName )
2019-10-28 04:35:04 -07:00
{
2020-01-15 08:00:37 -08:00
std : : map < CStr , JS : : Heap < JSObject * > > : : iterator it = m_ScriptHandlers . find ( eventName ) ;
2019-10-28 04:35:04 -07:00
if ( it = = m_ScriptHandlers . end ( ) )
return ;
m_ScriptHandlers . erase ( it ) ;
if ( m_ScriptHandlers . empty ( ) )
2021-05-14 04:12:07 -07:00
JS_RemoveExtraGCRootsTracer ( ScriptRequest ( m_pGUI . GetScriptInterface ( ) ) . cx , Trace , this ) ;
2021-01-17 07:44:14 -08:00
std : : unordered_map < CStr , std : : vector < IGUIObject * > > : : iterator it2 = m_pGUI . m_EventObjects . find ( eventName ) ;
if ( it2 = = m_pGUI . m_EventObjects . end ( ) )
return ;
std : : vector < IGUIObject * > & handlers = it2 - > second ;
handlers . erase ( std : : remove ( handlers . begin ( ) , handlers . end ( ) , this ) , handlers . end ( ) ) ;
if ( handlers . empty ( ) )
m_pGUI . m_EventObjects . erase ( it2 ) ;
2019-10-28 04:35:04 -07:00
}
2020-01-15 08:00:37 -08:00
InReaction IGUIObject : : SendEvent ( EGUIMessageType type , const CStr & eventName )
2011-04-28 13:42:11 -07:00
{
2011-11-09 05:09:01 -08:00
PROFILE2_EVENT ( " gui event " ) ;
2020-01-15 08:00:37 -08:00
PROFILE2_ATTR ( " type: %s " , eventName . c_str ( ) ) ;
2011-11-09 05:09:01 -08:00
PROFILE2_ATTR ( " object: %s " , m_Name . c_str ( ) ) ;
2011-04-28 13:42:11 -07:00
SGUIMessage msg ( type ) ;
HandleMessage ( msg ) ;
2020-01-15 08:00:37 -08:00
ScriptEvent ( eventName ) ;
2011-04-28 13:42:11 -07:00
2020-01-15 08:00:37 -08:00
return msg . skipped ? IN_PASS : IN_HANDLED ;
2011-04-28 13:42:11 -07:00
}
2020-01-15 08:00:37 -08:00
InReaction IGUIObject : : SendMouseEvent ( EGUIMessageType type , const CStr & eventName )
2004-07-08 08:23:47 -07:00
{
2020-01-15 08:00:37 -08:00
PROFILE2_EVENT ( " gui mouse event " ) ;
PROFILE2_ATTR ( " type: %s " , eventName . c_str ( ) ) ;
PROFILE2_ATTR ( " object: %s " , m_Name . c_str ( ) ) ;
SGUIMessage msg ( type ) ;
HandleMessage ( msg ) ;
2004-07-08 08:23:47 -07:00
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
ScriptRequest rq ( m_pGUI . GetScriptInterface ( ) ) ;
2014-01-04 02:14:53 -08:00
2004-07-08 08:23:47 -07:00
// Set up the 'mouse' parameter
2020-11-13 05:18:22 -08:00
JS : : RootedValue mouse ( rq . cx ) ;
2019-07-22 12:35:14 -07:00
2021-03-28 14:55:13 -07:00
const CVector2D & mousePos = m_pGUI . GetMousePos ( ) ;
2019-08-10 05:51:27 -07:00
2021-05-13 10:23:52 -07:00
Script : : CreateObject (
2020-11-13 05:18:22 -08:00
rq ,
2019-07-22 12:35:14 -07:00
& mouse ,
2021-03-28 14:55:13 -07:00
" x " , mousePos . X ,
" y " , mousePos . Y ,
2019-08-21 03:12:33 -07:00
" buttons " , m_pGUI . GetMouseButtons ( ) ) ;
2020-11-30 01:03:20 -08:00
JS : : RootedValueVector paramData ( rq . cx ) ;
2020-12-15 01:03:44 -08:00
ignore_result ( paramData . append ( mouse ) ) ;
2020-01-15 08:00:37 -08:00
ScriptEvent ( eventName , paramData ) ;
return msg . skipped ? IN_PASS : IN_HANDLED ;
}
void IGUIObject : : ScriptEvent ( const CStr & eventName )
2020-05-10 07:01:00 -07:00
{
ScriptEventWithReturn ( eventName ) ;
}
bool IGUIObject : : ScriptEventWithReturn ( const CStr & eventName )
2020-01-15 08:00:37 -08:00
{
if ( m_ScriptHandlers . find ( eventName ) = = m_ScriptHandlers . end ( ) )
2020-05-10 07:01:00 -07:00
return false ;
2020-01-15 08:00:37 -08:00
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
ScriptRequest rq ( m_pGUI . GetScriptInterface ( ) ) ;
2020-11-30 01:03:20 -08:00
JS : : RootedValueVector paramData ( rq . cx ) ;
2020-05-10 07:01:00 -07:00
return ScriptEventWithReturn ( eventName , paramData ) ;
2004-07-08 08:23:47 -07:00
}
2004-08-30 19:09:58 -07:00
2020-01-15 08:00:37 -08:00
void IGUIObject : : ScriptEvent ( const CStr & eventName , const JS : : HandleValueArray & paramData )
2020-05-10 07:01:00 -07:00
{
ScriptEventWithReturn ( eventName , paramData ) ;
}
bool IGUIObject : : ScriptEventWithReturn ( const CStr & eventName , const JS : : HandleValueArray & paramData )
2010-09-11 12:49:21 -07:00
{
2020-01-15 08:00:37 -08:00
std : : map < CStr , JS : : Heap < JSObject * > > : : iterator it = m_ScriptHandlers . find ( eventName ) ;
2010-09-11 12:49:21 -07:00
if ( it = = m_ScriptHandlers . end ( ) )
2020-05-10 07:01:00 -07:00
return false ;
2010-09-11 12:49:21 -07:00
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
ScriptRequest rq ( m_pGUI . GetScriptInterface ( ) ) ;
2020-11-13 05:18:22 -08:00
JS : : RootedObject obj ( rq . cx , GetJSObject ( ) ) ;
JS : : RootedValue handlerVal ( rq . cx , JS : : ObjectValue ( * it - > second ) ) ;
JS : : RootedValue result ( rq . cx ) ;
2019-07-19 14:15:04 -07:00
2020-11-13 05:18:22 -08:00
if ( ! JS_CallFunctionValue ( rq . cx , obj , handlerVal , paramData , & result ) )
2020-05-10 07:01:00 -07:00
{
2020-06-14 03:34:49 -07:00
LOGERROR ( " Errors executing script event \" %s \" " , eventName . c_str ( ) ) ;
Improve JS Exception handling.
- Check for pending exceptions after function calls and script
executions.
- Call LOGERROR instead of JS_ReportError when there is a conversion
error in FromJSVal, since that can only be called from C++ (where JS
errors don't really make sense). Instead, C++ callers of FromJSVal
should handle the failure and, themselves, either report an error or
simply do something else.
- Wrap JS_ReportError since that makes updating it later easier.
This isn't a systematical fix since ToJSVal also ought return a boolean
for failures, and we probably should trigger errors instead of warnings
on 'implicit' conversions, rather a preparation diff.
Part of the SM52 migration, stage: SM45 compatible (actually SM52
incompatible, too).
Based on a patch by: Itms
Comments by: Vladislavbelov, Stan`
Refs #742, #4893
Differential Revision: https://code.wildfiregames.com/D3093
This was SVN commit r24187.
2020-11-15 10:29:17 -08:00
ScriptException : : CatchPending ( rq ) ;
2020-05-10 07:01:00 -07:00
return false ;
}
return JS : : ToBoolean ( result ) ;
2010-09-11 12:49:21 -07:00
}
2019-08-02 05:18:30 -07:00
JSObject * IGUIObject : : GetJSObject ( )
{
2007-06-08 15:56:01 -07:00
// Cache the object when somebody first asks for it, because otherwise
2019-08-02 05:18:30 -07:00
// we end up doing far too much object allocation.
2021-04-09 11:01:47 -07:00
if ( ! m_JSObject )
2019-08-02 05:18:30 -07:00
CreateJSObject ( ) ;
2021-04-09 11:01:47 -07:00
return m_JSObject - > Get ( ) ;
2007-06-08 15:56:01 -07:00
}
2019-09-30 07:08:14 -07:00
bool IGUIObject : : IsEnabled ( ) const
{
return m_Enabled ;
}
2019-08-22 16:51:10 -07:00
bool IGUIObject : : IsHidden ( ) const
2019-08-21 06:22:25 -07:00
{
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
return m_Hidden ;
2019-08-21 06:22:25 -07:00
}
2019-08-22 16:51:10 -07:00
bool IGUIObject : : IsHiddenOrGhost ( ) const
2019-08-21 06:22:25 -07:00
{
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
return m_Hidden | | m_Ghost ;
2019-08-21 06:22:25 -07:00
}
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
void IGUIObject : : PlaySound ( const CStrW & soundPath ) const
2019-08-22 15:34:12 -07:00
{
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
if ( g_SoundManager & & ! soundPath . empty ( ) )
2019-08-22 15:34:12 -07:00
g_SoundManager - > PlayAsUI ( soundPath . c_str ( ) , false ) ;
}
2004-08-30 19:09:58 -07:00
CStr IGUIObject : : GetPresentableName ( ) const
{
// __internal(), must be at least 13 letters to be able to be
// an internal name
2007-02-01 06:46:14 -08:00
if ( m_Name . length ( ) < = 12 )
2004-08-30 19:09:58 -07:00
return m_Name ;
2022-12-04 11:56:12 -08:00
if ( std : : string_view { m_Name } . substr ( 0 , 10 ) = = " __internal " )
2004-08-30 19:09:58 -07:00
return CStr ( " [unnamed object] " ) ;
else
return m_Name ;
2004-10-14 03:09:26 -07:00
}
void IGUIObject : : SetFocus ( )
{
2019-08-21 03:12:33 -07:00
m_pGUI . SetFocusedObject ( this ) ;
2004-10-14 03:09:26 -07:00
}
2021-04-09 11:01:47 -07:00
void IGUIObject : : ReleaseFocus ( )
{
m_pGUI . SetFocusedObject ( nullptr ) ;
}
2004-10-14 03:09:26 -07:00
bool IGUIObject : : IsFocused ( ) const
{
2019-08-21 03:12:33 -07:00
return m_pGUI . GetFocusedObject ( ) = = this ;
2004-11-07 13:30:47 -08:00
}
2005-07-20 16:49:39 -07:00
2019-09-18 13:51:45 -07:00
bool IGUIObject : : IsBaseObject ( ) const
{
2020-12-09 06:39:14 -08:00
return this = = m_pGUI . GetBaseObject ( ) ;
2019-09-18 13:51:45 -07:00
}
2005-07-20 16:49:39 -07:00
bool IGUIObject : : IsRootObject ( ) const
{
2020-12-09 06:39:14 -08:00
return m_pParent = = m_pGUI . GetBaseObject ( ) ;
2005-07-20 16:49:39 -07:00
}
2009-09-27 08:04:46 -07:00
2015-08-21 10:08:41 -07:00
void IGUIObject : : TraceMember ( JSTracer * trc )
2015-01-24 06:46:52 -08:00
{
2019-08-01 13:20:24 -07:00
// Please ensure to adapt the Tracer enabling and disabling in accordance with the GC things traced!
2016-01-12 16:42:55 -08:00
for ( std : : pair < const CStr , JS : : Heap < JSObject * > > & handler : m_ScriptHandlers )
2020-11-12 00:04:24 -08:00
JS : : TraceEdge ( trc , & handler . second , " IGUIObject::m_ScriptHandlers " ) ;
2015-01-24 06:46:52 -08:00
}