The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

737 lines
32KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_GRAPHICSCONTEXT_JUCEHEADER__
  19. #define __JUCE_GRAPHICSCONTEXT_JUCEHEADER__
  20. #include "../fonts/juce_Font.h"
  21. #include "../geometry/juce_Rectangle.h"
  22. #include "../geometry/juce_PathStrokeType.h"
  23. #include "../geometry/juce_Line.h"
  24. #include "../colour/juce_Colours.h"
  25. #include "../colour/juce_ColourGradient.h"
  26. #include "../placement/juce_RectanglePlacement.h"
  27. class LowLevelGraphicsContext;
  28. class Image;
  29. class FillType;
  30. class RectangleList;
  31. //==============================================================================
  32. /**
  33. A graphics context, used for drawing a component or image.
  34. When a Component needs painting, a Graphics context is passed to its
  35. Component::paint() method, and this you then call methods within this
  36. object to actually draw the component's content.
  37. A Graphics can also be created from an image, to allow drawing directly onto
  38. that image.
  39. @see Component::paint
  40. */
  41. class JUCE_API Graphics
  42. {
  43. public:
  44. //==============================================================================
  45. /** Creates a Graphics object to draw directly onto the given image.
  46. The graphics object that is created will be set up to draw onto the image,
  47. with the context's clipping area being the entire size of the image, and its
  48. origin being the image's origin. To draw into a subsection of an image, use the
  49. reduceClipRegion() and setOrigin() methods.
  50. Obviously you shouldn't delete the image before this context is deleted.
  51. */
  52. explicit Graphics (const Image& imageToDrawOnto);
  53. /** Destructor. */
  54. ~Graphics();
  55. //==============================================================================
  56. /** Changes the current drawing colour.
  57. This sets the colour that will now be used for drawing operations - it also
  58. sets the opacity to that of the colour passed-in.
  59. If a brush is being used when this method is called, the brush will be deselected,
  60. and any subsequent drawing will be done with a solid colour brush instead.
  61. @see setOpacity
  62. */
  63. void setColour (Colour newColour);
  64. /** Changes the opacity to use with the current colour.
  65. If a solid colour is being used for drawing, this changes its opacity
  66. to this new value (i.e. it doesn't multiply the colour's opacity by this amount).
  67. If a gradient is being used, this will have no effect on it.
  68. A value of 0.0 is completely transparent, 1.0 is completely opaque.
  69. */
  70. void setOpacity (float newOpacity);
  71. /** Sets the context to use a gradient for its fill pattern.
  72. */
  73. void setGradientFill (const ColourGradient& gradient);
  74. /** Sets the context to use a tiled image pattern for filling.
  75. Make sure that you don't delete this image while it's still being used by
  76. this context!
  77. */
  78. void setTiledImageFill (const Image& imageToUse,
  79. int anchorX, int anchorY,
  80. float opacity);
  81. /** Changes the current fill settings.
  82. @see setColour, setGradientFill, setTiledImageFill
  83. */
  84. void setFillType (const FillType& newFill);
  85. //==============================================================================
  86. /** Changes the font to use for subsequent text-drawing functions.
  87. Note there's also a setFont (float, int) method to quickly change the size and
  88. style of the current font.
  89. @see drawSingleLineText, drawMultiLineText, drawTextAsPath, drawText, drawFittedText
  90. */
  91. void setFont (const Font& newFont);
  92. /** Changes the size of the currently-selected font.
  93. This is a convenient shortcut that changes the context's current font to a
  94. different size. The typeface won't be changed.
  95. @see Font
  96. */
  97. void setFont (float newFontHeight);
  98. /** Returns the currently selected font. */
  99. Font getCurrentFont() const;
  100. /** Draws a one-line text string.
  101. This will use the current colour (or brush) to fill the text. The font is the last
  102. one specified by setFont().
  103. @param text the string to draw
  104. @param startX the position to draw the left-hand edge of the text
  105. @param baselineY the position of the text's baseline
  106. @param justification the horizontal flags indicate which end of the text string is
  107. anchored at the specified point.
  108. @see drawMultiLineText, drawText, drawFittedText, GlyphArrangement::addLineOfText
  109. */
  110. void drawSingleLineText (const String& text,
  111. int startX, int baselineY,
  112. const Justification& justification = Justification::left) const;
  113. /** Draws text across multiple lines.
  114. This will break the text onto a new line where there's a new-line or
  115. carriage-return character, or at a word-boundary when the text becomes wider
  116. than the size specified by the maximumLineWidth parameter.
  117. @see setFont, drawSingleLineText, drawFittedText, GlyphArrangement::addJustifiedText
  118. */
  119. void drawMultiLineText (const String& text,
  120. int startX, int baselineY,
  121. int maximumLineWidth) const;
  122. /** Renders a string of text as a vector path.
  123. This allows a string to be transformed with an arbitrary AffineTransform and
  124. rendered using the current colour/brush. It's much slower than the normal text methods
  125. but more accurate.
  126. @see setFont
  127. */
  128. void drawTextAsPath (const String& text,
  129. const AffineTransform& transform) const;
  130. /** Draws a line of text within a specified rectangle.
  131. The text will be positioned within the rectangle based on the justification
  132. flags passed-in. If the string is too long to fit inside the rectangle, it will
  133. either be truncated or will have ellipsis added to its end (if the useEllipsesIfTooBig
  134. flag is true).
  135. @see drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText
  136. */
  137. void drawText (const String& text,
  138. int x, int y, int width, int height,
  139. const Justification& justificationType,
  140. bool useEllipsesIfTooBig) const;
  141. /** Draws a line of text within a specified rectangle.
  142. The text will be positioned within the rectangle based on the justification
  143. flags passed-in. If the string is too long to fit inside the rectangle, it will
  144. either be truncated or will have ellipsis added to its end (if the useEllipsesIfTooBig
  145. flag is true).
  146. @see drawSingleLineText, drawFittedText, drawMultiLineText, GlyphArrangement::addJustifiedText
  147. */
  148. void drawText (const String& text,
  149. const Rectangle<int>& area,
  150. const Justification& justificationType,
  151. bool useEllipsesIfTooBig) const;
  152. /** Tries to draw a text string inside a given space.
  153. This does its best to make the given text readable within the specified rectangle,
  154. so it useful for labelling things.
  155. If the text is too big, it'll be squashed horizontally or broken over multiple lines
  156. if the maximumLinesToUse value allows this. If the text just won't fit into the space,
  157. it'll cram as much as possible in there, and put some ellipsis at the end to show that
  158. it's been truncated.
  159. A Justification parameter lets you specify how the text is laid out within the rectangle,
  160. both horizontally and vertically.
  161. The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally
  162. to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you
  163. can set this value to 1.0f.
  164. @see GlyphArrangement::addFittedText
  165. */
  166. void drawFittedText (const String& text,
  167. int x, int y, int width, int height,
  168. const Justification& justificationFlags,
  169. int maximumNumberOfLines,
  170. float minimumHorizontalScale = 0.7f) const;
  171. /** Tries to draw a text string inside a given space.
  172. This does its best to make the given text readable within the specified rectangle,
  173. so it useful for labelling things.
  174. If the text is too big, it'll be squashed horizontally or broken over multiple lines
  175. if the maximumLinesToUse value allows this. If the text just won't fit into the space,
  176. it'll cram as much as possible in there, and put some ellipsis at the end to show that
  177. it's been truncated.
  178. A Justification parameter lets you specify how the text is laid out within the rectangle,
  179. both horizontally and vertically.
  180. The minimumHorizontalScale parameter specifies how much the text can be squashed horizontally
  181. to try to squeeze it into the space. If you don't want any horizontal scaling to occur, you
  182. can set this value to 1.0f.
  183. @see GlyphArrangement::addFittedText
  184. */
  185. void drawFittedText (const String& text,
  186. const Rectangle<int>& area,
  187. const Justification& justificationFlags,
  188. int maximumNumberOfLines,
  189. float minimumHorizontalScale = 0.7f) const;
  190. //==============================================================================
  191. /** Fills the context's entire clip region with the current colour or brush.
  192. (See also the fillAll (Colour) method which is a quick way of filling
  193. it with a given colour).
  194. */
  195. void fillAll() const;
  196. /** Fills the context's entire clip region with a given colour.
  197. This leaves the context's current colour and brush unchanged, it just
  198. uses the specified colour temporarily.
  199. */
  200. void fillAll (Colour colourToUse) const;
  201. //==============================================================================
  202. /** Fills a rectangle with the current colour or brush.
  203. @see drawRect, fillRoundedRectangle
  204. */
  205. void fillRect (int x, int y, int width, int height) const;
  206. /** Fills a rectangle with the current colour or brush. */
  207. void fillRect (const Rectangle<int>& rectangle) const;
  208. /** Fills a rectangle with the current colour or brush. */
  209. void fillRect (const Rectangle<float>& rectangle) const;
  210. /** Fills a rectangle with the current colour or brush.
  211. This uses sub-pixel positioning so is slower than the fillRect method which
  212. takes integer co-ordinates.
  213. */
  214. void fillRect (float x, float y, float width, float height) const;
  215. /** Uses the current colour or brush to fill a rectangle with rounded corners.
  216. @see drawRoundedRectangle, Path::addRoundedRectangle
  217. */
  218. void fillRoundedRectangle (float x, float y, float width, float height,
  219. float cornerSize) const;
  220. /** Uses the current colour or brush to fill a rectangle with rounded corners.
  221. @see drawRoundedRectangle, Path::addRoundedRectangle
  222. */
  223. void fillRoundedRectangle (const Rectangle<float>& rectangle,
  224. float cornerSize) const;
  225. /** Fills a rectangle with a checkerboard pattern, alternating between two colours.
  226. */
  227. void fillCheckerBoard (const Rectangle<int>& area,
  228. int checkWidth, int checkHeight,
  229. Colour colour1, Colour colour2) const;
  230. /** Draws four lines to form a rectangular outline, using the current colour or brush.
  231. The lines are drawn inside the given rectangle, and greater line thicknesses
  232. extend inwards.
  233. @see fillRect
  234. */
  235. void drawRect (int x, int y, int width, int height,
  236. int lineThickness = 1) const;
  237. /** Draws four lines to form a rectangular outline, using the current colour or brush.
  238. The lines are drawn inside the given rectangle, and greater line thicknesses
  239. extend inwards.
  240. @see fillRect
  241. */
  242. void drawRect (float x, float y, float width, float height,
  243. float lineThickness = 1.0f) const;
  244. /** Draws four lines to form a rectangular outline, using the current colour or brush.
  245. The lines are drawn inside the given rectangle, and greater line thicknesses
  246. extend inwards.
  247. @see fillRect
  248. */
  249. void drawRect (const Rectangle<int>& rectangle, int lineThickness = 1) const;
  250. /** Draws four lines to form a rectangular outline, using the current colour or brush.
  251. The lines are drawn inside the given rectangle, and greater line thicknesses
  252. extend inwards.
  253. @see fillRect
  254. */
  255. void drawRect (const Rectangle<float>& rectangle, float lineThickness = 1.0f) const;
  256. /** Uses the current colour or brush to draw the outline of a rectangle with rounded corners.
  257. @see fillRoundedRectangle, Path::addRoundedRectangle
  258. */
  259. void drawRoundedRectangle (float x, float y, float width, float height,
  260. float cornerSize, float lineThickness) const;
  261. /** Uses the current colour or brush to draw the outline of a rectangle with rounded corners.
  262. @see fillRoundedRectangle, Path::addRoundedRectangle
  263. */
  264. void drawRoundedRectangle (const Rectangle<float>& rectangle,
  265. float cornerSize, float lineThickness) const;
  266. /** Draws a 1x1 pixel using the current colour or brush. */
  267. void setPixel (int x, int y) const;
  268. //==============================================================================
  269. /** Fills an ellipse with the current colour or brush.
  270. The ellipse is drawn to fit inside the given rectangle.
  271. @see drawEllipse, Path::addEllipse
  272. */
  273. void fillEllipse (float x, float y, float width, float height) const;
  274. /** Fills an ellipse with the current colour or brush.
  275. The ellipse is drawn to fit inside the given rectangle.
  276. @see drawEllipse, Path::addEllipse
  277. */
  278. void fillEllipse (const Rectangle<float>& area) const;
  279. /** Draws an elliptical stroke using the current colour or brush.
  280. @see fillEllipse, Path::addEllipse
  281. */
  282. void drawEllipse (float x, float y, float width, float height,
  283. float lineThickness) const;
  284. //==============================================================================
  285. /** Draws a line between two points.
  286. The line is 1 pixel wide and drawn with the current colour or brush.
  287. */
  288. void drawLine (float startX, float startY, float endX, float endY) const;
  289. /** Draws a line between two points with a given thickness.
  290. @see Path::addLineSegment
  291. */
  292. void drawLine (float startX, float startY, float endX, float endY,
  293. float lineThickness) const;
  294. /** Draws a line between two points.
  295. The line is 1 pixel wide and drawn with the current colour or brush.
  296. */
  297. void drawLine (const Line<float>& line) const;
  298. /** Draws a line between two points with a given thickness.
  299. @see Path::addLineSegment
  300. */
  301. void drawLine (const Line<float>& line, float lineThickness) const;
  302. /** Draws a dashed line using a custom set of dash-lengths.
  303. @param line the line to draw
  304. @param dashLengths a series of lengths to specify the on/off lengths - e.g.
  305. { 4, 5, 6, 7 } will draw a line of 4 pixels, skip 5 pixels,
  306. draw 6 pixels, skip 7 pixels, and then repeat.
  307. @param numDashLengths the number of elements in the array (this must be an even number).
  308. @param lineThickness the thickness of the line to draw
  309. @param dashIndexToStartFrom the index in the dash-length array to use for the first segment
  310. @see PathStrokeType::createDashedStroke
  311. */
  312. void drawDashedLine (const Line<float>& line,
  313. const float* dashLengths, int numDashLengths,
  314. float lineThickness = 1.0f,
  315. int dashIndexToStartFrom = 0) const;
  316. /** Draws a vertical line of pixels at a given x position.
  317. The x position is an integer, but the top and bottom of the line can be sub-pixel
  318. positions, and these will be anti-aliased if necessary.
  319. The bottom parameter must be greater than or equal to the top parameter.
  320. */
  321. void drawVerticalLine (int x, float top, float bottom) const;
  322. /** Draws a horizontal line of pixels at a given y position.
  323. The y position is an integer, but the left and right ends of the line can be sub-pixel
  324. positions, and these will be anti-aliased if necessary.
  325. The right parameter must be greater than or equal to the left parameter.
  326. */
  327. void drawHorizontalLine (int y, float left, float right) const;
  328. //==============================================================================
  329. /** Fills a path using the currently selected colour or brush.
  330. */
  331. void fillPath (const Path& path,
  332. const AffineTransform& transform = AffineTransform::identity) const;
  333. /** Draws a path's outline using the currently selected colour or brush.
  334. */
  335. void strokePath (const Path& path,
  336. const PathStrokeType& strokeType,
  337. const AffineTransform& transform = AffineTransform::identity) const;
  338. /** Draws a line with an arrowhead at its end.
  339. @param line the line to draw
  340. @param lineThickness the thickness of the line
  341. @param arrowheadWidth the width of the arrow head (perpendicular to the line)
  342. @param arrowheadLength the length of the arrow head (along the length of the line)
  343. */
  344. void drawArrow (const Line<float>& line,
  345. float lineThickness,
  346. float arrowheadWidth,
  347. float arrowheadLength) const;
  348. //==============================================================================
  349. /** Types of rendering quality that can be specified when drawing images.
  350. @see blendImage, Graphics::setImageResamplingQuality
  351. */
  352. enum ResamplingQuality
  353. {
  354. lowResamplingQuality = 0, /**< Just uses a nearest-neighbour algorithm for resampling. */
  355. mediumResamplingQuality = 1, /**< Uses bilinear interpolation for upsampling and area-averaging for downsampling. */
  356. highResamplingQuality = 2 /**< Uses bicubic interpolation for upsampling and area-averaging for downsampling. */
  357. };
  358. /** Changes the quality that will be used when resampling images.
  359. By default a Graphics object will be set to mediumRenderingQuality.
  360. @see Graphics::drawImage, Graphics::drawImageTransformed, Graphics::drawImageWithin
  361. */
  362. void setImageResamplingQuality (const ResamplingQuality newQuality);
  363. /** Draws an image.
  364. This will draw the whole of an image, positioning its top-left corner at the
  365. given co-ordinates, and keeping its size the same. This is the simplest image
  366. drawing method - the others give more control over the scaling and clipping
  367. of the images.
  368. Images are composited using the context's current opacity, so if you
  369. don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f)
  370. (or setColour() with an opaque colour) before drawing images.
  371. */
  372. void drawImageAt (const Image& imageToDraw, int topLeftX, int topLeftY,
  373. bool fillAlphaChannelWithCurrentBrush = false) const;
  374. /** Draws part of an image, rescaling it to fit in a given target region.
  375. The specified area of the source image is rescaled and drawn to fill the
  376. specifed destination rectangle.
  377. Images are composited using the context's current opacity, so if you
  378. don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f)
  379. (or setColour() with an opaque colour) before drawing images.
  380. @param imageToDraw the image to overlay
  381. @param destX the left of the destination rectangle
  382. @param destY the top of the destination rectangle
  383. @param destWidth the width of the destination rectangle
  384. @param destHeight the height of the destination rectangle
  385. @param sourceX the left of the rectangle to copy from the source image
  386. @param sourceY the top of the rectangle to copy from the source image
  387. @param sourceWidth the width of the rectangle to copy from the source image
  388. @param sourceHeight the height of the rectangle to copy from the source image
  389. @param fillAlphaChannelWithCurrentBrush if true, then instead of drawing the source image's pixels,
  390. the source image's alpha channel is used as a mask with
  391. which to fill the destination using the current colour
  392. or brush. (If the source is has no alpha channel, then
  393. it will just fill the target with a solid rectangle)
  394. @see setImageResamplingQuality, drawImageAt, drawImageWithin, fillAlphaMap
  395. */
  396. void drawImage (const Image& imageToDraw,
  397. int destX, int destY, int destWidth, int destHeight,
  398. int sourceX, int sourceY, int sourceWidth, int sourceHeight,
  399. bool fillAlphaChannelWithCurrentBrush = false) const;
  400. /** Draws an image, having applied an affine transform to it.
  401. This lets you throw the image around in some wacky ways, rotate it, shear,
  402. scale it, etc.
  403. Images are composited using the context's current opacity, so if you
  404. don't want it to be drawn semi-transparently, be sure to call setOpacity (1.0f)
  405. (or setColour() with an opaque colour) before drawing images.
  406. If fillAlphaChannelWithCurrentBrush is set to true, then the image's RGB channels
  407. are ignored and it is filled with the current brush, masked by its alpha channel.
  408. If you want to render only a subsection of an image, use Image::getClippedImage() to
  409. create the section that you need.
  410. @see setImageResamplingQuality, drawImage
  411. */
  412. void drawImageTransformed (const Image& imageToDraw,
  413. const AffineTransform& transform,
  414. bool fillAlphaChannelWithCurrentBrush = false) const;
  415. /** Draws an image to fit within a designated rectangle.
  416. If the image is too big or too small for the space, it will be rescaled
  417. to fit as nicely as it can do without affecting its aspect ratio. It will
  418. then be placed within the target rectangle according to the justification flags
  419. specified.
  420. @param imageToDraw the source image to draw
  421. @param destX top-left of the target rectangle to fit it into
  422. @param destY top-left of the target rectangle to fit it into
  423. @param destWidth size of the target rectangle to fit the image into
  424. @param destHeight size of the target rectangle to fit the image into
  425. @param placementWithinTarget this specifies how the image should be positioned
  426. within the target rectangle - see the RectanglePlacement
  427. class for more details about this.
  428. @param fillAlphaChannelWithCurrentBrush if true, then instead of drawing the image, just its
  429. alpha channel will be used as a mask with which to
  430. draw with the current brush or colour. This is
  431. similar to fillAlphaMap(), and see also drawImage()
  432. @see setImageResamplingQuality, drawImage, drawImageTransformed, drawImageAt, RectanglePlacement
  433. */
  434. void drawImageWithin (const Image& imageToDraw,
  435. int destX, int destY, int destWidth, int destHeight,
  436. const RectanglePlacement& placementWithinTarget,
  437. bool fillAlphaChannelWithCurrentBrush = false) const;
  438. //==============================================================================
  439. /** Returns the position of the bounding box for the current clipping region.
  440. @see getClipRegion, clipRegionIntersects
  441. */
  442. Rectangle<int> getClipBounds() const;
  443. /** Checks whether a rectangle overlaps the context's clipping region.
  444. If this returns false, no part of the given area can be drawn onto, so this
  445. method can be used to optimise a component's paint() method, by letting it
  446. avoid drawing complex objects that aren't within the region being repainted.
  447. */
  448. bool clipRegionIntersects (const Rectangle<int>& area) const;
  449. /** Intersects the current clipping region with another region.
  450. @returns true if the resulting clipping region is non-zero in size
  451. @see setOrigin, clipRegionIntersects
  452. */
  453. bool reduceClipRegion (int x, int y, int width, int height);
  454. /** Intersects the current clipping region with another region.
  455. @returns true if the resulting clipping region is non-zero in size
  456. @see setOrigin, clipRegionIntersects
  457. */
  458. bool reduceClipRegion (const Rectangle<int>& area);
  459. /** Intersects the current clipping region with a rectangle list region.
  460. @returns true if the resulting clipping region is non-zero in size
  461. @see setOrigin, clipRegionIntersects
  462. */
  463. bool reduceClipRegion (const RectangleList& clipRegion);
  464. /** Intersects the current clipping region with a path.
  465. @returns true if the resulting clipping region is non-zero in size
  466. @see reduceClipRegion
  467. */
  468. bool reduceClipRegion (const Path& path, const AffineTransform& transform = AffineTransform::identity);
  469. /** Intersects the current clipping region with an image's alpha-channel.
  470. The current clipping path is intersected with the area covered by this image's
  471. alpha-channel, after the image has been transformed by the specified matrix.
  472. @param image the image whose alpha-channel should be used. If the image doesn't
  473. have an alpha-channel, it is treated as entirely opaque.
  474. @param transform a matrix to apply to the image
  475. @returns true if the resulting clipping region is non-zero in size
  476. @see reduceClipRegion
  477. */
  478. bool reduceClipRegion (const Image& image, const AffineTransform& transform);
  479. /** Excludes a rectangle to stop it being drawn into. */
  480. void excludeClipRegion (const Rectangle<int>& rectangleToExclude);
  481. /** Returns true if no drawing can be done because the clip region is zero. */
  482. bool isClipEmpty() const;
  483. //==============================================================================
  484. /** Saves the current graphics state on an internal stack.
  485. To restore the state, use restoreState().
  486. @see ScopedSaveState
  487. */
  488. void saveState();
  489. /** Restores a graphics state that was previously saved with saveState().
  490. @see ScopedSaveState
  491. */
  492. void restoreState();
  493. /** Uses RAII to save and restore the state of a graphics context.
  494. On construction, this calls Graphics::saveState(), and on destruction it calls
  495. Graphics::restoreState() on the Graphics object that you supply.
  496. */
  497. class ScopedSaveState
  498. {
  499. public:
  500. ScopedSaveState (Graphics& g);
  501. ~ScopedSaveState();
  502. private:
  503. Graphics& context;
  504. JUCE_DECLARE_NON_COPYABLE (ScopedSaveState)
  505. };
  506. //==============================================================================
  507. /** Begins rendering to an off-screen bitmap which will later be flattened onto the current
  508. context with the given opacity.
  509. The context uses an internal stack of temporary image layers to do this. When you've
  510. finished drawing to the layer, call endTransparencyLayer() to complete the operation and
  511. composite the finished layer. Every call to beginTransparencyLayer() MUST be matched
  512. by a corresponding call to endTransparencyLayer()!
  513. This call also saves the current state, and endTransparencyLayer() restores it.
  514. */
  515. void beginTransparencyLayer (float layerOpacity);
  516. /** Completes a drawing operation to a temporary semi-transparent buffer.
  517. See beginTransparencyLayer() for more details.
  518. */
  519. void endTransparencyLayer();
  520. /** Moves the position of the context's origin.
  521. This changes the position that the context considers to be (0, 0) to
  522. the specified position.
  523. So if you call setOrigin (100, 100), then the position that was previously
  524. referred to as (100, 100) will subsequently be considered to be (0, 0).
  525. @see reduceClipRegion, addTransform
  526. */
  527. void setOrigin (int newOriginX, int newOriginY);
  528. /** Adds a transformation which will be performed on all the graphics operations that
  529. the context subsequently performs.
  530. After calling this, all the coordinates that are passed into the context will be
  531. transformed by this matrix.
  532. @see setOrigin
  533. */
  534. void addTransform (const AffineTransform& transform);
  535. /** Resets the current colour, brush, and font to default settings. */
  536. void resetToDefaultState();
  537. /** Returns true if this context is drawing to a vector-based device, such as a printer. */
  538. bool isVectorDevice() const;
  539. //==============================================================================
  540. /** Create a graphics that uses a given low-level renderer.
  541. For internal use only.
  542. NB. The context will NOT be deleted by this object when it is deleted.
  543. */
  544. Graphics (LowLevelGraphicsContext*) noexcept;
  545. /** @internal */
  546. LowLevelGraphicsContext& getInternalContext() const noexcept { return context; }
  547. private:
  548. //==============================================================================
  549. LowLevelGraphicsContext& context;
  550. ScopedPointer <LowLevelGraphicsContext> contextToDelete;
  551. bool saveStatePending;
  552. void saveStateIfPending();
  553. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Graphics)
  554. };
  555. #endif // __JUCE_GRAPHICSCONTEXT_JUCEHEADER__