Class: RbSDL2::Event
- Inherits:
-
Object
show all
- Extended by:
- SingleForwardable
- Includes:
- EventType
- Defined in:
- lib/rb_sdl2/event/event.rb
Constant Summary
Constants included
from EventType
RbSDL2::EventType::COMMON_EVENT_TYPES, RbSDL2::EventType::ENTITY_MAP, RbSDL2::EventType::NAME_MAP, RbSDL2::EventType::USER_EVENT_TYPES
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from EventType
#app_did_enter_background?, #app_did_enter_foreground?, #app_low_memory?, #app_terminating?, #app_will_enter_background?, #app_will_enter_foreground?, #audio_device_added?, #audio_device_removed?, #clipboard_update?, #controller_axis_motion?, #controller_button_down?, #controller_button_up?, #controller_device_added?, #controller_device_remapped?, #controller_device_removed?, #controller_sensor_update?, #controller_touchpad_down?, #controller_touchpad_motion?, #controller_touchpad_up?, disable, #display_event?, #dollar_gesture?, #dollar_record?, #drop_begin?, #drop_complete?, #drop_file?, #drop_text?, enable, #finger_down?, #finger_motion?, #finger_up?, ignore?, #joy_axis_motion?, #joy_ball_motion?, #joy_button_down?, #joy_button_up?, #joy_device_added?, #joy_device_removed?, #joy_hat_motion?, #key_down?, #key_up?, #keymap_changed?, #locale_changed?, #mouse_button_down?, #mouse_button_up?, #mouse_motion?, #mouse_wheel?, #multi_gesture?, #poll_sentinel?, #quit?, register_events, #render_device_reset?, #render_targets_reset?, #sensor_update?, #sys_wm_event?, #text_editing?, #text_editing_ext?, #text_input?, to_name, to_types, #user_event?, #window_event?
Constructor Details
#initialize(ptr) ⇒ Event
Returns a new instance of Event.
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/rb_sdl2/event/event.rb', line 47
def initialize(ptr)
@ptr = ptr
@entity = nil
@obj = if drop_file? || drop_text?
SDLPointer.new(entity[:file])
elsif text_editing_ext?
SDLPointer.new(entity[:text])
elsif sys_wm_event? && entity[:msg].null?
raise TypeError
end
end
|
Class Method Details
.new(type:, **members) ⇒ Object
34
35
36
37
38
|
# File 'lib/rb_sdl2/event/event.rb', line 34
def new(type:, **members)
obj = super(EventPointer.new(type))
members.each_pair { |sym, val| obj[sym] = val }
obj
end
|
.quit? ⇒ Boolean
20
21
22
23
|
# File 'lib/rb_sdl2/event/event.rb', line 20
def quit?
pump
exist?(::SDL::QUIT)
end
|
.to_ptr(ptr) ⇒ Object
40
41
42
43
44
|
# File 'lib/rb_sdl2/event/event.rb', line 40
def to_ptr(ptr)
obj = allocate
obj.__send__(:initialize, ptr)
obj
end
|
Instance Method Details
#[](sym) ⇒ Object
SDL_SYSWMEVENT の msg はポインターです。このポインターの取り扱いはアプリケーションに委ねられます。 SDL_USEREVENT の data1, data2 はポインターです。このポインターの取り扱いはアプリケーションに委ねられます。
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/rb_sdl2/event/event.rb', line 62
def [](sym)
obj = entity[sym]
case sym
when :data then obj.to_a
when :file then if drop_file? || drop_text?
SDL.ptr_to_str(obj)
else
nil
end
when :keysym then { scancode: obj[:scancode], sym: obj[:sym], mod: obj[:mod] }
when :msg then obj
when :text then SDL.ptr_to_str(obj.to_ptr)
when :type then type
else obj
end
end
|
#[]=(sym, val) ⇒ Object
SDL_SYSWMEVENT の msg への書き込みはできません。 SDL_USEREVENT の data1, data2 はポインターです。このポインターの取り扱いはアプリケーションに委ねられます。
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/rb_sdl2/event/event.rb', line 82
def []=(sym, val)
raise FrozenError if frozen?
case sym
when :data then entity[sym].tap { |st| val.each.with_index { |v, i| st[i] = v } }
when :file then if drop_file? || drop_text?
entity[sym] = @obj = SDLPointer.from_string(val)
else
raise TypeError
end
when :keysym then entity[sym].tap { |st| val.each { |k, v| st[k] = v } }
when :msg then raise NotImplementedError
when :text then if text_editing_ext?
entity[sym] = @obj = SDLPointer.from_string(val)
else
::SDL.utf8strlcpy(entity[sym].to_ptr, SDL.str_to_sdl(val), entity[sym].size)
end
when :type then raise TypeError
else entity[sym] = val
end
end
|
#initialize_copy(obj) ⇒ Object
clone, dup はディープコピーを行います。
108
109
110
111
|
# File 'lib/rb_sdl2/event/event.rb', line 108
def initialize_copy(obj)
super
initialize(EventPointer.copy(obj.to_ptr))
end
|
#inspect ⇒ Object
113
|
# File 'lib/rb_sdl2/event/event.rb', line 113
def inspect = "#<#{self.class.name}: #{name}>"
|
#member?(name) ⇒ Boolean
115
|
# File 'lib/rb_sdl2/event/event.rb', line 115
def member?(name) = members.include?(name)
|
#members ⇒ Object
117
|
# File 'lib/rb_sdl2/event/event.rb', line 117
def members = entity.members.grep_v(/\Apadding/)
|
#name ⇒ Object
119
|
# File 'lib/rb_sdl2/event/event.rb', line 119
def name = EventType.to_name(type)
|
#to_h ⇒ Object
121
|
# File 'lib/rb_sdl2/event/event.rb', line 121
def to_h = members.map { |sym| [sym, self[sym]] }.to_h
|
#to_ptr ⇒ Object
123
|
# File 'lib/rb_sdl2/event/event.rb', line 123
def to_ptr = @ptr
|
#to_s ⇒ Object
125
|
# File 'lib/rb_sdl2/event/event.rb', line 125
def to_s = name.to_s
|
#type ⇒ Object
Also known as:
to_i
127
|
# File 'lib/rb_sdl2/event/event.rb', line 127
def type = @ptr.type
|