mirror of
https://github.com/ksherlock/TwoTerm.git
synced 2024-11-04 17:04:48 +00:00
tabTo, insertc, deletec for TextPort.
git-svn-id: svn://qnap.local/TwoTerm/trunk@2023 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
parent
01d1a214c1
commit
272ad2a166
@ -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 -
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
Loading…
Reference in New Issue
Block a user