]> git.saurik.com Git - wxWidgets.git/blame - interface/dc.h
forward declare wxVideoMode as struct, not class, now that it was reverted to be...
[wxWidgets.git] / interface / dc.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: dc.h
e54c96f1 3// Purpose: interface of wxDC
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxDC
11 @wxheader{dc.h}
7c913512 12
23324ae1
FM
13 A wxDC is a @e device context onto which graphics and text can be drawn.
14 It is intended to represent a number of output devices in a generic way,
15 so a window can have a device context associated with it, and a printer also
16 has a device context.
17 In this way, the same piece of code may write to a number of different devices,
18 if the device context is used as a parameter.
7c913512 19
23324ae1 20 Notice that wxDC is an abstract base class and can't be created directly,
7c913512
FM
21 please use wxPaintDC, wxClientDC,
22 wxWindowDC, wxScreenDC,
23324ae1 23 wxMemoryDC or wxPrinterDC.
7c913512 24
23324ae1
FM
25 Please note that in addition to the versions of the methods documented here,
26 there are also versions which accept single @c wxPoint parameter instead of
27 two @c wxCoord ones or @c wxPoint and @c wxSize instead of four of
28 them.
5c02d584
FM
29
30 @todo Precise definition of default/initial state.
31
32 @todo Pixelwise definition of operations (e.g. last point of a line not drawn).
33
34 @todo Coordinates: state clearly which type of coordinates are returned by the
35 various Get*Point() or similar functions - often they are client coordinates
36 but not always
37
7c913512 38
23324ae1 39 @library{wxcore}
c0cc7004 40 @category{dc,gdi}
7c913512 41
e54c96f1 42 @see Overview()
23324ae1
FM
43*/
44class wxDC : public wxObject
45{
46public:
47 /**
48 Copy from a source DC to this DC, specifying the destination
49 coordinates, size of area to copy, source DC, source coordinates,
50 logical function, whether to use a bitmap mask, and mask source position.
3c4f71cc 51
7c913512 52 @param xdest
4cc4bfaf 53 Destination device context x position.
7c913512 54 @param ydest
4cc4bfaf 55 Destination device context y position.
7c913512 56 @param width
4cc4bfaf 57 Width of source area to be copied.
7c913512 58 @param height
4cc4bfaf 59 Height of source area to be copied.
7c913512 60 @param source
4cc4bfaf 61 Source device context.
7c913512 62 @param xsrc
4cc4bfaf 63 Source device context x position.
7c913512 64 @param ysrc
4cc4bfaf 65 Source device context y position.
7c913512 66 @param logicalFunc
4cc4bfaf 67 Logical function to use: see SetLogicalFunction().
7c913512 68 @param useMask
4cc4bfaf
FM
69 If @true, Blit does a transparent blit using the mask that is associated
70 with the bitmap
71 selected into the source device context. The Windows implementation does
72 the following if MaskBlt cannot be used:
3c4f71cc
VS
73
74
4cc4bfaf
FM
75 Creates a temporary bitmap and copies the destination area into it.
76 Copies the source area into the temporary bitmap using the specified
77 logical function.
78 Sets the masked area in the temporary bitmap to BLACK by ANDing the
79 mask bitmap with the temp bitmap with the foreground colour set to WHITE
80 and the bg colour set to BLACK.
81 Sets the unmasked area in the destination area to BLACK by ANDing the
82 mask bitmap with the destination area with the foreground colour set to
83 BLACK
84 and the background colour set to WHITE.
85 ORs the temporary bitmap with the destination area.
86 Deletes the temporary bitmap.
3c4f71cc
VS
87
88
4cc4bfaf
FM
89 This sequence of operations ensures that the source's transparent area need
90 not be black,
91 and logical functions are supported.
92 Note: on Windows, blitting with masks can be speeded up considerably by
23324ae1 93 compiling
4cc4bfaf 94 wxWidgets with the wxUSE_DC_CACHE option enabled. You can also influence
23324ae1 95 whether MaskBlt
4cc4bfaf
FM
96 or the explicit mask blitting code above is used, by using wxSystemOptions
97 and
98 setting the no-maskblt option to 1.
7c913512 99 @param xsrcMask
4cc4bfaf
FM
100 Source x position on the mask. If both xsrcMask and ysrcMask are -1, xsrc
101 and ysrc
102 will be assumed for the mask source position. Currently only implemented on
23324ae1 103 Windows.
7c913512 104 @param ysrcMask
4cc4bfaf
FM
105 Source y position on the mask. If both xsrcMask and ysrcMask are -1, xsrc
106 and ysrc
107 will be assumed for the mask source position. Currently only implemented on
23324ae1 108 Windows.
3c4f71cc 109
23324ae1 110 @remarks There is partial support for Blit in wxPostScriptDC, under X.
3c4f71cc 111
4cc4bfaf 112 @see StretchBlit(), wxMemoryDC, wxBitmap, wxMask
23324ae1
FM
113 */
114 bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width,
115 wxCoord height, wxDC* source,
116 wxCoord xsrc, wxCoord ysrc,
117 int logicalFunc = wxCOPY,
4cc4bfaf 118 bool useMask = false,
23324ae1
FM
119 wxCoord xsrcMask = -1,
120 wxCoord ysrcMask = -1);
121
122 /**
7c913512
FM
123 Adds the specified point to the bounding box which can be retrieved with
124 MinX(), MaxX() and
23324ae1 125 MinY(), MaxY() functions.
3c4f71cc 126
4cc4bfaf 127 @see ResetBoundingBox()
23324ae1
FM
128 */
129 void CalcBoundingBox(wxCoord x, wxCoord y);
130
131 /**
132 Clears the device context using the current background brush.
133 */
134 void Clear();
135
136 /**
137 Performs all necessary computations for given platform and context type
7c913512 138 after each change of scale and origin parameters. Usually called automatically
23324ae1
FM
139 internally after such changes.
140 */
141 virtual void ComputeScaleAndOrigin();
142
143 /**
144 Displays a cross hair using the current pen. This is a vertical
145 and horizontal line the height and width of the window, centred
146 on the given point.
147 */
148 void CrossHair(wxCoord x, wxCoord y);
149
150 /**
151 Destroys the current clipping region so that none of the DC is clipped.
152 See also SetClippingRegion().
153 */
154 void DestroyClippingRegion();
155
156 /**
157 Convert device X coordinate to logical coordinate, using the current
158 mapping mode.
159 */
160 virtual wxCoord DeviceToLogicalX(wxCoord x);
161
162 /**
163 Convert device X coordinate to relative logical coordinate, using the current
164 mapping mode but ignoring the x axis orientation.
165 Use this function for converting a width, for example.
166 */
167 virtual wxCoord DeviceToLogicalXRel(wxCoord x);
168
169 /**
170 Converts device Y coordinate to logical coordinate, using the current
171 mapping mode.
172 */
173 virtual wxCoord DeviceToLogicalY(wxCoord y);
174
175 /**
176 Convert device Y coordinate to relative logical coordinate, using the current
177 mapping mode but ignoring the y axis orientation.
178 Use this function for converting a height, for example.
179 */
180 virtual wxCoord DeviceToLogicalYRel(wxCoord y);
181
182 /**
183 Draws an arc of a circle, centred on (@e xc, yc), with starting point (@e x1,
184 y1)
185 and ending at (@e x2, y2). The current pen is used for the outline
186 and the current brush for filling the shape.
23324ae1
FM
187 The arc is drawn in an anticlockwise direction from the start point to the end
188 point.
189 */
190 void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
191 wxCoord xc, wxCoord yc);
192
193 /**
4cc4bfaf 194 Draw a bitmap on the device context at the specified point. If @a transparent
23324ae1
FM
195 is @true and the bitmap has
196 a transparency mask, the bitmap will be drawn transparently.
23324ae1
FM
197 When drawing a mono-bitmap, the current text foreground colour will be used to
198 draw the foreground
199 of the bitmap (all bits set to 1), and the current text background colour to
200 draw the background
7c913512 201 (all bits set to 0). See also SetTextForeground(),
23324ae1
FM
202 SetTextBackground() and wxMemoryDC.
203 */
204 void DrawBitmap(const wxBitmap& bitmap, wxCoord x, wxCoord y,
205 bool transparent);
206
207 //@{
208 /**
209 Draws a check mark inside the given rectangle.
210 */
211 void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width,
212 wxCoord height);
4cc4bfaf 213 void DrawCheckMark(const wxRect& rect);
23324ae1
FM
214 //@}
215
216 //@{
217 /**
218 Draws a circle with the given centre and radius.
3c4f71cc 219
4cc4bfaf 220 @see DrawEllipse()
23324ae1
FM
221 */
222 void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
7c913512 223 void DrawCircle(const wxPoint& pt, wxCoord radius);
23324ae1
FM
224 //@}
225
226 //@{
227 /**
228 Draws an ellipse contained in the rectangle specified either with the given top
229 left corner and the given size or directly. The current pen is used for the
230 outline and the current brush for filling the shape.
3c4f71cc 231
4cc4bfaf 232 @see DrawCircle()
23324ae1
FM
233 */
234 void DrawEllipse(wxCoord x, wxCoord y, wxCoord width,
235 wxCoord height);
7c913512
FM
236 void DrawEllipse(const wxPoint& pt, const wxSize& size);
237 void DrawEllipse(const wxRect& rect);
23324ae1
FM
238 //@}
239
240 /**
241 Draws an arc of an ellipse. The current pen is used for drawing the arc and
242 the current brush is used for drawing the pie.
4cc4bfaf 243 @a x and @a y specify the x and y coordinates of the upper-left corner of the
23324ae1
FM
244 rectangle that contains
245 the ellipse.
4cc4bfaf 246 @a width and @a height specify the width and height of the rectangle that
23324ae1
FM
247 contains
248 the ellipse.
4cc4bfaf 249 @a start and @a end specify the start and end of the arc relative to the
23324ae1
FM
250 three-o'clock
251 position from the center of the rectangle. Angles are specified
252 in degrees (360 is a complete circle). Positive values mean
4cc4bfaf 253 counter-clockwise motion. If @a start is equal to @e end, a
23324ae1
FM
254 complete ellipse will be drawn.
255 */
256 void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord width,
257 wxCoord height,
258 double start,
259 double end);
260
261 /**
262 Draw an icon on the display (does nothing if the device context is PostScript).
263 This can be the simplest way of drawing bitmaps on a window.
264 */
265 void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
266
267 //@{
268 /**
269 Draw optional bitmap and the text into the given rectangle and aligns it as
270 specified
271 by alignment parameter; it also will emphasize the character with the given
272 index if
273 it is != -1 and return the bounding rectangle if required.
274 */
275 virtual void DrawLabel(const wxString& text,
276 const wxBitmap& image,
277 const wxRect& rect,
278 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
279 int indexAccel = -1,
4cc4bfaf 280 wxRect* rectBounding = NULL);
7c913512
FM
281 void DrawLabel(const wxString& text, const wxRect& rect,
282 int alignment = wxALIGN_LEFT | wxALIGN_TOP,
283 int indexAccel = -1);
23324ae1
FM
284 //@}
285
286 /**
287 Draws a line from the first point to the second. The current pen is used
288 for drawing the line. Note that the point (x2, y2) is not part of the
289 line and is not drawn by this function (this is consistent with the behaviour
290 of many other toolkits).
291 */
292 void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
293
294 //@{
295 /**
296 This method uses a list of wxPoints, adding the optional offset
297 coordinate. The programmer is responsible for deleting the list
298 of points.
299 */
300 void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0,
301 wxCoord yoffset = 0);
4cc4bfaf 302 void DrawLines(const wxPointList* points,
7c913512
FM
303 wxCoord xoffset = 0,
304 wxCoord yoffset = 0);
23324ae1
FM
305 //@}
306
307 /**
308 Draws a point using the color of the current pen. Note that the other
309 properties of the pen are not used, such as width etc..
310 */
311 void DrawPoint(wxCoord x, wxCoord y);
312
313 /**
314 Draws two or more filled polygons using an array of @e points, adding the
315 optional offset coordinates.
23324ae1
FM
316 Notice that for the platforms providing a native implementation
317 of this function (Windows and PostScript-based wxDC currently), this is more
318 efficient than using DrawPolygon() in a loop.
4cc4bfaf
FM
319 @a n specifies the number of polygons to draw, the array @e count of size
320 @a n specifies the number of points in each of the polygons in the
23324ae1 321 @e points array.
23324ae1
FM
322 The last argument specifies the fill rule: @b wxODDEVEN_RULE (the default)
323 or @b wxWINDING_RULE.
23324ae1
FM
324 The current pen is used for drawing the outline, and the current brush for
325 filling the shape. Using a transparent brush suppresses filling.
23324ae1
FM
326 The polygons maybe disjoint or overlapping. Each polygon specified in a call to
327 @b DrawPolyPolygon must be closed. Unlike polygons created by the
328 DrawPolygon() member function, the polygons created by
329 @b DrawPolyPolygon are not closed automatically.
330 */
331 void DrawPolyPolygon(int n, int count[], wxPoint points[],
332 wxCoord xoffset = 0,
333 wxCoord yoffset = 0,
334 int fill_style = wxODDEVEN_RULE);
335
336 //@{
337 /**
338 This method draws a filled polygon using a list of wxPoints,
339 adding the optional offset coordinate.
23324ae1
FM
340 The last argument specifies the fill rule: @b wxODDEVEN_RULE (the
341 default) or @b wxWINDING_RULE.
23324ae1
FM
342 The current pen is used for drawing the outline, and the current brush
343 for filling the shape. Using a transparent brush suppresses filling.
344 The programmer is responsible for deleting the list of points.
23324ae1
FM
345 Note that wxWidgets automatically closes the first and last points.
346 */
347 void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0,
348 wxCoord yoffset = 0,
349 int fill_style = wxODDEVEN_RULE);
4cc4bfaf 350 void DrawPolygon(const wxPointList* points,
7c913512
FM
351 wxCoord xoffset = 0,
352 wxCoord yoffset = 0,
353 int fill_style = wxODDEVEN_RULE);
23324ae1
FM
354 //@}
355
356 /**
357 Draws a rectangle with the given top left corner, and with the given
358 size. The current pen is used for the outline and the current brush
359 for filling the shape.
360 */
361 void DrawRectangle(wxCoord x, wxCoord y, wxCoord width,
362 wxCoord height);
363
364 /**
4cc4bfaf 365 Draws the text rotated by @a angle degrees.
1f1d2182 366 @note Under Win9x only TrueType fonts can be drawn by this function. In
23324ae1
FM
367 particular, a font different from @c wxNORMAL_FONT should be used as the
368 latter is not a TrueType font. @c wxSWISS_FONT is an example of a font
369 which is.
3c4f71cc 370
4cc4bfaf 371 @see DrawText()
23324ae1
FM
372 */
373 void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
374 double angle);
375
376 /**
377 Draws a rectangle with the given top left corner, and with the given
378 size. The corners are quarter-circles using the given radius. The
379 current pen is used for the outline and the current brush for filling
380 the shape.
4cc4bfaf
FM
381 If @a radius is positive, the value is assumed to be the
382 radius of the rounded corner. If @a radius is negative,
23324ae1
FM
383 the absolute value is assumed to be the @e proportion of the smallest
384 dimension of the rectangle. This means that the corner can be
385 a sensible size relative to the size of the rectangle, and also avoids
386 the strange effects X produces when the corners are too big for
387 the rectangle.
388 */
389 void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width,
390 wxCoord height,
391 double radius);
392
393 //@{
394 /**
395 Draws a three-point spline using the current pen.
396 */
397 void DrawSpline(int n, wxPoint points[]);
4cc4bfaf 398 void DrawSpline(const wxPointList* points);
7c913512
FM
399 void DrawSpline(wxCoord x1, wxCoord y1, wxCoord x2,
400 wxCoord y2,
401 wxCoord x3,
402 wxCoord y3);
23324ae1
FM
403 //@}
404
405 /**
406 Draws a text string at the specified point, using the current text font,
407 and the current text foreground and background colours.
23324ae1
FM
408 The coordinates refer to the top-left corner of the rectangle bounding
409 the string. See GetTextExtent() for how
410 to get the dimensions of a text string, which can be used to position the
411 text more precisely.
1f1d2182 412 @note under wxGTK the current
23324ae1
FM
413 @ref getlogicalfunction() "logical function" is used by this function
414 but it is ignored by wxMSW. Thus, you should avoid using logical functions
415 with this function in portable programs.
416 */
417 void DrawText(const wxString& text, wxCoord x, wxCoord y);
418
419 /**
420 Ends a document (only relevant when outputting to a printer).
421 */
422 void EndDoc();
423
424 /**
425 Ends a document page (only relevant when outputting to a printer).
426 */
427 void EndPage();
428
429 /**
430 Flood fills the device context starting from the given point, using
431 the @e current brush colour, and using a style:
23324ae1
FM
432 wxFLOOD_SURFACE: the flooding occurs until a colour other than the given
433 colour is encountered.
434 wxFLOOD_BORDER: the area to be flooded is bounded by the given colour.
23324ae1 435 Returns @false if the operation failed.
23324ae1
FM
436 @e Note: The present implementation for non-Windows platforms may fail to find
437 colour borders if the pixels do not match the colour exactly. However the
438 function will still return @true.
439 */
440 bool FloodFill(wxCoord x, wxCoord y, const wxColour& colour,
4cc4bfaf 441 int style = wxFLOOD_SURFACE);
23324ae1
FM
442
443 /**
444 Gets the brush used for painting the background (see wxDC::SetBackground).
445 */
328f5751 446 const wxBrush GetBackground() const;
23324ae1
FM
447
448 /**
449 Returns the current background mode: @c wxSOLID or @c wxTRANSPARENT.
3c4f71cc 450
4cc4bfaf 451 @see SetBackgroundMode()
23324ae1 452 */
328f5751 453 int GetBackgroundMode() const;
23324ae1
FM
454
455 /**
456 Gets the current brush (see wxDC::SetBrush).
457 */
328f5751 458 const wxBrush GetBrush() const;
23324ae1
FM
459
460 /**
461 Gets the character height of the currently set font.
462 */
463 wxCoord GetCharHeight();
464
465 /**
466 Gets the average character width of the currently set font.
467 */
468 wxCoord GetCharWidth();
469
470 /**
471 Gets the rectangle surrounding the current clipping region.
472 */
473 void GetClippingBox(wxCoord x, wxCoord y, wxCoord width,
474 wxCoord height);
475
476 /**
477 Returns the depth (number of bits/pixel) of this DC.
3c4f71cc 478
e54c96f1 479 @see wxDisplayDepth()
23324ae1 480 */
328f5751 481 int GetDepth() const;
23324ae1
FM
482
483 /**
484 Gets the current font. Notice that even although each device context object has
7c913512 485 some default font after creation, this method would return a @c wxNullFont
23324ae1
FM
486 initially and only after calling SetFont() a valid
487 font is returned.
488 */
328f5751 489 const wxFont GetFont() const;
23324ae1
FM
490
491 /**
492 Gets the current layout direction of the device context. On platforms where RTL
493 layout
7c913512
FM
494 is supported, the return value will either be @c wxLayout_LeftToRight or
495 @c wxLayout_RightToLeft. If RTL layout is not supported, the return value will
23324ae1 496 be @c wxLayout_Default.
3c4f71cc 497
4cc4bfaf 498 @see SetLayoutDirection()
23324ae1 499 */
328f5751 500 wxLayoutDirection GetLayoutDirection() const;
23324ae1
FM
501
502 /**
503 Gets the current logical function (see wxDC::SetLogicalFunction).
504 */
505 int GetLogicalFunction();
506
507 /**
508 Gets the @e mapping mode for the device context (see wxDC::SetMapMode).
509 */
510 int GetMapMode();
511
512 //@{
513 /**
514 Gets the dimensions of the string using the currently selected font.
4cc4bfaf 515 @a string is the text string to measure, @e heightLine, if non @NULL,
23324ae1 516 is where to store the height of a single line.
4cc4bfaf 517 The text extent is returned in @a w and @a h pointers (first form) or as
23324ae1 518 a wxSize object (second form).
4cc4bfaf 519 If the optional parameter @a font is specified and valid, then it is used
23324ae1 520 for the text extent calculation. Otherwise the currently selected font is.
23324ae1 521 Note that this function works both with single-line and multi-line strings.
3c4f71cc 522
4cc4bfaf 523 @see wxFont, SetFont(), GetPartialTextExtents(), GetTextExtent()
23324ae1 524 */
4cc4bfaf
FM
525 void GetMultiLineTextExtent(const wxString& string, wxCoord* w,
526 wxCoord* h,
527 wxCoord* heightLine = NULL,
328f5751
FM
528 wxFont* font = NULL) const;
529 const wxSize GetMultiLineTextExtent(const wxString& string) const;
23324ae1
FM
530 //@}
531
532 /**
533 Returns the resolution of the device in pixels per inch.
534 */
328f5751 535 wxSize GetPPI() const;
23324ae1
FM
536
537 /**
4cc4bfaf
FM
538 Fills the @a widths array with the widths from the beginning of
539 @a text to the corresponding character of @e text. The generic
23324ae1
FM
540 version simply builds a running total of the widths of each character
541 using GetTextExtent(), however if the
542 various platforms have a native API function that is faster or more
543 accurate than the generic implementation then it should be used
7c913512 544 instead.
3c4f71cc 545
4cc4bfaf 546 @see GetMultiLineTextExtent(), GetTextExtent()
23324ae1
FM
547 */
548 bool GetPartialTextExtents(const wxString& text,
328f5751 549 wxArrayInt& widths) const;
23324ae1
FM
550
551 /**
552 Gets the current pen (see wxDC::SetPen).
553 */
328f5751 554 const wxPen GetPen() const;
23324ae1
FM
555
556 /**
4cc4bfaf 557 Gets in @a colour the colour at the specified location.
23324ae1 558 Not available for wxPostScriptDC or wxMetafileDC.
23324ae1
FM
559 Note that setting a pixel can be done using DrawPoint().
560 */
4cc4bfaf 561 bool GetPixel(wxCoord x, wxCoord y, wxColour* colour);
23324ae1
FM
562
563 //@{
564 /**
565 This gets the horizontal and vertical resolution in device units. It can be
566 used to scale graphics to fit the page.
567 For example, if @e maxX and @e maxY
568 represent the maximum horizontal and vertical 'pixel' values used in your
569 application, the following code will scale the graphic to fit on the
570 printer page:
3c4f71cc
VS
571
572
23324ae1 573 @b GetSize()
3c4f71cc 574
23324ae1 575 Returns a Wx::Size
3c4f71cc 576
23324ae1 577 @b GetSizeWH()
3c4f71cc 578
23324ae1
FM
579 Returns a 2-element list
580 @c ( width, height )
581 */
328f5751
FM
582 void GetSize(wxCoord* width, wxCoord* height) const;
583 const wxSize GetSize() const;
23324ae1
FM
584 //@}
585
586 //@{
587 /**
588 Returns the horizontal and vertical resolution in millimetres.
589 */
328f5751
FM
590 void GetSizeMM(wxCoord* width, wxCoord* height) const;
591 const wxSize GetSizeMM() const;
23324ae1
FM
592 //@}
593
594 /**
595 Gets the current text background colour (see wxDC::SetTextBackground).
596 */
328f5751 597 const wxColour GetTextBackground() const;
23324ae1
FM
598
599 //@{
600 /**
601 Gets the dimensions of the string using the currently selected font.
4cc4bfaf 602 @a string is the text string to measure, @a descent is the
23324ae1 603 dimension from the baseline of the font to the bottom of the
4cc4bfaf 604 descender, and @a externalLeading is any extra vertical space added
23324ae1 605 to the font by the font designer (usually is zero).
4cc4bfaf 606 The text extent is returned in @a w and @a h pointers (first form) or as
23324ae1 607 a wxSize object (second form).
4cc4bfaf 608 If the optional parameter @a font is specified and valid, then it is used
23324ae1 609 for the text extent calculation. Otherwise the currently selected font is.
23324ae1 610 Note that this function only works with single-line strings.
3c4f71cc 611
4cc4bfaf
FM
612 @see wxFont, SetFont(), GetPartialTextExtents(),
613 GetMultiLineTextExtent()
614 */
615 void GetTextExtent(const wxString& string, wxCoord* w,
616 wxCoord* h,
617 wxCoord* descent = NULL,
618 wxCoord* externalLeading = NULL,
328f5751
FM
619 const wxFont* font = NULL) const;
620 const wxSize GetTextExtent(const wxString& string) const;
23324ae1
FM
621 //@}
622
623 /**
624 Gets the current text foreground colour (see wxDC::SetTextForeground).
625 */
328f5751 626 const wxColour GetTextForeground() const;
23324ae1
FM
627
628 /**
629 Gets the current user scale factor (set by wxDC::SetUserScale).
630 */
631 void GetUserScale(double x, double y);
632
633 //@{
634 /**
7c913512 635 Fill the area specified by rect with a radial gradient, starting from
4cc4bfaf 636 @a initialColour at the centre of the circle and fading to @a destColour
23324ae1 637 on the circle outside.
4cc4bfaf 638 @a circleCenter are the relative coordinates of centre of the circle in
23324ae1
FM
639 the specified @e rect. If not specified, the cercle is placed at the
640 centre of rect.
cdbcf4c2 641 @note Currently this function is very slow, don't use it for
23324ae1
FM
642 real-time drawing.
643 */
644 void GradientFillConcentric(const wxRect& rect,
645 const wxColour& initialColour,
646 const wxColour& destColour);
7c913512
FM
647 void GradientFillConcentric(const wxRect& rect,
648 const wxColour& initialColour,
649 const wxColour& destColour,
650 const wxPoint& circleCenter);
23324ae1
FM
651 //@}
652
653 /**
4cc4bfaf
FM
654 Fill the area specified by @a rect with a linear gradient, starting from
655 @a initialColour and eventually fading to @e destColour. The
656 @a nDirection specifies the direction of the colour change, default is to
657 use @a initialColour on the left part of the rectangle and
658 @a destColour on the right one.
23324ae1
FM
659 */
660 void GradientFillLinear(const wxRect& rect,
661 const wxColour& initialColour,
662 const wxColour& destColour,
663 wxDirection nDirection = wxEAST);
664
665 /**
666 Returns @true if the DC is ok to use.
667 */
4cc4bfaf 668 bool Ok();
23324ae1
FM
669
670 /**
671 Converts logical X coordinate to device coordinate, using the current
672 mapping mode.
673 */
674 virtual wxCoord LogicalToDeviceX(wxCoord x);
675
676 /**
677 Converts logical X coordinate to relative device coordinate, using the current
678 mapping mode but ignoring the x axis orientation.
679 Use this for converting a width, for example.
680 */
681 virtual wxCoord LogicalToDeviceXRel(wxCoord x);
682
683 /**
684 Converts logical Y coordinate to device coordinate, using the current
685 mapping mode.
686 */
687 virtual wxCoord LogicalToDeviceY(wxCoord y);
688
689 /**
690 Converts logical Y coordinate to relative device coordinate, using the current
691 mapping mode but ignoring the y axis orientation.
692 Use this for converting a height, for example.
693 */
694 virtual wxCoord LogicalToDeviceYRel(wxCoord y);
695
696 /**
697 Gets the maximum horizontal extent used in drawing commands so far.
698 */
4cc4bfaf 699 wxCoord MaxX();
23324ae1
FM
700
701 /**
702 Gets the maximum vertical extent used in drawing commands so far.
703 */
4cc4bfaf 704 wxCoord MaxY();
23324ae1
FM
705
706 /**
707 Gets the minimum horizontal extent used in drawing commands so far.
708 */
4cc4bfaf 709 wxCoord MinX();
23324ae1
FM
710
711 /**
712 Gets the minimum vertical extent used in drawing commands so far.
713 */
4cc4bfaf 714 wxCoord MinY();
23324ae1
FM
715
716 /**
717 Resets the bounding box: after a call to this function, the bounding box
718 doesn't contain anything.
3c4f71cc 719
4cc4bfaf 720 @see CalcBoundingBox()
23324ae1
FM
721 */
722 void ResetBoundingBox();
723
724 /**
725 Sets the x and y axis orientation (i.e., the direction from lowest to
7c913512 726 highest values on the axis). The default orientation is
23324ae1 727 x axis from left to right and y axis from top down.
3c4f71cc 728
7c913512 729 @param xLeftRight
4cc4bfaf
FM
730 True to set the x axis orientation to the natural
731 left to right orientation, @false to invert it.
7c913512 732 @param yBottomUp
4cc4bfaf
FM
733 True to set the y axis orientation to the natural
734 bottom up orientation, @false to invert it.
23324ae1
FM
735 */
736 void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
737
738 /**
739 Sets the current background brush for the DC.
740 */
741 void SetBackground(const wxBrush& brush);
742
743 /**
4cc4bfaf 744 @a mode may be one of wxSOLID and wxTRANSPARENT. This setting determines
23324ae1
FM
745 whether text will be drawn with a background colour or not.
746 */
747 void SetBackgroundMode(int mode);
748
749 /**
750 Sets the current brush for the DC.
23324ae1
FM
751 If the argument is wxNullBrush, the current brush is selected out of the device
752 context (leaving wxDC without any valid brush), allowing the current brush to
753 be destroyed safely.
23324ae1 754 See also wxBrush.
23324ae1
FM
755 See also wxMemoryDC for the interpretation of colours
756 when drawing into a monochrome bitmap.
757 */
758 void SetBrush(const wxBrush& brush);
759
760 //@{
761 /**
762 Sets the clipping region for this device context to the intersection of the
763 given region described by the parameters of this method and the previously set
7c913512 764 clipping region. You should call
23324ae1
FM
765 DestroyClippingRegion() if you want to set
766 the clipping region exactly to the region specified.
23324ae1
FM
767 The clipping region is an area to which drawing is restricted. Possible uses
768 for the clipping region are for clipping text or for speeding up window redraws
769 when only a known area of the screen is damaged.
3c4f71cc 770
4cc4bfaf 771 @see DestroyClippingRegion(), wxRegion
23324ae1
FM
772 */
773 void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width,
774 wxCoord height);
7c913512
FM
775 void SetClippingRegion(const wxPoint& pt, const wxSize& sz);
776 void SetClippingRegion(const wxRect& rect);
777 void SetClippingRegion(const wxRegion& region);
23324ae1
FM
778 //@}
779
780 /**
781 Sets the device origin (i.e., the origin in pixels after scaling has been
782 applied).
23324ae1
FM
783 This function may be useful in Windows printing
784 operations for placing a graphic on a page.
785 */
786 void SetDeviceOrigin(wxCoord x, wxCoord y);
787
788 /**
789 Sets the current font for the DC. It must be a valid font, in particular you
790 should not pass @c wxNullFont to this method.
23324ae1
FM
791 See also wxFont.
792 */
793 void SetFont(const wxFont& font);
794
795 /**
4cc4bfaf 796 Sets the current layout direction for the device context. @a dir may be either
23324ae1 797 @c wxLayout_Default, @c wxLayout_LeftToRight or @c wxLayout_RightToLeft.
3c4f71cc 798
4cc4bfaf 799 @see GetLayoutDirection()
23324ae1
FM
800 */
801 void SetLayoutDirection(wxLayoutDirection dir);
802
803 /**
804 Sets the current logical function for the device context. This determines how
805 a source pixel (from a pen or brush colour, or source device context if
806 using wxDC::Blit) combines with a destination pixel in the
807 current device context.
23324ae1
FM
808 The possible values
809 and their meaning in terms of source and destination pixel values are
810 as follows:
3c4f71cc 811
23324ae1
FM
812 The default is wxCOPY, which simply draws with the current colour.
813 The others combine the current colour and the background using a
814 logical operation. wxINVERT is commonly used for drawing rubber bands or
815 moving outlines, since drawing twice reverts to the original colour.
816 */
817 void SetLogicalFunction(int function);
818
819 /**
820 The @e mapping mode of the device context defines the unit of
821 measurement used to convert logical units to device units. Note that
822 in X, text drawing isn't handled consistently with the mapping mode; a
823 font is always specified in point size. However, setting the @e user scale (see
824 wxDC::SetUserScale) scales the text appropriately. In
825 Windows, scalable TrueType fonts are always used; in X, results depend
826 on availability of fonts, but usually a reasonable match is found.
23324ae1 827 The coordinate origin is always at the top left of the screen/printer.
23324ae1
FM
828 Drawing to a Windows printer device context uses the current mapping mode,
829 but mapping mode is currently ignored for PostScript output.
23324ae1 830 The mapping mode can be one of the following:
3c4f71cc 831
23324ae1 832 wxMM_TWIPS
3c4f71cc 833
23324ae1
FM
834 Each logical unit is 1/20 of a point, or 1/1440 of
835 an inch.
3c4f71cc 836
23324ae1 837 wxMM_POINTS
3c4f71cc 838
23324ae1 839 Each logical unit is a point, or 1/72 of an inch.
3c4f71cc 840
23324ae1 841 wxMM_METRIC
3c4f71cc 842
23324ae1 843 Each logical unit is 1 mm.
3c4f71cc 844
23324ae1 845 wxMM_LOMETRIC
3c4f71cc 846
23324ae1 847 Each logical unit is 1/10 of a mm.
3c4f71cc 848
23324ae1 849 wxMM_TEXT
3c4f71cc 850
23324ae1
FM
851 Each logical unit is 1 device pixel.
852 */
853 void SetMapMode(int int);
854
855 /**
856 If this is a window DC or memory DC, assigns the given palette to the window
857 or bitmap associated with the DC. If the argument is wxNullPalette, the current
858 palette is selected out of the device context, and the original palette
859 restored.
23324ae1
FM
860 See wxPalette for further details.
861 */
862 void SetPalette(const wxPalette& palette);
863
864 /**
865 Sets the current pen for the DC.
23324ae1
FM
866 If the argument is wxNullPen, the current pen is selected out of the device
867 context (leaving wxDC without any valid pen), allowing the current brush to
868 be destroyed safely.
23324ae1
FM
869 See also wxMemoryDC for the interpretation of colours
870 when drawing into a monochrome bitmap.
871 */
872 void SetPen(const wxPen& pen);
873
874 /**
875 Sets the current text background colour for the DC.
876 */
877 void SetTextBackground(const wxColour& colour);
878
879 /**
880 Sets the current text foreground colour for the DC.
23324ae1
FM
881 See also wxMemoryDC for the interpretation of colours
882 when drawing into a monochrome bitmap.
883 */
884 void SetTextForeground(const wxColour& colour);
885
886 /**
887 Sets the user scaling factor, useful for applications which require
888 'zooming'.
889 */
890 void SetUserScale(double xScale, double yScale);
891
892 /**
893 Starts a document (only relevant when outputting to a printer).
894 Message is a message to show while printing.
895 */
896 bool StartDoc(const wxString& message);
897
898 /**
899 Starts a document page (only relevant when outputting to a printer).
900 */
901 bool StartPage();
902
903 /**
904 Copy from a source DC to this DC, specifying the destination
905 coordinates, destination size, source DC, source coordinates,
7c913512 906 size of source area to copy, logical function, whether to use a bitmap mask,
23324ae1 907 and mask source position.
3c4f71cc 908
7c913512 909 @param xdest
4cc4bfaf 910 Destination device context x position.
7c913512 911 @param ydest
4cc4bfaf 912 Destination device context y position.
7c913512 913 @param dstWidth
4cc4bfaf 914 Width of destination area.
7c913512 915 @param dstHeight
4cc4bfaf 916 Height of destination area.
7c913512 917 @param source
4cc4bfaf 918 Source device context.
7c913512 919 @param xsrc
4cc4bfaf 920 Source device context x position.
7c913512 921 @param ysrc
4cc4bfaf 922 Source device context y position.
7c913512 923 @param srcWidth
4cc4bfaf 924 Width of source area to be copied.
7c913512 925 @param srcHeight
4cc4bfaf 926 Height of source area to be copied.
7c913512 927 @param logicalFunc
4cc4bfaf 928 Logical function to use: see SetLogicalFunction().
7c913512 929 @param useMask
4cc4bfaf
FM
930 If @true, Blit does a transparent blit using the mask that is associated
931 with the bitmap
932 selected into the source device context. The Windows implementation does
933 the following if MaskBlt cannot be used:
3c4f71cc
VS
934
935
4cc4bfaf
FM
936 Creates a temporary bitmap and copies the destination area into it.
937 Copies the source area into the temporary bitmap using the specified
938 logical function.
939 Sets the masked area in the temporary bitmap to BLACK by ANDing the
940 mask bitmap with the temp bitmap with the foreground colour set to WHITE
941 and the background colour set to BLACK.
942 Sets the unmasked area in the destination area to BLACK by ANDing the
943 mask bitmap with the destination area with the foreground colour set to
944 BLACK
945 and the background colour set to WHITE.
946 ORs the temporary bitmap with the destination area.
947 Deletes the temporary bitmap.
3c4f71cc
VS
948
949
4cc4bfaf
FM
950 This sequence of operations ensures that the source's transparent area need
951 not be black,
952 and logical functions are supported.
953 Note: on Windows, blitting with masks can be speeded up considerably by
23324ae1 954 compiling
4cc4bfaf 955 wxWidgets with the wxUSE_DC_CACHE option enabled. You can also influence
23324ae1 956 whether MaskBlt
4cc4bfaf
FM
957 or the explicit mask blitting code above is used, by using wxSystemOptions
958 and
959 setting the no-maskblt option to 1.
7c913512 960 @param xsrcMask
4cc4bfaf
FM
961 Source x position on the mask. If both xsrcMask and ysrcMask are -1, xsrc
962 and ysrc
963 will be assumed for the mask source position. Currently only implemented on
23324ae1 964 Windows.
7c913512 965 @param ysrcMask
4cc4bfaf
FM
966 Source y position on the mask. If both xsrcMask and ysrcMask are -1, xsrc
967 and ysrc
968 will be assumed for the mask source position. Currently only implemented on
23324ae1 969 Windows.
3c4f71cc 970
23324ae1
FM
971 @remarks There is partial support for Blit in wxPostScriptDC, under X.
972 */
973 bool StretchBlit(wxCoord xdest, wxCoord ydest, wxCoord dstWidth,
974 wxCoord dstHeight,
975 wxDC* source, wxCoord xsrc,
976 wxCoord ysrc,
977 wxCoord srcWidth,
978 wxCoord srcHeight,
979 int logicalFunc = wxCOPY,
4cc4bfaf 980 bool useMask = false,
23324ae1
FM
981 wxCoord xsrcMask = -1,
982 wxCoord ysrcMask = -1);
983};
984
985
e54c96f1 986
23324ae1
FM
987/**
988 @class wxDCClipper
989 @wxheader{dc.h}
7c913512
FM
990
991 wxDCClipper is a small helper class for setting a clipping region on a
23324ae1
FM
992 wxDC and unsetting it automatically. An object of wxDCClipper
993 class is typically created on the stack so that it is automatically destroyed
994 when the object goes out of scope. A typical usage example:
7c913512 995
23324ae1
FM
996 @code
997 void MyFunction(wxDC& dc)
998 {
999 wxDCClipper clip(rect);
1000 ... drawing functions here are affected by clipping rect ...
1001 }
7c913512 1002
23324ae1
FM
1003 void OtherFunction()
1004 {
1005 wxDC dc;
1006 MyFunction(dc);
1007 ... drawing functions here are not affected by clipping rect ...
1008 }
1009 @endcode
7c913512 1010
23324ae1
FM
1011 @library{wxcore}
1012 @category{gdi}
7c913512 1013
e54c96f1 1014 @see wxDC::SetClippingRegion
23324ae1 1015*/
7c913512 1016class wxDCClipper
23324ae1
FM
1017{
1018public:
1019 //@{
1020 /**
4cc4bfaf
FM
1021 Sets the clipping region to the specified region @a r or rectangle specified
1022 by either a single @a rect parameter or its position (@a x and @e y)
1023 and size (@a w ad @e h).
23324ae1
FM
1024 The clipping region is automatically unset when this object is destroyed.
1025 */
1026 wxDCClipper(wxDC& dc, const wxRegion& r);
7c913512
FM
1027 wxDCClipper(wxDC& dc, const wxRect& rect);
1028 wxDCClipper(wxDC& dc, int x, int y, int w, int h);
23324ae1
FM
1029 //@}
1030};
e54c96f1 1031