1
Python / Re: SFML and wxpython playing nicely
« on: July 15, 2016, 11:37:12 am »
It is possible with pysfml-cython and wxpython. Here is how: gist.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
If I understand, you want an input class that let's you know if a key was just pressed, just released and if it is hold?
I've done this time ago. It's pretty simple, just have two array of bool (one for key pressed and other for key released). The hold state is actually returning sf::Input::IsKeyDown.
Now just take care of reseting the states every frame, then pass the sf::Event(s) to the wrapper class to update the pressed and released states and that's all!
That's not necessarily elegant. Inheritance is often abused.
I believe you have a wrong understanding of OOP. The way of thinking, where object-oriented programming and extensibility can only be achieved through inheritance, is typical for languages like Java, but only one possibility in multi-paradigm C++.
In my opinion, Laurent (the SFML developer) had a good reason to make those members private. Protected access is only useful, if inherited classes are really desired and need access to the base class – that is, by design. If the public interface covers the necessary interactions, there is no need to expose the internal implementation. Breaking encapsulation (whether it's by making members public or protected) is generally a bad idea, as it binds the user to a concrete implementation, making future changes difficult.
You should try to find a less intrusive solution to achieve the desired functionality. What if you wrap sf::Input (write a class containing sf::Input as member and forward functions)?
enum KeyStates{
NOKEY = 1,
KEYPRESSED = 2,
//modifiers
KEYCHANGED = 4,
KEYDOWN = KEYPRESSED | KEYCHANGED,
KEYUP = NOKEY | KEYCHANGED
};
case Event::KeyPressed :
if(myKeys[EventReceived.Key.Code] == NOKEY) {
myKeys[EventReceived.Key.Code] = KEYDOWN;
}
else {
myKeys[EventReceived.Key.Code] = KEYPRESSED;
}
break;
case Event::KeyReleased :
if(myKeys[EventReceived.Key.Code] == KEYPRESSED) {
myKeys[EventReceived.Key.Code] = KEYUP;
}
else {
myKeys[EventReceived.Key.Code] = NOKEY;
}
break;
for (int i = 0; i < Key::Count; ++i) {
myKeys[i] = NOKEY;
//myKeysCurrent[i] = NOKEY;
//myKeysLast[i] = NOKEY;
}
void Input::FlushKeychangedStates()
{
for (int i = 0; i < Key::Count; ++i) {
if(myKeys[i] & KEYPRESSED) {
myKeys[i] = KEYPRESSED;
}
else if(myKeys[i] & NOKEY) {
myKeys[i] = NOKEY;
}
//myKeysCurrent[i] = NOKEY;
//myKeysLast[i] = NOKEY;
}
}