UniGraphics Library Fork to support mbed os 6.3 Release for ILI9341
Dependents: TFT_ILI9341_UniGraphic TFT_ILI9341_os6
Graphics/TextDisplay.cpp@2:59188908eb60, 2020-10-08 (annotated)
- Committer:
- amouroug
- Date:
- Thu Oct 08 18:11:03 2020 -0500
- Revision:
- 2:59188908eb60
- Parent:
- 0:bb2bda4f5846
Added GraphicsDisplay GFX API to draw triangle.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
amouroug | 0:bb2bda4f5846 | 1 | /* mbed TextDisplay Display Library Base Class |
amouroug | 0:bb2bda4f5846 | 2 | * Copyright (c) 2007-2009 sford |
amouroug | 0:bb2bda4f5846 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
amouroug | 0:bb2bda4f5846 | 4 | */ |
amouroug | 0:bb2bda4f5846 | 5 | |
amouroug | 0:bb2bda4f5846 | 6 | #include "TextDisplay.h" |
amouroug | 0:bb2bda4f5846 | 7 | |
amouroug | 0:bb2bda4f5846 | 8 | TextDisplay::TextDisplay(const char *name) : Stream(name){ |
amouroug | 0:bb2bda4f5846 | 9 | _row = 0; |
amouroug | 0:bb2bda4f5846 | 10 | _column = 0; |
amouroug | 0:bb2bda4f5846 | 11 | if (name == NULL) { |
amouroug | 0:bb2bda4f5846 | 12 | _path = NULL; |
amouroug | 0:bb2bda4f5846 | 13 | } else { |
amouroug | 0:bb2bda4f5846 | 14 | _path = new char[strlen(name) + 2]; |
amouroug | 0:bb2bda4f5846 | 15 | sprintf(_path, "/%s", name); |
amouroug | 0:bb2bda4f5846 | 16 | } |
amouroug | 0:bb2bda4f5846 | 17 | } |
amouroug | 0:bb2bda4f5846 | 18 | |
amouroug | 0:bb2bda4f5846 | 19 | int TextDisplay::_putc(int value) { |
amouroug | 0:bb2bda4f5846 | 20 | if(value == '\n') { |
amouroug | 0:bb2bda4f5846 | 21 | _column = 0; |
amouroug | 0:bb2bda4f5846 | 22 | _row++; |
amouroug | 0:bb2bda4f5846 | 23 | if(_row >= rows()) { |
amouroug | 0:bb2bda4f5846 | 24 | _row = 0; |
amouroug | 0:bb2bda4f5846 | 25 | } |
amouroug | 0:bb2bda4f5846 | 26 | } else { |
amouroug | 0:bb2bda4f5846 | 27 | character(_column, _row, value); |
amouroug | 0:bb2bda4f5846 | 28 | _column++; |
amouroug | 0:bb2bda4f5846 | 29 | if(_column >= columns()) { |
amouroug | 0:bb2bda4f5846 | 30 | _column = 0; |
amouroug | 0:bb2bda4f5846 | 31 | _row++; |
amouroug | 0:bb2bda4f5846 | 32 | if(_row >= rows()) { |
amouroug | 0:bb2bda4f5846 | 33 | _row = 0; |
amouroug | 0:bb2bda4f5846 | 34 | } |
amouroug | 0:bb2bda4f5846 | 35 | } |
amouroug | 0:bb2bda4f5846 | 36 | } |
amouroug | 0:bb2bda4f5846 | 37 | return value; |
amouroug | 0:bb2bda4f5846 | 38 | } |
amouroug | 0:bb2bda4f5846 | 39 | |
amouroug | 0:bb2bda4f5846 | 40 | // crude cls implementation, should generally be overwritten in derived class |
amouroug | 0:bb2bda4f5846 | 41 | void TextDisplay::cls() { |
amouroug | 0:bb2bda4f5846 | 42 | locate(0, 0); |
amouroug | 0:bb2bda4f5846 | 43 | for(int i=0; i<columns()*rows(); i++) { |
amouroug | 0:bb2bda4f5846 | 44 | putc(' '); |
amouroug | 0:bb2bda4f5846 | 45 | } |
amouroug | 0:bb2bda4f5846 | 46 | } |
amouroug | 0:bb2bda4f5846 | 47 | |
amouroug | 0:bb2bda4f5846 | 48 | void TextDisplay::locate(int column, int row) { |
amouroug | 0:bb2bda4f5846 | 49 | _column = column; |
amouroug | 0:bb2bda4f5846 | 50 | _row = row; |
amouroug | 0:bb2bda4f5846 | 51 | } |
amouroug | 0:bb2bda4f5846 | 52 | |
amouroug | 0:bb2bda4f5846 | 53 | int TextDisplay::_getc() { |
amouroug | 0:bb2bda4f5846 | 54 | return -1; |
amouroug | 0:bb2bda4f5846 | 55 | } |
amouroug | 0:bb2bda4f5846 | 56 | |
amouroug | 0:bb2bda4f5846 | 57 | void TextDisplay::foreground(uint16_t colour) { |
amouroug | 0:bb2bda4f5846 | 58 | _foreground = colour; |
amouroug | 0:bb2bda4f5846 | 59 | } |
amouroug | 0:bb2bda4f5846 | 60 | |
amouroug | 0:bb2bda4f5846 | 61 | void TextDisplay::background(uint16_t colour) { |
amouroug | 0:bb2bda4f5846 | 62 | _background = colour; |
amouroug | 0:bb2bda4f5846 | 63 | } |
amouroug | 0:bb2bda4f5846 | 64 | |
amouroug | 0:bb2bda4f5846 | 65 | bool TextDisplay::claim (FILE *stream) { |
amouroug | 0:bb2bda4f5846 | 66 | if ( _path == NULL) { |
amouroug | 0:bb2bda4f5846 | 67 | fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n"); |
amouroug | 0:bb2bda4f5846 | 68 | return false; |
amouroug | 0:bb2bda4f5846 | 69 | } |
amouroug | 0:bb2bda4f5846 | 70 | if (freopen(_path, "w", stream) == NULL) { |
amouroug | 0:bb2bda4f5846 | 71 | // Failed, should not happen |
amouroug | 0:bb2bda4f5846 | 72 | return false; |
amouroug | 0:bb2bda4f5846 | 73 | } |
amouroug | 0:bb2bda4f5846 | 74 | // make sure we use line buffering |
amouroug | 0:bb2bda4f5846 | 75 | setvbuf(stdout, NULL, _IOLBF, columns()); |
amouroug | 0:bb2bda4f5846 | 76 | return true; |
amouroug | 0:bb2bda4f5846 | 77 | } |