SFML community forums

Help => Graphics => Topic started by: LB on July 02, 2011, 03:07:04 am

Title: Drawing TextBox.
Post by: LB on July 02, 2011, 03:07:04 am
I'm trying to draw a textbox with SFML (2.0). It, basicly a box drawed as background, a sf::Text with the contents and a sf::Sprite with the cursor. My problem is to limit the drawed text to the box, to don't show any text outside the textbox. I tryed to do it with sf::View but I failed. I'm also thinking on blit (pixel by pixel) each glyph in an sf::Image and draw it. It probably works, but is not a fast way. What is the best way to do it?

Also, a possible interesting function to be added is a Drawable::SetClipRect(IntRect), to draw just a part of the object. It can be useful for tiled images or for cases like mine.
Title: Drawing TextBox.
Post by: Haikarainen on July 02, 2011, 07:40:48 am
In the future you will be able to use RenderMasks(if i recall correctly).

For now, look at sf::Text::GetRect(), sf::Text::GetCharacterSize() and its other functions, dont remember how i did it but it can be done and is easy.

Have 1 std::string containing the full text, and then pick an appropriate number of letters from that string and sf::Text::SetString(std::string::c_str()).
Title: Drawing TextBox.
Post by: LB on July 02, 2011, 03:37:09 pm
But how to draw just a part of the string (splitting glyphs)?

Sample:

(http://i56.tinypic.com/33afml1.png)

Note that it don't shows the entire "r", just a half. I think it should be done with some kind of viewport.
Title: Drawing TextBox.
Post by: Haikarainen on July 02, 2011, 03:53:17 pm
Quote from: "LB"
But how to draw just a part of the string (splitting glyphs)?

Sample:

(http://i56.tinypic.com/33afml1.png)

Note that it don't shows the entire "r", just a half. I think it should be done with some kind of viewport.


I never ought'd to care about that, i just split the string. I guess the effect could be achievable using views, but if you are going to create something consistent i would wait for rendermasks :)
Title: Drawing TextBox.
Post by: JAssange on July 02, 2011, 06:30:41 pm
You could render to a render target image and then render a subrect of the image that now contains the text.
Title: Drawing TextBox.
Post by: LB on July 02, 2011, 07:02:49 pm
Cool! It is exactly what I was wanting. Thank you!