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

  1.  
  2.  
  3. #ifndef _dwgsurf_h_ /* Thu Sep 29 11:34:19 1994 */
  4. #define _dwgsurf_h_
  5.  
  6.  
  7.  
  8.  
  9. /*
  10.  *
  11.  *          Copyright (C) 1994, M. A. Sridhar
  12.  *  
  13.  *
  14.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  15.  *     to copy, modify or distribute this software  as you see fit,
  16.  *     and to use  it  for  any  purpose, provided   this copyright
  17.  *     notice and the following   disclaimer are included  with all
  18.  *     copies.
  19.  *
  20.  *                        DISCLAIMER
  21.  *
  22.  *     The author makes no warranties, either expressed or implied,
  23.  *     with respect  to  this  software, its  quality, performance,
  24.  *     merchantability, or fitness for any particular purpose. This
  25.  *     software is distributed  AS IS.  The  user of this  software
  26.  *     assumes all risks  as to its quality  and performance. In no
  27.  *     event shall the author be liable for any direct, indirect or
  28.  *     consequential damages, even if the  author has been  advised
  29.  *     as to the possibility of such damages.
  30.  *
  31.  */
  32.  
  33.  
  34.  
  35. // A DrawingSurface is an abstract class representing a surface that can be
  36. // drawn on.
  37.  
  38. // Author: M. A. Sridhar
  39.  
  40.  
  41. #if defined(__GNUC__)
  42. #pragma interface
  43. #endif
  44.  
  45.  
  46. #include "base/object.h"
  47.  
  48. #include "ui/rectangl.h"
  49. #include "ui/font.h"
  50. #include "ui/pen.h"
  51. #include "ui/brush.h"
  52. #include "ui/uidefs.h"
  53. // #include "ui/colormap.h"
  54.  
  55. #if defined(__MS_WINDOWS__)
  56. typedef  long UI_DwgSurfHandle;
  57.  
  58. #elif defined(__OS2__)
  59. typedef  ulong UI_DwgSurfHandle;
  60.  
  61. #elif defined(__X_MOTIF__)
  62. struct _XGC;
  63. typedef struct _XGC* UI_DwgSurfHandle;
  64.  
  65. #endif
  66.  
  67. class CL_EXPORT UI_VisualObject;
  68. class CL_EXPORT UI_Bitmap;
  69. class CL_EXPORT UI_Arc;
  70. class CL_EXPORT UI_Chord;
  71. class CL_EXPORT UI_PieWedge;
  72.  
  73.  
  74. enum UID_DrawOptions {UID_Outline = 1, UID_Fill = 2};
  75.  
  76. class CL_EXPORT UI_DrawingSurface: public CL_Object {
  77.  
  78. public:
  79.  
  80.     UI_DrawingSurface ();
  81.  
  82.     ~UI_DrawingSurface () {};
  83.  
  84.     // 
  85.     // --------------------------- Query ---------------------------------
  86.     //     
  87.  
  88.     virtual double HorzPixelsPerMM () const = 0;
  89.     // Return the number of pixels per millimeter in the horizontal
  90.     // direction.
  91.  
  92.     virtual double VertPixelsPerMM () const = 0;
  93.     // Return the number of pixels per millimeter in the vertical direction.
  94.  
  95.     virtual UI_Rectangle DrawingArea() const = 0;
  96.     // Returns the rectangle enclosing the drawing surface, in pixels. The
  97.     // origin is (0, 0).
  98.  
  99.     virtual UI_Rectangle DrawingAreaInMM () const = 0;
  100.     // Returns the drawing area, in millimeters. The origin is (0, 0).
  101.  
  102.     virtual bool SupportsColor () const {return TRUE;};
  103.     // Return TRUE if this DrawingSurface supports color, FALSE otherwise.
  104.     // The default implementation returns TRUE unconditionally.
  105.     
  106.     // Pen, Font and Brush  are resources
  107.     // maintained by this object. These may be accessed and modified 
  108.     // via the following reference methods.
  109.  
  110.     virtual UI_Font& Font();
  111.     // Return (a reference to) the font used by this surface. The return
  112.     // value can be modified by the Font methods.
  113.  
  114.     virtual UI_Pen&  Pen();
  115.     // Return (a reference to) the pen used by this surface. The return
  116.     // value can be modified by the Pen methods.
  117.  
  118.  
  119.     virtual UI_Brush& Brush();
  120.     // Return (a reference to) the background brush used by this surface.
  121.     // The return value can be modified by the Brush methods.
  122.  
  123.     
  124.     // 
  125.     // -------------------------- Draw  operations ------------------------
  126.     // 
  127.  
  128.  
  129.     virtual bool DrawLine (const UI_Point& p, const UI_Point& q);
  130.     // Draw a line from {\tt p} to {\tt q}, using our pen.
  131.  
  132.     virtual void ColorDisplay (const UI_Color& c);
  133.     // Paint client rectangle with specified color.
  134.  
  135.     virtual void ColorRectangle (const UI_Rectangle& r, const UI_Color& cs);
  136.     // Convenience function to color the interior of the given rectangle.
  137.     
  138.     virtual void DrawRectangle (const UI_Rectangle& rect,
  139.                                 ushort opt = UID_Outline); 
  140.     // Draw a rectangle using the current pen. The second parameter
  141.     // specifies the outline and fill options.
  142.                 
  143.     virtual void DrawEllipse (const UI_Rectangle& rect,
  144.                               ushort opt = UID_Outline); 
  145.     // Draw an ellipse with given bounding rectangle, using the current pen.
  146.     // The second parameter specifies the outline and fill options.
  147.     // (If the "rectangle" happens to be a square, then a circle is drawn.)
  148.                 
  149.     virtual void DrawArc (const UI_Arc &arc);
  150.     // Draw an arc with the using the parameters given to UI_Arc.
  151.  
  152.     virtual void DrawChord (const UI_Chord& chord,
  153.                             ushort opt = UID_Outline); 
  154.     // Draw a chord using the current pen. The second parameter
  155.     // specifies the outline and fill options.
  156.  
  157.     virtual void DrawPieWedge (const UI_PieWedge& pie,
  158.                                ushort opt = UID_Outline); 
  159.     // Draw a pie wedge using the current pen. The second parameter
  160.     // specifies the outline and fill options.
  161.         
  162.     virtual void DrawPolygon (UI_Point pointArray[], short numPoints,
  163.                               ushort opt = UID_Outline);
  164.     // Draw a closed polygon by connecting the points in the array with
  165.     // line segments, in the order of occurrence of the points.  The second
  166.     // parameter specifies the outline and fill options.
  167.     // The first point in the array is taken as the starting point.
  168.  
  169.     virtual void DrawPolyLine (UI_Point pointArray[], short numPoints);
  170.     // Draw a figure by connecting the points in the array with
  171.     // line segments, in the order of occurrence of the points. 
  172.     // The first point in the array is taken as the starting point.
  173.  
  174.     virtual void DrawPoint (const UI_Point& p, const UI_Color& color);
  175.     // Draw a point at position {\tt p} with given color.
  176.  
  177.     virtual bool DrawBitmap (const UI_Bitmap& b, const UI_Point& topLeft) = 0;
  178.     // [Pure virtual] Draw the given bitmap on this surface.
  179.      
  180.     // 
  181.     // ------------------------ Text operations -------------------------
  182.     // 
  183.  
  184.     virtual void WriteString (const CL_String& str, const UI_Rectangle& box,
  185.                               UI_TextStyle style = UIText_Left);
  186.     // Write the given text string within the given box, in the given
  187.     // style. This method is guaranteed to handle a single line, not
  188.     // necessarily multiple lines. It draws the text within the rectangle,
  189.     // clipping the text if necessary.
  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.  
  197.  
  198.     // Basic methods:
  199.     
  200.     const char* ClassName () const {return "UI_DrawingSurface";};
  201.  
  202.     // -------------------- End public protocol -------------------------
  203.  
  204.     
  205. protected:
  206.     UI_Pen*          _pen;       // These must be set up by the derived class.
  207.     UI_Font*         _font;
  208.     UI_Brush*        _brush;
  209.     UI_DwgSurfHandle _handle;
  210.     long             _horzPixels;
  211.     long             _vertPixels;
  212.     
  213. public:
  214.  
  215.     UI_DwgSurfHandle Handle() const;
  216.     // [For YACL internal use only]
  217.  
  218. };
  219.  
  220.  
  221.  
  222. inline void UI_DrawingSurface::ColorDisplay (const UI_Color& c)
  223. {
  224.     ColorRectangle (DrawingArea (), c);
  225. }
  226.  
  227.  
  228. inline UI_DwgSurfHandle UI_DrawingSurface::Handle () const
  229. {
  230.     return _handle;
  231. }
  232.  
  233.  
  234. inline UI_Font& UI_DrawingSurface::Font ()
  235. {
  236.     return *_font;
  237. }
  238.  
  239. inline UI_Pen& UI_DrawingSurface::Pen ()
  240. {
  241.     return *_pen;
  242. }
  243.  
  244. inline UI_Brush& UI_DrawingSurface::Brush ()
  245. {
  246.     return *_brush;
  247. }
  248.  
  249.  
  250.  
  251. #endif /* _dwgsurf_h_ */
  252.