libg15render.h File Reference

#include <string.h>
#include <ft2build.h>

Go to the source code of this file.

Data Structures

struct  g15canvas
 This structure holds the data need to render objects to the LCD screen. More...

Defines

#define BYTE_SIZE   8
#define G15_BUFFER_LEN   1048
#define G15_COLOR_BLACK   1
#define G15_COLOR_WHITE   0
#define G15_LCD_HEIGHT   43
#define G15_LCD_OFFSET   32
#define G15_LCD_WIDTH   160
#define G15_MAX_FACE   5
#define G15_PIXEL_FILL   1
#define G15_PIXEL_NOFILL   0
#define G15_TEXT_LARGE   2
#define G15_TEXT_MED   1
#define G15_TEXT_SMALL   0

Typedefs

typedef struct g15canvas g15canvas
 This structure holds the data need to render objects to the LCD screen.

Functions

void g15r_clearScreen (g15canvas *canvas, int color)
 Fills the screen with pixels of color.
void g15r_drawBar (g15canvas *canvas, int x1, int y1, int x2, int y2, int color, int num, int max, int type)
 Draws a completion bar.
void g15r_drawBigNum (g15canvas *canvas, unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, int color, int num)
 Draw a large number.
void g15r_drawCircle (g15canvas *canvas, int x, int y, int r, int fill, int color)
 Draws a circle centered at (x, y) with a radius of r.
void g15r_drawIcon (g15canvas *canvas, char *buf, int my_x, int my_y, int width, int height)
 Draw an icon to the screen from a wbmp buffer.
void g15r_drawLine (g15canvas *canvas, int px1, int py1, int px2, int py2, const int color)
 Draws a line from (px1, py1) to (px2, py2).
void g15r_drawRoundBox (g15canvas *canvas, int x1, int y1, int x2, int y2, int fill, int color)
 Draws a box with rounded corners bounded by (x1, y1) and (x2, y2).
void g15r_drawSprite (g15canvas *canvas, char *buf, int my_x, int my_y, int width, int height, int start_x, int start_y, int total_width)
 Draw a sprite to the screen from a wbmp buffer.
int g15r_getPixel (g15canvas *canvas, unsigned int x, unsigned int y)
 Gets the value of the pixel at (x, y).
void g15r_initCanvas (g15canvas *canvas)
 Clears the canvas and resets the mode switches.
int g15r_loadWbmpSplash (g15canvas *canvas, char *filename)
 Draw a splash screen from 160x43 wbmp file.
char * g15r_loadWbmpToBuf (char *filename, int *img_width, int *img_height)
 Load a wbmp file into a buffer.
void g15r_pixelBox (g15canvas *canvas, int x1, int y1, int x2, int y2, int color, int thick, int fill)
 Draws a box bounded by (x1, y1) and (x2, y2).
void g15r_pixelOverlay (g15canvas *canvas, int x1, int y1, int width, int height, short colormap[])
 Overlays a bitmap of size width x height starting at (x1, y1).
void g15r_pixelReverseFill (g15canvas *canvas, int x1, int y1, int x2, int y2, int fill, int color)
 Fills an area bounded by (x1, y1) and (x2, y2).
void g15r_renderCharacterLarge (g15canvas *canvas, int x, int y, unsigned char character, unsigned int sx, unsigned int sy)
 Renders a character in the large font at (x, y).
void g15r_renderCharacterMedium (g15canvas *canvas, int x, int y, unsigned char character, unsigned int sx, unsigned int sy)
 Renders a character in the meduim font at (x, y).
void g15r_renderCharacterSmall (g15canvas *canvas, int x, int y, unsigned char character, unsigned int sx, unsigned int sy)
 Renders a character in the small font at (x, y).
void g15r_renderString (g15canvas *canvas, unsigned char stringOut[], int row, int size, unsigned int sx, unsigned int sy)
 Renders a string with font size in row.
void g15r_setPixel (g15canvas *canvas, unsigned int x, unsigned int y, int val)
 Sets the value of the pixel at (x, y).
void g15r_ttfLoad (g15canvas *canvas, char *fontname, int fontsize, int face_num)
 Loads a font through the FreeType2 library.
void g15r_ttfPrint (g15canvas *canvas, int x, int y, int fontsize, int face_num, int color, int center, char *print_string)
 Prints a string in a given font.

Variables

unsigned char fontdata_6x4 []
 Font data for the small (6x4) font.
unsigned char fontdata_7x5 []
 Font data for the medium (7x5) font.
unsigned char fontdata_8x8 []
 Font data for the large (8x8) font.

Define Documentation

#define BYTE_SIZE   8
#define G15_BUFFER_LEN   1048

Definition at line 22 of file libg15render.h.

Referenced by g15r_clearScreen(), g15r_initCanvas(), and g15r_loadWbmpSplash().

#define G15_COLOR_BLACK   1
#define G15_COLOR_WHITE   0
#define G15_LCD_HEIGHT   43

Definition at line 24 of file libg15render.h.

Referenced by g15r_getPixel(), and g15r_setPixel().

#define G15_LCD_OFFSET   32

Definition at line 23 of file libg15render.h.

#define G15_LCD_WIDTH   160

Definition at line 25 of file libg15render.h.

Referenced by g15r_getPixel(), and g15r_setPixel().

#define G15_MAX_FACE   5

Definition at line 33 of file libg15render.h.

Referenced by g15r_ttfLoad().

#define G15_PIXEL_FILL   1

Definition at line 32 of file libg15render.h.

#define G15_PIXEL_NOFILL   0

Definition at line 31 of file libg15render.h.

#define G15_TEXT_LARGE   2

Definition at line 30 of file libg15render.h.

Referenced by g15r_renderString().

#define G15_TEXT_MED   1

Definition at line 29 of file libg15render.h.

Referenced by g15r_renderString().

#define G15_TEXT_SMALL   0

Definition at line 28 of file libg15render.h.

Referenced by g15r_renderString().


Typedef Documentation

typedef struct g15canvas g15canvas

This structure holds the data need to render objects to the LCD screen.


Function Documentation

void g15r_clearScreen ( g15canvas canvas,
int  color 
)

Fills the screen with pixels of color.

Clears the screen and fills it with pixels of color

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
color Screen will be filled with this color.

Definition at line 80 of file screen.c.

References g15canvas::buffer, and G15_BUFFER_LEN.

00081 {
00082   memset (canvas->buffer, (color ? 0xFF : 0), G15_BUFFER_LEN);
00083 }

void g15r_drawBar ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  num,
int  max,
int  type 
)

Draws a completion bar.

Given a maximum value, and a value between 0 and that maximum value, calculate and draw a bar showing that percentage.

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x1 Defines leftmost bound of the bar.
y1 Defines uppermost bound of the bar.
x2 Defines rightmost bound of the bar.
y2 Defines bottommost bound of the bar.
color The bar will be drawn this color.
num Number of units relative to max filled.
max Number of units equal to 100% filled.
type Type of bar. 1=solid bar, 2=solid bar with border, 3 = solid bar with I-frame.

Definition at line 337 of file pixel.c.

References g15r_drawLine(), and g15r_pixelBox().

00339 {
00340   float len, length;
00341   int x;
00342   if (max == 0)
00343     return;
00344   if (num > max)
00345     num = max;
00346 
00347   if (type == 2)
00348     {
00349       y1 += 2;
00350       y2 -= 2;
00351       x1 += 2;
00352       x2 -= 2;
00353     }
00354 
00355   len = ((float) max / (float) num);
00356   length = (x2 - x1) / len;
00357 
00358   if (type == 1)
00359     {
00360       g15r_pixelBox (canvas, x1, y1 - type, x2, y2 + type, color ^ 1, 1, 1);
00361       g15r_pixelBox (canvas, x1, y1 - type, x2, y2 + type, color, 1, 0);
00362     }
00363   else if (type == 2)
00364     {
00365       g15r_pixelBox (canvas, x1 - 2, y1 - type, x2 + 2, y2 + type, color ^ 1,
00366                      1, 1);
00367       g15r_pixelBox (canvas, x1 - 2, y1 - type, x2 + 2, y2 + type, color, 1,
00368                      0);
00369     }
00370   else if (type == 3)
00371     {
00372       g15r_drawLine (canvas, x1, y1 - type, x1, y2 + type, color);
00373       g15r_drawLine (canvas, x2, y1 - type, x2, y2 + type, color);
00374       g15r_drawLine (canvas, x1, y1 + ((y2 - y1) / 2), x2,
00375                      y1 + ((y2 - y1) / 2), color);
00376     }
00377   g15r_pixelBox (canvas, x1, y1, (int) ceil (x1 + length), y2, color, 1, 1);
00378 }

void g15r_drawBigNum ( g15canvas canvas,
unsigned int  x1,
unsigned int  y1,
unsigned int  x2,
unsigned int  y2,
int  color,
int  num 
)

Draw a large number.

Draw a large number to a canvas

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x1 Defines leftmost bound of the number.
y1 Defines uppermost bound of the number.
x2 Defines rightmost bound of the number.
y2 Defines bottommost bound of the number.
num The number to be drawn.

Definition at line 545 of file pixel.c.

References g15r_pixelBox().

00546 {
00547     x1 += 2;
00548     x2 -= 2;
00549     
00550     switch(num){
00551         case 0:
00552             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00553             g15r_pixelBox (canvas, x1 +5, y1 +5, x2 -5, y2 - 6, 1 - color, 1, 1);
00554             break;
00555         case 1: 
00556             g15r_pixelBox (canvas, x2-5, y1, x2, y2 , color, 1, 1);
00557             g15r_pixelBox (canvas, x1, y1, x2 -5, y2, 1 - color, 1, 1);
00558             break;
00559         case 2:
00560             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00561             g15r_pixelBox (canvas, x1, y1+5, x2 -5, y1+((y2/2)-3), 1 - color, 1, 1);
00562             g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2 , y2-6, 1 - color, 1, 1);
00563             break;
00564         case 3:
00565             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00566             g15r_pixelBox (canvas, x1, y1+5, x2 -5, y1+((y2/2)-3), 1 - color, 1, 1);
00567             g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
00568             break;
00569         case 4:
00570             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00571             g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2 -5, y2, 1 - color, 1, 1);
00572             g15r_pixelBox (canvas, x1+5, y1, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
00573             break;
00574         case 5:
00575             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00576             g15r_pixelBox (canvas, x1+5, y1+5, x2 , y1+((y2/2)-3), 1 - color, 1, 1);
00577             g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
00578             break;
00579         case 6:
00580             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00581             g15r_pixelBox (canvas, x1+5, y1+5, x2 , y1+((y2/2)-3), 1 - color, 1, 1);
00582             g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
00583             break;
00584         case 7:
00585             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00586             g15r_pixelBox (canvas, x1, y1+5, x2 -5, y2, 1 - color, 1, 1);
00587             break;
00588         case 8:
00589             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00590             g15r_pixelBox (canvas, x1+5, y1+5, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
00591             g15r_pixelBox (canvas, x1+5, y1+((y2/2)+3), x2-5 , y2-6, 1 - color, 1, 1);
00592             break;
00593         case 9:
00594             g15r_pixelBox (canvas, x1, y1, x2, y2 , color, 1, 1);
00595             g15r_pixelBox (canvas, x1+5, y1+5, x2-5 , y1+((y2/2)-3), 1 - color, 1, 1);
00596             g15r_pixelBox (canvas, x1, y1+((y2/2)+3), x2-5 , y2, 1 - color, 1, 1);
00597             break;
00598         case 10: 
00599             g15r_pixelBox (canvas, x2-5, y1+5, x2, y1+10 , color, 1, 1);
00600             g15r_pixelBox (canvas, x2-5, y2-10, x2, y2-5 , color, 1, 1);
00601             break;
00602         case 11: 
00603             g15r_pixelBox (canvas, x1, y1+((y2/2)-2), x2, y1+((y2/2)+2), color, 1, 1);
00604             break;
00605         case 12:
00606             g15r_pixelBox (canvas, x2-5, y2-5, x2, y2 , color, 1, 1);
00607             break;
00608     }
00609 }

void g15r_drawCircle ( g15canvas canvas,
int  x,
int  y,
int  r,
int  fill,
int  color 
)

Draws a circle centered at (x, y) with a radius of r.

Draws a circle centered at (x, y) with a radius of r.

The circle will be filled if fill != 0.

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x Defines horizontal center of the circle.
y Defines vertical center of circle.
r Defines radius of circle.
fill The circle will be filled with color if fill != 0.
color Lines defining the circle will be drawn this color.

Definition at line 203 of file pixel.c.

References g15r_drawLine(), and g15r_setPixel().

00204 {
00205   int xx, yy, dd;
00206 
00207   xx = 0;
00208   yy = r;
00209   dd = 2 * (1 - r);
00210 
00211   while (yy >= 0)
00212     {
00213       if (!fill)
00214         {
00215           g15r_setPixel (canvas, x + xx, y - yy, color);
00216           g15r_setPixel (canvas, x + xx, y + yy, color);
00217           g15r_setPixel (canvas, x - xx, y - yy, color);
00218           g15r_setPixel (canvas, x - xx, y + yy, color);
00219         }
00220       else
00221         {
00222           g15r_drawLine (canvas, x - xx, y - yy, x + xx, y - yy, color);
00223           g15r_drawLine (canvas, x - xx, y + yy, x + xx, y + yy, color);
00224         }
00225       if (dd + yy > 0)
00226         {
00227           yy--;
00228           dd = dd - (2 * yy + 1);
00229         }
00230       if (xx > dd)
00231         {
00232           xx++;
00233           dd = dd + (2 * xx + 1);
00234         }
00235     }
00236 }

void g15r_drawIcon ( g15canvas canvas,
char *  buf,
int  my_x,
int  my_y,
int  width,
int  height 
)

Draw an icon to the screen from a wbmp buffer.

Draw an icon to a canvas

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated in is found.
buf A pointer to the buffer holding the icon to be displayed.
my_x Leftmost boundary of image.
my_y Topmost boundary of image.
width Width of the image in buf.
height Height of the image in buf.

Definition at line 411 of file pixel.c.

References BYTE_SIZE, and g15r_setPixel().

00412 {
00413     int y,x,val;
00414     unsigned int pixel_offset = 0;
00415     unsigned int byte_offset, bit_offset;
00416 
00417     for (y=0; y < height - 1; y++)
00418       for (x=0; x < width - 1; x++)
00419         {
00420                 pixel_offset = y * width + x;
00421                 byte_offset = pixel_offset / BYTE_SIZE;
00422                 bit_offset = 7 - (pixel_offset % BYTE_SIZE);
00423 
00424                 val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
00425                 g15r_setPixel (canvas, x + my_x, y + my_y, val);
00426         }
00427 }

void g15r_drawLine ( g15canvas canvas,
int  px1,
int  py1,
int  px2,
int  py2,
const int  color 
)

Draws a line from (px1, py1) to (px2, py2).

A line of color is drawn from (px1, py1) to (px2, py2).

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
px1 X component of point 1.
py1 Y component of point 1.
px2 X component of point 2.
py2 Y component of point 2.
color Line will be drawn this color.

Definition at line 99 of file pixel.c.

References g15r_setPixel(), and swap().

Referenced by g15r_drawBar(), g15r_drawCircle(), g15r_drawRoundBox(), and g15r_pixelBox().

00101 {
00102   /* 
00103    * Bresenham's Line Algorithm
00104    * http://en.wikipedia.org/wiki/Bresenham's_algorithm
00105    */
00106 
00107   int steep = 0;
00108 
00109   if (abs (py2 - py1) > abs (px2 - px1))
00110     steep = 1;
00111 
00112   if (steep)
00113     {
00114       swap (&px1, &py1);
00115       swap (&px2, &py2);
00116     }
00117 
00118   if (px1 > px2)
00119     {
00120       swap (&px1, &px2);
00121       swap (&py1, &py2);
00122     }
00123 
00124   int dx = px2 - px1;
00125   int dy = abs (py2 - py1);
00126 
00127   int error = 0;
00128   int y = py1;
00129   int ystep = (py1 < py2) ? 1 : -1;
00130   int x = 0;
00131 
00132   for (x = px1; x <= px2; ++x)
00133     {
00134       if (steep)
00135         g15r_setPixel (canvas, y, x, color);
00136       else
00137         g15r_setPixel (canvas, x, y, color);
00138 
00139       error += dy;
00140       if (2 * error >= dx)
00141         {
00142           y += ystep;
00143           error -= dx;
00144         }
00145     }
00146 }

void g15r_drawRoundBox ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  fill,
int  color 
)

Draws a box with rounded corners bounded by (x1, y1) and (x2, y2).

Draws a rounded box around the area bounded by (x1, y1) and (x2, y2).

The box will be filled if fill != 0.

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x1 Defines leftmost bound of the box.
y1 Defines uppermost bound of the box.
x2 Defines rightmost bound of the box.
y2 Defines bottommost bound of the box.
fill The box will be filled with color if fill != 0.
color Lines defining the box will be drawn this color.

Definition at line 252 of file pixel.c.

References G15_COLOR_BLACK, G15_COLOR_WHITE, g15r_drawLine(), and g15r_setPixel().

00254 {
00255   int y, shave = 3;
00256 
00257   if (shave > (x2 - x1) / 2)
00258     shave = (x2 - x1) / 2;
00259   if (shave > (y2 - y1) / 2)
00260     shave = (y2 - y1) / 2;
00261 
00262   if ((x1 != x2) && (y1 != y2))
00263     {
00264       if (fill)
00265         {
00266           g15r_drawLine (canvas, x1 + shave, y1, x2 - shave, y1, color);
00267           for (y = y1 + 1; y < y1 + shave; y++)
00268             g15r_drawLine (canvas, x1 + 1, y, x2 - 1, y, color);
00269           for (y = y1 + shave; y <= y2 - shave; y++)
00270             g15r_drawLine (canvas, x1, y, x2, y, color);
00271           for (y = y2 - shave + 1; y < y2; y++)
00272             g15r_drawLine (canvas, x1 + 1, y, x2 - 1, y, color);
00273           g15r_drawLine (canvas, x1 + shave, y2, x2 - shave, y2, color);
00274           if (shave == 4)
00275             {
00276               g15r_setPixel (canvas, x1 + 1, y1 + 1,
00277                              color ==
00278                              G15_COLOR_WHITE ? G15_COLOR_BLACK :
00279                              G15_COLOR_WHITE);
00280               g15r_setPixel (canvas, x1 + 1, y2 - 1,
00281                              color ==
00282                              G15_COLOR_WHITE ? G15_COLOR_BLACK :
00283                              G15_COLOR_WHITE);
00284               g15r_setPixel (canvas, x2 - 1, y1 + 1,
00285                              color ==
00286                              G15_COLOR_WHITE ? G15_COLOR_BLACK :
00287                              G15_COLOR_WHITE);
00288               g15r_setPixel (canvas, x2 - 1, y2 - 1,
00289                              color ==
00290                              G15_COLOR_WHITE ? G15_COLOR_BLACK :
00291                              G15_COLOR_WHITE);
00292             }
00293         }
00294       else
00295         {
00296           g15r_drawLine (canvas, x1 + shave, y1, x2 - shave, y1, color);
00297           g15r_drawLine (canvas, x1, y1 + shave, x1, y2 - shave, color);
00298           g15r_drawLine (canvas, x2, y1 + shave, x2, y2 - shave, color);
00299           g15r_drawLine (canvas, x1 + shave, y2, x2 - shave, y2, color);
00300           if (shave > 1)
00301             {
00302               g15r_drawLine (canvas, x1 + 1, y1 + 1, x1 + shave - 1, y1 + 1,
00303                              color);
00304               g15r_drawLine (canvas, x2 - shave + 1, y1 + 1, x2 - 1, y1 + 1,
00305                              color);
00306               g15r_drawLine (canvas, x1 + 1, y2 - 1, x1 + shave - 1, y2 - 1,
00307                              color);
00308               g15r_drawLine (canvas, x2 - shave + 1, y2 - 1, x2 - 1, y2 - 1,
00309                              color);
00310               g15r_drawLine (canvas, x1 + 1, y1 + 1, x1 + 1, y1 + shave - 1,
00311                              color);
00312               g15r_drawLine (canvas, x1 + 1, y2 - 1, x1 + 1, y2 - shave + 1,
00313                              color);
00314               g15r_drawLine (canvas, x2 - 1, y1 + 1, x2 - 1, y1 + shave - 1,
00315                              color);
00316               g15r_drawLine (canvas, x2 - 1, y2 - 1, x2 - 1, y2 - shave + 1,
00317                              color);
00318             }
00319         }
00320     }
00321 }

void g15r_drawSprite ( g15canvas canvas,
char *  buf,
int  my_x,
int  my_y,
int  width,
int  height,
int  start_x,
int  start_y,
int  total_width 
)

Draw a sprite to the screen from a wbmp buffer.

Draw a sprite to a canvas

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated in is found.
buf A pointer to the buffer holding a set of sprites.
my_x Leftmost boundary of image.
my_y Topmost boundary of image.
width Width of the sprite.
height Height of the sprite.
start_x X offset for reading sprite from buf.
start_y Y offset for reading sprite from buf.
total_width Width of the set of sprites held in buf.

Definition at line 443 of file pixel.c.

References BYTE_SIZE, and g15r_setPixel().

00444 {
00445     int y,x,val;
00446     unsigned int pixel_offset = 0;
00447     unsigned int byte_offset, bit_offset;
00448 
00449     for (y=0; y < height - 1; y++)
00450       for (x=0; x < width - 1; x++)
00451         {
00452                 pixel_offset = (y + start_y) * total_width + (x + start_x);
00453                 byte_offset = pixel_offset / BYTE_SIZE;
00454                 bit_offset = 7 - (pixel_offset % BYTE_SIZE);
00455 
00456                 val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
00457                 g15r_setPixel (canvas, x + my_x, y + my_y, val);
00458         }
00459 }

int g15r_getPixel ( g15canvas canvas,
unsigned int  x,
unsigned int  y 
)

Gets the value of the pixel at (x, y).

Retrieves the value of the pixel at (x, y)

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x X offset for pixel to be retrieved.
y Y offset for pixel to be retrieved.

Definition at line 29 of file screen.c.

References g15canvas::buffer, BYTE_SIZE, G15_LCD_HEIGHT, and G15_LCD_WIDTH.

Referenced by g15r_pixelReverseFill(), and g15r_setPixel().

00030 {
00031   if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
00032     return 0;
00033 
00034   unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
00035   unsigned int byte_offset = pixel_offset / BYTE_SIZE;
00036   unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
00037 
00038   return (canvas->buffer[byte_offset] & (1 << bit_offset)) >> bit_offset;
00039 }

void g15r_initCanvas ( g15canvas canvas  ) 

Clears the canvas and resets the mode switches.

Clears the screen and resets the mode values for a canvas

Parameters:
canvas A pointer to a g15canvas struct

Definition at line 91 of file screen.c.

References g15canvas::buffer, g15canvas::ftLib, G15_BUFFER_LEN, g15canvas::mode_cache, g15canvas::mode_reverse, and g15canvas::mode_xor.

00092 {
00093   memset (canvas->buffer, 0, G15_BUFFER_LEN);
00094   canvas->mode_cache = 0;
00095   canvas->mode_reverse = 0;
00096   canvas->mode_xor = 0;
00097 #ifdef TTF_SUPPORT
00098   if (FT_Init_FreeType (&canvas->ftLib))
00099     printf ("Freetype couldnt initialise\n");
00100 #endif
00101 }

int g15r_loadWbmpSplash ( g15canvas canvas,
char *  filename 
)

Draw a splash screen from 160x43 wbmp file.

wbmp splash screen loader - assumes image is 160x43

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
filename A string holding the path to the wbmp to be displayed.

Definition at line 387 of file pixel.c.

References g15canvas::buffer, G15_BUFFER_LEN, and g15r_loadWbmpToBuf().

00388 {
00389     int width=0, height=0;
00390     char *buf;
00391      
00392     buf = g15r_loadWbmpToBuf(filename,
00393                              &width,
00394                              &height);
00395 
00396     memcpy (canvas->buffer, buf, G15_BUFFER_LEN);
00397     return 0;
00398 }

char* g15r_loadWbmpToBuf ( char *  filename,
int *  img_width,
int *  img_height 
)

Load a wbmp file into a buffer.

basic wbmp loader - loads a wbmp image into a buffer.

Parameters:
filename A string holding the path to the wbmp to be loaded.
img_width A pointer to an int that will hold the image width on return.
img_height A pointer to an int that will hold the image height on return.

Definition at line 469 of file pixel.c.

References BYTE_SIZE.

Referenced by g15r_loadWbmpSplash().

00470 {
00471     int wbmp_fd;
00472     int retval;
00473     int x,y,val;
00474     char *buf;
00475     unsigned int buflen,header=4;
00476     unsigned char headerbytes[5];
00477     unsigned int pixel_offset = 0;
00478     unsigned int byte_offset, bit_offset;
00479     
00480     wbmp_fd=open(filename,O_RDONLY);
00481     if(!wbmp_fd){
00482         return NULL;
00483     }
00484     
00485     retval=read(wbmp_fd,headerbytes,5);
00486     
00487     if(retval){
00488         if (headerbytes[2] & 1) {
00489             *img_width = ((unsigned char)headerbytes[2] ^ 1) | (unsigned char)headerbytes[3];
00490             *img_height = headerbytes[4];
00491             header = 5;
00492         } else {
00493             *img_width = headerbytes[2];
00494             *img_height = headerbytes[3];
00495         }
00496 
00497         int byte_width = *img_width / 8;
00498         if (*img_width %8)
00499           byte_width++;
00500 
00501         buflen = byte_width * (*img_height);
00502 
00503         buf = (char *)malloc (buflen);
00504         if (buf == NULL)
00505           return NULL;
00506 
00507         if (header == 4)
00508           buf[0]=headerbytes[4];
00509 
00510         retval=read(wbmp_fd,buf+(5-header),buflen);
00511 
00512         close(wbmp_fd);
00513     }
00514 
00515     /* now invert the image */
00516     for (y = 0; y < *img_height; y++)
00517       for (x = 0; x < *img_width; x++)
00518         {
00519                 pixel_offset = y * (*img_width) + x;
00520                 byte_offset = pixel_offset / BYTE_SIZE;
00521                 bit_offset = 7 - (pixel_offset % BYTE_SIZE);
00522 
00523                 val = (buf[byte_offset] & (1 << bit_offset)) >> bit_offset;
00524 
00525                 if (!val)
00526                   buf[byte_offset] = buf[byte_offset] | 1 << bit_offset;
00527                 else
00528                   buf[byte_offset] = buf[byte_offset] & ~(1 << bit_offset);
00529         }
00530 
00531     return buf;
00532 }

void g15r_pixelBox ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  color,
int  thick,
int  fill 
)

Draws a box bounded by (x1, y1) and (x2, y2).

Draws a box around the area bounded by (x1, y1) and (x2, y2).

The box will be filled if fill != 0 and the sides will be thick pixels wide.

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x1 Defines leftmost bound of the box.
y1 Defines uppermost bound of the box.
x2 Defines rightmost bound of the box.
y2 Defines bottommost bound of the box.
color Lines defining the box will be drawn this color.
thick Lines defining the box will be this many pixels thick.
fill The box will be filled with color if fill != 0.

Definition at line 163 of file pixel.c.

References g15r_drawLine(), and g15r_setPixel().

Referenced by g15r_drawBar(), and g15r_drawBigNum().

00165 {
00166   int i = 0;
00167   for (i = 0; i < thick; ++i)
00168     {
00169       g15r_drawLine (canvas, x1, y1, x2, y1, color);    /* Top    */
00170       g15r_drawLine (canvas, x1, y1, x1, y2, color);    /* Left   */
00171       g15r_drawLine (canvas, x2, y1, x2, y2, color);    /* Right  */
00172       g15r_drawLine (canvas, x1, y2, x2, y2, color);    /* Bottom */
00173       x1++;
00174       y1++;
00175       x2--;
00176       y2--;
00177     }
00178 
00179   int x = 0, y = 0;
00180 
00181   if (fill)
00182     {
00183       for (x = x1; x <= x2; ++x)
00184         for (y = y1; y <= y2; ++y)
00185           g15r_setPixel (canvas, x, y, color);
00186     }
00187 
00188 }

void g15r_pixelOverlay ( g15canvas canvas,
int  x1,
int  y1,
int  width,
int  height,
short  colormap[] 
)

Overlays a bitmap of size width x height starting at (x1, y1).

A 1-bit bitmap defined in colormap[] is drawn to the canvas with an upper left corner at (x1, y1) and a lower right corner at (x1+width, y1+height).

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x1 Defines the leftmost bound of the area to be drawn.
y1 Defines the uppermost bound of the area to be drawn.
width Defines the width of the bitmap to be drawn.
height Defines the height of the bitmap to be drawn.
colormap An array containing width*height entries of value 0 for pixel off or != 0 for pixel on.

Definition at line 74 of file pixel.c.

References G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

00076 {
00077   int i = 0;
00078 
00079   for (i = 0; i < (width * height); ++i)
00080     {
00081       int color = (colormap[i] ? G15_COLOR_BLACK : G15_COLOR_WHITE);
00082       int x = x1 + i % width;
00083       int y = y1 + i / width;
00084       g15r_setPixel (canvas, x, y, color);
00085     }
00086 }

void g15r_pixelReverseFill ( g15canvas canvas,
int  x1,
int  y1,
int  x2,
int  y2,
int  fill,
int  color 
)

Fills an area bounded by (x1, y1) and (x2, y2).

The area with an upper left corner at (x1, y1) and lower right corner at (x2, y2) will be filled with color if fill>0 or the current contents of the area will be reversed if fill==0.

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x1 Defines leftmost bound of area to be filled.
y1 Defines uppermost bound of area to be filled.
x2 Defines rightmost bound of area to be filled.
y2 Defines bottommost bound of area to be filled.
fill Area will be filled with color if fill != 0, else contents of area will have color values reversed.
color If fill != 0, then area will be filled if color == 1 and emptied if color == 0.

Definition at line 45 of file pixel.c.

References g15r_getPixel(), and g15r_setPixel().

00047 {
00048   int x = 0;
00049   int y = 0;
00050 
00051   for (x = x1; x <= x2; ++x)
00052     {
00053       for (y = y1; y <= y2; ++y)
00054         {
00055           if (!fill)
00056             color = !g15r_getPixel (canvas, x, y);
00057           g15r_setPixel (canvas, x, y, color);
00058         }
00059     }
00060 }

void g15r_renderCharacterLarge ( g15canvas canvas,
int  x,
int  y,
unsigned char  character,
unsigned int  sx,
unsigned int  sy 
)

Renders a character in the large font at (x, y).

Definition at line 22 of file text.c.

References fontdata_8x8, G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

Referenced by g15r_renderString().

00025 {
00026   int helper = character * 8;   /* for our font which is 8x8 */
00027 
00028   int top_left_pixel_x = sx + col * (8);        /* 1 pixel spacing */
00029   int top_left_pixel_y = sy + row * (8);        /* once again 1 pixel spacing */
00030 
00031   int x, y;
00032   for (y = 0; y < 8; ++y)
00033     {
00034       for (x = 0; x < 8; ++x)
00035         {
00036           char font_entry = fontdata_8x8[helper + y];
00037 
00038           if (font_entry & 1 << (7 - x))
00039             g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
00040                            G15_COLOR_BLACK);
00041           else
00042             g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
00043                            G15_COLOR_WHITE);
00044 
00045         }
00046     }
00047 }

void g15r_renderCharacterMedium ( g15canvas canvas,
int  x,
int  y,
unsigned char  character,
unsigned int  sx,
unsigned int  sy 
)

Renders a character in the meduim font at (x, y).

Definition at line 50 of file text.c.

References fontdata_7x5, G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

Referenced by g15r_renderString().

00053 {
00054   int helper = character * 7 * 5;       /* for our font which is 6x4 */
00055 
00056   int top_left_pixel_x = sx + col * (5);        /* 1 pixel spacing */
00057   int top_left_pixel_y = sy + row * (7);        /* once again 1 pixel spacing */
00058 
00059   int x, y;
00060   for (y = 0; y < 7; ++y)
00061     {
00062       for (x = 0; x < 5; ++x)
00063         {
00064           char font_entry = fontdata_7x5[helper + y * 5 + x];
00065           if (font_entry)
00066             g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
00067                            G15_COLOR_BLACK);
00068           else
00069             g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
00070                            G15_COLOR_WHITE);
00071 
00072         }
00073     }
00074 }

void g15r_renderCharacterSmall ( g15canvas canvas,
int  x,
int  y,
unsigned char  character,
unsigned int  sx,
unsigned int  sy 
)

Renders a character in the small font at (x, y).

Definition at line 77 of file text.c.

References fontdata_6x4, G15_COLOR_BLACK, G15_COLOR_WHITE, and g15r_setPixel().

Referenced by g15r_renderString().

00080 {
00081   int helper = character * 6 * 4;       /* for our font which is 6x4 */
00082 
00083   int top_left_pixel_x = sx + col * (4);        /* 1 pixel spacing */
00084   int top_left_pixel_y = sy + row * (6);        /* once again 1 pixel spacing */
00085 
00086   int x, y;
00087   for (y = 0; y < 6; ++y)
00088     {
00089       for (x = 0; x < 4; ++x)
00090         {
00091           char font_entry = fontdata_6x4[helper + y * 4 + x];
00092           if (font_entry)
00093             g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
00094                            G15_COLOR_BLACK);
00095           else
00096             g15r_setPixel (canvas, top_left_pixel_x + x, top_left_pixel_y + y,
00097                            G15_COLOR_WHITE);
00098 
00099         }
00100     }
00101 }

void g15r_renderString ( g15canvas canvas,
unsigned char  stringOut[],
int  row,
int  size,
unsigned int  sx,
unsigned int  sy 
)

Renders a string with font size in row.

Definition at line 104 of file text.c.

References G15_TEXT_LARGE, G15_TEXT_MED, G15_TEXT_SMALL, g15r_renderCharacterLarge(), g15r_renderCharacterMedium(), and g15r_renderCharacterSmall().

00106 {
00107 
00108   int i = 0;
00109   for (i; stringOut[i] != NULL; ++i)
00110     {
00111       switch (size)
00112         {
00113         case G15_TEXT_SMALL:
00114           {
00115             g15r_renderCharacterSmall (canvas, i, row, stringOut[i], sx, sy);
00116             break;
00117           }
00118         case G15_TEXT_MED:
00119           {
00120             g15r_renderCharacterMedium (canvas, i, row, stringOut[i], sx, sy);
00121             break;
00122           }
00123         case G15_TEXT_LARGE:
00124           {
00125             g15r_renderCharacterLarge (canvas, i, row, stringOut[i], sx, sy);
00126             break;
00127           }
00128         default:
00129           break;
00130         }
00131     }
00132 
00133 }

void g15r_setPixel ( g15canvas canvas,
unsigned int  x,
unsigned int  y,
int  val 
)

Sets the value of the pixel at (x, y).

Sets the value of the pixel at (x, y)

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x X offset for pixel to be set.
y Y offset for pixel to be set.
val Value to which pixel should be set.

Definition at line 50 of file screen.c.

References g15canvas::buffer, BYTE_SIZE, G15_LCD_HEIGHT, G15_LCD_WIDTH, g15r_getPixel(), g15canvas::mode_reverse, and g15canvas::mode_xor.

Referenced by draw_ttf_char(), g15r_drawCircle(), g15r_drawIcon(), g15r_drawLine(), g15r_drawRoundBox(), g15r_drawSprite(), g15r_pixelBox(), g15r_pixelOverlay(), g15r_pixelReverseFill(), g15r_renderCharacterLarge(), g15r_renderCharacterMedium(), and g15r_renderCharacterSmall().

00051 {
00052   if (x >= G15_LCD_WIDTH || y >= G15_LCD_HEIGHT)
00053     return;
00054 
00055   unsigned int pixel_offset = y * G15_LCD_WIDTH + x;
00056   unsigned int byte_offset = pixel_offset / BYTE_SIZE;
00057   unsigned int bit_offset = 7 - (pixel_offset % BYTE_SIZE);
00058 
00059   if (canvas->mode_xor)
00060     val ^= g15r_getPixel (canvas, x, y);
00061   if (canvas->mode_reverse)
00062     val = !val;
00063 
00064   if (val)
00065     canvas->buffer[byte_offset] =
00066       canvas->buffer[byte_offset] | 1 << bit_offset;
00067   else
00068     canvas->buffer[byte_offset] =
00069       canvas->buffer[byte_offset] & ~(1 << bit_offset);
00070 
00071 }

void g15r_ttfLoad ( g15canvas canvas,
char *  fontname,
int  fontsize,
int  face_num 
)

Loads a font through the FreeType2 library.

Load a font for use with FreeType2 font support

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
fontname Absolute pathname to font file to be loaded.
fontsize Size in points for font to be loaded.
face_num Slot into which font face will be loaded.

Definition at line 145 of file text.c.

References g15canvas::ftLib, G15_MAX_FACE, g15canvas::ttf_face, and g15canvas::ttf_fontsize.

00146 {
00147   int errcode = 0;
00148 
00149   if (face_num < 0)
00150     face_num = 0;
00151   if (face_num > G15_MAX_FACE)
00152     face_num = G15_MAX_FACE;
00153 
00154   if (canvas->ttf_fontsize[face_num])
00155     FT_Done_Face (canvas->ttf_face[face_num][0]);       /* destroy the last face */
00156 
00157   if (!canvas->ttf_fontsize[face_num] && !fontsize)
00158     canvas->ttf_fontsize[face_num] = 10;
00159   else
00160     canvas->ttf_fontsize[face_num] = fontsize;
00161 
00162   errcode =
00163     FT_New_Face (canvas->ftLib, fontname, 0, &canvas->ttf_face[face_num][0]);
00164   if (errcode)
00165     {
00166       canvas->ttf_fontsize[face_num] = 0;
00167     }
00168   else
00169     {
00170       if (canvas->ttf_fontsize[face_num]
00171           && FT_IS_SCALABLE (canvas->ttf_face[face_num][0]))
00172         errcode =
00173           FT_Set_Char_Size (canvas->ttf_face[face_num][0], 0,
00174                             canvas->ttf_fontsize[face_num] * 64, 90, 0);
00175     }
00176 }

void g15r_ttfPrint ( g15canvas canvas,
int  x,
int  y,
int  fontsize,
int  face_num,
int  color,
int  center,
char *  print_string 
)

Prints a string in a given font.

Render a string with a FreeType2 font

Parameters:
canvas A pointer to a g15canvas struct in which the buffer to be operated on is found.
x initial x position for string.
y initial y position for string.
fontsize Size of string in points.
face_num Font to be used is loaded in this slot.
color Text will be drawn this color.
center Text will be centered if center == 1 and right justified if center == 2.
print_string Pointer to the string to be printed.

Definition at line 283 of file text.c.

References calc_ttf_centering(), calc_ttf_right_justify(), calc_ttf_true_ypos(), draw_ttf_str(), g15canvas::ttf_face, and g15canvas::ttf_fontsize.

00285 {
00286   int errcode = 0;
00287 
00288   if (canvas->ttf_fontsize[face_num])
00289     {
00290       if (fontsize > 0 && FT_IS_SCALABLE (canvas->ttf_face[face_num][0]))
00291         {
00292           canvas->ttf_fontsize[face_num] = fontsize;
00293           int errcode =
00294             FT_Set_Pixel_Sizes (canvas->ttf_face[face_num][0], 0,
00295                                 canvas->ttf_fontsize[face_num]);
00296           if (errcode)
00297             printf ("Trouble setting the Glyph size!\n");
00298         }
00299       y =
00300         calc_ttf_true_ypos (canvas->ttf_face[face_num][0], y,
00301                             canvas->ttf_fontsize[face_num]);
00302       if (center == 1)
00303         x = calc_ttf_centering (canvas->ttf_face[face_num][0], print_string);
00304       else if (center == 2)
00305         x = calc_ttf_right_justify (canvas->ttf_face[face_num][0], print_string);
00306       draw_ttf_str (canvas, print_string, x, y, color,
00307                     canvas->ttf_face[face_num][0]);
00308     }
00309 }


Variable Documentation

unsigned char fontdata_6x4[]

Font data for the small (6x4) font.

Referenced by g15r_renderCharacterSmall().

unsigned char fontdata_7x5[]

Font data for the medium (7x5) font.

Referenced by g15r_renderCharacterMedium().

unsigned char fontdata_8x8[]

Font data for the large (8x8) font.

Referenced by g15r_renderCharacterLarge().

Generated on Fri Dec 10 14:29:07 2010 for libg15render by  doxygen 1.6.3