本文整理汇总了C++中sf::Text::getGlobalBounds方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::getGlobalBounds方法的具体用法?C++ Text::getGlobalBounds怎么用?C++ Text::getGlobalBounds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::getGlobalBounds方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
void Scoring::Draw(unsigned int p_num, int score)
{
std::stringstream pointsStream;
pointsStream << score;
points_graphics.setString(pointsStream.str());
switch(p_num)
{
case 0:
points_graphics.setPosition(5,5);
break;
case 1:
points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,5);
break;
case 2:
points_graphics.setPosition(5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5);
break;
case 3:
points_graphics.setPosition(WindowManager::GetSize().x - points_graphics.getGlobalBounds().width - 5,WindowManager::GetSize().y - points_graphics.getGlobalBounds().height - 5);
break;
}
WindowManager::Draw(points_graphics);
}
示例2: arrange
void DropDown::arrange(sf::Text &text,sf::RectangleShape &shape)
{
float ratiox = shape.getGlobalBounds().width/text.getGlobalBounds().width;
float ratioy = (shape.getGlobalBounds().height/text.getGlobalBounds().height);
ratioy*=0.5f;
text.scale(ratiox,ratioy);
}
示例3: drawNumbers
void drawNumbers(sf::RenderWindow & window,sf::Text & text, float bgHeight) {
std::string textNum;
sf::Vector2f position = getCenter(window);
for (int i = 0; i < NUMBER_OF_DIGITS; i++) {
position = polarToCartesianSys(bgHeight * 0.5f - text.getGlobalBounds().height * 2, 30.f * ( i + 1 ) - 90);
text.setString(std::to_string( i + 1 ));
text.setOrigin(text.getGlobalBounds().width * 0.5f, text.getGlobalBounds().height * 0.5f);
text.setPosition(position.x + window.getSize().x * 0.5f, position.y + window.getSize().y * 0.5f);
window.draw(text);
}
}
示例4: init
virtual void init()
{
dt=0;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
darken = sf::RectangleShape(sf::Vector2f(800,400));
tit.setFont(standard_font);
score.setFont(standard_font);
std::stringstream ss;
ss << your_score;
std::string str = ss.str();
tit.setString("Congrats! You beat the game\nIt took you:");
score.setString(str + " seconds");
tit.setCharacterSize(24);
score.setCharacterSize(24);
// dla centrowania obiektow
sf::FloatRect tempt = tit.getGlobalBounds();
sf::FloatRect tempr = score.getGlobalBounds();
tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
score.setOrigin(sf::Vector2f(tempr.width/2,tempr.height/2));
tit.setPosition(400,150);
score.setPosition(400,200);
score.setColor(sf::Color(0,127,127));
timer.restart();
};
示例5:
void Cursor::setCursorPos(const sf::Text &text)
{
sf::FloatRect textSize = text.getGlobalBounds();
sf::Vector2f textPos = text.getPosition();
_cursor.setPosition(textSize.width + textPos.x, textPos.y);
}
示例6: initialize
void initialize(sf::RenderWindow &mainWindow, sf::Font &mainFont)
{
titleText.setFont(mainFont);
titleText.setString("Triangle Super");
titleText.setCharacterSize(72);
titleText.setPosition(mainWindow.getSize().x/2 - titleText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/2 - titleText.getGlobalBounds().height/2.f);
playText.setFont(mainFont);
playText.setString("Play!");
playText.setCharacterSize(30);
playText.setPosition(mainWindow.getSize().x/3 - playText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/3 *2 - playText.getGlobalBounds().height/2.f);
quitText.setFont(mainFont);
quitText.setString("Quit.");
quitText.setCharacterSize(30);
quitText.setPosition(mainWindow.getSize().x/3 *2 - quitText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/3*2-quitText.getGlobalBounds().height/2.f);
scoreText.setFont(mainFont);
scoreText.setCharacterSize(30);
scoreText.setPosition(mainWindow.getSize().x/2 - scoreText.getGlobalBounds().width/2.f,
mainWindow.getSize().y/3-scoreText.getGlobalBounds().height/2.f);
}
示例7: 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);
}
示例8: draw
virtual void draw(RenderWindow *window) {
sf::RectangleShape box(window->getView().getSize());
box.setFillColor(color);
text.setPosition((window->getView().getSize() - Vector2f(text.getGlobalBounds().width, text.getGlobalBounds().height)) * 0.5f);
window->draw(text);
window->draw(box);
}
示例9: isTextClicked
bool isTextClicked(sf::Text text, sf::RenderWindow& window)
{
// check if mouse is currently intersecting with text
if(text.getGlobalBounds().intersects(sf::Rect<float> ((float)sf::Mouse::getPosition(window).x,
(float)sf::Mouse::getPosition(window).y, 8, 8)))
{
return true; // if so return true, text has been clicked
}
else return false; // else return false, text has NOT been clicked
}
示例10: generateGameModeButton
void MenuScreen::generateGameModeButton(sf::Text& button, const string& modeName,
short position, const sf::Font *font,
const sf::Vector2u& screenSize )
{
button = sf::Text( modeName, *font );
button.setColor( sf::Color::Blue );
button.setStyle( sf::Text::Regular );
sf::FloatRect textRect = button.getGlobalBounds();
button.setOrigin( textRect.left + textRect.width / 2.0f,
textRect.top + textRect.height / 2.0f );
button.setPosition( screenSize.x / 2, screenSize.y * 0.2 + position * Constants::LENGTH_BUTTON_SEPERATION );
}
示例11: init
virtual void init()
{
dt=0;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
darken = sf::RectangleShape(sf::Vector2f(800,400));
tit.setFont(standard_font);
tit.setString("Made by");
explain.setFont(standard_font);
explain.setString("Just a bored slacker");
explain.setCharacterSize(36);
explain.setPosition(260,320);
tit.setCharacterSize(24);
// dla centrowania obiektow
sf::FloatRect tempt = tit.getGlobalBounds();
tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
tit.setPosition(400,120);
if (!tex.loadFromFile("gfx/jabslogo.png"))
{
std::cout<<"Fuckup"<<std::endl;
}
spr.setTexture(tex);
spr.setPosition(334,144);
timer.restart();
};
示例12: init
virtual void init()
{
dt=0;
if (!standard_font.loadFromFile("fonts/Unique.ttf"))
{
// error...
}
darken = sf::RectangleShape(sf::Vector2f(800,400));
tit.setFont(standard_font);
subtit.setFont(standard_font);
tit.setString(title);
subtit.setString(subtitle);
tit.setCharacterSize(24);
subtit.setCharacterSize(18);
// dla centrowania obiektow
sf::FloatRect tempt = tit.getGlobalBounds();
sf::FloatRect temps = subtit.getGlobalBounds();
tit.setOrigin(sf::Vector2f(tempt.width/2,tempt.height/2));
subtit.setOrigin(sf::Vector2f(temps.width/2,temps.height/2));
tit.setPosition(400,150);
subtit.setPosition(400,180);
timer.restart();
};
示例13: draw
void Renderer::draw(sf::Text const& text, ZIndex_t zindex, sf::RenderStates const& states)
{
auto bounds = text.getGlobalBounds();
if(isInScreen(bounds))
{
m_drawCallbacks.push_back({
zindex,
[&text, states] (sf::RenderTarget& renderer)
{
renderer.draw(text, states);
}
});
}
}
示例14: trimTextToRectangleWidth
void assetHandle::trimTextToRectangleWidth(sf::Text &text, sf::RectangleShape &rect)
{
while(true)
{
sf::FloatRect floatRect = text.getGlobalBounds();
if ((floatRect.left + floatRect.width) > rect.getSize().x)
{
std::string newString = text.getString();
newString = newString.substr(0, newString.size()-1);
text.setString(newString);
}
else
break;
}
}
示例15: centerHonrizontally
void centerHonrizontally(sf::Text& text, unsigned int total_width)
{
const sf::FloatRect bounds = text.getGlobalBounds();
text.setPosition( (total_width - bounds.width) / 2, text.getPosition().y );
}