当前位置: 首页>>代码示例>>C++>>正文


C++ Text::getLocalBounds方法代码示例

本文整理汇总了C++中sf::Text::getLocalBounds方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::getLocalBounds方法的具体用法?C++ Text::getLocalBounds怎么用?C++ Text::getLocalBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sf::Text的用法示例。


在下文中一共展示了Text::getLocalBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: pauseMenu

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]);
	}
}
开发者ID:133440,项目名称:Final-Project,代码行数:35,代码来源:Billiards.cpp

示例2: draw

/**
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);
}
开发者ID:TheOneThatIsChosen720,项目名称:Virtual-Pet,代码行数:12,代码来源:SpriteManager.cpp

示例3: update

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);
}
开发者ID:niasie,项目名称:Dodger,代码行数:10,代码来源:Menupoint.hpp

示例4: endGame

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]);
	}
}
开发者ID:133440,项目名称:Final-Project,代码行数:49,代码来源:Billiards.cpp

示例5: draw

	// 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);
	}
开发者ID:xeloni,项目名称:ProjetsClion,代码行数:16,代码来源:observer.hpp

示例6: showMenu

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);
	}
}
开发者ID:Coguar,项目名称:Field964,代码行数:53,代码来源:Menu.cpp

示例7: showMission

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();
}
开发者ID:Coguar,项目名称:Field964,代码行数:26,代码来源:Menu.cpp

示例8: getCenter

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;
}
开发者ID:abodelot,项目名称:cosmoscroll,代码行数:7,代码来源:SFML_Helper.cpp

示例9: origin_from_text

void origin_from_text(sf::Text text)
{
	
	const sf::FloatRect rectangle{text.getLocalBounds()};
	
	text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
	
}
开发者ID:janderkkotlarski,项目名称:GUI,代码行数:8,代码来源:Top_Down_V0-2.cpp

示例10: resize

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);
}
开发者ID:abodelot,项目名称:cosmoscroll,代码行数:8,代码来源:SFML_Helper.cpp

示例11: set_origin

	void set_origin()
	{
		
		const sf::FloatRect rectangle{m_text.getLocalBounds()};
		
		m_text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
		
	}
开发者ID:janderkkotlarski,项目名称:Gravtacles,代码行数:8,代码来源:Gravtacles_V0-7.cpp

示例12: createOption

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));

}
开发者ID:NotTrulyEvil,项目名称:Yagami_Raito_Windows,代码行数:9,代码来源:MenuState.cpp

示例13: MoveDraw

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);
	}
}
开发者ID:133440,项目名称:Final-Project,代码行数:44,代码来源:Billiards.cpp

示例14: UpdateText

//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);
}
开发者ID:vellucci,项目名称:Tetris-Clone,代码行数:11,代码来源:FontManager.cpp

示例15: _drawSelectedChoice

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());
}
开发者ID:gmpetrov,项目名称:Gomoku,代码行数:13,代码来源:SfmlHandler.cpp


注:本文中的sf::Text::getLocalBounds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。