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

nodes.c

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  AUTHOR: Wilson T
00004  *
00005  *   TITLE: nodes.c
00006  *
00007  *  DATE: April 28, 1993
00008  *
00009  *  PURPOSE:  Nodes definitions.
00010  *
00011  *************************************************************************/
00012 
00013 #include <graphics.h>
00014 #include <stdio.h>
00015 #include <math.h>
00016 
00017 #include"nodes.h"
00018 #include"map.h"
00019 
00020 void Nodes::set_constants(int Id, int colorfill, BOOLEAN state)
00021 {
00022   /*****************************************************************
00023 
00024     Flag states of Nodes...
00025 
00026       Activated - User input detected...
00027       BStatus - Whether the option is selected or not...
00028       Able    - Allow/disallow interaction with user...
00029 
00030    *****************************************************************/
00031 
00032   Activated   = False;
00033   BStatus   = Off;  // For now, may be a user-defined field later.
00034   Able      = state;
00035 
00036   NCOLORFILL=colorfill;
00037   IdNum = Id;
00038   Drawn = No;
00039   X=0; Y=0;
00040 }
00041 
00042 void Nodes::Init(Display *d, int x, int y)
00043 {
00044   NBOXSIZE=CCIRCLE+2*STOPRAD;
00045 
00046   X = x-NBOXSIZE/2; X2=X+NBOXSIZE;
00047   Y = y-NBOXSIZE/2; Y2=Y+NBOXSIZE;
00048 
00049   Disp = d;
00050   BkColor=Disp->GetBkColor();
00051 }
00052 
00053 void Nodes::Draw()
00054 {
00055   Disp->FastDraw();
00056 
00057   Disp->SetColor(BLACK);
00058 
00059   if(theMap.taxi(IdNum))  // Taxi Stop
00060     Disp->SetFillStyle(SOLID_FILL, YELLOW);
00061   else
00062     Disp->SetFillStyle(SOLID_FILL, GREEN);
00063   Disp->FillEllipse(X+NBOXSIZE/2, Y+NBOXSIZE/2-CCIRCLE/2+STOPRAD, STOPRAD, STOPRAD);
00064 
00065   if(theMap.bus(IdNum)) // Bus Stop
00066     Disp->SetFillStyle(SOLID_FILL, GREEN);
00067   else
00068     Disp->SetFillStyle(SOLID_FILL, YELLOW);
00069   Disp->FillEllipse(X+NBOXSIZE/2+CCIRCLE/2, Y+NBOXSIZE/2+2*STOPRAD-2, STOPRAD, STOPRAD);
00070 
00071   if(theMap.subway(IdNum))  // Subway Stop
00072     Disp->SetFillStyle(SOLID_FILL, RED);
00073   else if (theMap.taxi (IdNum))
00074     Disp->SetFillStyle(SOLID_FILL, YELLOW);
00075   else
00076     Disp->SetFillStyle(SOLID_FILL, GREEN);
00077   Disp->FillEllipse(X+NBOXSIZE/2-CCIRCLE/2, Y+NBOXSIZE/2+2*STOPRAD-2, STOPRAD, STOPRAD);
00078 
00079   if(Able)
00080     Disp->SetFillStyle(SOLID_FILL, NBOXCOLOR);
00081   else
00082     Disp->SetFillStyle(SOLID_FILL, NOFFCOLOR);
00083 
00084   int radius = (int)(CCIRCLE/2);
00085   Disp->SetColor(BLACK);
00086   Disp->FillEllipse(X+NBOXSIZE/2, Y+NBOXSIZE/2+STOPRAD, radius, radius);
00087 
00088   if(BStatus)
00089     fill_box();
00090 
00091   Disp->Done();
00092   Drawn=Yes;
00093 }
00094 
00095 void Nodes::empty_box(int color)
00096 {
00097   Disp->FastDraw();
00098 
00099   Disp->SetFillStyle(SOLID_FILL, color);
00100   int radius = (int)(CCIRCLE/2);
00101   Disp->SetColor(BLACK);
00102   Disp->FillEllipse(X+NBOXSIZE/2, Y+NBOXSIZE/2+STOPRAD, radius, radius);
00103 
00104   Disp->Done();
00105 
00106   BStatus = Off;
00107 }
00108 
00109 void Nodes::fill_box()
00110 {
00111   Disp->FastDraw();
00112 
00113   Disp->SetFillStyle(SOLID_FILL, NCOLORFILL);
00114   Disp->SetColor(NCOLORFILL);
00115 
00116   int radius = (int)(CCIRCLE/2);
00117   Disp->SetColor(BLACK);
00118   Disp->FillEllipse(X+NBOXSIZE/2, Y+NBOXSIZE/2+STOPRAD, radius-NFILLSIZE, radius-NFILLSIZE);
00119 
00120   Disp->Done();
00121 
00122   BStatus = On;
00123 }
00124 
00125 void Nodes::animate_frame()
00126 {
00127   Disp->FastDraw();
00128 
00129   if (Activated)
00130     Disp->SetColor(BLACK);
00131   else
00132     Disp->SetColor(NBOXCOLOR);
00133 
00134   Disp->SetLineStyle(SOLID_LINE, 0, NFRAME);
00135 
00136   int radius = (int)(CCIRCLE/2);
00137   Disp->Circle(X+NBOXSIZE/2, Y+NBOXSIZE/2+STOPRAD, radius-1);
00138 
00139   Disp->Done();
00140 }
00141 
00142 Message Nodes::Dispatch(Message &msg)
00143 {
00144   switch(msg.origin) {
00145     case MouseMsg:
00146       return mouse_msg(msg);
00147     case KeyMsg:
00148       return key_msg(msg);
00149     case GodMsg:
00150       return command_msg(msg);
00151   }
00152   return msg;
00153 }
00154 
00155 Message Nodes::mouse_msg(Message &msg)
00156 {
00157   if (ButtonBounds(msg.d1, msg.d2) && Able) {
00158     switch(msg.code) {
00159       case LMouseDown:
00160         Activated = True;
00161         animate_frame();
00162         return Acknowledged;
00163       case LMouseStillDown:
00164         if(!Activated) {
00165           Activated = True;
00166           animate_frame();
00167         }
00168         return NullMsg;
00169       case LMouseUp:
00170         Activated = False;
00171         BStatus = BStatus? Off : On;
00172         animate_frame();
00173         animate_box();
00174         return Message(ButtonMsg, Status, IdNum, BStatus);
00175       default:
00176         return NullMsg;
00177     }
00178   }
00179   if(msg.code==LMouseStillDown && Activated && Able) {
00180     Activated = False;
00181     animate_frame();
00182     animate_box();
00183   }
00184   return NullMsg;
00185 }
00186 
00187 Message Nodes::command_msg(Message &msg)
00188 {
00189   if(msg.d1 != IdNum)
00190     return NullMsg;
00191 
00192   switch (msg.code) {
00193     case Disable:
00194       animate_box();
00195       disable_box();
00196       return Acknowledged;
00197     case Enable:
00198       enable_box();
00199       return Acknowledged;
00200     case RequestStatus:
00201       return Message(ButtonMsg, Status, IdNum, (int)status());
00202   }
00203   return NullMsg;
00204 }
00205 
00206 Message Nodes::key_msg(Message &)
00207 {
00208 /*  if (KeyBounds(msg.d1, msg.d2) && Able)
00209       return NullMsg; */
00210 
00211 return NullMsg;
00212 }
00213 

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