Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

MapWindow Class Reference

#include <mapwin.h>

Inheritance diagram for MapWindow:

Window ScrnObj List of all members.

Public Methods

 MapWindow (void)
 ~MapWindow (void)
void Init (Display *, int, int)
void Draw (void)
void EnableNodes (MoveList &, int)
void DisableNodes (MoveList &)
void HilightNode (int, int)
void UnHilightNode (int)

Private Methods

void AllocNodes (void)
void DrawLines (void)
void ConnectNode (int node1, int node2)
void Scale (int &, int &)
void NewConnectNode (int, int, byte)

Private Attributes

int NNodes
Nodes ** NodeList

Constructor & Destructor Documentation

MapWindow::MapWindow void   
 

Definition at line 19 of file mapwin.c.

References Window::BkColor, Window::BorderColor, Window::ClientD, Window::CliX1, Window::CliX2, Window::CliY1, Window::CliY2, ScrnObj::Drawn, False, MapWinXDim, MapWinYDim, NNodes, NodeList, Window::Title, Window::TitleColor, Window::TitleD, Window::TX1, Window::TX2, Window::TY1, Window::TY2, Window::XDim, and Window::YDim.

00020 {
00021   XDim = MapWinXDim;  YDim = MapWinYDim;
00022   CliX1 = CliY1 = CliX2 = CliY2 = 0;
00023   TX1 = TY1 = TX2 = TY2 = 0;
00024   BorderColor = RED;
00025   BkColor = LIGHTGRAY;
00026   TitleColor = WHITE;
00027   Title = NULL;
00028   Title = new char[80];
00029   strcpy(Title, "- Ye Olde Map of London -");
00030   ClientD = TitleD = NULL;
00031   NodeList = NULL;
00032   NNodes = 0;
00033   Drawn = False;
00034 }

MapWindow::~MapWindow void   
 

Definition at line 37 of file mapwin.c.

References NodeList.

00038 {
00039   delete NodeList;
00040 }


Member Function Documentation

void MapWindow::AllocNodes void    [private]
 

Definition at line 66 of file mapwin.c.

References Display::Add(), Window::ClientD, NNodes, NodeList, Off, and Scale().

Referenced by Init().

00067 {
00068   int px, py;
00069 
00070   NNodes = theMap.num_nodes ();
00071   NodeList = new Nodes* [NNodes+1];
00072     assert (NodeList != 0);
00073 
00074   for (int i=1; i<=NNodes; i++) {
00075     NodeList[i] = new Nodes(i, Off);
00076     assert (NodeList[i] != NULL);
00077     px=theMap.x(i); py=theMap.y(i);
00078     Scale (px, py);
00079     ClientD->Add(NodeList[i], px, py);
00080   }
00081 }

void MapWindow::ConnectNode int    node1,
int    node2
[private]
 

Definition at line 151 of file mapwin.c.

References Window::ClientD, Viewport::Line(), Scale(), Viewport::SetColor(), and Viewport::SetLineStyle().

Referenced by DrawLines().

00152 {
00153   const int Spacing=2;
00154 
00155   int x, y, x2, y2, i=0, px1[3], py1[3], px2[3], py2[3], face;
00156 
00157   x=theMap.x(node1); y=theMap.y(node1);
00158   x2=theMap.x(node2); y2=theMap.y(node2);
00159 
00160   Scale (x, y);
00161   Scale (x2, y2);
00162 
00163   i=0;
00164   if (theMap.taxi(node1, node2)) i++;
00165   if (theMap.bus(node1, node2)) i++;
00166   if (theMap.subway(node1, node2)) i++;
00167 
00168   if((x<x2)&&(y>y2)) face=0;
00169   else if((x>x2)&&(y>y2)) face=1;
00170   else if((x>x2)&&(y<y2)) face=0;
00171   else if((x<x2)&&(y<y2)) face=1;
00172   else face=1;
00173 
00174   switch(face) {
00175     case 0:
00176       px1[0]=x-Spacing; py1[0]=y-Spacing;
00177       px1[1]=x;     py1[1]=y;
00178       px1[2]=x+Spacing; py1[2]=y+Spacing;
00179       px2[0]=x2-Spacing;  py2[0]=y2-Spacing;
00180       px2[1]=x2;    py2[1]=y2;
00181       px2[2]=x2+Spacing;  py2[2]=y2+Spacing;
00182       break;
00183     case 1:
00184       px1[0]=x+Spacing; py1[0]=y-Spacing;
00185       px1[1]=x;     py1[1]=y;
00186       px1[2]=x-Spacing; py1[2]=y+Spacing;
00187       px2[0]=x2+Spacing;  py2[0]=y2-Spacing;
00188       px2[1]=x2;    py2[1]=y2;
00189       px2[2]=x2-Spacing;  py2[2]=y2+Spacing;
00190       break;
00191   }
00192 
00193   int which;
00194   for (int count=0; count<i; count++) {
00195     ClientD->SetLineStyle(SOLID_LINE, 0, Spacing);
00196     switch(count) {
00197       case 0: // Taxi
00198         if(theMap.taxi(node1, node2))
00199           ClientD->SetColor(YELLOW), which=0;
00200         else if (theMap.bus (node1, node2))
00201           ClientD->SetColor(GREEN), which=1;
00202         else {
00203           ClientD->SetColor (RED);
00204           ClientD->SetLineStyle(SOLID_LINE, 0, 3);
00205           which=2;
00206         }
00207         break;
00208       case 1:
00209         if(theMap.subway(node1, node2)) {
00210           ClientD->SetColor (RED);
00211           ClientD->SetLineStyle(SOLID_LINE, 0, 3);
00212           which=2;
00213         }
00214         else if (theMap.bus (node1, node2))
00215           ClientD->SetColor(GREEN), which=1;
00216         else
00217           ClientD->SetColor(YELLOW), which=0;
00218         break;
00219       case 2:
00220         if(theMap.bus(node1, node2))
00221           ClientD->SetColor(GREEN), which=1;
00222         else if (theMap.taxi (node1, node2))
00223           ClientD->SetColor(YELLOW), which=0;
00224         else {
00225           ClientD->SetColor (RED);
00226           ClientD->SetLineStyle(SOLID_LINE, 0, 3);
00227           which=2;
00228         }
00229         break;
00230     }
00231 
00232     ClientD->Line(px1[which], py1[which], px2[which], py2[which]);
00233   }
00234   ClientD->SetLineStyle(SOLID_LINE, 0, 1);
00235 }

void MapWindow::DisableNodes MoveList  
 

Definition at line 112 of file mapwin.c.

References MoveList::GetCurrent(), MoveList::Next(), Move::Node, NodeList, and MoveList::Reset().

Referenced by UserInterface::FlashNodes(), and UserInterface::GetPlayerMove().

00113 {
00114   if(mlist.Reset()) {
00115     do {
00116       NodeList[mlist.GetCurrent()->Node]->DisableNode();
00117     } while(mlist.Next());
00118   }
00119 }

void MapWindow::Draw void    [virtual]
 

Reimplemented from Window.

Definition at line 84 of file mapwin.c.

References Viewport::Clear(), Window::ClientD, ScrnObj::Disp, Viewport::Done(), Display::Draw(), Window::DrawBorder(), DrawLines(), ScrnObj::Drawn, Window::DrawTitle(), Viewport::FastDraw(), Window::PrepScreen(), and True.

00085 {
00086   if (!Drawn) {
00087     assert (Disp != NULL);
00088     Disp->FastDraw ();
00089     PrepScreen ();
00090     DrawBorder ();
00091 
00092     if (TitleD)
00093       DrawTitle ();
00094 
00095     ClientD->Clear ();
00096     DrawLines ();
00097     ClientD->Draw ();
00098     Disp->Done ();
00099     Drawn = True;
00100   }
00101 }

void MapWindow::DrawLines void    [private]
 

Definition at line 131 of file mapwin.c.

References ConnectNode().

Referenced by Draw().

00132 {
00133   int num_lines=0, node, i, j, k;
00134 
00135   for(i=1; i<=theMap.num_nodes(); i++) {
00136     node= i;
00137     num_lines=theMap.num_connections(i);
00138     for(j=0; j<num_lines; j++)
00139     {
00140       int ToNode = theMap.connected_to (i, j);
00141       for (k= 0; k < theMap.num_connections(i, j); k++) {
00142       ConnectNode(node, theMap.connected_to(i, j, k));
00143       node= theMap.connected_to(i, j, k);
00144       }
00145       if (i < ToNode)
00146       ConnectNode(node, theMap.connected_to(i, j));
00147     }
00148   }
00149 }

void MapWindow::EnableNodes MoveList  ,
int   
 

Definition at line 103 of file mapwin.c.

References MoveList::GetCurrent(), MoveList::Next(), Move::Node, NodeList, and MoveList::Reset().

Referenced by UserInterface::FlashNodes().

00104 {
00105   if(mlist.Reset()) {
00106     do {
00107       NodeList[mlist.GetCurrent()->Node]->EnableNode(color);
00108     } while(mlist.Next());
00109   }
00110 }

void MapWindow::HilightNode int   ,
int   
 

Definition at line 121 of file mapwin.c.

References Nodes::ChangeStatus(), NodeList, and On.

Referenced by UserInterface::EndTurn(), UserInterface::FlashNodes(), and UserInterface::ShowAllPlayers().

00122 {
00123   NodeList[idnum]->ChangeStatus(On, color);
00124 }

void MapWindow::Init Display  ,
int   ,
int   
[virtual]
 

Reimplemented from Window.

Definition at line 43 of file mapwin.c.

References AllocNodes(), Window::BkColor, Window::BorderColor, Window::CalcBorder(), Window::CalcTitle(), Window::ClientD, Window::CliX1, Window::CliX2, Window::CliY1, Window::CliY2, ScrnObj::Disp, Viewport::SetBkColor(), Viewport::SetColor(), Viewport::SetTextJustify(), Viewport::SetTextStyle(), Window::TitleColor, Window::TitleD, TitleFont, TitleFontSize, Window::TX1, Window::TX2, Window::TY1, Window::TY2, ScrnObj::X, and ScrnObj::Y.

00044 {
00045   Disp = d;
00046   X = x;  Y = y;
00047 
00048   CalcBorder ();
00049   if (Title) {
00050     CalcTitle ();
00051     TitleD = new Display (Disp, TX1, TY1, TX2, TY2);
00052     assert (TitleD != 0);
00053     TitleD->SetBkColor (BorderColor);
00054     TitleD->SetTextJustify (CENTER_TEXT, TOP_TEXT);
00055     TitleD->SetTextStyle (TitleFont, HORIZ_DIR, TitleFontSize);
00056     TitleD->SetColor (TitleColor);
00057   }
00058 
00059   ClientD = new Display (Disp, CliX1, CliY1, CliX2, CliY2);
00060   assert (ClientD != 0);
00061   ClientD->SetBkColor (BkColor);
00062   AllocNodes ();
00063 }

void MapWindow::NewConnectNode int   ,
int   ,
byte   
[private]
 

void MapWindow::Scale int &   ,
int &   
[private]
 

Definition at line 284 of file mapwin.c.

References Window::ClientD, Viewport::GetMaxX(), and Viewport::GetMaxY().

Referenced by AllocNodes(), and ConnectNode().

00285 {
00286   const float ScreenPortion=.98;
00287 
00288   int maxx, maxy;
00289   maxx = theMap.max_x ();
00290   maxy = theMap.max_y ();
00291 
00292   float mx=ClientD->GetMaxX()*ScreenPortion;
00293   float my=ClientD->GetMaxY()*ScreenPortion;
00294 
00295   x = x * (mx / maxx);
00296   y = y * (my / maxy);
00297 }

void MapWindow::UnHilightNode int   
 

Definition at line 126 of file mapwin.c.

References Nodes::ChangeStatus(), NodeList, and Off.

Referenced by UserInterface::BeginTurn(), UserInterface::EndTurn(), UserInterface::FlashNodes(), and UserInterface::GetPlayerMove().

00127 {
00128   NodeList[idnum]->ChangeStatus(Off);
00129 }


Member Data Documentation

int MapWindow::NNodes [private]
 

Definition at line 24 of file mapwin.h.

Referenced by AllocNodes(), and MapWindow().

Nodes** MapWindow::NodeList [private]
 

Definition at line 25 of file mapwin.h.

Referenced by AllocNodes(), DisableNodes(), EnableNodes(), HilightNode(), MapWindow(), UnHilightNode(), and ~MapWindow().


The documentation for this class was generated from the following files:
Generated on Sun Jul 6 23:07:17 2003 for Scotland Yard by doxygen1.2.15