1
Window / 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:
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):
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.
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.