[Scummvm-cvs-logs] CVS: scummvm/gui console.cpp,1.1,1.2 console.h,1.1,1.2
Max Horn
fingolfin at users.sourceforge.net
Sat Dec 14 07:46:02 CET 2002
Update of /cvsroot/scummvm/scummvm/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv19598/gui
Modified Files:
console.cpp console.h
Log Message:
some more console code
Index: console.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- console.cpp 14 Dec 2002 14:31:44 -0000 1.1
+++ console.cpp 14 Dec 2002 15:45:45 -0000 1.2
@@ -56,6 +56,9 @@
_currentColumn = 0;
_currentLine = 0;
_scrollLine = 0;
+
+ print("ScummVM "SCUMMVM_VERSION" (" SCUMMVM_CVS ")\n");
+ print("Console is ready\n");
}
void ConsoleDialog::drawDialog()
@@ -70,10 +73,12 @@
// Draw text
int start = _scrollLine - _linesPerPage + 1;
int y = _y + 1;
+ if (start < 0)
+ start = 0;
for (int line = 0; line < _linesPerPage; line++) {
int x = _x + 1;
for (int column = 0; column < _lineWidth; column++) {
- int l = (start+line+_linesInBuffer) % _linesInBuffer;
+ int l = (start+line) % _linesInBuffer;
byte c = _buffer[l * _lineWidth + column];
_gui->drawChar(c, x, y, _gui->_textcolor);
x += kCharWidth;
@@ -88,8 +93,60 @@
{
_currentColumn = 0;
if (_currentLine == _scrollLine)
- _scrollLine = (_scrollLine + 1) % _linesInBuffer;
- _currentLine = (_currentLine + 1) % _linesInBuffer;
+ _scrollLine++;
+ _currentLine++;
+}
+
+int ConsoleDialog::printf(const char *format, ...)
+{
+ va_list argptr;
+
+ va_start(argptr, format);
+ int count = this->vprintf(format, argptr);
+ va_end (argptr);
+ return count;
+}
+
+int ConsoleDialog::vprintf(const char *format, va_list argptr)
+{
+ char buf[2048];
+
+ int count = vsnprintf(buf, sizeof(buf), format, argptr);
+ print(buf);
+ return count;
+}
+
+void ConsoleDialog::putchar(int c)
+{
+ if (c == '\n')
+ nextLine();
+ else {
+ int pos = (_currentLine % _linesInBuffer) * _lineWidth + _currentColumn;
+ _buffer[pos] = (char)c;
+ _currentColumn++;
+ if (_currentColumn >= _lineWidth)
+ nextLine();
+ }
+ draw(); // FIXME - not nice to redraw the full console just for one char!
+}
+
+void ConsoleDialog::print(const char *str)
+{
+ int pos = (_currentLine % _linesInBuffer) * _lineWidth + _currentColumn;
+ while (*str) {
+ if (*str == '\n') {
+ nextLine();
+ pos += _lineWidth - _currentColumn;
+ } else {
+ _buffer[pos++] = *str;
+ _currentColumn++;
+ if (_currentColumn >= _lineWidth)
+ nextLine();
+ }
+ pos %= kBufferSize;
+ str++;
+ }
+ draw();
}
void ConsoleDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers) {
@@ -101,20 +158,14 @@
} else if (keycode == 8) { // Backspace
if (_currentColumn == 0) {
_currentColumn = _lineWidth - 1;
- _currentLine--;
- if (_currentLine < 0)
- _currentLine = _linesInBuffer - 1;
+ if (_currentLine > 0)
+ _currentLine--;
} else
_currentColumn--;
- _buffer[_currentLine * _lineWidth + _currentColumn] = ' ';
+ _buffer[(_currentLine % _linesInBuffer) * _lineWidth + _currentColumn] = ' ';
draw(); // FIXME - not nice to redraw the full console just for one char!
} else if ((ascii >= 31) && (ascii <= 122)) { // Printable ASCII, add to string
- _buffer[_currentLine * _lineWidth + _currentColumn] = (char)ascii;
- _currentColumn++;
- if (_currentColumn >= _lineWidth) {
- nextLine();
- }
- draw(); // FIXME - not nice to redraw the full console just for one char!
+ putchar(ascii);
} else {
debug(2, "Unhandled keycode from ConsoleDialog: %d\n", keycode);
}
Index: console.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/console.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- console.h 14 Dec 2002 14:31:44 -0000 1.1
+++ console.h 14 Dec 2002 15:45:45 -0000 1.2
@@ -25,6 +25,7 @@
#include "common/str.h"
#include "common/list.h"
+#include <stdarg.h>
enum {
kBufferSize = 32768,
@@ -55,12 +56,13 @@
virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers);
// void handleCommand(CommandSender *sender, uint32 cmd, uint32 data);
- //printf(const char *format, ...)
- //vprintf(
-// void printString(const String &str);
-// const String &readString();
+ int printf(const char *format, ...);
+ int vprintf(const char *format, va_list argptr);
+#undef putchar
+ void putchar(int c);
protected:
+ void print(const char *str);
void nextLine();
};
More information about the Scummvm-git-logs
mailing list