In my event polling part i have something looking like this at the moment. It does its work nicely:
while(this->window.pollEvent(event)) {
switch(event.type) {
case sf::Event::TextEntered:
if (gui.selectedItem.type == GUI_TEXTFIELD) {
gui.handleTextEntered(event.text.unicode);
}
break;
}
}
And then in my gui class the handleTextEntered function looks a bit like this:
void GuiClass::handleTextEntered(sf::Uint32 key) {
if (key >= 128 || key == 27 || key == 13) return;
if (key == 8) {
if (wins[selectedItem.win].textfields[selectedItem.nr].text != "")
wins[selectedItem.win].textfields[selectedItem.nr].text.erase(wins[selectedItem.win].textfields[selectedItem.nr].text.getSize()-1, 1);
return;
}
if (selectedItem.type == GUI_TEXTFIELD) {
wins[selectedItem.win].textfields[selectedItem.nr].text += static_cast<char>(key);
}
}
It's a bit crude and requires an overhaul, but it does the job.
n the code you sent me, could you explain to me the second part ?
you see i am using a generic code by having a Interface class. Everybody inherits it.
I have a TextBox class with :
class TextBox : public IObject
20 {
21 private:
22 int _x;
23 int _y;
24 int _height;
25 int _width;
26 int _type;
27 bool _isVisible;
28 bool _isConcerned;
29 std::string _color;
30 sf::RectangleShape *_box;
31 sf::Font *_font;
32 sf::Text *_text;
i have a CreateObject() function and a DrawObject() function for each classes (objects). How do i apply your code to my class ?