Esempio n. 1
0
void TBColor::SetFromString(const char *str, int len)
{
	int r, g, b, a;
	if (len == 9 && sscanf(str, "#%2x%2x%2x%2x", &r, &g, &b, &a) == 4)			// rrggbbaa
		Set(TBColor(r, g, b, a));
	else if (len == 7 && sscanf(str, "#%2x%2x%2x", &r, &g, &b) == 3)			// rrggbb
		Set(TBColor(r, g, b));
	else if (len == 5 && sscanf(str, "#%1x%1x%1x%1x", &r, &g, &b, &a) == 4)		// rgba
		Set(TBColor(r + (r << 4), g + (g << 4), b + (b << 4), a + (a << 4)));
	else if (len == 4 && sscanf(str, "#%1x%1x%1x", &r, &g, &b) == 3)			// rgb
		Set(TBColor(r + (r << 4), g + (g << 4), b + (b << 4)));
	else
		Set(TBColor());
}
Esempio n. 2
0
void TBFontFace::RenderGlyph(TBFontGlyph *glyph)
{
	assert(!glyph->frag);
	TBFontGlyphData glyph_data;
	if (m_font_renderer->RenderGlyph(&glyph_data, glyph->cp))
	{
		TBFontGlyphData *effect_glyph_data = m_effect.Render(&glyph->metrics, &glyph_data);
		TBFontGlyphData *result_glyph_data = effect_glyph_data ? effect_glyph_data : &glyph_data;

		// The glyph data may be in uint8 format, which we have to convert since we always
		// create fragments (and TBBitmap) in 32bit format.
		uint32 *glyph_dsta_src = result_glyph_data->data32;
		if (!glyph_dsta_src && result_glyph_data->data8)
		{
			if (m_temp_buffer.Reserve(result_glyph_data->w * result_glyph_data->h * sizeof(uint32)))
			{
				glyph_dsta_src = (uint32 *) m_temp_buffer.GetData();
				for (int y = 0; y < result_glyph_data->h; y++)
					for (int x = 0; x < result_glyph_data->w; x++)
					{
#ifdef TB_PREMULTIPLIED_ALPHA
						uint8 opacity = result_glyph_data->data8[x + y * result_glyph_data->stride];
						glyph_dsta_src[x + y * result_glyph_data->w] = TBColor(opacity, opacity, opacity, opacity);
#else
						glyph_dsta_src[x + y * result_glyph_data->w] = TBColor(255, 255, 255, result_glyph_data->data8[x + y * result_glyph_data->stride]);
#endif
					}
			}
		}

		// Finally, the glyph data is ready and we can create a bitmap fragment.
		if (glyph_dsta_src)
		{
			glyph->has_rgb = result_glyph_data->rgb;
			m_glyph_cache->CreateFragment(glyph, result_glyph_data->w, result_glyph_data->h,
										result_glyph_data->stride, glyph_dsta_src);
		}

		delete effect_glyph_data;
	}
#ifdef TB_RUNTIME_DEBUG_INFO
	//char glyph_str[9];
	//int len = utf8::encode(cp, glyph_str);
	//glyph_str[len] = 0;
	//TBStr info;
	//info.SetFormatted("Created glyph %d (\"%s\"). Cache contains %d glyphs (%d%% full) using %d bitmaps.\n", cp, glyph_str, m_all_glyphs.CountLinks(), m_frag_manager.GetUseRatio(), m_frag_manager.GetNumMaps());
	//TBDebugOut(info);
#endif
}
void ResourceEditWindow::OnPaintChildren(const PaintProps &paint_props)
{
	TBWindow::OnPaintChildren(paint_props);

	// Paint the selection of the selected widget
	if (TBWidget *selected_widget = GetSelectedWidget())
	{
		TBRect widget_rect(0, 0, selected_widget->GetRect().w, selected_widget->GetRect().h);
		selected_widget->ConvertToRoot(widget_rect.x, widget_rect.y);
		ConvertFromRoot(widget_rect.x, widget_rect.y);
		g_renderer->DrawRect(widget_rect, TBColor(255, 205, 0));
	}
}
Esempio n. 4
0
void TBLayout::OnPaintChildren(const PaintProps &paint_props)
{
	TBRect padding_rect = GetPaddingRect();
	if (padding_rect.IsEmpty())
		return;

	// If we overflow the layout, apply clipping when painting children
	TBRect old_clip_rect;
	if (m_overflow)
	{
		// We only want clipping in one axis (the overflowing one) so we
		// don't damage any expanded skins on the other axis. Add some fluff.
		TBRect clip_rect = padding_rect;
		const int fluff = 100;

		if (m_axis == AXIS_X)
			clip_rect = clip_rect.Expand(m_overflow_scroll == 0 ? fluff : 0, fluff,
										m_overflow_scroll == m_overflow ? fluff : 0, fluff);
		else
			clip_rect = clip_rect.Expand(fluff, m_overflow_scroll == 0 ? fluff : 0,
										fluff, m_overflow_scroll == m_overflow ? fluff : 0);

		old_clip_rect = g_renderer->SetClipRect(clip_rect, true);

		TB_IF_DEBUG_SETTING(LAYOUT_CLIPPING, g_renderer->DrawRect(clip_rect, TBColor(255, 0, 0, 200)));
	}

	// Paint children
	TBWidget::OnPaintChildren(paint_props);

	// Paint fadeout image over the overflowed edges
	// to the indicate to used that it's overflowed.
	if (m_overflow && m_packed.paint_overflow_fadeout)
	{
		TBID skin_x, skin_y;
		if (m_axis == AXIS_X)
			skin_x = TBIDC("TBLayout.fadeout_x");
		else
			skin_y = TBIDC("TBLayout.fadeout_y");

		DrawEdgeFadeout(padding_rect, skin_x, skin_y,
			m_overflow_scroll,
			m_overflow_scroll,
			m_overflow - m_overflow_scroll,
			m_overflow - m_overflow_scroll);
	}

	// Restore clipping
	if (m_overflow)
		g_renderer->SetClipRect(old_clip_rect, false);
}
Esempio n. 5
0
void DemoApplication::RenderFrame(int window_w, int window_h)
{
	// Override RenderFrame without calling super, since we want
	// to inject code between BeginPaint/EndPaint.
	// Application::RenderFrame(window_w, window_h);

	// Render
	g_renderer->BeginPaint(window_w, window_h);
	GetRoot()->InvokePaint(TBWidget::PaintProps());

#if defined(TB_RUNTIME_DEBUG_INFO) && defined(TB_IMAGE)
	// Enable to debug image manager fragments
	//g_image_manager->Debug();
#endif

	frame_counter++;
	frame_counter_total++;

	// Update the FPS counter
	double time = TBSystem::GetTimeMS();
	if (time > frame_counter_reset_time + 1000)
	{
		fps = (int) ((frame_counter / (time - frame_counter_reset_time)) * 1000);
		frame_counter_reset_time = time;
		frame_counter = 0;
	}

	// Draw FPS
	TBWidgetValue *continuous_repaint_val = g_value_group.GetValue(TBIDC("continous-repaint"));
	bool continuous_repaint = continuous_repaint_val ? !!continuous_repaint_val->GetInt() : 0;

	TBStr str;
	if (continuous_repaint)
		str.SetFormatted("FPS: %d Frame %d", fps, frame_counter_total);
	else
		str.SetFormatted("Frame %d", frame_counter_total);
	GetRoot()->GetFont()->DrawString(5, 5, TBColor(255, 255, 255), str);

	g_renderer->EndPaint();

	// If we want continous updates or got animations running, reinvalidate immediately
	if (continuous_repaint || TBAnimationManager::HasAnimationsRunning())
		GetRoot()->Invalidate();
}
void TBScrollContainerRoot::OnPaintChildren(const PaintProps &paint_props)
{
	// We only want clipping in one axis (the overflowing one) so we
	// don't damage any expanded skins on the other axis. Add some fluff.
	const int fluff = 100;
	TBScrollContainer *sc = static_cast<TBScrollContainer *>(GetParent());
	TBRect clip_rect = GetPaddingRect().Expand(sc->m_scrollbar_x.CanScrollNegative() ? 0 : fluff,
												sc->m_scrollbar_y.CanScrollNegative() ? 0 : fluff,
												sc->m_scrollbar_x.CanScrollPositive() ? 0 : fluff,
												sc->m_scrollbar_y.CanScrollPositive() ? 0 : fluff);

	TBRect old_clip_rect = g_renderer->SetClipRect(clip_rect, true);

	TB_IF_DEBUG_SETTING(LAYOUT_CLIPPING, g_renderer->DrawRect(clip_rect, TBColor(255, 0, 0, 200)));

	TBWidget::OnPaintChildren(paint_props);

	g_renderer->SetClipRect(old_clip_rect, false);
}