Class: SDL2::Event
- Inherits:
-
Object
- Object
- SDL2::Event
- Defined in:
- event.c,
event.c
Overview
This class represents SDL’s events.
All events are represented by the instance of subclasses of this class.
Introduction of event subsystem
Event handling allows your application to receive input from the user. Event handling is initialized (along with video) with a call to:
SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
Internally, SDL stores all the events waiting to be handled in an event queue. Using methods like Event.poll, you can observe and handle input events.
The queue is conceptually a sequence of objects of SDL2::Event. You can read an event from the queue with Event.poll and you can process the information from the object.
Note: peep and wait will be implemented later.
Direct Known Subclasses
ControllerAxisMotion, ControllerButton, ControllerDevice, JoyAxisMotion, JoyBallMotion, JoyButton, JoyDevice, JoyHatMotion, Keyboard, MouseButton, MouseMotion, MouseWheel, Quit, SysWM, TextEditing, TextInput, TouchFinger, Window
Defined Under Namespace
Classes: ControllerAxisMotion, ControllerButton, ControllerButtonDown, ControllerButtonUp, ControllerDevice, ControllerDeviceAdded, ControllerDeviceRemapped, ControllerDeviceRemoved, FingerDown, FingerMotion, FingerUp, JoyAxisMotion, JoyBallMotion, JoyButton, JoyButtonDown, JoyButtonUp, JoyDevice, JoyDeviceAdded, JoyDeviceRemoved, JoyHatMotion, KeyDown, KeyUp, Keyboard, MouseButton, MouseButtonDown, MouseButtonUp, MouseMotion, MouseWheel, Quit, SysWM, TextEditing, TextInput, TouchFinger, Window
Instance Attribute Summary collapse
-
#timestamp ⇒ Integer
timestamp of the event.
-
#type ⇒ Integer
SDL’s internal event type enum.
Class Method Summary collapse
-
.enable=(bool) ⇒ Boolean
Set wheter the event is enable.
-
.enabled? ⇒ Boolean
Get whether the event is enabled.
-
.poll ⇒ SDL2::Event?
Poll for currently pending events.
Instance Method Summary collapse
-
#inspect ⇒ String
Inspection string.
-
#window ⇒ SDL2::Window
Return the object of Window corresponding to the window_id attribute.
Instance Attribute Details
#timestamp ⇒ Integer
timestamp of the event
#type ⇒ Integer
SDL’s internal event type enum
Class Method Details
.enable=(bool) ⇒ Boolean
158 159 160 161 162 163 164 165 |
# File 'event.c', line 158
static VALUE Event_s_set_enable(VALUE self, VALUE val)
{
VALUE event_type = rb_iv_get(self, "event_type");
if (event_type == Qnil)
rb_raise(rb_eArgError, "You cannot enable %s directly", rb_class2name(self));
SDL_EventState(NUM2INT(event_type), RTEST(val) ? SDL_ENABLE : SDL_DISABLE);
return val;
}
|
.enabled? ⇒ Boolean
Get whether the event is enabled.
This method is available for subclasses of SDL2::Event corresponding to SDL’s event types.
133 134 135 136 137 138 139 140 141 |
# File 'event.c', line 133
static VALUE Event_s_enabled_p(VALUE self)
{
VALUE event_type = rb_iv_get(self, "event_type");
if (event_type == Qnil) {
rb_warn("You cannot enable %s directly", rb_class2name(self));
return Qfalse;
}
return INT2BOOL(SDL_EventState(NUM2INT(event_type), SDL_QUERY) == SDL_ENABLE);
}
|
.poll ⇒ SDL2::Event?
Poll for currently pending events.
115 116 117 118 119 120 121 122 123 |
# File 'event.c', line 115
static VALUE Event_s_poll(VALUE self)
{
SDL_Event ev;
if (SDL_PollEvent(&ev)) {
return Event_new(&ev);
} else {
return Qnil;
}
}
|
Instance Method Details
#inspect ⇒ String
Returns inspection string
215 216 217 218 219 220 |
# File 'event.c', line 215
static VALUE Event_inspect(VALUE self)
{
SDL_Event* ev; Data_Get_Struct(self, SDL_Event, ev);
return rb_sprintf("<%s: type=%u timestamp=%u>",
rb_obj_classname(self), ev->common.type, ev->common.timestamp);
}
|
#window ⇒ SDL2::Window
Return the object of Window corresponding to the window_id attribute.
Some subclasses of SDL2::Event have window_id attribute to point the window which creates the event. The type of the window_id attribute is integer, and you need to convert it with Window.find_by_id to get the Window object. This method returns the Window object.
234 235 236 237 238 |
# File 'event.c', line 234
static VALUE Event_window(VALUE self)
{
VALUE window_id = rb_funcall(self, rb_intern("window_id"), 0);
return find_window_by_id(NUM2UINT(window_id));
}
|