Fork of LCD-Window which works with Enhanced TextLCD from Wim
Fork of LcdWindow by
Diff: terminal.cpp
- Revision:
- 2:5ac5bab7daaf
- Parent:
- 1:65f72ed914fa
- Child:
- 3:e5d5e2fe4bf6
diff -r 65f72ed914fa -r 5ac5bab7daaf terminal.cpp --- a/terminal.cpp Tue Nov 16 20:49:18 2010 +0000 +++ b/terminal.cpp Sat Nov 27 22:54:13 2010 +0000 @@ -1,17 +1,17 @@ /* * mbed LCDWindow library * Copyright (c) 2010 Hendrik Lipka -* +* * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: -* +* * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. -* +* * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,51 +26,60 @@ Terminal::Terminal(Window* window) { _window=window; - _height=window->getHeight(); - _width=window->getWidth(); - _lines=new char*[_height]; - for (int i=0;i<_height;i++) { - _lines[i]=createLine(); - } + _columns=window->getColumns(); + _rows=window->getRows(); + _lineBuffer=new char*[_rows]; + clear(); } -char* Terminal::createLine() -{ - char* text=new char[_width+1]; - memset(text,32,_width); - text[_width]=0; +char* Terminal::createLine() { + char* text=new char[_columns+1]; + memset(text,32,_columns); + text[_columns]=0; return text; } -void Terminal::writeText(const unsigned int line, const unsigned int pos, const char text[]) { - _window->writeText(line,pos,text); - int min=pos+strlen(text); - if (min>_width) - min=_width; - for (int i=pos;i<min;i++) { - _lines[line][i]=text[i-pos]; // copy text into proper line +void Terminal::character(int column, int row, int c) { + if (column>_columns || row > _rows) { + return; + } + _lineBuffer[row][column]=c; + _window->character(column,row,c); + +} + +void Terminal::writeText(const unsigned int column, const unsigned int row, const char text[]) { + _window->writeText(column,row,text); + int min=column+strlen(text); + if (min>_columns) + min=_columns; + for (int i=column;i<min;i++) { + _lineBuffer[row][i]=text[i-column]; // copy text into proper line } } void Terminal::addText(const char text[]) { - delete [] _lines[0]; - for (int i=0;i<_height-1;i++) { - _lines[i]=_lines[i+1]; + delete [] _lineBuffer[0]; + for (int i=0;i<_rows-1;i++) { + _lineBuffer[i]=_lineBuffer[i+1]; } - _lines[_height-1]=createLine(); - memset(_lines[_height-1],32,_width); + _lineBuffer[_rows-1]=createLine(); + memset(_lineBuffer[_rows-1],32,_columns); int min=strlen(text); - if (min>_width) - min=_width; + if (min>_columns) + min=_columns; for (int i=0;i<min;i++) { - _lines[_height-1][i]=text[i]; // copy text into proper line + _lineBuffer[_rows-1][i]=text[i]; // copy text into proper line } - clear(); - for (int i=0;i<_height;i++) { - _window->writeText(i,0,_lines[i]); + _window->clear(); + for (int i=0;i<_rows;i++) { + _window->writeText(0,i,_lineBuffer[i]); } } void Terminal::clear() { + for (int i=0;i<_rows;i++) { + _lineBuffer[i]=createLine(); + } _window->clear(); }