|
From: <cn...@us...> - 2009-11-18 22:10:46
|
Revision: 623
http://hgengine.svn.sourceforge.net/hgengine/?rev=623&view=rev
Author: cnlohr
Date: 2009-11-18 22:10:37 +0000 (Wed, 18 Nov 2009)
Log Message:
-----------
add dialogs
Modified Paths:
--------------
Mercury2/modules/Cu2.cpp
Mercury2/modules/Cu2.h
Modified: Mercury2/modules/Cu2.cpp
===================================================================
--- Mercury2/modules/Cu2.cpp 2009-11-18 22:09:24 UTC (rev 622)
+++ Mercury2/modules/Cu2.cpp 2009-11-18 22:10:37 UTC (rev 623)
@@ -10,7 +10,7 @@
///////////////////////////////////////COPPER 2 ELEMENT///////////////////////////////////////
Cu2Element::Cu2Element() : TransformNode(),
- m_pFocusNode(0), m_bCanTabStop( false ), m_iButtonMask(0), m_bWasMouseInThisFrame(0),
+ m_pFocusNode(0), m_bCanTabStop( true ), m_bWasMouseInThisFrame(0),
m_fX(0), m_fY(0), m_fW(100), m_fH(100),
m_fOrigX(0), m_fOrigY(0), m_fOrigW(100), m_fOrigH(100)
{
@@ -45,7 +45,7 @@
SetSize( m_fOrigW, m_fOrigH );
}
-bool Cu2Element::MouseMotion( int x, int y, unsigned char iCurrentButtonMask )
+bool Cu2Element::MouseMotion( int x, int y, unsigned char iCurrentButtonMask, unsigned char iLastButtonMask )
{
if( IsHidden() )
return false;
@@ -62,13 +62,12 @@
for( unsigned button = 0; button < 8; button++ )
{
unsigned char Mask = 1<<button;
- bool bWasDown = m_iButtonMask & Mask;
+ bool bWasDown = iLastButtonMask & Mask;
bool bIsDown = iCurrentButtonMask & Mask;
if( bWasDown && !bIsDown )
{
//XXX: When we release outside - we want to propogate that information, and that can be tricky..
//So, instead, we choose to propogate that elsewhere...
- m_iButtonMask &= ~Mask;
if( bIsInside )
MouseAction( x, y, RELEASE_IN, button );
else
@@ -76,18 +75,19 @@
}
else if( !bWasDown && bIsDown && bIsInside )
{
- m_iButtonMask |= Mask;
MouseAction( x, y, PRESS_IN, button );
}
}
if( bIsInside )
- for( MercuryNode* send = FirstChild(); send; send = NextChild( send ) )
+ for( MercuryNode* send = LastChild(); send; send = PrevChild( send ) )
{
Cu2Element * sa = dynamic_cast<Cu2Element*>(send);
if( sa )
{
- sa->MouseMotion( x - int(sa->m_fX), y - int(sa->m_fY), iCurrentButtonMask );
+ //Break on the first one that is a hit, that way we don't pass mouse info to buttons below.
+ if( sa->MouseMotion( x - int(sa->m_fX), y - int(sa->m_fY), iCurrentButtonMask, iLastButtonMask ) )
+ return bIsInside;
}
}
@@ -108,7 +108,8 @@
void Cu2Element::MouseAction( int x, int y, Cu2Action c, int iWhichButton )
{
- //nothing
+ if( c == PRESS_IN )
+ RaiseFocus();
}
void Cu2Element::AddChild(MercuryNode* n)
@@ -154,6 +155,39 @@
return 0;
}
+bool Cu2Element::HasFocus()
+{
+ Cu2Element * sa = dynamic_cast<Cu2Element*>(Parent());
+
+ if( sa && sa->m_pFocusNode == this )
+ return true;
+ else
+ return false;
+}
+
+void Cu2Element::RaiseFocus()
+{
+ Cu2Element * ca = dynamic_cast<Cu2Element*>(Parent());
+
+ if( ca )
+ {
+ bool bCouldTabStop = IsEnableTabStop( );
+
+ //Remove this node from wherever it is
+ ca->RemoveChild( this );
+
+ //This is reset by RemoveChild - so we have to update.
+ SetEnableTabStop( bCouldTabStop );
+
+ //Make it so it draws last.
+ ca->AddChild( this );
+
+ ca->m_pFocusNode = this;
+
+ ca->RaiseFocus();
+ }
+}
+
void Cu2Element::SetHidden( bool bHide )
{
MercuryNode::SetHidden( bHide );
@@ -184,12 +218,14 @@
for( MercuryNode* send = FirstChild(); send; send = NextChild( send ) )
{
Cu2Element * sa = dynamic_cast<Cu2Element*>(send);
+
if( sa && sa->IsEnableTabStop() && !sa->IsHidden() )
{
m_pFocusNode = sa;
return;
}
}
+
m_pFocusNode = 0;
}
@@ -242,8 +278,10 @@
}
else
{
- MouseMotion( m.dx, MercuryWindow::GetCurrentWindow()->Height()-m.dy, m.buttons.data );
+ MouseMotion( m.dx, MercuryWindow::GetCurrentWindow()->Height()-m.dy, m.buttons.data, m_iLastButtonMask );
}
+
+ m_iLastButtonMask = m.buttons.data;
}
void Cu2Root::HandleKeyboardInput(const MessageData& data)
@@ -312,7 +350,7 @@
if( c == RELEASE_IN )
{
if( m_bDown )
- Click();
+ Click( x, y );
m_bDown = false;
}
@@ -320,6 +358,8 @@
{
m_bDown = false;
}
+
+ Cu2Element::MouseAction( x, y, c, iWhichButton );
}
void Cu2Button::Refresh()
@@ -336,11 +376,10 @@
if( m_bAutoSize )
{
SetSize( m_pText->GetRMaxX() + 8, m_pText->GetRMaxY() + 8 );
- printf( "Size: %f %f\n", m_pText->GetRMaxX() + 8, m_pText->GetRMaxY() + 8 );
}
}
-void Cu2Button::Click()
+void Cu2Button::Click( int x, int y )
{
if( m_sMessageToSend.length() )
MESSAGEMAN.BroadcastMessage( m_sMessageToSend, new PointerDataMessage( this ) );
@@ -389,7 +428,128 @@
REGISTER_NODE_TYPE(Cu2Button);
+///////////////////////////////////////COPPER 2 DIALOG///////////////////////////////////////
+
+Cu2Dialog::Cu2Dialog() : Cu2Element(), m_bDragging( false ), m_iClickX( 0 ), m_iClickY( 0 )
+{
+ m_sTitle = "(not set)";
+ m_pTitle = (TextNode*)NODEFACTORY.Generate( "TextNode" );
+ AddChild( m_pTitle );
+}
+
+void Cu2Dialog::LoadFromXML(const XMLNode& node)
+{
+ LOAD_FROM_XML( "text", m_sTitle, );
+
+ if( m_pTitle )
+ {
+ m_pTitle->SetAlignment( TextNode::LEFT );
+ m_pTitle->LoadFont( node.Attribute("font") );
+ m_pTitle->SetSize( StrToFloat( node.Attribute("size") ) );
+ m_pTitle->SetShiftAbsolute( true );
+ m_pTitle->SetShiftX( 3 );
+ m_pTitle->SetShiftY( GetH() - 18 );
+ SetText( m_sTitle );
+ }
+ Cu2Element::LoadFromXML( node );
+}
+
+void Cu2Dialog::SaveToXMLTag( MString & sXMLStream )
+{
+ if( !m_pTitle )
+ m_pTitle->SaveToXMLTag( sXMLStream );
+
+ Cu2Element::SaveToXMLTag( sXMLStream );
+}
+
+void Cu2Dialog::Render( const MercuryMatrix& m )
+{
+ glDisable( GL_TEXTURE_2D );
+ glColor3f( 0.5, 0.5, 0.5 );
+
+ glBegin( GL_QUADS );
+ glVertex2f( 1., 1. );
+ glVertex2f( GetW()-1, 1 );
+ glVertex2f( GetW()-1, GetH()-1);
+ glVertex2f( 1., GetH()-1 );
+ glEnd();
+
+ glLineWidth( 2 );
+ glBegin( GL_LINES );
+ glColor3f( 0.7, 0.7, 0.7 );
+ glVertex2f( 1, 1 );
+ glVertex2f( 1, GetH()-1 );
+ glVertex2f( 1, GetH()-1 );
+ glVertex2f( GetW()-2, GetH()-1 );
+ glColor3f( 0.1, 0.1, 0.1 );
+ glVertex2f( GetW()-1, GetH()-2 );
+ glVertex2f( GetW()-1, 1 );
+ glVertex2f( GetW()-1, 1 );
+ glVertex2f( 1, 1 );
+ glEnd();
+
+ if( HasFocus() )
+ glColor3f( 0., 0., 1. );
+ else
+ glColor3f( .3, .3, .3 );
+
+ glBegin( GL_QUADS );
+ glVertex2f( 2., GetH()-18 );
+ glVertex2f( GetW()-2, GetH()-18 );
+ glVertex2f( GetW()-2, GetH()-3 );
+ glVertex2f( 2., GetH()-3 );
+ glEnd();
+
+ glEnable( GL_TEXTURE_2D );
+
+ glColor3f( 1., 1., 1. );
+
+ TransformNode::Render( m );
+}
+
+void Cu2Dialog::MouseAction( int x, int y, Cu2Action c, int iWhichButton )
+{
+ if( y > GetH() - 14 && c == PRESS_IN )
+ {
+ m_bDragging = true;
+ m_iClickX = x;
+ m_iClickY = y;
+ }
+
+ if( c == RELEASE_IN || c == RELEASE_OUT )
+ m_bDragging = false;
+
+
+ Cu2Element::MouseAction( x, y, c, iWhichButton );
+}
+
+bool Cu2Dialog::MouseMotion( int x, int y, unsigned char iCurrentButtonMask, unsigned char iLastButtonMask )
+{
+ if( m_bDragging )
+ {
+ float ix = GetX() - ( m_iClickX - x );
+ float iy = GetY() - ( m_iClickY - y );
+
+ SetXY( ix, iy );
+ }
+ return Cu2Element::MouseMotion( x, y, iCurrentButtonMask, iLastButtonMask );
+}
+
+void Cu2Dialog::SetText( const MString & sText )
+{
+ m_sTitle = sText;
+ if( m_pTitle )
+ {
+ m_pTitle->SetText( m_sTitle );
+ m_pTitle->RenderText();
+ }
+}
+
+
+REGISTER_NODE_TYPE(Cu2Dialog);
+
+
/****************************************************************************
* Copyright (C) 2008-2009 by Joshua Allen *
* Charles Lohr *
Modified: Mercury2/modules/Cu2.h
===================================================================
--- Mercury2/modules/Cu2.h 2009-11-18 22:09:24 UTC (rev 622)
+++ Mercury2/modules/Cu2.h 2009-11-18 22:10:37 UTC (rev 623)
@@ -37,7 +37,7 @@
///Push raw mouse event. Generally, this calls MouseAction, and is only called internally.
///You may override this if you want to take actions that require mouse motion.
- virtual bool MouseMotion( int x, int y, unsigned char iCurrentButtonMask );
+ virtual bool MouseMotion( int x, int y, unsigned char iCurrentButtonMask, unsigned char iLastButtonMask );
///Called when a key is pressed - down the focus line.
virtual void GetKeypress( int key, bool bDown, bool bRepeat );
@@ -53,6 +53,12 @@
///Also handle tab stopping correctly.
virtual void SetHidden( bool bHide );
+ ///Does this node have focus?
+ bool HasFocus();
+
+ ///Make this object get focus.
+ void RaiseFocus();
+
///Progress to the next tab.
Cu2Element * NextTab();
@@ -68,12 +74,6 @@
///Propogate Release (You should not override this or modify it)
void PropogateReleaseOut( int x, int y, int iWhichButton );
- ///Get current button mask
- inline unsigned char GetCurrentButtonMask() { return m_iButtonMask; }
-
- ///Get if current button is down
- inline bool IsButtonDown( char iWhichButton ) { return (m_iButtonMask)&(1<<iWhichButton); }
-
///Set Position
void SetXY( float fX, float fY ) { m_fX = fX; m_fY = fY; SetPosition( MercuryVertex( m_fX, m_fY, 0. ) ); }
void SetX( float fX ) { m_fX = fX; SetPosition( MercuryVertex( m_fX, m_fY, 0 ) ); }
@@ -102,9 +102,6 @@
bool m_bCanTabStop;
- ///Mask of currently depressed buttons.
- unsigned char m_iButtonMask;
-
bool m_bWasMouseInThisFrame;
float m_fX, m_fY, m_fW, m_fH;
@@ -133,6 +130,7 @@
GENRTTI( Cu2Root );
private:
static Cu2Root * g_pCurrentInstance;
+ unsigned char m_iLastButtonMask;
};
class TextNode;
@@ -145,7 +143,7 @@
virtual void MouseAction( int x, int y, Cu2Action c, int iWhichButton );
///This function gets called whenever the button is clicked, you should abstract from this.
- virtual void Click();
+ virtual void Click( int x, int y );
virtual void LoadFromXML(const XMLNode& node);
virtual void SaveToXMLTag( MString & sXMLStream );
@@ -168,6 +166,29 @@
TextNode * m_pText;
};
+class Cu2Dialog : public Cu2Element
+{
+public:
+ Cu2Dialog();
+ GENRTTI( Cu2Dialog );
+
+ TextNode * GetTextNodeHandle() { return m_pTitle; }
+
+ virtual void LoadFromXML(const XMLNode& node);
+ virtual void SaveToXMLTag( MString & sXMLStream );
+ virtual void Render( const MercuryMatrix& m );
+ virtual bool MouseMotion( int x, int y, unsigned char iCurrentButtonMask, unsigned char iLastButtonMask );
+ virtual void MouseAction( int x, int y, Cu2Action c, int iWhichButton );
+
+ void SetText( const MString & sText );
+
+private:
+ bool m_bDragging;
+ int m_iClickX, m_iClickY;
+ TextNode * m_pTitle;
+ MString m_sTitle;
+};
+
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|