mbed-os
Fork of mbed-os by
features/unsupported/tests/mbed/freopen/TextDisplay.cpp@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | /* mbed TextDisplay Display Library Base Class |
elessair | 0:f269e3021894 | 2 | * Copyright (c) 2007-2009 sford |
elessair | 0:f269e3021894 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
elessair | 0:f269e3021894 | 4 | */ |
elessair | 0:f269e3021894 | 5 | |
elessair | 0:f269e3021894 | 6 | #include "TextDisplay.h" |
elessair | 0:f269e3021894 | 7 | |
elessair | 0:f269e3021894 | 8 | TextDisplay::TextDisplay(const char *name) : Stream(name) { |
elessair | 0:f269e3021894 | 9 | _row = 0; |
elessair | 0:f269e3021894 | 10 | _column = 0; |
elessair | 0:f269e3021894 | 11 | } |
elessair | 0:f269e3021894 | 12 | |
elessair | 0:f269e3021894 | 13 | int TextDisplay::_putc(int value) { |
elessair | 0:f269e3021894 | 14 | if(value == '\n') { |
elessair | 0:f269e3021894 | 15 | _column = 0; |
elessair | 0:f269e3021894 | 16 | _row++; |
elessair | 0:f269e3021894 | 17 | if(_row >= rows()) { |
elessair | 0:f269e3021894 | 18 | _row = 0; |
elessair | 0:f269e3021894 | 19 | } |
elessair | 0:f269e3021894 | 20 | } else { |
elessair | 0:f269e3021894 | 21 | character(_column, _row, value); |
elessair | 0:f269e3021894 | 22 | _column++; |
elessair | 0:f269e3021894 | 23 | if(_column >= columns()) { |
elessair | 0:f269e3021894 | 24 | _column = 0; |
elessair | 0:f269e3021894 | 25 | _row++; |
elessair | 0:f269e3021894 | 26 | if(_row >= rows()) { |
elessair | 0:f269e3021894 | 27 | _row = 0; |
elessair | 0:f269e3021894 | 28 | } |
elessair | 0:f269e3021894 | 29 | } |
elessair | 0:f269e3021894 | 30 | } |
elessair | 0:f269e3021894 | 31 | return value; |
elessair | 0:f269e3021894 | 32 | } |
elessair | 0:f269e3021894 | 33 | |
elessair | 0:f269e3021894 | 34 | // crude cls implementation, should generally be overwritten in derived class |
elessair | 0:f269e3021894 | 35 | void TextDisplay::cls() { |
elessair | 0:f269e3021894 | 36 | locate(0, 0); |
elessair | 0:f269e3021894 | 37 | for(int i=0; i<columns()*rows(); i++) { |
elessair | 0:f269e3021894 | 38 | putc(' '); |
elessair | 0:f269e3021894 | 39 | } |
elessair | 0:f269e3021894 | 40 | } |
elessair | 0:f269e3021894 | 41 | |
elessair | 0:f269e3021894 | 42 | void TextDisplay::locate(int column, int row) { |
elessair | 0:f269e3021894 | 43 | _column = column; |
elessair | 0:f269e3021894 | 44 | _row = row; |
elessair | 0:f269e3021894 | 45 | } |
elessair | 0:f269e3021894 | 46 | |
elessair | 0:f269e3021894 | 47 | int TextDisplay::_getc() { |
elessair | 0:f269e3021894 | 48 | return -1; |
elessair | 0:f269e3021894 | 49 | } |
elessair | 0:f269e3021894 | 50 | |
elessair | 0:f269e3021894 | 51 | void TextDisplay::foreground(int colour) { |
elessair | 0:f269e3021894 | 52 | _foreground = colour; |
elessair | 0:f269e3021894 | 53 | } |
elessair | 0:f269e3021894 | 54 | |
elessair | 0:f269e3021894 | 55 | void TextDisplay::background(int colour) { |
elessair | 0:f269e3021894 | 56 | _background = colour; |
elessair | 0:f269e3021894 | 57 | } |