TUCKER: add clipping for text drawing

svn-id: r44393
This commit is contained in:
Gregory Montoir 2009-09-27 10:36:45 +00:00
parent 1b1471e8da
commit 0f564aad81
5 changed files with 38 additions and 37 deletions

View File

@ -165,13 +165,16 @@ void Graphics::copyRect(uint8 *dst, int dstPitch, uint8 *src, int srcPitch, int
}
}
void Graphics::drawStringChar(uint8 *dst, uint8 chr, int pitch, uint8 chrColor, const uint8 *src) {
void Graphics::drawStringChar(uint8 *dst, int xDst, int yDst, int pitch, uint8 chr, uint8 chrColor, const uint8 *src) {
if (chr < 32 || chr - 32 >= _charset.xCount * _charset.yCount) {
return;
}
const int h = MIN(_charset.charH, 200 - yDst);
const int w = MIN(_charset.charW, pitch - xDst);
dst += yDst * pitch + xDst;
int offset = (chr - 32) * _charset.charH * _charset.charW;
for (int y = 0; y < _charset.charH; ++y) {
for (int x = 0; x < _charset.charW; ++x) {
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
const int color = src[offset++];
if (color != 0) {
if (_charsetType == kCharsetTypeCredits) {

View File

@ -57,7 +57,7 @@ public:
static void copyRect(uint8 *dst, int dstPitch, uint8 *src, int srcPitch, int w, int h);
static void drawStringChar(uint8 *dst, uint8 chr, int pitch, uint8 chrColor, const uint8 *src);
static void drawStringChar(uint8 *dst, int xDst, int yDst, int pitch, uint8 chr, uint8 chrColor, const uint8 *src);
static void setCharset(CharsetType type);

View File

@ -3033,17 +3033,17 @@ void TuckerEngine::execData3PreUpdate_locationNum70() {
_panelState = 1;
setCursorType(2);
int pos = getPositionForLine(22, _infoBarBuf);
int offset = (_flagsTable[143] == 0) ? 90 * 640 + 88 : 72 * 640 + 88;
drawStringAlt(offset, color, &_infoBarBuf[pos]);
Graphics::drawStringChar(_locationBackgroundGfxBuf + offset + 9 * 640, 62, 640, color, _charsetGfxBuf);
const int yPos = (_flagsTable[143] == 0) ? 90 : 72;
drawStringAlt(88, yPos, color, &_infoBarBuf[pos]);
Graphics::drawStringChar(_locationBackgroundGfxBuf, 88, yPos + 9, 640, 62, color, _charsetGfxBuf);
if (_flagsTable[143] != 0) {
pos = getPositionForLine(_flagsTable[143] * 2 + 23, _infoBarBuf);
drawStringAlt(offset + 18 * 640, color, &_infoBarBuf[pos]);
drawStringAlt(88, yPos + 18, color, &_infoBarBuf[pos]);
pos = getPositionForLine(_flagsTable[143] * 2 + 24, _infoBarBuf);
drawStringAlt(offset + 27 * 640, color, &_infoBarBuf[pos]);
drawStringAlt(88, yPos + 27, color, &_infoBarBuf[pos]);
}
execData3PreUpdate_locationNum70Helper();
drawStringAlt(offset + 9 * 640 + 8, color, _updateLocation70String, _updateLocation70StringLen);
drawStringAlt(88 + 8, yPos + 9, color, _updateLocation70String, _updateLocation70StringLen);
}
void TuckerEngine::execData3PreUpdate_locationNum70Helper() {

View File

@ -191,7 +191,7 @@ void TuckerEngine::restart() {
_conversationOptionsCount = 0;
_fadedPanel = false;
_panelLockedFlag = 0;
_panelItemWidth = 0;
_conversationOptionLinesCount = 0;
memset(_inventoryItemsState, 0, sizeof(_inventoryItemsState));
memset(_inventoryObjectsList, 0, sizeof(_inventoryObjectsList));
_inventoryObjectsOffset = 0;
@ -1425,11 +1425,11 @@ void TuckerEngine::drawConversationTexts() {
color = 106;
}
drawSpeechText(x, y, _characterSpeechDataPtr, _instructionsActionsTable[i], color);
if (_mousePosY > y && _mousePosY < _panelItemWidth * 10 + y + 1) {
if (_mousePosY > y && _mousePosY < _conversationOptionLinesCount * 10 + y + 1) {
_nextTableToLoadIndex = i;
flag = 1;
}
y += _panelItemWidth * 10;
y += _conversationOptionLinesCount * 10;
}
if (flag == 0) {
_nextTableToLoadIndex = -1;
@ -2822,47 +2822,45 @@ void TuckerEngine::updateSprite(int i) {
}
void TuckerEngine::drawStringInteger(int num, int x, int y, int digits) {
int offset = y * 640 + x + _scrollOffset;
char numStr[4];
assert(num < 1000);
sprintf(numStr, "%03d", num);
int i = (digits > 2) ? 0 : 1;
for (; i < 3; ++i) {
Graphics::drawStringChar(_locationBackgroundGfxBuf + offset, numStr[i], 640, 102, _charsetGfxBuf);
offset += 8;
Graphics::drawStringChar(_locationBackgroundGfxBuf, _scrollOffset + x, y, 640, numStr[i], 102, _charsetGfxBuf);
x += 8;
}
addDirtyRect(_scrollOffset + x, y, Graphics::_charset.charW * 3, Graphics::_charset.charH);
}
void TuckerEngine::drawStringAlt(int offset, int color, const uint8 *str, int strLen) {
int startOffset = offset;
void TuckerEngine::drawStringAlt(int x, int y, int color, const uint8 *str, int strLen) {
const int xStart = x;
int pos = 0;
while (pos != strLen && str[pos] != '\n') {
const uint8 chr = str[pos];
Graphics::drawStringChar(_locationBackgroundGfxBuf + offset, chr, 640, color, _charsetGfxBuf);
offset += _charWidthTable[chr];
Graphics::drawStringChar(_locationBackgroundGfxBuf, x, y, 640, chr, color, _charsetGfxBuf);
x += _charWidthTable[chr];
++pos;
}
addDirtyRect(startOffset % 640, startOffset / 640, Graphics::_charset.charW * pos, Graphics::_charset.charH);
addDirtyRect(xStart, y, x - xStart, Graphics::_charset.charH);
}
void TuckerEngine::drawItemString(int offset, int num, const uint8 *str) {
int count = getPositionForLine(num, str);
while (str[count] != '\n') {
const uint8 chr = str[count];
Graphics::drawStringChar(_itemsGfxBuf + offset, chr, 320, 1, _charsetGfxBuf);
offset += _charWidthTable[chr];
++count;
void TuckerEngine::drawItemString(int x, int num, const uint8 *str) {
int pos = getPositionForLine(num, str);
while (str[pos] != '\n') {
const uint8 chr = str[pos];
Graphics::drawStringChar(_itemsGfxBuf, x, 0, 320, chr, 1, _charsetGfxBuf);
x += _charWidthTable[chr];
++pos;
}
}
void TuckerEngine::drawCreditsString(int x, int y, int num) {
uint8 *dst = _locationBackgroundGfxBuf + y * 640 + x;
int pos = getPositionForLine(num, _ptTextBuf);
while (_ptTextBuf[pos] != '\n') {
const uint8 chr = _ptTextBuf[pos];
Graphics::drawStringChar(dst, chr, 640, 1, _charsetGfxBuf);
dst += _charWidthTable[chr];
Graphics::drawStringChar(_locationBackgroundGfxBuf, x, y, 640, chr, 1, _charsetGfxBuf);
x += _charWidthTable[chr];
++pos;
}
}
@ -3752,7 +3750,7 @@ void TuckerEngine::drawSpeechText(int xStart, int y, const uint8 *dataPtr, int n
if (_conversationOptionsCount != 0) {
xPos = xStart + _scrollOffset;
yPos = i * 10 + y;
_panelItemWidth = count;
_conversationOptionLinesCount = count;
} else {
yPos = y - (count - i) * 10;
}
@ -3784,9 +3782,9 @@ int TuckerEngine::splitSpeechTextLines(const uint8 *dataPtr, int pos, int x, int
}
void TuckerEngine::drawSpeechTextLine(const uint8 *dataPtr, int pos, int count, int x, int y, uint8 color) {
int xStart = x;
const int xStart = x;
for (int i = 0; i < count && dataPtr[pos] != '\n'; ++i) {
Graphics::drawStringChar(_locationBackgroundGfxBuf + y * 640 + x, dataPtr[pos], 640, color, _charsetGfxBuf);
Graphics::drawStringChar(_locationBackgroundGfxBuf, x, y, 640, dataPtr[pos], color, _charsetGfxBuf);
x += _charWidthTable[dataPtr[pos]];
++pos;
}

View File

@ -338,8 +338,8 @@ protected:
void updateSprites();
void updateSprite(int i);
void drawStringInteger(int num, int x, int y, int digits);
void drawStringAlt(int offset, int color, const uint8 *str, int strLen = -1);
void drawItemString(int offset, int num, const uint8 *str);
void drawStringAlt(int x, int y, int color, const uint8 *str, int strLen = -1);
void drawItemString(int x, int num, const uint8 *str);
void drawCreditsString(int x, int y, int num);
void updateCharSpeechSound(bool displayText);
void updateItemsGfxColors(int bit0, int bit7);
@ -672,7 +672,7 @@ protected:
int _conversationOptionsCount;
bool _fadedPanel;
int _panelLockedFlag;
int _panelItemWidth;
int _conversationOptionLinesCount;
int _inventoryItemsState[50];
int _inventoryObjectsList[40];
int _inventoryObjectsOffset;