示例#1
0
int
Dialog::get_button_at(const Vector& mouse_pos) const
{
  Rectf bg_rect(Vector(SCREEN_WIDTH/2 - m_text_size.width/2,
                       SCREEN_HEIGHT/2 - m_text_size.height/2),
                Sizef(m_text_size.width,
                      m_text_size.height + 44));

  for(int i = 0; i < static_cast<int>(m_buttons.size()); ++i)
  {
    float segment_width = bg_rect.get_width() / m_buttons.size();
    float button_width = segment_width;
    float button_height = 24.0f;
    Vector pos(bg_rect.p1.x + segment_width/2.0f + i * segment_width,
               bg_rect.p2.y - 12);
    Rectf button_rect(Vector(pos.x - button_width/2, pos.y - button_height/2),
                      Vector(pos.x + button_width/2, pos.y + button_height/2));
    if (button_rect.contains(mouse_pos))
    {
      return i;
    }
  }
  return -1;
}
示例#2
0
	MultiPlayerMenu::MultiPlayerMenu(const FRect &rect, int2 window_size)
		:HudLayer(rect, HudLayer::slide_top), m_please_refresh(true), m_window_size(window_size) {
		enum { spacing = layer_spacing };

		setTitle("Connecting to server:");
		m_visible_time = 0.0f;

		m_waiting_for_refresh = false;
		m_waiting_to_connect = false;

		m_last_refresh_time = -1.0;
		m_last_connect_time = -1.0;

		FRect button_rect(s_button_size);
		button_rect += float2(rect.width() - spacing, rect.height() - spacing) - button_rect.size();

		PHudButton button_close = make_shared<HudClickButton>(button_rect);
		button_close->setIcon(HudIcon::close);

		button_rect -= float2(s_button_size.x + spacing * 2, 0.0f);
		PHudButton button_down = make_shared<HudClickButton>(button_rect);
		button_down->setIcon(HudIcon::down_arrow);
		button_down->setAccelerator(InputKey::pagedown);

		button_rect -= float2(s_button_size.x + spacing * 2, 0.0f);
		PHudButton button_up = make_shared<HudClickButton>(button_rect);
		button_up->setIcon(HudIcon::up_arrow);
		button_up->setAccelerator(InputKey::pageup);

		button_rect -= float2(s_button_size.x + spacing * 2, 0.0f);
		button_rect = button_rect.enlarge({50, 0}, {});
		PHudButton button_refresh = make_shared<HudClickButton>(button_rect);
		button_refresh->setLabel("refresh");
		
		button_rect -= float2(button_rect.width() + spacing * 2, 0.0f);
		button_rect = button_rect.enlarge({20, 0}, {});
		PHudButton button_connect = make_shared<HudClickButton>(button_rect);
		button_connect->setLabel("connect");
		button_connect->setAccelerator(InputKey::enter);

		button_rect = FRect(float2(185, s_button_size.y));
		button_rect += float2(rect.width() - button_rect.width() - spacing, spacing + topOffset());
		m_password = make_shared<HudEditBox>(button_rect, net::limits::max_password_size);
		m_password->setLabel("Pass: "******"Nick: ");
		m_nick_name->setText("random_dude");

		FRect sub_rect(rect.size());
		sub_rect = sub_rect.inset(float2(spacing, spacing * 2 + topOffset() + s_button_size.y),
						 		  float2(spacing, spacing * 2 + s_button_size.y));
		m_grid = make_shared<HudGrid>(sub_rect);
		
		m_grid->addColumn("Server name",	150.0f);
		m_grid->addColumn("Map name",	150.0f);
		m_grid->addColumn("Num players",	80.0f);
		m_grid->addColumn("Game mode",	80.0f);
		m_grid->addColumn("Ping",		50.0f);
		attach(m_grid);

		m_buttons.push_back(button_close);
		m_buttons.push_back(button_up);
		m_buttons.push_back(button_down);
		m_buttons.push_back(button_refresh);
		m_buttons.push_back(button_connect);
		m_buttons.push_back(m_password);
		m_buttons.push_back(m_nick_name);

		for(auto &button : m_buttons) {
			button->setButtonStyle(HudButtonStyle::small);
			attach(button);
		}

		m_client.reset(new net::Client());
	}