mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-05 23:09:02 +00:00
CHANGED: #1471 implemented property querying for CInterfaceElement.
This commit is contained in:
parent
14ac62dbad
commit
f245e69063
8 changed files with 235 additions and 37 deletions
|
@ -121,6 +121,7 @@ namespace NLGUI
|
|||
// help to serialize an action handler
|
||||
static void serialAH(NLMISC::IStream &f, IActionHandler *&ah);
|
||||
|
||||
static std::string stripId( const std::string &fullId );
|
||||
|
||||
/// Parse the element and initalize it
|
||||
virtual bool parse (xmlNodePtr cur, CInterfaceGroup *parentGroup);
|
||||
|
@ -288,6 +289,7 @@ namespace NLGUI
|
|||
const std::string &defVal);
|
||||
|
||||
// Parse tools
|
||||
static std::string HotSpotToString( THotSpot spot );
|
||||
static THotSpot convertHotSpot (const char *ptr); //
|
||||
static void convertHotSpotCouple (const char *ptr, THotSpot &parentPosRef, THotSpot &posRef);
|
||||
static NLMISC::CRGBA convertColor (const char *ptr);
|
||||
|
|
|
@ -160,8 +160,11 @@ namespace NLGUI
|
|||
/// Association builders : associate an element of the interface with the string ID of
|
||||
/// another element used as reference for position values
|
||||
void addParentPositionAssociation (CInterfaceElement *element, const std::string &parentID);
|
||||
std::string getParentPosAssociation( CInterfaceElement *element ) const;
|
||||
void addParentSizeAssociation (CInterfaceElement *element, const std::string &parentID);
|
||||
std::string getParentSizeAssociation( CInterfaceElement *element ) const;
|
||||
void addParentSizeMaxAssociation (CInterfaceElement *element, const std::string &parentID);
|
||||
std::string getParentSizeMaxAssociation( CInterfaceElement *element ) const;
|
||||
|
||||
/// LUA Class Association builder : associate a lua script to a group (called for each group after every document parsed)
|
||||
void addLuaClassAssociation(CInterfaceGroup *group, const std::string &luaScript);
|
||||
|
|
|
@ -45,6 +45,9 @@ namespace NLGUI
|
|||
virtual void addParentSizeAssociation( CInterfaceElement *element, const std::string &parentID ) = 0;
|
||||
virtual void addParentSizeMaxAssociation( CInterfaceElement *element, const std::string &parentID ) = 0;
|
||||
virtual void addLuaClassAssociation( CInterfaceGroup *group, const std::string &luaScript ) = 0;
|
||||
virtual std::string getParentPosAssociation( CInterfaceElement *element ) const = 0;
|
||||
virtual std::string getParentSizeAssociation( CInterfaceElement *element ) const = 0;
|
||||
virtual std::string getParentSizeMaxAssociation( CInterfaceElement *element ) const = 0;
|
||||
virtual CInterfaceGroup* createGroupInstance( const std::string &templateName, const std::string &parentID, const std::pair< std::string, std::string > *templateParams, uint numParams, bool updateLinks = true ) = 0;
|
||||
virtual CInterfaceGroup* createGroupInstance( const std::string &templateName, const std::string &parentID, std::vector< std::pair< std::string, std::string > > &templateParams, bool updateLinks = true ) = 0;
|
||||
virtual bool parseGroupChildren( xmlNodePtr cur, CInterfaceGroup * parentGroup, bool reload ) = 0;
|
||||
|
|
|
@ -73,6 +73,15 @@ namespace NLGUI
|
|||
return _Id;
|
||||
}
|
||||
|
||||
std::string CInterfaceElement::stripId( const std::string &fullId )
|
||||
{
|
||||
std::string id = fullId;
|
||||
std::string::size_type i = id.find_last_of( ':' );
|
||||
if( i != std::string::npos )
|
||||
id = id.substr( i + 1, id.size() - 1 );
|
||||
return id;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool CInterfaceElement::parse(xmlNodePtr cur, CInterfaceGroup * parentGroup)
|
||||
{
|
||||
|
@ -186,35 +195,6 @@ namespace NLGUI
|
|||
if (ptr)
|
||||
{
|
||||
parseSizeRef(ptr.getDatas());
|
||||
sint32 nWhat = 0;
|
||||
const char *seekPtr = ptr.getDatas();
|
||||
while (*seekPtr != 0)
|
||||
{
|
||||
if ((*seekPtr=='w')||(*seekPtr=='W'))
|
||||
{
|
||||
_SizeRef |= 1;
|
||||
nWhat = 1;
|
||||
}
|
||||
|
||||
if ((*seekPtr=='h')||(*seekPtr=='H'))
|
||||
{
|
||||
_SizeRef |= 2;
|
||||
nWhat = 2;
|
||||
}
|
||||
|
||||
if ((*seekPtr>='1')&&(*seekPtr<='9'))
|
||||
{
|
||||
if (nWhat != 0)
|
||||
{
|
||||
if (nWhat == 1)
|
||||
_SizeDivW = *seekPtr-'0';
|
||||
if (nWhat == 2)
|
||||
_SizeDivH = *seekPtr-'0';
|
||||
}
|
||||
}
|
||||
|
||||
++seekPtr;
|
||||
}
|
||||
}
|
||||
|
||||
// snapSize();
|
||||
|
@ -249,6 +229,64 @@ namespace NLGUI
|
|||
else
|
||||
return "false";
|
||||
}
|
||||
else
|
||||
if( name == "x" )
|
||||
{
|
||||
return NLMISC::toString( getX() );
|
||||
}
|
||||
else
|
||||
if( name == "y" )
|
||||
{
|
||||
return NLMISC::toString( getY() );
|
||||
}
|
||||
else
|
||||
if( name == "w" )
|
||||
{
|
||||
return NLMISC::toString( getW() );
|
||||
}
|
||||
else
|
||||
if( name == "h" )
|
||||
{
|
||||
return NLMISC::toString( getH() );
|
||||
}
|
||||
else
|
||||
if( name == "posref" )
|
||||
{
|
||||
std::string posref;
|
||||
posref = HotSpotToString( getParentPosRef() );
|
||||
posref += " ";
|
||||
posref += HotSpotToString( getPosRef() );
|
||||
return posref;
|
||||
}
|
||||
else
|
||||
if( name == "sizeref" )
|
||||
{
|
||||
return getSizeRefAsString();
|
||||
}
|
||||
if( name == "posparent" )
|
||||
{
|
||||
return CWidgetManager::getInstance()->getParser()->getParentPosAssociation( (CInterfaceElement*)this );
|
||||
}
|
||||
else
|
||||
if( name == "sizeparent" )
|
||||
{
|
||||
return CWidgetManager::getInstance()->getParser()->getParentSizeAssociation( (CInterfaceElement*)this );
|
||||
}
|
||||
else
|
||||
if( name == "global_color" )
|
||||
{
|
||||
return toString( _ModulateGlobalColor );
|
||||
}
|
||||
else
|
||||
if( name == "render_layer" )
|
||||
{
|
||||
return toString( _RenderLayer );
|
||||
}
|
||||
else
|
||||
if( name == "avoid_resize_parent" )
|
||||
{
|
||||
return toString( _AvoidResizeParent );
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
@ -263,7 +301,22 @@ namespace NLGUI
|
|||
// ------------------------------------------------------------------------------------------------
|
||||
std::string CInterfaceElement::getSizeRefAsString() const
|
||||
{
|
||||
return "IMPLEMENT ME!";
|
||||
std::string s;
|
||||
if( ( _SizeRef & 1 ) != 0 )
|
||||
{
|
||||
s += "w";
|
||||
if( _SizeDivW < 10 )
|
||||
s += toString( _SizeDivW );
|
||||
}
|
||||
|
||||
if( ( _SizeRef & 2 ) != 0 )
|
||||
{
|
||||
s += "h";
|
||||
if( _SizeDivH < 10 )
|
||||
s += toString( _SizeDivH );
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -704,6 +757,49 @@ namespace NLGUI
|
|||
}
|
||||
}
|
||||
|
||||
std::string CInterfaceElement::HotSpotToString( THotSpot spot )
|
||||
{
|
||||
switch( spot )
|
||||
{
|
||||
case Hotspot_TL:
|
||||
return "TL";
|
||||
break;
|
||||
|
||||
case Hotspot_TM:
|
||||
return "TM";
|
||||
break;
|
||||
|
||||
case Hotspot_TR:
|
||||
return "TR";
|
||||
break;
|
||||
|
||||
case Hotspot_ML:
|
||||
return "ML";
|
||||
break;
|
||||
|
||||
case Hotspot_MM:
|
||||
return "MM";
|
||||
break;
|
||||
|
||||
case Hotspot_MR:
|
||||
return "MR";
|
||||
break;
|
||||
|
||||
case Hotspot_BL:
|
||||
return "BL";
|
||||
break;
|
||||
|
||||
case Hotspot_BM:
|
||||
return "BM";
|
||||
break;
|
||||
|
||||
case Hotspot_BR:
|
||||
return "BR";
|
||||
break;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
THotSpot CInterfaceElement::convertHotSpot (const char *ptr)
|
||||
|
|
|
@ -1969,18 +1969,48 @@ namespace NLGUI
|
|||
_ParentPositionsMap.insert (std::map<CInterfaceElement*,std::string>::value_type(element, parent));
|
||||
}
|
||||
|
||||
std::string CInterfaceParser::getParentPosAssociation( CInterfaceElement *element ) const
|
||||
{
|
||||
std::map< CInterfaceElement*, std::string >::const_iterator itr =
|
||||
_ParentPositionsMap.find( element );
|
||||
if( itr == _ParentPositionsMap.end() )
|
||||
return "parent";
|
||||
else
|
||||
return CInterfaceElement::stripId( itr->second );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void CInterfaceParser::addParentSizeAssociation(CInterfaceElement* element, const std::string& parent)
|
||||
{
|
||||
_ParentSizesMap.insert (std::map<CInterfaceElement*,std::string>::value_type(element, parent));
|
||||
}
|
||||
|
||||
std::string CInterfaceParser::getParentSizeAssociation( CInterfaceElement *element ) const
|
||||
{
|
||||
std::map< CInterfaceElement*, std::string >::const_iterator itr =
|
||||
_ParentSizesMap.find( element );
|
||||
if( itr == _ParentSizesMap.end() )
|
||||
return "parent";
|
||||
else
|
||||
return CInterfaceElement::stripId( itr->second );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void CInterfaceParser::addParentSizeMaxAssociation (CInterfaceElement *element, const std::string &parent)
|
||||
{
|
||||
_ParentSizesMaxMap.insert (std::map<CInterfaceElement*,std::string>::value_type(element, parent));
|
||||
}
|
||||
|
||||
std::string CInterfaceParser::getParentSizeMaxAssociation( CInterfaceElement *element ) const
|
||||
{
|
||||
std::map< CInterfaceElement*, std::string >::const_iterator itr =
|
||||
_ParentSizesMap.find( element );
|
||||
if( itr == _ParentSizesMap.end() )
|
||||
return "parent";
|
||||
else
|
||||
return CInterfaceElement::stripId( itr->second );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void CInterfaceParser::addLuaClassAssociation (CInterfaceGroup *group, const std::string &luaScript)
|
||||
{
|
||||
|
|
|
@ -91,25 +91,34 @@ namespace GUIEditor
|
|||
void CPropBrowserCtrl::setupProperty( const SPropEntry &prop, const CInterfaceElement *element )
|
||||
{
|
||||
QtVariantProperty *p = NULL;
|
||||
QVariant v;
|
||||
|
||||
if( prop.propType == "string" )
|
||||
{
|
||||
p = propertyMgr->addProperty( QVariant::String, prop.propName.c_str() );
|
||||
p->setValue( element->getProperty( prop.propName ).c_str() );
|
||||
v = element->getProperty( prop.propName ).c_str();
|
||||
}
|
||||
else
|
||||
if( prop.propType == "bool" )
|
||||
{
|
||||
p = propertyMgr->addProperty( QVariant::Bool, prop.propName.c_str() );
|
||||
bool value = false;
|
||||
if( element->getProperty( prop.propName ) == "true" )
|
||||
value = true;
|
||||
|
||||
p->setValue( value );
|
||||
NLMISC::fromString( element->getProperty( prop.propName ), value );
|
||||
v = value;
|
||||
}
|
||||
else
|
||||
if( prop.propType == "int" )
|
||||
{
|
||||
p = propertyMgr->addProperty( QVariant::Int, prop.propName.c_str() );
|
||||
sint32 value = 0;
|
||||
NLMISC::fromString( element->getProperty( prop.propName ), value );
|
||||
v = value;
|
||||
}
|
||||
|
||||
if( p == NULL )
|
||||
return;
|
||||
|
||||
p->setValue( v );
|
||||
browser->addProperty( p );
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
<widget>
|
||||
<header>
|
||||
<name>InterfaceElement</name>
|
||||
<guiname>ie</guiname>
|
||||
<guiname>CInterfaceElement</guiname>
|
||||
<description></description>
|
||||
<abstract>true</abstract>
|
||||
<icon></icon>
|
||||
|
@ -17,5 +17,60 @@
|
|||
<type>bool</type>
|
||||
<default>true</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>x</name>
|
||||
<type>int</type>
|
||||
<default>0</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>y</name>
|
||||
<type>int</type>
|
||||
<default>0</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>w</name>
|
||||
<type>int</type>
|
||||
<default>0</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>h</name>
|
||||
<type>int</type>
|
||||
<default>0</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>posref</name>
|
||||
<type>string</type>
|
||||
<default>BL BL</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>sizeref</name>
|
||||
<type>string</type>
|
||||
<default></default>
|
||||
</property>
|
||||
<property>
|
||||
<name>posparent</name>
|
||||
<type>string</type>
|
||||
<default>parent</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>sizeparent</name>
|
||||
<type>string</type>
|
||||
<default>parent</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>global_color</name>
|
||||
<type>bool</type>
|
||||
<default>true</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>render_layer</name>
|
||||
<type>int</type>
|
||||
<default>0</default>
|
||||
</property>
|
||||
<property>
|
||||
<name>avoid_resize_parent</name>
|
||||
<type>bool</type>
|
||||
<default>false</default>
|
||||
</property>
|
||||
</properties>
|
||||
</widget>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<widget>
|
||||
<header>
|
||||
<name>InterfaceGroup</name>
|
||||
<guiname>ig</guiname>
|
||||
<guiname>CInterfaceGroup</guiname>
|
||||
<ancestor>CtrlBase</ancestor>
|
||||
<description></description>
|
||||
<abstract>false</abstract>
|
||||
|
|
Loading…
Reference in a new issue