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.

150 lines
6.7KB

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