1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: Generic gdi pen and colour
4
// Author: John Labenski
7
// Copyright: (c) John Labenski
8
// Licence: wxWidgets licence
9
/////////////////////////////////////////////////////////////////////////////
11
#ifndef _WX_GENERGDI_H_
12
#define _WX_GENERGDI_H_
14
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15
#pragma interface "genergdi.h"
18
#include "wx/colour.h"
21
#include "wx/things/thingdef.h"
23
class WXDLLIMPEXP_THINGS wxGenericColour;
24
class WXDLLIMPEXP_THINGS wxGenericPen;
25
class WXDLLIMPEXP_THINGS wxGenericBrush;
27
// Uncreated and invalid versions of the generic colour, pen, and brush
28
WXDLLIMPEXP_DATA_THINGS(extern const wxGenericColour) wxNullGenericColour;
29
WXDLLIMPEXP_DATA_THINGS(extern const wxGenericPen) wxNullGenericPen;
30
WXDLLIMPEXP_DATA_THINGS(extern const wxGenericBrush) wxNullGenericBrush;
32
// Arrays of the generic colours, pens, and brushes
33
WX_DECLARE_OBJARRAY_WITH_DECL(wxGenericColour, wxArrayGenericColour, class WXDLLIMPEXP_THINGS);
34
WX_DECLARE_OBJARRAY_WITH_DECL(wxGenericPen, wxArrayGenericPen, class WXDLLIMPEXP_THINGS);
35
WX_DECLARE_OBJARRAY_WITH_DECL(wxGenericBrush, wxArrayGenericBrush, class WXDLLIMPEXP_THINGS);
37
//----------------------------------------------------------------------------
38
// wxGenericColour - a RGBA colour that's converts from and to a wxColour.
39
// You can have thousands of them without using up resources. (on MSW)
40
//----------------------------------------------------------------------------
42
class WXDLLIMPEXP_THINGS wxGenericColour : public wxObject
45
wxGenericColour() : wxObject() {}
46
wxGenericColour( const wxGenericColour& c ) { Create(c); }
47
wxGenericColour( const wxColour& c ) { Create(c); }
48
wxGenericColour( unsigned char red, unsigned char green,
49
unsigned char blue, unsigned char alpha=255 )
50
: wxObject() { Create(red, green, blue, alpha); }
51
wxGenericColour( unsigned long colABGR ) : wxObject() { CreateABGR(colABGR); }
53
// Implicit conversion from the colour name
54
wxGenericColour( const wxString &colourName ) : wxObject() { Create(colourName); }
55
wxGenericColour( const char *colourName ) : wxObject() { Create(wxString::FromAscii(colourName)); }
57
wxGenericColour( const wxChar *colourName ) : wxObject() { Create(wxString(colourName)); }
60
virtual ~wxGenericColour() {}
61
// Destroy the refed data
62
void Destroy() { UnRef(); }
63
// Is this colour valid, has refed data
64
bool Ok() const { return m_refData != NULL; }
66
// -----------------------------------------------------------------------
67
// (re)Create this colour, unrefing this colour first.
68
// Use these to detach this colour from it's refed copies.
69
void Create( const wxGenericColour& c );
70
void Create( const wxColour& c);
71
void Create( unsigned char red = 0, unsigned char green = 0,
72
unsigned char blue = 0, unsigned char alpha=255 );
73
void CreateABGR( unsigned long colABGR );
74
void CreateARGB( unsigned long colARGB );
75
void Create( const wxString& colourName );
77
// -----------------------------------------------------------------------
78
// Set the colour values of the refed data.
79
// Use these to adjust the values of all the refed copies.
80
void Set( const wxGenericColour &c );
81
void Set( const wxColour& c );
82
void Set( unsigned char red, unsigned char green,
83
unsigned char blue, unsigned char alpha=255 );
84
void SetABGR( unsigned long colABGR );
85
void SetARGB( unsigned long colARGB );
86
void Set( const wxString& colourName );
88
void SetRed ( unsigned char r );
89
void SetGreen( unsigned char g );
90
void SetBlue ( unsigned char b );
91
void SetAlpha( unsigned char a );
93
// -----------------------------------------------------------------------
94
// Get the colour values
95
inline wxColour GetColour() const { return wxColour(GetRed(), GetGreen(), GetBlue()); }
97
unsigned char GetRed() const;
98
unsigned char GetGreen() const;
99
unsigned char GetBlue() const;
100
unsigned char GetAlpha() const;
102
// wxWidgets wxColour compatibility functions
103
unsigned char Red() const { return GetRed(); }
104
unsigned char Green() const { return GetGreen(); }
105
unsigned char Blue() const { return GetBlue(); }
106
unsigned char Alpha() const { return GetAlpha(); }
108
// -----------------------------------------------------------------------
110
bool IsSameAs( const wxGenericColour& c ) const;
111
bool IsSameAs( const wxColour& c ) const;
113
// Get a "hot to cold" colour where i ranges from 0 to 255
114
wxGenericColour GetHotColdColour(double i) const;
116
// Read colour to and from string
117
//wxString WriteString(const wxString& format = wxT("%d,%d,%d,%d")) const;
118
//bool ReadString(const wxString& str, const wxString& format = wxT("%d,%d,%d,%d"));
121
bool operator == (const wxGenericColour& c) const
122
{ return m_refData == c.m_refData; }
123
bool operator != (const wxGenericColour& c) const
124
{ return m_refData != c.m_refData; }
126
wxGenericColour& operator = (const wxGenericColour& c)
132
wxGenericColour& operator = ( const wxColour& c ) { Create(c); return *this; }
136
virtual wxObjectRefData *CreateRefData() const;
137
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
139
DECLARE_DYNAMIC_CLASS(wxGenericColour)
142
//----------------------------------------------------------------------------
143
// wxGenericPen - a pen structure that converts to and from wxPen
144
// You can have thousands of them without using up resources. (on MSW)
145
//----------------------------------------------------------------------------
147
class WXDLLIMPEXP_THINGS wxGenericPen : public wxObject
150
wxGenericPen() : wxObject() {}
151
wxGenericPen( const wxGenericPen &pen ) : wxObject() { Create(pen); }
152
wxGenericPen( const wxPen &pen ) : wxObject() { Create(pen); }
153
wxGenericPen( const wxGenericColour &colour, int width = 1, int style = wxSOLID,
154
int cap = wxCAP_ROUND, int join = wxJOIN_ROUND ) : wxObject()
155
{ Create(colour, width, style, cap, join); }
156
wxGenericPen( const wxColour &colour, int width = 1, int style = wxSOLID,
157
int cap = wxCAP_ROUND, int join = wxJOIN_ROUND ) : wxObject()
158
{ Create(colour, width, style, cap, join); }
160
virtual ~wxGenericPen() {}
161
// Destroy the refed data
162
void Destroy() { UnRef(); }
163
// Is this colour valid, has refed data
164
bool Ok() const { return m_refData != NULL; }
166
// -----------------------------------------------------------------------
167
// (re)Create this pen, unrefing this pen first.
168
// Use these to detach this pen from it's refed copies.
169
void Create( const wxGenericPen &pen );
170
void Create( const wxPen &pen );
171
void Create( const wxGenericColour &colour, int width = 1, int style = wxSOLID,
172
int cap = wxCAP_ROUND, int join = wxJOIN_ROUND );
173
void Create( const wxColour &colour, int width = 1, int style = wxSOLID,
174
int cap = wxCAP_ROUND, int join = wxJOIN_ROUND );
176
// -----------------------------------------------------------------------
177
// Set the values of the refed data.
178
// Use these to adjust the values of all the refed copies.
179
void Set( const wxGenericPen& pen );
180
void Set( const wxPen& pen );
181
void SetColour( const wxGenericColour &colour );
182
void SetColour( const wxColour &colour );
183
void SetColour( int red, int green, int blue, int alpha=255 );
184
void SetCap( int capStyle );
185
void SetJoin( int joinStyle );
186
void SetStyle( int style );
187
void SetWidth( int width );
188
void SetDashes( int number_of_dashes, const wxDash *dash );
190
// -----------------------------------------------------------------------
191
// Get the pen values
192
wxPen GetPen() const;
194
wxGenericColour GetGenericColour() const;
195
wxColour GetColour() const;
196
int GetWidth() const;
197
int GetStyle() const;
200
int GetDashes(wxDash **ptr) const;
201
int GetDashCount() const;
202
wxDash* GetDash() const;
204
// -----------------------------------------------------------------------
206
bool IsSameAs(const wxGenericPen& pen) const;
207
bool IsSameAs(const wxPen& pen) const;
209
// Read pen to and from string
210
//wxString WriteString() const;
211
//bool ReadString(const wxString& str);
214
bool operator == (const wxGenericPen& pen) const
215
{ return m_refData == pen.m_refData; }
216
bool operator != (const wxGenericPen& pen) const
217
{ return m_refData != pen.m_refData; }
219
wxGenericPen& operator = (const wxGenericPen& pen)
221
if ( (*this) != pen )
225
wxGenericPen& operator = ( const wxPen& pen ) { Create(pen); return *this; }
229
virtual wxObjectRefData *CreateRefData() const;
230
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
232
DECLARE_DYNAMIC_CLASS(wxGenericPen)
235
//----------------------------------------------------------------------------
236
// wxGenericBrush - a brush structure that converts to and from wxBrush
237
// You can have thousands of them without using up resources. (on MSW)
238
//----------------------------------------------------------------------------
240
class WXDLLIMPEXP_THINGS wxGenericBrush : public wxObject
243
wxGenericBrush() : wxObject() {}
244
wxGenericBrush( const wxGenericBrush &brush ) : wxObject() { Create(brush); }
245
wxGenericBrush( const wxBrush &brush ) : wxObject() { Create(brush); }
246
wxGenericBrush( const wxGenericColour &colour, int style = wxSOLID)
247
: wxObject() { Create(colour, style); }
248
wxGenericBrush( const wxColour &colour, int style = wxSOLID)
249
: wxObject() { Create(colour, style); }
250
wxGenericBrush( const wxBitmap& stipple ) : wxObject() { Create(stipple); }
252
virtual ~wxGenericBrush() {}
253
// Destroy the refed data
254
void Destroy() { UnRef(); }
255
// Is this colour valid, has refed data
256
bool Ok() const { return m_refData != NULL; }
258
// -----------------------------------------------------------------------
259
// (re)Create this brush, unrefing this pen first.
260
// Use these to detach this pen from it's refed copies.
261
void Create( const wxGenericBrush &brush );
262
void Create( const wxBrush &brush );
263
void Create( const wxGenericColour &colour, int style = wxSOLID );
264
void Create( const wxColour &colour, int style = wxSOLID );
265
void Create( const wxBitmap &stipple );
267
// -----------------------------------------------------------------------
268
// Set the values of the refed data.
269
// Use these to adjust the values of all the refed copies.
270
void Set( const wxGenericBrush& brush );
271
void Set( const wxBrush& brush );
272
void SetColour( const wxGenericColour &colour );
273
void SetColour( const wxColour &colour );
274
void SetColour( int red, int green, int blue, int alpha=255 );
275
void SetStyle( int style );
276
void SetStipple( const wxBitmap& stipple );
278
// -----------------------------------------------------------------------
279
// Get the brush values
280
wxBrush GetBrush() const;
282
wxGenericColour GetGenericColour() const;
283
wxColour GetColour() const;
284
int GetStyle() const;
285
wxBitmap* GetStipple() const;
288
{ return (GetStyle()>=wxFIRST_HATCH) && (GetStyle()<=wxLAST_HATCH); }
290
// -----------------------------------------------------------------------
292
bool IsSameAs(const wxGenericBrush& brush) const;
293
bool IsSameAs(const wxBrush& brush) const;
296
bool operator == (const wxGenericBrush& brush) const
297
{ return m_refData == brush.m_refData; }
298
bool operator != (const wxGenericBrush& brush) const
299
{ return m_refData != brush.m_refData; }
301
wxGenericBrush& operator = (const wxGenericBrush& brush)
303
if ( (*this) != brush )
307
wxGenericBrush& operator = ( const wxBrush& brush ) { Create(brush); return *this; }
311
virtual wxObjectRefData *CreateRefData() const;
312
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
314
DECLARE_DYNAMIC_CLASS(wxGenericBrush)
317
#endif // _WX_GENERGDI_H_