Class: SFML::Event
- Inherits:
-
Object
- Object
- SFML::Event
- Defined in:
- ext/window/event.c,
ext/window/event.c
Overview
A window or input event, polled from Window#poll_event!/#wait_event!.
#type tells which of the accessors below is meaningful for this particular event; the others return stale or default data.
Instance Method Summary collapse
-
#initialize ⇒ self
constructor
Does nothing; instances are built internally by the event-polling methods.
-
#joystick_button ⇒ Hash
Returns the descriptor Hash for a joystick button press or release event.
-
#joystick_connect ⇒ Hash
Returns the descriptor Hash for a joystick connect or disconnect event.
-
#joystick_move ⇒ Hash
Returns the descriptor Hash for a
"joystick-moved"event. -
#key ⇒ Hash
Returns the key descriptor Hash for a key press or release event.
-
#mouse_button ⇒ Hash
Returns the button descriptor Hash for a mouse press or release event.
-
#mouse_move ⇒ Vector2
Returns the new cursor position for a
"mouse-moved"event. -
#mouse_move_raw ⇒ Vector2
Returns the unfiltered relative motion for a
"mouse-moved-raw"event. -
#mouse_wheel_scroll ⇒ Hash
Returns the wheel descriptor Hash for a
"mouse-wheel-scrolled"event. -
#mouse_wheel_scroll ⇒ Hash
Returns the wheel descriptor Hash for a
"mouse-wheel-scrolled"event. -
#sensor ⇒ Hash
Returns the descriptor Hash for a
"sensor-changed"event. -
#size ⇒ Vector2
Returns the new size carried by a
"resized"event. -
#text ⇒ String
Returns the entered character for a
"text-entered"event. -
#touch ⇒ Hash
Returns the descriptor Hash for a touch begin, move or end event.
-
#type ⇒ String
Returns the event's kind as a String, such as
"closed"or"key-pressed".
Constructor Details
#initialize ⇒ self
Does nothing; instances are built internally by the event-polling methods.
54 55 56 |
# File 'ext/window/event.c', line 54 static VALUE Event_initialize(VALUE self) { return self; } |
Instance Method Details
#joystick_button ⇒ Hash
Returns the descriptor Hash for a joystick button press or release event.
227 228 229 230 231 232 233 234 235 |
# File 'ext/window/event.c', line 227
static VALUE Event_get_joystick_button(VALUE self) {
sfJoystickButtonEvent* event = &Get_Event_Struct(self)->joystickButton;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickId));
rb_hash_aset(hash, ID2SYM(rb_intern("button")), UINT2NUM(event->button));
return hash;
}
|
#joystick_connect ⇒ Hash
Returns the descriptor Hash for a joystick connect or disconnect event.
244 245 246 247 248 249 250 251 252 253 254 |
# File 'ext/window/event.c', line 244
static VALUE Event_get_joystick_connect(VALUE self) {
sfEvent* event = Get_Event_Struct(self);
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")),
UINT2NUM(event->joystickConnect.joystickId));
rb_hash_aset(hash, ID2SYM(rb_intern("connected")),
BOOL2RB(event->type == sfEvtJoystickConnected));
return hash;
}
|
#joystick_move ⇒ Hash
Returns the descriptor Hash for a "joystick-moved" event.
208 209 210 211 212 213 214 215 216 217 218 |
# File 'ext/window/event.c', line 208
static VALUE Event_get_joystick_move(VALUE self) {
sfJoystickMoveEvent* event = &Get_Event_Struct(self)->joystickMove;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("joystick_id")), UINT2NUM(event->joystickId));
rb_hash_aset(hash, ID2SYM(rb_intern("axis")),
ID2SYM(rb_intern(joystick_axis_name(event->axis))));
rb_hash_aset(hash, ID2SYM(rb_intern("position")), DBL2NUM(event->position));
return hash;
}
|
#key ⇒ Hash
Returns the key descriptor Hash for a key press or release event.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'ext/window/event.c', line 88
static VALUE Event_get_key(VALUE self) {
sfKeyEvent* event = &Get_Event_Struct(self)->key;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("code")), ID2SYM(rb_intern(get_key_event(event->code))));
rb_hash_aset(hash, ID2SYM(rb_intern("scancode")),
rb_str_new2(sfKeyboard_getDescription(event->scancode)));
rb_hash_aset(hash, ID2SYM(rb_intern("alt")), BOOL2RB(event->alt));
rb_hash_aset(hash, ID2SYM(rb_intern("control")), BOOL2RB(event->control));
rb_hash_aset(hash, ID2SYM(rb_intern("shift")), BOOL2RB(event->shift));
rb_hash_aset(hash, ID2SYM(rb_intern("system")), BOOL2RB(event->system));
return hash;
}
|
#mouse_button ⇒ Hash
Returns the button descriptor Hash for a mouse press or release event.
169 170 171 172 173 174 175 176 177 178 179 |
# File 'ext/window/event.c', line 169
static VALUE Event_get_mouse_button(VALUE self) {
sfMouseButtonEvent* event = &Get_Event_Struct(self)->mouseButton;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("button")),
ID2SYM(rb_intern(mouse_button_name(event->button))));
rb_hash_aset(hash, ID2SYM(rb_intern("position")),
vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
return hash;
}
|
#mouse_move ⇒ Vector2
Returns the new cursor position for a "mouse-moved" event.
143 144 145 146 147 |
# File 'ext/window/event.c', line 143
static VALUE Event_get_mouse_move(VALUE self) {
sfVector2i position = Get_Event_Struct(self)->mouseMove.position;
return vec2f_to_rb((sfVector2f){(float)position.x, (float)position.y});
}
|
#mouse_move_raw ⇒ Vector2
Returns the unfiltered relative motion for a "mouse-moved-raw" event.
156 157 158 159 160 |
# File 'ext/window/event.c', line 156
static VALUE Event_get_mouse_move_raw(VALUE self) {
sfVector2i delta = Get_Event_Struct(self)->mouseMoveRaw.delta;
return vec2f_to_rb((sfVector2f){(float)delta.x, (float)delta.y});
}
|
#mouse_wheel_scroll ⇒ Hash
Returns the wheel descriptor Hash for a "mouse-wheel-scrolled" event.
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/window/event.c', line 188
static VALUE Event_get_mouse_wheel_scroll(VALUE self) {
sfMouseWheelScrollEvent* event = &Get_Event_Struct(self)->mouseWheelScroll;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("wheel")),
ID2SYM(rb_intern(mouse_wheel_name(event->wheel))));
rb_hash_aset(hash, ID2SYM(rb_intern("delta")), DBL2NUM(event->delta));
rb_hash_aset(hash, ID2SYM(rb_intern("position")),
vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
return hash;
}
|
#mouse_wheel_scroll ⇒ Hash
Returns the wheel descriptor Hash for a "mouse-wheel-scrolled" event.
188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/window/event.c', line 188
static VALUE Event_get_mouse_wheel_scroll(VALUE self) {
sfMouseWheelScrollEvent* event = &Get_Event_Struct(self)->mouseWheelScroll;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("wheel")),
ID2SYM(rb_intern(mouse_wheel_name(event->wheel))));
rb_hash_aset(hash, ID2SYM(rb_intern("delta")), DBL2NUM(event->delta));
rb_hash_aset(hash, ID2SYM(rb_intern("position")),
vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
return hash;
}
|
#sensor ⇒ Hash
Returns the descriptor Hash for a "sensor-changed" event.
280 281 282 283 284 285 286 287 288 289 |
# File 'ext/window/event.c', line 280
static VALUE Event_get_sensor(VALUE self) {
sfSensorEvent* event = &Get_Event_Struct(self)->sensor;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("type")),
ID2SYM(rb_intern(sensor_type_name(event->sensorType))));
rb_hash_aset(hash, ID2SYM(rb_intern("value")), vec3f_to_rb(event->value));
return hash;
}
|
#size ⇒ Vector2
Returns the new size carried by a "resized" event.
75 76 77 78 79 |
# File 'ext/window/event.c', line 75
static VALUE Event_get_size(VALUE self) {
sfVector2u size = Get_Event_Struct(self)->size.size;
return vec2f_to_rb((sfVector2f){(float)size.x, (float)size.y});
}
|
#text ⇒ String
Returns the entered character for a "text-entered" event.
133 134 135 |
# File 'ext/window/event.c', line 133
static VALUE Event_get_text(VALUE self) {
return unicode_to_utf8(Get_Event_Struct(self)->text.unicode);
}
|
#touch ⇒ Hash
Returns the descriptor Hash for a touch begin, move or end event.
263 264 265 266 267 268 269 270 271 272 |
# File 'ext/window/event.c', line 263
static VALUE Event_get_touch(VALUE self) {
sfTouchEvent* event = &Get_Event_Struct(self)->touch;
VALUE hash = rb_hash_new();
rb_hash_aset(hash, ID2SYM(rb_intern("finger")), UINT2NUM(event->finger));
rb_hash_aset(hash, ID2SYM(rb_intern("position")),
vec2f_to_rb((sfVector2f){(float)event->position.x, (float)event->position.y}));
return hash;
}
|
#type ⇒ String
Returns the event's kind as a String, such as "closed" or "key-pressed".
65 66 67 |
# File 'ext/window/event.c', line 65
static VALUE Event_type(VALUE self) {
return rb_str_new2(get_event_name(Get_Event_Struct(self)->type));
}
|