本文整理汇总了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]);
}
}
示例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);
}
示例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);
}
示例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]);
}
}
示例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);
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例11: set_origin
void set_origin()
{
const sf::FloatRect rectangle{m_text.getLocalBounds()};
m_text.setOrigin(0.5f*rectangle.width, 0.95f*rectangle.height);
}
示例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));
}
示例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);
}
}
示例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);
}
示例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());
}