Arunkumar Mourougappane / UniGraphic

Dependents:   TFT_ILI9341_UniGraphic TFT_ILI9341_os6

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GraphicsDisplay.h Source File

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     /** draw a empty triangle
00190    *
00191    * @param x0,y0 1st vertice of triangle
00192    * @param x1,y1 2nd vertice of triangle
00193    * @param x2,y2 3rd vertice of triangle
00194    * @param color 16 bit color
00195    *
00196    */    
00197   virtual void triangle(int x0, int y0,int x1, int y1, int x2, int y2, unsigned short color);
00198 
00199    /** draw a filled triangle
00200    *
00201    * @param x0,y0 1st vertice of triangle
00202    * @param x1,y1 2nd vertice of triangle
00203    * @param x2,y2 3rd vertice of triangle
00204    * @param color 16 bit color
00205    *
00206    */  
00207   virtual void fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, unsigned short color);
00208 
00209     /** setup cursor position for text
00210    *
00211    * @param x x-position (top left)
00212    * @param y y-position 
00213    */   
00214   virtual void locate(int x, int y);
00215     
00216     /** put a char on the screen
00217    *
00218    * @param value char to print
00219    * @returns printed char
00220    *
00221    */
00222   virtual int _putc(int value);
00223     
00224   /** draw a character on given position out of the active font to the TFT
00225    *
00226    * @param x x-position of char (top left) 
00227    * @param y y-position
00228    * @param c char to print
00229    *
00230    */    
00231   virtual void character(int x, int y, int c);
00232     
00233   /** paint a bitmap on the TFT 
00234    *
00235    * @param x,y : upper left corner 
00236    * @param w width of bitmap
00237    * @param h high of bitmap
00238    * @param *bitmap pointer to the bitmap data
00239    *
00240    *   bitmap format: 16 bit R5 G6 B5
00241    * 
00242    *   use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5            
00243    *   use winhex to load this file and mark data stating at offset 0x46 to end
00244    *   use edit -> copy block -> C Source to export C array
00245    *   paste this array into your program
00246    * 
00247    *   define the array as static const unsigned char to put it into flash memory
00248    *   cast the pointer to (unsigned char *) :
00249    *   tft.Bitmap(10,40,309,50,(unsigned char *)scala);
00250    */    
00251   void Bitmap(int x, int y, int w, int h,unsigned char *bitmap);
00252     
00253     /** paint monochrome bitmap to screen
00254       *
00255       * @param bm Bitmap in flash
00256       * @param x  x start
00257       * @param y  y start 
00258       *
00259       */
00260     void Bitmap_BW(Bitmap_s bm, int x, int y);
00261     
00262    /** paint a 16 bit BMP from filesytem on the TFT (slow) 
00263    *
00264    * @param x,y : position of upper left corner 
00265    * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp"
00266    *
00267    * @returns 1 if bmp file was found and painted
00268    * @returns  0 if bmp file was found not found
00269    * @returns -1 if file is no bmp
00270    * @returns -2 if bmp file is no 16 bit bmp
00271    * @returns -3 if bmp file is to big for screen 
00272    * @returns -4 if buffer malloc go wrong
00273    *
00274    *   bitmap format: 16 bit R5 G6 B5
00275    * 
00276    *   use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
00277    *   copy to internal file system or SD card           
00278    */      
00279   int BMP_16(int x, int y, const char *Name_BMP);  
00280     
00281     
00282     
00283   /** select the font to use
00284    *
00285    * @param f pointer to font array 
00286    * @param firstascii first ascii code present in font array, default 32 (space)
00287    * @param lastascii last ascii code present in font array, default 127 (DEL)
00288    * @param proportional enable/disable variable font width (default enabled)
00289    *                                                                              
00290    *   font array can created with GLCD Font Creator from http://www.mikroe.com
00291    *   you have to add 4 parameter at the beginning of the font array to use: 
00292    *   - the number of byte / char (not used in this revision, set to whatever)
00293    *   - the vertial size in pixel
00294    *   - the horizontal size in pixel
00295    *   - the number of byte per vertical line (not used in this revision, set to whatever)
00296    *   you also have to change the array to cont unsigned char[] and __align(2)
00297    *
00298    */  
00299   void set_font(unsigned char* f, unsigned char firstascii=32, unsigned char lastascii=127, bool proportional = true);
00300   
00301   /** Zoom fount
00302    *
00303    * @param x_mul horizontal size multiplier
00304    * @param y_mul vertical size multiplier
00305    */  
00306   void set_font_zoom(unsigned char x_mul, unsigned char y_mul);
00307 
00308     /** Get the number of columns based on the currently active font.
00309     * @returns number of columns.
00310     * @note this method may be overridden in a derived class.
00311     */
00312     virtual int columns();
00313 
00314     /** Get the number of rows based on the currently active font.
00315     * @returns number of rows.
00316     * @note this method may be overridden in a derived class.
00317     */
00318     virtual int rows();
00319     
00320     /** get the current oriented screen width in pixels
00321     * @returns screen width in pixels.
00322     */
00323     int width();
00324 
00325     /** get the current oriented screen height in pixels
00326     * @returns screen height in pixels.
00327     */
00328     int height();
00329     
00330     /** set the current oriented screen width in pixels
00331     * @param width screen width in pixels.
00332     */
00333     void set_width(int width);
00334 
00335     /** set the current oriented screen height in pixels
00336     * @param height screen height in pixels.
00337     */
00338     void set_height(int height);
00339     
00340     /** setup auto update of screen 
00341       *
00342       * @param up 1 = on , 0 = off
00343       * if switched off the program has to call copy_to_lcd() 
00344       * to update screen from framebuffer
00345       */
00346     void set_auto_up(bool up);
00347  
00348     /** get status of the auto update function
00349       *
00350       *  @returns if auto update is on
00351       */
00352     bool get_auto_up(void); 
00353     
00354     
00355     
00356 private:
00357 
00358     unsigned char* font;
00359     // display width and height related to current orientation
00360     int oriented_width;
00361     int oriented_height;
00362     
00363     // text char location
00364     int char_x;
00365     int char_y;
00366     
00367     int  fontoffset;// bytes / char (short)
00368     int  fonthor;   // hor size of font (char)
00369     int  fontvert;  // ver size of font (char)
00370     int fontbpl;   // bytes per line (char)
00371     int fontzoomver; // size multiplier
00372     int fontzoomhor; // size multiplier
00373     unsigned char firstch;  // first ascii code present in font array (usually 32)
00374     unsigned char lastch;   // last ascii code present in font array (usually 127)
00375     bool auto_up;  // autoupdate flag for LCD
00376     bool fontprop;
00377     
00378 
00379 };
00380 
00381 #endif