예제 #1
0
파일: j1Gui.cpp 프로젝트: ianexe/GUI
void Gui_Element::Center(bool x, bool y)
{
	if (x || y)
	{
		int _x = GetLocalPos().x;
		int _y = GetLocalPos().y;

		if (parent != NULL)
		{
			if (x)
			{
				_x = parent->GetLocalRect().w / 2 - rect.w / 2;
			}

			if (y)
			{
				_y = parent->GetLocalRect().h / 2 - rect.h / 2;
			}
		}

		else
		{
			if (x)
				_x = App->render->camera.w / 2 - rect.w / 2;

			if (y)
				_y = App->render->camera.h / 2 - rect.h / 2;
		}

		SetLocalPos(_x, _y);
	}
}
예제 #2
0
void CHitSquare::DebugDraw()
{
	char buff[80];
	_stprintf(buff, "sqr_x = %f sqr_y = %f\n",GetPos()->x,GetPos()->y);
	m_pDebugFont->Draw((int)(m_Direction< 0) * 550,340,buff);
	_stprintf(buff, "sqr_Lx = %f sqr_Ly = %f\n",GetLocalPos()->x,GetLocalPos()->y);
	m_pDebugFont->Draw((int)(m_Direction< 0) * 550,360,buff);
}
예제 #3
0
void GuiList::AddItem(GuiText* text)
{
  text->SetDrawBg(true); // TODO TEMP TEST
  text->SetJust(GuiText::AMJU_JUST_LEFT); // ?
  text->SizeToText(); // Resize
  text->RecalcFirstLast();

  // Resize as appropriate
  Vec2f mySize = GetSize();
  Vec2f size = text->GetSize();
  // Resize horizontally to width of text ?
  // OR chop text to fit in list box ?
  //size.x = GetSize().x;
  //text->SetSize(size);
  // Increase size of listbox vertically
  mySize.x = std::max(mySize.x, size.x);
  mySize.y += text->GetSize().y;
  SetSize(mySize);

  Vec2f pos = GetLocalPos();
  // NB subtract => go down the screen
  // TODO This should be accumulated height
  pos.y -= 0.1f * (float)m_children.size(); // TODO
  text->SetLocalPos(pos);

  AddChild(text);
}
예제 #4
0
파일: actionmenu.cpp 프로젝트: kenhilf/SFPC
void ActionMenu::Init()
{
	Vector2f pos = GetLocalPos();
	m_slider = Slider(pos);
	m_slider.SetSlideRate(800);
	if (m_numChoices == 2)
	{
		pos.x = GAME_SCREEN_WIDTH;
		m_miniWin.SetLocalPos(Position(68, 1));
	}
	else if (m_numChoices == 4)
	{
		m_bAllCaps = true;
		pos.y = GAME_SCREEN_HEIGHT;
		m_miniWin.SetLocalPos(Position(80, 25));
	}
	m_slider.SetOffScreenPos(pos);
	m_slider.SnapOffScreen();
	AddChild(m_slider);

	m_miniWin.IgnoreSlider(true);
	m_miniWin.SetText(GetCurrChoiceText());
	m_miniWin.SetFont(FontMgr::Instance().GetFont(FontStyle::FixedWidth));
	AddChild(m_miniWin);
}
예제 #5
0
파일: j1Gui.cpp 프로젝트: ianexe/GUI
bool Gui_Element::CheckEvent(Gui_Element* hover, Gui_Element* focus)
{
	bool inside = (hover == this);
	bool focused = (focus == this);

	int mouse_x = 0;
	int mouse_y = 0;
	App->input->GetMousePosition(mouse_x, mouse_y);

	p2List_item<j1Module*>* listener = listener_list.start;
	while (listener != NULL)
	{
		if (inside != mouseInside)
		{
			//Check if, when outside, mouse enters
			if (inside)
			{
				listener->data->ReceiveEvent(this, MOUSE_ENTER);
			}
			//Check if, when inside, mouse leaves
			else
			{
				listener->data->ReceiveEvent(this, MOUSE_LEAVE);
				clicked = false;
			}
			mouseInside = inside;
		}

		if (inside)
		{
			if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_DOWN)
			{
				listener->data->ReceiveEvent(this, MOUSE_CLICK_DOWN);
				clicked = true;
			}
				
			else if (App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_UP)
			{
				listener->data->ReceiveEvent(this, MOUSE_CLICK_UP);
				clicked = false;
			}
				
			if (draggable && clicked && App->input->GetMouseButtonDown(SDL_BUTTON_LEFT) == KEY_REPEAT)
			{
				p2Point<int> p = GetLocalPos();
				int mouse_motionX = 0;
				int mouse_motionY = 0;
				App->input->GetMouseMotion(mouse_motionX, mouse_motionY);
				SetLocalPos(p.x + mouse_motionX, p.y + mouse_motionY);
			}
		}

		if (focusIn != focused)
		{
			if (listener)
			{
				if (focused)
					listener->data->ReceiveEvent(this, FOCUS_ON);
				else
					listener->data->ReceiveEvent(this, FOCUS_OFF);
			}
			focusIn = focused;
		}

		if (focused)
		{
			if (listener)
			{
				if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_DOWN)
					listener->data->ReceiveEvent(this, MOUSE_CLICK_DOWN);
				if (App->input->GetKey(SDL_SCANCODE_RETURN) == KEY_UP)
					listener->data->ReceiveEvent(this, MOUSE_CLICK_UP);
			}
		}
		listener = listener->next;
	}

	return true;
}