/* ============================================================================== This file is part of the JUCE library - "Jules' Utility Class Extensions" Copyright 2004-11 by Raw Material Software Ltd. ------------------------------------------------------------------------------ JUCE can be redistributed and/or modified under the terms of the GNU General Public License (Version 2), as published by the Free Software Foundation. A copy of the license is included in the JUCE distribution, or can be found online at www.gnu.org/licenses. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ------------------------------------------------------------------------------ To release a closed-source product which uses JUCE, commercial licenses are available: visit www.rawmaterialsoftware.com/juce for more information. ============================================================================== */ LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image) : savedState (new RenderingHelpers::SoftwareRendererSavedState (image, image.getBounds())) { } LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (const Image& image, const Point& origin, const RectangleList& initialClip) : savedState (new RenderingHelpers::SoftwareRendererSavedState (image, initialClip, origin.x, origin.y)) { } LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer() {} //============================================================================== bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const { return false; } void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y) { savedState->transform.setOrigin (x, y); } void LowLevelGraphicsSoftwareRenderer::addTransform (const AffineTransform& t) { savedState->transform.addTransform (t); } float LowLevelGraphicsSoftwareRenderer::getScaleFactor() { return savedState->transform.getScaleFactor(); } Rectangle LowLevelGraphicsSoftwareRenderer::getClipBounds() const { return savedState->getClipBounds(); } bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const { return savedState->clip == nullptr; } bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle& r) { return savedState->clipToRectangle (r); } bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& r) { return savedState->clipToRectangleList (r); } void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle& r) { savedState->excludeClipRectangle (r); } void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform) { savedState->clipToPath (path, transform); } void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const AffineTransform& transform) { savedState->clipToImageAlpha (sourceImage, transform); } bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle& r) { return savedState->clipRegionIntersects (r); } //============================================================================== void LowLevelGraphicsSoftwareRenderer::saveState() { savedState.save(); } void LowLevelGraphicsSoftwareRenderer::restoreState() { savedState.restore(); } void LowLevelGraphicsSoftwareRenderer::beginTransparencyLayer (float opacity) { savedState.beginTransparencyLayer (opacity); } void LowLevelGraphicsSoftwareRenderer::endTransparencyLayer() { savedState.endTransparencyLayer(); } //============================================================================== void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType) { savedState->fillType = fillType; } void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity) { savedState->fillType.setOpacity (newOpacity); } void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality) { savedState->interpolationQuality = quality; } //============================================================================== void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle& r, const bool replaceExistingContents) { savedState->fillRect (r, replaceExistingContents); } void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform) { savedState->fillPath (path, transform); } void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const AffineTransform& transform) { savedState->renderImage (sourceImage, transform, nullptr); } void LowLevelGraphicsSoftwareRenderer::drawLine (const Line & line) { Path p; p.addLineSegment (line, 1.0f); fillPath (p, AffineTransform::identity); } void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, const float top, const float bottom) { if (bottom > top) savedState->fillRect (Rectangle ((float) x, top, 1.0f, bottom - top)); } void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, const float left, const float right) { if (right > left) savedState->fillRect (Rectangle (left, (float) y, right - left, 1.0f)); } void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform) { const Font& f = savedState->font; if (transform.isOnlyTranslation() && savedState->transform.isOnlyTranslated) { using namespace RenderingHelpers; GlyphCache , SoftwareRendererSavedState>::getInstance() .drawGlyph (*savedState, f, glyphNumber, transform.getTranslationX(), transform.getTranslationY()); } else { const float fontHeight = f.getHeight(); savedState->drawGlyph (f, glyphNumber, AffineTransform::scale (fontHeight * f.getHorizontalScale(), fontHeight) .followedBy (transform)); } } void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont) { savedState->font = newFont; } const Font& LowLevelGraphicsSoftwareRenderer::getFont() { return savedState->font; }