本文整理汇总了C++中sf::Text::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::getPosition方法的具体用法?C++ Text::getPosition怎么用?C++ Text::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::Text
的用法示例。
在下文中一共展示了Text::getPosition方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void WindowCreateThing::init(sf::RenderWindow &window) {
rectTitle.setSize(sf::Vector2f(window.getSize().x*0.45, window.getSize().y*0.07));
rectTitle.setPosition(sf::Vector2f(window.getSize().x/2-(rectTitle.getSize().x/2), window.getSize().x/4-(rectTitle.getSize().y/2)));
rectTitle.setFillColor(sf::Color(158, 158, 158));
rectTitle.setOutlineColor(sf::Color::Black);
rectTitle.setOutlineThickness(1.f);
rectMain.setSize(sf::Vector2f(window.getSize().x*0.45,window.getSize().y*0.45));
rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
rectMain.setFillColor(sf::Color::White);
rectMain.setOutlineColor(sf::Color::Black);
rectMain.setOutlineThickness(1.f);
load();
starting_position = sf::Mouse::getPosition(window);
textTitle.setFont(font);
textTitle.setString("CreateThings.txt");
textTitle.setCharacterSize(24);
textTitle.setColor(sf::Color::White);
textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
//textTitle.setPosition(sf::Vector2f(400,10));
textClose.setFont(font);
textClose.setString("X");
textClose.setStyle(sf::Text::Bold);
textClose.setCharacterSize(35);
textClose.setColor(sf::Color::White);
textClose.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x-30, rectTitle.getPosition().y+rectTitle.getSize().y*0.05));
///// FOLDER ICONE
textureFolder.setSmooth(true);
spriteFodler.setTexture(textureFolder);
sf::Vector2f targetSize(25.0f, 25.0f);
spriteFodler.setScale(
targetSize.x / spriteFodler.getLocalBounds().width,
targetSize.y / spriteFodler.getLocalBounds().height);
spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-targetSize.x, textTitle.getPosition().y));
///// CLOSE ICONE
/*textureClose.setSmooth(true);
spriteClose.setTexture(textureClose);
sf::Vector2f targetSize2(window.getSize().y*0.07, window.getSize().y*0.07);
spriteClose.setScale(
targetSize2.x / spriteClose.getLocalBounds().width,
targetSize2.y / spriteClose.getLocalBounds().height);
spriteClose.setPosition(rectTitle.getPosition().x+rectTitle.getSize().x-targetSize2.x, rectTitle.getPosition().y);*/
}
示例2: 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;
}
示例3:
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);
}
示例4: drawHUD
void Renderer::drawHUD(sf::Text const& text, sf::RenderStates const& states)
{
sf::Text t = text;
auto px = text.getPosition() / 100.f;
auto pw = m_renderer->mapPixelToCoords({static_cast<int>(px.x * m_screenRect.width), static_cast<int>(px.y * m_screenRect.height)});
t.setPosition(pw);
m_drawCallbacks.push_back({
ZIndex_t(ZIndex::HUD),
[t, states] (sf::RenderTarget& renderer)
{
renderer.draw(t, states);
}
});
}
示例5: update
void WindowCreateThing::update(sf::RenderWindow &window) {
sf::FloatRect test(rectTitle.getPosition().x, rectTitle.getPosition().y, rectTitle.getSize().x, rectTitle.getSize().y);
if(test.contains(sf::Mouse::getPosition(window).x, sf::Mouse::getPosition(window).y)){
if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && boo){
starting_position.x = sf::Mouse::getPosition(window).x-rectTitle.getPosition().x;
starting_position.y = sf::Mouse::getPosition(window).y-rectTitle.getPosition().y;
boo = false;
}
if( sf::Event::MouseMoved && sf::Mouse::isButtonPressed(sf::Mouse::Left) ){
rectTitle.setPosition( sf::Mouse::getPosition(window).x-starting_position.x, sf::Mouse::getPosition(window).y-starting_position.y );
rectMain.setPosition(sf::Vector2f(rectTitle.getPosition().x, rectTitle.getPosition().y+rectTitle.getSize().y));
textTitle.setPosition(sf::Vector2f(rectTitle.getPosition().x+rectTitle.getSize().x*0.3, rectTitle.getPosition().y+rectTitle.getSize().y*0.1));
spriteFodler.setPosition(sf::Vector2f(textTitle.getPosition().x-25.0f, textTitle.getPosition().y));
}
if(!sf::Mouse::isButtonPressed(sf::Mouse::Left)){
boo = true;
}
}
if(!sf::Mouse::isButtonPressed(sf::Mouse::Left)){
boo = true;
}
}
示例6: init_char_width
void init_char_width(){
if (!PTSANS.loadFromFile("PTN57F.ttf" )) return;
PTSANS_loaded = true;
string tq;
int tmp = log_string.getPosition().x;
for( int i = 255; i--; ){
tq = (char) i;
log_string.setString( tq );
char_width[i] = log_string.findCharacterPos( 1 ).x - tmp;
}
}
示例7: 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 );
}
示例8: CreateText
Primitive::Ptr Renderer::CreateText( const sf::Text& text, sf::Color background_color_hint ) {
Primitive::Ptr primitive( new Primitive );
const sf::Font& font = text.getFont();
unsigned int character_size = text.getCharacterSize();
sf::Color color = text.getColor();
if( m_preblend ) {
color = sf::Color::White;
}
sf::Vector2f atlas_offset = LoadFont( font, character_size, background_color_hint, text.getColor() );
const sf::String& str = text.getString();
std::size_t length = str.getSize();
float horizontal_spacing = static_cast<float>( font.getGlyph( L' ', character_size, false ).advance );
float vertical_spacing = static_cast<float>( font.getLineSpacing( character_size ) );
sf::Vector2f position( std::floor( text.getPosition().x + .5f ), std::floor( text.getPosition().y + static_cast<float>( character_size ) + .5f ) );
const static float tab_spaces = 2.f;
sf::Uint32 previous_character = 0;
for( std::size_t index = 0; index < length; ++index ) {
sf::Uint32 current_character = str[index];
position.x += static_cast<float>( font.getKerning( previous_character, current_character, character_size ) );
switch( current_character ) {
case L' ':
position.x += horizontal_spacing;
continue;
case L'\t':
position.x += horizontal_spacing * tab_spaces;
continue;
case L'\n':
position.y += vertical_spacing;
position.x = 0.f;
continue;
case L'\v':
position.y += vertical_spacing * tab_spaces;
continue;
default:
break;
}
const sf::Glyph& glyph = font.getGlyph( current_character, character_size, false );
Primitive::Vertex vertex0;
Primitive::Vertex vertex1;
Primitive::Vertex vertex2;
Primitive::Vertex vertex3;
vertex0.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left ), static_cast<float>( glyph.bounds.top ) );
vertex1.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left ), static_cast<float>( glyph.bounds.top + glyph.bounds.height ) );
vertex2.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left + glyph.bounds.width ), static_cast<float>( glyph.bounds.top ) );
vertex3.position = position + sf::Vector2f( static_cast<float>( glyph.bounds.left + glyph.bounds.width ), static_cast<float>( glyph.bounds.top + glyph.bounds.height ) );
vertex0.color = color;
vertex1.color = color;
vertex2.color = color;
vertex3.color = color;
// Let SFML cast the Rect for us.
sf::FloatRect texture_rect( glyph.textureRect );
vertex0.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top );
vertex1.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left, texture_rect.top + texture_rect.height );
vertex2.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top );
vertex3.texture_coordinate = atlas_offset + sf::Vector2f( texture_rect.left + texture_rect.width, texture_rect.top + texture_rect.height );
primitive->AddVertex( vertex0 );
primitive->AddVertex( vertex1 );
primitive->AddVertex( vertex2 );
primitive->AddVertex( vertex2 );
primitive->AddVertex( vertex1 );
primitive->AddVertex( vertex3 );
position.x += static_cast<float>( glyph.advance );
previous_character = current_character;
}
AddPrimitive( primitive );
return primitive;
}
示例9: CenterTextHor
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);
}
示例10: CenterTextVert
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);
}
示例11: DrawDropShadowText
// Render text with gaussian blur drop shadow
void ShadowTextRenderer::DrawDropShadowText(sf::RenderTarget& target, sf::Text& text, bool highQuality = true)
{
sf::View oldView = Utilities::SetDefaultView(target);
sf::RenderStates states = sf::RenderStates();
states.blendMode = sf::BlendMode::BlendAlpha;
if (gaussianShader && highQuality)
{
sf::FloatRect bounds = text.getGlobalBounds();
sf::Vector2u size = sf::Vector2u(bounds.width * 2.0f, bounds.height * 4.0f);
auto ptr = findFromTextureCache(size);
sf::RenderTexture* base;
if (ptr != 0)
base = ptr;
else
{
base = new sf::RenderTexture();
base->create(size.x, size.y);
base->setSmooth(true);
}
sf::View view = base->getView();
view.setCenter(text.getPosition().x + bounds.width / 2.0f, text.getPosition().y + bounds.height / 2.0f);
base->setView(view);
base->clear(sf::Color::Transparent);
sf::Color oldColor = text.getColor();
text.setColor(sf::Color::Black);
base->draw(text, states);
text.setColor(oldColor);
base->display();
ptr = findFromTextureCache(size);
sf::RenderTexture* shadow;
if (ptr != 0)
shadow = ptr;
else
{
shadow = new sf::RenderTexture();
shadow->create(size.x, size.y);
shadow->setSmooth(true);
}
view = shadow->getView();
view.setCenter(shadow->getSize().x / 2.0f, shadow->getSize().y / 2.0f);
shadow->setView(view);
shadow->clear(sf::Color::Transparent);
gaussianShader->setParameter("texture", base->getTexture());
gaussianShader->setParameter("resolution", bounds.width);
gaussianShader->setParameter("blurScale", 0.4f);
gaussianShader->setParameter("blurStrength", 0.5f);
gaussianShader->setParameter("blurAmount", 6.0f);
gaussianShader->setParameter("dir", sf::Vector2f(1.0f, 0.0f));
states.shader = gaussianShader;
shadow->draw(sf::Sprite(base->getTexture()), states);
shadow->display();
addToTextureCache(base);
sf::Texture shadowTex = shadow->getTexture();
shadow->clear(sf::Color::Transparent);
gaussianShader->setParameter("texture", shadowTex);
gaussianShader->setParameter("resolution", bounds.height);
gaussianShader->setParameter("dir", sf::Vector2f(0.0f, 1.0f));
states.shader = gaussianShader;
shadow->draw(sf::Sprite(shadowTex), states);
shadow->display();
states.shader = 0;
sf::Sprite shadowSpr = sf::Sprite(shadow->getTexture());
shadowSpr.setPosition(text.getPosition() - sf::Vector2f(shadow->getSize().x / 2.0f , shadow->getSize().y / 2.0f) + sf::Vector2f(bounds.width / 2.0f, bounds.height / 2.0f));
target.draw(shadowSpr, states);
addToTextureCache(shadow);
//sf::Sprite baseSpr = sf::Sprite(base.getTexture());
//baseSpr.setPosition(text.getPosition() + (text.getPosition() - view.getCenter()));
}
else
{
sf::Vector2f oldPos = text.getPosition();
text.setPosition(oldPos - sf::Vector2f(2.0f, 2.0f));
sf::Color oldColor = text.getColor();
text.setColor(sf::Color::Black);
target.draw(text, states);
//.........这里部分代码省略.........