You are not logged in.

#1 2008-09-17 04:43:23

SquidMan
Member

Simple, console-type Printf

This printf function works almost exactly like the standard printf function, except it takes a font as well.
Keep in mind that I used Crayon's Printf as the base for this, and have not yet tested it (but it should work!)

Code:

int _GRRLIB_global_x;
int _GRRLIB_global_y;
int _GRRLIB_global_simple_printf_uninitialized=1;

void GRRLIB_SimplePrintf(u8 font[], const char *text,...)
{
    int i, size, n = 0;
    char tmp[1024];
    u16 charHeight = 8, charWidth = 8;

    if(_GRRLIB_global_simple_printf_uninitialized)
    {
        _GRRLIB_global_x=-1*charHeight;
        _GRRLIB_global_y=0;
        _GRRLIB_global_simple_printf_uninitialized=0;
    }

    va_list argp;
    va_start(argp, text);
    size = vsprintf(tmp, text, argp);
    va_end(argp);

    GXColor col = GRRLIB_Splitu32(0xFF000000);
    for(i=0; i<size; i++, n++)
    {
        _GRRLIB_global_x+=charWidth;
        if(tmp[i] == '\n')
        {
            _GRRLIB_global_y += (charHeight);
            n = -1;
            _GRRLIB_global_x=-charHeight;
        }
        else
        {
            GRRLIB_DrawChar(_GRRLIB_global_x+n*charWidth*zoom, _GRRLIB_global_y, charWidth, charHeight, data, 0, 1, 1, tmp[i], 128, col );
        }
    }
}

Working on WiiMU, libmisc (crypto, compression, archiving, configuration), and a little project called GRRLIB+, an unofficial GRRLIB variant with some added functions for simplicity.

Offline

 

#2 2008-09-17 19:40:57

NoNameNo
Administrator

Re: Simple, console-type Printf

always nice too see contributions wink

btw what a grrlib+ for ?? why dont you join us ?? (in fact me wink ) to help me maintenaing grrlib ?? wink

Offline

 

#3 2008-09-17 20:58:29

Crayon
Bad Mother Fucker

Re: Simple, console-type Printf

SquidMan if you really want to make something more general, you could add (not tested):

Code:

        else if(tmp[i] == '\t')
        {   // Tabs are 4 spaces
            GRRLIB_DrawChar(_GRRLIB_global_x+n*charWidth*zoom, _GRRLIB_global_y, charWidth, charHeight, data, 0, 1, 1, ' ', 128, col );
            GRRLIB_DrawChar(_GRRLIB_global_x+n*charWidth*zoom, _GRRLIB_global_y, charWidth, charHeight, data, 0, 1, 1, ' ', 128, col );
            GRRLIB_DrawChar(_GRRLIB_global_x+n*charWidth*zoom, _GRRLIB_global_y, charWidth, charHeight, data, 0, 1, 1, ' ', 128, col );
            GRRLIB_DrawChar(_GRRLIB_global_x+n*charWidth*zoom, _GRRLIB_global_y, charWidth, charHeight, data, 0, 1, 1, ' ', 128, col );
        }

NoNameNo I've been trying to help for months, what append to the repository? What I see is nonameno logged in 21 days ago! I sent you an email with a suggestion on how to use fonts and you never replied. I still want to help and I look forward to use a new release of GRRLIB.

Last edited by Crayon (2008-09-17 20:59:07)

Offline

 

Board footer

Powered by FluxBB