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

Author Topic: sf::Event::TextEvent producing '\v' when Enter is pressed, instead of '\n'?  (Read 5219 times)

0 Members and 1 Guest are viewing this topic.

Clairvoire

  • Newbie
  • *
  • Posts: 29
    • AOL Instant Messenger - Clairvoire
    • View Profile
    • http://clairvoire.deviantart.com
When inspecting a 'text entered' event, the integer I get from sf::Event::TextEvent::unicode is 13, for carriage return.  I would've expected this to be 10, or '\n' for newline. 

Is this intended, or is something going wrong here?  (I've never encountered a carriage return before, so this took me a bit by surprise)
« Last Edit: August 18, 2014, 08:28:04 am by Clairvoire »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
I'm guessing this is a confusion about number bases.
Vertical tab is 11 (decimal), 13 (octal) and carriage return is 13 (decimal), 15 (octal).
« Last Edit: August 18, 2014, 08:39:28 am by Jesper Juhl »

czaloj

  • Newbie
  • *
  • Posts: 5
    • View Profile
I'm gonna post this here since it's kinda on the same topic:

    WTF SFML!!!!! You send enter/tab/backspace as text events... really? I converted a text handler to an SFML implementation (it works perfectly with SDL and GLFW text events), and lo and behold... it doesn't work as I planned. Thank you dev(s). ..|.. You really followed the standard.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Quote
You really followed the standard.
I'm curious to know which standard.

Quote
WTF SFML!!!!! You send enter/tab/backspace as text events... really?
We just forward what the OS generates for its corresponding native event (WM_CHAR on Windows, for example). It's not SFML that decides what is suitable for the TextEntered event, it's the OS.

And no need to be so rude, just filter out the characters that you don't need... There are useful functions for that in the standard library.
Laurent Gomila - SFML developer

czaloj

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sorry, much of my anger is because of some guy in my project being an SFML purist. It's just that when you say TextEvent - I expect text:

void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods, int plain)
{
    if (codepoint < 32 || (codepoint > 126 && codepoint < 160))
        return;
     // ...
 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
As Laurent said, SFML's TextEntered event is using what the OS provides. Whether you've a different expectation or not, is nothing we can influence by any means.
This also means that the event is not limited to ASCII, but instead will return unicode characters as well.

And last but not least \n, \t and even \b are in my opinion text characters as well.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

czaloj

  • Newbie
  • *
  • Posts: 5
    • View Profile
Another example of standard text input:

int
SDL_SendKeyboardText(const char *text)
{
    SDL_Keyboard *keyboard = &SDL_keyboard;
    int posted;

    /* Don't post text events for unprintable characters */
    if ((unsigned char)*text < ' ' || *text == 127) {
        return 0;
    }
 

I guess I'm just saying it would be nice if you adhered to what other APIs are doing for text events, call it some other event type, or EMPHATICALLY state what your function is doing.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10800
    • View Profile
    • development blog
    • Email
Another example of standard text input:
There's not "standard" so you should stop using that word in this context. ;)

I guess I'm just saying it would be nice if you adhered to what other APIs are doing for text events, call it some other event type, or EMPHATICALLY state what your function is doing.
We don't change implementations just because other libraries do it differently. We provide what the OS provides and if something doesn't suit the user's need, they can very easily filter it out themselves. If we were filtering by default and someone wanted to use the events, they'd have to edit SFML's source code to achieve what they want. As such the current implementation gives more freedom to the user.

And it is emphasized in the tutorial:
Note that, since they are part of the Unicode standard, some non-printable characters such as backspace are generated by this event. In most cases you'll need to filter them out.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

czaloj

  • Newbie
  • *
  • Posts: 5
    • View Profile
Ok, would you please link this kind of information to the documentation, because it is not clear as it currently stands. I never stumbled on that tutorial as I looked at your docs.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Events Explained
Directly after the code snippet.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord


BlueCobold

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Sorry, but in my eyes not sending \r, \t or \b like SDL does, to me is a bug. They are characters you enter by pressing keys on your keyboard. Different applications will handle these keys differently (IDE vs. Browser for example), but the framework shouldn't decide about what the application wants to do with the entered key, the application should. Freedom to the developer is the key here.

 

anything