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

viewport.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 * FILE: viewport.h
00003 * AUTHOR: CAL
00004 * DATE: 25 April 1993
00005 * PURPOSE:
00006 *   A Viewport is a rectangular portion of the physical screen in
00007 *   which one can draw pixel-oriented objects such as circles
00008 *   and lines.  Viewports support remember information about
00009 *   their colors, text-styles, line-styles, etc., and automatically
00010 *   switch to these attributes if necessary.
00011 ***********************************************************************/
00012 
00013 #ifndef _VIEWPORT_H
00014 #define _VIEWPORT_H
00015 
00016 #include <stddef.h>
00017 #include "typedefs.h"
00018 #include "video.h"
00019 #include "msmouse.h"
00020 
00021 
00022 /**********************************************************************
00023 * Settings structures
00024 ***********************************************************************/
00025 
00026 struct ViewSettings
00027 {
00028   int X1, Y1, X2, Y2;
00029   ViewSettings (int x1, int y1, int x2, int y2)
00030     { X1 = x1;  Y1 = y1;  X2 = x2;  Y2 = y2; }
00031   ViewSettings (void)
00032     { X1 = Y1 = 0;  X2 = Screen.GetMaxX ();  Y2 = Screen.GetMaxY (); }
00033   void Install (void)
00034     { setviewport (X1, Y1, X2, Y2, True); }
00035 };
00036 
00037 
00038 struct ColorSettings
00039 {
00040   int BG, FG;
00041   ColorSettings (void)
00042     { BG = BLACK;  FG = WHITE; }
00043   void Install (void)
00044     { setcolor (FG); }
00045 };
00046 
00047 
00048 struct FillSettings
00049 {
00050   int  Pattern, Color;
00051   FillSettings (void)
00052     { Pattern = SOLID_FILL;  Color = WHITE; }
00053   void Install (void)
00054     { setfillstyle (Pattern, Color); }
00055 };
00056 
00057 
00058 struct LineSettings
00059 {
00060   int Style, Thickness;
00061   unsigned Pattern;
00062   LineSettings (void)
00063     { Style = SOLID_LINE;  Pattern = 0x01; Thickness = NORM_WIDTH; }
00064   void Install (void)
00065     { setlinestyle (Style, Pattern, Thickness); }
00066 };
00067 
00068 
00069 struct TextSettings
00070 {
00071   int Font, Direction, CharSize, HJust, VJust;
00072   TextSettings (void)
00073     { Font = DEFAULT_FONT;  Direction = HORIZ_DIR;  CharSize = 1;
00074       HJust = LEFT_TEXT;  VJust = TOP_TEXT; }
00075   void Install (void)
00076     { settextstyle (Font, Direction, CharSize);
00077       settextjustify (HJust, VJust); }
00078 };
00079 
00080 
00081 struct Position
00082 {
00083   int X, Y;
00084   Position (void) { X = Y = 0; }
00085   void Install (void)
00086     {  moveto (X, Y); }
00087   void Save (void)
00088     { X = getx ();  Y = gety (); }
00089 };
00090 
00091 
00092 /**********************************************************************
00093 * Class Viewport
00094 ***********************************************************************/
00095 
00096 class Viewport
00097 {                               // Private settings data
00098 protected:
00099   ViewSettings  SView;
00100   ColorSettings SColor;
00101   FillSettings  SFill;
00102   LineSettings  SLine;
00103   TextSettings  SText;
00104   Position      SPos;
00105   Viewport* Parent;
00106         // Context management stuff
00107   static Viewport* Context;
00108   void Install (void);
00109   void SwitchTo (void) { if (Context != this) Install (); }
00110 
00111         // In preparation for drawing:
00112   void DoDraw (void)   { if (!Fast) Mouse.Hide (); }
00113   void DoneDraw (void) { if (!Fast) Mouse.Show (); }
00114   static int Fast;
00115 public:
00116   void FastDraw (void) { if (!Fast) Mouse.Hide (); Fast++; }
00117   void Done (void)     { Fast--; if (!Fast) Mouse.Show (); }
00118 
00119         // Constructors
00120   Viewport (Viewport* parent, int x1, int y1, int x2, int y2);
00121   Viewport (void);
00122 
00123         // Modifiers
00124 
00125   void SetColor   (int c)   { SColor.FG = c;  Context = NULL; }
00126   void SetBkColor (int c)   { SColor.BG = c;  Context = NULL; }
00127   void SetFillStyle (int pat, int col)
00128     { SFill.Pattern = pat;  SFill.Color = col;  Context = NULL; }
00129   void SetLineStyle (int st, unsigned pat, int thick)
00130     { SLine.Style = st;  SLine.Pattern = pat;  SLine.Thickness = thick;
00131       Context = NULL; }
00132   void SetTextStyle (int fnt, int dir, int size)
00133     { SText.Font = fnt;  SText.Direction = dir;  SText.CharSize = size;
00134       Context = NULL; }
00135   void SetTextJustify (int hor, int ver)
00136     { SText.HJust = hor;  SText.VJust = ver;
00137       Context = NULL; }
00138 
00139         // Selector Functions
00140 
00141   int TextHeight (char* s)
00142     { SwitchTo ();  return textheight (s); }
00143   int TextWidth (char* s)
00144     { SwitchTo ();  return textwidth (s);  }
00145   int GetBkColor (void)  { return SColor.BG; }
00146   int GetColor (void)  { return SColor.FG; }
00147   int GetMaxColor (void) { return Screen.GetMaxColor (); }
00148   int GetMaxX (void)   { return (SView.X2 - SView.X1); }
00149   int GetMaxY (void)   { return (SView.Y2 - SView.Y1); }
00150   int GetX (void)  { return SPos.X; }
00151   int GetY (void)  { return SPos.Y; }
00152   int TransX (int x);   // Translate parent's coordinate system
00153   int TransY (int y);   //  to ours.
00154   bool InBounds (int x, int y); // Check whether (x,y) is in this viewport
00155 
00156         // Drawing Functions
00157 
00158   void Bar (int x1, int y1, int x2, int y2)
00159     { SwitchTo (); DoDraw (); bar (x1, y1, x2, y2); DoneDraw ();}
00160   void Circle (int x, int y, int r)
00161     { SwitchTo (); DoDraw (); circle (x, y, r); DoneDraw ();}
00162   void Clear ();
00163   void FillEllipse (int x, int y, int xr, int yr)
00164     { SwitchTo (); DoDraw (); fillellipse (x, y, xr, yr); DoneDraw ();}
00165   void FloodFill (int x, int y, int border)
00166     { SwitchTo (); DoDraw (); floodfill (x, y, border); DoneDraw ();}
00167   void GetImage (int x1, int y1, int x2, int y2, void far *img)
00168     { SwitchTo (); getimage (x1, y1, x2, y2, img); }
00169   unsigned GetPixel (int x, int y)
00170     { SwitchTo (); return getpixel (x, y); }
00171   void Line (int x1, int y1, int x2, int y2)
00172     { SwitchTo (); DoDraw (); line (x1, y1, x2, y2); DoneDraw ();}
00173   void LineRel (int dx, int dy)
00174     { SwitchTo (); DoDraw (); linerel (dx, dy); DoneDraw (); SPos.Save (); }
00175   void LineTo (int x, int y)
00176     { SwitchTo (); DoDraw (); lineto (x, y); DoneDraw (); SPos.Save (); }
00177   void MoveRel (int dx, int dy)
00178     { SwitchTo (); moverel (dx, dy);  SPos.Save (); }
00179   void MoveTo (int x, int y)
00180     { SwitchTo (); moveto (x, y);  SPos.Save (); }
00181   void OutText (char* s)
00182     { SwitchTo (); DoDraw (); outtext (s); DoneDraw ();}
00183   void OutTextXY (int x, int y, char* s)
00184     { SwitchTo (); DoDraw (); outtextxy (x, y, s); DoneDraw ();}
00185   void PutImage (int x, int y, void far *img, int op)
00186     { SwitchTo (); DoDraw (); putimage (x, y, img, op); DoneDraw ();}
00187   void PutPixel (int x, int y, int clr)
00188     { SwitchTo (); DoDraw (); putpixel (x, y, clr); DoneDraw ();}
00189   void Rectangle (int x1, int y1, int x2, int y2)
00190     { SwitchTo (); DoDraw (); rectangle (x1, y1, x2, y2); DoneDraw ();}
00191 
00192 };
00193 
00194 
00195 #endif
00196 

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