diff --git a/cpp/Screen.cpp b/cpp/Screen.cpp index d6f8648..1c007e9 100644 --- a/cpp/Screen.cpp +++ b/cpp/Screen.cpp @@ -137,29 +137,7 @@ void Screen::putc(TextPort *textPort, uint8_t c) -void Screen::tabTo(TextPort *textPort, unsigned xPos) -{ - if (!textPort) textPort = &_port; - - CharInfo clear(' ', _flag); - iPoint cursor = textPort->absoluteCursor(); - - xPos = std::min((int)xPos, textPort->frame.width() - 1); - - _updates.push_back(cursor); - - for (unsigned x = textPort->cursor.x; x < xPos; ++x) - { - - _screen[cursor.y][x + textPort->frame.minX()] = clear; - } - - textPort->cursor.x = xPos; - if (textPort != &_port) _port.cursor = textPort->absoluteCursor(); - _updates.push_back(_port.cursor); - -} #pragma mark - diff --git a/cpp/Screen.h b/cpp/Screen.h index 4b73c18..4f2dc89 100644 --- a/cpp/Screen.h +++ b/cpp/Screen.h @@ -46,7 +46,6 @@ typedef struct TextPort { MarginBehavior rightMargin; bool advanceCursor; - //bool lineFeed; bool scroll; // clamp setCursor calls. @@ -176,6 +175,9 @@ public: void insertLine(TextPort *textPort, int line); void deleteLine(TextPort *textPort, int line); + void insertc(TextPort *textPort, uint8_t c); + void deletec(TextPort *textPort); + void beginUpdate(); iRect endUpdate(); @@ -184,7 +186,7 @@ public: void lock(); void unlock(); - + void setTextPort(const TextPort& textPort); virtual void setSize(unsigned width, unsigned height); virtual void setCursorType(CursorType cursor); diff --git a/cpp/Screen_TextPort.cpp b/cpp/Screen_TextPort.cpp index 153f3bf..cce2d7c 100644 --- a/cpp/Screen_TextPort.cpp +++ b/cpp/Screen_TextPort.cpp @@ -7,3 +7,118 @@ // #include "Screen.h" + + + +void Screen::setTextPort(const TextPort& textPort) +{ + TextPort tmp(textPort); + + // call virtual method... + setSize(textPort.frame.width(), textPort.frame.height()); + + tmp.frame.origin = iPoint(0, 0); + _port = tmp; +} + +/* + * Non-destructive tab. + * Sets the horizontal cursor position, may wrap and scroll + * + * + */ +void Screen::tabTo(TextPort *textPort, unsigned xPos) +{ + + if (!textPort) textPort = &_port; + + iRect frame = textPort->frame; + + // best case -- no wrapping needed. + if (xPos < frame.width()) + { + textPort->cursor.x = xPos; + + } + else if (textPort->rightMargin == TextPort::MarginWrap) + { + // worst case -- wrapping needed. + textPort->cursor.x = 0; + incrementY(textPort); + + if (textPort != &_port) _port.cursor = textPort->absoluteCursor(); + + return; + } + else + { + // clamp to right margin. + textPort->cursor.x = frame.width() - 1; + } + + if (textPort != &_port) _port.cursor = textPort->absoluteCursor(); + + return; +} + +// insert a character at the current cursor position, +// moving all characters right 1. +// no wrapping is performed. +void Screen::insertc(TextPort *textPort, uint8_t c) +{ + if (!textPort) textPort = &_port; + + iRect frame = textPort->frame; + iPoint cursor = textPort->cursor; + iPoint absoluteCursor = textPort->absoluteCursor(); + + if (cursor.x >= frame.width()) return; + if (cursor.y >= frame.height()) return; + + CharInfoIterator iter = _screen[absoluteCursor.y].begin(); + CharInfoIterator begin = iter + absoluteCursor.x; + CharInfoIterator end = iter + frame.maxX(); + + CharInfo ci(c, _flag); + // move all chars forward 1. + for (iter = begin; iter < end; ++iter) + { + std::swap(ci, *iter); + } + + _updates.push_back(absoluteCursor); + _updates.push_back(iPoint(frame.maxX(), absoluteCursor.y)); +} + +// delete the character at the current cursor position, +// moving any character to the right left 1 spot +// the final position is blank filled. +// no wrapping is performed. +void Screen::deletec(TextPort *textPort) +{ + if (!textPort) textPort = &_port; + + iRect frame = textPort->frame; + iPoint cursor = textPort->cursor; + iPoint absoluteCursor = textPort->absoluteCursor(); + + if (cursor.x >= frame.width()) return; + if (cursor.y >= frame.height()) return; + + CharInfoIterator iter = _screen[absoluteCursor.y].begin(); + CharInfoIterator begin = iter + absoluteCursor.x; + CharInfoIterator end = iter + frame.maxX() - 1; + + + for (iter = begin; iter < end; ++iter) + { + iter[0] = iter[1]; + + } + + // not sure about the flag situation... + *iter = CharInfo(' ', _flag); + + _updates.push_back(absoluteCursor); + _updates.push_back(iPoint(frame.maxX(), absoluteCursor.y)); +} \ No newline at end of file