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

  1.  
  2.  
  3. #ifndef _graphic_h_ /* Fri Oct 28 17:18:04 1994 */
  4. #define _graphic_h_
  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. // GraphicObject is an abstract class representing a graphic object that can
  34. // be drawn on a DrawingSurface.
  35.  
  36.  
  37. #if defined(__GNUC__)
  38. #pragma interface
  39. #endif
  40.  
  41. #include "base/object.h"
  42. #include "ui/point.h"
  43.  
  44. class CL_EXPORT UI_DrawingSurface;
  45. class CL_EXPORT UI_Rectangle;
  46.  
  47. enum UI_HitTest {
  48.     UIHit_Boundary, UIHit_Inside, UIHit_Outside
  49. };
  50.  
  51.  
  52. struct UI_PointPair {
  53.     UI_PointPair (const UI_Point& p, const UI_Point& q) : p1 (p), p2(q) {};
  54.     UI_PointPair () {};
  55.     UI_Point p1, p2;
  56. };
  57.  
  58. class CL_EXPORT UI_GraphicObject: public CL_Object {
  59.  
  60. public:
  61.  
  62.     ~UI_GraphicObject() {};
  63.     
  64.     virtual UI_Rectangle BoundingRectangle () const = 0;
  65.     // Return the bounding rectangle for this graphic. [Pure virtual]
  66.  
  67.     virtual UI_Point Center () const;
  68.     // Return the center of this GraphicObject. The default implementation
  69.     // returns the center of the BoundingRectangle.
  70.     
  71.     virtual bool DrawOn (UI_DrawingSurface& sfc,
  72.                          const UI_Point& p = UI_Point (0, 0)) const = 0;
  73.     // [Pure virtual method] Draw the graphic on the given surface,
  74.     // translated with respect to {\tt p} (i.e., treating {\tt p} as the
  75.     // origin).
  76.  
  77.     virtual bool ReshapeTo (const UI_Point& p1, const UI_Point& p2);
  78.     // Grow or shrink the graphic so that the two given points become the
  79.     // diagonally-opposing points of its bounding box. Return TRUE if
  80.     // successful. The default implementation returns FALSE unconditionally.
  81.  
  82.     virtual bool Fill   (UI_DrawingSurface& s) const;
  83.     // Fill the interior of the graphic on the given surface with the current
  84.     // foreground color of the given surface. This operation makes sense
  85.     // only for closed figures. The default implementation returns FALSE.
  86.  
  87.     virtual UI_HitTest HitTest (const UI_Point& p) const;
  88.     // Tell whether the given point is inside, outside or on the boundary of
  89.     // this graphic. The default implementation uses HitTest on the bounding
  90.     // rectangle.
  91.  
  92.     virtual bool IntersectsBoundary (const UI_Rectangle& r) const;
  93.     // Tell whether the given rectangle intersects the boundary of this
  94.     // GraphicObject. The default implementation uses the bounding
  95.     // rectangle.
  96.  
  97.     virtual bool IsContainedIn (const UI_Rectangle& r) const;
  98.     // Tell whether the given rectangle entirely contains this
  99.     // GraphicObject. The default implementation returns whether this
  100.     // object's bounding rectangle is contained in {\tt r}.
  101.  
  102. };
  103.  
  104. #endif /* _graphic_h_ */
  105.