00001 #include "global.h"
00002 #include "MercuryTheme.h"
00003 #include "ScreenCopper.h"
00004 #include "MercuryInput.h"
00005 #include "MercuryDisplay.h"
00006 #include "MercuryUtil.h"
00007 #include "MercuryLog.h"
00008
00009 #include "MercuryObjectFactory.h"
00010 REGISTER_SCREEN_CLASS( ScreenCopper )
00011 KeyMappingWithCode( button_showmenu, "0-27" );
00012
00013 #define MC_INPUT 2
00014 #define MC_LOADOVERLAY 3
00015 #define MC_UNLOADOVERLAY 4
00016
00017 void ScreenCopper::Init()
00018 {
00019 MercuryScreen::Init();
00020
00021
00022 m_sprCursor.SetName( m_name + "::Base::Cursor" );
00023 m_sprCursor.Init();
00024 m_sprCursor.LoadImage( THEME.GetMetricS( m_name, "Cursor" ) );
00025 m_sprCursor.SetDrawOrder(100);
00026 AddOrthoObject( &m_sprCursor );
00027
00028 MString sMainWindowName = THEME.GetMetricS( m_name, "MainWindowName", "" );
00029 m_wndMain = GetCopperByClass( "CopperWindowLoadable", sMainWindowName );
00030 m_wndMain->Init( NULL, sMainWindowName );
00031 m_wndMain->SetHeight( DISPLAY->GetDimensions().height );
00032 m_wndMain->SetWidth( DISPLAY->GetDimensions().width );
00033 AddOrthoObject( m_wndMain );
00034
00035
00036 RegisterMessage( MC_INPUT, "unmappedinput" );
00037 RegisterMessage( MC_INPUT, "mappedinput" );
00038 RegisterMessage( MC_LOADOVERLAY, "CopperLoadOverlay" );
00039 RegisterMessage( MC_UNLOADOVERLAY, "CopperUnloadOverlay" );
00040
00041 m_wndOverlay = NULL;
00042
00043 this->Tweening.AddCommand(THEME.GetMetricS(m_name, "OnCommand" ));
00044 }
00045
00046 ScreenCopper::~ScreenCopper()
00047 {
00048 SAFE_DELETE( m_wndMain );
00049 SAFE_DELETE( m_wndOverlay );
00050 }
00051
00052 void ScreenCopper::Update( const float dTime )
00053 {
00054
00055
00056
00057 int x,y,dX,dY;
00058 INPUTMAN->GetCursorPosition( x, y );
00059 dX = x - m_iOldCoreX;
00060 dY = y - m_iOldCoreY;
00061 m_iOldCoreX = x;
00062 m_iOldCoreY = y;
00063
00064 if ( ( dY != 0 ) || ( dX != 0 ) )
00065 {
00066 m_iOldX += dX;
00067 m_iOldY += dY;
00068 m_iOldX = Clamp( m_iOldX, 0, int(DISPLAY->GetBasedDimensions().width)-1 );
00069 m_iOldY = Clamp( m_iOldY, 0, int(DISPLAY->GetBasedDimensions().height)-1 );
00070
00071 m_sprCursor.SetX( float(m_iOldX) );
00072 m_sprCursor.SetY( float(m_iOldY) );
00073
00074 CopperMouseEvent c;
00075 c.pType = CopperMouseEvent::MOUSE_MOVE;
00076 c.x = m_iOldX;
00077 c.y = m_iOldY;
00078 if ( m_wndOverlay )
00079 m_wndOverlay->MouseEvent( c );
00080 m_wndMain->MouseEvent( c );
00081 }
00082 MercuryScreen::Update( dTime );
00083 }
00084
00085 void ScreenCopper::Message( int Message, PStack & data, const MString & name )
00086 {
00087 if ( Message == MC_INPUT )
00088 {
00089 InputMessageStruct c(data);
00090
00091
00092 if ( c.code == button_showmenu && c.type == IET_RELEASE )
00093 if ( GetHide() )
00094 {
00095 this->Tweening.StopTweening();
00096 this->Tweening.AddCommand(THEME.GetMetricS(m_name, "HideOff" ));
00097 }
00098 else
00099 {
00100 this->Tweening.StopTweening();
00101 this->Tweening.AddCommand(THEME.GetMetricS(m_name, "HideOn" ));
00102 }
00103
00104 if ( GetHide() )
00105 return;
00106
00107
00108 if ( c.button > 0 && c.button < 3 )
00109 {
00110 CopperMouseEvent g;
00111 if ( c.type == IET_DOWN )
00112 g.pType = CopperMouseEvent::MOUSE_DOWN;
00113 else if ( c.type == IET_RELEASE )
00114 g.pType = CopperMouseEvent::MOUSE_UP;
00115 else
00116 return;
00117
00118 g.x = m_iOldX;
00119 g.y = m_iOldY;
00120 bool bOverlayGotMouse = false;
00121 if ( m_wndOverlay )
00122 bOverlayGotMouse = m_wndOverlay->MouseEvent( g );
00123 if ( !bOverlayGotMouse || g.pType == CopperMouseEvent::MOUSE_UP )
00124 m_wndMain->MouseEvent( g );
00125 return;
00126 }
00127
00128
00129 CopperKeypress cuKP;
00130 cuKP.cLetter = c.button;
00131 if ( c.type == IET_DOWN )
00132 cuKP.pType = CopperKeypress::KEY_DOWN;
00133 if ( c.type == IET_RELEASE )
00134 cuKP.pType = CopperKeypress::KEY_UP;
00135 m_wndMain->KeyPress( cuKP );
00136 if ( m_wndOverlay )
00137 m_wndOverlay->KeyPress( cuKP );
00138 } else if ( Message == MC_LOADOVERLAY ) {
00139 if ( m_wndOverlay )
00140 {
00141 RemoveObject( m_wndOverlay );
00142 SAFE_DELETE( m_wndOverlay );
00143 }
00144
00145
00146 MString sOverlayData = data.PeekItem(0).GetValueS();
00147 MString sOverlayWindowName;
00148 float sX = 0, sY = 0;
00149
00150 int iBU = BytesUntil( sOverlayData.c_str(), ",", 0, sOverlayData.length(), 1 );
00151
00152 if ( iBU >= 0 && iBU < (int)sOverlayData.length() )
00153 {
00154 sOverlayWindowName = sOverlayData.substr( 0, iBU );
00155 sOverlayData = sOverlayData.substr( iBU+1 );
00156 iBU = BytesUntil( sOverlayData.c_str(), ",", 0, sOverlayData.length(), 1 );
00157 if ( iBU >= 0 )
00158 {
00159 sX = (float)atoi( sOverlayData.substr( 0, iBU ).c_str() );
00160 sOverlayData = sOverlayData.substr( iBU+1 );
00161 if ( sOverlayData.length() > 0 )
00162 sY = (float)atoi( sOverlayData.c_str() );
00163 }
00164 } else
00165 sOverlayWindowName = sOverlayData;
00166
00167 m_wndOverlay = GetCopperByClass( "CopperWindowLoadable", sOverlayWindowName );
00168 m_wndOverlay->SetPosition( MercuryPoint( sX, sY, 0 ) );
00169 m_wndOverlay->Init( NULL, sOverlayWindowName );
00170 AddOrthoObject( m_wndOverlay );
00171 } else if ( Message == MC_UNLOADOVERLAY ) {
00172 if ( m_wndOverlay )
00173 {
00174 RemoveObject( m_wndOverlay );
00175 SAFE_DELETE( m_wndOverlay );
00176 }
00177 }
00178 }
00179
00180 void ScreenCopper::Draw()
00181 {
00182 MercuryScreen::Draw();
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211