Welcome,
Guest
. Please
login
or
register
. Did you miss your
activation email?
French forum
Home
Help
Search
Login
Register
SFML community forums
»
Help
»
Graphics
»
sf::View - not working correct
Print
Pages: [
1
]
Author
Topic: sf::View - not working correct (Read 640 times)
0 Members and 1 Guest are viewing this topic.
tBane
Newbie
Posts: 2
sf::View - not working correct
«
on:
December 08, 2024, 11:20:53 am »
Hi! I tried positioning text in texture but my code now work. I think so SFML 2.6.2 not working correctly, because I think my code is correct. I use global coordinates for all objects and result is in screenshot. I think this red bar should be a hover of blue rect.
(click to show/hide)
ScrollableText::ScrollableText(std::wstring text) : Dialog(DialogType::ScrollableText) {
border = sf::RectangleShape(sf::Vector2f(width, height));
border.setFillColor(panelColor_dark);
border.setPosition(cam->position.x-width/2.0f, cam->position.y-height/2.0f);
rect = sf::RectangleShape(sf::Vector2f(width-2*borderWidth, height-2*borderWidth));
rect.setFillColor(panelColor_normal);
rect.setPosition(cam->position.x - width/2.0f + borderWidth, cam->position.y - height/2.0f+borderWidth);
sf::Vector2f scrollbar_size = sf::Vector2f(16, height - 2.0f * borderWidth);
textarea = new TextArea(text, cam->position, width - 2.0f*borderWidth - 2.0f*margin - scrollbar_size.x);
textarea->setPosition(sf::Vector2f(- width/2.0f + borderWidth + margin, - height/2.0f + borderWidth + margin));
sf::Vector2f scrollbar_position = sf::Vector2f(width/2.0f-borderWidth-scrollbar_size.x, -height/2.0f + borderWidth);
float scroll_max = textarea->getSize().y + textarea->getLineHeight();
float scroll_len = height;
scrollbar = new Scrollbar(scrollbar_size, scrollbar_position, 0, scroll_max, 0, scroll_len);
// TO-DO - generowanie tekstury przewijalnej dla tekstu
text_texture.create(width-2.0f*(borderWidth+margin) - scrollbar_size.x, height-2.0f*(borderWidth+margin));
sf::View v = sf::View(sf::FloatRect(sf::Vector2f(cam->position.x-width/2.0f+borderWidth+margin, cam->position.y-height/2.0f+borderWidth+margin), sf::Vector2f(width-2*(borderWidth+margin), height-2*(borderWidth+margin))));
text_texture.setView(v);
text_texture.setSmooth(true);
text_texture.clear(sf::Color::Red);
textarea->setRectColor(sf::Color::Blue);
text_texture.draw(textarea->rect);
for (auto& text : textarea->texts)
text_texture.draw(text);
text_texture.display();
text_sprite = sf::Sprite(text_texture.getTexture());
sf::Vector2f textpos;
textpos.x = cam->position.x + position.x - width / 2.0f + borderWidth + margin - (textarea->texts[0].getPosition().x-textarea->rect.getPosition().x);
textpos.y = cam->position.y + position.y - height / 2.0f + borderWidth + margin - (textarea->texts[0].getPosition().y - textarea->rect.getPosition().y);
text_sprite.setPosition(textpos);
// TO-DO
}
«
Last Edit: December 08, 2024, 11:29:49 am by tBane
»
Logged
eXpl0it3r
SFML Team
Hero Member
Posts: 11049
Re: sf::View - not working correct
«
Reply #1 on:
December 08, 2024, 10:00:43 pm »
Unfortunately, I don't quite understand what you're trying to say (maybe a translation tool can help?)
What does "be a hover" mean in "I think this red bar should be a hover of blue rect"?
Logged
Official FAQ:
https://www.sfml-dev.org/faq.php
Official Discord Server:
https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog:
https://duerrenberger.dev/blog/
tBane
Newbie
Posts: 2
Re: sf::View - not working correct
«
Reply #2 on:
December 09, 2024, 08:33:40 am »
Sorry for the poor wording. I need to render a texture that I create using text. I've already found a solution:
(click to show/hide)
sf::View v = sf::View( sf::FloatRect( sf::Vector2f( cam->position.x - width / 2.0f + borderWidth + margin, cam->position.y - height / 2.0f + borderWidth + margin ), sf::Vector2f( width - 2 *( borderWidth + margin ) - scrollbar->size.x, height - 2 *( borderWidth + margin ) ) ) );
Logged
Print
Pages: [
1
]
SFML community forums
»
Help
»
Graphics
»
sf::View - not working correct