aboutsummaryrefslogtreecommitdiff
path: root/engines/adl/display.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/adl/display.cpp')
-rw-r--r--engines/adl/display.cpp178
1 files changed, 45 insertions, 133 deletions
diff --git a/engines/adl/display.cpp b/engines/adl/display.cpp
index ffb98c4a1b..a6d94f6e13 100644
--- a/engines/adl/display.cpp
+++ b/engines/adl/display.cpp
@@ -71,7 +71,8 @@ static byte font[64][5] = {
Display::Display() :
_scanlines(false),
_cursorPos(0),
- _mode(kModeText) {
+ _mode(kModeText),
+ _showCursor(false) {
_frameBuf = new byte[kFrameBufSize];
_frameBufSurface = new Graphics::Surface;
_frameBufSurface->create(kWidth * 2, kHeight * 2, Graphics::PixelFormat::createFormatCLUT8());
@@ -367,8 +368,12 @@ void Display::clear(byte color) {
void Display::updateTextSurface() {
for (uint row = 0; row < 24; ++row)
for (uint col = 0; col < 40; ++col) {
+ int charPos = row * 40 + col;
char c = _textBuf[row * 40 + col];
+ if (charPos == _cursorPos && _showCursor)
+ c = (c & 0x3f) | 0x40;
+
Common::Rect r(7 * 2, 8 * 2);
r.translate(((c & 0x3f) % 16) * 7 * 2, (c & 0x3f) / 16 * 8 * 2);
@@ -381,36 +386,6 @@ void Display::updateTextSurface() {
}
}
-void Display::printString(const Common::String &str) {
- Common::String::const_iterator it;
- for (it = str.begin(); it != str.end(); ++it) {
- byte b = *it;
-
- if (b == ('\r' | 0x80))
- _cursorPos = (_cursorPos / 40 + 1) * 40;
- else if (b < 0x80 || b >= 0xa0)
- _textBuf[_cursorPos++] = b;
-
- if (_cursorPos == kTextBufSize) {
- memmove(_textBuf, _textBuf + 40, kTextBufSize - 40);
- memset(_textBuf + kTextBufSize - 40, ' ' | 0x80, 40);
- _cursorPos -= 40;
- }
- }
-
- updateTextSurface();
-}
-
-void Display::printASCIIString(const Common::String &str) {
- Common::String aStr;
-
- Common::String::const_iterator it;
- for (it = str.begin(); it != str.end(); ++it)
- aStr += APPLECHAR(*it);
-
- printString(aStr);
-}
-
void Display::drawChar(byte c, int x, int y) {
byte *buf = (byte *)_font->getPixels() + y * _font->pitch + x;
@@ -463,126 +438,63 @@ void Display::updateScreen() {
}
}
-Common::String Display::inputString(byte prompt) {
- Common::String s;
-
- if (prompt > 0)
- printString(Common::String(prompt));
-
- while (1) {
- byte b = inputKey();
-
- if (g_engine->shouldQuit())
- return 0;
-
- if (b == 0)
- continue;
-
- if (b == ('\r' | 0x80)) {
- s += b;
- printString(Common::String(b));
- return s;
- }
-
- if (b < 0xa0) {
- switch (b) {
- case Common::KEYCODE_BACKSPACE | 0x80:
- if (!s.empty()) {
- --_cursorPos;
- _textBuf[_cursorPos] = ' ' | 0x80;
- s.deleteLastChar();
- }
- break;
- };
- } else {
- s += b;
- printString(Common::String(b));
- }
- }
+void Display::home() {
+ memset(_textBuf, APPLECHAR(' '), kTextBufSize);
+ _cursorPos = 0;
}
-byte Display::convertKey(uint16 ascii) {
- ascii = toupper(ascii);
-
- if (ascii >= 0x80)
- return 0;
+void Display::moveCursorForward() {
+ ++_cursorPos;
- ascii |= 0x80;
+ if (_cursorPos >= kTextBufSize)
+ scrollUp();
+}
- if (ascii >= 0x80 && ascii <= 0xe0)
- return ascii;
+void Display::moveCursorBackward() {
+ --_cursorPos;
- return 0;
+ if (_cursorPos < 0)
+ _cursorPos = 0;
}
-byte Display::inputKey() {
- Common::EventManager *ev = g_system->getEventManager();
+void Display::moveCursorTo(const Common::Point &pos) {
+ _cursorPos = pos.y * 40 + pos.x;
- byte orgChar = _textBuf[_cursorPos];
- _textBuf[_cursorPos] = (orgChar & 0x3f) | 0x40;
+ if (_cursorPos >= kTextBufSize)
+ error("Cursor position (%i, %i) out of bounds", pos.x, pos.y);
+}
- byte key = 0;
+void Display::setCharAtCursor(byte c) {
+ _textBuf[_cursorPos] = c;
+}
- while (!g_engine->shouldQuit() && key == 0) {
- Common::Event event;
- if (ev->pollEvent(event)) {
- if (event.type != Common::EVENT_KEYDOWN)
- continue;
+void Display::scrollUp() {
+ memmove(_textBuf, _textBuf + 40, kTextBufSize - 40);
+ memset(_textBuf + kTextBufSize - 40, ' ' | 0x80, 40);
+ _cursorPos -= 40;
+}
- if (event.kbd.flags & Common::KBD_CTRL) {
- if (event.kbd.keycode == Common::KEYCODE_q)
- g_engine->quitGame();
- continue;
- }
+void Display::printString(const Common::String &str) {
+ Common::String::const_iterator c;
+ for (c = str.begin(); c != str.end(); ++c) {
+ byte b = *c;
- switch (event.kbd.keycode) {
- case Common::KEYCODE_BACKSPACE:
- case Common::KEYCODE_RETURN:
- key = convertKey(event.kbd.keycode);
- break;
- default:
- if (event.kbd.ascii >= 0x20 && event.kbd.ascii < 0x80)
- key = convertKey(event.kbd.ascii);
- };
+ if (*c == APPLECHAR('\r'))
+ _cursorPos = (_cursorPos / 40 + 1) * 40;
+ else if (b < 0x80 || b >= 0xa0) {
+ setCharAtCursor(b);
+ ++_cursorPos;
}
- updateTextSurface();
- updateScreen();
- g_system->updateScreen();
- g_system->delayMillis(16);
+ if (_cursorPos == kTextBufSize)
+ scrollUp();
}
- _textBuf[_cursorPos] = orgChar;
- return key;
-}
-
-void Display::delay(uint32 ms) {
- Common::EventManager *ev = g_system->getEventManager();
-
- uint32 start = g_system->getMillis();
-
- while (!g_engine->shouldQuit() && g_system->getMillis() - start < ms) {
- Common::Event event;
- if (ev->pollEvent(event)) {
- if (event.type == Common::EVENT_KEYDOWN && (event.kbd.flags & Common::KBD_CTRL)) {
- switch(event.kbd.keycode) {
- case Common::KEYCODE_q:
- g_engine->quitGame();
- break;
- default:
- break;
- }
- }
- }
- updateScreen();
- g_system->updateScreen();
- g_system->delayMillis(16);
- }
+ updateTextSurface();
}
-void Display::home() {
- memset(_textBuf, ' ' | 0x80, kTextBufSize);
- _cursorPos = 0;
+void Display::showCursor(bool enable) {
+ _showCursor = enable;
}
void Display::setCursorPos(Common::Point pos) {