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

Author Topic: National letters - input text on screen  (Read 1761 times)

0 Members and 1 Guest are viewing this topic.

Mr.Goose

  • Newbie
  • *
  • Posts: 4
    • View Profile
National letters - input text on screen
« on: August 03, 2023, 05:00:53 pm »
Hi everyone!

I have one issue, where I need your help with. I made field, where you can write name of your character, when you making it. Everything looks fine, but I can't figure out how can I input my national (polish) letters in (ę, ó, ą, ś, ł, ż, ź, ć, ń).

Here is my code:

(click to show/hide)

I tried everything, for ex. I tried to implement unicode numbers to this "else if", but only two letters works ("Ó, ó"). Another letters are replaced by another.

Can you help me with that issue?

fallahn

  • Hero Member
  • *****
  • Posts: 507
  • Buns.
    • View Profile
    • Trederia
Re: National letters - input text on screen
« Reply #1 on: August 03, 2023, 07:12:05 pm »
Assuming name_input_string is a std::string (hard to tell without a namespace) try:

Code: [Select]
char_creation_name_input_txt.setString(sf::String::fromUtf8(name_input_string.begin(), name_input_string.end());

Mr.Goose

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: National letters - input text on screen
« Reply #2 on: August 03, 2023, 08:20:13 pm »
Unfortunetly, that doesn't work. Characters still doesn't show up or are replaced by other characters, when I delete that "else if".

I tried to change advanced save settings in Visual Studio 2022 from Middleeuropean (codepage 1250) to UTF-8, but that doesn't works too.

Yes, name_input_string is exacly string.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: National letters - input text on screen
« Reply #3 on: August 03, 2023, 10:18:38 pm »
I have to ask but are the characters you are hoping to see within the range you allow?

unicode 65-90 and 97-122.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mr.Goose

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: National letters - input text on screen
« Reply #4 on: August 05, 2023, 10:09:26 am »
Yes, after fallahn suggestions I deleted that "else if" with unicode range. Unfortunetly when I do this, my national letters are replaced by other letters, for ex. "ń" is replaced by "D".

EDIT:
Additional info! When I just draw texts on screen, I just write letter "L" before string. For ex.:

(click to show/hide)

This letter "L" works, but when I want to write text directly on screen, that doesn't works.
« Last Edit: August 05, 2023, 11:18:29 pm by Mr.Goose »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: National letters - input text on screen
« Reply #5 on: August 06, 2023, 09:45:02 pm »
Ah, have you tried using a wide string? i.e. std::w_string

There are 'better' string types for unicode characters but, apparently, SFML doesn't support them yet.

https://www.sfml-dev.org/tutorials/2.6/graphics-text.php#how-to-avoid-problems-with-non-ascii-characters
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

kimci86

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: National letters - input text on screen
« Reply #6 on: August 06, 2023, 10:26:53 pm »
If name_input_string is an std::string and you do:
Code: [Select]
name_input_string += ev->text.unicode;then the 4-bytes unicode character will be narrowed down to only one byte and lose information.
For example "ń" (unicode character U+0144) becomes "D" (unicode character U+0044). Only the least significant byte is added to the string.

You can use sf::String instead of std::string to store unicode characters.
Alternatively you could encode unicode characters to UTF-8 encoding to store them in an std::string.
« Last Edit: August 06, 2023, 11:01:25 pm by kimci86 »

Mr.Goose

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: National letters - input text on screen
« Reply #7 on: August 08, 2023, 09:27:31 am »
And that finally works!

I just change string to String, as you said.

Thank you kimci86 and everyone else for help!

 

anything