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

Author Topic: Event subtypes inaccessible  (Read 4529 times)

0 Members and 1 Guest are viewing this topic.

amiralawi

  • Newbie
  • *
  • Posts: 2
    • View Profile
Event subtypes inaccessible
« on: September 28, 2007, 06:18:18 am »
Currently the event class is setup using an anonymous union and named (but otherwise inaccessible) structs:

Code: [Select]
class Event
{
public :

    ////////////////////////////////////////////////////////////
    /// Enumeration of the different types of events
    ////////////////////////////////////////////////////////////
    enum EventType
    {
        Close,
        Resize,
        LostFocus,
        GainedFocus,
        TextEntered,
        KeyPressed,
        KeyReleased,
        MouseWheelMoved,
        MouseButtonPressed,
        MouseButtonReleased,
        MouseMove,
        JoystickButtonPressed,
        JoystickButtonReleased,
        JoystickMove
    };

    ////////////////////////////////////////////////////////////
    // Member data
    ////////////////////////////////////////////////////////////
    EventType Type; ///< Type of the event

    union
    {

        ////////////////////////////////////////////////////////////
        /// Text event parameters
        ////////////////////////////////////////////////////////////
        struct
        {
            Uint16 Unicode;
        } Text;

        ////////////////////////////////////////////////////////////
        /// Keyboard events parameters
        ////////////////////////////////////////////////////////////
        struct
        {
            Key::Code Code;
            bool      Alt;
            bool      Control;
            bool      Shift;
        } Key;

        ////////////////////////////////////////////////////////////
        /// Mouse events parameters
        ////////////////////////////////////////////////////////////
        struct
        {
            unsigned int Buttons;
            unsigned int X;
            unsigned int Y;
        } Mouse;

        ////////////////////////////////////////////////////////////
        /// Mouse wheel events parameters
        ////////////////////////////////////////////////////////////
        struct
        {
            int Delta;
        } MouseWheel;

        ////////////////////////////////////////////////////////////
        /// Joystick events parameters
        ////////////////////////////////////////////////////////////
        struct
        {
            unsigned int JoystickId;
            unsigned int Button;
            int          X;
            int          Y;
            int          Z;
        } Joystick;

        ////////////////////////////////////////////////////////////
        /// Size events parameters
        ////////////////////////////////////////////////////////////
        struct
        {
            unsigned int Width;
            unsigned int Height;
        } Size;
    };
};


Is there any particular reason for this?  If the structures were defined separately from their instantiations in the event class then they would be accessible outside of the class while still preserving their current usability (ie, won't break anyone's code):


Code: [Select]
class Event
{
public :

    ////////////////////////////////////////////////////////////
    /// Enumeration of the different types of events
    ////////////////////////////////////////////////////////////
    enum EventType
    {
        Close,
        Resize,
        LostFocus,
        GainedFocus,
        TextEntered,
        KeyPressed,
        KeyReleased,
        MouseWheelMoved,
        MouseButtonPressed,
        MouseButtonReleased,
        MouseMove,
        JoystickButtonPressed,
        JoystickButtonReleased,
        JoystickMove
    };

struct TextEvent{
Uint 16 Unicode;
};

struct KeyEvent{
Key::Code Code;
bool Alt;
bool Control;
bool Shift;
};

struct MouseEvent{
unsigned int Buttons;
unsigned int X;
unsigned int Y;
};

//etc.

    EventType Type; ///< Type of the event

    union
    {
        TextEvent Text;
KeyEvent Key;
MouseEvent Mouse;

//etc.
    };
};


The reason I bring this up is because this is creating a problem in my effort to create a set of python bindings.  I can work around it, but the result will be a very inelegant one, and it seems like this is how it should be anyways.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Event subtypes inaccessible
« Reply #1 on: September 28, 2007, 08:16:42 am »
I think you should do the same way as the Ruby binding. Events in RubySFML are no more a union of structs, they are just unions of members. In other words, you just put / fill (I don't know about the details) the members matching the event type.
Laurent Gomila - SFML developer

 

anything