]> git.saurik.com Git - wxWidgets.git/blame_incremental - interface/gdicmn.h
fix for infinite sizing loop (partial patch 1907189)
[wxWidgets.git] / interface / gdicmn.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: gdicmn.h
3// Purpose: interface of wxRealPoint
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxRealPoint
11 @wxheader{gdicmn.h}
12
13 A @b wxRealPoint is a useful data structure for graphics operations.
14 It contains floating point @e x and @e y members.
15 See also wxPoint for an integer version.
16
17 @library{wxcore}
18 @category{data}
19
20 @see wxPoint
21*/
22class wxRealPoint
23{
24public:
25 //@{
26 /**
27 Create a point.
28 double x
29 double y
30 Members of the @b wxRealPoint object.
31 */
32 wxRealPoint();
33 wxRealPoint(double x, double y);
34 //@}
35};
36
37
38
39/**
40 @class wxRect
41 @wxheader{gdicmn.h}
42
43 A class for manipulating rectangles.
44
45 @library{wxcore}
46 @category{data}
47
48 @see wxPoint, wxSize
49*/
50class wxRect
51{
52public:
53 //@{
54 /**
55 Creates a wxRect object from size values at the origin.
56 */
57 wxRect();
58 wxRect(int x, int y, int width, int height);
59 wxRect(const wxPoint& topLeft, const wxPoint& bottomRight);
60 wxRect(const wxPoint& pos, const wxSize& size);
61 wxRect(const wxSize& size);
62 //@}
63
64 //@{
65 /**
66 Returns the rectangle having the same size as this one but centered relatively
67 to the given rectangle @e r. By default, rectangle is centred in both
68 directions but if @a dir includes only @c wxVERTICAL or only
69 @c wxHORIZONTAL flag, then it is only centered in this direction while
70 the other component of its position remains unchanged.
71 */
72 wxRect CentreIn(const wxRect& r, int dir = wxBOTH) const;
73 const wxRect CenterIn(const wxRect& r, int dir = wxBOTH) const;
74 //@}
75
76 //@{
77 /**
78 Returns @true if the given rectangle is completely inside this rectangle
79 (or touches its boundary) and @false otherwise.
80 */
81 bool Contains(int x, int y) const;
82 const bool Contains(const wxPoint& pt) const;
83 const bool Contains(const wxRect& rect) const;
84 //@}
85
86 //@{
87 /**
88 Decrease the rectangle size.
89 This method is the opposite from Inflate():
90 Deflate(a, b) is equivalent to Inflate(-a, -b).
91 Please refer to Inflate() for full description.
92
93 @see Inflate()
94 */
95 void Deflate(wxCoord dx, wxCoord dy) const;
96 void Deflate(const wxSize& diff) const;
97 void Deflate(wxCoord diff) const;
98 wxRect Deflate(wxCoord dx, wxCoord dy) const;
99 //@}
100
101 /**
102 Gets the bottom point of the rectangle.
103 */
104 int GetBottom() const;
105
106 /**
107 Gets the position of the bottom left corner.
108 */
109 wxPoint GetBottomLeft() const;
110
111 /**
112 Gets the position of the bottom right corner.
113 */
114 wxPoint GetBottomRight() const;
115
116 /**
117 Gets the height member.
118 */
119 int GetHeight() const;
120
121 /**
122 Gets the left point of the rectangle (the same as wxRect::GetX).
123 */
124 int GetLeft() const;
125
126 /**
127 Gets the position.
128 */
129 wxPoint GetPosition() const;
130
131 /**
132 Gets the right point of the rectangle.
133 */
134 int GetRight() const;
135
136 /**
137 Gets the size.
138
139 @see SetSize()
140 */
141 wxSize GetSize() const;
142
143 /**
144 Gets the top point of the rectangle (the same as wxRect::GetY).
145 */
146 int GetTop() const;
147
148 /**
149 Gets the position of the top left corner of the rectangle, same as
150 GetPosition().
151 */
152 wxPoint GetTopLeft() const;
153
154 /**
155 Gets the position of the top right corner.
156 */
157 wxPoint GetTopRight() const;
158
159 /**
160 Gets the width member.
161 */
162 int GetWidth() const;
163
164 /**
165 Gets the x member.
166 */
167 int GetX() const;
168
169 /**
170 Gets the y member.
171 */
172 int GetY() const;
173
174 //@{
175 /**
176 Increases the size of the rectangle.
177 The second form uses the same @a diff for both @a dx and @e dy.
178 The first two versions modify the rectangle in place, the last one returns a
179 new rectangle leaving this one unchanged.
180 The left border is moved farther left and the right border is moved farther
181 right by @e dx. The upper border is moved farther up and the bottom border
182 is moved farther down by @e dy. (Note the the width and height of the
183 rectangle thus change by 2*@a dx and 2*@e dy, respectively.) If one or
184 both of @a dx and @a dy are negative, the opposite happens: the rectangle
185 size decreases in the respective direction.
186 Inflating and deflating behaves "naturally''. Defined more precisely, that
187 means:
188 "Real'' inflates (that is, @a dx and/or @a dy = 0) are not
189 constrained. Thus inflating a rectangle can cause its upper left corner
190 to move into the negative numbers. (the versions prior to 2.5.4 forced
191 the top left coordinate to not fall below (0, 0), which implied a
192 forced move of the rectangle.)
193 Deflates are clamped to not reduce the width or height of the
194 rectangle below zero. In such cases, the top-left corner is nonetheless
195 handled properly. For example, a rectangle at (10, 10) with size (20,
196 40) that is inflated by (-15, -15) will become located at (20, 25) at
197 size (0, 10). Finally, observe that the width and height are treated
198 independently. In the above example, the width is reduced by 20,
199 whereas the height is reduced by the full 30 (rather than also stopping
200 at 20, when the width reached zero).
201
202 @see Deflate()
203 */
204 void Inflate(wxCoord dx, wxCoord dy) const;
205 void Inflate(const wxSize& diff) const;
206 void Inflate(wxCoord diff) const;
207 wxRect Inflate(wxCoord dx, wxCoord dy) const;
208 //@}
209
210 //@{
211 /**
212 Modifies the rectangle to contain the overlapping box of this rectangle and the
213 one passed in as parameter. The const version returns the new rectangle, the
214 other one modifies this rectangle in place.
215 */
216 wxRect Intersect(const wxRect& rect);
217 const wxRect& Intersect(const wxRect& rect);
218 //@}
219
220 /**
221 Returns @true if this rectangle has a non-empty intersection with the
222 rectangle @a rect and @false otherwise.
223 */
224 bool Intersects(const wxRect& rect) const;
225
226 /**
227 Returns @true if this rectangle has a width or height less than or equal to
228 0 and @false otherwise.
229 */
230 bool IsEmpty() const;
231
232 //@{
233 /**
234 Moves the rectangle by the specified offset. If @a dx is positive, the
235 rectangle is moved to the right, if @a dy is positive, it is moved to the
236 bottom, otherwise it is moved to the left or top respectively.
237 */
238 void Offset(wxCoord dx, wxCoord dy);
239 void Offset(const wxPoint& pt);
240 //@}
241
242 /**
243 Sets the height.
244 */
245 void SetHeight(int height);
246
247 /**
248 Sets the size.
249
250 @see GetSize()
251 */
252 void SetSize(const wxSize& s);
253
254 /**
255 Sets the width.
256 */
257 void SetWidth(int width);
258
259 /**
260 Sets the x position.
261 */
262 void SetX(int x);
263
264 /**
265 Sets the y position.
266 */
267 void SetY(int y);
268
269 //@{
270 /**
271 Modifies the rectangle to contain the bounding box of this rectangle and the
272 one passed in as parameter. The const version returns the new rectangle, the
273 other one modifies this rectangle in place.
274 */
275 wxRect Union(const wxRect& rect);
276 const wxRect& Union(const wxRect& rect);
277 //@}
278
279 /**
280 int height
281 Height member.
282 */
283
284
285 //@{
286 /**
287 Returns the intersection of two rectangles (which may be empty).
288 */
289 bool operator !=(const wxRect& r1, const wxRect& r2);
290 wxRect operator +(const wxRect& r1, const wxRect& r2);
291 wxRect operator +=(const wxRect& r);
292 See also wxRect operator *(const wxRect& r1,
293 const wxRect& r2);
294 wxRect operator *=(const wxRect& r);
295 //@}
296
297 /**
298 Assignment operator.
299 */
300 void operator =(const wxRect& rect);
301
302 /**
303 Equality operator.
304 */
305 bool operator ==(const wxRect& r1, const wxRect& r2);
306
307 /**
308 int width
309 Width member.
310 */
311
312
313 /**
314 int x
315 x coordinate of the top-level corner of the rectangle.
316 */
317
318
319 /**
320 int y
321 y coordinate of the top-level corner of the rectangle.
322 */
323};
324
325
326
327/**
328 @class wxBrushList
329 @wxheader{gdicmn.h}
330
331 A brush list is a list containing all brushes which have been created.
332
333 @library{wxcore}
334 @category{gdi}
335
336 @see wxBrush
337*/
338class wxBrushList : public wxList
339{
340public:
341 /**
342 Constructor. The application should not construct its own brush list:
343 use the object pointer @b wxTheBrushList.
344 */
345 wxBrushList();
346
347 /**
348 Finds a brush with the specified attributes and returns it, else creates a new
349 brush, adds it
350 to the brush list, and returns it.
351
352 @param colour
353 Colour object.
354 @param style
355 Brush style. See wxBrush::SetStyle for a list of styles.
356 */
357 wxBrush* FindOrCreateBrush(const wxColour& colour,
358 int style = wxSOLID);
359};
360
361
362
363/**
364 @class wxPoint
365 @wxheader{gdicmn.h}
366
367 A @b wxPoint is a useful data structure for graphics operations.
368 It simply contains integer @e x and @e y members.
369
370 See also wxRealPoint for a floating point version.
371
372 @library{wxcore}
373 @category{data}
374
375 @see wxRealPoint
376*/
377class wxPoint
378{
379public:
380 //@{
381 /**
382 Create a point.
383 */
384 wxPoint();
385 wxPoint(int x, int y);
386 //@}
387
388 //@{
389 /**
390 Operators for sum and subtraction between a wxPoint object and a
391 wxSize object.
392 */
393 void operator =(const wxPoint& pt);
394 bool operator ==(const wxPoint& p1, const wxPoint& p2);
395 bool operator !=(const wxPoint& p1, const wxPoint& p2);
396 wxPoint operator +(const wxPoint& p1, const wxPoint& p2);
397 wxPoint operator -(const wxPoint& p1, const wxPoint& p2);
398 wxPoint operator +=(const wxPoint& pt);
399 wxPoint operator -=(const wxPoint& pt);
400 wxPoint operator +(const wxPoint& pt, const wxSize& sz);
401 wxPoint operator -(const wxPoint& pt, const wxSize& sz);
402 wxPoint operator +(const wxSize& sz, const wxPoint& pt);
403 wxPoint operator -(const wxSize& sz, const wxPoint& pt);
404 wxPoint operator +=(const wxSize& sz);
405 wxPoint operator -=(const wxSize& sz);
406 //@}
407
408 /**
409 int x
410 x member.
411 */
412
413
414 /**
415 int y
416 y member.
417 */
418};
419
420
421
422/**
423 @class wxColourDatabase
424 @wxheader{gdicmn.h}
425
426 wxWidgets maintains a database of standard RGB colours for a predefined
427 set of named colours (such as "BLACK'', "LIGHT GREY''). The
428 application may add to this set if desired by using
429 wxColourDatabase::AddColour and may use it to look up
430 colours by names using wxColourDatabase::Find or find the names
431 for the standard colour suing wxColourDatabase::FindName.
432
433 There is one predefined instance of this class called
434 @b wxTheColourDatabase.
435
436 @library{wxcore}
437 @category{FIXME}
438
439 @see wxColour
440*/
441class wxColourDatabase
442{
443public:
444 /**
445 Constructs the colour database. It will be initialized at the first use.
446 */
447 wxColourDatabase();
448
449 //@{
450 /**
451 Adds a colour to the database. If a colour with the same name already exists,
452 it is replaced.
453 Please note that the overload taking a pointer is deprecated and will be
454 removed in the next wxWidgets version, please don't use it.
455 */
456 void AddColour(const wxString& colourName,
457 const wxColour& colour);
458 void AddColour(const wxString& colourName, wxColour* colour);
459 //@}
460
461 /**
462 Finds a colour given the name. Returns an invalid colour object (that is, such
463 that its @ref wxColour::isok Ok method returns @false) if the colour wasn't
464 found in the database.
465 */
466 wxColour Find(const wxString& colourName);
467
468 /**
469 Finds a colour name given the colour. Returns an empty string if the colour is
470 not found in the database.
471 */
472 wxString FindName(const wxColour& colour) const;
473};
474
475
476
477/**
478 @class wxFontList
479 @wxheader{gdicmn.h}
480
481 A font list is a list containing all fonts which have been created. There
482 is only one instance of this class: @b wxTheFontList. Use this object to search
483 for a previously created font of the desired type and create it if not already
484 found.
485 In some windowing systems, the font may be a scarce resource, so it is best to
486 reuse old resources if possible. When an application finishes, all fonts will
487 be
488 deleted and their resources freed, eliminating the possibility of 'memory
489 leaks'.
490
491 @library{wxcore}
492 @category{gdi}
493
494 @see wxFont
495*/
496class wxFontList : public wxList
497{
498public:
499 /**
500 Constructor. The application should not construct its own font list:
501 use the object pointer @b wxTheFontList.
502 */
503 wxFontList();
504
505 /**
506 Finds a font of the given specification, or creates one and adds it to the
507 list. See the @ref wxFont::ctor "wxFont constructor" for
508 details of the arguments.
509 */
510 wxFont* FindOrCreateFont(int point_size, int family, int style,
511 int weight,
512 bool underline = false,
513 const wxString& facename = NULL,
514 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
515};
516
517
518
519/**
520 @class wxSize
521 @wxheader{gdicmn.h}
522
523 A @b wxSize is a useful data structure for graphics operations.
524 It simply contains integer @e width and @e height members.
525
526 wxSize is used throughout wxWidgets as well as wxPoint which, although almost
527 equivalent to wxSize, has a different meaning: wxPoint represents a position
528 while wxSize - the size.
529
530 @b wxPython note: wxPython defines aliases for the @c x and @c y members
531 named @c width and @c height since it makes much more sense for
532 sizes.
533
534
535 @library{wxcore}
536 @category{data}
537
538 @see wxPoint, wxRealPoint
539*/
540class wxSize
541{
542public:
543 //@{
544 /**
545 Creates a size object.
546 */
547 wxSize();
548 wxSize(int width, int height);
549 //@}
550
551 //@{
552 /**
553 Decreases the size in x- and y- directions
554 By @e size.x and @e size.y for the first overload
555 By @a dx and @a dy for the second one
556 By @a d and @a d for the third one
557
558 @see IncBy()
559 */
560 void DecBy(const wxSize& size);
561 void DecBy(int dx, int dy);
562 void DecBy(int d);
563 //@}
564
565 /**
566 Decrements this object so that both of its dimensions are not greater than the
567 corresponding dimensions of the @e size.
568
569 @see IncTo()
570 */
571 void DecTo(const wxSize& size);
572
573 /**
574 Gets the height member.
575 */
576 int GetHeight() const;
577
578 /**
579 Gets the width member.
580 */
581 int GetWidth() const;
582
583 //@{
584 /**
585 Increases the size in x- and y- directions
586 By @e size.x and @e size.y for the first overload
587 By @a dx and @a dy for the second one
588 By @a d and @a d for the third one
589
590 @see DecBy()
591 */
592 void IncBy(const wxSize& size);
593 void IncBy(int dx, int dy);
594 void IncBy(int d);
595 //@}
596
597 /**
598 Increments this object so that both of its dimensions are not less than the
599 corresponding dimensions of the @e size.
600
601 @see DecTo()
602 */
603 void IncTo(const wxSize& size);
604
605 /**
606 Returns @true if neither of the size object components is equal to -1, which
607 is used as default for the size values in wxWidgets (hence the predefined
608 @c wxDefaultSize has both of its components equal to -1).
609 This method is typically used before calling
610 SetDefaults().
611 */
612 bool IsFullySpecified() const;
613
614 //@{
615 /**
616 Operators for division and multiplication between a wxSize object and an
617 integer.
618 */
619 void operator =(const wxSize& sz);
620 bool operator ==(const wxSize& s1, const wxSize& s2);
621 bool operator !=(const wxSize& s1, const wxSize& s2);
622 wxSize operator +(const wxSize& s1, const wxSize& s2);
623 wxSize operator -(const wxSize& s1, const wxSize& s2);
624 wxSize operator +=(const wxSize& sz);
625 wxSize operator -=(const wxSize& sz);
626 wxSize operator /(const wxSize& sz, int factor);
627 wxSize operator *(const wxSize& sz, int factor);
628 wxSize operator *(int factor, const wxSize& sz);
629 wxSize operator /=(int factor);
630 wxSize operator *=(int factor);
631 //@}
632
633 /**
634 Scales the dimensions of this object by the given factors.
635 If you want to scale both dimensions by the same factor you can also use
636 the @ref operators() "operator *="
637 Returns a reference to this object (so that you can concatenate other
638 operations in the same line).
639 */
640 wxSize Scale(float xscale, float yscale);
641
642 /**
643 Sets the width and height members.
644 */
645 void Set(int width, int height);
646
647 /**
648 Combine this size object with another one replacing the default (i.e. equal
649 to -1) components of this object with those of the other. It is typically
650 used like this:
651
652 @see IsFullySpecified()
653 */
654 void SetDefaults(const wxSize& sizeDefault);
655
656 /**
657 Sets the height.
658 */
659 void SetHeight(int height);
660
661 /**
662 Sets the width.
663 */
664 void SetWidth(int width);
665};
666
667
668
669/**
670 @class wxPenList
671 @wxheader{gdicmn.h}
672
673 There is only one instance of this class: @b wxThePenList. Use
674 this object to search for a previously created pen of the desired
675 type and create it if not already found. In some windowing systems,
676 the pen may be a scarce resource, so it can pay to reuse old
677 resources if possible. When an application finishes, all pens will
678 be deleted and their resources freed, eliminating the possibility of
679 'memory leaks'. However, it is best not to rely on this automatic
680 cleanup because it can lead to double deletion in some circumstances.
681
682 There are two mechanisms in recent versions of wxWidgets which make the
683 pen list less useful than it once was. Under Windows, scarce resources
684 are cleaned up internally if they are not being used. Also, a referencing
685 counting mechanism applied to all GDI objects means that some sharing
686 of underlying resources is possible. You don't have to keep track of pointers,
687 working out when it is safe delete a pen, because the referencing counting does
688 it for you. For example, you can set a pen in a device context, and then
689 immediately delete the pen you passed, because the pen is 'copied'.
690
691 So you may find it easier to ignore the pen list, and instead create
692 and copy pens as you see fit. If your Windows resource meter suggests
693 your application is using too many resources, you can resort to using
694 GDI lists to share objects explicitly.
695
696 The only compelling use for the pen list is for wxWidgets to keep
697 track of pens in order to clean them up on exit. It is also kept for
698 backward compatibility with earlier versions of wxWidgets.
699
700 @library{wxcore}
701 @category{gdi}
702
703 @see wxPen
704*/
705class wxPenList
706{
707public:
708 /**
709 Constructor. The application should not construct its own pen list:
710 use the object pointer @b wxThePenList.
711 */
712 wxPenList();
713
714 //@{
715 /**
716 Finds a pen with the specified attributes and returns it, else creates a new
717 pen, adds it
718 to the pen list, and returns it.
719
720 @param colour
721 Colour object.
722 @param colourName
723 Colour name, which should be in the colour database.
724 @param width
725 Width of pen.
726 @param style
727 Pen style. See wxPen::wxPen for a list of styles.
728 */
729 wxPen* FindOrCreatePen(const wxColour& colour, int width,
730 int style);
731 wxPen* FindOrCreatePen(const wxString& colourName, int width,
732 int style);
733 //@}
734};
735
736
737
738// ============================================================================
739// Global functions/macros
740// ============================================================================
741
742/** @ingroup group_funcmacro_gdi */
743//@{
744
745/**
746 Returns the dimensions of the work area on the display. On Windows
747 this means the area not covered by the taskbar, etc. Other platforms
748 are currently defaulting to the whole display until a way is found to
749 provide this info for all window managers, etc.
750*/
751void wxClientDisplayRect(int* x, int* y, int* width,
752 int* height);
753wxRect wxGetClientDisplayRect();
754
755/**
756 Returns the display size in pixels.
757*/
758void wxDisplaySize(int* width, int* height);
759wxSize wxGetDisplaySize();
760
761/**
762 Returns the display size in millimeters.
763*/
764void wxDisplaySizeMM(int* width, int* height);
765wxSize wxGetDisplaySizeMM();
766
767/**
768 This macro loads an icon from either application resources (on the platforms
769 for which they exist, i.e. Windows and OS2) or from an XPM file. It allows to
770 avoid using @c #ifdefs when creating icons.
771
772 @see @ref overview_wxbitmapoverview, wxBITMAP()
773*/
774wxICON();
775
776/**
777 Returns @true if the display is colour, @false otherwise.
778*/
779bool wxColourDisplay();
780
781/**
782 This macro loads a bitmap from either application resources (on the platforms
783 for which they exist, i.e. Windows and OS2) or from an XPM file. It allows to
784 avoid using @c #ifdefs when creating bitmaps.
785
786 @see @ref overview_wxbitmapoverview, wxICON()
787*/
788#define wxBITMAP() /* implementation is private */
789
790/**
791 Returns the depth of the display (a value of 1 denotes a monochrome display).
792*/
793int wxDisplayDepth();
794
795//@}
796