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
00042
00043
00044 m_fWidth = float(m_pImage.GetWidth());
00045 m_fHeight = float(m_pImage.GetHeight());
00046
00047
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
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160