SFML community forums

Help => General => Topic started by: Njifra on December 02, 2013, 11:02:09 pm

Title: Insertion Point
Post by: Njifra on December 02, 2013, 11:02:09 pm
I need help with making insertion point.
If anyone doesn't know what is it, it is thingy('|') that appears and then disappears and so on... when you edit or insert text...
I really need help!!!
Thanks!!!
Title: Re: Insertion Point
Post by: Nexus on December 02, 2013, 11:36:47 pm
You mean the caret? Where are you stuck?
Title: Re: Insertion Point
Post by: eXpl0it3r on December 02, 2013, 11:59:11 pm
For a blinking cursor/insertion point/caret you can use rectangle shape and a clock to time it, but you need to be specific with what you need help. :)
Title: Re: Insertion Point
Post by: Njifra on December 03, 2013, 08:03:54 pm
Quote
Nexus said:
You mean the caret? Where are you stuck?
Yes, caret.
Well I'm making my own textbox, so im stuck at blinking cursor/insertion point/caret...
Charachter size that I'm using is 20...
Font is arial.ttf
Anything more?
For textbox I'm using sprite... It looks pretty awesome, just it is bad without caret, cuz you cant know if u selected textbox or so...
Oh, yes, I use SFML 2.0
Title: Re: Insertion Point
Post by: Nexus on December 03, 2013, 08:34:37 pm
I meant if you have already tried to implement it, and if there has been a specific problem.

Generally, look at the sf::Text and sf::Glyph classes. With them, you can find out the width of single characters. By comparing the character position with the mouse position, you know where the caret is placed. It requires some thinking, but it shouldn't be extremely difficult.
Title: Re: Insertion Point
Post by: Njifra on December 03, 2013, 08:39:27 pm
Can I just use sf::Text::getGlobalBound or getLocalBound to get width and height?
Title: Re: Insertion Point
Post by: Nexus on December 03, 2013, 08:43:14 pm
No, getGlobalBounds() only yields the position of the text's bounding rectangle. You are interested in the positions and sizes of the single characters in the text object.
Title: Re: Insertion Point
Post by: Njifra on December 03, 2013, 08:49:42 pm
Thanks for help!!!
Title: Re: Insertion Point
Post by: Laurent on December 03, 2013, 08:59:53 pm
http://www.sfml-dev.org/documentation/2.1/classsf_1_1Text.php#adf120ed4159e43daa782b17fea23ea82
Title: Re: Insertion Point
Post by: Njifra on December 03, 2013, 10:26:05 pm
Thanks Laurent and Nexus, I made working caret/insertion point, if anyone wants coding, just ask me!!!
:D