home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / include / krcstran.hpp < prev    next >
C/C++ Source or Header  |  1997-02-04  |  9KB  |  210 lines

  1. // Kroni's Classes: Objekte für Zeichnen im mathematischen Koordinatensystem
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: krcstran.hpp
  4.  
  5. // **********************************************************************************************************
  6. //
  7. // defines these classes:
  8. //
  9. //   KrPoint                 Define a point in two dimensional space with floating point coordinates
  10. //   KrRectangle             Define a rectangle with floating point coordinates
  11. //   KrAlignment             Define how to align objects relative to available space
  12. //   KrCoordSystemTranslator Define a coordinate system and map it to any output device drawing area
  13. //   KrGraphicList           Enhances IGraphicList to be compatible with KrCoordSystemTranslator
  14. //   KrDrawingCanvas         Enhances IDrawingCanvas to be compatible with KrCoordSystemTranslator
  15. //
  16. // defines those global symbols for private use:
  17. //
  18. //   _KrFrameList
  19. //
  20. // **********************************************************************************************************
  21.  
  22.  
  23. #ifndef __KRCSTRAN_HPP__
  24. #define __KRCSTRAN_HPP__
  25.  
  26.  
  27. #include <idrawcv.hpp>                           // IDrawingCanvas & Co.
  28. #include <iglist.hpp>                            // IGList
  29.  
  30.  
  31.  
  32. class KrPoint                                    // Point with mathematical (floating point) coordinates
  33. {
  34. public:
  35.   KrPoint (double _x, double _y) {x=_x;y=_y;};
  36.   KrPoint () {x=y=0;};
  37.   double x;
  38.   double y;
  39. };
  40.  
  41.  
  42. class KrRectangle                                // Rectangle with mathematical (floating point) coordinates
  43. {
  44.  
  45. public:
  46.  
  47.   KrRectangle (KrPoint p1, KrPoint p2);
  48.   KrRectangle () {dLeft=dRight=dTop=dBottom=0;};
  49.  
  50.   double width () {return dRight-dLeft;};
  51.   double height () {return dTop-dBottom;};
  52.  
  53.   double left () const {return dLeft;};
  54.   double right () const {return dRight;};
  55.   double top () const {return dTop;};
  56.   double bottom () const {return dBottom;};
  57.  
  58.   void setLeft (double d);
  59.   void setRight (double d);
  60.   void setTop (double d);
  61.   void setBottom (double d);
  62.  
  63. private:
  64.  
  65.   double dLeft, dRight, dTop, dBottom;
  66.  
  67. };
  68.  
  69.  
  70. class _KrFrameList
  71. {
  72. public:
  73.   _KrFrameList () {next=0;};
  74.   KrPoint fMin;
  75.   KrPoint fMax;
  76.   _KrFrameList * next;
  77. };
  78.  
  79.  
  80. class KrAlignment
  81. {
  82.  
  83. public:
  84.  
  85.   KrAlignment (int h = KrAlignment::center, int v = KrAlignment::center);
  86.   void setHorizontal (int h);
  87.   void setVertical (int v);
  88.   int horizontal ();
  89.   int vertical ();
  90.  
  91.   typedef enum { center = 1, right, left, top, bottom } align;
  92.  
  93. private:
  94.  
  95.   int horiz, vert;
  96.  
  97. };
  98.  
  99.  
  100. class KrCoordSystemTranslator : public IBase
  101. {
  102.  
  103. public:
  104.  
  105.   KrCoordSystemTranslator (const KrPoint & p1 = KrPoint(1,1), const KrPoint & p2 = KrPoint(0,0));
  106.                                                  // Defines a coordinate system with corners p1 and p2
  107.                                                  //   If p2 is left out: between p1 and (0,0)
  108.                                                  //   If no parameter is given: between (0,0) and (1,1)
  109.                                                  //   Initial physical draw area: (0,1000),(0,1000)
  110.                                                  // Note: numerically unstable choices will result
  111.                                                  //   in undefined behaviour
  112.  
  113.   void assign (const IGraphicContext & printer); // Get physical draw area
  114.  
  115.   IPoint & translate (const KrPoint p) const;    // Translate logical units to physical units
  116.   IRectangle & translate (const KrRectangle p) const;
  117.  
  118.   void setAspectRatio (double ar=0);             // ar=0 -> automatic adjustment to full size
  119.                                                  //  Meaning of aspect ratio value ar:
  120.                                                  //  take a square coordinate  system with
  121.                                                  //  y-range 0..1 and x-range 0..ar.
  122.   double aspectRatio ();                         // Returns current value of aspect ratio
  123.   Boolean isFixedAspectRatio ();                 // True -> setAspectRatio has been used with ar != 0
  124.  
  125.   void setDeviceAspectRatio (double ar=0);       // Overrules automatic detection of output device
  126.                                                  //   aspect ratio, unless ar=0
  127.   double deviceAspectRatio ();                   // Gets the aspect ratio of the device
  128.   Boolean isFixedDeviceAspectRatio ();           // Did we overrule automatic detetion of device aspect
  129.                                                  //   ratio?
  130.  
  131.   void addFrame (const KrPoint & p, double scale);
  132.                                                  // Add a frame with left low corner p and relative size
  133.                                                  //   "scale". All subsequent drawing will be relative
  134.                                                  //   to the frame instead of relative to the whole area.
  135.                                                  //   This includes further calls of addFrame itself.
  136.                                                  //   Logarithmic scales will be ignored when placing
  137.                                                  //   the frame, but within the frame the scale will be
  138.                                                  //   logarithmic again.
  139.   void removeFrame ();                           // Restore the status before the previous addFrame()
  140.  
  141.   void setAlignment (const KrAlignment & alignment);
  142.                                                  // If fixed aspect ratio is used, the coordinate system will
  143.                                                  //   cover only part of the device/window. This function
  144.                                                  //   fixes how the system will be aligned on the device.
  145.   KrAlignment & alignment ();                    // Gets the current alignment
  146.  
  147. private:
  148.  
  149.   void setStretches ();                          // Set xStretch, yStretch, xOrg, yOrg
  150.  
  151.   KrPoint cMin, cMax;                            // Corners (left,low) and (right,high) of coordinate system
  152.   IPoint pMin, pMax;                             // Corners (minimal values) and (maximal values) of
  153.                                                  //   physical device area to paint on
  154.   KrPoint hMin, hMax;                            // Corners of hidden (for aRatio expanded) coordinate system
  155.   KrPoint fMin, fMax;                            // Corners of frame
  156.   double xStretch, yStretch, xOrg, yOrg;         // Cached temporary variables for performance improvement
  157.   Boolean xLog, yLog;                            // Indicates logarithmic coordinate systems
  158.  
  159.   double aRatio;                                 // Current aspect ratio
  160.   double logicalARatio;                          // Same as aRatio if aspect ratio is fixed; 0 otherwise.
  161.   Boolean iFixedAspectRatio;                     // Is aspect ratio fixed?
  162.   Boolean iFixedPAspectRatio;                    // Is device aspect ratio fixed?
  163.   double pAspectRatio;                           // Physical aspect ratio
  164.  
  165.   _KrFrameList * frameList;                      // Lists all current and previous frames
  166.  
  167.   KrAlignment align;                             // Alignment of coordinate system on device in case of
  168.                                                  //   fixed aspect ratio
  169. };
  170.  
  171.  
  172. class KrGraphicList : public IGList              // This is only technical; I hope to get rid of it sometime
  173. {
  174.  
  175. public:
  176.  
  177.   KrGraphicList (KrCoordSystemTranslator & trans);
  178.  
  179.   virtual KrGraphicList & drawOn (IGraphicContext & graphicContext);
  180.  
  181. private:
  182.  
  183.   KrCoordSystemTranslator * translator;
  184.  
  185. };
  186.  
  187.  
  188. class KrDrawingCanvas : public IDrawingCanvas    // This is only technical; I hope to get rid of it sometime
  189. {
  190.  
  191. public:
  192.  
  193.   KrDrawingCanvas (unsigned long windowIdentifier, IWindow *parent, IWindow *owner,
  194.                    const IRectangle & initial = IRectangle(), const Style style = defaultStyle ());
  195.                                                  // Constructor, syntax identical to IDrawingCanvas
  196.   ~KrDrawingCanvas ();                           // Destructor
  197.  
  198. private:
  199.  
  200.   IHandle::Value hps;                            // Handle to the presentation space we will draw on
  201.   IPresSpaceHandle * ip;                         // UICL object representating hps
  202.   IGraphicContext * dc;                          // UICL object representating ip
  203.   IGraphicContext * oldGraphicContext;           // graphics context used by IDrawingCanvas
  204.  
  205. };
  206.  
  207.  
  208. #endif
  209.  
  210.