aboutsummaryrefslogtreecommitdiff
path: root/graphics/VectorRendererSpec.cpp
diff options
context:
space:
mode:
authorNarek Mailian2013-06-13 12:32:36 +0000
committerNarek Mailian2013-08-16 20:54:08 +0200
commit887a99e211c25fd16e4cf3b7505ae17678c2f997 (patch)
treeabb8a48758d30bab824e9794feb193a7d83609cf /graphics/VectorRendererSpec.cpp
parent1d21f5db264b98c53ef1475bdf0f2ffbe01c2e79 (diff)
downloadscummvm-rg350-887a99e211c25fd16e4cf3b7505ae17678c2f997.tar.gz
scummvm-rg350-887a99e211c25fd16e4cf3b7505ae17678c2f997.tar.bz2
scummvm-rg350-887a99e211c25fd16e4cf3b7505ae17678c2f997.zip
GRAPHICS: Added changes and improved code from inisider/scummvm (partial text)
Includes code from https://github.com/inisider/scummvm/ , which has been squashed and bugfixed
Diffstat (limited to 'graphics/VectorRendererSpec.cpp')
-rw-r--r--graphics/VectorRendererSpec.cpp86
1 files changed, 76 insertions, 10 deletions
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 **/