Пример #1
0
void CL_GUIComponent::render(CL_GraphicContext &gc, const CL_Rect &clip_rect, bool include_children)
{
	if (!impl->visible)
		return;

	if (!impl->css_layout.is_null())
	{
		impl->css_layout.layout(gc, get_size());
		impl->css_layout.render(gc, this);
	}

	if (impl->func_render.is_null() == false)
	{
		impl->func_render.invoke(gc, clip_rect);
	}
	else
	{
		CL_GUIThemePart part(this);
		CL_Rect geometry = get_size();
		part.render_box(gc, CL_RectPS(0, 0, geometry.get_width(), geometry.get_height()), clip_rect);
	}

	if (include_children)
	{
		if (impl->clip_children)
		{
			push_cliprect(gc, impl->clip_children_rect);
		}

		CL_GUIComponent *cur = impl->first_child;
		while (cur)
		{
			CL_Rect cur_geometry = cur->get_geometry();

			CL_Rect update_rect = component_to_window_coords(clip_rect);
			update_rect.overlap(component_to_window_coords(cur_geometry));
			if (update_rect.get_width() > 0 && update_rect.get_height() > 0)
			{
				CL_Rect child_dirty_rect = cur->window_to_component_coords(update_rect);

				gc.push_translate((float)cur_geometry.left, (float)cur_geometry.top);
				cur->render(gc, child_dirty_rect, true);
				gc.pop_modelview();
			}
			cur = cur->impl->next_sibling;
		}

		if (impl->clip_children)
		{
			pop_cliprect(gc);
		}
	}
}
Пример #2
0
void Sandpit::draw(CL_GraphicContext &p_gc)
{
	assert(m_built);

	if (m_texture.is_null()) {
		// create texture
		m_texture = CL_SharedPtr<CL_Texture>(
				new CL_Texture(
						p_gc,
						m_pixelData->get_width(), m_pixelData->get_height()
				)
		);

		m_texture->set_image(*m_pixelData);
	}

	p_gc.set_texture(0, *m_texture);

	CL_Rectf drawRect(0, 0, m_pixelData->get_width(), m_pixelData->get_height());

	p_gc.push_translate(m_position.x, m_position.y);
	CL_Draw::texture(p_gc, drawRect, CL_Colorf::white);
	p_gc.pop_modelview();
}
Пример #3
0
bool TextShooter::draw(CL_GraphicContext &gc, unsigned int current_time)
{
	int time_delta = current_time - start_time;
	if (time_delta < 0)	// Not on screen
		return true;

	if (time_delta >= duration)	// Reached destination
		return false;

	CL_Vec3f current_position;

	// Get position
	current_position.x = start_position.x + (((end_position.x - start_position.x) * time_delta) / duration);
	current_position.y = start_position.y + (((end_position.y - start_position.y) * time_delta) / duration);
	current_position.z = start_position.z + (((end_position.z - start_position.z) * time_delta) / duration);

	// Get fade towards end
	float font_alpha = (float) (duration  - time_delta);
	font_alpha /= end_fade_time;
	if (font_alpha > 1.0f) font_alpha = 1.0f;

	// Get initial white colour setting
	float font_white = (float) time_delta;
	font_white /= initial_white_time;
	if (font_white > 1.0f) font_white = 1.0f;
	font_white = 1.0f - font_white;

	// Calculate color
	CL_Colorf font_color;
	if (use_red_component)
	{
		font_color.r = 1.0f;
	}
	else
	{
		font_color.r = font_white;
	}

	if (use_green_component)
	{
		font_color.g = 1.0f;
	}
	else
	{
		font_color.g = font_white;
	}

	if (use_blue_component)
	{
		font_color.b = 1.0f;
	}
	else
	{
		font_color.b = font_white;
	}

	font_color.a = font_alpha;

	// Draw the text
	gc.push_translate(current_position.x, current_position.y, current_position.z);
	gc.push_scale( 2.0f / gc.get_width(), -2.0f / gc.get_height());

	CL_Size text_size = vector_font.get_text_size(gc, text);

	vector_font.draw_text(gc, -text_size.width/2, text_size.height/4, text, font_color);
	gc.pop_modelview();
	gc.pop_modelview();

	return true;
}