From b39a42b909dfb1c174044cf977d272f94445b18e Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Tue, 9 Sep 2003 05:30:34 +0000 Subject: [lcd4linux @ 2003-09-09 05:30:33 by reinelt] even more icons stuff --- icon.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 25 deletions(-) (limited to 'icon.c') diff --git a/icon.c b/icon.c index ae5e332..12e5a22 100644 --- a/icon.c +++ b/icon.c @@ -1,4 +1,4 @@ -/* $Id: icon.c,v 1.3 2003/09/01 04:09:34 reinelt Exp $ +/* $Id: icon.c,v 1.4 2003/09/09 05:30:34 reinelt Exp $ * * generic icon and heartbeat handling * @@ -20,6 +20,9 @@ * * * $Log: icon.c,v $ + * Revision 1.4 2003/09/09 05:30:34 reinelt + * even more icons stuff + * * Revision 1.3 2003/09/01 04:09:34 reinelt * icons nearly finished, but MatrixOrbital only * @@ -32,6 +35,24 @@ * */ +/* + * exported functions: + * + * int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, + * void(*defchar)(int ascii, char *bitmap)) + * initializes all icons stuff and reads the bitmaps from config file. + * + * void icon_clear(void) + * clears the icon framebuffer + * + * int icon_draw (int num, int seq, int row, int col) + * puts icon #num sequence #seq at position row, col in the icon framebuffer + * + * int icon_peek (int row, int col) + * returns icon# or -1 if none from position row, col + * + */ + #include #include @@ -42,6 +63,12 @@ #include "icon.h" +typedef struct BITMAP { + int nData; + int lData; + char *Data; +} BITMAP; + static int ROWS=0; static int COLS=0; static int XRES=0; @@ -49,35 +76,49 @@ static int YRES=0; static int CHARS; static int ICONS=0; -static int *Screen=NULL; -static char *Bitmap=NULL; +static int *Screen=NULL; +static struct BITMAP *Bitmap=NULL; +static void(*Defchar)(int ascii, char *bitmap); + -static int icon_read_bitmap (int num, char *bitmap) +static int icon_read_bitmap (int num) { - int row, col, len; + struct BITMAP *bm = Bitmap+num; + int row, n; char key[15]; - char *val; - char map; + char *val, *v; + char *map; for (row=0; row len=%d", num, row, val, len); - for (col=0; colData+row; + n=0; + for (v=val; *v!='\0'; v++) { + if (n>=bm->nData) { + bm->nData++; + bm->Data=realloc(bm->Data, bm->nData*YRES*sizeof(char)); + memset (bm->Data+n*YRES, 0, YRES*sizeof(char)); + map=bm->Data+n*YRES+row; + } + switch (*v) { + case '|': + n++; + map+=YRES; + break; + case '*': + (*map)<<=1; + (*map)|=1; + break; + default: + (*map)<<=1; } } - *(bitmap+row-1)=map; } return 0; } - int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, void(*defchar)(int ascii, char *bitmap)) { @@ -108,19 +149,23 @@ int icon_init (int rows, int cols, int xres, int yres, int chars, int icons, free (Bitmap); } - if ((Bitmap=malloc(YRES*icons*sizeof(*Bitmap)))==NULL) { - error ("icon bitmap allocation failed: out of memory"); + if ((Bitmap=malloc(icons*sizeof(*Bitmap)))==NULL) { + error ("icon allocation failed: out of memory"); return -1; } - - memset (Bitmap, 0, YRES*icons*sizeof(*Bitmap)); + + Defchar=defchar; for (n=0; n=ICONS) return -1; + if (row>=ROWS) return -1; + if (col>=COLS) return -1; + + seq%=Bitmap[num].nData; + if (seq!=Bitmap[num].lData) { + Bitmap[num].lData=seq; + Defchar (CHARS-num-1, Bitmap[num].Data+seq*YRES); + } + + // just redefine icon? + if (row<0 || col<0) return 0; + // icons use last ascii codes from userdef chars Screen[row*COLS+col]=CHARS-num-1; + return 0; } -- cgit v1.2.3