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.

149 lines
6.5KB

  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. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image)
  18. : savedState (new RenderingHelpers::SoftwareRendererSavedState (image, image.getBounds()))
  19. {
  20. }
  21. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image, Point<int> origin,
  22. const RectangleList<int>& initialClip)
  23. : savedState (new RenderingHelpers::SoftwareRendererSavedState (image, initialClip, origin.x, origin.y))
  24. {
  25. }
  26. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer() {}
  27. //==============================================================================
  28. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const { return false; }
  29. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y) { savedState->transform.setOrigin (x, y); }
  30. void LowLevelGraphicsSoftwareRenderer::addTransform (const AffineTransform& t) { savedState->transform.addTransform (t); }
  31. float LowLevelGraphicsSoftwareRenderer::getScaleFactor() { return savedState->transform.getScaleFactor(); }
  32. Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const { return savedState->getClipBounds(); }
  33. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const { return savedState->clip == nullptr; }
  34. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r) { return savedState->clipToRectangle (r); }
  35. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList<int>& r) { return savedState->clipToRectangleList (r); }
  36. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r) { savedState->excludeClipRectangle (r); }
  37. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  38. {
  39. savedState->clipToPath (path, transform);
  40. }
  41. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const AffineTransform& transform)
  42. {
  43. savedState->clipToImageAlpha (sourceImage, transform);
  44. }
  45. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  46. {
  47. return savedState->clipRegionIntersects (r);
  48. }
  49. //==============================================================================
  50. void LowLevelGraphicsSoftwareRenderer::saveState() { savedState.save(); }
  51. void LowLevelGraphicsSoftwareRenderer::restoreState() { savedState.restore(); }
  52. void LowLevelGraphicsSoftwareRenderer::beginTransparencyLayer (float opacity) { savedState.beginTransparencyLayer (opacity); }
  53. void LowLevelGraphicsSoftwareRenderer::endTransparencyLayer() { savedState.endTransparencyLayer(); }
  54. //==============================================================================
  55. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  56. {
  57. savedState->fillType = fillType;
  58. }
  59. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  60. {
  61. savedState->fillType.setOpacity (newOpacity);
  62. }
  63. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  64. {
  65. savedState->interpolationQuality = quality;
  66. }
  67. //==============================================================================
  68. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  69. {
  70. savedState->fillRect (r, replaceExistingContents);
  71. }
  72. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  73. {
  74. savedState->fillPath (path, transform);
  75. }
  76. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const AffineTransform& transform)
  77. {
  78. savedState->renderImage (sourceImage, transform, nullptr);
  79. }
  80. void LowLevelGraphicsSoftwareRenderer::drawLine (const Line <float>& line)
  81. {
  82. Path p;
  83. p.addLineSegment (line, 1.0f);
  84. fillPath (p, AffineTransform::identity);
  85. }
  86. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, const float top, const float bottom)
  87. {
  88. if (bottom > top)
  89. savedState->fillRect (Rectangle<float> ((float) x, top, 1.0f, bottom - top));
  90. }
  91. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, const float left, const float right)
  92. {
  93. if (right > left)
  94. savedState->fillRect (Rectangle<float> (left, (float) y, right - left, 1.0f));
  95. }
  96. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  97. {
  98. const Font& f = savedState->font;
  99. if (transform.isOnlyTranslation() && savedState->transform.isOnlyTranslated)
  100. {
  101. using namespace RenderingHelpers;
  102. GlyphCache <CachedGlyphEdgeTable <SoftwareRendererSavedState>, SoftwareRendererSavedState>::getInstance()
  103. .drawGlyph (*savedState, f, glyphNumber,
  104. transform.getTranslationX(),
  105. transform.getTranslationY());
  106. }
  107. else
  108. {
  109. const float fontHeight = f.getHeight();
  110. savedState->drawGlyph (f, glyphNumber,
  111. AffineTransform::scale (fontHeight * f.getHorizontalScale(), fontHeight)
  112. .followedBy (transform));
  113. }
  114. }
  115. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont) { savedState->font = newFont; }
  116. const Font& LowLevelGraphicsSoftwareRenderer::getFont() { return savedState->font; }