Fork of LCD-Window which works with Enhanced TextLCD from Wim
Fork of LcdWindow by
terminal.cpp
00001 /* 00002 * mbed LCDWindow library 00003 * Copyright (c) 2010 Hendrik Lipka 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 */ 00023 00024 #include "terminal.h" 00025 #include "string.h" 00026 00027 Terminal::Terminal (Window* window):Window() 00028 { 00029 _window=window; 00030 _columns=window->getColumns (); 00031 _rows=window->getRows (); 00032 _lineBuffer=new char*[_rows]; 00033 _enabled = true; 00034 clear(); 00035 } 00036 00037 char* Terminal::createLine() 00038 { 00039 char* text=new char[_columns+1]; 00040 memset(text,32,_columns); 00041 text[_columns]=0; 00042 return text; 00043 } 00044 00045 void Terminal::character(int column, int row, int c) 00046 { 00047 if (column>_columns || row > _rows) { 00048 return; 00049 } 00050 _lineBuffer[row][column]=c; 00051 if (_enabled) { 00052 _window->character(column,row,c); 00053 } 00054 00055 } 00056 00057 void Terminal::writeText(const unsigned int column, const unsigned int row, const char text[]) 00058 { 00059 if (_enabled) { 00060 _window->writeText(column,row,text); 00061 } 00062 int min=column+strlen(text); 00063 if (min>_columns) 00064 min=_columns; 00065 for (int i=column; i<min; i++) { 00066 _lineBuffer[row][i]=text[i-column]; // copy text into proper line 00067 } 00068 } 00069 00070 void Terminal::addText(const char text[]) 00071 { 00072 delete [] _lineBuffer[0]; 00073 for (int i=0; i<_rows-1; i++) { 00074 _lineBuffer[i]=_lineBuffer[i+1]; 00075 } 00076 _lineBuffer[_rows-1]=createLine(); 00077 memset(_lineBuffer[_rows-1],32,_columns); 00078 int min=strlen(text); 00079 if (min>_columns) 00080 min=_columns; 00081 for (int i=0; i<min; i++) { 00082 _lineBuffer[_rows-1][i]=text[i]; // copy text into proper line 00083 } 00084 if (_enabled) { 00085 _window->clear(); 00086 for (int i=0; i<_rows; i++) { 00087 _window->writeText(0,i,_lineBuffer[i]); 00088 } 00089 } 00090 // text longer than line? 00091 if (strlen(text) > _columns) { 00092 // add the remaining text to the next Line 00093 this->addText(text + _columns); 00094 } 00095 } 00096 00097 void Terminal::clear() 00098 { 00099 for (int i=0; i<_rows; i++) { 00100 _lineBuffer[i]=createLine(); 00101 } 00102 if (_enabled) { 00103 _window->clear(); 00104 } 00105 } 00106 00107 void Terminal::disableDisplay() 00108 { 00109 if (_enabled) { 00110 _enabled = false; 00111 _window->clear(); 00112 } 00113 } 00114 00115 void Terminal::enableDisplay() 00116 { 00117 if (! _enabled) { 00118 _enabled = true; 00119 _window->clear(); 00120 //Display the buffer-content 00121 for (int i=0; i<_rows; i++) { 00122 _window->writeText(0,i,_lineBuffer[i]); 00123 } 00124 } 00125 }
Generated on Tue Jul 12 2022 20:32:52 by
1.7.2
