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

Author Topic: TextEntered Event does weird stuff  (Read 3965 times)

0 Members and 1 Guest are viewing this topic.

Trampeltier

  • Newbie
  • *
  • Posts: 8
    • View Profile
TextEntered Event does weird stuff
« on: January 15, 2014, 09:51:15 pm »
Hi everyone,
my problem is that if I use the TextEntered-Event, It's working fine, BUT there will spawn RANDOM GENERATED CHARACTERS  :o :o :o :o
It's not the first time it happened to me - in my last project aswell.
I'm using the event as given in the documentation, so am I the only one beeing affected by that?
Could there be programs, which create these symbols?
Here is an example of the symbols - I have saved them by using fstream:

Ì  îÞÑ´ª¢š‰~o^IA<5&    
,,F“¨¶Üëø ÿüôîéä×ÑÈÀ¬ —Ž|pcU.zzjYF?;742111 1111111111111111000 ÿ໕e4%% ÷éÚǵž‹u_M=.#    !$&()+,-..///00/-("
$).269<>@B>=;::98740+%~vi]QD9*þìßʹ¨šŽ~ri`WOH?80' '/:=@@ABBCDDFFHKNUY\adgknstvwxxxxyyyyyyyxvvusqokgffeedccbZVRK5&)S~¦Çé
þûûú ÷ôóòññïîÜƱ ‰uI2*>LWabdd\P B.

 ””­É'ùÌ {[

þþü.>O^’¥³ÂÌÔÙàãåæææèéêêêêêêéééçåáÞÚÔÎÈþº¹¹¹º½ÂÉÓåù`bcddeed^320/.,+)'&%$$$$$$$$$$$$$11ƒƒ{uqkd^ZVROLIFC@=;:876555544444445569<?BDEGGHHIIJJKMNPSWZ_bfilortwy{~€‚‚‚ƒ„„„      cceffgghijjjjj29ABDEFFFFEDA?=;862-'8889<>ADGJQTYbekqw}ˆ’—› ¤¨­±³µ¶¶······¸¸º»¼¼¼ÆÏÖÝÞÞÞÞ*8DLWXYYYYTO.7899MŽ…}uqooqrty{|ƒ‡Œ’¥­³´´´±¬¨¢š“Šjjlmmlkhecba`WVRI3ÿã '>HVaqwyy yyyyvvurpnl &"%Œ’–š¡§©«ª§¦¥¢ œ™˜—–‘Ž‹ˆ„}wsnheba`_^][WUTNIGEA>:974&-'T~±1BR\djoqtyzz{|}~€„‡‹Ž““’’‘‘‘““”••—˜˜˜šúáÃŽw`M0  "1<HUdimpstux}‡‰‹ŒŒŽ‘’•–˜˜™šš›œœž ¢±±°¯¯®®®®®®®®¯²µ·ºÁÅÉÌÖÙÜÞÞáãäää äãáàÝÛÙ×ÖÑÏÌÊÅÃÀ½´°«¥™“ˆ|vqld`[WMJFEZesŒ— ¡ ‹|m\>/!De—›œ œŸ§®µ¿ÐÖÕ̺¨qIººººººº¹¹¹¼½ÁÄÉÎ×ãìõü  !##$$%%%%$#!!!!ëêç1Kdz% 77779<>??60+&" ü÷ôðíêéèçåáÞÚØÕÒÐÎÍÌËÕÜâéïöý  !#%'.4;DO\hu‡­yF ךe5%4?IU_gov{ƒƒ„„†‡ˆ‰ŠŒ…~tk^QB/"*2:@GLN[]ekw}ƒ‰’™Ÿ£«nA 


If there is no way fixing that, should I use the KeyPressed-Event?

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: TextEntered Event does weird stuff
« Reply #1 on: January 15, 2014, 10:00:14 pm »
Please post a complete and minimal example.

http://en.sfml-dev.org/forums/index.php?topic=5559.0

(Taking a guess here... you aren't encoding/decoding something properly or worse still, incorrectly using the event loop)
« Last Edit: January 15, 2014, 10:02:57 pm by zsbzsb »
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Trampeltier

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: TextEntered Event does weird stuff
« Reply #2 on: January 15, 2014, 10:21:48 pm »
So my code looks like this:


//This function is triggered in the main function
void game::events::mainEvents()
{
        sf::Event Event;
        while (game::Window->pollEvent(Event))
        {
                switch (Event.type)
                {
                case sf::Event::Closed:
                        game::events::Close(Event);
                case sf::Event::Resized:
                        game::events::Resize(Event);
                case sf::Event::MouseMoved:
                        game::events::MouseMove(Event);
                case sf::Event::MouseButtonReleased:
                        game::events::MouseReleased(Event);
                case sf::Event::TextEntered:
                        game::events::TextEntered(Event);
                }
        }
}

//This is the TextEntered-Event Function:
void game::events::TextEntered(sf::Event& Event)
{
        for(unsigned int i = 0; i < game::gui::GUIManagerVector.size(); i++)
        {
                game::gui::GUIManagerVector[i]->CheckPossibleTextEntered(Event, *game::Window);
        }
}

void game::gui::GUIManager::CheckPossibleTextEntered(sf::Event& Event, sf::RenderWindow& Window)
{
        for(size_t i = 0; i <  this->InputBoxes.size(); i++)
        {
                if (InputBoxes[i]->GetState())
                {
                        char TempChar = static_cast<char>(Event.text.unicode);
                        std::string TempString(1, TempChar);
                        std::cout << TempString;
                        std::ofstream Write("weirdtext.txt", std::ios::app);
                        Write<< TempString;
                        Write.close();
                       
                        InputBoxes[i]->AddText(TempString);
                }
        }
}

 

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: TextEntered Event does weird stuff
« Reply #3 on: January 15, 2014, 10:29:18 pm »
You lack breaks in your switch.
Back to C++ gamedev with SFML in May 2023

Trampeltier

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: TextEntered Event does weird stuff
« Reply #4 on: January 15, 2014, 10:50:42 pm »
Thanks, so now I'm using if-statement instead of switch and it's working!
But why is that if I may ask you?

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: TextEntered Event does weird stuff
« Reply #5 on: January 15, 2014, 11:23:19 pm »
You just needed to add breaks to the switch... like here: http://www.sfml-dev.org/tutorials/2.1/window-events.php
switch cases in c++ fall through, compiler may warn but must compile that, in C# it's forbidden to omit breaks after cases that contain code to prevent bugs like this one.
Back to C++ gamedev with SFML in May 2023

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: TextEntered Event does weird stuff
« Reply #6 on: January 15, 2014, 11:46:53 pm »
I typed the text entered event given in the vs 2.1 event tutorial and got a compile error " cout not recognized"  What gives please?
Thanks

math1992

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • Email
Re: TextEntered Event does weird stuff
« Reply #7 on: January 16, 2014, 02:25:04 am »
Did you forget
 #include <iostream>
or
using namespace std;
?
« Last Edit: January 16, 2014, 02:28:01 am by math1992 »

wvtrammell

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: TextEntered Event does weird stuff
« Reply #8 on: January 16, 2014, 04:25:51 am »
Thanks
That fixed it.

wintertime

  • Sr. Member
  • ****
  • Posts: 255
    • View Profile
Re: TextEntered Event does weird stuff
« Reply #9 on: January 16, 2014, 11:31:23 am »
That is wrong:
            char TempChar = static_cast<char>(Event.text.unicode);
            std::string TempString(1, TempChar);
 
You should collect the UTF-32 characters you get in a sf::string. Then use sf::Text to draw it or do correct conversion to other encodings.

 

anything