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

mapwin.c

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  FILE: mapwin.c
00004  *  AUTHOR: Wilson T
00005  *  DATE: 30 April 1993
00006  *  PURPOSE:
00007  *
00008  **************************************************************************/
00009 
00010 #include <assert.h>
00011 #include <string.h>
00012 #include <stdlib.h>
00013 #include "mapwin.h"
00014 #include "map.h"
00015 
00016 const unsigned lines[3] = { 0xFC00, 0x03E0, 0x001F};
00017 
00018 
00019 MapWindow::MapWindow (void)
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 }
00035 
00036 
00037 MapWindow::~MapWindow (void)
00038 {
00039   delete NodeList;
00040 }
00041 
00042 
00043 void MapWindow::Init (Display *d, int x, int 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 }
00064 
00065 
00066 void MapWindow::AllocNodes (void)
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 }
00082 
00083 
00084 void MapWindow::Draw (void)
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 }
00102 
00103 void MapWindow::EnableNodes(MoveList &mlist, int color)
00104 {
00105   if(mlist.Reset()) {
00106     do {
00107       NodeList[mlist.GetCurrent()->Node]->EnableNode(color);
00108     } while(mlist.Next());
00109   }
00110 }
00111 
00112 void MapWindow::DisableNodes(MoveList &mlist)
00113 {
00114   if(mlist.Reset()) {
00115     do {
00116       NodeList[mlist.GetCurrent()->Node]->DisableNode();
00117     } while(mlist.Next());
00118   }
00119 }
00120 
00121 void MapWindow::HilightNode(int idnum, int color)
00122 {
00123   NodeList[idnum]->ChangeStatus(On, color);
00124 }
00125 
00126 void MapWindow::UnHilightNode(int idnum)
00127 {
00128   NodeList[idnum]->ChangeStatus(Off);
00129 }
00130 
00131 void MapWindow::DrawLines (void)
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 }
00150 
00151 void MapWindow::ConnectNode(int node1, int node2)
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 }
00236 
00237 /*
00238 void MapWindow::ConnectNode(int node1, int node2)
00239 {
00240   int x, y, x2, y2, i=0;
00241 
00242   x=theMap.x(node1); y=theMap.y(node1);
00243   x2=theMap.x(node2); y2=theMap.y(node2);
00244 
00245   Scale (x, y);
00246   Scale (x2, y2);
00247 
00248 //  i=theMap.taxi(node1, node2)+theMap.bus(node1, node2)+
00249 //    theMap.subway(node1, node2);
00250 
00251   for(int count=0; count<3; count++) {
00252     ClientD->SetLineStyle(USERBIT_LINE, lines[count], TransWidth);
00253     switch(count) {
00254       case 0: // Taxi
00255         if(theMap.taxi(node1, node2))
00256           ClientD->SetColor(YELLOW);
00257         else if (theMap.bus (node1, node2))
00258           ClientD->SetColor(GREEN);
00259         else
00260           ClientD->SetColor (RED);
00261         break;
00262       case 1:
00263         if(theMap.bus(node1, node2))
00264           ClientD->SetColor(GREEN);
00265         else if (theMap.taxi (node1, node2))
00266           ClientD->SetColor(YELLOW);
00267         else
00268           ClientD->SetColor (RED);
00269         break;
00270       case 2:
00271         if(theMap.subway(node1, node2))
00272           ClientD->SetColor(RED);
00273         else if (theMap.taxi (node1, node2))
00274           ClientD->SetColor(YELLOW);
00275         else
00276           ClientD->SetColor(GREEN);
00277         break;
00278     }
00279     ClientD->Line(x, y, x2, y2);
00280   }
00281   ClientD->SetLineStyle(SOLID_LINE, 0, 1);
00282 }
00283 */
00284 void MapWindow::Scale (int& x, int& y)
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 }
00298 
00299 

Generated on Sun Jul 6 23:07:15 2003 for Scotland Yard by doxygen1.2.15