TEST_FIXTURE(SDL_fixture, HierachalMouseClickHandling)
{
	CHECK(SDL_init_ok);
	if(SDL_init_ok)
	{
		child_click_count = 0;
		parent_click_count = 0;

		Event e;
		e.event.mouse_event.x = 50;
		e.event.mouse_event.y = 10;
		e.event.mouse_event.btns = MouseButton::Left;
		e.event_type = EventType::MouseUp;
		
		Widget* parent = new Widget();
		Widget* child = new Widget();
		child->SetSize(Vector2i(20,20));
		child->SetPosition(Vector2i(40, 5));
		parent->AddChild(child);

		boost::signals::scoped_connection c = parent->OnClick.connect(parent_callback);
		boost::signals::scoped_connection c2 = child->OnClick.connect(child_callback);

		parent->HandleEvent(e);
		CHECK_EQUAL(1, child_click_count);
		CHECK_EQUAL(0, parent_click_count);

		e.event.mouse_event.x = 0;
		e.event.mouse_event.y = 0;
		parent->HandleEvent(e);
		CHECK_EQUAL(1, child_click_count);
		CHECK_EQUAL(1, parent_click_count);
		Widget::ClearRoot();
	}
}
Ejemplo n.º 2
0
TEST_FIXTURE(SDL_fixture, WidgetChildren)
{
	UNITTEST_TIME_CONSTRAINT(50);

	CHECK(SDL_init_ok);
	if(SDL_init_ok)
	{
		Widget* w = new Widget();
		Widget* w2 = new Widget();
		w->AddChild(w2);
		CHECK(std::find(w->GetChildren().begin(), w->GetChildren().end(), w2) != w->GetChildren().end());
		Widget::ClearRoot();
	}
}
Ejemplo n.º 3
0
TEST_FIXTURE(SDL_fixture, AddAndRemove)
{
	UNITTEST_TIME_CONSTRAINT(50);

	CHECK(SDL_init_ok);
	if(SDL_init_ok)
	{
		Widget* w = new Widget();
		Widget* w2 = new Widget();
		Widget* w3 = new Widget();
		w->AddChild(w2);
		w->AddChild(w3);
		CHECK_EQUAL(2, w->GetChildren().size());
		w->RemoveChild(w2);
		CHECK_EQUAL(1, w->GetChildren().size());
		Widget::ClearRoot();
	}
}
TEST_FIXTURE(SDL_fixture, HierarchalWidgets)
{
	/* Layout 
	|------------------------------|  |--------|
	|A                             |  |E       |
	| |-----------|   |-------|    |  |        |
	| |B          |   |C      |    |  |        |
	| |           |   |-------|    |  |        |
	| |           |                |  |        |
	| |           |                |  |        |
	| |           |   |-------|    |  |        |
	| |           |   |D      |    |  |        |
	| |-----------|   |-------|    |  |        |
	|                              |  |        |
	|------------------------------|  |--------|
	                                            
	|------------------------------------------|
	|F                                         |
	|------------------------------------------|
	*/
	UNITTEST_TIME_CONSTRAINT(50);

	CHECK(SDL_init_ok);
	if(SDL_init_ok)
	{
		Widget* A = new Widget();
		Widget* B = new Widget();
		Widget* C = new Widget();
		Widget* D = new Widget();
		Widget* E = new Widget();
		Widget* F = new Widget();

		A->AddChild(B);
		A->AddChild(C);
		A->AddChild(D);

		A->LinkInnerRight(B);
		A->LinkInnerLeft(C);
		A->LinkInnerDown(B);
		A->LinkInnerUp(B);
		A->LinkRight(E);
		E->LinkLeft(A);

		B->LinkRight(C);
		C->LinkLeft(B);
		D->LinkLeft(B);
		
		A->LinkDown(F);
		E->LinkDown(F);
		F->LinkUp(A);

		A->SetFocus();
		CHECK_EQUAL(true, A->HasFocus());
		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyDown));
		CHECK_EQUAL(true, B->HasFocus());

		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyDown));
		CHECK_EQUAL(true, F->HasFocus());

		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyUp));
		CHECK_EQUAL(true, A->HasFocus());

		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyUp));
		CHECK_EQUAL(true, B->HasFocus());

		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyUp));
		CHECK_EQUAL(true, A->HasFocus());

		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyRight));
		CHECK_EQUAL(true, B->HasFocus());

		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyRight));
		CHECK_EQUAL(true, C->HasFocus());

		Widget::GetWidgetWithFocus()->HandleEvent(Event(EventType::KeyRight));
		CHECK_EQUAL(true, E->HasFocus());
		Widget::ClearRoot();
	}
}