home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / dsplsurf.h < prev    next >
C/C++ Source or Header  |  1995-04-08  |  8KB  |  252 lines

  1. #ifndef _dsplsurf_h_
  2. #define _dsplsurf_h_
  3.  
  4.  
  5.  
  6.  
  7.  
  8. /*
  9.  *
  10.  *          Copyright (C) 1994, M. A. Sridhar
  11.  *  
  12.  *
  13.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  14.  *     to copy, modify or distribute this software  as you see fit,
  15.  *     and to use  it  for  any  purpose, provided   this copyright
  16.  *     notice and the following   disclaimer are included  with all
  17.  *     copies.
  18.  *
  19.  *                        DISCLAIMER
  20.  *
  21.  *     The author makes no warranties, either expressed or implied,
  22.  *     with respect  to  this  software, its  quality, performance,
  23.  *     merchantability, or fitness for any particular purpose. This
  24.  *     software is distributed  AS IS.  The  user of this  software
  25.  *     assumes all risks  as to its quality  and performance. In no
  26.  *     event shall the author be liable for any direct, indirect or
  27.  *     consequential damages, even if the  author has been  advised
  28.  *     as to the possibility of such damages.
  29.  *
  30.  */
  31.  
  32.  
  33.  
  34. // Authors:   M. A. Sridhar
  35. //            N. Bhowmik
  36.  
  37.  
  38. // A DisplaySurface is an encapsulation of a region on the screen that
  39. // provides drawing operations. This region must be associated with the
  40. // window of the  'client display' - a VisualObject that is
  41. // specified during construction. The DisplaySurface inherits its abstract
  42. // behavior from the DrawingSurface, and overrides appropriate methods to
  43. // provide drawing facilities on a screen.
  44. // Each DisplaySurface object maintains default Font,
  45. // Brush and Pen objects.  It is important that a
  46. // display surface not be kept open for very long.
  47.  
  48.  
  49.  
  50. #if defined(__GNUC__)
  51. #pragma interface
  52. #endif
  53.  
  54.  
  55. #include "ui/uidefs.h"
  56. #include "ui/dwgsurf.h"
  57. #include "ui/stencil.h"
  58.  
  59. class CL_EXPORT UI_VisualObject;
  60.  
  61. class CL_EXPORT UI_DisplaySurface: public UI_DrawingSurface {
  62.  
  63.  
  64. public:
  65.  
  66.     UI_VisualObject& Client () const;
  67.  
  68.     double HorzPixelsPerMM () const {return _horzPPM;};
  69.     // Return the number of pixels per millimeter in the horizontal direction.
  70.  
  71.     double VertPixelsPerMM () const {return _vertPPM;};
  72.     // Return the number of pixels per inch in the vertical direction.
  73.     
  74.     UI_Rectangle DrawingArea () const;
  75.  
  76.     UI_Rectangle DrawingAreaInMM () const;
  77.  
  78.     // UI_ColorMap& ColorMap () const;
  79.     
  80.  
  81.     // ------------------------ Graphic modes ----------------------
  82.     enum GraphicsMode {
  83.         GMode_Clear = 0,        //
  84.         GMode_And,
  85.         GMode_AndReverse,
  86.         GMode_Copy,
  87.         GMode_AndInverted,
  88.         GMode_NoOp,
  89.         GMode_Xor,
  90.         GMode_Or,
  91.         GMode_Nor,
  92.         GMode_Equiv,
  93.         GMode_Invert,
  94.         GMode_OrReverse,
  95.         GMode_CopyInverted,
  96.         GMode_OrInverted,
  97.         GMode_Nand,
  98.         GMode_Set
  99.     };
  100.  
  101.     virtual GraphicsMode Mode () const;
  102.     // Return the current graphics mode.
  103.  
  104.     virtual void Mode (GraphicsMode mode);
  105.     // Set the current graphics mode.
  106.     
  107.     // 
  108.     // Draw  operations:
  109.     // 
  110.  
  111.  
  112.     void DrawPoint (const UI_Point& p, const UI_Color& color);
  113.     // Draw a point at position {\tt p} with given color.
  114.     
  115.     void DrawRectangle (const UI_Rectangle& rect,
  116.                         ushort opt = UID_Outline); 
  117.     // Draw a rectangle using the current pen. The second parameter
  118.     // specifies the outline and fill options.
  119.                 
  120.     void DrawEllipse (const UI_Rectangle& rect,
  121.                       ushort opt = UID_Outline); 
  122.     // Draw an ellipse with given bounding rectangle, using the current pen.
  123.     // The second parameter specifies the outline and fill options.
  124.     // (If the "rectangle" happens to be a square, then a circle is drawn.)
  125.                 
  126.     virtual void DrawArc (const UI_Arc &arc);
  127.     // Draw an arc with the using the parameters given to UI_Arc.
  128.  
  129.     virtual void DrawChord (const UI_Chord& chord,
  130.                             ushort opt = UID_Outline); 
  131.     // Draw a chord using the current pen. The second parameter
  132.     // specifies the outline and fill options.
  133.  
  134.     virtual void DrawPieWedge (const UI_PieWedge& pie,
  135.                                ushort opt = UID_Outline); 
  136.     // Draw a pie wedge using the current pen. The second parameter
  137.     // specifies the outline and fill options.
  138.         
  139.     void DrawPolygon (UI_Point pointArray[], short numPoints,
  140.                       ushort opt = UID_Outline);
  141.     // Draw a closed polygon by connecting the points in the array with
  142.     // line segments, in the order of occurrence of the points.  The second
  143.     // parameter specifies the outline and fill options.
  144.     // The first point in the array is taken as the starting point.
  145.  
  146.     bool DrawLine (const UI_Point& p, const UI_Point& q);
  147.     // Draw a line from  p to q, using our pen.
  148.  
  149.     // For the following drawing methods, if no starting point is
  150.     // specified then the figure is drawn at the current pen position.
  151.  
  152.     void DrawPolyLine (UI_Point* pointArray, short numPoints);
  153.     // Draw a figure by connecting the points in the array with
  154.     // line segments, in the order of occurrence of the points. 
  155.     // The first point in the array is taken as the starting point.
  156.     
  157.     bool DrawBitmap (const UI_Bitmap& b, const UI_Point& topLeft);
  158.     // Draw the given bitmap on this surface.
  159.      
  160.     void ClearDisplay();
  161.     // Paints client surface with current background color.
  162.  
  163.     void ColorRectangle (const UI_Rectangle& r, const UI_Color& cs);
  164.  
  165.     
  166.     bool InvertRectangle (const UI_Rectangle&);
  167.     // Reverse the forground and background in the given rectangle. Return
  168.     // TRUE on success, FALSE on failure.
  169.  
  170.  
  171.     bool Invert (const UI_Stencil& mask, const UI_Point& p);
  172.     // Given a binary {\tt mask}, position
  173.     // the mask against this DisplaySurface so that its top left corner is
  174.     // at {\tt p}. Invert the DisplaySurface pixels under 1-bits in the
  175.     // mask, and leave the rest unaltered.
  176.     
  177.     bool Draw (const UI_Bitmap& map, const UI_Stencil& s, const UI_Point& p);
  178.     // Draw the given Bitmap on this DisplaySurface with top left corner at
  179.     // the given point, but leave unaltered the pixels corresponding to
  180.     // 0-bits in the Stencil.
  181.  
  182.     // 
  183.     // Text operations:
  184.     // 
  185.  
  186.     UI_Font& Font();
  187.     
  188.     void WriteString (const CL_String& str, const UI_Rectangle& text_rect,
  189.                       UI_TextStyle style = UIText_Left);
  190.  
  191.     
  192.     virtual short TextWidth (const char* s) const;
  193.     // Return the width (in pixels) of the text string s if it were drawn
  194.     // on this DisplaySurface using its current font.
  195.  
  196.     const char* ClassName () const {return "UI_DisplaySurface";};
  197.  
  198. protected:
  199.  
  200.     UI_DisplaySurface  (UI_VisualObject* o);
  201.  
  202.     ~UI_DisplaySurface ();
  203.  
  204.     void _Init ();
  205.  
  206.     void SetFont (UI_Font*);
  207.     // SetFont: called only by UI_VisualObject and no one else!
  208.     
  209.     friend class UI_VisualObject;
  210.  
  211.  
  212.     
  213.  
  214. protected:
  215.     
  216.     bool             _ownFont;
  217.     UI_VisualObject& _client;
  218.     //    UI_ColorMap*     _colorMap;
  219.  
  220.     double           _horzPPM;
  221.     double           _vertPPM;
  222.  
  223. private:
  224.     bool _FontWillChange (CL_Object&, long);
  225.  
  226.     bool _FontChanged    (CL_Object&, long);
  227.  
  228.     UI_Point _ProjectToCorner (UI_Rectangle &rect, UI_Point &p);
  229.  
  230. #if defined(__X_MOTIF__)
  231.     void _DrawFontLine (const UI_Point& p1, const UI_Point& p2);
  232.     // [X-windows-specific; internal use only]
  233.     
  234.     
  235. #endif
  236. };
  237.  
  238.  
  239.  
  240.  
  241.  
  242. // inline UI_ColorMap& UI_DisplaySurface::ColorMap () const
  243. // {
  244. //     return *_colorMap;
  245. // }
  246.  
  247.  
  248.  
  249.  
  250. #endif
  251.  
  252.