diff options
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/VectorRenderer.h | 2 | ||||
-rw-r--r-- | graphics/VectorRendererSpec.cpp | 86 | ||||
-rw-r--r-- | graphics/VectorRendererSpec.h | 2 | ||||
-rw-r--r-- | graphics/font.cpp | 2 |
4 files changed, 79 insertions, 13 deletions
diff --git a/graphics/VectorRenderer.h b/graphics/VectorRenderer.h index 5d6369c08f..4ca76224e1 100644 --- a/graphics/VectorRenderer.h +++ b/graphics/VectorRenderer.h @@ -466,7 +466,7 @@ public: */ virtual void drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, Graphics::TextAlign alignH, - GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis) = 0; + GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool useEllipsis, const Common::Rect &textDrawableArea) = 0; /** * Allows to temporarily enable/disable all shadows drawing. diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp index e4843ba78b..f9041fc8ff 100644 --- a/graphics/VectorRendererSpec.cpp +++ b/graphics/VectorRendererSpec.cpp @@ -646,24 +646,90 @@ darkenFill(PixelType *ptr, PixelType *end) { template<typename PixelType> void VectorRendererSpec<PixelType>:: drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, - Graphics::TextAlign alignH, GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool ellipsis) { + Graphics::TextAlign alignH, GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool ellipsis, const Common::Rect &textDrawableArea) { int offset = area.top; if (font->getFontHeight() < area.height()) { switch (alignV) { - case GUI::ThemeEngine::kTextAlignVCenter: - offset = area.top + ((area.height() - font->getFontHeight()) >> 1); - break; - case GUI::ThemeEngine::kTextAlignVBottom: - offset = area.bottom - font->getFontHeight(); - break; - default: - break; + case GUI::ThemeEngine::kTextAlignVCenter: + offset = area.top + ((area.height() - font->getFontHeight()) >> 1); + break; + case GUI::ThemeEngine::kTextAlignVBottom: + offset = area.bottom - font->getFontHeight(); + break; + default: + break; } } - font->drawString(_activeSurface, text, area.left, offset, area.width() - deltax, _fgColor, alignH, deltax, ellipsis); + 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; + } + + backSurface.free(); } /** LINES **/ diff --git a/graphics/VectorRendererSpec.h b/graphics/VectorRendererSpec.h index 4ed80cb55f..08d00dd569 100644 --- a/graphics/VectorRendererSpec.h +++ b/graphics/VectorRendererSpec.h @@ -61,7 +61,7 @@ public: } void drawString(const Graphics::Font *font, const Common::String &text, const Common::Rect &area, Graphics::TextAlign alignH, - GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool elipsis); + GUI::ThemeEngine::TextAlignVertical alignV, int deltax, bool elipsis, const Common::Rect &textDrawableArea = Common::Rect(0, 0, 0, 0)); void setFgColor(uint8 r, uint8 g, uint8 b) { _fgColor = _format.RGBToColor(r, g, b); } void setBgColor(uint8 r, uint8 g, uint8 b) { _bgColor = _format.RGBToColor(r, g, b); } diff --git a/graphics/font.cpp b/graphics/font.cpp index 3b00cd8568..a852274b06 100644 --- a/graphics/font.cpp +++ b/graphics/font.cpp @@ -128,7 +128,7 @@ void Font::drawString(Surface *dst, const Common::String &sOld, int x, int y, in w = getCharWidth(cur); if (x+w > rightX) break; - if (x >= leftX) + if (x+w >= leftX) drawChar(dst, str[i], x, y, color); x += w; } |