
#include "generic.h"
#include "lfptypes.h"

#include "fontcode.h"

#include "textcode.h"

#define MAX_TCEL 30

static struct {
SI xco;
SI yco;
TXTCEL_T *cel;
} tCelList[MAX_TCEL];



TXTCEL_T *add_text_cel(char *string, SI x, SI y)
{
SI i;
TXTCEL_T *tCel;

    tCel = InitTxtCel(NULL, 0, FONT_07, FPAL_07_NUM, FFLG_XL | FFLG_YC);
	ClearTxtCel( tCel); 
    WriteTxtCel( tCel, string);

    for (i=0 ;i<MAX_TCEL ;i++ )
    {
        if ( tCelList[i].cel == NULL)
        {
            tCelList[i].cel = tCel;
            tCelList[i].xco = x;
            tCelList[i].yco = y;
			//printf("added tCel %x, no %d\n\n", tCel, i);
			return tCel;
        }
    }
    DIAGNOSE("No cels left\n");

    return NULL;
}


void delete_text_cel(TXTCEL_T *tCel)
{
SI i;

    for (i=0 ;i<MAX_TCEL ;i++ )
    {
        if ( tCelList[i].cel == tCel)
        {
			FreeTxtCel(tCel);
			MemFree(tCel);
            tCelList[i].cel = NULL;

			//printf("deleted tCel %x, no %d\n", tCel, i);
            return;
        }
    }
    printf("\nCouldn't find tCel %x !\n\n", tCel);
}

void render_tcels(void)
{
SI i;

    for (i=0 ;i<MAX_TCEL ;i++ )
    {
        if ( tCelList[i].cel)
        {
            DrawTxtCel(tCelList[i].cel, tCelList[i].xco, tCelList[i].yco);
        }
    }
}











