Marcel Visser
/
DisplayBRW
brw1
RA8875/TextDisplay.h@0:a115ff47d1c1, 2015-11-30 (annotated)
- Committer:
- reiniermarcel
- Date:
- Mon Nov 30 11:13:18 2015 +0000
- Revision:
- 0:a115ff47d1c1
ok
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
reiniermarcel | 0:a115ff47d1c1 | 1 | /* mbed TextDisplay Library Base Class |
reiniermarcel | 0:a115ff47d1c1 | 2 | * Copyright (c) 2007-2009 sford |
reiniermarcel | 0:a115ff47d1c1 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
reiniermarcel | 0:a115ff47d1c1 | 4 | * |
reiniermarcel | 0:a115ff47d1c1 | 5 | * A common base class for Text displays |
reiniermarcel | 0:a115ff47d1c1 | 6 | * To port a new display, derive from this class and implement |
reiniermarcel | 0:a115ff47d1c1 | 7 | * the constructor (setup the display), character (put a character |
reiniermarcel | 0:a115ff47d1c1 | 8 | * at a location), rows and columns (number of rows/cols) functions. |
reiniermarcel | 0:a115ff47d1c1 | 9 | * Everything else (locate, printf, putc, cls) will come for free |
reiniermarcel | 0:a115ff47d1c1 | 10 | * |
reiniermarcel | 0:a115ff47d1c1 | 11 | * The model is the display will wrap at the right and bottom, so you can |
reiniermarcel | 0:a115ff47d1c1 | 12 | * keep writing and will always get valid characters. The location is |
reiniermarcel | 0:a115ff47d1c1 | 13 | * maintained internally to the class to make this easy |
reiniermarcel | 0:a115ff47d1c1 | 14 | */ |
reiniermarcel | 0:a115ff47d1c1 | 15 | |
reiniermarcel | 0:a115ff47d1c1 | 16 | #ifndef MBED_TEXTDISPLAY_H |
reiniermarcel | 0:a115ff47d1c1 | 17 | #define MBED_TEXTDISPLAY_H |
reiniermarcel | 0:a115ff47d1c1 | 18 | |
reiniermarcel | 0:a115ff47d1c1 | 19 | #include "mbed.h" |
reiniermarcel | 0:a115ff47d1c1 | 20 | |
reiniermarcel | 0:a115ff47d1c1 | 21 | #include "DisplayDefs.h" |
reiniermarcel | 0:a115ff47d1c1 | 22 | |
reiniermarcel | 0:a115ff47d1c1 | 23 | /// A text display class that supports character based |
reiniermarcel | 0:a115ff47d1c1 | 24 | /// presentation. |
reiniermarcel | 0:a115ff47d1c1 | 25 | /// |
reiniermarcel | 0:a115ff47d1c1 | 26 | class TextDisplay : public Stream |
reiniermarcel | 0:a115ff47d1c1 | 27 | { |
reiniermarcel | 0:a115ff47d1c1 | 28 | public: |
reiniermarcel | 0:a115ff47d1c1 | 29 | |
reiniermarcel | 0:a115ff47d1c1 | 30 | // functions needing implementation in derived implementation class |
reiniermarcel | 0:a115ff47d1c1 | 31 | /// Create a TextDisplay interface |
reiniermarcel | 0:a115ff47d1c1 | 32 | /// |
reiniermarcel | 0:a115ff47d1c1 | 33 | /// @param name The name used in the path to access the display through |
reiniermarcel | 0:a115ff47d1c1 | 34 | /// the stdio stream. |
reiniermarcel | 0:a115ff47d1c1 | 35 | /// |
reiniermarcel | 0:a115ff47d1c1 | 36 | TextDisplay(const char *name = NULL); |
reiniermarcel | 0:a115ff47d1c1 | 37 | |
reiniermarcel | 0:a115ff47d1c1 | 38 | /// output a character at the given position |
reiniermarcel | 0:a115ff47d1c1 | 39 | /// |
reiniermarcel | 0:a115ff47d1c1 | 40 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 41 | /// |
reiniermarcel | 0:a115ff47d1c1 | 42 | /// @param[in] x position in pixels |
reiniermarcel | 0:a115ff47d1c1 | 43 | /// @param[in] y position in pixels |
reiniermarcel | 0:a115ff47d1c1 | 44 | /// @param[in] c the character to be written to the TextDisplay |
reiniermarcel | 0:a115ff47d1c1 | 45 | /// @returns number of pixels to advance the cursor which could be the cell width |
reiniermarcel | 0:a115ff47d1c1 | 46 | /// for non-proportional characters, or the actual character width for |
reiniermarcel | 0:a115ff47d1c1 | 47 | /// proportional characters. |
reiniermarcel | 0:a115ff47d1c1 | 48 | /// |
reiniermarcel | 0:a115ff47d1c1 | 49 | virtual int character(int x, int y, int c) = 0; |
reiniermarcel | 0:a115ff47d1c1 | 50 | |
reiniermarcel | 0:a115ff47d1c1 | 51 | /// return number of rows on TextDisplay |
reiniermarcel | 0:a115ff47d1c1 | 52 | /// |
reiniermarcel | 0:a115ff47d1c1 | 53 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 54 | /// |
reiniermarcel | 0:a115ff47d1c1 | 55 | /// @returns number of text rows for the display for the currently |
reiniermarcel | 0:a115ff47d1c1 | 56 | /// active font. |
reiniermarcel | 0:a115ff47d1c1 | 57 | /// |
reiniermarcel | 0:a115ff47d1c1 | 58 | virtual int rows() = 0; |
reiniermarcel | 0:a115ff47d1c1 | 59 | |
reiniermarcel | 0:a115ff47d1c1 | 60 | /// return number if columns on TextDisplay |
reiniermarcel | 0:a115ff47d1c1 | 61 | /// |
reiniermarcel | 0:a115ff47d1c1 | 62 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 63 | /// |
reiniermarcel | 0:a115ff47d1c1 | 64 | /// @returns number of text rows for the display for the currently |
reiniermarcel | 0:a115ff47d1c1 | 65 | /// active font. |
reiniermarcel | 0:a115ff47d1c1 | 66 | /// |
reiniermarcel | 0:a115ff47d1c1 | 67 | virtual int columns() = 0; |
reiniermarcel | 0:a115ff47d1c1 | 68 | |
reiniermarcel | 0:a115ff47d1c1 | 69 | // functions that come for free, but can be overwritten |
reiniermarcel | 0:a115ff47d1c1 | 70 | |
reiniermarcel | 0:a115ff47d1c1 | 71 | /// redirect output from a stream (stoud, sterr) to display |
reiniermarcel | 0:a115ff47d1c1 | 72 | /// |
reiniermarcel | 0:a115ff47d1c1 | 73 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 74 | /// |
reiniermarcel | 0:a115ff47d1c1 | 75 | /// @param[in] stream that shall be redirected to the TextDisplay |
reiniermarcel | 0:a115ff47d1c1 | 76 | /// @returns true if the claim succeeded. |
reiniermarcel | 0:a115ff47d1c1 | 77 | /// |
reiniermarcel | 0:a115ff47d1c1 | 78 | virtual bool claim (FILE *stream); |
reiniermarcel | 0:a115ff47d1c1 | 79 | |
reiniermarcel | 0:a115ff47d1c1 | 80 | /// clear screen |
reiniermarcel | 0:a115ff47d1c1 | 81 | /// |
reiniermarcel | 0:a115ff47d1c1 | 82 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 83 | /// |
reiniermarcel | 0:a115ff47d1c1 | 84 | /// @param[in] layers is ignored, but supports maintaining the same |
reiniermarcel | 0:a115ff47d1c1 | 85 | /// API for the graphics layer. |
reiniermarcel | 0:a115ff47d1c1 | 86 | /// @returns error code. |
reiniermarcel | 0:a115ff47d1c1 | 87 | /// |
reiniermarcel | 0:a115ff47d1c1 | 88 | virtual RetCode_t cls(uint16_t layers = 0) = 0; |
reiniermarcel | 0:a115ff47d1c1 | 89 | |
reiniermarcel | 0:a115ff47d1c1 | 90 | /// locate the cursor at a character position. |
reiniermarcel | 0:a115ff47d1c1 | 91 | /// |
reiniermarcel | 0:a115ff47d1c1 | 92 | /// Based on the currently active font, locate the cursor on screen. |
reiniermarcel | 0:a115ff47d1c1 | 93 | /// |
reiniermarcel | 0:a115ff47d1c1 | 94 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 95 | /// |
reiniermarcel | 0:a115ff47d1c1 | 96 | /// @param[in] column is the horizontal offset from the left side. |
reiniermarcel | 0:a115ff47d1c1 | 97 | /// @param[in] row is the vertical offset from the top. |
reiniermarcel | 0:a115ff47d1c1 | 98 | /// @returns error code. |
reiniermarcel | 0:a115ff47d1c1 | 99 | /// |
reiniermarcel | 0:a115ff47d1c1 | 100 | virtual RetCode_t locate(textloc_t column, textloc_t row) = 0; |
reiniermarcel | 0:a115ff47d1c1 | 101 | |
reiniermarcel | 0:a115ff47d1c1 | 102 | /// set the foreground color |
reiniermarcel | 0:a115ff47d1c1 | 103 | /// |
reiniermarcel | 0:a115ff47d1c1 | 104 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 105 | /// |
reiniermarcel | 0:a115ff47d1c1 | 106 | /// @param[in] color is color to use for foreground drawing. |
reiniermarcel | 0:a115ff47d1c1 | 107 | /// @returns error code. |
reiniermarcel | 0:a115ff47d1c1 | 108 | /// |
reiniermarcel | 0:a115ff47d1c1 | 109 | virtual RetCode_t foreground(color_t color) = 0; |
reiniermarcel | 0:a115ff47d1c1 | 110 | |
reiniermarcel | 0:a115ff47d1c1 | 111 | /// set the background color |
reiniermarcel | 0:a115ff47d1c1 | 112 | /// |
reiniermarcel | 0:a115ff47d1c1 | 113 | /// @note this method may be overridden in a derived class. |
reiniermarcel | 0:a115ff47d1c1 | 114 | /// |
reiniermarcel | 0:a115ff47d1c1 | 115 | /// @param[in] color is color to use for background drawing. |
reiniermarcel | 0:a115ff47d1c1 | 116 | /// @returns error code. |
reiniermarcel | 0:a115ff47d1c1 | 117 | /// |
reiniermarcel | 0:a115ff47d1c1 | 118 | virtual RetCode_t background(color_t color) = 0; |
reiniermarcel | 0:a115ff47d1c1 | 119 | // putc (from Stream) |
reiniermarcel | 0:a115ff47d1c1 | 120 | // printf (from Stream) |
reiniermarcel | 0:a115ff47d1c1 | 121 | |
reiniermarcel | 0:a115ff47d1c1 | 122 | protected: |
reiniermarcel | 0:a115ff47d1c1 | 123 | virtual int _putc(int value); |
reiniermarcel | 0:a115ff47d1c1 | 124 | virtual int _getc(); |
reiniermarcel | 0:a115ff47d1c1 | 125 | |
reiniermarcel | 0:a115ff47d1c1 | 126 | // character location |
reiniermarcel | 0:a115ff47d1c1 | 127 | uint16_t _column; |
reiniermarcel | 0:a115ff47d1c1 | 128 | uint16_t _row; |
reiniermarcel | 0:a115ff47d1c1 | 129 | |
reiniermarcel | 0:a115ff47d1c1 | 130 | // colors |
reiniermarcel | 0:a115ff47d1c1 | 131 | color_t _foreground; |
reiniermarcel | 0:a115ff47d1c1 | 132 | color_t _background; |
reiniermarcel | 0:a115ff47d1c1 | 133 | char *_path; |
reiniermarcel | 0:a115ff47d1c1 | 134 | }; |
reiniermarcel | 0:a115ff47d1c1 | 135 | |
reiniermarcel | 0:a115ff47d1c1 | 136 | #endif |