Audio plugin host https://kx.studio/carla
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.

731 lines
33KB

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