diff options
author | Johannes Schickel | 2013-08-06 22:28:35 +0200 |
---|---|---|
committer | Narek Mailian | 2013-08-22 11:46:48 +0200 |
commit | 81ae06cae36a398c4126cfa80022677703e9ab57 (patch) | |
tree | 2b5dba6c9216961829d934ea362490f64cc9de0b | |
parent | 6fa3c7751f0f60071ebf8cd8e1ccd4b819939c32 (diff) | |
download | scummvm-rg350-81ae06cae36a398c4126cfa80022677703e9ab57.tar.gz scummvm-rg350-81ae06cae36a398c4126cfa80022677703e9ab57.tar.bz2 scummvm-rg350-81ae06cae36a398c4126cfa80022677703e9ab57.zip |
GRAPHICS: Simplify VectorRendererSpec::drawString.
This removes the two additional copy steps for rendering when a drawable text
area is specified. Instead it uses Surface::getSubArea to draw directly onto
_activeSurface.
-rw-r--r-- | graphics/VectorRendererSpec.cpp | 73 |
1 files changed, 10 insertions, 63 deletions
diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp index 2414f667ab..73fcee10e6 100644 --- a/graphics/VectorRendererSpec.cpp +++ b/graphics/VectorRendererSpec.cpp @@ -729,70 +729,17 @@ drawString(const Graphics::Font *font, const Common::String &text, const Common: if (textDrawableArea.isEmpty()) { font->drawString(_activeSurface, text, area.left, offset, area.width() - deltax, _fgColor, alignH, deltax, ellipsis); // warning("there is no text drawable area. Please set this area for clipping"); - return; - } - - int textWidth = font->getStringWidth(text); - - int emptySpace = 0; - - switch (alignH) { - case Graphics::kTextAlignLeft: - // Let emptyspace = 0 - break; - case Graphics::kTextAlignCenter: - emptySpace = (area.width() - textWidth) / 2; - break; - case Graphics::kTextAlignRight: - emptySpace = area.right - textWidth; - break; - case Graphics::kTextAlignInvalid: - // warning("VectorRendererSpec<PixelType>::drawString(...) invalid text align"); - // return; - default: - break; - } - - // if text drawable area don't have any text for clipping - if ((textDrawableArea.right < (area.left + emptySpace)) || (textDrawableArea.left > (area.right - emptySpace))) - return; - - Surface backSurface; - backSurface.create(area.width(), font->getFontHeight() + 4, _activeSurface->format); - - byte *activeSurfacePtr = (byte *)_activeSurface->getBasePtr(area.left, area.top); - byte *backSurfacePtr = (byte *)backSurface.getBasePtr(0, 0); - - // copy background... - for (int i = 0; i < backSurface.h; i++) { - memcpy(backSurfacePtr, activeSurfacePtr, backSurface.w * backSurface.format.bytesPerPixel); - - activeSurfacePtr += _activeSurface->pitch; - backSurfacePtr += backSurface.pitch; - } - - font->drawString(&backSurface, text, 0, 0, area.width() - deltax, _fgColor, alignH, deltax, ellipsis); - - int fromX = ((area.left + emptySpace) < textDrawableArea.left) ? textDrawableArea.left : area.left + emptySpace; - int toX = ((area.right - emptySpace) > textDrawableArea.right) ? textDrawableArea.right : area.right - emptySpace; - - int bytesX = toX - fromX; - - int fromY = (area.top < textDrawableArea.top) ? textDrawableArea.top : area.top; - int toY = (textDrawableArea.bottom < area.bottom) ? textDrawableArea.bottom : area.bottom; - - // copy text from backSurface to activeSurface - activeSurfacePtr = (byte *)_activeSurface->getBasePtr(fromX, fromY); - backSurfacePtr = (byte *)backSurface.getBasePtr(fromX - area.left, fromY - area.top); - - for (int i = fromY; i < toY; i++) { - memcpy(activeSurfacePtr, backSurfacePtr, bytesX * backSurface.format.bytesPerPixel); - - activeSurfacePtr += _activeSurface->pitch; - backSurfacePtr += backSurface.pitch; + } else { + // The area we can draw to is the intersection between the allowed + // drawing area (textDrawableArea) and the area where we try to draw + // the text (area). + Common::Rect drawArea = textDrawableArea.findIntersectingRect(area); + + if (!drawArea.isEmpty()) { + Surface textAreaSurface = _activeSurface->getSubArea(drawArea); + font->drawString(&textAreaSurface, text, area.left - drawArea.left, offset - drawArea.top, area.width() - deltax, _fgColor, alignH, deltax, ellipsis); + } } - - backSurface.free(); } /** LINES **/ |