コード例 #1
0
ファイル: gui_component.cpp プロジェクト: Cassie90/ClanLib
GUIComponent *GUIComponent::get_component_at(const Point &point)
{
	if (is_visible() == false)
	{
		return 0;
	}
	else
	{
		Rect parent_rect = get_size();
		if( parent_rect.contains(point) )  
		{
			std::vector<GUIComponent *> children = get_child_components();
			std::size_t pos, size = children.size();

			for( pos=size; pos>0; pos-- )
			{
				GUIComponent *child = children[pos-1];
				if(child->is_visible())
				{
					if (child->get_geometry().contains(point))
					{
						Point P = point;
						P.x -= child->get_geometry().left;
						P.y -= child->get_geometry().top;
						GUIComponent *comp = child->get_component_at(P);
						if (comp)
							return comp;
						else
							return child;
					}
				}
			}
			return this;
		}
		else
		{
			return 0;
		}
	}
}
コード例 #2
0
ファイル: gui_component.cpp プロジェクト: Cassie90/ClanLib
void GUIComponent::render(Canvas &canvas, const Rect &clip_rect, bool include_children)
{
	if (!impl->visible)
		return;

	Rect viewport = get_top_level_component()->get_size();
	CSSResourceCache *resource_cache = &impl->gui_manager_impl->resource_cache;
	CSSLayoutGraphics graphics(canvas, resource_cache, viewport, 0);

	Rect border_box = get_size();
	Rect padding_box = Rect(border_box).shrink(impl->css_used_values.border.left, impl->css_used_values.border.top, impl->css_used_values.border.right, impl->css_used_values.border.bottom);
	Rect content_box = Rect(padding_box).shrink(impl->css_used_values.padding.left, impl->css_used_values.padding.top, impl->css_used_values.padding.right, impl->css_used_values.padding.bottom);

	CSSBackgroundRenderer background(&graphics, resource_cache, impl->element.get_css_values().get_background());
	background.set_border_box(border_box);
	background.set_padding_box(padding_box);
	background.set_content_box(content_box);
	background.set_initial_containing_box(get_top_level_component()->get_viewport());
	background.render();

	CSSBorderRenderer border(&graphics, resource_cache, impl->element.get_css_values().get_border());
	border.set_border_box(border_box);
	border.set_border_values(impl->css_used_values.border.left, impl->css_used_values.border.top, impl->css_used_values.border.right, impl->css_used_values.border.bottom);
	border.render();

	if (impl->func_render.is_null() == false)
	{
		impl->func_render.invoke(canvas, clip_rect);
	}
	else
	{
		//GUIThemePart part(this);
		//Rect geometry = get_size();
		//part.render_box(canvas, RectPS(0, 0, geometry.get_width(), geometry.get_height()), clip_rect);
	}

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

		GUIComponent *cur = impl->first_child;
		while (cur)
		{
			Rect cur_geometry = cur->get_geometry();

			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)
			{
				Rect child_dirty_rect = cur->window_to_component_coords(update_rect);

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

		if (impl->clip_children)
		{
			pop_cliprect(canvas);
		}
	}
}