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

Author Topic: Insertion Point  (Read 1688 times)

0 Members and 1 Guest are viewing this topic.

Njifra

  • Guest
Insertion Point
« 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!!!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Insertion Point
« Reply #1 on: December 02, 2013, 11:36:47 pm »
You mean the caret? Where are you stuck?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Insertion Point
« Reply #2 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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Njifra

  • Guest
Re: Insertion Point
« Reply #3 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
« Last Edit: December 03, 2013, 08:40:02 pm by Njifra »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Insertion Point
« Reply #4 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Njifra

  • Guest
Re: Insertion Point
« Reply #5 on: December 03, 2013, 08:39:27 pm »
Can I just use sf::Text::getGlobalBound or getLocalBound to get width and height?
« Last Edit: December 03, 2013, 08:42:51 pm by Njifra »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Insertion Point
« Reply #6 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Njifra

  • Guest
Re: Insertion Point
« Reply #7 on: December 03, 2013, 08:49:42 pm »
Thanks for help!!!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Laurent Gomila - SFML developer

Njifra

  • Guest
Re: Insertion Point
« Reply #9 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