CGUIFont* GUIFontManager::GetDefaultFont(bool border)
{
  // first find "font13" or "__defaultborder__"
  unsigned int font13index = m_vecFonts.size();
  CGUIFont *font13border = NULL;
  for (unsigned int i = 0; i < m_vecFonts.size(); i++)
  {
    CGUIFont* font = m_vecFonts[i];
    if (font->GetFontName() == "font13")
      font13index = i;
    else if (font->GetFontName() == "__defaultborder__")
      font13border = font;
  }
  // no "font13" means no default font is found - use the first font found.
  if (font13index == m_vecFonts.size())
  {
    if (m_vecFonts.empty())
      return NULL;
    font13index = 0;
  }

  if (border)
  {
    if (!font13border)
    { // create it
      CGUIFont *font13 = m_vecFonts[font13index];
      OrigFontInfo fontInfo = m_vecFontInfo[font13index];
      font13border = LoadTTF("__defaultborder__", fontInfo.fileName, 0xFF000000, 0, fontInfo.size, font13->GetStyle(), true, 1.0f, fontInfo.aspect, &fontInfo.sourceRes, fontInfo.preserveAspect);
    }
    return font13border;
  }
  return m_vecFonts[font13index];
}
//! returns the font
IGUIFont* CGUIEnvironment::getFont(const c8* filename)
{
	// search existing font

	SFont f;
	if (!filename)
		filename = "";

	f.Filename = filename;
	f.Filename.make_lower();

	s32 index = Fonts.binary_search(f);
	if (index != -1)
		return Fonts[index].Font;

	// not existing yet. try to load font.

	CGUIFont* font = new CGUIFont(Driver);
	if (!font->load(filename))
	{
		font->drop();
		return 0;
	}

	// add to fonts.

	f.Font = font;
	Fonts.push_back(f);

	return font;
}
void CGUIEnvironment::loadBuidInFont()
{
	const c8* filename = "#DefaultFont";

#ifdef PPC
	for (int i=0; i<sizeof(BuildInFontData)/sizeof(s32); i++) BuildInFontData[i] = OSReadSwapInt32(&BuildInFontData[i],0);
#endif

	io::IReadFile* file = io::createMemoryReadFile(BuildInFontData, BuildInFontDataSize, filename, false);

	CGUIFont* font = new CGUIFont(Driver);
	if (!font->load(file))
	{
		os::Printer::log("Error: Could not load built-in Font.", ELL_ERROR);
		font->drop();
		file->drop();
		return;
	}

	SFont f;
	f.Filename = filename;
	f.Font = font;
	Fonts.push_back(f);

	file->drop();
}
Exemple #4
0
void CSEdDesktop::AddStartMenu()
{
	CGUIMenu* menu;
	CGUIMenuItem* mi;

	menu = new CGUIMenu(185);
	menu->SetPictureStripSize(44);
	menu->SetMenuPictureSize(40);

	mi = new CGUIMenuItem(menu,0,0,185,40,"Quit",new CGUIRectHost(0,0,styleSet->Get("LebkyTB3")->GetTexture(0)));
	CGUIFont *font = new CGUIFont();
	font->CreateFont(ARIAL,13);
	mi->SetLabelFormated("Quit",font);
	mi->SetShortCut("F4",false,false,false,VK_F4,true);
	font->Release();
	menu->AddMenuItem(0,mi);

	mi->AcceptEvent(mainGUI->handler->GetID(),EClicked);
	mainGUI->handler->icons[2]=mi->GetID();

	mi = new CGUIMenuItem(menu,0,0,185,40,"Script Editor",new CGUIRectHost(0,0,styleSet->Get("StartMenu_Script")->GetTexture(0)));
	font = new CGUIFont();
	font->CreateFont(ARIAL,13);
	mi->SetLabelFormated("Script Editor",font);
	mi->SetShortCut("F1",false,false,false,VK_F1,true);
	font->Release();
	menu->AddMenuItem(0,mi);

	mi->AcceptEvent(mainGUI->handler->GetID(),EClicked);
	mainGUI->handler->icons[3]=mi->GetID();


	mi = new CGUIMenuItem(menu,0,0,185,40,"Level Editor",new CGUIRectHost(0,0,styleSet->Get("StartMenu_Level")->GetTexture(0)));
	font = new CGUIFont();
	font->CreateFont(ARIAL,13);
	mi->SetLabelFormated("Level Editor",font);
	mi->SetShortCut("F2",false,false,false,VK_F2,true);
	font->Release();
	menu->AddMenuItem(0,mi);

	mi->AcceptEvent(mainGUI->handler->GetID(),EClicked);
	mainGUI->handler->icons[0]=mi->GetID();


	mi = new CGUIMenuItem(menu,0,0,185,60,"Game",new CGUIRectHost(0,0,styleSet->Get("StartMenu_Game")->GetTexture(0)));
	font = new CGUIFont();
	font->CreateFont(ARIAL,20);
	mi->SetLabelFormated("GAME",font);
	mi->SetShortCut("F3",false,false,false,VK_F3,true);
	font->Release();
	menu->AddMenuItem(0,mi);

	mi->AcceptEvent(mainGUI->handler->GetID(),EClicked);
	mainGUI->handler->icons[1]=mi->GetID();


	startMenu=menu;

}
CGUIFont* GUIFontManager::GetFont(const CStdString& strFontName, bool fallback /*= true*/)
{
  for (int i = 0; i < (int)m_vecFonts.size(); ++i)
  {
    CGUIFont* pFont = m_vecFonts[i];
    if (pFont->GetFontName().Equals(strFontName))
      return pFont;
  }
  // fall back to "font13" if we have none
  if (fallback && !strFontName.empty() && !strFontName.Equals("-") && !strFontName.Equals("font13"))
    return GetFont("font13");
  return NULL;
}
Exemple #6
0
CGUIFont* GUIFontManager::GetFont(const std::string& strFontName, bool fallback /*= true*/)
{
  for (int i = 0; i < (int)m_vecFonts.size(); ++i)
  {
    CGUIFont* pFont = m_vecFonts[i];
    if (StringUtils::EqualsNoCase(pFont->GetFontName(), strFontName))
      return pFont;
  }
  // fall back to "font13" if we have none
  if (fallback && !strFontName.empty() && strFontName != "-" && !StringUtils::EqualsNoCase(strFontName, "font13"))
    return GetFont("font13");
  return NULL;
}
Exemple #7
0
void GUIFontManager::ReloadTTFFonts(void)
{
   g_graphicsContext.SetScalingResolution(m_skinResolution, 0, 0, true);
   
   for (unsigned int i = 0; i < m_vecFonts.size(); i++)
   {
      CGUIFont* font = m_vecFonts[i];
      OrigFontInfo fontInfo = m_vecFontInfo[i];      
      CGUIFontTTF* currentFontTTF = font->GetFont();
      
      float aspect = fontInfo.aspect;
      int iSize = fontInfo.size;
      CStdString& strPath = fontInfo.fontFilePath;
      CStdString& strFilename = fontInfo.fileName;

      // #ifdef PRE_SKIN_VERSION_2_1_COMPATIBILITY
      if (g_SkinInfo.GetVersion() > 2.0 && m_skinResolution == PAL_16x9 || m_skinResolution == PAL60_16x9 || m_skinResolution == NTSC_16x9 || m_skinResolution == HDTV_480p_16x9)
        aspect *= 0.75f;
   
      aspect *= g_graphicsContext.GetGUIScaleY() / g_graphicsContext.GetGUIScaleX();
      float newSize = (float) iSize / g_graphicsContext.GetGUIScaleY();

      // check if we already have this font file loaded (font object could differ only by color or style)
      CStdString TTFfontName;
      TTFfontName.Format("%s_%f_%f", strFilename, newSize, aspect);

      CGUIFontTTF* pFontFile = GetFontFile(TTFfontName); 
      if (!pFontFile)
      {
         pFontFile = new CGUIFontTTF(TTFfontName);
         bool bFontLoaded = pFontFile->Load(strPath, newSize, aspect);
         pFontFile->CopyReferenceCountFrom(*currentFontTTF);
   
         if (!bFontLoaded)
         {
           delete pFontFile;   
           // font could not b loaded
           CLog::Log(LOGERROR, "Couldn't re-load font file:%s", _P(strPath).c_str());
           return;
         }
      
         m_vecFontFiles.push_back(pFontFile);
      }
           
      font->SetFont(pFontFile);
   }
}
Exemple #8
0
void GUIFontManager::ReloadTTFFonts(void)
{
  if (!m_vecFonts.size())
    return;   // we haven't even loaded fonts in yet

  for (unsigned int i = 0; i < m_vecFonts.size(); i++)
  {
    CGUIFont* font = m_vecFonts[i];
    OrigFontInfo fontInfo = m_vecFontInfo[i];

    float aspect = fontInfo.aspect;
    float newSize = (float)fontInfo.size;
    CStdString& strPath = fontInfo.fontFilePath;
    CStdString& strFilename = fontInfo.fileName;

    RescaleFontSizeAndAspect(&newSize, &aspect, fontInfo.sourceRes, fontInfo.preserveAspect);

    CStdString TTFfontName;
    TTFfontName.Format("%s_%f_%f%s", strFilename, newSize, aspect, fontInfo.border ? "_border" : "");
    CGUIFontTTFBase* pFontFile = GetFontFile(TTFfontName);
    if (!pFontFile)
    {
      pFontFile = new CGUIFontTTF(TTFfontName);
      if (!pFontFile || !pFontFile->Load(strPath, newSize, aspect, 1.0f, fontInfo.border))
      {
        delete pFontFile;
        // font could not be loaded
        CLog::Log(LOGERROR, "Couldn't re-load font file:%s", strPath.c_str());
        return;
      }

      m_vecFontFiles.push_back(pFontFile);
    }

    font->SetFont(pFontFile);
  }
}
CGUIFont* CFontBundle::loadResourceById( const CResourceId& id, const CResourceId& fullName )
{
    // open file
    FILE* f = fopen( fullName.getUniqueName().c_str(), "rb" );
    if( !f ) {
        return NULL;
    }
    assert( f );

    // read magic
    char magic[4];
    fread( &magic, 1, 4, f );
    if( magic[0]!='D' || magic[1]!='F' || magic[2]!='N' || magic[3]!='T' ) {
        std::string msg = "file isn't valid font file! '" + id.getUniqueName() + "'";
        CConsole::CON_ERROR.write( msg );
        THROW_ERROR( msg );
    }
    // letter count
    int letterCount;
    fread( &letterCount, 1, 4, f );
    // first letter
    int firstLetter;
    fread( &firstLetter, 1, 4, f );
    // max width
    unsigned short maxWidth;
    fread( &maxWidth, 1, 2, f );
    // max height
    unsigned short maxHeight;
    fread( &maxHeight, 1, 2, f );

    // load texture - with same name
    CD3DTexture* texture = RGET_TEX(id);
    assert( texture );
    D3DSURFACE_DESC desc;
    texture->getObject()->GetLevelDesc( 0, &desc );
    float halftexX = 0.5f / desc.Width;
    float halftexY = 0.5f / desc.Height;

    // create font
    CGUIFont* font = new CGUIFont( letterCount, firstLetter, maxWidth, maxHeight, *texture );
    assert( font );

    // read letter infos
    for( int i = 0; i < letterCount; ++i ) {
        CGUIFont::SLetter& l = font->getLetterByNumber( i );
        fread( &l.u0, 1, 4, f );
        fread( &l.v0, 1, 4, f );
        fread( &l.u1, 1, 4, f );
        fread( &l.v1, 1, 4, f );
        l.u0 += halftexX;
        l.v0 += halftexY;
        l.u1 += halftexX;
        l.v1 += halftexY;
        unsigned short v;
        fread( &v, 1, 2, f );
        l.width = v;
        fread( &v, 1, 2, f );
        l.height = v;
    }

    // close file
    fclose( f );

    CONSOLE.write( "font loaded '" + id.getUniqueName() + "'" );

    return font;
}