File: pen.h

package info (click to toggle)
wxwidgets3.0 3.0.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 120,808 kB
  • ctags: 118,010
  • sloc: cpp: 889,420; makefile: 52,980; ansic: 21,933; sh: 5,603; python: 2,935; xml: 1,534; perl: 281
file content (557 lines) | stat: -rw-r--r-- 15,469 bytes parent folder | download | duplicates (10)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
/////////////////////////////////////////////////////////////////////////////
// Name:        pen.h
// Purpose:     interface of wxPen* classes
// Author:      wxWidgets team
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
    The possible styles for a wxPen.

    Note that hatched pen styles are not supported by X11-based ports,
    including wxGTK.
*/
enum wxPenStyle
{
    wxPENSTYLE_INVALID = -1,

    wxPENSTYLE_SOLID,
        /**< Solid style. */

    wxPENSTYLE_DOT,
        /**< Dotted style. */

    wxPENSTYLE_LONG_DASH,
        /**< Long dashed style. */

    wxPENSTYLE_SHORT_DASH,
        /**< Short dashed style. */

    wxPENSTYLE_DOT_DASH,
        /**< Dot and dash style. */

    wxPENSTYLE_USER_DASH,
        /**< Use the user dashes: see wxPen::SetDashes. */

    wxPENSTYLE_TRANSPARENT,
        /**< No pen is used. */

    wxPENSTYLE_STIPPLE_MASK_OPAQUE,
        /**< @todo WHAT's this? */

    wxPENSTYLE_STIPPLE_MASK,
        /**< @todo WHAT's this? */

    wxPENSTYLE_STIPPLE,
        /**< Use the stipple bitmap. */

    wxPENSTYLE_BDIAGONAL_HATCH,
        /**< Backward diagonal hatch. */

    wxPENSTYLE_CROSSDIAG_HATCH,
        /**< Cross-diagonal hatch. */

    wxPENSTYLE_FDIAGONAL_HATCH,
        /**< Forward diagonal hatch. */

    wxPENSTYLE_CROSS_HATCH,
        /**< Cross hatch. */

    wxPENSTYLE_HORIZONTAL_HATCH,
        /**< Horizontal hatch. */

    wxPENSTYLE_VERTICAL_HATCH,
        /**< Vertical hatch. */

    wxPENSTYLE_FIRST_HATCH,
        /**< First of the hatch styles (inclusive). */

    wxPENSTYLE_LAST_HATCH
        /**< Last of the hatch styles (inclusive). */
};

/**
    The possible join values of a wxPen.

    @todo use wxPENJOIN_ prefix
*/
enum wxPenJoin
{
    wxJOIN_INVALID = -1,

    wxJOIN_BEVEL = 120,
    wxJOIN_MITER,
    wxJOIN_ROUND,
};


/**
    The possible cap values of a wxPen.

    @todo use wxPENCAP_ prefix
*/
enum wxPenCap
{
    wxCAP_INVALID = -1,

    wxCAP_ROUND = 130,
    wxCAP_PROJECTING,
    wxCAP_BUTT
};



/**
    @class wxPen

    A pen is a drawing tool for drawing outlines. It is used for drawing
    lines and painting the outline of rectangles, ellipses, etc.
    It has a colour, a width and a style.

    @note On a monochrome display, wxWidgets shows all non-white pens as black.

    Do not initialize objects on the stack before the program commences,
    since other required structures may not have been set up yet.
    Instead, define global pointers to objects and create them in wxApp::OnInit()
    or when required.

    An application may wish to dynamically create pens with different characteristics,
    and there is the consequent danger that a large number of duplicate pens will
    be created. Therefore an application may wish to get a pointer to a pen by using
    the global list of pens ::wxThePenList, and calling the member function
    wxPenList::FindOrCreatePen().
    See wxPenList for more info.

    This class uses @ref overview_refcount "reference counting and copy-on-write" internally
    so that assignments between two instances of this class are very cheap.
    You can therefore use actual objects instead of pointers without efficiency problems.
    If an instance of this class is changed it will create its own data internally
    so that other instances, which previously shared the data using the reference
    counting, are not affected.

    @library{wxcore}
    @category{gdi}

    @stdobjects
    @li ::wxNullPen
    @li ::wxBLACK_DASHED_PEN
    @li ::wxBLACK_PEN
    @li ::wxBLUE_PEN
    @li ::wxCYAN_PEN
    @li ::wxGREEN_PEN
    @li ::wxYELLOW_PEN
    @li ::wxGREY_PEN
    @li ::wxLIGHT_GREY_PEN
    @li ::wxMEDIUM_GREY_PEN
    @li ::wxRED_PEN
    @li ::wxTRANSPARENT_PEN
    @li ::wxWHITE_PEN

    @see wxPenList, wxDC, wxDC::SetPen()
*/
class wxPen : public wxGDIObject
{
public:
    /**
        Default constructor. The pen will be uninitialised, and IsOk() will return @false.
    */
    wxPen();

    /**
        Constructs a pen from a colour object, pen width and style.

        @param colour
            A colour object.
        @param width
            Pen width. Under Windows, the pen width cannot be greater than 1 if
            the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH,
            @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH.
        @param style
            The style may be one of the ::wxPenStyle values.

        @remarks Different versions of Windows and different versions of other
                 platforms support very different subsets of the styles above
                 - there is no similarity even between Windows95 and Windows98 -
                 so handle with care.

        @see SetStyle(), SetColour(), SetWidth()
    */
    wxPen(const wxColour& colour, int width = 1, wxPenStyle style = wxPENSTYLE_SOLID);

    /**
        Constructs a stippled pen from a stipple bitmap and a width.

        @param width
            Pen width. Under Windows, the pen width cannot be greater than 1 if
            the style is @c wxPENSTYLE_DOT, @c wxPENSTYLE_LONG_DASH, @c wxPENSTYLE_SHORT_DASH,
            @c wxPENSTYLE_DOT_DASH, or @c wxPENSTYLE_USER_DASH.
        @param stipple
            A stipple bitmap.

        @onlyfor{wxmsw,wxosx}

        @see SetWidth(), SetStipple()
    */
    wxPen(const wxBitmap& stipple, int width);

    /**
        Copy constructor, uses @ref overview_refcount.

        @param pen
            A pointer or reference to a pen to copy.
    */
    wxPen(const wxPen& pen);

    /**
        Destructor.
        @see @ref overview_refcount_destruct "reference-counted object destruction"

        @remarks Although all remaining pens are deleted when the application
                 exits, the application should try to clean up all pens
                 itself. This is because wxWidgets cannot know if a
                 pointer to the pen object is stored in an application
                 data structure, and there is a risk of double deletion.
    */
    virtual ~wxPen();

    /**
        Returns the pen cap style, which may be one of @c wxCAP_ROUND,
        @c wxCAP_PROJECTING and @c wxCAP_BUTT.

        The default is @c wxCAP_ROUND.

        @see SetCap()
    */
    virtual wxPenCap GetCap() const;

    /**
        Returns a reference to the pen colour.

        @see SetColour()
    */
    virtual wxColour GetColour() const;

    /**
        Gets an array of dashes (defined as @c char in X, @c DWORD under Windows).
        @a dashes is a pointer to the internal array. Do not deallocate or store this
        pointer.

        @return The number of dashes associated with this pen.

        @see SetDashes()
    */
    virtual int GetDashes(wxDash** dashes) const;

    /**
        Returns the pen join style, which may be one of @c wxJOIN_BEVEL,
        @c wxJOIN_ROUND and @c wxJOIN_MITER.

        The default is @c wxJOIN_ROUND.

        @see SetJoin()
    */
    virtual wxPenJoin GetJoin() const;

    /**
        Gets a pointer to the stipple bitmap.

        @see SetStipple()
    */
    virtual wxBitmap* GetStipple() const;

    /**
        Returns the pen style.

        @see wxPen(), SetStyle()
    */
    virtual wxPenStyle GetStyle() const;

    /**
        Returns the pen width.

        @see SetWidth()
    */
    virtual int GetWidth() const;

    /**
        Returns @true if the pen is initialised.

        Notice that an uninitialized pen object can't be queried for any pen
        properties and all calls to the accessor methods on it will result in
        an assert failure.
    */
    virtual bool IsOk() const;

    /**
        Returns @true if the pen is a valid non-transparent pen.

        This method returns @true if the pen object is initialized and has a
        non-transparent style. Notice that this should be used instead of
        simply testing whether GetStyle() returns a style different from
        wxPENSTYLE_TRANSPARENT if the pen may be invalid as GetStyle() would
        assert in this case.

        @see IsTransparent()

        @since 2.9.2.
     */
    bool IsNonTransparent() const;

    /**
        Returns @true if the pen is transparent.

        A transparent pen is simply a pen with wxPENSTYLE_TRANSPARENT style.

        Notice that this function works even for non-initialized pens (for
        which it returns @false) unlike tests of the form <code>GetStyle() ==
        wxPENSTYLE_TRANSPARENT</code> which would assert if the pen is invalid.

        @see IsNonTransparent()

        @since 2.9.2.
     */
    bool IsTransparent() const;

    /**
        Sets the pen cap style, which may be one of @c wxCAP_ROUND, @c wxCAP_PROJECTING
        and @c wxCAP_BUTT. The default is @c wxCAP_ROUND.

        @see GetCap()
    */
    virtual void SetCap(wxPenCap capStyle);

    //@{
    /**
        The pen's colour is changed to the given colour.

        @see GetColour()
    */
    virtual void SetColour(wxColour& colour);
    virtual void SetColour(unsigned char red, unsigned char green, unsigned char blue);
    //@}

    /**
        Associates an array of dash values (defined as @c char in X, @c DWORD under
        Windows) with the pen.

        The array is not deallocated by wxPen, but neither must it be deallocated by
        the calling application until the pen is deleted or this function is called
        with a @NULL array.

        @see GetDashes()
    */
    virtual void SetDashes(int n, const wxDash* dash);

    /**
        Sets the pen join style, which may be one of @c wxJOIN_BEVEL, @c wxJOIN_ROUND
        and @c wxJOIN_MITER.

        The default is @c wxJOIN_ROUND.

        @see GetJoin()
    */
    virtual void SetJoin(wxPenJoin join_style);

    /**
        Sets the bitmap for stippling.

        @see GetStipple()
    */
    virtual void SetStipple(const wxBitmap& stipple);

    /**
        Set the pen style.

        @see wxPen()
    */
    virtual void SetStyle(wxPenStyle style);

    /**
        Sets the pen width.

        @see GetWidth()
    */
    virtual void SetWidth(int width);

    /**
        Inequality operator.

        See @ref overview_refcount_equality "reference-counted object comparison" for
        more info.
    */
    bool operator!=(const wxPen& pen) const;

    /**
        Assignment operator, using @ref overview_refcount.
    */
    wxPen& operator=(const wxPen& pen);

    /**
        Equality operator.

        See @ref overview_refcount_equality "reference-counted object comparison" for
        more info.
    */
    bool operator==(const wxPen& pen) const;
};

/**
    An empty pen.
    wxPen::IsOk() always returns @false for this object.
*/
wxPen wxNullPen;

/**
    Red pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxRED_PEN;

/**
    Blue pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxBLUE_PEN;

/**
    Cyan pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxCYAN_PEN;

/**
    Green pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxGREEN_PEN;

/**
    Yellow pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxYELLOW_PEN;

/**
    Black pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxBLACK_PEN;

/**
    White pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxWHITE_PEN;

/**
    Transparent pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxTRANSPARENT_PEN;

/**
    Black dashed pen.
    Except for the color and for the @c wxPENSTYLE_SHORT_DASH it has all standard attributes
    (1-pixel width, @c wxCAP_ROUND style, etc...).
*/
wxPen* wxBLACK_DASHED_PEN;

/**
    Grey pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxGREY_PEN;

/**
    Medium-grey pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxMEDIUM_GREY_PEN;

/**
    Light-grey pen.
    Except for the color it has all standard attributes
    (1-pixel width, @c wxPENSTYLE_SOLID and @c wxCAP_ROUND styles, etc...).
*/
wxPen* wxLIGHT_GREY_PEN;



/**
    @class wxPenList

    There is only one instance of this class: ::wxThePenList.
    Use this object to search for a previously created pen of the desired
    type and create it if not already found. In some windowing systems,
    the pen may be a scarce resource, so it can pay to reuse old
    resources if possible. When an application finishes, all pens will
    be deleted and their resources freed, eliminating the possibility of
    'memory leaks'. However, it is best not to rely on this automatic
    cleanup because it can lead to double deletion in some circumstances.

    There are two mechanisms in recent versions of wxWidgets which make the
    pen list less useful than it once was. Under Windows, scarce resources
    are cleaned up internally if they are not being used. Also, a referencing
    counting mechanism applied to all GDI objects means that some sharing
    of underlying resources is possible. You don't have to keep track of pointers,
    working out when it is safe delete a pen, because the referencing counting does
    it for you. For example, you can set a pen in a device context, and then
    immediately delete the pen you passed, because the pen is 'copied'.

    So you may find it easier to ignore the pen list, and instead create
    and copy pens as you see fit. If your Windows resource meter suggests
    your application is using too many resources, you can resort to using
    GDI lists to share objects explicitly.

    The only compelling use for the pen list is for wxWidgets to keep
    track of pens in order to clean them up on exit. It is also kept for
    backward compatibility with earlier versions of wxWidgets.

    @library{wxcore}
    @category{gdi}

    @stdobjects
    ::wxThePenList

    @see wxPen
*/
class wxPenList
{
public:
    /**
        Constructor. The application should not construct its own pen list:
        use the object pointer ::wxThePenList.
    */
    wxPenList();

    /**
        Finds a pen with the specified attributes and returns it, else creates a
        new pen, adds it to the pen list, and returns it.

        @param colour
            Colour object.
        @param width
            Width of pen.
        @param style
            Pen style. See ::wxPenStyle for a list of styles.
    */
    wxPen* FindOrCreatePen(const wxColour& colour,
                           int width = 1,
                           wxPenStyle style = wxPENSTYLE_SOLID);
};

/**
    The global list of wxPen objects ready to be re-used (for better performances).
*/
wxPenList* wxThePenList;