File: vpen.cpp

package info (click to toggle)
libv1.22 1.22-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,380 kB
  • ctags: 9,765
  • sloc: cpp: 58,097; ansic: 6,814; makefile: 1,597; java: 515; sh: 24
file content (139 lines) | stat: -rw-r--r-- 3,228 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//===============================================================
// vpen.cxx: vColor class for drawing - Windows
//
// Copyright (C) 1995,1996, 1997, 1998  Bruce E. Wampler
//
// This file is part of the V C++ GUI Framework, and is covered
// under the terms of the GNU Library General Public License,
// Version 2. This library has NO WARRANTY. See the source file
// vapp.cxx for more complete information about license terms.
//===============================================================

#include <v/vwin32.h>		// for Win 32 stuff
#include <v/vapp.h>
#include <v/vpen.h>

//=======================>>> vPen::vPen <<<===========================
  vPen::vPen(unsigned int r, unsigned int g, unsigned int b,
	      int width, int style)
  {
      penColor._r = r, penColor._g = g; penColor._b = b;
      penColor._pixel = RGB(r,g,b);
      penWidth = width; penStyle = style; _created = 0; _hpen = 0;
  }

//=======================>>> vPen::~vPen <<<===========================
  vPen::~vPen()
  {
    ReleaseHpen();
  }

//=====================>>> vPen::vPen <<<===========================
  vPen::vPen(const vPen& p)
  {
    _created = 0;
    _hpen = 0;
    penColor = p.penColor;
    penWidth = p.penWidth;
    penStyle = p.penStyle;
  }

//=====================>>> vPen::operator= <<<===========================
  vPen & vPen::operator =(const vPen& p)
  {
    if (this == &p)     // assigning to self
      {
	return *this;
      }

    ReleaseHpen();
    // now just like a copy constructor
    penColor = p.penColor;
    penWidth = p.penWidth;
    penStyle = p.penStyle;

    return *this;               // allow r to l multiple assignment
  }

//=====================>>> vPen::SetStyle <<<===========================
  void vPen::SetStyle(int style)
  {
    if (style == penStyle)
	return;			// no change
    penStyle = style;
    ReleaseHpen();
  }

//=====================>>> vPen::SetWidth <<<===========================
  void vPen::SetWidth(int width)
  {
    if (width == penWidth)
	return;			// no change
    penWidth = width;
    ReleaseHpen();
  }


//=====================>>> vPen::SetColor <<<===========================
  void vPen::SetColor(const vColor& c)
  {
    if (c == penColor)
	return;			// no change
    penColor = c;
    ReleaseHpen();
  }

//=====================>>> vPen::SetColor <<<===========================
  void vPen::SetColor(unsigned int r, unsigned int g, unsigned int b)
  {
    if (penColor.r() == r && penColor.g() == g && penColor.b() == b)
	return;			// no change

    penColor.Set(r,g,b);
    ReleaseHpen();
  }


//=====================>>> vPen::GetHPEN <<<===========================
  HPEN vPen::GetHPEN() VCONST
  {
    if (!_created)
      {
	int ps;
	int pw = penWidth;

	switch (penStyle)
	  {
	    case vSolid:
		ps = PS_SOLID;
		break;

	    case vTransparent:
		ps = PS_NULL;
		break;

	    case vDash:
		ps = PS_DASH;
		pw = 1;		// $#$% Windows only allows width of 1
		break;

	    case vDot:
		ps = PS_DOT;
		pw = 1;
		break;

	    case vDashDot:
		ps = PS_DASHDOT;
		pw = 1;
		break;

	    default:
		ps = PS_SOLID;
		break;
	  }

	 _hpen = ::CreatePen(ps, pw, penColor._pixel);
	 _created = 1;
      }
      return _hpen;			// return a created pen handle
  }