home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / source / krgobj.cpp < prev    next >
Text File  |  1997-02-14  |  4KB  |  172 lines

  1. // Kroni's Classes: Verschiedene Grafikobjekte
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: krgobj.hpp
  4.  
  5.  
  6. #include "krgobj.hpp"
  7. #include "krtrace.hpp"
  8.  
  9. #define INCL_GPIPRIMITIVES                       // GpiSetTextAlignment & Co.
  10. #include <os2.h>
  11.  
  12. #include <igrafctx.hpp>                          // IGraphicContext
  13.  
  14.  
  15.  
  16. KrGLine::KrGLine (KrCoordSystemTranslator & translator,
  17.                 const KrPoint & startingPoint, const KrPoint & endPoint)
  18.   : IGLine (IPoint(0,0),IPoint(1,1))             // Just to initialize the structure somehow
  19. {
  20.   trans = &translator;
  21.   start = startingPoint;
  22.   end = endPoint;
  23.   IGLine::setStartingPoint (trans->translate(start));
  24.   IGLine::setEndingPoint (trans->translate(end));
  25. };
  26.  
  27.  
  28. KrGLine & KrGLine::drawOn (IGraphicContext & graphicContext)
  29. {
  30.   IGLine::setStartingPoint (trans->translate(start));
  31.   IGLine::setEndingPoint (trans->translate(end));
  32.   IGLine::drawOn (graphicContext);
  33.   return (*this);
  34. };
  35.  
  36.  
  37.  
  38. KrGString::KrGString (KrCoordSystemTranslator & translator, const IString & text,
  39.      const KrPoint & positionPoint)
  40.   : IGString (text,IPoint(0,0))
  41. {
  42.   trans = &translator;
  43.   stringPosition = positionPoint;
  44.   setAlignment ();
  45.   IGString::moveTo (trans->translate(stringPosition));
  46. };
  47.  
  48.  
  49. void KrGString::setAlignment (const KrAlignment & al)
  50. {
  51.   align = al;
  52. };
  53.  
  54.  
  55. KrAlignment & KrGString::alignment ()
  56. {
  57.   return align;
  58. };
  59.  
  60.  
  61. KrGString & KrGString::drawOn (IGraphicContext & graphicContext)
  62. {
  63.  
  64.   IGString::moveTo (trans->translate(stringPosition));
  65.  
  66.   LONG lHoriz = 0, lVert = 0;                    // Gpi variables for alignment
  67.  
  68.   switch (align.horizontal())
  69.      {
  70.      case KrAlignment::left:
  71.         lHoriz = TA_LEFT;
  72.         break;
  73.      case KrAlignment::right:
  74.         lHoriz = TA_RIGHT;
  75.         break;
  76.      case KrAlignment::center:
  77.         lHoriz = TA_CENTER;
  78.         break;
  79.      };
  80.  
  81.   switch (align.vertical())
  82.      {
  83.      case KrAlignment::top:
  84.         lVert = TA_TOP;
  85.         break;
  86.      case KrAlignment::bottom:
  87.         lVert = TA_BOTTOM;
  88.         break;
  89.      case KrAlignment::center:
  90.         lVert = TA_HALF;
  91.         break;
  92.      };
  93.  
  94.  
  95.   if (!GpiSetTextAlignment (graphicContext.handle(),lHoriz,lVert))
  96.      _KRSYSTHROW (IAssertionFailure("GpiSetTextAlignment failed"));
  97.  
  98.  
  99.   IGString::drawOn (graphicContext);
  100.   return (*this);
  101.  
  102. };
  103.  
  104.  
  105.  
  106. KrGBox::KrGBox (KrCoordSystemTranslator & translator, const KrRectangle & aRectangle, const IColor & aColor)
  107.   : IGRectangle ()
  108.   , color (aColor)
  109. {
  110.   trans = &translator;
  111.   rectangle = aRectangle;
  112. };
  113.  
  114.  
  115. KrGBox & KrGBox::drawOn (IGraphicContext & graphicContext)
  116. {
  117.   IGRectangle::setEnclosingRect (trans->translate(rectangle));
  118.  
  119.   IGraphicBundle gb (graphicContext);            // save current attributes
  120.   graphicContext.setDrawOperation (IGraphicBundle::fill);
  121.   graphicContext.setPenWidth (0);
  122.   graphicContext.setFillPattern (IGraphicBundle::filled);
  123.   graphicContext.setFillColor (color);
  124.  
  125.   IGRectangle::drawOn (graphicContext);
  126.  
  127.   graphicContext.setGraphicBundle (gb);
  128.  
  129.   return (*this);
  130. };
  131.  
  132.  
  133. KrFrame::KrFrame (KrCoordSystemTranslator & translator, const KrPoint & p, double scale)
  134. {
  135.   trans = &translator;
  136.   bPoint = p;
  137.   dScale = scale;
  138. };
  139.  
  140.  
  141. KrFrame & KrFrame::drawOn (IGraphicContext & graphicContext)
  142. {
  143.   trans -> addFrame (bPoint, dScale);
  144.   return (*this);
  145. };
  146.  
  147.  
  148. KrPoint & KrFrame::basePoint ()
  149. {
  150.   return bPoint;
  151. };
  152.  
  153. double KrFrame::scale ()
  154. {
  155.   return dScale;
  156. };
  157.  
  158.  
  159.  
  160. KrAntiFrame::KrAntiFrame (KrCoordSystemTranslator & translator)
  161. {
  162.   trans = &translator;
  163. };
  164.  
  165.  
  166. KrAntiFrame & KrAntiFrame::drawOn (IGraphicContext & graphicContext)
  167. {
  168.   trans -> removeFrame ();
  169.   return (*this);
  170. };
  171.  
  172.