Exemplo n.º 1
0
void pauseMenu()
{
	pause.setFont(myFont);
	pause.setCharacterSize(WIDTH / 16);
	pause.setStyle(sf::Text::Bold);
	pause.setColor(sf::Color::Black);
	pause.setString("PAUSE");
	pause.setOrigin(pause.getLocalBounds().width / 2, pause.getLocalBounds().height / 2);
	pause.setPosition(WIDTH / 2, 3 * HEIGHT / 16);

	sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8);

	for (int i = 0; i < pauseMenuRect.size(); i++)
	{
		pauseMenuRect[i].setSize(menuRectSize);
		pauseMenuRect[i].setFillColor(grey);
		pauseMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2);
		pauseMenuRect[i].setPosition(WIDTH / 2, 6 * HEIGHT / 16 + i * (5 * HEIGHT / 32));

		pauseMenuText[i].setFont(myFont);
		pauseMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5);
		pauseMenuText[i].setStyle(sf::Text::Bold);
		pauseMenuText[i].setColor(sf::Color::Black);
		pauseMenuText[i].setString(pauseMenuCommands[i]);
		pauseMenuText[i].setOrigin(pauseMenuText[i].getLocalBounds().width / 2, pauseMenuText[i].getLocalBounds().height / 2);
		pauseMenuText[i].setPosition(pauseMenuRect[i].getPosition().x, pauseMenuRect[i].getPosition().y);
	}

	BILLIARDS.draw(pause);
	for (int i = 0; i < pauseMenuRect.size(); i++)
	{
		BILLIARDS.draw(pauseMenuRect[i]);
		BILLIARDS.draw(pauseMenuText[i]);
	}
}
/**
Text drawing for buttons.
*/
void SpriteManager::draw (sf::Text button_text, int x, int y, int width, int height, sf::RenderWindow &window) {


    button_text.setFont (font);
    sf::FloatRect text_rect = button_text.getLocalBounds ();
    button_text.setPosition ((x + (width / 2)) - (button_text.getLocalBounds ().width / 2), (y + (height / 2)) - (button_text.getLocalBounds ().height));//Centers text to button.

    window.draw (button_text);
}
Exemplo n.º 3
0
void Menupoint::update(sf::Window& window)
{
	if	(_pos.x <= sf::Mouse::getPosition(window).x &&
	   	 _pos.x + _text.getLocalBounds().width >= sf::Mouse::getPosition(window).x &&
	   	 _pos.y <= sf::Mouse::getPosition(window).y &&
	   	 _pos.y + _text.getLocalBounds().height >= sf::Mouse::getPosition(window).y)
		_text.setColor(sf::Color::Blue);
	else
		_text.setColor(sf::Color::White);
}
Exemplo n.º 4
0
void endGame()
{
	endTitle.setFont(myFont);
	endTitle.setCharacterSize(WIDTH / 16);
	endTitle.setStyle(sf::Text::Bold);
	endTitle.setColor(sf::Color::Black);
	string str;
	if (end1P)
	{
		stringstream message;
		message << "Final score: " << mover;
		str = message.str();
		
	}
	else if (end2P)
	{
		stringstream message;
		message << "Player " << mover << " wins!";
		str = message.str();
	}
	endTitle.setString(str);
	endTitle.setOrigin(endTitle.getLocalBounds().width / 2, endTitle.getLocalBounds().height / 2);
	endTitle.setPosition(WIDTH / 2, 2 * HEIGHT / 5);

	sf::Vector2f menuRectSize(3 * WIDTH / 16, HEIGHT / 8);

	for (int i = 0; i < endMenuRect.size(); i++)
	{
		endMenuRect[i].setSize(menuRectSize);
		endMenuRect[i].setFillColor(grey);
		endMenuRect[i].setOrigin(menuRectSize.x / 2, menuRectSize.y / 2);
		endMenuRect[i].setPosition(WIDTH / 2, 4 * HEIGHT / 5);

		endMenuText[i].setFont(myFont);
		endMenuText[i].setCharacterSize(2 * pause.getCharacterSize() / 5);
		endMenuText[i].setStyle(sf::Text::Bold);
		endMenuText[i].setColor(sf::Color::Black);
		endMenuText[i].setString(endMenuCommands[i]);
		endMenuText[i].setOrigin(endMenuText[i].getLocalBounds().width / 2, endMenuText[i].getLocalBounds().height / 2);
		endMenuText[i].setPosition(endMenuRect[i].getPosition().x, endMenuRect[i].getPosition().y);
	}

	BILLIARDS.draw(endTitle);
	for (int i = 0; i < endMenuRect.size(); i++)
	{
		BILLIARDS.draw(endMenuRect[i]);
		BILLIARDS.draw(endMenuText[i]);
	}
}
Exemplo n.º 5
0
	// Rendu
	void draw(sf::RenderTarget& renderer, const sf::Vector2f& center)
	{

		sf::Vector2f position(center);
		_text.setString(_label);
		position.x -= _text.getLocalBounds().width / 2.0f;
		position.y -= _text.getLocalBounds().height / 2.0f;
		_border.setSize(sf::Vector2f(_text.getLocalBounds().width + 10,
									 _text.getLocalBounds().height + 10));
		_border.setPosition(position);

		_text.setPosition(position);
		renderer.draw(_text);
		renderer.draw(_border);
	}
Exemplo n.º 6
0
void showMenu(Game1 & game, MenuText & menu_text, sf::Text & text, MenuImg & fon, menuBools & bools)
{

	game.window->draw(*fon.sprite);
	if (!bools.about) {
		text.setString(menu_text.new_game);
		menu_text.new_game_rect = { fon.sprite->getPosition().x - menu_text.new_game_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.new_game_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
		_choose_color(text, game.pos, menu_text.new_game_rect);
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x - menu_text.new_game_pos.x, fon.sprite->getPosition().y - menu_text.new_game_pos.y);
		game.window->draw(text);

		text.setString(menu_text.continue_game);
		menu_text.continue_game_rect = { fon.sprite->getPosition().x - menu_text.continue_game_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.continue_game_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
		if (bools.first_play) {
			text.setColor(Color(128, 128, 128));
		}
		else {
			_choose_color(text, game.pos, menu_text.continue_game_rect);
		}
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x - menu_text.continue_game_pos.x, fon.sprite->getPosition().y - menu_text.continue_game_pos.y);
		game.window->draw(text);

		text.setString(menu_text.about);
		menu_text.about_rect = { fon.sprite->getPosition().x - menu_text.about_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.about_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
		_choose_color(text, game.pos, menu_text.about_rect);
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x - menu_text.about_pos.x, fon.sprite->getPosition().y - menu_text.about_pos.y);
		game.window->draw(text);

		text.setString(menu_text.exit);
		menu_text.exit_rect = { fon.sprite->getPosition().x - menu_text.exit_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.exit_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
		_choose_color(text, game.pos, menu_text.exit_rect);
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x - menu_text.exit_pos.x, fon.sprite->getPosition().y - menu_text.exit_pos.y);
		game.window->draw(text);
	}
	else {
		text.setColor(Color::Red);
		text.setString(menu_text.about_text);
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x - menu_text.about_text_pos.x, fon.sprite->getPosition().y - menu_text.about_text_pos.y);
		game.window->draw(text);

		text.setString(menu_text.back);
		menu_text.back_rect = { fon.sprite->getPosition().x - menu_text.back_pos.x - text.getLocalBounds().width / 2, fon.sprite->getPosition().y - menu_text.back_pos.y, text.getLocalBounds().width, text.getLocalBounds().height };
		_choose_color(text, game.pos, menu_text.back_rect);
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x - menu_text.back_pos.x, fon.sprite->getPosition().y - menu_text.back_pos.y);
		game.window->draw(text);
	}
}
Exemplo n.º 7
0
void showMission(Game1 & game, MissionText & mission_text, sf::Text & text, Hero & hero, MenuImg & fon, menuBools & bools)
{
	if (!bools.first_play) {
		switch (hero.player->quest)
		{
		case Player::quest_status::start: text.setString(mission_text.start); break;
		case Player::quest_status::find_car: text.setString(mission_text.find_car); break;
		case Player::quest_status::find_gaz: text.setString(mission_text.find_gaz); break;
		case Player::quest_status::find_busket: text.setString(mission_text.find_buscket); break;
		case Player::quest_status::find_colon: text.setString(mission_text.find_colon); break;
		case Player::quest_status::go_to_car: text.setString(mission_text.go_to_car); break;
		}
		text.setOrigin(text.getLocalBounds().width / 2, 0);
		text.setPosition(fon.sprite->getPosition().x + 220, fon.sprite->getPosition().y - 250);
		text.setColor(Color::Red);
		game.window->draw(text);
	}
	else {
		fon.hand_sprite->setPosition(fon.sprite->getPosition().x + 200, fon.sprite->getPosition().y);
		game.window->draw(*fon.hand_sprite);

	}
	game.aim_sprite->setPosition(game.pos);
	game.window->draw(*game.aim_sprite);
	game.window->display();
}
Exemplo n.º 8
0
sf::Vector2f getCenter(const sf::Text& text)
{
    sf::Vector2f center = text.getPosition();
    center.x += text.getLocalBounds().width  / 2.f;
    center.y += text.getLocalBounds().height / 2.f;
    return center;
}
Exemplo n.º 9
0
void origin_from_text(sf::Text text)
{
	
	const sf::FloatRect rectangle{text.getLocalBounds()};
	
	text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
	
}
Exemplo n.º 10
0
void resize(sf::Text& text, float width, float height)
{
    int local_width  = text.getLocalBounds().width;
    int local_height = text.getLocalBounds().height;

    if ((local_width > 0) && (local_height > 0))
        text.setScale(width / local_width, height / local_height);
}
Exemplo n.º 11
0
	void set_origin()
	{
		
		const sf::FloatRect rectangle{m_text.getLocalBounds()};
		
		m_text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
		
	}
Exemplo n.º 12
0
void MenuState::createOption(sf::Text& textOption, int order, std::string s){
	textOption.setFont(terminal); //This font is blurry need another one!
	textOption.setCharacterSize(20);
	textOption.setString(s);
	textOption.setOrigin(static_cast<int> (textOption.getLocalBounds().width / 2), static_cast<int>(textOption.getLocalBounds().height / 2));
	textOption.setPosition(static_cast<int>((window.getDefaultView().getSize().x) / 2), 130 + order*50);
	textOption.setColor(sf::Color(128,128,128));

}
Exemplo n.º 13
0
void MoveDraw()
{
	moves.setFont(myFont);
	moves.setCharacterSize(12);
	moves.setStyle(sf::Text::Bold);
	moves.setColor(sf::Color::Red);
	moves.setOrigin(moves.getLocalBounds().width / 2, moves.getLocalBounds().height / 2);
	moves.setPosition(WIDTH * 3 / 4, borderDepth / 2);
	bestScore.setFont(myFont);
	bestScore.setCharacterSize(12);
	bestScore.setStyle(sf::Text::Bold);
	bestScore.setColor(sf::Color::Red);
	bestScore.setOrigin(bestScore.getLocalBounds().width / 2, bestScore.getLocalBounds().height / 2);
	bestScore.setPosition(WIDTH * 1 / 4, borderDepth / 2);

	stringstream mess2;
	if (BS != 0)
		mess2 << "Best Score: " << BS;
	else
		mess2 << "Best Score: --";
	string message2 = mess2.str();
	bestScore.setString(message2);

	if ((twoPlayerGame) || (pause2P))
	{
		if (mover > 2)
			mover = 1;
		stringstream mess;
		mess << "Player " << mover << "'s turn";
		string message = mess.str();
		moves.setString(message);
		BILLIARDS.draw(moves);
	}
	else
	{
		stringstream mess;
		mess << "Moves: " << mover;
		string message = mess.str();
		moves.setString(message);
		BILLIARDS.draw(bestScore);
		if ((onePlayerGame)||(pause1P))
			BILLIARDS.draw(moves);
	}
}
Exemplo n.º 14
0
//will update the string of the text if needed and color and will keep the text centered if specified
void FontManager::UpdateText(sf::Text& text, const char* txt, sf::Color color, bool setOrigin)
{
	if (txt != NULL)
		text.setString(txt);

	if (setOrigin)
		text.setOrigin(text.getGlobalBounds().width / 2.0f, text.getLocalBounds().height / 2.0f);

	text.setColor(color);
}
Exemplo n.º 15
0
void SfmlHandler::_drawSelectedChoice(sf::Text & choice)
{
	sf::FloatRect backgroundRect = choice.getLocalBounds();

	sf::RectangleShape background(sf::Vector2f(backgroundRect.width, 2));
	background.setFillColor(_colorMap[eColor::RED]);

	sf::Vector2f pos = background.getPosition();

	background.setPosition(pos.x, pos.y + 74);

	_window->draw(background, choice.getTransform());
}
Exemplo n.º 16
0
void centerAlignText(sf::Text& t) {
	sf::FloatRect r = t.getLocalBounds();
	t.setOrigin(r.width / 2, 0);
}
Exemplo n.º 17
0
inline void centerOrigin(sf::Text& text)
{
	sf::FloatRect bounds = text.getLocalBounds();
	text.setOrigin(std::floor(bounds.left + bounds.width / 2.f), std::floor(bounds.top + bounds.height / 2.f));
}
Exemplo n.º 18
0
 void CenterTextVert(sf::Text& message, const sf::RenderTarget& target)
 {
     sf::FloatRect message_bounds = message.getLocalBounds();
     message.setOrigin(0, message_bounds.top + (message_bounds.height/2.f));
     message.setPosition(message.getPosition().x, target.getSize().y/2.f);
 }
Exemplo n.º 19
0
void MameUIsenWindow::centerElement(sf::Text& text)
{
	sf::FloatRect fr = text.getLocalBounds();
	text.setOrigin(fr.left + fr.width/2.0f, fr.top + fr.height/2.0f);
}
Exemplo n.º 20
0
void draw_statistics(
	window& window,
	const black_label::path& asset_directory,
	const black_label::rendering::pipeline& rendering_pipeline,
	bool options_complete )
{
	static sf::Font font;
	static sf::Text text;
	static bool uninitialized{true};
	if (uninitialized) {
		using namespace black_label;
		system::error_code error_code;
		auto font_file = canonical_and_preferred("fonts/Vegur-Regular.ttf", asset_directory, error_code);

		if (error_code || !font.loadFromFile(font_file.string())) return;

		text.setFont(font);
		uninitialized = false;
	}


	gpu::vertex_array::unbind();
	gpu::buffer::unbind();
	gpu::framebuffer::unbind();
	window.window_.resetGLStates();

	static bool has_written_message{false};
	if (options_complete && rendering_pipeline.is_complete()) {
		has_written_message = false;
		static unordered_map<string, double> averages;
		stringstream ss;
		ss.precision(4);
		auto output_pass = [&] ( const std::string& name, const chrono::high_resolution_clock::duration& render_duration )
		{ 
			if (10s < render_duration || 10us > render_duration) return;
			auto render_time = duration_cast<duration<double, milli>>(render_duration).count();
			static const double alpha{0.75};
			averages[name] = alpha * render_time + (1.0 - alpha) * averages[name];
			ss << name << " [ms]: " << render_time << " (" << averages[name] << ")\n"; 
		};

		output_pass("rendering_pipeline.json", rendering_pipeline.render_time);

		output_pass(
			"\t" + rendering_pipeline.shadow_mapping.name, 
			rendering_pipeline.shadow_mapping.render_time);

		auto all_passes = rendering_pipeline.shadow_mapping.render_time;
		chrono::high_resolution_clock::duration ldm{0};
		for (const auto& pass : rendering_pipeline.passes) {
			all_passes += pass.render_time;
			if ("ldm" == pass.name.substr(0, 3)) {
				ldm += pass.render_time;
				continue;
			}
			output_pass("\t" + pass.name, pass.render_time);
		}
	
		output_pass("\tldm (all passes)", ldm);

		output_pass("\t(sequencing overhead)", rendering_pipeline.render_time - all_passes);

		ss << "data_buffer_size" << " [MB]: " << rendering_pipeline.data_buffer_size * 1.0e-6f << "\n"; 
		ss << "photon_buffer_size" << " [MB]: " << rendering_pipeline.photon_buffer_size * 1.0e-6f << "\n"; 

		text.setString(ss.str());
		text.setCharacterSize(16);

		text.setColor(sf::Color::Black);
		text.setPosition(6, 1);
		window.window_.draw(text);

		text.setColor(sf::Color::White);
		text.setPosition(5, 0);
		window.window_.draw(text);
	}
	else if (!has_written_message) {
		has_written_message = true;
		auto window_size = window.window_.getSize();
		sf::RectangleShape rectangle{sf::Vector2f{window_size}};
		rectangle.setFillColor(sf::Color{0, 0, 0, 180});
		window.window_.draw(rectangle);
		
		text.setString("Error in rendering config.");
		text.setCharacterSize(22);
		sf::FloatRect textBounds = text.getLocalBounds();
		text.setPosition(sf::Vector2f(
			floor(window_size.x / 2.0f - (textBounds.left + textBounds.width / 2.0f)), 
			floor(window_size.y / 2.0f - (textBounds.top  + textBounds.height / 2.0f))));
		text.setColor(sf::Color::White);
		window.window_.draw(text);
	}
}
Exemplo n.º 21
0
void centerOrigin(sf::Text& text)
{
    sf::FloatRect bounds = text.getLocalBounds();
    text.setOrigin(bounds.left + bounds.width / 2.f, bounds.top + bounds.height / 2.f);
}
Exemplo n.º 22
0
void centerTextOrigin( sf::Text& text )
{
	text.setOrigin( text.getLocalBounds().width / 2, text.getLocalBounds().height / 2 );
}
Exemplo n.º 23
0
 void CenterText(sf::Text& message, const sf::RenderTarget& target)
 {
     sf::FloatRect message_bounds = message.getLocalBounds();
     message.setOrigin(message_bounds.left + (message_bounds.width/2.0f), message_bounds.top + (message_bounds.height/2.0f));
     message.setPosition(sf::Vector2f(target.getSize() / (unsigned)2));
 }
Exemplo n.º 24
0
 void CenterTextHor(sf::Text& message, const sf::RenderTarget& target)
 {
     sf::FloatRect message_bounds = message.getLocalBounds();
     message.setOrigin(message_bounds.left + (message_bounds.width/2.f), 0);
     message.setPosition(target.getSize().x/2.f, message.getPosition().y);
 }