lib/unigraphic/GraphicsDisplay.h

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

mercurial