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

PushButton Class Reference

#include <button.h>

Inheritance diagram for PushButton:

ScrnObj List of all members.

Public Methods

 PushButton (char *, int, int)
 PushButton (char *, int, int, int, int)
void Init (Display *, int, int)
 ~PushButton ()
void Draw ()
void Erase ()
BOOLEAN ButtonBounds (int, int)
BOOLEAN ButtonStatus ()
int ButtonId ()
Message Dispatch (Message &)
int GetXDim ()
int GetYDim ()

Private Methods

void set_constants (char *, int, int)
void image_size ()
void image_size (int, int)
void draw_shadows (SHADOW_STYLE, int)
void draw_frame ()
void name_button ()
void depress_button ()
void redraw ()
void animate_button ()

Private Attributes

void * surface
int string_height
int string_width
int X2
int Y2
int xdim
int ydim
char string [80]
int Color
int IdNum
BOOLEAN Activated
BOOLEAN Drawn

Constructor & Destructor Documentation

PushButton::PushButton char *   ,
int   ,
int   
[inline]
 

Definition at line 69 of file button.h.

References image_size(), set_constants(), ScrnObj::X, X2, xdim, ScrnObj::Y, Y2, and ydim.

00070   {set_constants(name, color, Id); image_size();
00071    xdim=X2-X; ydim=Y2-Y;}

PushButton::PushButton char *   ,
int   ,
int   ,
int   ,
int   
[inline]
 

Definition at line 73 of file button.h.

References image_size(), set_constants(), ScrnObj::X, X2, xdim, ScrnObj::Y, Y2, and ydim.

00074   {set_constants(name, color, Id); image_size(x2, y2);
00075    xdim=X2-X; ydim=Y2-Y;}

PushButton::~PushButton   [inline]
 

Definition at line 47 of file button.h.

References Erase(), and surface.

00048     {if (Drawn) Erase(); delete surface;}


Member Function Documentation

void PushButton::animate_button   [inline, private]
 

Definition at line 84 of file button.h.

References depress_button(), and redraw().

Referenced by Dispatch().

00085   {if (Activated) depress_button(); else redraw();}

BOOLEAN PushButton::ButtonBounds int   ,
int   
 

Definition at line 124 of file button.c.

References False, SHADOWS, True, ScrnObj::X, X2, ScrnObj::Y, and Y2.

Referenced by Dispatch().

00125 {
00126   // Mouse will call and supply the coordinates of its position
00127   //  It's up to the button itself to determine it's bounds.
00128 
00129   BOOLEAN flag = False;
00130 
00131   if ((Mx<=X2-SHADOWS) && (Mx>=X) && (My<=Y2-SHADOWS) && (My>=Y))
00132     flag = True;
00133   else
00134     flag = False;
00135 
00136   return flag;
00137 }

int PushButton::ButtonId   [inline]
 

Definition at line 90 of file button.h.

References IdNum.

00091   {return IdNum;}

BOOLEAN PushButton::ButtonStatus   [inline]
 

Definition at line 87 of file button.h.

References Activated, and BOOLEAN.

00088   {return Activated;}

void PushButton::depress_button   [private]
 

Definition at line 82 of file button.c.

References BOTTOM_RIGHT, ScrnObj::Disp, Viewport::Done(), draw_shadows(), Viewport::FastDraw(), FRAME, Viewport::Line(), name_button(), Viewport::SetColor(), TOP_LEFT, ScrnObj::X, X2, ScrnObj::Y, and Y2.

Referenced by animate_button().

00083 {
00084   Disp->FastDraw();
00085 
00086   // Re-modified for test...
00087   draw_shadows(BOTTOM_RIGHT, LIGHTGRAY);
00088   draw_shadows(TOP_LEFT, LIGHTGRAY);
00089   Disp->SetColor(DARKGRAY);
00090   Disp->Line(X+FRAME, Y+FRAME, X2-FRAME, Y+FRAME);
00091   Disp->Line(X+FRAME, Y+FRAME, X+FRAME, Y2-FRAME);
00092 
00093   name_button();
00094   Disp->Done();
00095 }

Message PushButton::Dispatch Message   [virtual]
 

Reimplemented from ScrnObj.

Definition at line 177 of file button.c.

References Activated, animate_button(), ButtonBounds(), ButtonMsg, ButtonPress, Message::code, Message::d1, Message::d2, False, IdNum, LMouseDown, LMouseUp, MouseMsg, MouseStillDown, Message::origin, and True.

00178 {
00179   switch(msg.origin) {
00180     case MouseMsg:
00181       if (ButtonBounds(msg.d1, msg.d2)) {
00182         switch(msg.code) {
00183           case LMouseDown:
00184             Activated = True;
00185             animate_button();
00186             return Acknowledged;
00187           case MouseStillDown:
00188             if(!Activated) {
00189               Activated = True;
00190               animate_button();
00191             }
00192             return Acknowledged;
00193           case LMouseUp:
00194             Activated = False;
00195             animate_button();
00196             return Message (ButtonMsg, ButtonPress, IdNum);
00197           default:
00198             return NullMsg;
00199         }
00200       }
00201       if(msg.code==MouseStillDown && Activated) {
00202         Activated = False;
00203         animate_button();
00204       }
00205       return NullMsg;
00206 
00207 /*    case KeyMsg:
00208       if (KeyBounds(msg.d1, msg.d2)
00209       return NullMsg;           */
00210   }
00211 
00212 return NullMsg;
00213 }

void PushButton::Draw   [virtual]
 

Implements ScrnObj.

Definition at line 47 of file button.c.

References Activated, Viewport::Bar(), BOTTOM_RIGHT, ScrnObj::Disp, Viewport::Done(), draw_frame(), draw_shadows(), Drawn, False, Viewport::FastDraw(), FRAME, name_button(), Viewport::SetFillStyle(), TOP_LEFT, ScrnObj::X, X2, ScrnObj::Y, Y2, and Yes.

00048 {
00049   Activated = False;
00050   Drawn = Yes;
00051 
00052   Disp->FastDraw();
00053   Disp->SetFillStyle(SOLID_FILL, LIGHTGRAY);
00054   Disp->Bar(X+FRAME, Y+FRAME, X2-FRAME, Y2-FRAME);
00055 
00056   draw_shadows(BOTTOM_RIGHT, DARKGRAY);
00057   draw_shadows(TOP_LEFT, WHITE);
00058   draw_frame();
00059   name_button();
00060   Disp->Done();
00061 }

void PushButton::draw_frame   [private]
 

Definition at line 139 of file button.c.

References ScrnObj::Disp, FRAME, Viewport::Rectangle(), Viewport::SetColor(), Viewport::SetLineStyle(), ScrnObj::X, X2, ScrnObj::Y, and Y2.

Referenced by Draw().

00140 {
00141   Disp->SetLineStyle(SOLID_LINE, 0, FRAME+1);
00142   Disp->SetColor(BLACK);
00143   Disp->Rectangle(X, Y, X2, Y2);
00144   Disp->SetLineStyle(SOLID_LINE, 0, 1);
00145 }

void PushButton::draw_shadows SHADOW_STYLE   ,
int   
[private]
 

Definition at line 97 of file button.c.

References BOTTOM_LEFT, BOTTOM_RIGHT, ScrnObj::Disp, FRAME, Viewport::Line(), Viewport::SetColor(), SHADOW_STYLE, SHADOWS, TOP_LEFT, TOP_RIGHT, ScrnObj::X, X2, ScrnObj::Y, and Y2.

Referenced by depress_button(), Draw(), and redraw().

00098 {
00099   // Side shadows...
00100   int x = X+FRAME, y = Y+FRAME, x2 = X2-SHADOWS+FRAME, y2 = Y2-SHADOWS+FRAME;
00101 
00102   Disp->SetColor(color);
00103   for(int count=0; count<SHADOWS; count++)
00104   {
00105     switch(style) {
00106       case TOP_LEFT:
00107         Disp->Line(x+count, y+count, x2-count, y+count);
00108         Disp->Line(x+count, y+count, x+count, y2-count);
00109       break;
00110       case BOTTOM_RIGHT:
00111         Disp->Line(x+count, y2-count, x2-count, y2-count);
00112         Disp->Line(x2-count, y+count, x2-count, y2-count);
00113       break;
00114       case TOP_RIGHT:
00115         // Undefined for now...
00116       break;
00117       case BOTTOM_LEFT:
00118         // Undefined for now...
00119       break;
00120     }
00121   }
00122 }

void PushButton::Erase   [virtual]
 

Reimplemented from ScrnObj.

Definition at line 63 of file button.c.

References Viewport::Bar(), ScrnObj::Disp, Drawn, Viewport::GetBkColor(), No, Viewport::SetFillStyle(), ScrnObj::X, X2, ScrnObj::Y, Y2, and Yes.

Referenced by ~PushButton().

00064 {
00065   if(Drawn == Yes) {
00066     Drawn = No;
00067     Disp->SetFillStyle(SOLID_FILL, Disp->GetBkColor());
00068     Disp->Bar(X, Y, X2, Y2);
00069   }
00070 }

int PushButton::GetXDim   [inline, virtual]
 

Reimplemented from ScrnObj.

Definition at line 93 of file button.h.

References xdim.

Referenced by CPanelWindow::Init(), UserInterface::Intro(), MessageWin(), UserInterface::ShowSpyMoves(), and UserInterface::UFWOOM().

00094   {return xdim;}

int PushButton::GetYDim   [inline, virtual]
 

Reimplemented from ScrnObj.

Definition at line 96 of file button.h.

References ydim.

Referenced by CPanelWindow::Init(), UserInterface::Intro(), MessageWin(), UserInterface::ShowSpyMoves(), UserInterface::TransPop(), and UserInterface::UFWOOM().

00097   {return ydim;}

void PushButton::image_size int   ,
int   
[inline, private]
 

Definition at line 77 of file button.h.

References ScrnObj::X, X2, ScrnObj::Y, and Y2.

00078   {X2 = X+x2; Y2 = Y+y2;}

void PushButton::image_size   [inline, private]
 

Definition at line 80 of file button.h.

References BORDERX, BORDERY, FRAME, SHADOWS, string_height, string_width, ScrnObj::X, X2, ScrnObj::Y, and Y2.

Referenced by PushButton().

00081   {X2 = X+string_width+(2*BORDERX)+(2*SHADOWS)+(2*FRAME);
00082   Y2 = Y+string_height+(2*BORDERY)+(2*SHADOWS)+(2*FRAME);}

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

Reimplemented from ScrnObj.

Definition at line 39 of file button.c.

References ScrnObj::Disp, ScrnObj::X, X2, ScrnObj::Y, and Y2.

00040 {
00041   X = x; X2+=X;
00042   Y = y; Y2+=Y;
00043 
00044   Disp = d;
00045 }

void PushButton::name_button   [private]
 

Definition at line 147 of file button.c.

References BORDERX, BORDERY, byte, Color, ScrnObj::Disp, FONT, FONT_SIZE, FRAME, Viewport::GetImage(), Viewport::GetMaxX(), Viewport::GetMaxY(), Viewport::OutTextXY(), Viewport::PutImage(), Viewport::Rectangle(), Viewport::SetColor(), Viewport::SetTextJustify(), Viewport::SetTextStyle(), SHADOWS, string, surface, ScrnObj::X, X2, ScrnObj::Y, and Y2.

Referenced by depress_button(), Draw(), and redraw().

00148 {
00149   int displacement, x, y, x2, y2;
00150 
00151   displacement = (Activated)? 1 : 0;
00152 
00153   x = X+BORDERX+SHADOWS+FRAME+displacement+1;
00154   y = Y+BORDERY+SHADOWS+FRAME+displacement-2;
00155   x2  = X2-BORDERX-SHADOWS-FRAME+displacement+1;
00156   y2  = Y2-BORDERY-SHADOWS-FRAME+displacement+1;
00157 
00158   Disp->SetColor(LIGHTGRAY);
00159   Disp->Rectangle(x-displacement, y-displacement, x2+1, y2+1);
00160 
00161   Viewport surf (Disp, x, y, x2, y2);
00162 
00163   if(surface==NULL) {
00164     int s = imagesize(x, y, x2, y2);
00165     surface = (void*) new byte [s];
00166     assert (surface != NULL);
00167     surf.SetColor(Color);
00168     surf.SetTextStyle (FONT, HORIZ_DIR, FONT_SIZE);
00169     surf.SetTextJustify(CENTER_TEXT, CENTER_TEXT);
00170     surf.OutTextXY(surf.GetMaxX()/2, surf.GetMaxY()/2, string);
00171     surf.GetImage(0, 0, surf.GetMaxX(), surf.GetMaxY(), surface);
00172   }
00173   else
00174     surf.PutImage(0, 0, surface, COPY_PUT);
00175 }

void PushButton::redraw   [private]
 

Definition at line 72 of file button.c.

References BOTTOM_RIGHT, ScrnObj::Disp, Viewport::Done(), draw_shadows(), Viewport::FastDraw(), name_button(), and TOP_LEFT.

Referenced by animate_button().

00073 {
00074   Disp->FastDraw();
00075 
00076   draw_shadows(BOTTOM_RIGHT, DARKGRAY);
00077   draw_shadows(TOP_LEFT, WHITE);
00078   name_button();
00079   Disp->Done();
00080 }

void PushButton::set_constants char *   ,
int   ,
int   
[private]
 

Definition at line 20 of file button.c.

References Activated, Color, Drawn, False, FONT, FONT_SIZE, IdNum, No, Viewport::SetTextStyle(), string, string_height, string_width, surface, Viewport::TextHeight(), Viewport::TextWidth(), ScrnObj::X, and ScrnObj::Y.

Referenced by PushButton().

00021 {
00022   Activated   = False;
00023   Color   = color;
00024   surface   = NULL;
00025   strcpy(string, name);
00026   IdNum = Id;
00027   Drawn = No;
00028   X=0; Y=0;
00029 
00030   Viewport surf;
00031   surf.SetTextStyle(FONT, HORIZ_DIR, FONT_SIZE);
00032 
00033   string_height = surf.TextHeight(string);
00034   // Adjust for differing fonts...
00035   string_height = (int)(string_height+(string_height*.33));
00036   string_width  = surf.TextWidth(string);
00037 }


Member Data Documentation

BOOLEAN PushButton::Activated [private]
 

Definition at line 41 of file button.h.

Referenced by ButtonStatus(), Dispatch(), Draw(), and set_constants().

int PushButton::Color [private]
 

Definition at line 40 of file button.h.

Referenced by name_button(), and set_constants().

BOOLEAN PushButton::Drawn [private]
 

Reimplemented from ScrnObj.

Definition at line 41 of file button.h.

Referenced by Draw(), Erase(), and set_constants().

int PushButton::IdNum [private]
 

Definition at line 40 of file button.h.

Referenced by ButtonId(), Dispatch(), and set_constants().

char PushButton::string[80] [private]
 

Definition at line 39 of file button.h.

Referenced by name_button(), and set_constants().

int PushButton::string_height [private]
 

Definition at line 38 of file button.h.

Referenced by image_size(), and set_constants().

int PushButton::string_width [private]
 

Definition at line 38 of file button.h.

Referenced by image_size(), and set_constants().

void* PushButton::surface [private]
 

Definition at line 37 of file button.h.

Referenced by name_button(), set_constants(), and ~PushButton().

int PushButton::X2 [private]
 

Definition at line 38 of file button.h.

Referenced by ButtonBounds(), depress_button(), Draw(), draw_frame(), draw_shadows(), Erase(), image_size(), Init(), name_button(), and PushButton().

int PushButton::xdim [private]
 

Definition at line 38 of file button.h.

Referenced by GetXDim(), and PushButton().

int PushButton::Y2 [private]
 

Definition at line 38 of file button.h.

Referenced by ButtonBounds(), depress_button(), Draw(), draw_frame(), draw_shadows(), Erase(), image_size(), Init(), name_button(), and PushButton().

int PushButton::ydim [private]
 

Definition at line 38 of file button.h.

Referenced by GetYDim(), and PushButton().


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