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
162 163 164 165 166 167 168 169 |
# File 'event.c', line 162
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.
137 138 139 140 141 142 143 144 145 |
# File 'event.c', line 137
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.
119 120 121 122 123 124 125 126 127 |
# File 'event.c', line 119
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.
219 220 221 222 223 224 |
# File 'event.c', line 219
static VALUE Event_inspect(VALUE self)
{
SDL_Event* ev; TypedData_Get_Struct(self, SDL_Event, &SDL_Event_data_type, 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.
238 239 240 241 242 |
# File 'event.c', line 238
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));
}
|