␊ |
#define vram VIDEO(baseAddr)␊ |
␊ |
#define TAB_PIXELS_WIDTH (font->chars[0]->width * 4) // tab = 4 spaces␊ |
␊ |
int lasttime = 0; // we need this for animating maybe␊ |
␊ |
␊ |
|
␉return 1;␊ |
}␊ |
␊ |
pixmap_t* charToPixmap(unsigned char ch, font_t *font) {␊ |
␉unsigned int cha = (unsigned int)ch - 32;␊ |
␉if (cha >= font->count)␊ |
␉␉// return ? if the font for the char doesn't exists␊ |
␉␉cha = '?' - 32;␊ |
␊ |
␉return font->chars[cha] ? font->chars[cha] : NULL;␊ |
}␊ |
␊ |
position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {␊ |
␉pixmap_t* pm = charToPixmap(ch, font);␊ |
␉if (pm && ((p.x + pm->width) < blendInto->width))␊ |
␉{␊ |
␉␉blend(pm, blendInto, p);␊ |
␉␉return pos(p.x + pm->width, p.y);␊ |
␉}␊ |
␉else␊ |
␉␉return p;␊ |
}␊ |
␊ |
void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p)␊ |
{␊ |
␉int i=0;␊ |
␉int y=0; // we need this to support multilines '\n'␊ |
␉int x=0;␊ |
␉position_t current_pos = pos(p.x, p.y);␊ |
␉␊ |
␉for(i=0;i<strlen(ch);i++)␊ |
␉for (i=0; i < strlen(ch); i++)␊ |
␉{␊ |
␉␉int cha=(int)ch[i];␊ |
␉␉␊ |
␉␉cha-=32;␊ |
␉␉␊ |
␉␉// newline ?␊ |
␉␉if( ch[i] == '\n' )␊ |
␉␉if ( ch[i] == '\n' )␊ |
␉␉{␊ |
␉␉␉x = 0;␊ |
␉␉␉y += font->height;␊ |
␉␉␉current_pos.x = p.x;␊ |
␉␉␉current_pos.y += font->height;␊ |
␉␉␉continue;␊ |
␉␉}␊ |
␉␉␊ |
␉␉// tab ?␊ |
␉␉if( ch[i] == '\t' )␊ |
␉␉␉x+=(font->chars[0]->width*5);␊ |
␉␉if ( ch[i] == '\t' )␊ |
␉␉{␊ |
␉␉␉current_pos.x += TAB_PIXELS_WIDTH;␊ |
␉␉␉continue;␊ |
␉␉}␊ |
␉␉␊ |
␉␉if(font->chars[cha] && ((x + font->chars[cha]->width) < blendInto->width))␊ |
␉␉␉blend(font->chars[cha], blendInto, pos(p.x+x, p.y+y));␊ |
␉␉␊ |
␉␉x += font->chars[cha]->width;␊ |
␉␉current_pos = drawChar(ch[i], font, blendInto, current_pos);␊ |
␉}␊ |
}␊ |
␊ |
|
{␊ |
␉int i = 0;␊ |
␉int width = 0;␊ |
␉int max_width = 0;␊ |
␊ |
␉// calculate the width in pixels␊ |
␉for(i=0;i<strlen(text);i++)␊ |
␉␉width += font->chars[text[i]-32]->width;␊ |
␉for (i=0; i < strlen(text); i++) {␊ |
␉␉if (text[i] == '\n')␊ |
␉␉␉width = 0;␊ |
␉␉else if (text[i] == '\t')␊ |
␉␉␉width += TAB_PIXELS_WIDTH;␊ |
␉␉else␊ |
␉␉{␊ |
␉␉␉pixmap_t* pm = charToPixmap(text[i], font);␊ |
␉␉␉if (pm)␊ |
␉␉␉␉width += pm->width;␊ |
␉␉}␊ |
␉␉if (width > max_width)␊ |
␉␉␉max_width = width;␊ |
␉}␊ |
␊ |
␉p.x = ( p.x - ( width / 2 ) );␊ |
␉p.x = ( p.x - ( max_width / 2 ) );␊ |
␉p.y = ( p.y - ( font->height / 2 ) ); ␊ |
␉␊ |
␉if ( p.x == -6 )␊ |
␉{␊ |
␉␉p.x = 0;␊ |
␉}␊ |
␉␊ |
␉for(i=0;i<strlen(text);i++)␊ |
␉{␊ |
␉␉int cha=(int)text[i];␊ |
␉␉␊ |
␉␉cha-=32;␊ |
␊ |
␉␉if(font->chars[cha])␊ |
␉␉{␊ |
␉␉␉blend(font->chars[cha], blendInto, p);␊ |
␉␉␉p.x += font->chars[cha]->width;␊ |
␉␉}␊ |
␉}␊ |
␉␊ |
␉drawStr(text, font, blendInto, p);␊ |
}␊ |
␊ |
int initFont(font_t *font, image_t *data)␊ |
|
␉␊ |
␉bool monospaced = false;␊ |
␉␊ |
␉font->height = data->image->height;␉␊ |
␉font->height = data->image->height;␊ |
␊ |
␉for( x = 0; x < data->image->width; x++)␊ |
␉for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)␊ |
␉{␊ |
␉␉start = end;␊ |
␉␉␉␉␊ |
|
␉␉}␊ |
␉}␊ |
␊ |
␉for (x = count; x < CHARACTERS_COUNT; x++)␊ |
␉␉font->chars[x] = NULL;␊ |
␊ |
␉if(monospaced)␊ |
␉␉font->width = 0;␊ |
␊ |
␉font->count = count;␊ |
␊ |
␉return 0;␊ |
}␊ |
␊ |