el h / SimpleGUI

Fork of SimpleGUI by Duncan McIntyre

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FontRenderer.h Source File

FontRenderer.h

00001 #ifndef SIMPLEGUI_FONT_RENDERER_H
00002 #define SIMPLEGUI_FONT_RENDERER_H
00003 
00004 #include "Font.h"
00005 #include "GraphicsDisplay.h"
00006 /**
00007 * Abstract base class defining the interface for class which can render fonts to a GraphicsDisplay
00008 * Should probably use some template wizardy to specify the covariant Font type....
00009 **/
00010 class FontRenderer {
00011 public:
00012 
00013     FontRenderer() : _foreground(0xffff), _background(0)
00014     
00015     {
00016         window(0,0,0,0,true);
00017     }
00018     // You need to implement this..
00019     //virtual void setFont(Font* font) =0;
00020     
00021     /**
00022     * Render a single character at the current cursor location, advance the cursor
00023     * Clip/wrap as necessary
00024     **/
00025     virtual void putc(const char  c, GraphicsDisplay* display, Font* font) =0;
00026     /**
00027     * Render a string at the current cursor location, advance the cursor
00028     * Clip/wrap as necessary
00029     **/
00030     virtual void puts(const char* s, GraphicsDisplay* display, Font* font) =0;
00031 
00032     void setForeground(uint16_t foreground) {
00033         _foreground = foreground;
00034     }
00035     
00036     void setBackground(uint16_t background) {
00037         _background = background;
00038     }
00039     
00040     /**
00041     * Sets the window into which to render. placing the cursor at (x,y)
00042     **/
00043     void window(int x, int y, int width, int height, bool clip) {
00044         _wx0 = x;
00045         _wy0 = y;
00046         _wx1 = x + width;
00047         _wy1 = y + height;
00048         
00049         if(_wx0 > _wx1) {
00050             int tmp = _wx0;
00051             _wx0 = _wx1;
00052             _wx1 = tmp;
00053         }
00054         
00055         if(_wy0 > _wy1) {
00056             int tmp = _wy0;
00057             _wy0 = _wy1;
00058             _wy1 = tmp;
00059         }
00060         
00061         _cx = _wx0;
00062         _cy = _wy0;
00063         _clip = clip;
00064     }
00065         
00066 protected:
00067     uint16_t _foreground, _background;
00068     int _wx0, _wx1, _wy0, _wy1, _cx, _cy;
00069     bool _clip;
00070 };
00071 
00072 #endif