CopperPrimitives.cpp

Go to the documentation of this file.
00001 #include "CopperPrimitives.h"
00002 #include "MercuryTheme.h"
00003 #include "MercuryUtil.h"
00004 
00005 REGISTER_COPPER_CLASS( CopperWindowLoadable )
00006 void CopperWindowLoadable::Init( CopperWindow * pParent, const MString & sName )
00007 {
00008     int i;
00009     CopperWindow::Init( pParent, sName );
00010 
00011     SetWidth( THEME.GetMetricF( sName, "Width" ) );
00012     SetHeight( THEME.GetMetricF( sName, "Height" ) );
00013 
00014     int NumObjects = THEME.GetMetricI( sName, "NumWindows" );
00015 
00016     for ( i = 0; i < NumObjects; i++ )
00017     {
00018         MString sWinType = THEME.GetMetricS( sName, ssprintf( "Window%dClass", i+1 ) );
00019         MString sWinName = THEME.GetMetricS( sName, ssprintf( "Window%dName", i+1 ) );
00020         CopperWindow * pNewWindow = GetCopperByClass( sWinType, sWinName );
00021         pNewWindow->Init( this, sWinName );
00022         pNewWindow->SetX( THEME.GetMetricF( sName, ssprintf( "Window%dX", i+1 ) ) );
00023         pNewWindow->SetY( THEME.GetMetricF( sName, ssprintf( "Window%dY", i+1 ) ) );
00024         m_vWindows.push_back( pNewWindow );
00025     }
00026 
00027     for ( i = NumObjects - 1; i >= 0; i-- )
00028         AddObject( m_vWindows[i] );
00029 }
00030 
00031 REGISTER_COPPER_CLASS( CopperPicture )
00032 void CopperPicture::Init( CopperWindow * pParent, const MString & sName )
00033 {
00034     CopperWindow::Init( pParent, sName );
00035 
00036     m_pImage.SetName( m_name + "::" + "Image" );
00037     m_pImage.Init();
00038     m_pImage.LoadImage( THEME.GetMetricS( sName, "Image" ) );
00039     AddObject( &m_pImage );
00040 
00041     //Copper need this information to determine if a mouse click is on target
00042     //This should be changed because m_pImage's size could change during
00043     //execution.
00044     m_fWidth = float(m_pImage.GetWidth());
00045     m_fHeight = float(m_pImage.GetHeight());
00046 
00047     //Apparently copper likes placement from the corners, not center...
00048     m_pImage.SetVAlignment(TOP);
00049     m_pImage.SetHAlignment(LEFT);
00050 }
00051 
00052 REGISTER_COPPER_CLASS( CopperCaption )
00053 void CopperCaption::Init( CopperWindow * pParent, const MString & sName )
00054 {
00055     CopperWindow::Init( pParent, sName );
00056     m_pText.SetName( m_name + "::CaptionText" );
00057     m_pText.Init();
00058     m_pText.SetFont( THEME.GetMetricS( sName, "Font" ) );
00059     m_pText.SetText( THEME.GetMetricS( sName, "Text" ) );
00060     m_pText.SetX( THEME.GetMetricF( sName, "TextX" ) );
00061     m_pText.SetY( THEME.GetMetricF( sName, "TextY" ) );
00062     m_pText.SetDrawOrder(1);
00063     AddObject( &m_pText );
00064 }
00065 
00066 REGISTER_COPPER_CLASS( CopperButton )
00067 void CopperButton::Init( CopperWindow * pParent, const MString & sName )
00068 {
00069     CopperCaption::Init( pParent, sName );
00070 
00071     m_bCurrentlyPressed = false;
00072 
00073     m_pBrdReleaseInBox.Message = THEME.GetMetricS( sName, "ReleaseInBoxMessage" );
00074     m_pBrdReleaseInBox.Data = THEME.GetMetricS( sName, "ReleaseInBoxData" );
00075 
00076     m_pBGDown.SetName( m_name + "::BGDown" );
00077     m_pBGDown.Init();
00078     m_pBGDown.LoadImage( THEME.GetMetricS( sName, "ImageDown" ) );
00079     m_pBGDown.Tweening.AddCommand( THEME.GetMetricS( sName, "ImageDownOnCommand" ) );
00080     AddObject( &m_pBGDown );
00081 
00082     m_pBGUp.SetName( m_name + "::BGUp" );
00083     m_pBGUp.Init();
00084     m_pBGUp.LoadImage( THEME.GetMetricS( sName, "ImageUp" ) );
00085     m_pBGUp.Tweening.AddCommand( THEME.GetMetricS( sName, "ImageUpOnCommand" ) );
00086     AddObject( &m_pBGUp );
00087 
00088     m_fWidth = float(m_pBGUp.GetWidth());
00089     m_fHeight = float(m_pBGUp.GetHeight());
00090 
00091     MercuryPoint pTranslate( m_fWidth/2, m_fHeight/2, 0 );
00092     m_pBGDown.SetPosition( pTranslate );
00093     m_pBGUp.SetPosition( pTranslate );
00094 }
00095 
00096 bool CopperButton::MouseEvent( const CopperMouseEvent & pMouseEvent )
00097 {
00098     CopperCaption::MouseEvent( pMouseEvent );
00099 
00100     if ( pMouseEvent.pType == CopperMouseEvent::MOUSE_UP )
00101     {
00102         if ( m_bCurrentlyPressed && IsMouseEventOnTarget( pMouseEvent ) )
00103             m_pBrdReleaseInBox.Broadcast();
00104         m_bCurrentlyPressed = false;
00105         ToggleDownImage(m_bCurrentlyPressed);
00106     }
00107 
00108     if ( pMouseEvent.pType == CopperMouseEvent::MOUSE_DOWN )
00109     {
00110         m_bCurrentlyPressed = true;
00111         ToggleDownImage(m_bCurrentlyPressed);
00112     }
00113     return true;
00114 }
00115 
00116 void CopperButton::ToggleDownImage(bool isPressed)
00117 {
00118     if (isPressed)
00119     {
00120         m_pBGDown.Tweening.FinishTweening();
00121         m_pBGDown.Tweening.AddCommand( THEME.GetMetricS( GetName(), "ImageDownShow" ) );
00122 
00123         m_pBGUp.Tweening.FinishTweening();
00124         m_pBGUp.Tweening.AddCommand( THEME.GetMetricS( GetName(), "ImageUpHide" ) );
00125     }
00126     else
00127     {
00128         m_pBGDown.Tweening.FinishTweening();
00129         m_pBGDown.Tweening.AddCommand( THEME.GetMetricS( GetName(), "ImageDownHide" ) );
00130 
00131         m_pBGUp.Tweening.FinishTweening();
00132         m_pBGUp.Tweening.AddCommand( THEME.GetMetricS( GetName(), "ImageUpShow" ) );
00133     }
00134 }
00135 
00136 /*
00137  * (c) 2006 Charles Lohr
00138  * All rights reserved.
00139  * 
00140  * Permission is hereby granted, free of charge, to any person obtaining a
00141  * copy of this software and associated documentation files (the
00142  * "Software"), to deal in the Software without restriction, including
00143  * without limitation the rights to use, copy, modify, merge, publish,
00144  * distribute, and/or sell copies of the Software, and to permit persons to
00145  * whom the Software is furnished to do so, provided that the above
00146  * copyright notice(s) and this permission notice appear in all copies of
00147  * the Software and that both the above copyright notice(s) and this
00148  * permission notice appear in supporting documentation.
00149  * 
00150  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00151  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00152  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
00153  * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
00154  * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
00155  * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00156  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
00157  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00158  * PERFORMANCE OF THIS SOFTWARE.
00159  */
00160 

Hosted by SourceForge.net Logo