// Filename : FONT.C // Coded by : Scott Evans // Created/Modified : 25/2/98 // Description : New font stuff #include extern BRIGHTNESS brightness[]; // Function : SetFontInfo() // Coded by : Scott Evans // Created/Modified : 25/2/98 // Description : Initialises a font // Parameters : finfo - pointer to font structure // sinfo - texture details // l - object list to use // cw,ch - width and height of one character // c - colour of font // sx,sy - scale value for font // Returns : None // Notes : None void SetFontInfo(FONT_INFO *finfo,SPRITE_DATA_INFO *sinfo,OBJECT_LIST_HEADER *l,u_byte cw,u_byte ch,BRIGHTNESS *c,u_long sx,u_long sy) { finfo->cw=cw; finfo->ch=ch; finfo->info=sinfo; finfo->list=l; finfo->brightness.r=c->r; finfo->brightness.g=c->g; finfo->brightness.b=c->b; finfo->sx=sx; finfo->sy=sy; } // Function : MapCharacterToImage() // Coded by : Scott Evans // Created/Modified : 25/2/98 // Description : Finds correct sprite image for character // Parameters : s - pointer to character // Returns : Number of image in sprite bank used for this character // Notes : None u_byte MapCharacterToImage(u_byte *s) { u_byte n; switch(*s) { case 'A' ... 'Z': n=*s-'A'+FIRST_UPPER_CASE_LETTER; break; case 'a' ... 'z': n=*s-'a'+FIRST_LOWER_CASE_LETTER; break; case '0' ... '9': n=*s-'0'+FIRST_NUMBER; break; case ',': n=COMMA; break; case '.': n=FULL_STOP; break; case '?': n=QUESTION_MARK; break; case ':': n=COLON; break; case '(': n=OPEN_BRACKET; break; case ')': n=CLOSE_BRACKET; break; case ' ': n=SPACE; break; case '\n': n=NEW_LINE; break; case '^': n=PSX_TRIANGLE; break; case '&': n=PSX_CROSS; break; case '@': n=PSX_SQUARE; break; case '~': n=PSX_CIRCLE; break; default: #ifdef DEBUG_INFO PrintFM("Failed\n"); #endif n=-1; break; } return(n); } // Function : PrintString() // Coded by : Scott Evans // Created/Modified : 25/2/98 // Description : Print a text string // Parameters : s - pointer to character string // f - pointer to font information // pos - position of string // Returns : Number of characters generated // Notes : Does not set position of characters OBJECT_STRING *PrintString(u_byte *s,FONT_INFO *f,VECTOR *pos,OBJECT_STRING *os) { OBJECT *new_object; SPRITE *sp; u_long x,y; byte n; u_byte l=0; x=y=0; while(*s) { // Work out which texture to use n=MapCharacterToImage(s); s++; // Is it a character we can display if(n!=NEW_LINE && n!=SPACE && n>=0) { if((new_object=CreateObject(f->list,SPRITE_OBJECT))) { l++; if(l==1) os->start=new_object; // Initialise the object sp=&new_object->type.s; sp->info=f->info->offsets; sp->animation_on=0; new_object->visible=1; new_object->can_move=1; new_object->extra[0]=0; new_object->blink=0; new_object->ot_offset=1; SetObjectsPosition(new_object,pos->vx+x,pos->vy+y,pos->vz); SetObjectsWidthHeight(new_object,f->info->offsets[n].w,f->info->offsets[n].h); SetGsSPRITE(&sp->s,0,new_object->screen.vx,new_object->screen.vy, new_object->w,new_object->h,f->info->tpage, f->info->offsets[n].u,f->info->offsets[n].v, f->info->cx,f->info->cy+f->info->offsets[n].clut_y,0x80,0x80,0x80,0,0,f->sx,f->sy,0); // If it is a PSX button symbol don't use font brightness if(nbrightness); else SetObjectsBrightness(new_object,&brightness[NORMAL_TEXT_BRIGHTNESS]); } } x+=f->cw; if(n==NEW_LINE) { x=0; y+=f->ch; } } os->length=l; return(os); }