00001 #include "../borqueror.h"
00002
00003 StarSystemObject::StarSystemObject( void )
00004 : curSS( 0 )
00005 {
00006 }
00007
00008
00009 StarSystemObject::~StarSystemObject( void )
00010 {
00011 }
00012
00013 const bool StarSystemObject::SetupWindow( const Message &msg )
00014 {
00015 XImage::SetupWindow( msg );
00016
00017 MessageServer::Instance().RegisterMessageClient( this , Message::MOUSE_MOVE );
00018 MessageServer::Instance().RegisterMessageClient( this , Message::CTRL_LCLICK );
00019 MessageServer::Instance().RegisterMessageClient( this , Message::CTRL_VALUECHANGE );
00020 MessageServer::Instance().RegisterMessageClient( this , Message::MOUSE_BUTTONUP );
00021 MessageServer::Instance().RegisterMessageClient( this , Message::MOUSE_BUTTONDOWN );
00022
00023 curSS = 0;
00024 return true;
00025 }
00026
00027 void StarSystemObject::Draw( void )
00028 {
00029 XBox::Draw();
00030
00031 if( curSS )
00032 {
00033 int size = (int)(Height() - GetFontSize() * 4);
00034 XRect r( x , y + (Height() - size) / 2 , w , size );
00035
00036 curSS->DrawStarSystem( GetGDI() , r , id );
00037 }
00038 }
00039
00040 const bool StarSystemObject::evMouseMove( const MouseMessage &msg )
00041 {
00042 bool ans = XImage::evMouseMove( msg );
00043
00044 if( HitTest( msg.Point ) == RELPOS_INSIDE && curSS != 0 )
00045 {
00046 ans = true;
00047 }
00048
00049 return ans;
00050 }
00051
00052 const bool StarSystemObject::evMouseLClick( const CtrlMessage &msg )
00053 {
00054 bool ans = XImage::evMouseLClick( msg );
00055
00056 if( curSS )
00057 {
00058 Form *f = Rsrc::GetAddr( ePlayGame );
00059
00060 if( curSS->ClickedOn( &ArsApplication::mousexy ) )
00061 {
00062 StarInfoDlg sidlg( id , curSS , this );
00063 if( !sidlg.MainLoop() )
00064 {
00065 ArsPostMessage( CtrlMessage( Message::CTRL_LCLICK, this, this, 0 ) );
00066 return true;
00067 }
00068 }
00069 else
00070 {
00071 vector<Planet *>::iterator pos = find_if( curSS->begin() , curSS->end() , bind2nd( mem_fun( &Planet::ClickedOn ) , &ArsApplication::mousexy ) );
00072 if( pos != curSS->end() )
00073 {
00074 PlanetInfoDlg pidlg( curSS , this );
00075 pidlg.SetupInfo( (*pos) );
00076 if( !pidlg.MainLoop() )
00077 {
00078 ArsPostMessage( CtrlMessage( Message::CTRL_LCLICK, this, this, 0 ) );
00079 return true;
00080 }
00081 }
00082 }
00083
00084 f->GetArsObject( 20 )->SetDirty();
00085 ArsPostMessage( Message( Message::APP_PAINT , (*f)[0] ) );
00086
00087 ans = true;
00088 }
00089 return ans;
00090 }
00091
00092 const bool StarSystemObject::evValueChange( const CtrlMessage &msg )
00093 {
00094 bool ans = XImage::evValueChange( msg );
00095
00096 if( ((Window *)msg.source)->GetId() == 20 )
00097 {
00098 curSS = (StarSystem *)msg.value;
00099 SetDirty( true );
00100 ans = true;
00101 }
00102 return ans;
00103 }
00104