|
From: <cn...@us...> - 2010-01-11 20:21:56
|
Revision: 652
http://hgengine.svn.sourceforge.net/hgengine/?rev=652&view=rev
Author: cnlohr
Date: 2010-01-11 20:21:50 +0000 (Mon, 11 Jan 2010)
Log Message:
-----------
better support for values
Modified Paths:
--------------
Mercury2/Themes/default/File/scenegraph.xml
Mercury2/modules/Cu2.cpp
Mercury2/modules/Cu2.h
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryValue.cpp
Mercury2/src/MercuryValue.h
Modified: Mercury2/Themes/default/File/scenegraph.xml
===================================================================
--- Mercury2/Themes/default/File/scenegraph.xml 2010-01-11 19:24:25 UTC (rev 651)
+++ Mercury2/Themes/default/File/scenegraph.xml 2010-01-11 20:21:50 UTC (rev 652)
@@ -72,7 +72,9 @@
<node type="Cu2Root" width="640" height="480" hidden="true" >
<node type="Cu2Button" text="hello" font="FONT:FreeSans.hgfont" size=".25" alignment="CENTER" x="10" y="450" name="Button" />
<node type="Cu2Dialog" text="T00" font="FONT:FreeSans.hgfont" size=".25" x="200" y="40" name="Dialog" >
- <node type="Cu2Button" text="hel0" font="FONT:FreeSans.hgfont" size=".25" alignment="CENTER" x="10" y="40" />
+ <node type="Cu2Button" text="A" font="FONT:FreeSans.hgfont" size=".25" alignment="CENTER" x="32" y="40" associatedValue="TestMode" associatedValueSet="A" />
+ <node type="Cu2Button" text="B" font="FONT:FreeSans.hgfont" size=".25" alignment="CENTER" x="10" y="40" associatedValue="TestMode" associatedValueSet="B"/>
+ <node type="Cu2Label" text="[nil]" font="FONT:FreeSans.hgfont" size=".25" alignment="CENTER" x="10" y="10" associatedValue="TestMode" />
</node>
</node>
</node>
Modified: Mercury2/modules/Cu2.cpp
===================================================================
--- Mercury2/modules/Cu2.cpp 2010-01-11 19:24:25 UTC (rev 651)
+++ Mercury2/modules/Cu2.cpp 2010-01-11 20:21:50 UTC (rev 652)
@@ -324,6 +324,8 @@
LOAD_FROM_XML( "text", m_sText, );
LOAD_FROM_XML( "autoSize", m_bAutoSize, StrToBool );
LOAD_FROM_XML( "clickPayload", m_sValueToSend, );
+ LOAD_FROM_XML( "associatedValue", m_sAssociatedValue, );
+ LOAD_FROM_XML( "associatedValueSet", m_sAssociatedValueSet, );
if( m_pText )
{
@@ -346,6 +348,8 @@
if( m_sMessageToSend.length() ) sXMLStream += ssprintf( "clickMessage=\"%s\" ", m_sMessageToSend.c_str() );
if( m_sValueToSend.length() ) sXMLStream += ssprintf( "clickPayload=\"%s\" ", m_sValueToSend.c_str() );
if( m_bAutoSize ) sXMLStream += ssprintf( "autoSize=\"%d\" ", m_bAutoSize );
+ if( m_sAssociatedValue.length() ) sXMLStream += ssprintf( "associatedValue=\"%s\" ", m_sAssociatedValue.c_str() );
+ if( m_sAssociatedValueSet.length() ) sXMLStream += ssprintf( "associatedValueSet=\"%s\" ", m_sAssociatedValueSet.c_str() );
if( !m_pText )
m_pText->SaveToXMLTag( sXMLStream );
@@ -391,6 +395,9 @@
void Cu2Button::Click( int x, int y )
{
+ if( m_sAssociatedValue.length() )
+ MESSAGEMAN.GetValue( m_sAssociatedValue )->SetString( m_sAssociatedValueSet );
+
if( m_sMessageToSend.length() )
MESSAGEMAN.BroadcastMessage( m_sMessageToSend, new PointerDataMessage( this ) );
}
@@ -438,6 +445,90 @@
REGISTER_NODE_TYPE(Cu2Button);
+///////////////////////////////////////COPPER 2 LABEL///////////////////////////////////////
+
+Cu2Label::Cu2Label() : Cu2Element()
+{
+ m_pText = (TextNode*)NODEFACTORY.Generate( "TextNode" );
+ AddChild( m_pText );
+ m_bAutoSize = true;
+ m_bDown = false;
+}
+
+Cu2Label::~Cu2Label()
+{
+ if( m_sAssociatedValue.length() )
+ MESSAGEMAN.GetValue( m_sAssociatedValue )->DetachModifyDelegate( (ValueDelegate)&Cu2Label::ChangeValue, this );
+}
+
+void Cu2Label::LoadFromXML(const XMLNode& node)
+{
+ LOAD_FROM_XML( "associatedValue", m_sAssociatedValue, );
+ if( m_sAssociatedValue.length() )
+ {
+ MESSAGEMAN.GetValue( m_sAssociatedValue )->AttachModifyDelegate( (ValueDelegate)&Cu2Label::ChangeValue, this );
+ printf( "Associating Value: %s\n", m_sAssociatedValue.c_str() );
+ }
+
+ LOAD_FROM_XML( "text", m_sText, );
+ LOAD_FROM_XML( "autoSize", m_bAutoSize, StrToBool );
+
+ if( m_pText )
+ {
+ m_pText->SetAlignment( TextNode::LEFT );
+ m_pText->LoadFont( node.Attribute("font") );
+ m_pText->SetSize( StrToFloat( node.Attribute("size") ) );
+ SetText( m_sText );
+ m_pText->SetShiftAbsolute( true );
+ m_pText->SetShiftX( 5 );
+ m_pText->SetShiftY( 5 );
+ }
+
+ Cu2Element::LoadFromXML( node );
+
+ Refresh();
+}
+
+void Cu2Label::SaveToXMLTag( MString & sXMLStream )
+{
+ if( m_sAssociatedValue.length() ) sXMLStream += ssprintf( "m_sAssociatedValue=\"%s\" ", m_sAssociatedValue.c_str() );
+ if( m_bAutoSize ) sXMLStream += ssprintf( "autoSize=\"%d\" ", m_bAutoSize );
+
+ if( !m_pText )
+ m_pText->SaveToXMLTag( sXMLStream );
+
+ Cu2Element::SaveToXMLTag( sXMLStream );
+}
+void Cu2Label::Refresh()
+{
+ if( !m_pText )
+ {
+ LOG.Write( "Warning: Cu2Button \"" + GetName() + "\" does not have valid Text box associated." );
+ return;
+ }
+
+ m_pText->SetText( m_sText );
+ m_pText->RenderText();
+
+ if( m_bAutoSize )
+ {
+ SetSize( m_pText->GetRMaxX() + 8, m_pText->GetRMaxY() + 8 );
+ }
+}
+
+void Cu2Label::Render( const MercuryMatrix& m )
+{
+ TransformNode::Render( m );
+}
+
+void Cu2Label::ChangeValue( MValue * v )
+{
+ m_sText = v->GetString();
+ Refresh();
+}
+
+REGISTER_NODE_TYPE(Cu2Label);
+
///////////////////////////////////////COPPER 2 DIALOG///////////////////////////////////////
Modified: Mercury2/modules/Cu2.h
===================================================================
--- Mercury2/modules/Cu2.h 2010-01-11 19:24:25 UTC (rev 651)
+++ Mercury2/modules/Cu2.h 2010-01-11 20:21:50 UTC (rev 652)
@@ -170,6 +170,9 @@
GENRTTI( Cu2Button );
private:
+ MString m_sAssociatedValue;
+ MString m_sAssociatedValueSet;
+
MString m_sMessageToSend;
MString m_sValueToSend;
MString m_sText;
@@ -178,6 +181,39 @@
TextNode * m_pText;
};
+///Standard label (doesn't do anything but display something)
+class Cu2Label : public Cu2Element
+{
+public:
+ Cu2Label();
+ ~Cu2Label();
+
+ virtual void LoadFromXML(const XMLNode& node);
+ virtual void SaveToXMLTag( MString & sXMLStream );
+
+ virtual void Render( const MercuryMatrix& m );
+
+ void SetText( const MString & sText ) { m_sText = sText; Refresh(); }
+ void SetAutoSize( bool bAutoSize ) { m_bAutoSize = bAutoSize; Refresh(); }
+ void Refresh();
+
+ MString & Payload() { return m_sValueToSend; }
+ TextNode * GetTextNodeHandle() { return m_pText; }
+
+ void ChangeValue( MValue * v );
+
+ GENRTTI( Cu2Button );
+private:
+ MString m_sAssociatedValue;
+ MString m_sMessageToSend;
+ MString m_sValueToSend;
+ MString m_sText;
+ bool m_bAutoSize;
+ bool m_bDown;
+ TextNode * m_pText;
+};
+
+///Dialog box (for putting other things into and being able to drag around)
class Cu2Dialog : public Cu2Element
{
public:
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2010-01-11 19:24:25 UTC (rev 651)
+++ Mercury2/src/Mercury2.cpp 2010-01-11 20:21:50 UTC (rev 652)
@@ -211,12 +211,12 @@
public:
TestMouse()
{
- MESSAGEMAN.GetValue( "Input.CursorGrabbed" )->AttachModifyDelegate( (ValueDelegate)&TestMouse::ChangeX, (MessageHandler*)this );
+ MESSAGEMAN.GetValue( "TestMode" )->AttachModifyDelegate( (ValueDelegate)&TestMouse::ChangeX, (MessageHandler*)this );
}
void ChangeX( MValue * v )
{
- printf( "Changed: %d\n", v->GetBool() );
+ printf( "Changed: %s\n", v->GetString().c_str() );
}
} TM;
///XXXXXXX REMOVE THIS CODE BEFORE ANY RELEASE XXXXXXXXXXx
Modified: Mercury2/src/MercuryValue.cpp
===================================================================
--- Mercury2/src/MercuryValue.cpp 2010-01-11 19:24:25 UTC (rev 651)
+++ Mercury2/src/MercuryValue.cpp 2010-01-11 20:21:50 UTC (rev 652)
@@ -93,19 +93,31 @@
}
-const MString & MValue::ConvString()
+const MString MValue::ConvString()
{
- static const MString NILVAL = "(NIL)";
switch( m_CurType )
{
case TYPE_STRING: return *m_Data.dataS;
- case TYPE_INT: ssprintf( "%d", m_Data.l );
- case TYPE_FLOAT: ssprintf( "%f", m_Data.f );
- case TYPE_PTR: ssprintf( "%p", m_Data.v );
- default: return NILVAL;
+ case TYPE_INT: return ssprintf( "%d", m_Data.l );
+ case TYPE_FLOAT: return ssprintf( "%.2f", m_Data.f );
+ case TYPE_PTR: return ssprintf( "%p", m_Data.v );
+ default: return "(NIL)";
}
}
+void MValue::ConvString( MString & ret )
+{
+ switch( m_CurType )
+ {
+ case TYPE_STRING: ret = *m_Data.dataS;
+ case TYPE_INT: ret = ssprintf( "%d", m_Data.l );
+ case TYPE_FLOAT: ret = ssprintf( "%.2f", m_Data.f );
+ case TYPE_PTR: ret = ssprintf( "%p", m_Data.v );
+ default: ret = "(NIL)";
+ }
+}
+
+
bool MValue::ConvBool()
{
switch( m_CurType )
@@ -117,6 +129,22 @@
}
}
+
+
+void MValue::AttachModifyDelegate( DeletionNotifier NotifyFunction, MessageHandler * NotifyObject )
+{
+ DelegateNotifierList * d = new DelegateNotifierList( NotifyFunction, NotifyObject );
+ d->Next = DLModify;
+ DLModify = d;
+}
+
+void MValue::DetachModifyDelegate( DeletionNotifier NotifyFunction, MessageHandler * NotifyObject )
+{
+ DLModify->DelNotifier( NotifyFunction, NotifyObject, DLModify );
+}
+
+
+
MVRefBase::MVRefBase(const MString & sPath)
{
mv = MESSAGEMAN.GetValue( sPath );
Modified: Mercury2/src/MercuryValue.h
===================================================================
--- Mercury2/src/MercuryValue.h 2010-01-11 19:24:25 UTC (rev 651)
+++ Mercury2/src/MercuryValue.h 2010-01-11 20:21:50 UTC (rev 652)
@@ -50,7 +50,8 @@
int GetInt() { MSemaphoreLock( &this->m_Sema ); return (m_CurType == TYPE_INT)?m_Data.l:ConvInt(); }
float GetFloat() { MSemaphoreLock( &this->m_Sema ); return (m_CurType == TYPE_FLOAT)?m_Data.f:ConvFloat(); }
- const MString & GetString() { MSemaphoreLock( &this->m_Sema ); return (m_CurType == TYPE_STRING)?*m_Data.dataS:ConvString(); }
+ const MString GetString() { MSemaphoreLock( &this->m_Sema ); return (m_CurType == TYPE_STRING)?*m_Data.dataS:ConvString(); }
+ void GetString( MString & str ) { MSemaphoreLock( &this->m_Sema ); if (m_CurType == TYPE_STRING) str = *m_Data.dataS; else ConvString( str ); }
bool GetBool() { MSemaphoreLock( &this->m_Sema ); return (m_CurType == TYPE_INT)?m_Data.l:ConvBool(); }
void * GetPtr() { MSemaphoreLock( &this->m_Sema ); return (m_CurType == TYPE_PTR)?m_Data.v:0; }
@@ -83,19 +84,15 @@
MVType GetType() { return m_CurType; }
- void AttachModifyDelegate( DeletionNotifier NotifyFunction, MessageHandler * NotifyObject )
- {
- DelegateNotifierList * d = new DelegateNotifierList( NotifyFunction, NotifyObject );
- d->Next = DLModify;
- DLModify = d;
- }
-
+ void AttachModifyDelegate( DeletionNotifier NotifyFunction, MessageHandler * NotifyObject );
+ void DetachModifyDelegate( DeletionNotifier NotifyFunction, MessageHandler * NotifyObject );
void SetReferences( short RefCount ) { m_References = RefCount; }
private:
//Conv functions are not thread protected - this is because the caller of these functions should be.
int ConvInt();
float ConvFloat();
- const MString & ConvString();
+ const MString ConvString();
+ void ConvString( MString & ret );
bool ConvBool();
//Cleanup (to be done when object is deleted or switching types)
@@ -191,7 +188,7 @@
MVRefString( MValue * m ) : MVRefBase( m ) { }
MVRefString( const MString & p ) : MVRefBase( p ) { }
- const MString & Get() { return mv->GetString(); }
+ const MString Get() { return mv->GetString(); }
void Set( const MString & sv ) { mv->SetString( sv ); }
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|