Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing TextBox.  (Read 4189 times)

0 Members and 1 Guest are viewing this topic.

LB

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Drawing TextBox.
« 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.

Haikarainen

  • Guest
Drawing TextBox.
« Reply #1 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()).

LB

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Drawing TextBox.
« Reply #2 on: July 02, 2011, 03:37:09 pm »
But how to draw just a part of the string (splitting glyphs)?

Sample:



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

Haikarainen

  • Guest
Drawing TextBox.
« Reply #3 on: July 02, 2011, 03:53:17 pm »
Quote from: "LB"
But how to draw just a part of the string (splitting glyphs)?

Sample:



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 :)

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Drawing TextBox.
« Reply #4 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.

LB

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Drawing TextBox.
« Reply #5 on: July 02, 2011, 07:02:49 pm »
Cool! It is exactly what I was wanting. Thank you!