lib/unigraphic/TextDisplay.h

Mon, 28 Jan 2019 21:51:45 +0100

author
David Douard <david.douard@logilab.fr>
date
Mon, 28 Jan 2019 21:51:45 +0100
changeset 24
b43536c064f6
parent 5
f1c85c2500f2
child 28
424d792fea4f
permissions
-rw-r--r--

Add the (missing?) Keypad lib

5
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
1 /* mbed TextDisplay Library Base Class
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
2 * Copyright (c) 2007-2009 sford
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
3 * Released under the MIT License: http://mbed.org/license/mit
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
4 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
5 * A common base class for Text displays
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
6 * To port a new display, derive from this class and implement
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
7 * the constructor (setup the display), character (put a character
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
8 * at a location), rows and columns (number of rows/cols) functions.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
9 * Everything else (locate, printf, putc, cls) will come for free
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
10 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
11 * The model is the display will wrap at the right and bottom, so you can
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
12 * keep writing and will always get valid characters. The location is
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
13 * maintained internally to the class to make this easy
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
14 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
15
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
16 #ifndef MBED_TEXTDISPLAY_H
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
17 #define MBED_TEXTDISPLAY_H
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
18
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
19 #include "mbed.h"
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
20
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
21 /** A common base class for Text displays
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
22 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
23 class TextDisplay : public Stream {
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
24 public:
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
25
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
26 // functions needing implementation in derived implementation class
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
27 // ----------------------------------------------------------------
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
28 /** Create a TextDisplay interface
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
29 * @param name The name used in the path to access the strean through the filesystem
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
30 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
31 TextDisplay(const char *name = NULL);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
32
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
33 /** output a character at the given position
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
34 *
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
35 * @param column column where charater must be written
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
36 * @param row where character must be written
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
37 * @param c the character to be written to the TextDisplay
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
38 * @note this method may be overridden in a derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
39 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
40 virtual void character(int column, int row, int c) = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
41
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
42 /** return number of rows on TextDisplay
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
43 * @result number of rows
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
44 * @note this method must be supported in the derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
45 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
46 virtual int rows() = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
47
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
48 /** return number of columns on TextDisplay
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
49 * @result number of columns
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
50 * @note this method must be supported in the derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
51 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
52 virtual int columns() = 0;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
53
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
54 // functions that come for free, but can be overwritten
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
55 // ----------------------------------------------------
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
56 /** redirect output from a stream (stoud, sterr) to display
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
57 * @param stream stream that shall be redirected to the TextDisplay
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
58 * @note this method may be overridden in a derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
59 * @returns true if the claim succeeded.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
60 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
61 virtual bool claim (FILE *stream);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
62
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
63 /** clear the entire screen
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
64 * @note this method may be overridden in a derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
65 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
66 virtual void cls();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
67
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
68 /** locate the cursor at a character position.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
69 * Based on the currently active font, locate the cursor on screen.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
70 * @note this method may be overridden in a derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
71 * @param column is the horizontal offset from the left side.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
72 * @param row is the vertical offset from the top.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
73 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
74 virtual void locate(int column, int row);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
75
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
76 /** set the foreground color
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
77 * @note this method may be overridden in a derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
78 * @param color is color to use for foreground drawing.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
79 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
80 virtual void foreground(uint16_t colour);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
81
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
82 /** set the background color
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
83 * @note this method may be overridden in a derived class.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
84 * @param color is color to use for background drawing.
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
85 */
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
86 virtual void background(uint16_t colour);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
87
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
88 // putc (from Stream)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
89 // printf (from Stream)
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
90
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
91 protected:
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
92
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
93 virtual int _putc(int value);
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
94 virtual int _getc();
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
95
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
96 // character location
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
97 int _column;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
98 int _row;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
99
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
100 // colours
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
101 volatile uint16_t _foreground;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
102 volatile uint16_t _background;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
103 char *_path;
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
104 };
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
105
f1c85c2500f2 several improvements
David Douard <david.douard@logilab.fr>
parents:
diff changeset
106 #endif

mercurial