home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vpen.cpp < prev    next >
C/C++ Source or Header  |  1999-01-24  |  4KB  |  116 lines

  1. //===============================================================
  2. // vpen.cxx: vPen class for drawing - Windows
  3. //
  4. // Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11. #include <v/vos2.h>        // for OS/2 stuff
  12. #include <v/vapp.h>
  13. #include <v/vpen.h>
  14. //=======================>>> vPen::vPen <<<===========================
  15.   vPen::vPen(unsigned int r, unsigned int g, unsigned int b,
  16.           int width, int style)
  17.   {
  18.       penColor._r = r, penColor._g = g; penColor._b = b;
  19.       penColor._pixel = SETRGB(r,g,b);
  20.       penWidth = width;
  21.       penStyle = style;
  22.   }
  23. //=======================>>> vPen::~vPen <<<===========================
  24.   vPen::~vPen()
  25.   {
  26.   }
  27. //=====================>>> vPen::vPen <<<===========================
  28.   vPen::vPen(const vPen& p)
  29.   {
  30.     penColor = p.penColor;
  31.     penWidth = p.penWidth;
  32.     penStyle = p.penStyle;
  33.   }
  34. //=====================>>> vPen::operator= <<<===========================
  35.   vPen & vPen::operator =(const vPen& p)
  36.   {
  37.     if (this == &p)  // assigning to self
  38.     {
  39.       return *this;
  40.     }
  41.     // now just like a copy constructor
  42.     penColor = p.penColor;
  43.     penWidth = p.penWidth;
  44.     penStyle = p.penStyle;
  45.     return *this;               // allow r to l multiple assignment
  46.   }
  47. //=====================>>> vPen::SetStyle <<<===========================
  48.   void vPen::SetStyle(int style)
  49.   {
  50.     if (style == penStyle)
  51.       return;     // no change
  52.     penStyle = style;
  53.   }
  54. //=====================>>> vPen::SetWidth <<<===========================
  55.   void vPen::SetWidth(int width)
  56.   {
  57.     if (width == penWidth)
  58.       return;    // no change
  59.     penWidth = width;
  60.   }
  61.  
  62. //=====================>>> vPen::SetColor <<<===========================
  63.   void vPen::SetColor(const vColor& c)
  64.   {
  65.     if (c == penColor)
  66.       return;         // no change
  67.     penColor = c;
  68.   }
  69.  
  70. //=====================>>> vPen::SetColor <<<===========================
  71.   void vPen::SetColor(unsigned int r, unsigned int g, unsigned int b)
  72.   {
  73.     if (penColor.r() == r && penColor.g() == g && penColor.b() == b)
  74.       return;        // no change
  75.     penColor.Set(r,g,b);
  76.   }
  77.  
  78. //=====================>>> vPen::GetHPEN <<<===========================
  79. // returns pointer to LINEBUNDLE set with vPen attributes
  80.   PLINEBUNDLE vPen::GetHPEN() VCONST
  81.   {
  82.     // we set both the width and geometric width, but only
  83.     // the geometric width will be used by the primitives
  84.     // and only if linetype is vSolid.
  85.     if (penWidth == 0)  // zero width pen is illegal
  86.       penWidth = 1;
  87.  
  88.     _lbPen.fxWidth = MAKEFIXED(penWidth, 0);
  89.     _lbPen.lGeomWidth = penWidth;
  90.     _lbPen.lColor = penColor._pixel;
  91.     _lbPen.usMixMode = FM_OVERPAINT;
  92.  
  93.     switch (penStyle)
  94.     {
  95.       case vSolid:
  96.           _lbPen.usType = LINETYPE_SOLID;
  97.           break;
  98.       case vTransparent:
  99.           _lbPen.usType = LINETYPE_INVISIBLE;
  100.           break;
  101.       case vDash:
  102.           _lbPen.usType = LINETYPE_SHORTDASH;
  103.           break;
  104.       case vDot:
  105.         _lbPen.usType = LINETYPE_DOT;
  106.           break;
  107.       case vDashDot:
  108.         _lbPen.usType = LINETYPE_DASHDOT;
  109.           break;
  110.       default:
  111.         _lbPen.usType = LINETYPE_SOLID;
  112.           break;
  113.     }
  114.     return &_lbPen;            // return a pointer to the linebundle
  115.   }
  116.