File: vbrush.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 (178 lines) | stat: -rw-r--r-- 5,082 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//===============================================================
// vbrush.cxx: vBrush 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/vbrush.h>

//=======================>>> vBrush::vBrush <<<===========================
  vBrush::vBrush(unsigned int r, unsigned int g, unsigned int b,
              int style, int fillMode)
  {
      brushColor._r = (unsigned char) r;
      brushColor._g = (unsigned char) g;
      brushColor._b = (unsigned char) b;
      brushColor._pixel = RGB(r,g,b);
      brushStyle = style;
      brushFillMode = fillMode;
      _created = 0; _hbrush = 0;
  }

//=======================>>> vBrush::~vBrush <<<===========================
  vBrush::~vBrush()
  {
    if (_created)
      ::DeleteObject(_hbrush);
  }

//=====================>>> vBrush::vBrush <<<===========================
  vBrush::vBrush(const vBrush& p)
  {
    // Copy constructor - needs to delete object if already
    // created, and copy the values as needed
    if (_created)
        ::DeleteObject(_hbrush);
    _created = 0;
    _hbrush = 0;
    brushColor = p.brushColor;
    brushFillMode = p.brushFillMode;
    brushStyle = p.brushStyle;
  }

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

    // now just like a copy constructor

    if (_created)
        ::DeleteObject(_hbrush);
    _created = 0;
    _hbrush = 0;
    brushColor = p.brushColor;
    brushFillMode = p.brushFillMode;
    brushStyle = p.brushStyle;

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

//=====================>>> vBrush::SetStyle <<<===========================
  void vBrush::SetStyle(int style)
  {
    if (style == brushStyle)
        return;                 // no change
    brushStyle = style;
    if (_created)
      {
        ::DeleteObject(_hbrush);
        _hbrush = 0; _created = 0;
      }
  }

//=====================>>> vBrush::SetFillMode <<<===========================
  void vBrush::SetFillMode(int fm)
  {
    if (fm == brushFillMode)
        return;                 // no change
    brushFillMode = fm;
    if (_created)
      {
        ::DeleteObject(_hbrush);
        _hbrush = 0; _created = 0;
      }
  }

//=====================>>> vBrush::SetColor <<<===========================
  void vBrush::SetColor(vColor c)
  {
    if (c == brushColor)
        return;                 // no change
    brushColor = c;
    if (_created)
      {
        ::DeleteObject(_hbrush);
        _hbrush = 0; _created = 0;
      }
  }

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

    brushColor.Set(r,g,b);
    if (_created)
      {
        ::DeleteObject(_hbrush);
        _hbrush = 0; _created = 0;
      }
  }

//=====================>>> vBrush::GetHBRUSH <<<===========================
  HBRUSH vBrush::GetHBRUSH() VCONST
  {
    if (! _created)
      {
        switch (brushStyle)
          {
            case vSolid:
                _hbrush = ::CreateSolidBrush(brushColor._pixel);
                break;

            case vTransparent:
              {
                LOGBRUSH lb;
                lb.lbStyle = BS_NULL;
                lb.lbColor = 0;
                lb.lbHatch = 0;
                _hbrush = ::CreateBrushIndirect(&lb);
                break;
              }
            case vHorizontalHatch:
                _hbrush = ::CreateHatchBrush(HS_HORIZONTAL,brushColor._pixel);
                break;

            case vVerticleHatch:
                _hbrush = ::CreateHatchBrush(HS_VERTICAL,brushColor._pixel);
                break;

            case vLeftDiagonalHatch:
                _hbrush = ::CreateHatchBrush(HS_FDIAGONAL,brushColor._pixel);
                break;

            case vRightDiagonalHatch:
                _hbrush = ::CreateHatchBrush(HS_BDIAGONAL,brushColor._pixel);
                break;

            case vCrossHatch:
                _hbrush = ::CreateHatchBrush(HS_CROSS,brushColor._pixel);
                break;

            case vDiagonalCrossHatch:
                _hbrush = ::CreateHatchBrush(HS_DIAGCROSS,brushColor._pixel);
                break;

            default:
                _hbrush = ::CreateSolidBrush(brushColor._pixel);
                break;


          }

         _created = 1;
      }
      return _hbrush;                   // return a created brush handle
  }