//=============================================================================
//=============================================================================
void UTBRendererBatcher::LoadDefaultResources()
{
    g_tb_lng->Load("resources/language/lng_en.tb.txt");

    // Load the default skin, and override skin that contains the graphics specific to the demo.
    g_tb_skin->Load("resources/default_skin/skin.tb.txt", "demo01/skin/skin.tb.txt");

    // **README**
    // - define TB_FONT_RENDERER_FREETYPE in tb_config.h for non-demo
#ifdef TB_FONT_RENDERER_TBBF
    void register_tbbf_font_renderer();
    register_tbbf_font_renderer();
#endif
#ifdef TB_FONT_RENDERER_STB
    void register_stb_font_renderer();
    register_stb_font_renderer();
#endif
#ifdef TB_FONT_RENDERER_FREETYPE
    void register_freetype_font_renderer();
    register_freetype_font_renderer();
#endif

    // Add fonts we can use to the font manager.
#if defined(TB_FONT_RENDERER_STB) || defined(TB_FONT_RENDERER_FREETYPE)
    g_font_manager->AddFontInfo("resources/vera.ttf", "Vera");
#endif
#ifdef TB_FONT_RENDERER_TBBF
    g_font_manager->AddFontInfo("resources/default_font/segoe_white_with_shadow.tb.txt", "Segoe");
    g_font_manager->AddFontInfo("fonts/neon.tb.txt", "Neon");
    g_font_manager->AddFontInfo("fonts/orangutang.tb.txt", "Orangutang");
    g_font_manager->AddFontInfo("fonts/orange.tb.txt", "Orange");
#endif

    // Set the default font description for widgets to one of the fonts we just added
    TBFontDescription fd;
#ifdef TB_FONT_RENDERER_TBBF
    fd.SetID(TBIDC("Segoe"));
#else
    fd.SetID(TBIDC("Vera"));
#endif
    fd.SetSize(g_tb_skin->GetDimensionConverter()->DpToPx(14));
    g_font_manager->SetDefaultFontDescription(fd);

    // Create the font now.
    TBFontFace *font = g_font_manager->CreateFontFace(g_font_manager->GetDefaultFontDescription());

    // Render some glyphs in one go now since we know we are going to use them. It would work fine
    // without this since glyphs are rendered when needed, but with some extra updating of the glyph bitmap.
    if ( font )
    {
        font->RenderGlyphs(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~•·åäöÅÄÖ");
    }

    root_.SetSkinBg(TBIDC("background"));

    TBWidgetsAnimationManager::Init();
}
void TBWidgetString::ValidatCachedSize(TBWidget *widget)
{
	const TBFontDescription fd = widget->GetCalculatedFontDescription();
	if (!m_height || fd != m_fd)
	{
		m_fd = fd;
		TBFontFace *font = g_font_manager->GetFontFace(fd);
		m_width = font->GetStringWidth(m_text);
		m_height = font->GetHeight();
	}
}
void TBWidgetString::Paint(TBWidget *widget, const TBRect &rect, const TBColor &color)
{
	TBFontFace *font = widget->GetFont();
	int string_w = GetWidth(widget);

	int x = rect.x;
	if (m_text_align == TB_TEXT_ALIGN_RIGHT)
		x += rect.w - string_w;
	else if (m_text_align == TB_TEXT_ALIGN_CENTER)
		x += MAX(0, (rect.w - string_w) / 2);
	int y = rect.y + (rect.h - GetHeight(widget)) / 2;

	if (string_w <= rect.w)
		font->DrawString(x, y, color, m_text);
	else
	{
		// There's not enough room for the entire string
		// so cut it off and end with ellipsis (...)

		// const char *end = "…"; // 2026 HORIZONTAL ELLIPSIS
		// Some fonts seem to render ellipsis a lot uglier than three dots.
		const char *end = "...";

		int endw = font->GetStringWidth(end);
		int startw = 0;
		int startlen = 0;
		while (m_text.CStr()[startlen])
		{
			int new_startw = font->GetStringWidth(m_text, startlen);
			if (new_startw + endw > rect.w)
				break;
			startw = new_startw;
			startlen++;
		}
		startlen = MAX(0, startlen - 1);
		font->DrawString(x, y, color, m_text, startlen);
		font->DrawString(x + startw, y, color, end);
	}
}
Exemple #4
0
int app_main()
{
	application = new DemoApplication();

	ApplicationBackend *application_backend = ApplicationBackend::Create(application, 1280, 700, "Demo");
	if (!application_backend)
		return 1;

	tb_core_init(application_backend->GetRenderer(), "resources/language/lng_en.tb.txt");

	// Load the default skin, and override skin that contains the graphics specific to the demo.
	g_tb_skin->Load("resources/default_skin/skin.tb.txt", "Demo/demo01/skin/skin.tb.txt");

	// Register font renderers.
#ifdef TB_FONT_RENDERER_TBBF
	void register_tbbf_font_renderer();
	register_tbbf_font_renderer();
#endif
#ifdef TB_FONT_RENDERER_STB
	void register_stb_font_renderer();
	register_stb_font_renderer();
#endif
#ifdef TB_FONT_RENDERER_FREETYPE
	void register_freetype_font_renderer();
	register_freetype_font_renderer();
#endif

	// Add fonts we can use to the font manager.
#if defined(TB_FONT_RENDERER_STB) || defined(TB_FONT_RENDERER_FREETYPE)
	g_font_manager->AddFontInfo("resources/vera.ttf", "Vera");
#endif
#ifdef TB_FONT_RENDERER_TBBF
	g_font_manager->AddFontInfo("resources/default_font/segoe_white_with_shadow.tb.txt", "Segoe");
	g_font_manager->AddFontInfo("Demo/fonts/neon.tb.txt", "Neon");
	g_font_manager->AddFontInfo("Demo/fonts/orangutang.tb.txt", "Orangutang");
	g_font_manager->AddFontInfo("Demo/fonts/orange.tb.txt", "Orange");
#endif

	// Set the default font description for widgets to one of the fonts we just added
	TBFontDescription fd;
#ifdef TB_FONT_RENDERER_TBBF
	fd.SetID(TBIDC("Segoe"));
#else
	fd.SetID(TBIDC("Vera"));
#endif
	fd.SetSize(g_tb_skin->GetDimensionConverter()->DpToPx(14));
	g_font_manager->SetDefaultFontDescription(fd);

	// Create the font now.
	TBFontFace *font = g_font_manager->CreateFontFace(g_font_manager->GetDefaultFontDescription());

	// Render some glyphs in one go now since we know we are going to use them. It would work fine
	// without this since glyphs are rendered when needed, but with some extra updating of the glyph bitmap.
	if (font)
		font->RenderGlyphs(" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~•·åäöÅÄÖ");

	// Give the root widget a background skin
	application->GetRoot()->SetSkinBg(TBIDC("background"));

	application->Init();
	application->Run();
	application->ShutDown();

	delete application;

	return 0;
}