/* * SCR_RegisterFont */ struct mufont_s *SCR_RegisterFont( const char *name ) { mufont_t *font; const char *extension; size_t len; extension = COM_FileExtension( name ); len = ( extension ? extension - name - 1 : strlen( name ) ); for( font = gs_muFonts; font; font = font->next ) { if( !Q_strnicmp( font->name, name, len ) ) { font->shader = R_RegisterPic( font->shadername ); return font; } } font = SCR_LoadMUFont( name, len ); if( !font ) { return NULL; } font->next = gs_muFonts; gs_muFonts = font; return font; }
static void Parse_Bitmap(menuFrameWork_t *menu) { static const cmd_option_t o_bitmap[] = { { "s:", "status" }, { "N:", "altname" }, { NULL } }; menuBitmap_t *b; char *status = NULL, *altname = NULL; int c; while ((c = Cmd_ParseOptions(o_bitmap)) != -1) { switch (c) { case 's': status = cmd_optarg; break; case 'N': altname = cmd_optarg; break; default: return; } } if (Cmd_Argc() - cmd_optind < 2) { Com_Printf("Usage: %s <name> <command>\n", Cmd_Argv(0)); return; } if (!altname) altname = va("%s_sel", Cmd_Argv(cmd_optind)); b = UI_Mallocz(sizeof(*b)); b->generic.type = MTYPE_BITMAP; b->generic.activate = Activate; b->generic.status = UI_CopyString(status); b->cmd = UI_CopyString(Cmd_ArgsFrom(cmd_optind + 1)); b->pics[0] = R_RegisterPic(Cmd_Argv(cmd_optind)); b->pics[1] = R_RegisterPic(altname); R_GetPicSize(&b->generic.width, &b->generic.height, b->pics[0]); Menu_AddItem(menu, b); }
static void Parse_Plaque(menuFrameWork_t *menu) { if (Cmd_Argc() < 2) { Com_Printf("Usage: %s <plaque> [logo]\n", Cmd_Argv(0)); return; } menu->plaque = R_RegisterPic(Cmd_Argv(1)); if (menu->plaque) { R_GetPicSize(&menu->plaque_rc.width, &menu->plaque_rc.height, menu->plaque); } if (Cmd_Argc() > 2) { menu->logo = R_RegisterPic(Cmd_Argv(2)); if (menu->logo) { R_GetPicSize(&menu->logo_rc.width, &menu->logo_rc.height, menu->logo); } } }
static void Parse_Background(menuFrameWork_t *menu) { char *s = Cmd_Argv(1); if (SCR_ParseColor(s, &menu->color)) { menu->image = 0; menu->transparent = menu->color.u8[3] != 255; } else { menu->image = R_RegisterPic(s); menu->transparent = R_GetPicSize(NULL, NULL, menu->image); } }
static void Parse_Banner(menuFrameWork_t *menu) { if (Cmd_Argc() < 2) { Com_Printf("Usage: %s <banner>\n", Cmd_Argv(0)); return; } menu->banner = R_RegisterPic(Cmd_Argv(1)); if (menu->banner) { R_GetPicSize(&menu->banner_rc.width, &menu->banner_rc.height, menu->banner); } }
static qboolean Parse_File(const char *path, int depth) { char *raw, *data, *p, *cmd; int argc; menuFrameWork_t *menu = NULL; qerror_t ret; ret = FS_LoadFile(path, (void **)&raw); if (!raw) { if (ret != Q_ERR_NOENT || depth) { Com_WPrintf("Couldn't %s %s: %s\n", depth ? "include" : "load", path, Q_ErrorString(ret)); } return qfalse; } data = raw; COM_Compress(data); while (*data) { p = strchr(data, '\n'); if (p) { *p = 0; } Cmd_TokenizeString(data, qtrue); argc = Cmd_Argc(); if (argc) { cmd = Cmd_Argv(0); if (menu) { if (!strcmp(cmd, "end")) { if (menu->nitems) { List_Append(&ui_menus, &menu->entry); } else { Com_WPrintf("Menu entry without items\n"); menu->free(menu); } menu = NULL; } else if (!strcmp(cmd, "title")) { if (menu->title) { Z_Free(menu->title); } menu->title = UI_CopyString(Cmd_Argv(1)); } else if (!strcmp(cmd, "plaque")) { Parse_Plaque(menu); } else if (!strcmp(cmd, "banner")) { Parse_Banner(menu); } else if (!strcmp(cmd, "background")) { Parse_Background(menu); } else if (!strcmp(cmd, "style")) { Parse_Style(menu); } else if (!strcmp(cmd, "values")) { Parse_Spin(menu, MTYPE_SPINCONTROL); } else if (!strcmp(cmd, "strings")) { Parse_Spin(menu, MTYPE_STRINGS); } else if (!strcmp(cmd, "pairs")) { Parse_Pairs(menu); } else if (!strcmp(cmd, "range")) { Parse_Range(menu); } else if (!strcmp(cmd, "action")) { Parse_Action(menu); } else if (!strcmp(cmd, "bitmap")) { Parse_Bitmap(menu); } else if (!strcmp(cmd, "bind")) { Parse_Bind(menu); } else if (!strcmp(cmd, "savegame")) { Parse_Savegame(menu, MTYPE_SAVEGAME); } else if (!strcmp(cmd, "loadgame")) { Parse_Savegame(menu, MTYPE_LOADGAME); } else if (!strcmp(cmd, "toggle")) { Parse_Toggle(menu); } else if (!strcmp(cmd, "field")) { Parse_Field(menu); } else if (!strcmp(cmd, "blank")) { Parse_Blank(menu); } else { Com_WPrintf("Unknown keyword '%s'\n", cmd); } } else { if (!strcmp(cmd, "begin")) { char *s = Cmd_Argv(1); if (!*s) { Com_WPrintf("Expected menu name after '%s'\n", cmd); break; } menu = UI_FindMenu(s); if (menu) { if (menu->free) { menu->free(menu); } List_Remove(&menu->entry); } menu = UI_Mallocz(sizeof(*menu)); menu->name = UI_CopyString(s); menu->push = Menu_Push; menu->pop = Menu_Pop; menu->free = Menu_Free; menu->image = uis.backgroundHandle; menu->color.u32 = uis.color.background.u32; menu->transparent = uis.transparent; } else if (!strcmp(cmd, "include")) { char *s = Cmd_Argv(1); if (!*s) { Com_WPrintf("Expected file name after '%s'\n", cmd); break; } if (depth == 16) { Com_WPrintf("Includes too deeply nested\n"); } else { Parse_File(s, depth + 1); } } else if (!strcmp(cmd, "color")) { Parse_Color(); } else if (!strcmp(cmd, "background")) { char *s = Cmd_Argv(1); if (SCR_ParseColor(s, &uis.color.background)) { uis.backgroundHandle = 0; uis.transparent = uis.color.background.u8[3] != 255; } else { uis.backgroundHandle = R_RegisterPic(s); uis.transparent = R_GetPicSize(NULL, NULL, uis.backgroundHandle); } } else if (!strcmp(cmd, "font")) { uis.fontHandle = R_RegisterFont(Cmd_Argv(1)); } else if (!strcmp(cmd, "cursor")) { uis.cursorHandle = R_RegisterPic(Cmd_Argv(1)); R_GetPicSize(&uis.cursorWidth, &uis.cursorHeight, uis.cursorHandle); } else if (!strcmp(cmd, "weapon")) { Cmd_ArgvBuffer(1, uis.weaponModel, sizeof(uis.weaponModel)); } else { Com_WPrintf("Unknown keyword '%s'\n", cmd); break; } } } if (!p) { break; } data = p + 1; } FS_FreeFile(raw); if (menu) { Com_WPrintf("Menu entry without 'end' terminator\n"); menu->free(menu); } return qtrue; }
//================= //SCR_RegisterConsoleMedia //================= void SCR_RegisterConsoleMedia( void ) { cls.whiteShader = R_RegisterPic( "gfx/ui/white" ); cls.consoleShader = R_RegisterPic( "gfx/ui/console" ); SCR_InitFonts(); }
static mufont_t *SCR_LoadMUFont( const char *name, size_t len ) { size_t filename_size; char *filename; qbyte *buf; char *ptr, *token, *start; int filenum; int length; mufont_t *font; struct shader_s *shader; int numchar; int x, y, w, h; filename_size = strlen( "fonts/" ) + len + strlen( ".tga" ) + 1; filename = Mem_TempMalloc( filename_size ); Q_snprintfz( filename, filename_size, "fonts/%s", name ); // load the shader COM_ReplaceExtension( filename, ".tga", filename_size ); shader = R_RegisterPic( filename ); if( !shader ) { Mem_TempFree( filename ); return NULL; } // load the font description COM_ReplaceExtension( filename, ".wfd", filename_size ); // load the file length = FS_FOpenFile( filename, &filenum, FS_READ ); if( length == -1 ) { Mem_TempFree( filename ); return NULL; } Mem_TempFree( filename ); buf = Mem_TempMalloc( length + 1 ); length = FS_Read( buf, length, filenum ); FS_FCloseFile( filenum ); if( !length ) { Mem_TempFree( buf ); return NULL; } // seems to be valid. Allocate it font = (mufont_t *)Font_Alloc( sizeof( mufont_t ) ); font->shader = shader; font->name = Font_Alloc( len + 1 ); Q_strncpyz( font->name, name, len + 1 ); // proceed ptr = ( char * )buf; // get texture width and height token = COM_Parse( &ptr ); if( !token[0] ) goto error; font->imagewidth = atoi( token ); token = COM_Parse( &ptr ); if( !token[0] ) goto error; font->imageheight = atoi( token ); font->numchars = MIN_FONT_CHARS; // get the number of chars start = ptr; while( ptr ) { // "<char>" "<x>" "<y>" "<width>" "<height>" token = COM_Parse( &ptr ); if( !token[0] ) break; numchar = atoi( token ); if( numchar <= 0 ) break; x = atoi( COM_Parse( &ptr ) ), y = atoi( COM_Parse( &ptr ) ); w = atoi( COM_Parse( &ptr ) ), h = atoi( COM_Parse( &ptr ) ); if( numchar < 32 || numchar >= MAX_FONT_CHARS ) continue; if( ( unsigned int )( numchar + 1 ) > font->numchars ) font->numchars = ( unsigned int )numchar + 1; } if( !font->numchars ) goto error; font->chars = Font_Alloc( font->numchars * sizeof( muchar_t ) ); // get the chars ptr = start; while( ptr ) { token = COM_Parse( &ptr ); if( !token[0] ) break; numchar = atoi( token ); if( numchar <= 0 ) break; x = atoi( COM_Parse( &ptr ) ), y = atoi( COM_Parse( &ptr ) ); w = atoi( COM_Parse( &ptr ) ), h = atoi( COM_Parse( &ptr ) ); if( numchar < 32 || ( unsigned int )numchar >= font->numchars ) continue; font->chars[numchar].x = x; font->chars[numchar].y = y; font->chars[numchar].width = w; font->chars[numchar].height = h; // create the texture coordinates font->chars[numchar].s1 = ( (float)x )/(float)font->imagewidth; font->chars[numchar].s2 = ( (float)( x + w ) )/(float)font->imagewidth; font->chars[numchar].t1 = ( (float)y )/(float)font->imageheight; font->chars[numchar].t2 = ( (float)( y + h ) )/(float)font->imageheight; } // mudFont is not always giving a proper size to the space character font->chars[' '].width = font->chars['-'].width; // height is the same for every character font->fontheight = font->chars['a'].height; // if REPLACEMENT_CHAR is not present in this font, copy '?' to that position if( !( font->chars[REPLACEMENT_CHAR].height ) ) font->chars[REPLACEMENT_CHAR] = font->chars['?']; Mem_TempFree( buf ); return font; error: if( font->chars ) Font_Free( font->chars ); if( font->name ) Font_Free( font->name ); Font_Free( font ); Mem_TempFree( buf ); return NULL; }