dc.h 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: dc.h
  3. // Purpose: interface of wxDC
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Logical raster operations which can be used with wxDC::SetLogicalFunction
  9. and some other wxDC functions (e.g. wxDC::Blit and wxDC::StretchBlit).
  10. The description of the values below refer to how a generic @e src source pixel
  11. and the corresponding @e dst destination pixel gets combined together to produce
  12. the final pixel. E.g. @c wxCLEAR and @c wxSET completely ignore the source
  13. and the destination pixel and always put zeroes or ones in the final surface.
  14. */
  15. enum wxRasterOperationMode
  16. {
  17. wxCLEAR, //!< 0
  18. wxXOR, //!< @e src XOR @e dst
  19. wxINVERT, //!< NOT @e dst
  20. wxOR_REVERSE, //!< @e src OR (NOT @e dst)
  21. wxAND_REVERSE, //!< @e src AND (NOT @e dst)
  22. wxCOPY, //!< @e src
  23. wxAND, //!< @e src AND @e dst
  24. wxAND_INVERT, //!< (NOT @e src) AND @e dst
  25. wxNO_OP, //!< @e dst
  26. wxNOR, //!< (NOT @e src) AND (NOT @e dst)
  27. wxEQUIV, //!< (NOT @e src) XOR @e dst
  28. wxSRC_INVERT, //!< (NOT @e src)
  29. wxOR_INVERT, //!< (NOT @e src) OR @e dst
  30. wxNAND, //!< (NOT @e src) OR (NOT @e dst)
  31. wxOR, //!< @e src OR @e dst
  32. wxSET //!< 1
  33. };
  34. /**
  35. Flood styles used by wxDC::FloodFill.
  36. */
  37. enum wxFloodFillStyle
  38. {
  39. /** The flooding occurs until a colour other than the given colour is encountered. */
  40. wxFLOOD_SURFACE = 1,
  41. /** The area to be flooded is bounded by the given colour. */
  42. wxFLOOD_BORDER
  43. };
  44. /**
  45. The mapping used to transform @e logical units to @e device units.
  46. See wxDC::SetMapMode.
  47. */
  48. enum wxMappingMode
  49. {
  50. /**
  51. Each logical unit is 1 device pixel.
  52. This is the default mapping mode for all wxDC-derived classes.
  53. */
  54. wxMM_TEXT = 1,
  55. /** Each logical unit is 1 millimeter. */
  56. wxMM_METRIC,
  57. /** Each logical unit is 1/10 of a millimeter. */
  58. wxMM_LOMETRIC,
  59. /**
  60. Each logical unit is 1/20 of a @e "printer point", or 1/1440 of an inch
  61. (also known as "twip"). Equivalent to about 17.64 micrometers.
  62. */
  63. wxMM_TWIPS,
  64. /**
  65. Each logical unit is a @e "printer point" i.e.\ 1/72 of an inch.
  66. Equivalent to about 353 micrometers.
  67. */
  68. wxMM_POINTS
  69. };
  70. /**
  71. Simple collection of various font metrics.
  72. This object is returned by wxDC::GetFontMetrics().
  73. @since 2.9.2
  74. @library{wxcore}
  75. @category{dc,gdi}
  76. */
  77. struct wxFontMetrics
  78. {
  79. /// Constructor initializes all fields to 0.
  80. wxFontMetrics();
  81. int height, ///< Total character height.
  82. ascent, ///< Part of the height above the baseline.
  83. descent, ///< Part of the height below the baseline.
  84. internalLeading, ///< Intra-line spacing.
  85. externalLeading, ///< Inter-line spacing.
  86. averageWidth; ///< Average font width, a.k.a. "x-width".
  87. };
  88. /**
  89. @class wxDC
  90. A wxDC is a @e "device context" onto which graphics and text can be drawn.
  91. It is intended to represent different output devices and offers a common
  92. abstract API for drawing on any of them.
  93. wxWidgets offers an alternative drawing API based on the modern drawing
  94. backends GDI+, CoreGraphics and Cairo. See wxGraphicsContext, wxGraphicsRenderer
  95. and related classes. There is also a wxGCDC linking the APIs by offering
  96. the wxDC API on top of a wxGraphicsContext.
  97. wxDC is an abstract base class and cannot be created directly.
  98. Use wxPaintDC, wxClientDC, wxWindowDC, wxScreenDC, wxMemoryDC or
  99. wxPrinterDC. Notice that device contexts which are associated with windows
  100. (i.e. wxClientDC, wxWindowDC and wxPaintDC) use the window font and colours
  101. by default (starting with wxWidgets 2.9.0) but the other device context
  102. classes use system-default values so you always must set the appropriate
  103. fonts and colours before using them.
  104. In addition to the versions of the methods documented below, there
  105. are also versions which accept single wxPoint parameter instead
  106. of the two wxCoord ones or wxPoint and wxSize instead of the four
  107. wxCoord parameters.
  108. Beginning with wxWidgets 2.9.0 the entire wxDC code has been
  109. reorganized. All platform dependent code (actually all drawing code)
  110. has been moved into backend classes which derive from a common
  111. wxDCImpl class. The user-visible classes such as wxClientDC and
  112. wxPaintDC merely forward all calls to the backend implementation.
  113. @section dc_units Device and logical units
  114. In the wxDC context there is a distinction between @e logical units and @e device units.
  115. @b Device units are the units native to the particular device; e.g. for a screen,
  116. a device unit is a @e pixel. For a printer, the device unit is defined by the
  117. resolution of the printer (usually given in @c DPI: dot-per-inch).
  118. All wxDC functions use instead @b logical units, unless where explicitly
  119. stated. Logical units are arbitrary units mapped to device units using
  120. the current mapping mode (see wxDC::SetMapMode).
  121. This mechanism allows to reuse the same code which prints on e.g. a window
  122. on the screen to print on e.g. a paper.
  123. @section dc_alpha_support Support for Transparency / Alpha Channel
  124. In general wxDC methods don't support alpha transparency and the alpha
  125. component of wxColour is simply ignored and you need to use wxGraphicsContext
  126. for full transparency support. There are, however, a few exceptions: first,
  127. under Mac OS X colours with alpha channel are supported in all the normal
  128. wxDC-derived classes as they use wxGraphicsContext internally. Second,
  129. under all platforms wxSVGFileDC also fully supports alpha channel. In both
  130. of these cases the instances of wxPen or wxBrush that are built from
  131. wxColour use the colour's alpha values when stroking or filling.
  132. @section Support for Transformation Matrix
  133. On some platforms (currently only under MSW and only on Windows NT, i.e.
  134. not Windows 9x/ME, systems) wxDC has support for applying an arbitrary
  135. affine transformation matrix to its coordinate system. Call
  136. CanUseTransformMatrix() to check if this support is available and then call
  137. SetTransformMatrix() if it is. If the transformation matrix is not
  138. supported, SetTransformMatrix() always simply returns false and doesn't do
  139. anything.
  140. @library{wxcore}
  141. @category{dc,gdi}
  142. @see @ref overview_dc, wxGraphicsContext, wxDCFontChanger, wxDCTextColourChanger,
  143. wxDCPenChanger, wxDCBrushChanger, wxDCClipper
  144. @todo Precise definition of default/initial state.
  145. @todo Pixelwise definition of operations (e.g. last point of a line not
  146. drawn).
  147. */
  148. class wxDC : public wxObject
  149. {
  150. public:
  151. /**
  152. @name Coordinate conversion functions
  153. */
  154. //@{
  155. /**
  156. Convert @e device X coordinate to logical coordinate, using the current
  157. mapping mode, user scale factor, device origin and axis orientation.
  158. */
  159. wxCoord DeviceToLogicalX(wxCoord x) const;
  160. /**
  161. Convert @e device X coordinate to relative logical coordinate, using the
  162. current mapping mode and user scale factor but ignoring the
  163. axis orientation. Use this for converting a width, for example.
  164. */
  165. wxCoord DeviceToLogicalXRel(wxCoord x) const;
  166. /**
  167. Converts @e device Y coordinate to logical coordinate, using the current
  168. mapping mode, user scale factor, device origin and axis orientation.
  169. */
  170. wxCoord DeviceToLogicalY(wxCoord y) const;
  171. /**
  172. Convert @e device Y coordinate to relative logical coordinate, using the
  173. current mapping mode and user scale factor but ignoring the
  174. axis orientation. Use this for converting a height, for example.
  175. */
  176. wxCoord DeviceToLogicalYRel(wxCoord y) const;
  177. /**
  178. Converts logical X coordinate to device coordinate, using the current
  179. mapping mode, user scale factor, device origin and axis orientation.
  180. */
  181. wxCoord LogicalToDeviceX(wxCoord x) const;
  182. /**
  183. Converts logical X coordinate to relative device coordinate, using the
  184. current mapping mode and user scale factor but ignoring the
  185. axis orientation. Use this for converting a width, for example.
  186. */
  187. wxCoord LogicalToDeviceXRel(wxCoord x) const;
  188. /**
  189. Converts logical Y coordinate to device coordinate, using the current
  190. mapping mode, user scale factor, device origin and axis orientation.
  191. */
  192. wxCoord LogicalToDeviceY(wxCoord y) const;
  193. /**
  194. Converts logical Y coordinate to relative device coordinate, using the
  195. current mapping mode and user scale factor but ignoring the
  196. axis orientation. Use this for converting a height, for example.
  197. */
  198. wxCoord LogicalToDeviceYRel(wxCoord y) const;
  199. //@}
  200. /**
  201. @name Drawing functions
  202. */
  203. //@{
  204. /**
  205. Clears the device context using the current background brush.
  206. */
  207. void Clear();
  208. /**
  209. Draws an arc from the given start to the given end point.
  210. @note DrawEllipticArc() has more clear semantics and it is recommended
  211. to use it instead of this function.
  212. The arc drawn is an arc of the circle centered at (@a xc, @a yc). Its
  213. start point is (@a xStart, @a yStart) whereas its end point is the
  214. point of intersection of the line passing by (@a xc, @a yc) and (@a
  215. xEnd, @a yEnd) with the circle passing by (@a xStart, @a yStart).
  216. The arc is drawn in a counter-clockwise direction between the start and
  217. the end points.
  218. The current pen is used for the outline and the current brush for
  219. filling the shape. Notice that unless the brush is transparent, the
  220. lines connecting the centre of the circle to the end points of the arc
  221. are drawn as well.
  222. */
  223. void DrawArc(wxCoord xStart, wxCoord yStart, wxCoord xEnd, wxCoord yEnd,
  224. wxCoord xc, wxCoord yc);
  225. /**
  226. @overload
  227. */
  228. void DrawArc(const wxPoint& ptStart, const wxPoint& ptEnd, const wxPoint& centre);
  229. /**
  230. Draw a bitmap on the device context at the specified point. If
  231. @a transparent is @true and the bitmap has a transparency mask, the
  232. bitmap will be drawn transparently.
  233. When drawing a mono-bitmap, the current text foreground colour will be
  234. used to draw the foreground of the bitmap (all bits set to 1), and the
  235. current text background colour to draw the background (all bits set to
  236. 0).
  237. @see SetTextForeground(), SetTextBackground(), wxMemoryDC
  238. */
  239. void DrawBitmap(const wxBitmap& bitmap, wxCoord x, wxCoord y,
  240. bool useMask = false);
  241. /**
  242. @overload
  243. */
  244. void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt,
  245. bool useMask = false);
  246. /**
  247. Draws a check mark inside the given rectangle.
  248. */
  249. void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
  250. /**
  251. @overload
  252. */
  253. void DrawCheckMark(const wxRect& rect);
  254. /**
  255. Draws a circle with the given centre and radius.
  256. @see DrawEllipse()
  257. */
  258. void DrawCircle(wxCoord x, wxCoord y, wxCoord radius);
  259. /**
  260. @overload
  261. */
  262. void DrawCircle(const wxPoint& pt, wxCoord radius);
  263. /**
  264. Draws an ellipse contained in the rectangle specified either with the
  265. given top left corner and the given size or directly. The current pen
  266. is used for the outline and the current brush for filling the shape.
  267. @see DrawCircle()
  268. */
  269. void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
  270. /**
  271. @overload
  272. */
  273. void DrawEllipse(const wxPoint& pt, const wxSize& size);
  274. /**
  275. @overload
  276. */
  277. void DrawEllipse(const wxRect& rect);
  278. /**
  279. Draws an arc of an ellipse. The current pen is used for drawing the arc
  280. and the current brush is used for drawing the pie.
  281. @a x and @a y specify the x and y coordinates of the upper-left corner
  282. of the rectangle that contains the ellipse.
  283. @a width and @a height specify the width and height of the rectangle
  284. that contains the ellipse.
  285. @a start and @a end specify the start and end of the arc relative to
  286. the three-o'clock position from the center of the rectangle. Angles are
  287. specified in degrees with 0 degree angle corresponding to the positive
  288. horizontal axis (3 o'clock) direction. Positive values mean
  289. counter-clockwise motion. If @a start is equal to @e end, a complete
  290. ellipse will be drawn.
  291. Notice that unlike DrawArc(), this function does not draw the lines to
  292. the arc ends, even when using non-transparent brush.
  293. */
  294. void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord width, wxCoord height,
  295. double start, double end);
  296. /**
  297. @overload
  298. */
  299. void DrawEllipticArc(const wxPoint& pt, const wxSize& sz,
  300. double sa, double ea);
  301. /**
  302. Draw an icon on the display (does nothing if the device context is
  303. PostScript). This can be the simplest way of drawing bitmaps on a
  304. window.
  305. */
  306. void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
  307. /**
  308. @overload
  309. */
  310. void DrawIcon(const wxIcon& icon, const wxPoint& pt);
  311. /**
  312. Draw optional bitmap and the text into the given rectangle and aligns
  313. it as specified by alignment parameter; it also will emphasize the
  314. character with the given index if it is != -1 and return the bounding
  315. rectangle if required.
  316. */
  317. void DrawLabel(const wxString& text, const wxBitmap& bitmap,
  318. const wxRect& rect,
  319. int alignment = wxALIGN_LEFT | wxALIGN_TOP,
  320. int indexAccel = -1, wxRect* rectBounding = NULL);
  321. /**
  322. @overload
  323. */
  324. void DrawLabel(const wxString& text, const wxRect& rect,
  325. int alignment = wxALIGN_LEFT | wxALIGN_TOP,
  326. int indexAccel = -1);
  327. /**
  328. Draws a line from the first point to the second. The current pen is
  329. used for drawing the line. Note that the point (@a x2, @a y2) is not
  330. part of the line and is not drawn by this function (this is consistent
  331. with the behaviour of many other toolkits).
  332. */
  333. void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
  334. /**
  335. @overload
  336. */
  337. void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
  338. /**
  339. Draws lines using an array of points of size @a n adding the optional
  340. offset coordinate. The current pen is used for drawing the lines.
  341. @beginWxPerlOnly
  342. Not supported by wxPerl.
  343. @endWxPerlOnly
  344. */
  345. void DrawLines(int n, const wxPoint points[], wxCoord xoffset = 0,
  346. wxCoord yoffset = 0);
  347. /**
  348. This method uses a list of wxPoints, adding the optional offset
  349. coordinate. The programmer is responsible for deleting the list of
  350. points.
  351. @beginWxPerlOnly
  352. The wxPerl version of this method accepts
  353. as its first parameter a reference to an array
  354. of wxPoint objects.
  355. @endWxPerlOnly
  356. */
  357. void DrawLines(const wxPointList* points,
  358. wxCoord xoffset = 0, wxCoord yoffset = 0);
  359. /**
  360. Draws a point using the color of the current pen. Note that the other
  361. properties of the pen are not used, such as width.
  362. */
  363. void DrawPoint(wxCoord x, wxCoord y);
  364. /**
  365. @overload
  366. */
  367. void DrawPoint(const wxPoint& pt);
  368. /**
  369. Draws a filled polygon using an array of points of size @a n, adding
  370. the optional offset coordinate. The first and last points are
  371. automatically closed.
  372. The last argument specifies the fill rule: @b wxODDEVEN_RULE (the
  373. default) or @b wxWINDING_RULE.
  374. The current pen is used for drawing the outline, and the current brush
  375. for filling the shape. Using a transparent brush suppresses filling.
  376. @beginWxPerlOnly
  377. Not supported by wxPerl.
  378. @endWxPerlOnly
  379. */
  380. void DrawPolygon(int n, const wxPoint points[], wxCoord xoffset = 0,
  381. wxCoord yoffset = 0,
  382. wxPolygonFillMode fill_style = wxODDEVEN_RULE);
  383. /**
  384. This method draws a filled polygon using a list of wxPoints, adding the
  385. optional offset coordinate. The first and last points are automatically
  386. closed.
  387. The last argument specifies the fill rule: @b wxODDEVEN_RULE (the
  388. default) or @b wxWINDING_RULE.
  389. The current pen is used for drawing the outline, and the current brush
  390. for filling the shape. Using a transparent brush suppresses filling.
  391. The programmer is responsible for deleting the list of points.
  392. @beginWxPerlOnly
  393. The wxPerl version of this method accepts
  394. as its first parameter a reference to an array
  395. of wxPoint objects.
  396. @endWxPerlOnly
  397. */
  398. void DrawPolygon(const wxPointList* points,
  399. wxCoord xoffset = 0, wxCoord yoffset = 0,
  400. wxPolygonFillMode fill_style = wxODDEVEN_RULE);
  401. /**
  402. Draws two or more filled polygons using an array of @a points, adding
  403. the optional offset coordinates.
  404. Notice that for the platforms providing a native implementation of this
  405. function (Windows and PostScript-based wxDC currently), this is more
  406. efficient than using DrawPolygon() in a loop.
  407. @a n specifies the number of polygons to draw, the array @e count of
  408. size @a n specifies the number of points in each of the polygons in the
  409. @a points array.
  410. The last argument specifies the fill rule: @b wxODDEVEN_RULE (the
  411. default) or @b wxWINDING_RULE.
  412. The current pen is used for drawing the outline, and the current brush
  413. for filling the shape. Using a transparent brush suppresses filling.
  414. The polygons maybe disjoint or overlapping. Each polygon specified in a
  415. call to DrawPolyPolygon() must be closed. Unlike polygons created by
  416. the DrawPolygon() member function, the polygons created by this
  417. method are not closed automatically.
  418. */
  419. void DrawPolyPolygon(int n, const int count[], const wxPoint points[],
  420. wxCoord xoffset = 0, wxCoord yoffset = 0,
  421. wxPolygonFillMode fill_style = wxODDEVEN_RULE);
  422. /**
  423. Draws a rectangle with the given top left corner, and with the given
  424. size. The current pen is used for the outline and the current brush
  425. for filling the shape.
  426. */
  427. void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
  428. /**
  429. @overload
  430. */
  431. void DrawRectangle(const wxPoint& pt, const wxSize& sz);
  432. /**
  433. @overload
  434. */
  435. void DrawRectangle(const wxRect& rect);
  436. /**
  437. Draws the text rotated by @a angle degrees
  438. (positive angles are counterclockwise; the full angle is 360 degrees).
  439. @note Under Win9x only TrueType fonts can be drawn by this function. In
  440. particular, a font different from @c wxNORMAL_FONT should be used
  441. as the latter is not a TrueType font. @c wxSWISS_FONT is an
  442. example of a font which is.
  443. @see DrawText()
  444. */
  445. void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y,
  446. double angle);
  447. /**
  448. @overload
  449. */
  450. void DrawRotatedText(const wxString& text, const wxPoint& point,
  451. double angle);
  452. /**
  453. Draws a rectangle with the given top left corner, and with the given
  454. size. The corners are quarter-circles using the given radius. The
  455. current pen is used for the outline and the current brush for filling
  456. the shape.
  457. If @a radius is positive, the value is assumed to be the radius of the
  458. rounded corner. If @a radius is negative, the absolute value is assumed
  459. to be the @e proportion of the smallest dimension of the rectangle.
  460. This means that the corner can be a sensible size relative to the size
  461. of the rectangle, and also avoids the strange effects X produces when
  462. the corners are too big for the rectangle.
  463. */
  464. void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width,
  465. wxCoord height, double radius);
  466. /**
  467. @overload
  468. */
  469. void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz,
  470. double radius);
  471. /**
  472. @overload
  473. */
  474. void DrawRoundedRectangle(const wxRect& rect, double radius);
  475. /**
  476. Draws a spline between all given points using the current pen.
  477. @beginWxPerlOnly
  478. Not supported by wxPerl.
  479. @endWxPerlOnly
  480. */
  481. void DrawSpline(int n, const wxPoint points[]);
  482. /**
  483. @overload
  484. @beginWxPerlOnly
  485. The wxPerl version of this method accepts
  486. as its first parameter a reference to an array
  487. of wxPoint objects.
  488. @endWxPerlOnly
  489. */
  490. void DrawSpline(const wxPointList* points);
  491. /**
  492. @overload
  493. @beginWxPerlOnly
  494. Not supported by wxPerl.
  495. @endWxPerlOnly
  496. */
  497. void DrawSpline(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2,
  498. wxCoord x3, wxCoord y3);
  499. /**
  500. Draws a text string at the specified point, using the current text
  501. font, and the current text foreground and background colours.
  502. The coordinates refer to the top-left corner of the rectangle bounding
  503. the string. See GetTextExtent() for how to get the dimensions of a text
  504. string, which can be used to position the text more precisely and
  505. DrawLabel() if you need to align the string differently.
  506. Starting from wxWidgets 2.9.2 @a text parameter can be a multi-line
  507. string, i.e. contain new line characters, and will be rendered
  508. correctly.
  509. @note The current @ref GetLogicalFunction() "logical function" is
  510. ignored by this function.
  511. */
  512. void DrawText(const wxString& text, wxCoord x, wxCoord y);
  513. /**
  514. @overload
  515. */
  516. void DrawText(const wxString& text, const wxPoint& pt);
  517. /**
  518. Fill the area specified by rect with a radial gradient, starting from
  519. @a initialColour at the centre of the circle and fading to
  520. @a destColour on the circle outside.
  521. The circle is placed at the centre of @a rect.
  522. @note Currently this function is very slow, don't use it for real-time
  523. drawing.
  524. */
  525. void GradientFillConcentric(const wxRect& rect,
  526. const wxColour& initialColour,
  527. const wxColour& destColour);
  528. /**
  529. Fill the area specified by rect with a radial gradient, starting from
  530. @a initialColour at the centre of the circle and fading to
  531. @a destColour on the circle outside.
  532. @a circleCenter are the relative coordinates of centre of the circle in
  533. the specified @a rect.
  534. @note Currently this function is very slow, don't use it for real-time
  535. drawing.
  536. */
  537. void GradientFillConcentric(const wxRect& rect,
  538. const wxColour& initialColour,
  539. const wxColour& destColour,
  540. const wxPoint& circleCenter);
  541. /**
  542. Fill the area specified by @a rect with a linear gradient, starting
  543. from @a initialColour and eventually fading to @e destColour.
  544. The @a nDirection specifies the direction of the colour change, default is
  545. to use @a initialColour on the left part of the rectangle and
  546. @a destColour on the right one.
  547. */
  548. void GradientFillLinear(const wxRect& rect, const wxColour& initialColour,
  549. const wxColour& destColour,
  550. wxDirection nDirection = wxRIGHT);
  551. /**
  552. Flood fills the device context starting from the given point, using
  553. the current brush colour, and using a style:
  554. - wxFLOOD_SURFACE: The flooding occurs until a colour other than the
  555. given colour is encountered.
  556. - wxFLOOD_BORDER: The area to be flooded is bounded by the given
  557. colour.
  558. Currently this method is not implemented in wxOSX and does nothing
  559. there.
  560. @return @false if the operation failed.
  561. @note The present implementation for non-Windows platforms may fail to
  562. find colour borders if the pixels do not match the colour
  563. exactly. However the function will still return @true.
  564. @note This method shouldn't be used with wxPaintDC under non-Windows
  565. platforms as it uses GetPixel() internally and this may give
  566. wrong results, notably in wxGTK. If you need to flood fill
  567. wxPaintDC, create a temporary wxMemoryDC, flood fill it and then
  568. blit it to, or draw as a bitmap on, wxPaintDC. See the example of
  569. doing this in the drawing sample and wxBufferedPaintDC class.
  570. */
  571. bool FloodFill(wxCoord x, wxCoord y, const wxColour& colour,
  572. wxFloodFillStyle style = wxFLOOD_SURFACE);
  573. /**
  574. @overload
  575. */
  576. bool FloodFill(const wxPoint& pt, const wxColour& col,
  577. wxFloodFillStyle style = wxFLOOD_SURFACE);
  578. /**
  579. Displays a cross hair using the current pen. This is a vertical and
  580. horizontal line the height and width of the window, centred on the
  581. given point.
  582. */
  583. void CrossHair(wxCoord x, wxCoord y);
  584. /**
  585. @overload
  586. */
  587. void CrossHair(const wxPoint& pt);
  588. //@}
  589. /**
  590. @name Clipping region functions
  591. */
  592. //@{
  593. /**
  594. Destroys the current clipping region so that none of the DC is clipped.
  595. @see SetClippingRegion()
  596. */
  597. void DestroyClippingRegion();
  598. /**
  599. Gets the rectangle surrounding the current clipping region.
  600. */
  601. void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *width, wxCoord *height) const;
  602. /**
  603. Sets the clipping region for this device context to the intersection of
  604. the given region described by the parameters of this method and the
  605. previously set clipping region.
  606. The clipping region is an area to which drawing is restricted. Possible
  607. uses for the clipping region are for clipping text or for speeding up
  608. window redraws when only a known area of the screen is damaged.
  609. Notice that you need to call DestroyClippingRegion() if you want to set
  610. the clipping region exactly to the region specified.
  611. Also note that if the clipping region is empty, any previously set
  612. clipping region is destroyed, i.e. it is equivalent to calling
  613. DestroyClippingRegion(), and not to clipping out all drawing on the DC
  614. as might be expected.
  615. @see DestroyClippingRegion(), wxRegion
  616. */
  617. void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height);
  618. /**
  619. @overload
  620. */
  621. void SetClippingRegion(const wxPoint& pt, const wxSize& sz);
  622. /**
  623. @overload
  624. */
  625. void SetClippingRegion(const wxRect& rect);
  626. /**
  627. Sets the clipping region for this device context.
  628. Unlike SetClippingRegion(), this function works with physical
  629. coordinates and not with the logical ones.
  630. */
  631. void SetDeviceClippingRegion(const wxRegion& region);
  632. //@}
  633. /**
  634. @name Text/character extent functions
  635. */
  636. //@{
  637. /**
  638. Gets the character height of the currently set font.
  639. */
  640. wxCoord GetCharHeight() const;
  641. /**
  642. Gets the average character width of the currently set font.
  643. */
  644. wxCoord GetCharWidth() const;
  645. /**
  646. Returns the various font characteristics.
  647. This method allows to retrieve some of the font characteristics not
  648. returned by GetTextExtent(), notably internal leading and average
  649. character width.
  650. Currently this method returns correct results only under wxMSW, in the
  651. other ports the internal leading will always be 0 and the average
  652. character width will be computed as the width of the character 'x'.
  653. @since 2.9.2
  654. */
  655. wxFontMetrics GetFontMetrics() const;
  656. /**
  657. Gets the dimensions of the string using the currently selected font.
  658. @a string is the text string to measure, @e heightLine, if non @NULL,
  659. is where to store the height of a single line.
  660. The text extent is set in the given @a w and @a h pointers.
  661. If the optional parameter @a font is specified and valid, then it is
  662. used for the text extent calculation, otherwise the currently selected
  663. font is used.
  664. @note This function works with both single-line and multi-line strings.
  665. @beginWxPerlOnly
  666. In wxPerl this method is implemented as
  667. GetMultiLineTextExtent(string, font = undef) returning a
  668. 3-element list (width, height, line_height)
  669. @endWxPerlOnly
  670. @see wxFont, SetFont(), GetPartialTextExtents(), GetTextExtent()
  671. */
  672. void GetMultiLineTextExtent(const wxString& string, wxCoord* w,
  673. wxCoord* h,
  674. wxCoord* heightLine = NULL,
  675. const wxFont* font = NULL) const;
  676. /**
  677. Gets the dimensions of the string using the currently selected font.
  678. @a string is the text string to measure, @e heightLine, if non @NULL,
  679. is where to store the height of a single line.
  680. @return The text extent as a wxSize object.
  681. @note This function works with both single-line and multi-line strings.
  682. @beginWxPerlOnly
  683. Not supported by wxPerl.
  684. @endWxPerlOnly
  685. @see wxFont, SetFont(), GetPartialTextExtents(), GetTextExtent()
  686. */
  687. wxSize GetMultiLineTextExtent(const wxString& string) const;
  688. /**
  689. Fills the @a widths array with the widths from the beginning of @a text
  690. to the corresponding character of @a text. The generic version simply
  691. builds a running total of the widths of each character using
  692. GetTextExtent(), however if the various platforms have a native API
  693. function that is faster or more accurate than the generic
  694. implementation then it should be used instead.
  695. @beginWxPerlOnly
  696. In wxPerl this method only takes the @a text parameter and
  697. returns the widths as a list of integers.
  698. @endWxPerlOnly
  699. @see GetMultiLineTextExtent(), GetTextExtent()
  700. */
  701. bool GetPartialTextExtents(const wxString& text,
  702. wxArrayInt& widths) const;
  703. /**
  704. Gets the dimensions of the string using the currently selected font.
  705. @a string is the text string to measure, @a descent is the dimension
  706. from the baseline of the font to the bottom of the descender, and
  707. @a externalLeading is any extra vertical space added to the font by the
  708. font designer (usually is zero).
  709. The text extent is returned in @a w and @a h pointers or as a wxSize
  710. object depending on which version of this function is used.
  711. If the optional parameter @a font is specified and valid, then it is
  712. used for the text extent calculation. Otherwise the currently selected
  713. font is.
  714. @note This function only works with single-line strings.
  715. @beginWxPerlOnly
  716. In wxPerl this method is implemented as GetTextExtent(string,
  717. font = undef) returning a 4-element list (width, height,
  718. descent, externalLeading)
  719. @endWxPerlOnly
  720. @see wxFont, SetFont(), GetPartialTextExtents(),
  721. GetMultiLineTextExtent()
  722. */
  723. void GetTextExtent(const wxString& string, wxCoord* w, wxCoord* h,
  724. wxCoord* descent = NULL,
  725. wxCoord* externalLeading = NULL,
  726. const wxFont* font = NULL) const;
  727. /**
  728. @overload
  729. @beginWxPerlOnly
  730. Not supported by wxPerl.
  731. @endWxPerlOnly
  732. */
  733. wxSize GetTextExtent(const wxString& string) const;
  734. //@}
  735. /**
  736. @name Text properties functions
  737. */
  738. //@{
  739. /**
  740. Returns the current background mode: @c wxSOLID or @c wxTRANSPARENT.
  741. @see SetBackgroundMode()
  742. */
  743. int GetBackgroundMode() const;
  744. /**
  745. Gets the current font.
  746. Notice that even although each device context object has some default font
  747. after creation, this method would return a ::wxNullFont initially and only
  748. after calling SetFont() a valid font is returned.
  749. */
  750. const wxFont& GetFont() const;
  751. /**
  752. Gets the current layout direction of the device context. On platforms
  753. where RTL layout is supported, the return value will either be
  754. @c wxLayout_LeftToRight or @c wxLayout_RightToLeft. If RTL layout is
  755. not supported, the return value will be @c wxLayout_Default.
  756. @see SetLayoutDirection()
  757. */
  758. wxLayoutDirection GetLayoutDirection() const;
  759. /**
  760. Gets the current text background colour.
  761. @see SetTextBackground()
  762. */
  763. const wxColour& GetTextBackground() const;
  764. /**
  765. Gets the current text foreground colour.
  766. @see SetTextForeground()
  767. */
  768. const wxColour& GetTextForeground() const;
  769. /**
  770. @a mode may be one of @c wxSOLID and @c wxTRANSPARENT.
  771. This setting determines whether text will be drawn with a background
  772. colour or not.
  773. */
  774. void SetBackgroundMode(int mode);
  775. /**
  776. Sets the current font for the DC.
  777. If the argument is ::wxNullFont (or another invalid font; see wxFont::IsOk),
  778. the current font is selected out of the device context (leaving wxDC without
  779. any valid font), allowing the current font to be destroyed safely.
  780. @see wxFont
  781. */
  782. void SetFont(const wxFont& font);
  783. /**
  784. Sets the current text background colour for the DC.
  785. */
  786. void SetTextBackground(const wxColour& colour);
  787. /**
  788. Sets the current text foreground colour for the DC.
  789. @see wxMemoryDC for the interpretation of colours when drawing into a
  790. monochrome bitmap.
  791. */
  792. void SetTextForeground(const wxColour& colour);
  793. /**
  794. Sets the current layout direction for the device context.
  795. @param dir
  796. May be either @c wxLayout_Default, @c wxLayout_LeftToRight or
  797. @c wxLayout_RightToLeft.
  798. @see GetLayoutDirection()
  799. */
  800. void SetLayoutDirection(wxLayoutDirection dir);
  801. //@}
  802. /**
  803. @name Bounding box functions
  804. */
  805. //@{
  806. /**
  807. Adds the specified point to the bounding box which can be retrieved
  808. with MinX(), MaxX() and MinY(), MaxY() functions.
  809. @see ResetBoundingBox()
  810. */
  811. void CalcBoundingBox(wxCoord x, wxCoord y);
  812. /**
  813. Gets the maximum horizontal extent used in drawing commands so far.
  814. */
  815. wxCoord MaxX() const;
  816. /**
  817. Gets the maximum vertical extent used in drawing commands so far.
  818. */
  819. wxCoord MaxY() const;
  820. /**
  821. Gets the minimum horizontal extent used in drawing commands so far.
  822. */
  823. wxCoord MinX() const;
  824. /**
  825. Gets the minimum vertical extent used in drawing commands so far.
  826. */
  827. wxCoord MinY() const;
  828. /**
  829. Resets the bounding box: after a call to this function, the bounding
  830. box doesn't contain anything.
  831. @see CalcBoundingBox()
  832. */
  833. void ResetBoundingBox();
  834. //@}
  835. /**
  836. @name Page and document start/end functions
  837. */
  838. //@{
  839. /**
  840. Starts a document (only relevant when outputting to a printer).
  841. @a message is a message to show while printing.
  842. */
  843. bool StartDoc(const wxString& message);
  844. /**
  845. Starts a document page (only relevant when outputting to a printer).
  846. */
  847. void StartPage();
  848. /**
  849. Ends a document (only relevant when outputting to a printer).
  850. */
  851. void EndDoc();
  852. /**
  853. Ends a document page (only relevant when outputting to a printer).
  854. */
  855. void EndPage();
  856. //@}
  857. /**
  858. @name Bit-Block Transfer operations (blit)
  859. */
  860. //@{
  861. /**
  862. Copy from a source DC to this DC.
  863. With this method you can specify the destination coordinates and the
  864. size of area to copy which will be the same for both the source and
  865. target DCs. If you need to apply scaling while copying, use
  866. StretchBlit().
  867. Notice that source DC coordinates @a xsrc and @a ysrc are interpreted
  868. using the current source DC coordinate system, i.e. the scale, origin
  869. position and axis directions are taken into account when transforming
  870. them to physical (pixel) coordinates.
  871. @param xdest
  872. Destination device context x position.
  873. @param ydest
  874. Destination device context y position.
  875. @param width
  876. Width of source area to be copied.
  877. @param height
  878. Height of source area to be copied.
  879. @param source
  880. Source device context.
  881. @param xsrc
  882. Source device context x position.
  883. @param ysrc
  884. Source device context y position.
  885. @param logicalFunc
  886. Logical function to use, see SetLogicalFunction().
  887. @param useMask
  888. If @true, Blit does a transparent blit using the mask that is
  889. associated with the bitmap selected into the source device context.
  890. The Windows implementation does the following if MaskBlt cannot be
  891. used:
  892. <ol>
  893. <li>Creates a temporary bitmap and copies the destination area into
  894. it.</li>
  895. <li>Copies the source area into the temporary bitmap using the
  896. specified logical function.</li>
  897. <li>Sets the masked area in the temporary bitmap to BLACK by ANDing
  898. the mask bitmap with the temp bitmap with the foreground colour
  899. set to WHITE and the bg colour set to BLACK.</li>
  900. <li>Sets the unmasked area in the destination area to BLACK by
  901. ANDing the mask bitmap with the destination area with the
  902. foreground colour set to BLACK and the background colour set to
  903. WHITE.</li>
  904. <li>ORs the temporary bitmap with the destination area.</li>
  905. <li>Deletes the temporary bitmap.</li>
  906. </ol>
  907. This sequence of operations ensures that the source's transparent
  908. area need not be black, and logical functions are supported.
  909. @n @b Note: on Windows, blitting with masks can be speeded up
  910. considerably by compiling wxWidgets with the wxUSE_DC_CACHEING option
  911. enabled. You can also influence whether MaskBlt or the explicit
  912. mask blitting code above is used, by using wxSystemOptions and
  913. setting the @c no-maskblt option to 1.
  914. @param xsrcMask
  915. Source x position on the mask. If both xsrcMask and ysrcMask are
  916. @c -1, xsrc and ysrc will be assumed for the mask source position.
  917. Currently only implemented on Windows.
  918. @param ysrcMask
  919. Source y position on the mask. If both xsrcMask and ysrcMask are
  920. @c -1, xsrc and ysrc will be assumed for the mask source position.
  921. Currently only implemented on Windows.
  922. @remarks There is partial support for Blit() in wxPostScriptDC, under X.
  923. @see StretchBlit(), wxMemoryDC, wxBitmap, wxMask
  924. */
  925. bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width,
  926. wxCoord height, wxDC* source, wxCoord xsrc, wxCoord ysrc,
  927. wxRasterOperationMode logicalFunc = wxCOPY, bool useMask = false,
  928. wxCoord xsrcMask = wxDefaultCoord, wxCoord ysrcMask = wxDefaultCoord);
  929. /**
  930. Copy from a source DC to this DC possibly changing the scale.
  931. Unlike Blit(), this method allows to specify different source and
  932. destination region sizes, meaning that it can stretch or shrink it
  933. while copying. The same can be achieved by changing the scale of the
  934. source or target DC but calling this method is simpler and can also be
  935. more efficient if the platform provides a native implementation of it.
  936. The meaning of its other parameters is the same as with Blit(), in
  937. particular all source coordinates are interpreted using the source DC
  938. coordinate system, i.e. are affected by its scale, origin translation
  939. and axis direction.
  940. @param xdest
  941. Destination device context x position.
  942. @param ydest
  943. Destination device context y position.
  944. @param dstWidth
  945. Width of destination area.
  946. @param dstHeight
  947. Height of destination area.
  948. @param source
  949. Source device context.
  950. @param xsrc
  951. Source device context x position.
  952. @param ysrc
  953. Source device context y position.
  954. @param srcWidth
  955. Width of source area to be copied.
  956. @param srcHeight
  957. Height of source area to be copied.
  958. @param logicalFunc
  959. Logical function to use, see SetLogicalFunction().
  960. @param useMask
  961. If @true, Blit does a transparent blit using the mask that is
  962. associated with the bitmap selected into the source device context.
  963. The Windows implementation does the following if MaskBlt cannot be
  964. used:
  965. <ol>
  966. <li>Creates a temporary bitmap and copies the destination area into
  967. it.</li>
  968. <li>Copies the source area into the temporary bitmap using the
  969. specified logical function.</li>
  970. <li>Sets the masked area in the temporary bitmap to BLACK by ANDing
  971. the mask bitmap with the temp bitmap with the foreground colour
  972. set to WHITE and the bg colour set to BLACK.</li>
  973. <li>Sets the unmasked area in the destination area to BLACK by
  974. ANDing the mask bitmap with the destination area with the
  975. foreground colour set to BLACK and the background colour set to
  976. WHITE.</li>
  977. <li>ORs the temporary bitmap with the destination area.</li>
  978. <li>Deletes the temporary bitmap.</li>
  979. </ol>
  980. This sequence of operations ensures that the source's transparent
  981. area need not be black, and logical functions are supported.
  982. @n @b Note: on Windows, blitting with masks can be speeded up
  983. considerably by compiling wxWidgets with the wxUSE_DC_CACHEING option
  984. enabled. You can also influence whether MaskBlt or the explicit
  985. mask blitting code above is used, by using wxSystemOptions and
  986. setting the @c no-maskblt option to 1.
  987. @param xsrcMask
  988. Source x position on the mask. If both xsrcMask and ysrcMask are
  989. wxDefaultCoord, @a xsrc and @a ysrc will be assumed for the mask
  990. source position. Currently only implemented on Windows.
  991. @param ysrcMask
  992. Source y position on the mask. If both xsrcMask and ysrcMask are
  993. wxDefaultCoord, @a xsrc and @a ysrc will be assumed for the mask
  994. source position. Currently only implemented on Windows.
  995. There is partial support for Blit() in wxPostScriptDC, under X.
  996. See wxMemoryDC for typical usage.
  997. @since 2.9.0
  998. @see Blit(), wxMemoryDC, wxBitmap, wxMask
  999. */
  1000. bool StretchBlit(wxCoord xdest, wxCoord ydest,
  1001. wxCoord dstWidth, wxCoord dstHeight,
  1002. wxDC* source, wxCoord xsrc, wxCoord ysrc,
  1003. wxCoord srcWidth, wxCoord srcHeight,
  1004. wxRasterOperationMode logicalFunc = wxCOPY,
  1005. bool useMask = false,
  1006. wxCoord xsrcMask = wxDefaultCoord,
  1007. wxCoord ysrcMask = wxDefaultCoord);
  1008. //@}
  1009. /**
  1010. @name Background/foreground brush and pen
  1011. */
  1012. //@{
  1013. /**
  1014. Gets the brush used for painting the background.
  1015. @see wxDC::SetBackground()
  1016. */
  1017. const wxBrush& GetBackground() const;
  1018. /**
  1019. Gets the current brush.
  1020. @see wxDC::SetBrush()
  1021. */
  1022. const wxBrush& GetBrush() const;
  1023. /**
  1024. Gets the current pen.
  1025. @see SetPen()
  1026. */
  1027. const wxPen& GetPen() const;
  1028. /**
  1029. Sets the current background brush for the DC.
  1030. */
  1031. void SetBackground(const wxBrush& brush);
  1032. /**
  1033. Sets the current brush for the DC.
  1034. If the argument is ::wxNullBrush (or another invalid brush; see wxBrush::IsOk),
  1035. the current brush is selected out of the device context (leaving wxDC without
  1036. any valid brush), allowing the current brush to be destroyed safely.
  1037. @see wxBrush, wxMemoryDC (for the interpretation of colours when
  1038. drawing into a monochrome bitmap)
  1039. */
  1040. void SetBrush(const wxBrush& brush);
  1041. /**
  1042. Sets the current pen for the DC.
  1043. If the argument is ::wxNullPen (or another invalid pen; see wxPen::IsOk),
  1044. the current pen is selected out of the device context (leaving wxDC without any
  1045. valid pen), allowing the current pen to be destroyed safely.
  1046. @see wxMemoryDC for the interpretation of colours when drawing into a
  1047. monochrome bitmap.
  1048. */
  1049. void SetPen(const wxPen& pen);
  1050. //@}
  1051. /**
  1052. Copy attributes from another DC.
  1053. The copied attributes currently are:
  1054. - Font
  1055. - Text foreground and background colours
  1056. - Background brush
  1057. - Layout direction
  1058. @param dc
  1059. A valid (i.e. its IsOk() must return @true) source device context.
  1060. */
  1061. void CopyAttributes(const wxDC& dc);
  1062. /**
  1063. Returns the depth (number of bits/pixel) of this DC.
  1064. @see wxDisplayDepth()
  1065. */
  1066. int GetDepth() const;
  1067. /**
  1068. Returns the current device origin.
  1069. @see SetDeviceOrigin()
  1070. */
  1071. wxPoint GetDeviceOrigin() const;
  1072. /**
  1073. Gets the current logical function.
  1074. @see SetLogicalFunction()
  1075. */
  1076. wxRasterOperationMode GetLogicalFunction() const;
  1077. /**
  1078. Gets the current mapping mode for the device context.
  1079. @see SetMapMode()
  1080. */
  1081. wxMappingMode GetMapMode() const;
  1082. /**
  1083. Gets in @a colour the colour at the specified location. Not available
  1084. for wxPostScriptDC or wxMetafileDC.
  1085. @note Setting a pixel can be done using DrawPoint().
  1086. @note This method shouldn't be used with wxPaintDC as accessing the DC
  1087. while drawing can result in unexpected results, notably in wxGTK.
  1088. */
  1089. bool GetPixel(wxCoord x, wxCoord y, wxColour* colour) const;
  1090. /**
  1091. Returns the resolution of the device in pixels per inch.
  1092. */
  1093. wxSize GetPPI() const;
  1094. /**
  1095. Gets the horizontal and vertical extent of this device context in @e device units.
  1096. It can be used to scale graphics to fit the page.
  1097. For example, if @e maxX and @e maxY represent the maximum horizontal
  1098. and vertical 'pixel' values used in your application, the following
  1099. code will scale the graphic to fit on the printer page:
  1100. @code
  1101. wxCoord w, h;
  1102. dc.GetSize(&w, &h);
  1103. double scaleX = (double)(maxX / w);
  1104. double scaleY = (double)(maxY / h);
  1105. dc.SetUserScale(min(scaleX, scaleY),min(scaleX, scaleY));
  1106. @endcode
  1107. @beginWxPerlOnly
  1108. In wxPerl there are two methods instead of a single overloaded
  1109. method:
  1110. - GetSize(): returns a Wx::Size object.
  1111. - GetSizeWH(): returns a 2-element list (width, height).
  1112. @endWxPerlOnly
  1113. */
  1114. void GetSize(wxCoord* width, wxCoord* height) const;
  1115. /**
  1116. @overload
  1117. */
  1118. wxSize GetSize() const;
  1119. /**
  1120. Returns the horizontal and vertical resolution in millimetres.
  1121. */
  1122. void GetSizeMM(wxCoord* width, wxCoord* height) const;
  1123. /**
  1124. @overload
  1125. */
  1126. wxSize GetSizeMM() const;
  1127. /**
  1128. Gets the current user scale factor.
  1129. @beginWxPerlOnly
  1130. In wxPerl this method takes no arguments and return a two
  1131. element array (x, y).
  1132. @endWxPerlOnly
  1133. @see SetUserScale()
  1134. */
  1135. void GetUserScale(double* x, double* y) const;
  1136. /**
  1137. Returns @true if the DC is ok to use.
  1138. */
  1139. bool IsOk() const;
  1140. /**
  1141. Sets the x and y axis orientation (i.e.\ the direction from lowest to
  1142. highest values on the axis). The default orientation is x axis from
  1143. left to right and y axis from top down.
  1144. @param xLeftRight
  1145. True to set the x axis orientation to the natural left to right
  1146. orientation, @false to invert it.
  1147. @param yBottomUp
  1148. True to set the y axis orientation to the natural bottom up
  1149. orientation, @false to invert it.
  1150. */
  1151. void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
  1152. /**
  1153. Sets the device origin (i.e.\ the origin in pixels after scaling has
  1154. been applied). This function may be useful in Windows printing
  1155. operations for placing a graphic on a page.
  1156. */
  1157. void SetDeviceOrigin(wxCoord x, wxCoord y);
  1158. /**
  1159. Sets the current logical function for the device context.
  1160. It determines how a @e source pixel (from a pen or brush colour, or source
  1161. device context if using Blit()) combines with a @e destination pixel in
  1162. the current device context.
  1163. Text drawing is not affected by this function.
  1164. See ::wxRasterOperationMode enumeration values for more info.
  1165. The default is @c wxCOPY, which simply draws with the current colour.
  1166. The others combine the current colour and the background using a logical
  1167. operation. @c wxINVERT is commonly used for drawing rubber bands or moving
  1168. outlines, since drawing twice reverts to the original colour.
  1169. */
  1170. void SetLogicalFunction(wxRasterOperationMode function);
  1171. /**
  1172. The mapping mode of the device context defines the unit of measurement
  1173. used to convert @e logical units to @e device units.
  1174. Note that in X, text drawing isn't handled consistently with the mapping mode;
  1175. a font is always specified in point size. However, setting the user scale (see
  1176. SetUserScale()) scales the text appropriately. In Windows, scalable
  1177. TrueType fonts are always used; in X, results depend on availability of
  1178. fonts, but usually a reasonable match is found.
  1179. The coordinate origin is always at the top left of the screen/printer.
  1180. Drawing to a Windows printer device context uses the current mapping
  1181. mode, but mapping mode is currently ignored for PostScript output.
  1182. */
  1183. void SetMapMode(wxMappingMode mode);
  1184. /**
  1185. If this is a window DC or memory DC, assigns the given palette to the
  1186. window or bitmap associated with the DC. If the argument is
  1187. ::wxNullPalette, the current palette is selected out of the device
  1188. context, and the original palette restored.
  1189. @see wxPalette
  1190. */
  1191. void SetPalette(const wxPalette& palette);
  1192. /**
  1193. Sets the user scaling factor, useful for applications which require
  1194. 'zooming'.
  1195. */
  1196. void SetUserScale(double xScale, double yScale);
  1197. /**
  1198. @name Transformation matrix
  1199. See the notes about the availability of these functions in the class
  1200. documentation.
  1201. */
  1202. //@{
  1203. /**
  1204. Check if the use of transformation matrix is supported by the current
  1205. system.
  1206. Currently this function always returns @false for non-MSW platforms and
  1207. may return @false for old (Windows 9x/ME) Windows systems. Normally
  1208. support for the transformation matrix is always available in any
  1209. relatively recent Windows versions.
  1210. @since 2.9.2
  1211. */
  1212. bool CanUseTransformMatrix() const;
  1213. /**
  1214. Set the transformation matrix.
  1215. If transformation matrix is supported on the current system, the
  1216. specified @a matrix will be used to transform between wxDC and physical
  1217. coordinates. Otherwise the function returns @false and doesn't change
  1218. the coordinate mapping.
  1219. @since 2.9.2
  1220. */
  1221. bool SetTransformMatrix(const wxAffineMatrix2D& matrix);
  1222. /**
  1223. Return the transformation matrix used by this device context.
  1224. By default the transformation matrix is the identity matrix.
  1225. @since 2.9.2
  1226. */
  1227. wxAffineMatrix2D GetTransformMatrix() const;
  1228. /**
  1229. Revert the transformation matrix to identity matrix.
  1230. @since 2.9.2
  1231. */
  1232. void ResetTransformMatrix();
  1233. //@}
  1234. /**
  1235. @name query capabilities
  1236. */
  1237. //@{
  1238. /**
  1239. Does the DC support drawing bitmaps?
  1240. */
  1241. bool CanDrawBitmap() const;
  1242. /**
  1243. Does the DC support calculating the size required to draw text?
  1244. */
  1245. bool CanGetTextExtent() const;
  1246. //@}
  1247. /**
  1248. Returns a value that can be used as a handle to the native drawing
  1249. context, if this wxDC has something that could be thought of in that
  1250. way. (Not all of them do.)
  1251. For example, on Windows the return value is an HDC, on OSX it is a
  1252. CGContextRef and on wxGTK it will be a GdkDrawable. If the DC is a
  1253. wxGCDC then the return value will be the value returned from
  1254. wxGraphicsContext::GetNativeContext. A value of NULL is returned if
  1255. the DC does not have anything that fits the handle concept.
  1256. @since 2.9.5
  1257. */
  1258. void* GetHandle() const;
  1259. /**
  1260. If supported by the platform and the type of DC, fetch the contents of the DC, or a subset of it, as a bitmap.
  1261. */
  1262. wxBitmap GetAsBitmap(const wxRect *subrect = NULL) const;
  1263. void SetLogicalScale(double x, double y);
  1264. void GetLogicalScale(double *x, double *y) const;
  1265. void SetLogicalOrigin(wxCoord x, wxCoord y);
  1266. void GetLogicalOrigin(wxCoord *x, wxCoord *y) const;
  1267. wxPoint GetLogicalOrigin() const;
  1268. };
  1269. /**
  1270. @class wxDCClipper
  1271. wxDCClipper is a helper class for setting a clipping region on a wxDC
  1272. during its lifetime.
  1273. An object of wxDCClipper class is typically created on the stack so that it
  1274. is automatically destroyed when the object goes out of scope. A typical
  1275. usage example:
  1276. @code
  1277. void MyFunction(wxDC& dc)
  1278. {
  1279. wxDCClipper clip(dc, rect);
  1280. // ... drawing functions here are affected by clipping rect ...
  1281. }
  1282. void OtherFunction()
  1283. {
  1284. wxDC dc;
  1285. MyFunction(dc);
  1286. // ... drawing functions here are not affected by clipping rect ...
  1287. }
  1288. @endcode
  1289. @note Unlike other similar classes such as wxDCFontChanger, wxDCClipper
  1290. currently doesn't restore the previously active clipping region when it
  1291. is destroyed but simply resets clipping on the associated wxDC. This
  1292. may be changed in the future wxWidgets versions but has to be taken
  1293. into account explicitly in the current one.
  1294. @library{wxcore}
  1295. @category{gdi}
  1296. @see wxDC::SetClippingRegion(), wxDCFontChanger, wxDCTextColourChanger, wxDCPenChanger,
  1297. wxDCBrushChanger
  1298. */
  1299. class wxDCClipper
  1300. {
  1301. public:
  1302. //@{
  1303. /**
  1304. Sets the clipping region to the specified region/coordinates.
  1305. The clipping region is automatically unset when this object is destroyed.
  1306. */
  1307. wxDCClipper(wxDC& dc, const wxRegion& region);
  1308. wxDCClipper(wxDC& dc, const wxRect& rect);
  1309. wxDCClipper(wxDC& dc, wxCoord x, wxCoord y, wxCoord w, wxCoord h);
  1310. //@}
  1311. /**
  1312. Destroys the clipping region associated with the DC passed to the ctor.
  1313. */
  1314. ~wxDCClipper();
  1315. };
  1316. /**
  1317. @class wxDCBrushChanger
  1318. wxDCBrushChanger is a small helper class for setting a brush on a wxDC
  1319. and unsetting it automatically in the destructor, restoring the previous one.
  1320. @library{wxcore}
  1321. @category{gdi}
  1322. @see wxDC::SetBrush(), wxDCFontChanger, wxDCTextColourChanger, wxDCPenChanger,
  1323. wxDCClipper
  1324. */
  1325. class wxDCBrushChanger
  1326. {
  1327. public:
  1328. /**
  1329. Sets @a brush on the given @a dc, storing the old one.
  1330. @param dc
  1331. The DC where the brush must be temporary set.
  1332. @param brush
  1333. The brush to set.
  1334. */
  1335. wxDCBrushChanger(wxDC& dc, const wxBrush& brush);
  1336. /**
  1337. Restores the brush originally selected in the DC passed to the ctor.
  1338. */
  1339. ~wxDCBrushChanger();
  1340. };
  1341. /**
  1342. @class wxDCPenChanger
  1343. wxDCPenChanger is a small helper class for setting a pen on a wxDC
  1344. and unsetting it automatically in the destructor, restoring the previous one.
  1345. @library{wxcore}
  1346. @category{gdi}
  1347. @see wxDC::SetPen(), wxDCFontChanger, wxDCTextColourChanger, wxDCBrushChanger,
  1348. wxDCClipper
  1349. */
  1350. class wxDCPenChanger
  1351. {
  1352. public:
  1353. /**
  1354. Sets @a pen on the given @a dc, storing the old one.
  1355. @param dc
  1356. The DC where the pen must be temporary set.
  1357. @param pen
  1358. The pen to set.
  1359. */
  1360. wxDCPenChanger(wxDC& dc, const wxPen& pen);
  1361. /**
  1362. Restores the pen originally selected in the DC passed to the ctor.
  1363. */
  1364. ~wxDCPenChanger();
  1365. };
  1366. /**
  1367. @class wxDCTextColourChanger
  1368. wxDCTextColourChanger is a small helper class for setting a foreground
  1369. text colour on a wxDC and unsetting it automatically in the destructor,
  1370. restoring the previous one.
  1371. @library{wxcore}
  1372. @category{gdi}
  1373. @see wxDC::SetTextForeground(), wxDCFontChanger, wxDCPenChanger, wxDCBrushChanger,
  1374. wxDCClipper
  1375. */
  1376. class wxDCTextColourChanger
  1377. {
  1378. public:
  1379. /**
  1380. Trivial constructor not changing anything.
  1381. This constructor is useful if you don't know beforehand if the colour
  1382. needs to be changed or not. It simply creates the object which won't do
  1383. anything in its destructor unless Set() is called -- in which case it
  1384. would reset the previous colour.
  1385. */
  1386. wxDCTextColourChanger(wxDC& dc);
  1387. /**
  1388. Sets @a col on the given @a dc, storing the old one.
  1389. @param dc
  1390. The DC where the colour must be temporary set.
  1391. @param col
  1392. The colour to set.
  1393. */
  1394. wxDCTextColourChanger(wxDC& dc, const wxColour& col);
  1395. /**
  1396. Set the colour to use.
  1397. This method is meant to be called once only and only on the objects
  1398. created with the constructor overload not taking wxColour argument and
  1399. has the same effect as the other constructor, i.e. sets the colour to
  1400. the given @a col and ensures that the old value is restored when this
  1401. object is destroyed.
  1402. */
  1403. void Set(const wxColour& col);
  1404. /**
  1405. Restores the colour originally selected in the DC passed to the ctor.
  1406. */
  1407. ~wxDCTextColourChanger();
  1408. };
  1409. /**
  1410. @class wxDCFontChanger
  1411. wxDCFontChanger is a small helper class for setting a font on a wxDC and
  1412. unsetting it automatically in the destructor, restoring the previous one.
  1413. @since 2.9.0
  1414. @library{wxcore}
  1415. @category{gdi}
  1416. @see wxDC::SetFont(), wxDCTextColourChanger, wxDCPenChanger, wxDCBrushChanger,
  1417. wxDCClipper
  1418. */
  1419. class wxDCFontChanger
  1420. {
  1421. public:
  1422. /**
  1423. Trivial constructor not changing anything.
  1424. This constructor is useful if you don't know beforehand if the font
  1425. needs to be changed or not. It simply creates the object which won't do
  1426. anything in its destructor unless Set() is called -- in which case it
  1427. would reset the previous font.
  1428. @since 2.9.1
  1429. */
  1430. wxDCFontChanger(wxDC& dc);
  1431. /**
  1432. Sets @a font on the given @a dc, storing the old one.
  1433. @param dc
  1434. The DC where the font must be temporary set.
  1435. @param font
  1436. The font to set.
  1437. */
  1438. wxDCFontChanger(wxDC& dc, const wxFont& font);
  1439. /**
  1440. Set the font to use.
  1441. This method is meant to be called once only and only on the objects
  1442. created with the constructor overload not taking wxColour argument and
  1443. has the same effect as the other constructor, i.e. sets the font to
  1444. the given @a font and ensures that the old value is restored when this
  1445. object is destroyed.
  1446. */
  1447. void Set(const wxFont& font);
  1448. /**
  1449. Restores the font originally selected in the DC passed to the ctor.
  1450. */
  1451. ~wxDCFontChanger();
  1452. };