Mon, 11 Mar 2024 15:35:36 +0100
Add links to sr.ht repos and add an image in the README file
5 | 1 | /* mbed GraphicsDisplay Display Library Base Class |
2 | * Copyright (c) 2007-2009 sford | |
3 | * Released under the MIT License: http://mbed.org/license/mit | |
4 | * | |
5 | * A library for providing a common base class for Graphics displays | |
6 | * To port a new display, derive from this class and implement | |
7 | * the constructor (setup the display), pixel (put a pixel | |
8 | * at a location), width and height functions. Everything else | |
45 | 9 | * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) |
5 | 10 | * will come for free. You can also provide a specialised implementation |
11 | * of window and putp to speed up the results | |
12 | */ | |
13 | ||
14 | #ifndef MBED_GRAPHICSDISPLAY_H | |
15 | #define MBED_GRAPHICSDISPLAY_H | |
16 | ||
17 | #include "TextDisplay.h" | |
18 | #include "Terminal6x8.h" | |
19 | ||
20 | ||
21 | ||
22 | /* some RGB color definitions */ | |
23 | #define Black 0x0000 /* 0, 0, 0 */ | |
24 | #define Navy 0x000F /* 0, 0, 128 */ | |
25 | #define DarkGreen 0x03E0 /* 0, 128, 0 */ | |
26 | #define DarkCyan 0x03EF /* 0, 128, 128 */ | |
27 | #define Maroon 0x7800 /* 128, 0, 0 */ | |
28 | #define Purple 0x780F /* 128, 0, 128 */ | |
29 | #define Olive 0x7BE0 /* 128, 128, 0 */ | |
30 | #define LightGrey 0xC618 /* 192, 192, 192 */ | |
31 | #define DarkGrey 0x7BEF /* 128, 128, 128 */ | |
32 | #define Blue 0x001F /* 0, 0, 255 */ | |
33 | #define Green 0x07E0 /* 0, 255, 0 */ | |
34 | #define Cyan 0x07FF /* 0, 255, 255 */ | |
35 | #define Red 0xF800 /* 255, 0, 0 */ | |
36 | #define Magenta 0xF81F /* 255, 0, 255 */ | |
37 | #define Yellow 0xFFE0 /* 255, 255, 0 */ | |
38 | #define White 0xFFFF /* 255, 255, 255 */ | |
39 | #define Orange 0xFD20 /* 255, 165, 0 */ | |
40 | #define GreenYellow 0xAFE5 /* 173, 255, 47 */ | |
41 | ||
42 | /** Bitmap | |
43 | */ | |
44 | struct Bitmap_s{ | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
45 | unsigned int xSize; |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
46 | unsigned int ySize; |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
47 | unsigned int Byte_in_Line; |
5 | 48 | char* data; |
49 | }; | |
50 | ||
51 | /** A common base class for Graphics displays | |
52 | */ | |
53 | class GraphicsDisplay : public TextDisplay { | |
54 | ||
45 | 55 | public: |
56 | ||
5 | 57 | /** Create a GraphicsDisplay interface |
58 | * @param name The name used by the parent class to access the interface | |
59 | */ | |
60 | GraphicsDisplay(const char* name); | |
45 | 61 | |
5 | 62 | ////// functions needing implementation in derived implementation class /////////////////////////////////////// |
63 | ////// ---------------------------------------------------------------- /////////////////////////////////////// | |
64 | ||
65 | /** Draw a pixel in the specified color. | |
66 | * @note this method must be supported in the derived class. | |
67 | * @param x is the horizontal offset to this pixel. | |
68 | * @param y is the vertical offset to this pixel. | |
69 | * @param color defines the color for the pixel. | |
70 | */ | |
71 | virtual void pixel(int x, int y, unsigned short color) = 0; | |
45 | 72 | |
5 | 73 | /** Set the window, which controls where items are written to the screen. |
74 | * When something hits the window width, it wraps back to the left side | |
75 | * and down a row. If the initial write is outside the window, it will | |
76 | * be captured into the window when it crosses a boundary. | |
77 | * @param x is the left edge in pixels. | |
78 | * @param y is the top edge in pixels. | |
79 | * @param w is the window width in pixels. | |
80 | * @param h is the window height in pixels. | |
81 | * @note this method must be overridden in a derived class. | |
82 | */ | |
83 | virtual void window(int x, int y, int w, int h) = 0; | |
84 | ||
85 | /** Push a single pixel into the window and increment position. | |
86 | * You may first call window() then push pixels in loop. | |
87 | * @param color is the pixel color. | |
88 | * @note this method must be overridden in a derived class. | |
89 | */ | |
90 | virtual void window_pushpixel(unsigned short color) = 0; | |
45 | 91 | |
5 | 92 | /** Push some pixels of the same color into the window and increment position. |
93 | * You must first call window() then push pixels. | |
94 | * @param color is the pixel color. | |
95 | * @param count: how many | |
96 | */ | |
97 | virtual void window_pushpixel(unsigned short color, unsigned int count) = 0; | |
45 | 98 | |
5 | 99 | /** Push array of pixel colors into the window and increment position. |
100 | * You must first call window() then push pixels. | |
101 | * @param color is the pixel color. | |
102 | */ | |
103 | virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght) = 0; | |
45 | 104 | |
5 | 105 | /** If framebuffer is used, it needs to be sent to LCD from time to time |
106 | @note this method must be overridden in a derived class. | |
107 | @note real function for LCD, dummy for TFT | |
108 | */ | |
45 | 109 | virtual void copy_to_lcd() = 0; |
5 | 110 | |
111 | /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// | |
112 | /////// ----------------------------------------------------/////////////////////////////////////////////////// | |
113 | ||
114 | /** Set window to max possible size | |
115 | * May be overridden in a derived class. | |
116 | */ | |
117 | virtual void WindowMax(void); | |
118 | ||
119 | /** clear the entire screen | |
120 | * Basically it sets windomax then fill with background color | |
121 | * May be overridden in a derived class. | |
122 | */ | |
123 | virtual void cls(); | |
124 | ||
125 | /** draw a circle | |
126 | * | |
127 | * @param x0,y0 center | |
128 | * @param r radius | |
129 | * @param color 16 bit color * | |
130 | * | |
45 | 131 | */ |
132 | virtual void circle(int x, int y, int r, unsigned short color); | |
133 | ||
5 | 134 | /** draw a filled circle |
135 | * | |
136 | * @param x0,y0 center | |
137 | * @param r radius | |
138 | * @param color 16 bit color * | |
45 | 139 | */ |
140 | virtual void fillcircle(int x, int y, int r, unsigned short color); | |
141 | ||
142 | ||
5 | 143 | /** draw a 1 pixel line |
144 | * | |
145 | * @param x0,y0 start point | |
146 | * @param x1,y1 stop point | |
147 | * @param color 16 bit color | |
148 | * | |
45 | 149 | */ |
5 | 150 | virtual void line(int x0, int y0, int x1, int y1, unsigned short color); |
45 | 151 | |
5 | 152 | /** draw a horizontal line |
153 | * | |
154 | * @param x0 horizontal start | |
155 | * @param x1 horizontal stop | |
156 | * @param y vertical position | |
45 | 157 | * @param color 16 bit color |
5 | 158 | * |
159 | */ | |
160 | void hline(int x0, int x1, int y, unsigned short color); | |
45 | 161 | |
5 | 162 | /** draw a vertical line |
163 | * | |
164 | * @param x horizontal position | |
45 | 165 | * @param y0 vertical start |
5 | 166 | * @param y1 vertical stop |
167 | * @param color 16 bit color | |
168 | */ | |
169 | void vline(int y0, int y1, int x, unsigned short color); | |
45 | 170 | |
5 | 171 | /** draw a rect |
172 | * | |
173 | * @param x0,y0 top left corner | |
174 | * @param x1,y1 down right corner | |
175 | * @param color 16 bit color | |
176 | * * | |
45 | 177 | */ |
5 | 178 | virtual void rect(int x0, int y0, int x1, int y1, unsigned short color); |
45 | 179 | |
5 | 180 | /** draw a filled rect |
181 | * | |
182 | * @param x0,y0 top left corner | |
183 | * @param x1,y1 down right corner | |
184 | * @param color 16 bit color | |
185 | * | |
45 | 186 | */ |
5 | 187 | virtual void fillrect(int x0, int y0, int x1, int y1, unsigned short color); |
45 | 188 | |
5 | 189 | /** setup cursor position for text |
190 | * | |
191 | * @param x x-position (top left) | |
45 | 192 | * @param y y-position |
193 | */ | |
5 | 194 | virtual void locate(int x, int y); |
45 | 195 | |
5 | 196 | /** put a char on the screen |
197 | * | |
198 | * @param value char to print | |
199 | * @returns printed char | |
200 | * | |
201 | */ | |
202 | virtual int _putc(int value); | |
45 | 203 | |
204 | /** draw a character on current position out of the active font to the TFT | |
205 | * | |
206 | * @param c char to print | |
207 | * | |
208 | */ | |
209 | virtual void character(int c); | |
210 | ||
5 | 211 | /** draw a character on given position out of the active font to the TFT |
212 | * | |
45 | 213 | * @param x x-position of char (top left) |
5 | 214 | * @param y y-position |
215 | * @param c char to print | |
216 | * | |
45 | 217 | */ |
5 | 218 | virtual void character(int x, int y, int c); |
45 | 219 | |
220 | /** return the actual width of a character out of the active font to the TFT | |
221 | * | |
222 | * @param c char to print | |
223 | * @param move_location wether to move current poisition or not | |
5 | 224 | * |
45 | 225 | */ |
226 | virtual uint8_t char_width(char c, bool move_location=false); | |
227 | ||
228 | /** paint a bitmap on the TFT | |
229 | * | |
230 | * @param x,y : upper left corner | |
5 | 231 | * @param w width of bitmap |
232 | * @param h high of bitmap | |
233 | * @param *bitmap pointer to the bitmap data | |
234 | * | |
235 | * bitmap format: 16 bit R5 G6 B5 | |
45 | 236 | * |
237 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 | |
5 | 238 | * use winhex to load this file and mark data stating at offset 0x46 to end |
239 | * use edit -> copy block -> C Source to export C array | |
240 | * paste this array into your program | |
45 | 241 | * |
5 | 242 | * define the array as static const unsigned char to put it into flash memory |
243 | * cast the pointer to (unsigned char *) : | |
244 | * tft.Bitmap(10,40,309,50,(unsigned char *)scala); | |
45 | 245 | */ |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
246 | void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap); |
45 | 247 | |
5 | 248 | /** paint monochrome bitmap to screen |
249 | * | |
250 | * @param bm Bitmap in flash | |
251 | * @param x x start | |
45 | 252 | * @param y y start |
5 | 253 | * |
254 | */ | |
255 | void Bitmap_BW(Bitmap_s bm, int x, int y); | |
45 | 256 | |
257 | /** paint a 16 bit BMP from filesytem on the TFT (slow) | |
5 | 258 | * |
45 | 259 | * @param x,y : position of upper left corner |
5 | 260 | * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp" |
261 | * | |
262 | * @returns 1 if bmp file was found and painted | |
263 | * @returns 0 if bmp file was found not found | |
264 | * @returns -1 if file is no bmp | |
265 | * @returns -2 if bmp file is no 16 bit bmp | |
45 | 266 | * @returns -3 if bmp file is to big for screen |
5 | 267 | * @returns -4 if buffer malloc go wrong |
268 | * | |
269 | * bitmap format: 16 bit R5 G6 B5 | |
45 | 270 | * |
5 | 271 | * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 |
45 | 272 | * copy to internal file system or SD card |
273 | */ | |
274 | int BMP_16(int x, int y, const char *Name_BMP); | |
275 | ||
276 | ||
277 | ||
5 | 278 | /** select the font to use |
279 | * | |
45 | 280 | * @param f pointer to font array |
5 | 281 | * @param firstascii first ascii code present in font array, default 32 (space) |
282 | * @param lastascii last ascii code present in font array, default 127 (DEL) | |
283 | * @param proportional enable/disable variable font width (default enabled) | |
45 | 284 | * |
5 | 285 | * font array can created with GLCD Font Creator from http://www.mikroe.com |
45 | 286 | * you have to add 4 parameter at the beginning of the font array to use: |
5 | 287 | * - the number of byte / char (not used in this revision, set to whatever) |
288 | * - the vertial size in pixel | |
289 | * - the horizontal size in pixel | |
290 | * - the number of byte per vertical line (not used in this revision, set to whatever) | |
291 | * you also have to change the array to cont unsigned char[] and __align(2) | |
292 | * | |
45 | 293 | */ |
5 | 294 | void set_font(unsigned char* f, unsigned char firstascii=32, unsigned char lastascii=127, bool proportional = true); |
45 | 295 | |
5 | 296 | /** Zoom fount |
297 | * | |
298 | * @param x_mul horizontal size multiplier | |
299 | * @param y_mul vertical size multiplier | |
45 | 300 | */ |
5 | 301 | void set_font_zoom(unsigned char x_mul, unsigned char y_mul); |
302 | ||
303 | /** Get the number of columns based on the currently active font. | |
304 | * @returns number of columns. | |
305 | * @note this method may be overridden in a derived class. | |
306 | */ | |
307 | virtual int columns(); | |
308 | ||
309 | /** Get the number of rows based on the currently active font. | |
310 | * @returns number of rows. | |
311 | * @note this method may be overridden in a derived class. | |
312 | */ | |
313 | virtual int rows(); | |
45 | 314 | |
5 | 315 | /** get the current oriented screen width in pixels |
316 | * @returns screen width in pixels. | |
317 | */ | |
318 | int width(); | |
319 | ||
320 | /** get the current oriented screen height in pixels | |
321 | * @returns screen height in pixels. | |
322 | */ | |
323 | int height(); | |
45 | 324 | |
5 | 325 | /** set the current oriented screen width in pixels |
326 | * @param width screen width in pixels. | |
327 | */ | |
328 | void set_width(int width); | |
329 | ||
330 | /** set the current oriented screen height in pixels | |
331 | * @param height screen height in pixels. | |
332 | */ | |
333 | void set_height(int height); | |
45 | 334 | |
335 | /** setup auto update of screen | |
5 | 336 | * |
337 | * @param up 1 = on , 0 = off | |
45 | 338 | * if switched off the program has to call copy_to_lcd() |
5 | 339 | * to update screen from framebuffer |
340 | */ | |
341 | void set_auto_up(bool up); | |
45 | 342 | |
5 | 343 | /** get status of the auto update function |
344 | * | |
345 | * @returns if auto update is on | |
346 | */ | |
45 | 347 | bool get_auto_up(void); |
348 | ||
349 | ||
350 | ||
5 | 351 | private: |
352 | unsigned char* font; | |
353 | // display width and height related to current orientation | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
354 | unsigned int oriented_width; |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
355 | unsigned int oriented_height; |
45 | 356 | |
5 | 357 | // text char location |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
358 | unsigned int char_x; |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
359 | unsigned int char_y; |
45 | 360 | |
66
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
361 | unsigned int fontoffset;// bytes / char (short) |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
362 | unsigned int fonthor; // hor size of font (char) |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
363 | unsigned int fontvert; // ver size of font (char) |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
364 | unsigned int fontbpl; // bytes per line (char) |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
365 | unsigned int fontzoomver; // size multiplier |
48f29a1d43d6
Clean several compilation warnings
David Douard <david.douard@sdfa3.org>
parents:
45
diff
changeset
|
366 | unsigned int fontzoomhor; // size multiplier |
5 | 367 | unsigned char firstch; // first ascii code present in font array (usually 32) |
368 | unsigned char lastch; // last ascii code present in font array (usually 127) | |
369 | bool auto_up; // autoupdate flag for LCD | |
370 | bool fontprop; | |
45 | 371 | |
5 | 372 | |
373 | }; | |
374 | ||
375 | #endif |