Basically i glued Peter Drescher and Simon Ford libs in a GraphicsDisplay class, then derived TFT or LCD class (which inherits Protocols class), then the most derived ones (Inits), which are per-display and are the only part needed to be adapted to diff hw.
Fork of UniGraphic by
GraphicsDisplay.h
00001 /* mbed GraphicsDisplay Display Library Base Class 00002 * Copyright (c) 2007-2009 sford 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 * 00005 * A library for providing a common base class for Graphics displays 00006 * To port a new display, derive from this class and implement 00007 * the constructor (setup the display), pixel (put a pixel 00008 * at a location), width and height functions. Everything else 00009 * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) 00010 * will come for free. You can also provide a specialised implementation 00011 * of window and putp to speed up the results 00012 */ 00013 00014 #ifndef MBED_GRAPHICSDISPLAY_H 00015 #define MBED_GRAPHICSDISPLAY_H 00016 00017 #include "TextDisplay.h" 00018 #include "Terminal6x8.h" 00019 00020 00021 00022 /* some RGB color definitions */ 00023 #define Black 0x0000 /* 0, 0, 0 */ 00024 #define Navy 0x000F /* 0, 0, 128 */ 00025 #define DarkGreen 0x03E0 /* 0, 128, 0 */ 00026 #define DarkCyan 0x03EF /* 0, 128, 128 */ 00027 #define Maroon 0x7800 /* 128, 0, 0 */ 00028 #define Purple 0x780F /* 128, 0, 128 */ 00029 #define Olive 0x7BE0 /* 128, 128, 0 */ 00030 #define LightGrey 0xC618 /* 192, 192, 192 */ 00031 #define DarkGrey 0x7BEF /* 128, 128, 128 */ 00032 #define Blue 0x001F /* 0, 0, 255 */ 00033 #define Green 0x07E0 /* 0, 255, 0 */ 00034 #define Cyan 0x07FF /* 0, 255, 255 */ 00035 #define Red 0xF800 /* 255, 0, 0 */ 00036 #define Magenta 0xF81F /* 255, 0, 255 */ 00037 #define Yellow 0xFFE0 /* 255, 255, 0 */ 00038 #define White 0xFFFF /* 255, 255, 255 */ 00039 #define Orange 0xFD20 /* 255, 165, 0 */ 00040 #define GreenYellow 0xAFE5 /* 173, 255, 47 */ 00041 00042 /** Bitmap 00043 */ 00044 struct Bitmap_s{ 00045 int xSize; 00046 int ySize; 00047 int Byte_in_Line; 00048 char* data; 00049 }; 00050 00051 /** A common base class for Graphics displays 00052 */ 00053 class GraphicsDisplay : public TextDisplay { 00054 00055 public: 00056 00057 /** Create a GraphicsDisplay interface 00058 * @param name The name used by the parent class to access the interface 00059 */ 00060 GraphicsDisplay(const char* name); 00061 00062 ////// functions needing implementation in derived implementation class /////////////////////////////////////// 00063 ////// ---------------------------------------------------------------- /////////////////////////////////////// 00064 00065 /** Draw a pixel in the specified color. 00066 * @note this method must be supported in the derived class. 00067 * @param x is the horizontal offset to this pixel. 00068 * @param y is the vertical offset to this pixel. 00069 * @param color defines the color for the pixel. 00070 */ 00071 virtual void pixel(int x, int y, unsigned short color) = 0; 00072 00073 /** Set the window, which controls where items are written to the screen. 00074 * When something hits the window width, it wraps back to the left side 00075 * and down a row. If the initial write is outside the window, it will 00076 * be captured into the window when it crosses a boundary. 00077 * @param x is the left edge in pixels. 00078 * @param y is the top edge in pixels. 00079 * @param w is the window width in pixels. 00080 * @param h is the window height in pixels. 00081 * @note this method must be overridden in a derived class. 00082 */ 00083 virtual void window(int x, int y, int w, int h) = 0; 00084 00085 /** Push a single pixel into the window and increment position. 00086 * You may first call window() then push pixels in loop. 00087 * @param color is the pixel color. 00088 * @note this method must be overridden in a derived class. 00089 */ 00090 virtual void window_pushpixel(unsigned short color) = 0; 00091 00092 /** Push some pixels of the same color into the window and increment position. 00093 * You must first call window() then push pixels. 00094 * @param color is the pixel color. 00095 * @param count: how many 00096 */ 00097 virtual void window_pushpixel(unsigned short color, unsigned int count) = 0; 00098 00099 /** Push array of pixel colors into the window and increment position. 00100 * You must first call window() then push pixels. 00101 * @param color is the pixel color. 00102 */ 00103 virtual void window_pushpixelbuf(unsigned short* color, unsigned int lenght) = 0; 00104 00105 /** If framebuffer is used, it needs to be sent to LCD from time to time 00106 @note this method must be overridden in a derived class. 00107 @note real function for LCD, dummy for TFT 00108 */ 00109 virtual void copy_to_lcd() = 0; 00110 00111 /////// functions that come for free, but can be overwritten/////////////////////////////////////////////////// 00112 /////// ----------------------------------------------------/////////////////////////////////////////////////// 00113 00114 /** Set window to max possible size 00115 * May be overridden in a derived class. 00116 */ 00117 virtual void WindowMax(void); 00118 00119 /** clear the entire screen 00120 * Basically it sets windomax then fill with background color 00121 * May be overridden in a derived class. 00122 */ 00123 virtual void cls(); 00124 00125 /** draw a circle 00126 * 00127 * @param x0,y0 center 00128 * @param r radius 00129 * @param color 16 bit color * 00130 * 00131 */ 00132 virtual void circle(int x, int y, int r, unsigned short color); 00133 00134 /** draw a filled circle 00135 * 00136 * @param x0,y0 center 00137 * @param r radius 00138 * @param color 16 bit color * 00139 */ 00140 virtual void fillcircle(int x, int y, int r, unsigned short color); 00141 00142 00143 /** draw a 1 pixel line 00144 * 00145 * @param x0,y0 start point 00146 * @param x1,y1 stop point 00147 * @param color 16 bit color 00148 * 00149 */ 00150 virtual void line(int x0, int y0, int x1, int y1, unsigned short color); 00151 00152 /** draw a horizontal line 00153 * 00154 * @param x0 horizontal start 00155 * @param x1 horizontal stop 00156 * @param y vertical position 00157 * @param color 16 bit color 00158 * 00159 */ 00160 void hline(int x0, int x1, int y, unsigned short color); 00161 00162 /** draw a vertical line 00163 * 00164 * @param x horizontal position 00165 * @param y0 vertical start 00166 * @param y1 vertical stop 00167 * @param color 16 bit color 00168 */ 00169 void vline(int y0, int y1, int x, unsigned short color); 00170 00171 /** draw a rect 00172 * 00173 * @param x0,y0 top left corner 00174 * @param x1,y1 down right corner 00175 * @param color 16 bit color 00176 * * 00177 */ 00178 virtual void rect(int x0, int y0, int x1, int y1, unsigned short color); 00179 00180 /** draw a filled rect 00181 * 00182 * @param x0,y0 top left corner 00183 * @param x1,y1 down right corner 00184 * @param color 16 bit color 00185 * 00186 */ 00187 virtual void fillrect(int x0, int y0, int x1, int y1, unsigned short color); 00188 00189 /** setup cursor position for text 00190 * 00191 * @param x x-position (top left) 00192 * @param y y-position 00193 */ 00194 virtual void locate(int x, int y); 00195 00196 /** put a char on the screen 00197 * 00198 * @param value char to print 00199 * @returns printed char 00200 * 00201 */ 00202 virtual int _putc(int value); 00203 00204 /** draw a character on given position out of the active font to the TFT 00205 * 00206 * @param x x-position of char (top left) 00207 * @param y y-position 00208 * @param c char to print 00209 * 00210 */ 00211 virtual void character(int x, int y, int c); 00212 00213 /** paint a bitmap on the TFT 00214 * 00215 * @param x,y : upper left corner 00216 * @param w width of bitmap 00217 * @param h high of bitmap 00218 * @param *bitmap pointer to the bitmap data 00219 * 00220 * bitmap format: 16 bit R5 G6 B5 00221 * 00222 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00223 * use winhex to load this file and mark data stating at offset 0x46 to end 00224 * use edit -> copy block -> C Source to export C array 00225 * paste this array into your program 00226 * 00227 * define the array as static const unsigned char to put it into flash memory 00228 * cast the pointer to (unsigned char *) : 00229 * tft.Bitmap(10,40,309,50,(unsigned char *)scala); 00230 */ 00231 void Bitmap(int x, int y, int w, int h,unsigned char *bitmap); 00232 00233 /** paint monochrome bitmap to screen 00234 * 00235 * @param bm Bitmap in flash 00236 * @param x x start 00237 * @param y y start 00238 * 00239 */ 00240 void Bitmap_BW(Bitmap_s bm, int x, int y); 00241 00242 /** paint a 16 bit BMP from filesytem on the TFT (slow) 00243 * 00244 * @param x,y : position of upper left corner 00245 * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp" 00246 * 00247 * @returns 1 if bmp file was found and painted 00248 * @returns 0 if bmp file was found not found 00249 * @returns -1 if file is no bmp 00250 * @returns -2 if bmp file is no 16 bit bmp 00251 * @returns -3 if bmp file is to big for screen 00252 * @returns -4 if buffer malloc go wrong 00253 * 00254 * bitmap format: 16 bit R5 G6 B5 00255 * 00256 * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 00257 * copy to internal file system or SD card 00258 */ 00259 int BMP_16(int x, int y, const char *Name_BMP); 00260 00261 00262 00263 /** select the font to use 00264 * 00265 * @param f pointer to font array 00266 * @param firstascii first ascii code present in font array, default 32 (space) 00267 * @param lastascii last ascii code present in font array, default 127 (DEL) 00268 * @param proportional enable/disable variable font width (default enabled) 00269 * 00270 * font array can created with GLCD Font Creator from http://www.mikroe.com 00271 * you have to add 4 parameter at the beginning of the font array to use: 00272 * - the number of byte / char (not used in this revision, set to whatever) 00273 * - the vertial size in pixel 00274 * - the horizontal size in pixel 00275 * - the number of byte per vertical line (not used in this revision, set to whatever) 00276 * you also have to change the array to cont unsigned char[] and __align(2) 00277 * 00278 */ 00279 void set_font(unsigned char* f, unsigned char firstascii=32, unsigned char lastascii=127, bool proportional = true); 00280 00281 /** Get the number of columns based on the currently active font. 00282 * @returns number of columns. 00283 * @note this method may be overridden in a derived class. 00284 */ 00285 virtual int columns(); 00286 00287 /** Get the number of rows based on the currently active font. 00288 * @returns number of rows. 00289 * @note this method may be overridden in a derived class. 00290 */ 00291 virtual int rows(); 00292 00293 /** get the current oriented screen width in pixels 00294 * @returns screen width in pixels. 00295 */ 00296 int width(); 00297 00298 /** get the current oriented screen height in pixels 00299 * @returns screen height in pixels. 00300 */ 00301 int height(); 00302 00303 /** set the current oriented screen width in pixels 00304 * @param width screen width in pixels. 00305 */ 00306 void set_width(int width); 00307 00308 /** set the current oriented screen height in pixels 00309 * @param height screen height in pixels. 00310 */ 00311 void set_height(int height); 00312 00313 /** setup auto update of screen 00314 * 00315 * @param up 1 = on , 0 = off 00316 * if switched off the program has to call copy_to_lcd() 00317 * to update screen from framebuffer 00318 */ 00319 void set_auto_up(bool up); 00320 00321 /** get status of the auto update function 00322 * 00323 * @returns if auto update is on 00324 */ 00325 bool get_auto_up(void); 00326 00327 00328 00329 private: 00330 00331 unsigned char* font; 00332 // display width and height related to current orientation 00333 int oriented_width; 00334 int oriented_height; 00335 00336 // text char location 00337 int char_x; 00338 int char_y; 00339 00340 int fontoffset;// bytes / char (short) 00341 int fonthor; // hor size of font (char) 00342 int fontvert; // ver size of font (char) 00343 int fontbpl; // bytes per line (char) 00344 unsigned char firstch; // first ascii code present in font array (usually 32) 00345 unsigned char lastch; // last ascii code present in font array (usually 127) 00346 bool auto_up; // autoupdate flag for LCD 00347 bool fontprop; 00348 00349 00350 }; 00351 00352 #endif
Generated on Wed Jul 13 2022 21:19:22 by 1.7.2