Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

GalaxyScreen Class Reference

#include <galaxyscreen.h>

Collaboration diagram for GalaxyScreen:

Collaboration graph
[legend]

Public Member Functions

 GalaxyScreen (void)
virtual ~GalaxyScreen (void)
XPoint ToGalaxy (const XPoint &mp)
void ResetGalaxyDisplay (void)

Static Public Attributes

SDL_Surface * img = 0 *GalaxyScreen::bkgnd
SDL_Surface * bkgnd

Protected Member Functions

virtual const bool SetupWindow (const Message &msg)
virtual const bool evMouseMove (const MouseMessage &msg)
virtual const bool evMouseButtonUp (const MouseMessage &msg)
virtual const bool evMouseLClick (const CtrlMessage &msg)
virtual const bool evKeyUp (const KeyboardMessage &msg)
virtual const bool evTimer (const CtrlMessage &msg)
virtual void Draw (void)

Private Member Functions

void ShowTip (const XPoint &DrawPoint)
void HideTip (void)
 Hides the tooltip.


Private Attributes

XRect galaxyRect
StarSystemcurSS
XPoint mp
int zoom
XRect zr
XScrollBar * sbh
XScrollBar * sbv
Timer * timer
 A pointer to a timer so that tooltips only appear after the mouse has been motionless for a bit.

XPoint lastMousePosition
 The last mouse position.

XLabel * tooltip

Constructor & Destructor Documentation

GalaxyScreen::GalaxyScreen void   ) 
 

Definition at line 5 of file galaxyscreen.cpp.

References timer, and tooltip.

00006 : curSS( 0 ) , zoom( 1 ) 
00007 {
00008         timer = new Timer( this );
00009         tooltip = new XLabel();
00010 }

GalaxyScreen::~GalaxyScreen void   )  [virtual]
 

Definition at line 13 of file galaxyscreen.cpp.

References timer, and tooltip.

00014 {
00015         if( timer )
00016                 delete timer;
00017         timer = 0;
00018         if( tooltip )
00019                 delete tooltip;
00020         tooltip = 0;
00021 }


Member Function Documentation

void GalaxyScreen::Draw void   )  [protected, virtual]
 

Definition at line 89 of file galaxyscreen.cpp.

References img, sbh, sbv, and zr.

00090 {
00091         XBox::Draw();
00092 
00093         zr.x = sbh->GetPosition();
00094         zr.y = sbv->GetPosition();
00095 
00096         XRect   dst( GetWindowRect() );
00097         Graf::SDL_StretchBlt( img , &zr , GetGDI() , &dst );
00098 }

const bool GalaxyScreen::evKeyUp const KeyboardMessage &  msg  )  [protected, virtual]
 

Definition at line 171 of file galaxyscreen.cpp.

References curSS, galaxyRect, sbh, sbv, timer, zoom, and zr.

00172 {
00173         bool ans = XImage::evKeyUp( msg );
00174 
00175         switch( msg.Key )
00176         {
00177                 case SDLK_o :
00178                         if( zoom > 1 )
00179                         {
00180                                 zoom -= 1;
00181                                 ans = true;
00182                                 timer->StopTimer();
00183                                 SetDirty();
00184                         }
00185                         break;
00186 
00187                 case SDLK_i :
00188                         if( zoom < 6 )
00189                         {
00190                                 zoom += 1;
00191                                 timer->StopTimer();
00192                                 ans = true;
00193                                 SetDirty();
00194                         }
00195                         break;
00196         }
00197 
00198         if( ans  )
00199         {
00200                 int     zoomfactor = (int)pow( 2.0 , zoom - 1.0 );
00201                 int     zw = galaxyRect.Width() / zoomfactor , zh = galaxyRect.Height() / zoomfactor;
00202 
00203                 zr = XRect( 0 , 0 , zw , zh );
00204                 if( curSS )
00205                 {
00206                         zr.x = max( 0 , min( curSS->x - zw / 2 , galaxyRect.Right() - zw ) );
00207                         zr.y = max( 0 , min( curSS->y - zh / 2 , galaxyRect.Bottom() - zh ) );
00208                 }
00209                 else
00210                 {
00211                         zr.x = galaxyRect.Center().x - zw / 2;
00212                         zr.y = galaxyRect.Center().y - zh / 2;
00213                 }
00214                 sbh->SetLimits( 0 , galaxyRect.Width() - zw );
00215                 sbh->SetPosition( zr.x );
00216                 sbv->SetLimits( 0 , galaxyRect.Height() - zh );
00217                 sbv->SetPosition( zr.y );
00218         }
00219         return ans;
00220 }

const bool GalaxyScreen::evMouseButtonUp const MouseMessage &  msg  )  [protected, virtual]
 

Definition at line 144 of file galaxyscreen.cpp.

References mp, and timer.

00145 {
00146         mp = msg.Point;
00147         timer->StopTimer();
00148         return XBox::evMouseButtonUp( msg );
00149 }

const bool GalaxyScreen::evMouseLClick const CtrlMessage &  msg  )  [protected, virtual]
 

Definition at line 151 of file galaxyscreen.cpp.

References ArsSendMessage, curSS, GetGalaxy(), StarSystem::InVicinity(), mp, timer, and ToGalaxy().

00152 {
00153         XBox::evMouseLClick( msg );
00154         
00155         const bool changed = (curSS != 0);
00156 
00157         XPoint  ans = ToGalaxy( mp );
00158         vector<StarSystem *>::iterator  pos = find_if( GetGalaxy().begin() , GetGalaxy().end() , bind2nd( mem_fun( &StarSystem::InVicinity ) , &ans ) );
00159         if( pos != GetGalaxy().end() )
00160                 curSS = *pos;
00161         else
00162                 curSS = 0;
00163 
00164         timer->StopTimer();
00165         if( changed )
00166                 ArsSendMessage( CtrlMessage( Message::CTRL_VALUECHANGE , GetParent() , this , (long int)curSS ) );
00167 
00168         return true;
00169 }

const bool GalaxyScreen::evMouseMove const MouseMessage &  msg  )  [protected, virtual]
 

Definition at line 117 of file galaxyscreen.cpp.

References ArsSendMessage, curSS, GetGalaxy(), HideTip(), StarSystem::InVicinity(), lastMousePosition, timer, ToGalaxy(), and tooltip.

00118 {
00119         bool    ans = XBox::evMouseMove( msg );
00120 
00121         if( HitTest( msg.Point ) == RELPOS_INSIDE )
00122         {
00123                 XPoint  ans = ToGalaxy( msg.Point );
00124                 vector<StarSystem *>::iterator  pos = find_if( GetGalaxy().begin() , GetGalaxy().end() , bind2nd( mem_fun( &StarSystem::InVicinity ) , &ans ) );
00125                 if(curSS == 0 )
00126                 {
00127                         if( pos != GetGalaxy().end() )
00128                                 ArsSendMessage( CtrlMessage( Message::CTRL_VALUECHANGE , GetParent() , this , (long int)*pos ) );
00129                         else
00130                                 ArsSendMessage( CtrlMessage( Message::CTRL_VALUECHANGE , GetParent() , this , 0 ) );
00131                         ans = true;
00132                 }
00133 
00134                 lastMousePosition = msg.Point;
00135                 timer->StopTimer();
00136                 if( tooltip->IsVisible() )
00137                         HideTip();
00138                 if( pos != GetGalaxy().end() )
00139                         timer->StartTimer( 2000 );
00140         }
00141         return ans;
00142 }

const bool GalaxyScreen::evTimer const CtrlMessage &  msg  )  [protected, virtual]
 

Definition at line 254 of file galaxyscreen.cpp.

References lastMousePosition, and ShowTip().

00255 {
00256         bool ans = XImage::evTimer( msg );
00257 
00258         if( msg.Destination() == this )
00259         {
00260                 ShowTip( lastMousePosition + XPoint( -6 , 18 ) );
00261                 ans = true;
00262         }
00263         return ans;
00264 }

void GalaxyScreen::HideTip void   )  [private]
 

Hides the tooltip.

Definition at line 248 of file galaxyscreen.cpp.

References tooltip.

Referenced by evMouseMove().

00249 {
00250         tooltip->HideWindow();
00251         tooltip->UpdateWindow( true );
00252 }

void GalaxyScreen::ResetGalaxyDisplay void   ) 
 

Definition at line 75 of file galaxyscreen.cpp.

References bkgnd, StarSystem::DrawInfluenceZones(), StarSystem::DrawInGalaxy(), galaxyRect, GetGalaxy(), and img.

Referenced by SetupWindow().

00076 {
00077         if( bkgnd )
00078         {
00079                 SDL_SetAlpha( bkgnd , SDL_SRCALPHA , fade );
00080                 SDL_BlitSurface( bkgnd , 0 , img , &galaxyRect );
00081         }
00082         else
00083                 SDL_FillRect( img , &galaxyRect , 0xff000000 );
00084 
00085         for_each( GetGalaxy().begin() , GetGalaxy().end() , bind2nd( mem_fun( &StarSystem::DrawInGalaxy ) , img ) );
00086         for_each( GetGalaxy().begin() , GetGalaxy().end() , bind2nd( mem_fun( &StarSystem::DrawInfluenceZones ) , img ) );
00087 }

const bool GalaxyScreen::SetupWindow const Message &  msg  )  [protected, virtual]
 

Definition at line 23 of file galaxyscreen.cpp.

References bkgnd, curSS, ePlayGame, galaxyRect, Cfg::GetCfg(), Cfg::Handler::GetCfgInt(), icstring, ResetGalaxyDisplay(), sbh, sbv, tooltip, zoom, and zr.

00024 {
00025         XBox::SetupWindow( msg );
00026         icstring str( "0 0 0 0  (fonth 12) (fg 0xff104c18) (bg 0xffacca70) (states S_RAISED|S_ALIGN_LEFT|S_ALIGN_TOP)" );
00027         tooltip->Init( str );
00028         tooltip->SetParent( this );
00029         tooltip->HideWindow();
00030 
00031         string  name = Cfg::GetCfg().GetCfgString( "DefaultParameters" , "ShapeName" , "" );
00032         if( !name.empty() )
00033                 ChangeImage( "" , name , "@images" );
00034         else if( id == -1 )
00035                 if( key.empty() )
00036                         id = Graf::LoadImg( fname.empty() ? sct : fname );
00037                 else
00038                         id = Graf::LoadImg( sct , key , fname );
00039 
00040 
00041         {
00042                 Cfg::Handler    &h = Cfg::GetCfg( "@Generator" );
00043                 galaxyRect.x = galaxyRect.y = 0;
00044                 galaxyRect.w = h.GetCfgInt( "Galaxy-coord" , "playW" );
00045                 galaxyRect.h = h.GetCfgInt( "Galaxy-coord" , "playH" );
00046         }
00047         SDL_Surface *sfc = Graf::Img( id );
00048         Graf::SDL_StretchBlt( sfc , 0 , bkgnd , &galaxyRect , true );
00049 
00050         MessageServer::Instance().RegisterMessageClient( this , Message::MOUSE_BUTTONDOWN );
00051         MessageServer::Instance().RegisterMessageClient( this , Message::MOUSE_BUTTONUP );
00052         MessageServer::Instance().RegisterMessageClient( this , Message::MOUSE_MOVE );
00053         MessageServer::Instance().RegisterMessageClient( this , Message::CTRL_LCLICK );
00054         MessageServer::Instance().RegisterMessageClient( this , Message::KEYBOARD_KEYUP );
00055         MessageServer::Instance().RegisterMessageClient( this , Message::CTRL_TIMER);
00056 
00057         curSS = 0;
00058         zoom = 1;
00059 
00060         ResetGalaxyDisplay();
00061         
00062         sbh = dynamic_cast<XScrollBar *>( Rsrc::GetAddr( ePlayGame )->GetArsObject( 43 ) );
00063         sbh->SetLimits( 0 , 0 );
00064         sbh->SetPosition( 0 );
00065         sbv = dynamic_cast<XScrollBar *>( Rsrc::GetAddr( ePlayGame )->GetArsObject( 42 ) );
00066         sbv->SetLimits( 0 , 0 );
00067         sbv->SetPosition( 0 );
00068 
00069         int     zw = galaxyRect.Width() / zoom , zh = galaxyRect.Height() / zoom;
00070         zr = XRect( 0 , 0 , zw , zh );
00071 
00072         return true;
00073 }

void GalaxyScreen::ShowTip const XPoint &  DrawPoint  )  [private]
 

Displays the tooltip

Parameters:
DrawPoint Where to poisition the top left corner of the tooltip

Definition at line 222 of file galaxyscreen.cpp.

References GetGalaxy(), StarSystem::InVicinity(), lastMousePosition, ToGalaxy(), and tooltip.

Referenced by evTimer().

00223 {
00224         if( !tooltip->IsVisible() )
00225         {
00226                 XPoint  ans = ToGalaxy( lastMousePosition );
00227                 vector<StarSystem *>::iterator  pos = find_if( GetGalaxy().begin() , GetGalaxy().end() , bind2nd( mem_fun( &StarSystem::InVicinity ) , &ans ) );
00228                 if( pos != GetGalaxy().end() )
00229                 {
00230                         tooltip->SetWndText( (*pos)->GetStarInfo() );
00231                         tooltip->x = max( (int)x , p.x );
00232                         tooltip->y = max( (int)y , p.y );
00233                         XPoint  p = tooltip->GetTextSize( tooltip->GetWindowText() );
00234                         tooltip->w = p.x + 10;
00235                         tooltip->h = p.y + 10;
00236                         if( tooltip->Right() > Right() )
00237                                 tooltip->x = Right() - tooltip->Width();
00238                         if( tooltip->Bottom() > Bottom() )
00239                                 tooltip->y = Bottom() - tooltip->Height();
00240 
00241                         tooltip->ShowWindow();
00242                         tooltip->UpdateWindow( true );
00243                 }
00244         }
00245 }

XPoint GalaxyScreen::ToGalaxy const XPoint &  mp  ) 
 

Definition at line 100 of file galaxyscreen.cpp.

References galaxyRect, zoom, and zr.

Referenced by evMouseLClick(), evMouseMove(), and ShowTip().

00101 {
00102         XRect   dst( GetWindowRect() );
00103         int     zoomfactor = (int)pow( 2.0 , zoom - 1.0 );
00104         int     zw = galaxyRect.Width() / zoomfactor , zh = galaxyRect.Height() / zoomfactor;
00105 
00106         double  rw = (double)dst.Width() / zw;
00107         double  rh = (double)dst.Height() / zh;
00108 
00109         XPoint  ans = mp - XPoint( x , y );
00110         
00111         ans.x = (int)(ans.x / rw);
00112         ans.y = (int)(ans.y / rh);
00113         return ans  + zr.TopLeft();
00114 }


Field Documentation

SDL_Surface * GalaxyScreen::bkgnd [static]
 

Definition at line 36 of file galaxyscreen.h.

Referenced by ResetGalaxyDisplay(), InitGalaxyScreen::Run(), SetupWindow(), and MainGame::~MainGame().

StarSystem* GalaxyScreen::curSS [private]
 

Definition at line 23 of file galaxyscreen.h.

Referenced by evKeyUp(), evMouseLClick(), evMouseMove(), and SetupWindow().

XRect GalaxyScreen::galaxyRect [private]
 

Definition at line 21 of file galaxyscreen.h.

Referenced by evKeyUp(), ResetGalaxyDisplay(), SetupWindow(), and ToGalaxy().

SDL_Surface * GalaxyScreen::img = 0 *GalaxyScreen::bkgnd [static]
 

Definition at line 3 of file galaxyscreen.cpp.

Referenced by Draw(), ResetGalaxyDisplay(), InitGalaxyScreen::Run(), SetupGalaxyScreen::Run(), and MainGame::~MainGame().

XPoint GalaxyScreen::lastMousePosition [private]
 

The last mouse position.

Definition at line 32 of file galaxyscreen.h.

Referenced by evMouseMove(), evTimer(), and ShowTip().

XPoint GalaxyScreen::mp [private]
 

Definition at line 24 of file galaxyscreen.h.

Referenced by evMouseButtonUp(), and evMouseLClick().

XScrollBar* GalaxyScreen::sbh [private]
 

Definition at line 29 of file galaxyscreen.h.

Referenced by Draw(), evKeyUp(), and SetupWindow().

XScrollBar * GalaxyScreen::sbv [private]
 

Definition at line 29 of file galaxyscreen.h.

Referenced by Draw(), evKeyUp(), and SetupWindow().

Timer* GalaxyScreen::timer [private]
 

A pointer to a timer so that tooltips only appear after the mouse has been motionless for a bit.

Definition at line 31 of file galaxyscreen.h.

Referenced by evKeyUp(), evMouseButtonUp(), evMouseLClick(), evMouseMove(), GalaxyScreen(), and ~GalaxyScreen().

XLabel* GalaxyScreen::tooltip [private]
 

Definition at line 58 of file galaxyscreen.h.

Referenced by evMouseMove(), GalaxyScreen(), HideTip(), SetupWindow(), ShowTip(), and ~GalaxyScreen().

int GalaxyScreen::zoom [private]
 

Definition at line 26 of file galaxyscreen.h.

Referenced by evKeyUp(), SetupWindow(), and ToGalaxy().

XRect GalaxyScreen::zr [private]
 

Definition at line 27 of file galaxyscreen.h.

Referenced by Draw(), evKeyUp(), SetupWindow(), and ToGalaxy().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:21 2003 for Borqueror by doxygen 1.3.3