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.

729 lines
25KB

  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. namespace
  19. {
  20. template <typename Type>
  21. bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  22. {
  23. const int maxVal = 0x3fffffff;
  24. return (int) x >= -maxVal && (int) x <= maxVal
  25. && (int) y >= -maxVal && (int) y <= maxVal
  26. && (int) w >= -maxVal && (int) w <= maxVal
  27. && (int) h >= -maxVal && (int) h <= maxVal;
  28. }
  29. }
  30. //==============================================================================
  31. LowLevelGraphicsContext::LowLevelGraphicsContext()
  32. {
  33. }
  34. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  35. {
  36. }
  37. //==============================================================================
  38. Graphics::Graphics (const Image& imageToDrawOnto)
  39. : context (imageToDrawOnto.createLowLevelContext()),
  40. contextToDelete (context),
  41. saveStatePending (false)
  42. {
  43. }
  44. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) noexcept
  45. : context (internalContext),
  46. saveStatePending (false)
  47. {
  48. }
  49. Graphics::~Graphics()
  50. {
  51. }
  52. //==============================================================================
  53. void Graphics::resetToDefaultState()
  54. {
  55. saveStateIfPending();
  56. context->setFill (FillType());
  57. context->setFont (Font());
  58. context->setInterpolationQuality (Graphics::mediumResamplingQuality);
  59. }
  60. bool Graphics::isVectorDevice() const
  61. {
  62. return context->isVectorDevice();
  63. }
  64. bool Graphics::reduceClipRegion (const Rectangle<int>& area)
  65. {
  66. saveStateIfPending();
  67. return context->clipToRectangle (area);
  68. }
  69. bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h)
  70. {
  71. return reduceClipRegion (Rectangle<int> (x, y, w, h));
  72. }
  73. bool Graphics::reduceClipRegion (const RectangleList& clipRegion)
  74. {
  75. saveStateIfPending();
  76. return context->clipToRectangleList (clipRegion);
  77. }
  78. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform)
  79. {
  80. saveStateIfPending();
  81. context->clipToPath (path, transform);
  82. return ! context->isClipEmpty();
  83. }
  84. bool Graphics::reduceClipRegion (const Image& image, const AffineTransform& transform)
  85. {
  86. saveStateIfPending();
  87. context->clipToImageAlpha (image, transform);
  88. return ! context->isClipEmpty();
  89. }
  90. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude)
  91. {
  92. saveStateIfPending();
  93. context->excludeClipRectangle (rectangleToExclude);
  94. }
  95. bool Graphics::isClipEmpty() const
  96. {
  97. return context->isClipEmpty();
  98. }
  99. Rectangle<int> Graphics::getClipBounds() const
  100. {
  101. return context->getClipBounds();
  102. }
  103. void Graphics::saveState()
  104. {
  105. saveStateIfPending();
  106. saveStatePending = true;
  107. }
  108. void Graphics::restoreState()
  109. {
  110. if (saveStatePending)
  111. saveStatePending = false;
  112. else
  113. context->restoreState();
  114. }
  115. void Graphics::saveStateIfPending()
  116. {
  117. if (saveStatePending)
  118. {
  119. saveStatePending = false;
  120. context->saveState();
  121. }
  122. }
  123. void Graphics::setOrigin (const int newOriginX, const int newOriginY)
  124. {
  125. saveStateIfPending();
  126. context->setOrigin (newOriginX, newOriginY);
  127. }
  128. void Graphics::addTransform (const AffineTransform& transform)
  129. {
  130. saveStateIfPending();
  131. context->addTransform (transform);
  132. }
  133. bool Graphics::clipRegionIntersects (const Rectangle<int>& area) const
  134. {
  135. return context->clipRegionIntersects (area);
  136. }
  137. void Graphics::beginTransparencyLayer (float layerOpacity)
  138. {
  139. saveStateIfPending();
  140. context->beginTransparencyLayer (layerOpacity);
  141. }
  142. void Graphics::endTransparencyLayer()
  143. {
  144. context->endTransparencyLayer();
  145. }
  146. //==============================================================================
  147. void Graphics::setColour (const Colour& newColour)
  148. {
  149. saveStateIfPending();
  150. context->setFill (newColour);
  151. }
  152. void Graphics::setOpacity (const float newOpacity)
  153. {
  154. saveStateIfPending();
  155. context->setOpacity (newOpacity);
  156. }
  157. void Graphics::setGradientFill (const ColourGradient& gradient)
  158. {
  159. setFillType (gradient);
  160. }
  161. void Graphics::setTiledImageFill (const Image& imageToUse, const int anchorX, const int anchorY, const float opacity)
  162. {
  163. saveStateIfPending();
  164. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  165. context->setOpacity (opacity);
  166. }
  167. void Graphics::setFillType (const FillType& newFill)
  168. {
  169. saveStateIfPending();
  170. context->setFill (newFill);
  171. }
  172. //==============================================================================
  173. void Graphics::setFont (const Font& newFont)
  174. {
  175. saveStateIfPending();
  176. context->setFont (newFont);
  177. }
  178. void Graphics::setFont (const float newFontHeight, const int newFontStyleFlags)
  179. {
  180. saveStateIfPending();
  181. Font f (context->getFont());
  182. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  183. context->setFont (f);
  184. }
  185. Font Graphics::getCurrentFont() const
  186. {
  187. return context->getFont();
  188. }
  189. //==============================================================================
  190. void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY,
  191. const Justification& justification) const
  192. {
  193. if (text.isNotEmpty()
  194. && startX < context->getClipBounds().getRight())
  195. {
  196. GlyphArrangement arr;
  197. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  198. // Don't pass any vertical placement flags to this method - they'll be ignored.
  199. jassert (justification.getOnlyVerticalFlags() == 0);
  200. const int flags = justification.getOnlyHorizontalFlags();
  201. if (flags != Justification::left)
  202. {
  203. float w = arr.getBoundingBox (0, -1, true).getWidth();
  204. if ((flags & (Justification::horizontallyCentred | Justification::horizontallyJustified)) != 0)
  205. w /= 2.0f;
  206. arr.draw (*this, AffineTransform::translation (-w, 0));
  207. }
  208. else
  209. {
  210. arr.draw (*this);
  211. }
  212. }
  213. }
  214. void Graphics::drawTextAsPath (const String& text, const AffineTransform& transform) const
  215. {
  216. if (text.isNotEmpty())
  217. {
  218. GlyphArrangement arr;
  219. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  220. arr.draw (*this, transform);
  221. }
  222. }
  223. void Graphics::drawMultiLineText (const String& text, const int startX, const int baselineY, const int maximumLineWidth) const
  224. {
  225. if (text.isNotEmpty()
  226. && startX < context->getClipBounds().getRight())
  227. {
  228. GlyphArrangement arr;
  229. arr.addJustifiedText (context->getFont(), text,
  230. (float) startX, (float) baselineY, (float) maximumLineWidth,
  231. Justification::left);
  232. arr.draw (*this);
  233. }
  234. }
  235. void Graphics::drawText (const String& text,
  236. const int x, const int y, const int width, const int height,
  237. const Justification& justificationType,
  238. const bool useEllipsesIfTooBig) const
  239. {
  240. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  241. {
  242. GlyphArrangement arr;
  243. arr.addCurtailedLineOfText (context->getFont(), text,
  244. 0.0f, 0.0f, (float) width,
  245. useEllipsesIfTooBig);
  246. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  247. (float) x, (float) y, (float) width, (float) height,
  248. justificationType);
  249. arr.draw (*this);
  250. }
  251. }
  252. void Graphics::drawFittedText (const String& text,
  253. const int x, const int y, const int width, const int height,
  254. const Justification& justification,
  255. const int maximumNumberOfLines,
  256. const float minimumHorizontalScale) const
  257. {
  258. if (text.isNotEmpty()
  259. && width > 0 && height > 0
  260. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  261. {
  262. GlyphArrangement arr;
  263. arr.addFittedText (context->getFont(), text,
  264. (float) x, (float) y, (float) width, (float) height,
  265. justification,
  266. maximumNumberOfLines,
  267. minimumHorizontalScale);
  268. arr.draw (*this);
  269. }
  270. }
  271. //==============================================================================
  272. void Graphics::fillRect (int x, int y, int width, int height) const
  273. {
  274. // passing in a silly number can cause maths problems in rendering!
  275. jassert (areCoordsSensibleNumbers (x, y, width, height));
  276. context->fillRect (Rectangle<int> (x, y, width, height), false);
  277. }
  278. void Graphics::fillRect (const Rectangle<int>& r) const
  279. {
  280. context->fillRect (r, false);
  281. }
  282. void Graphics::fillRect (const float x, const float y, const float width, const float height) const
  283. {
  284. // passing in a silly number can cause maths problems in rendering!
  285. jassert (areCoordsSensibleNumbers (x, y, width, height));
  286. Path p;
  287. p.addRectangle (x, y, width, height);
  288. fillPath (p);
  289. }
  290. void Graphics::setPixel (int x, int y) const
  291. {
  292. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  293. }
  294. void Graphics::fillAll() const
  295. {
  296. fillRect (context->getClipBounds());
  297. }
  298. void Graphics::fillAll (const Colour& colourToUse) const
  299. {
  300. if (! colourToUse.isTransparent())
  301. {
  302. const Rectangle<int> clip (context->getClipBounds());
  303. context->saveState();
  304. context->setFill (colourToUse);
  305. context->fillRect (clip, false);
  306. context->restoreState();
  307. }
  308. }
  309. //==============================================================================
  310. void Graphics::fillPath (const Path& path, const AffineTransform& transform) const
  311. {
  312. if ((! context->isClipEmpty()) && ! path.isEmpty())
  313. context->fillPath (path, transform);
  314. }
  315. void Graphics::strokePath (const Path& path,
  316. const PathStrokeType& strokeType,
  317. const AffineTransform& transform) const
  318. {
  319. Path stroke;
  320. strokeType.createStrokedPath (stroke, path, transform, context->getScaleFactor());
  321. fillPath (stroke);
  322. }
  323. //==============================================================================
  324. void Graphics::drawRect (const int x, const int y, const int width, const int height,
  325. const int lineThickness) const
  326. {
  327. // passing in a silly number can cause maths problems in rendering!
  328. jassert (areCoordsSensibleNumbers (x, y, width, height));
  329. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  330. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  331. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  332. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  333. }
  334. void Graphics::drawRect (const float x, const float y, const float width, const float height, const float lineThickness) const
  335. {
  336. // passing in a silly number can cause maths problems in rendering!
  337. jassert (areCoordsSensibleNumbers (x, y, width, height));
  338. Path p;
  339. p.addRectangle (x, y, width, lineThickness);
  340. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  341. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  342. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  343. fillPath (p);
  344. }
  345. void Graphics::drawRect (const Rectangle<int>& r, const int lineThickness) const
  346. {
  347. drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(), lineThickness);
  348. }
  349. void Graphics::drawBevel (const int x, const int y, const int width, const int height,
  350. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  351. const bool useGradient, const bool sharpEdgeOnOutside) const
  352. {
  353. // passing in a silly number can cause maths problems in rendering!
  354. jassert (areCoordsSensibleNumbers (x, y, width, height));
  355. if (clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  356. {
  357. context->saveState();
  358. for (int i = bevelThickness; --i >= 0;)
  359. {
  360. const float op = useGradient ? (sharpEdgeOnOutside ? bevelThickness - i : i) / (float) bevelThickness
  361. : 1.0f;
  362. context->setFill (topLeftColour.withMultipliedAlpha (op));
  363. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  364. context->setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  365. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  366. context->setFill (bottomRightColour.withMultipliedAlpha (op));
  367. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  368. context->setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  369. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  370. }
  371. context->restoreState();
  372. }
  373. }
  374. //==============================================================================
  375. void Graphics::fillEllipse (const float x, const float y, const float width, const float height) const
  376. {
  377. // passing in a silly number can cause maths problems in rendering!
  378. jassert (areCoordsSensibleNumbers (x, y, width, height));
  379. Path p;
  380. p.addEllipse (x, y, width, height);
  381. fillPath (p);
  382. }
  383. void Graphics::drawEllipse (const float x, const float y, const float width, const float height,
  384. const float lineThickness) const
  385. {
  386. // passing in a silly number can cause maths problems in rendering!
  387. jassert (areCoordsSensibleNumbers (x, y, width, height));
  388. Path p;
  389. p.addEllipse (x, y, width, height);
  390. strokePath (p, PathStrokeType (lineThickness));
  391. }
  392. void Graphics::fillRoundedRectangle (const float x, const float y, const float width, const float height, const float cornerSize) const
  393. {
  394. // passing in a silly number can cause maths problems in rendering!
  395. jassert (areCoordsSensibleNumbers (x, y, width, height));
  396. Path p;
  397. p.addRoundedRectangle (x, y, width, height, cornerSize);
  398. fillPath (p);
  399. }
  400. void Graphics::fillRoundedRectangle (const Rectangle<float>& r, const float cornerSize) const
  401. {
  402. fillRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize);
  403. }
  404. void Graphics::drawRoundedRectangle (const float x, const float y, const float width, const float height,
  405. const float cornerSize, const float lineThickness) const
  406. {
  407. // passing in a silly number can cause maths problems in rendering!
  408. jassert (areCoordsSensibleNumbers (x, y, width, height));
  409. Path p;
  410. p.addRoundedRectangle (x, y, width, height, cornerSize);
  411. strokePath (p, PathStrokeType (lineThickness));
  412. }
  413. void Graphics::drawRoundedRectangle (const Rectangle<float>& r, const float cornerSize, const float lineThickness) const
  414. {
  415. drawRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize, lineThickness);
  416. }
  417. void Graphics::drawArrow (const Line<float>& line, const float lineThickness, const float arrowheadWidth, const float arrowheadLength) const
  418. {
  419. Path p;
  420. p.addArrow (line, lineThickness, arrowheadWidth, arrowheadLength);
  421. fillPath (p);
  422. }
  423. void Graphics::fillCheckerBoard (const Rectangle<int>& area,
  424. const int checkWidth, const int checkHeight,
  425. const Colour& colour1, const Colour& colour2) const
  426. {
  427. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  428. if (checkWidth > 0 && checkHeight > 0)
  429. {
  430. context->saveState();
  431. if (colour1 == colour2)
  432. {
  433. context->setFill (colour1);
  434. context->fillRect (area, false);
  435. }
  436. else
  437. {
  438. const Rectangle<int> clipped (context->getClipBounds().getIntersection (area));
  439. if (! clipped.isEmpty())
  440. {
  441. context->clipToRectangle (clipped);
  442. const int checkNumX = (clipped.getX() - area.getX()) / checkWidth;
  443. const int checkNumY = (clipped.getY() - area.getY()) / checkHeight;
  444. const int startX = area.getX() + checkNumX * checkWidth;
  445. const int startY = area.getY() + checkNumY * checkHeight;
  446. const int right = clipped.getRight();
  447. const int bottom = clipped.getBottom();
  448. for (int i = 0; i < 2; ++i)
  449. {
  450. context->setFill (i == ((checkNumX ^ checkNumY) & 1) ? colour1 : colour2);
  451. int cy = i;
  452. for (int y = startY; y < bottom; y += checkHeight)
  453. for (int x = startX + (cy++ & 1) * checkWidth; x < right; x += checkWidth * 2)
  454. context->fillRect (Rectangle<int> (x, y, checkWidth, checkHeight), false);
  455. }
  456. }
  457. }
  458. context->restoreState();
  459. }
  460. }
  461. //==============================================================================
  462. void Graphics::drawVerticalLine (const int x, float top, float bottom) const
  463. {
  464. context->drawVerticalLine (x, top, bottom);
  465. }
  466. void Graphics::drawHorizontalLine (const int y, float left, float right) const
  467. {
  468. context->drawHorizontalLine (y, left, right);
  469. }
  470. void Graphics::drawLine (const float x1, const float y1, const float x2, const float y2) const
  471. {
  472. context->drawLine (Line<float> (x1, y1, x2, y2));
  473. }
  474. void Graphics::drawLine (const Line<float>& line) const
  475. {
  476. context->drawLine (line);
  477. }
  478. void Graphics::drawLine (const float x1, const float y1, const float x2, const float y2, const float lineThickness) const
  479. {
  480. drawLine (Line<float> (x1, y1, x2, y2), lineThickness);
  481. }
  482. void Graphics::drawLine (const Line<float>& line, const float lineThickness) const
  483. {
  484. Path p;
  485. p.addLineSegment (line, lineThickness);
  486. fillPath (p);
  487. }
  488. void Graphics::drawDashedLine (const Line<float>& line, const float* const dashLengths,
  489. const int numDashLengths, const float lineThickness, int n) const
  490. {
  491. jassert (n >= 0 && n < numDashLengths); // your start index must be valid!
  492. const Point<double> delta ((line.getEnd() - line.getStart()).toDouble());
  493. const double totalLen = delta.getDistanceFromOrigin();
  494. if (totalLen >= 0.1)
  495. {
  496. const double onePixAlpha = 1.0 / totalLen;
  497. for (double alpha = 0.0; alpha < 1.0;)
  498. {
  499. jassert (dashLengths[n] > 0); // can't have zero-length dashes!
  500. const double lastAlpha = alpha;
  501. alpha += dashLengths [n] * onePixAlpha;
  502. n = (n + 1) % numDashLengths;
  503. if ((n & 1) != 0)
  504. {
  505. const Line<float> segment (line.getStart() + (delta * lastAlpha).toFloat(),
  506. line.getStart() + (delta * jmin (1.0, alpha)).toFloat());
  507. if (lineThickness != 1.0f)
  508. drawLine (segment, lineThickness);
  509. else
  510. context->drawLine (segment);
  511. }
  512. }
  513. }
  514. }
  515. //==============================================================================
  516. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality)
  517. {
  518. saveStateIfPending();
  519. context->setInterpolationQuality (newQuality);
  520. }
  521. //==============================================================================
  522. void Graphics::drawImageAt (const Image& imageToDraw,
  523. const int topLeftX, const int topLeftY,
  524. const bool fillAlphaChannelWithCurrentBrush) const
  525. {
  526. const int imageW = imageToDraw.getWidth();
  527. const int imageH = imageToDraw.getHeight();
  528. drawImage (imageToDraw,
  529. topLeftX, topLeftY, imageW, imageH,
  530. 0, 0, imageW, imageH,
  531. fillAlphaChannelWithCurrentBrush);
  532. }
  533. void Graphics::drawImageWithin (const Image& imageToDraw,
  534. const int destX, const int destY,
  535. const int destW, const int destH,
  536. const RectanglePlacement& placementWithinTarget,
  537. const bool fillAlphaChannelWithCurrentBrush) const
  538. {
  539. // passing in a silly number can cause maths problems in rendering!
  540. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  541. if (imageToDraw.isValid())
  542. {
  543. const int imageW = imageToDraw.getWidth();
  544. const int imageH = imageToDraw.getHeight();
  545. if (imageW > 0 && imageH > 0)
  546. {
  547. double newX = 0.0, newY = 0.0;
  548. double newW = imageW;
  549. double newH = imageH;
  550. placementWithinTarget.applyTo (newX, newY, newW, newH,
  551. destX, destY, destW, destH);
  552. if (newW > 0 && newH > 0)
  553. {
  554. drawImage (imageToDraw,
  555. roundToInt (newX), roundToInt (newY),
  556. roundToInt (newW), roundToInt (newH),
  557. 0, 0, imageW, imageH,
  558. fillAlphaChannelWithCurrentBrush);
  559. }
  560. }
  561. }
  562. }
  563. void Graphics::drawImage (const Image& imageToDraw,
  564. int dx, int dy, int dw, int dh,
  565. int sx, int sy, int sw, int sh,
  566. const bool fillAlphaChannelWithCurrentBrush) const
  567. {
  568. // passing in a silly number can cause maths problems in rendering!
  569. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  570. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  571. if (imageToDraw.isValid() && context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  572. {
  573. drawImageTransformed (imageToDraw.getClippedImage (Rectangle<int> (sx, sy, sw, sh)),
  574. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  575. .translated ((float) dx, (float) dy),
  576. fillAlphaChannelWithCurrentBrush);
  577. }
  578. }
  579. void Graphics::drawImageTransformed (const Image& imageToDraw,
  580. const AffineTransform& transform,
  581. const bool fillAlphaChannelWithCurrentBrush) const
  582. {
  583. if (imageToDraw.isValid() && ! context->isClipEmpty())
  584. {
  585. if (fillAlphaChannelWithCurrentBrush)
  586. {
  587. context->saveState();
  588. context->clipToImageAlpha (imageToDraw, transform);
  589. fillAll();
  590. context->restoreState();
  591. }
  592. else
  593. {
  594. context->drawImage (imageToDraw, transform);
  595. }
  596. }
  597. }
  598. //==============================================================================
  599. Graphics::ScopedSaveState::ScopedSaveState (Graphics& g)
  600. : context (g)
  601. {
  602. context.saveState();
  603. }
  604. Graphics::ScopedSaveState::~ScopedSaveState()
  605. {
  606. context.restoreState();
  607. }