A tiny drawing library. include line draw and bitmap-font draw.bitmap-font is from linux-kernel-source.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers tinydraw.h Source File

tinydraw.h

00001 /** Tiny library of drawing in framebuffer
00002  *
00003  * @section LICENSE
00004  * This source code is "GPLv2" license. 
00005  * The original of the font image is Linux kernel source. 
00006  * Because the Linux kernel license is "GPLv2 with the exception articles",
00007  * this program also applies GPLv2. 
00008  *
00009  * Copyright (C) 2010 tosihisa
00010  *
00011  * @section DESCRIPTION
00012  * Tiny library of drawing in framebuffer
00013  *
00014  */
00015 
00016 #ifndef __TINYDRAW_H    /* { */
00017 #define    __TINYDRAW_H
00018 
00019 #include "linuxfont/linuxfont.h"
00020 
00021 /** FrameBuffer(VRAM) X(Width) size */
00022 #define TD_X_MAX  (128)
00023 /** FrameBuffer(VRAM) Y(Width) size */
00024 #define TD_Y_MAX  (64)
00025 
00026 /** X/Y coordinate range type */
00027 typedef short TD_XY_t;
00028 
00029 /* X/Y coordinate type */
00030 typedef struct td_point_s {
00031     TD_XY_t x;
00032     TD_XY_t y;
00033 } TD_POINT_t;
00034 
00035 /** color type */
00036 typedef unsigned char TD_COLOR_t;
00037 
00038 /** color type (foreground and background pair) */
00039 typedef struct td_color_pair_s {
00040     TD_COLOR_t fore;    /**< foreground */
00041     TD_COLOR_t back;    /**< background */
00042 } TD_COLOR_PAIR_t;
00043 
00044 /**
00045  * Tiny library of drawing in framebuffer
00046  */
00047 class TinyDraw {
00048 public:
00049     /**
00050      * The frame buffer is cleared by 0. 
00051      *
00052      * @param none.
00053      * @return none.
00054      */
00055     void clear(void);
00056 
00057     /**
00058      * The dot is drawn in specified coordinates by the specified color code. 
00059      *
00060      * @param x [in] X coordinates
00061      * @param y [in] Y coordinates
00062      * @param fcol [in] Color-code (0 or 1 or COL_TRANS).
00063      * @return none.
00064      */
00065     void drawPoint(TD_XY_t x,TD_XY_t y,TD_COLOR_t fcol);
00066 
00067     /**
00068      * It draws in the line. 
00069      *
00070      * @param p1 [in] point of start.
00071      * @param p2 [in] point of end.
00072      * @param col [in] Color-code (now only use 'fore').
00073      * @return none.
00074      */
00075     void drawLine(TD_POINT_t *p1,TD_POINT_t *p2,TD_COLOR_PAIR_t *col);
00076 
00077     /**
00078      * It draws in the character.
00079      *
00080      * @param pnt [in] point of draw (upper left corner of font)
00081      * @param c [in] character code(only use ASCII-CODE now)
00082      * @param col [in] Color-code.
00083      * @param fontdesc [in] font-descriptor.
00084      * @return none.
00085      */
00086     void drawChar(TD_POINT_t *pnt,int c,TD_COLOR_PAIR_t *col,const struct font_desc *fontdesc);
00087 
00088     /**
00089      * It draws in the string.
00090      *
00091      * @param pnt [in] point of draw (upper left corner of font)
00092      * @param str [in] string (only use ASCII-CODE now)
00093      * @param col [in] Color-code.
00094      * @param fontdesc [in] font-descriptor.
00095      * @return none.
00096      */
00097     void drawStr(TD_POINT_t *pnt,char *str,TD_COLOR_PAIR_t *col,const struct font_desc *fontdesc);
00098 
00099     /**
00100      * Get the bit map image of the font. 
00101      *
00102      * @param c [in] character code(only use ASCII-CODE now)
00103      * @param fontdesc [in] font-descriptor.
00104      * @return pointer for bit map image.
00105      */
00106     char *getCharImage(int c,const struct font_desc *fontdesc);
00107 
00108     /**
00109      * Get the framebuffer pointer. 
00110      *
00111      * @param pnt [in] Coordinates.
00112      * @return pointer for framebuffer.
00113      */
00114     TD_COLOR_t *getVRAMPtr(TD_POINT_t *pnt);
00115 
00116     /**
00117      * Get the top of framebuffer pointer. 
00118      *
00119      * @param none.
00120      * @return pointer for top of framebuffer.
00121      */
00122     TD_COLOR_t *getVRAMPtr(void);
00123 
00124     static const int X_MAX = TD_X_MAX;
00125     static const int Y_MAX = TD_Y_MAX;
00126     static const TD_COLOR_t COL_TRANS = 0x80;
00127 
00128 private:
00129     TD_XY_t calcAbs(TD_XY_t v);
00130     TD_XY_t calcMin(TD_XY_t v1,TD_XY_t v2);
00131     int checkSign(TD_XY_t v);
00132 
00133     TD_COLOR_t VRAM[(TD_X_MAX * TD_Y_MAX * sizeof(TD_COLOR_t))/8];
00134 };
00135 
00136 #endif /* __TINYDRAW_H    } */
00137