ray 0.0.1 → 0.1.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/.yardopts +4 -0
- data/README.md +17 -21
- data/Rakefile +18 -139
- data/VERSION +1 -1
- data/ext/audio.cpp +723 -0
- data/ext/{color.c → color.cpp} +25 -13
- data/ext/drawable.cpp +91 -0
- data/ext/event.cpp +460 -0
- data/ext/extconf.rb +5 -104
- data/ext/font.cpp +190 -0
- data/ext/image.cpp +733 -0
- data/ext/input.cpp +74 -0
- data/ext/ray.cpp +168 -0
- data/ext/ray.hpp +356 -0
- data/ext/{rect.c → rect.cpp} +51 -37
- data/ext/shader.cpp +169 -0
- data/ext/shape.cpp +409 -0
- data/ext/sprite.cpp +306 -0
- data/ext/text.cpp +181 -0
- data/ext/vector.cpp +215 -0
- data/guide.md +619 -0
- data/lib/ray/audio.rb +0 -41
- data/lib/ray/color.rb +32 -10
- data/lib/ray/drawable.rb +16 -0
- data/lib/ray/dsl/event_listener.rb +25 -2
- data/lib/ray/dsl/event_runner.rb +33 -5
- data/lib/ray/dsl/event_translator.rb +66 -30
- data/lib/ray/dsl/handler.rb +3 -2
- data/lib/ray/dsl/matcher.rb +58 -14
- data/lib/ray/font.rb +38 -96
- data/lib/ray/font_set.rb +8 -8
- data/lib/ray/game.rb +87 -66
- data/lib/ray/helper.rb +105 -10
- data/lib/ray/image.rb +150 -24
- data/lib/ray/image_set.rb +3 -1
- data/lib/ray/input.rb +10 -0
- data/lib/ray/music_set.rb +5 -3
- data/lib/ray/ray.rb +21 -9
- data/lib/ray/rect.rb +48 -7
- data/lib/ray/rmagick.rb +41 -0
- data/lib/ray/scene.rb +99 -43
- data/lib/ray/scene_list.rb +67 -0
- data/lib/ray/shape.rb +132 -0
- data/lib/ray/sound_set.rb +4 -2
- data/lib/ray/sprite.rb +49 -111
- data/lib/ray/text.rb +101 -0
- data/lib/ray/text_helper.rb +37 -0
- data/lib/ray/turtle.rb +215 -0
- data/lib/ray/vector.rb +226 -0
- data/samples/audio/spacial.rb +44 -0
- data/samples/hello_world/hello.rb +9 -13
- data/samples/hello_world/hello_dsl.rb +8 -12
- data/samples/hello_world/text.rb +15 -0
- data/samples/opengl/binding.rb +38 -0
- data/samples/opengl/image.rb +32 -0
- data/samples/opengl/opengl.rb +34 -0
- data/samples/opengl/shader.rb +42 -0
- data/samples/pong/pong.rb +14 -10
- data/samples/run_scene.rb +53 -0
- data/samples/shaders/scene.rb +40 -0
- data/samples/shaders/shaders.rb +42 -0
- data/samples/shaders/shape.rb +34 -0
- data/samples/sokoban/sokoban.rb +18 -18
- data/samples/test/actual_scene.rb +41 -0
- data/samples/test/scene_riot.rb +39 -0
- data/samples/test/scene_spec.rb +32 -0
- data/samples/test/scene_test_unit.rb +25 -0
- data/samples/turtle/byzantium.rb +45 -0
- data/samples/turtle/hilbert.rb +48 -0
- data/samples/turtle/koch.rb +55 -0
- data/samples/turtle/mandala.rb +61 -0
- data/samples/turtle/tree.rb +57 -0
- data/test/audio_test.rb +69 -0
- data/test/color_test.rb +77 -0
- data/test/drawable_test.rb +19 -0
- data/test/dsl_test.rb +93 -0
- data/test/font_test.rb +57 -0
- data/test/helpers.rb +94 -0
- data/test/image_test.rb +82 -0
- data/test/ray_test.rb +25 -0
- data/test/rect_test.rb +121 -0
- data/{spec → test}/res/VeraMono.ttf +0 -0
- data/{spec → test}/res/aqua.bmp +0 -0
- data/{spec → test}/res/aqua.png +0 -0
- data/{spec → test}/res/aqua2.bmp +0 -0
- data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
- data/{spec → test}/res/pop.wav +0 -0
- data/test/resource_set_test.rb +99 -0
- data/test/run_all.rb +7 -0
- data/test/shape_test.rb +101 -0
- data/test/sprite_test.rb +89 -0
- data/test/text_test.rb +78 -0
- data/test/turtle_test.rb +176 -0
- data/test/vector_test.rb +111 -0
- data/yard_ext.rb +0 -28
- metadata +95 -139
- data/.gitignore +0 -23
- data/.gitmodules +0 -3
- data/.rspec +0 -3
- data/ext/audio.c +0 -473
- data/ext/event.c +0 -557
- data/ext/font.c +0 -287
- data/ext/image.c +0 -933
- data/ext/joystick.c +0 -145
- data/ext/ray.c +0 -489
- data/ext/ray.h +0 -245
- data/ext/ray_osx.m +0 -161
- data/lib/ray/joystick.rb +0 -30
- data/psp/SDL_psp_main.c +0 -84
- data/psp/bigdecimal/README +0 -60
- data/psp/bigdecimal/bigdecimal.c +0 -4697
- data/psp/bigdecimal/bigdecimal.h +0 -216
- data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
- data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
- data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
- data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
- data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
- data/psp/digest/bubblebabble/bubblebabble.c +0 -142
- data/psp/digest/defs.h +0 -20
- data/psp/digest/digest.c +0 -643
- data/psp/digest/digest.h +0 -32
- data/psp/digest/lib/digest.rb +0 -50
- data/psp/digest/lib/md5.rb +0 -27
- data/psp/digest/lib/sha1.rb +0 -27
- data/psp/digest/md5/md5.c +0 -420
- data/psp/digest/md5/md5.h +0 -80
- data/psp/digest/md5/md5init.c +0 -40
- data/psp/digest/rmd160/rmd160.c +0 -457
- data/psp/digest/rmd160/rmd160.h +0 -56
- data/psp/digest/rmd160/rmd160init.c +0 -40
- data/psp/digest/sha1/sha1.c +0 -269
- data/psp/digest/sha1/sha1.h +0 -39
- data/psp/digest/sha1/sha1init.c +0 -40
- data/psp/digest/sha2/lib/sha2.rb +0 -73
- data/psp/digest/sha2/sha2.c +0 -919
- data/psp/digest/sha2/sha2.h +0 -109
- data/psp/digest/sha2/sha2init.c +0 -52
- data/psp/enumerator/enumerator.c +0 -298
- data/psp/etc/etc.c +0 -559
- data/psp/ext.c +0 -289
- data/psp/fcntl/fcntl.c +0 -187
- data/psp/lib/rbconfig.rb +0 -178
- data/psp/nkf/lib/kconv.rb +0 -367
- data/psp/nkf/nkf-utf8/config.h +0 -88
- data/psp/nkf/nkf-utf8/nkf.c +0 -6040
- data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
- data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
- data/psp/nkf/nkf.c +0 -654
- data/psp/socket/addrinfo.h +0 -173
- data/psp/socket/getaddrinfo.c +0 -676
- data/psp/socket/getnameinfo.c +0 -270
- data/psp/socket/pspsocket.c +0 -71
- data/psp/socket/pspsocket.h +0 -28
- data/psp/socket/socket.c +0 -4662
- data/psp/socket/sockport.h +0 -76
- data/psp/stringio/stringio.c +0 -1306
- data/psp/strscan/strscan.c +0 -1320
- data/psp/syck/bytecode.c +0 -1166
- data/psp/syck/emitter.c +0 -1242
- data/psp/syck/gram.c +0 -1894
- data/psp/syck/gram.h +0 -79
- data/psp/syck/handler.c +0 -174
- data/psp/syck/implicit.c +0 -2990
- data/psp/syck/node.c +0 -408
- data/psp/syck/rubyext.c +0 -2367
- data/psp/syck/syck.c +0 -504
- data/psp/syck/syck.h +0 -456
- data/psp/syck/token.c +0 -2725
- data/psp/syck/yaml2byte.c +0 -257
- data/psp/syck/yamlbyte.h +0 -170
- data/psp/thread/thread.c +0 -1175
- data/psp/zlib/zlib.c +0 -3547
- data/script.rb +0 -10
- data/spec/ray/audio_spec.rb +0 -146
- data/spec/ray/color_spec.rb +0 -57
- data/spec/ray/event_spec.rb +0 -80
- data/spec/ray/font_spec.rb +0 -93
- data/spec/ray/image_set_spec.rb +0 -48
- data/spec/ray/image_spec.rb +0 -162
- data/spec/ray/joystick_spec.rb +0 -21
- data/spec/ray/matcher_spec.rb +0 -50
- data/spec/ray/ray_spec.rb +0 -88
- data/spec/ray/rect_spec.rb +0 -154
- data/spec/ray/resource_set_spec.rb +0 -105
- data/spec/ray/sprite_spec.rb +0 -163
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -8
data/lib/ray/audio.rb
CHANGED
|
@@ -1,45 +1,4 @@
|
|
|
1
1
|
module Ray
|
|
2
|
-
# Represents an audio channel, where sounds are played.
|
|
3
|
-
class Channel
|
|
4
|
-
# Creates a channel.
|
|
5
|
-
# @param [Integer] id Identifer of the channel.
|
|
6
|
-
def initialize(id)
|
|
7
|
-
@id = id
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# Plays a sound on the channel.
|
|
11
|
-
# @param [Ray::Sound] sound The sound to be played
|
|
12
|
-
# @param [Integer, :forever] times How many times the sound should be played.
|
|
13
|
-
def play(sound, times = 1)
|
|
14
|
-
sound.play(@id, times)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Stops playing on the channel, without being able to resume.
|
|
18
|
-
def stop
|
|
19
|
-
Ray::Audio.stop(@id)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Pauses the channel.
|
|
23
|
-
def pause
|
|
24
|
-
Ray::Audio.pause(@id)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# Resumes from pause.
|
|
28
|
-
def resume
|
|
29
|
-
Ray::Audio.resume(@id)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# @return [true, false] True if the channel is paused.
|
|
33
|
-
def paused?
|
|
34
|
-
Ray::Audio.paused?(@id)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# @return [true, false] True if a sound is being played.
|
|
38
|
-
def playing?
|
|
39
|
-
Ray::Audio.playing?(@id)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
2
|
class Sound
|
|
44
3
|
extend Ray::ResourceSet
|
|
45
4
|
add_set(/^(.*)$/) { |filename| new(filename) }
|
data/lib/ray/color.rb
CHANGED
|
@@ -13,17 +13,46 @@ module Ray
|
|
|
13
13
|
def fuschia; new(255, 0, 255); end
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def
|
|
16
|
+
def to_s
|
|
17
17
|
"RGBA(#{r}, #{g}, #{b}, #{a})"
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# @param [Ray::Color] color Another color
|
|
21
|
+
# @return [Ray::Color] Sum of two colors, each components
|
|
22
|
+
# are added.
|
|
23
|
+
def +(color)
|
|
24
|
+
r = red + color.red
|
|
25
|
+
g = green + color.green
|
|
26
|
+
b = blue + color.blue
|
|
27
|
+
a = alpha + color.alpha
|
|
28
|
+
|
|
29
|
+
Ray::Color.new(r > 255 ? 255 : r,
|
|
30
|
+
g > 255 ? 255 : g,
|
|
31
|
+
b > 255 ? 255 : b,
|
|
32
|
+
a > 255 ? 255 : a)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @param [Ray::Color] color Another color
|
|
36
|
+
# @return [Ray::Color] Product of two colors, each components
|
|
37
|
+
# are multiplied and then divided by 255.
|
|
38
|
+
def *(color)
|
|
39
|
+
Ray::Color.new(r * color.r / 255.0,
|
|
40
|
+
g * color.g / 255.0,
|
|
41
|
+
b * color.b / 255.0,
|
|
42
|
+
a * color.a / 255.0)
|
|
43
|
+
end
|
|
44
|
+
|
|
20
45
|
def ==(obj)
|
|
21
46
|
return false unless obj.is_a? Color
|
|
22
47
|
r == obj.r && g == obj.g && b == obj.b && a == obj.a
|
|
23
48
|
end
|
|
24
49
|
|
|
25
|
-
def
|
|
26
|
-
self
|
|
50
|
+
def eql?(obj)
|
|
51
|
+
self.class == obj.class && self == obj
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def hash
|
|
55
|
+
[r, g, b, a].hash
|
|
27
56
|
end
|
|
28
57
|
|
|
29
58
|
alias :red :r
|
|
@@ -37,10 +66,3 @@ module Ray
|
|
|
37
66
|
alias :alpha= :a=
|
|
38
67
|
end
|
|
39
68
|
end
|
|
40
|
-
|
|
41
|
-
class Array
|
|
42
|
-
# Converts an Array to a color
|
|
43
|
-
def to_color
|
|
44
|
-
Ray::Color.new(*self)
|
|
45
|
-
end
|
|
46
|
-
end
|
data/lib/ray/drawable.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Ray
|
|
2
|
+
class Drawable
|
|
3
|
+
# Draws the drawable on an image.
|
|
4
|
+
def draw_on(image)
|
|
5
|
+
image.draw_drawable self
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Draws the drawable.
|
|
9
|
+
#
|
|
10
|
+
# @option opts [Ray::Image] :on (Ray.screen) The image to draw the drawable
|
|
11
|
+
# on.
|
|
12
|
+
def draw(opts = {})
|
|
13
|
+
draw_on(opts[:on] || Ray.screen)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -13,7 +13,7 @@ module Ray
|
|
|
13
13
|
# the block will be called anyway)
|
|
14
14
|
def on(event, *args, &block)
|
|
15
15
|
return unless listener_runner
|
|
16
|
-
listener_runner.add_handler(event, args, block)
|
|
16
|
+
listener_runner.add_handler(event, current_event_group, args, block)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# @overload add_hook(event, ..., callable)
|
|
@@ -23,7 +23,30 @@ module Ray
|
|
|
23
23
|
# @example
|
|
24
24
|
# add_hook :quit, method(:exit!)
|
|
25
25
|
def add_hook(event, *args)
|
|
26
|
-
|
|
26
|
+
return unless listener_runner
|
|
27
|
+
listener_runner.add_handler(event, current_event_group, args[0...-1],
|
|
28
|
+
args.last)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Sets the current event group to name and runs a block to register
|
|
32
|
+
# events. The current event group is reset to its old value afterwards.
|
|
33
|
+
def event_group(name)
|
|
34
|
+
old_group = current_event_group
|
|
35
|
+
self.current_event_group = name
|
|
36
|
+
|
|
37
|
+
begin
|
|
38
|
+
yield name
|
|
39
|
+
ensure
|
|
40
|
+
self.current_event_group = old_group
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def current_event_group
|
|
45
|
+
@__listener_event_group ||= :default
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def current_event_group=(val)
|
|
49
|
+
@__listener_event_group = val
|
|
27
50
|
end
|
|
28
51
|
|
|
29
52
|
def listener_runner
|
data/lib/ray/dsl/event_runner.rb
CHANGED
|
@@ -12,6 +12,9 @@ module Ray
|
|
|
12
12
|
@event_list = []
|
|
13
13
|
@next_events = []
|
|
14
14
|
|
|
15
|
+
@event_groups = Hash.new { |h, k| h[k] = true }
|
|
16
|
+
@event_groups[:default] = true
|
|
17
|
+
|
|
15
18
|
@mutex = Mutex.new
|
|
16
19
|
end
|
|
17
20
|
|
|
@@ -22,20 +25,45 @@ module Ray
|
|
|
22
25
|
@next_events = []
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
handlers = @handlers.select { |o| group_enabled?(o.group) }
|
|
29
|
+
|
|
25
30
|
@event_list.each do |ev|
|
|
26
|
-
|
|
27
|
-
handler.call(ev)
|
|
28
|
-
end
|
|
31
|
+
handlers.select { |o| o.call(ev) if o.match?(ev) }
|
|
29
32
|
end
|
|
30
33
|
end
|
|
31
34
|
|
|
32
|
-
def add_handler(type, args, block)
|
|
33
|
-
@handlers << Ray::DSL::Handler.new(type, args, block)
|
|
35
|
+
def add_handler(type, group, args, block)
|
|
36
|
+
@handlers << Ray::DSL::Handler.new(type, group, args, block)
|
|
34
37
|
end
|
|
35
38
|
|
|
36
39
|
def add_event(type, args)
|
|
37
40
|
@mutex.synchronize { @next_events << Ray::DSL::Event.new(type, args) }
|
|
38
41
|
end
|
|
42
|
+
|
|
43
|
+
# Disables an event group
|
|
44
|
+
def disable_group(group)
|
|
45
|
+
@event_groups[group] = false
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Enables an event group
|
|
49
|
+
def enable_group(group)
|
|
50
|
+
@event_groups[group] = true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Removes all the handlers belonging to a given group
|
|
54
|
+
def remove_group(name)
|
|
55
|
+
@handlers.delete_if { |o| o.group == name }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Removes all the registred handlers
|
|
59
|
+
def clear
|
|
60
|
+
@handlers.clear
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# @return Whether an event group is enabled
|
|
64
|
+
def group_enabled?(group)
|
|
65
|
+
@event_groups[group]
|
|
66
|
+
end
|
|
39
67
|
end
|
|
40
68
|
end
|
|
41
69
|
end
|
|
@@ -3,31 +3,32 @@ module Ray
|
|
|
3
3
|
# Module charged to translate an instance of Ray::Event into the arguments
|
|
4
4
|
# you pass to raise_event. It is for instance used in Ray::Scene.
|
|
5
5
|
#
|
|
6
|
+
# Unless otherwise mentionned, points and sizes are Ray::Vector2 and
|
|
7
|
+
# rects Ray::Rect.
|
|
8
|
+
#
|
|
6
9
|
# == Raised events
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
#
|
|
10
|
+
# - quit
|
|
11
|
+
# - focus_gain
|
|
12
|
+
# - focus_loss
|
|
13
|
+
# - mouse_entered
|
|
14
|
+
# - mouse_left
|
|
15
|
+
# - mouse_motion(pos)
|
|
16
|
+
# - wheel_motion(pos, delta)
|
|
17
|
+
# - mouse_press(button, pos)
|
|
18
|
+
# - mouse_release(button, pos)
|
|
19
|
+
# - key_press(key, mod_keys)
|
|
20
|
+
# - key_release(key, mod_keys)
|
|
21
|
+
# - window_resize(size)
|
|
22
|
+
# - joy_motion(joystick_id, axis_id, axis_value)
|
|
23
|
+
# - joy_press(joystick_id, button_id)
|
|
24
|
+
# - joy_release(joystick_id, button_id)
|
|
18
25
|
module EventTranslator
|
|
19
|
-
FOCUS_TYPES = {
|
|
20
|
-
Ray::Event::APPMOUSEFOCUS => :mouse_focus,
|
|
21
|
-
Ray::Event::APPINPUTFOCUS => :input_focus,
|
|
22
|
-
Ray::Event::APPACTIVE => :app_activity
|
|
23
|
-
}
|
|
24
|
-
|
|
25
26
|
MOUSE_BUTTONS = {
|
|
26
|
-
Ray::Event::BUTTON_LEFT
|
|
27
|
-
Ray::Event::BUTTON_MIDDLE
|
|
28
|
-
Ray::Event::BUTTON_RIGHT
|
|
29
|
-
Ray::Event::
|
|
30
|
-
Ray::Event::
|
|
27
|
+
Ray::Event::BUTTON_LEFT => :left,
|
|
28
|
+
Ray::Event::BUTTON_MIDDLE => :middle,
|
|
29
|
+
Ray::Event::BUTTON_RIGHT => :right,
|
|
30
|
+
Ray::Event::BUTTON_EXTRA1 => :extra1,
|
|
31
|
+
Ray::Event::BUTTON_EXTRA2 => :extra2
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
class << self
|
|
@@ -36,8 +37,12 @@ module Ray
|
|
|
36
37
|
case ev.type
|
|
37
38
|
when Ray::Event::TYPE_NOEVENT then []
|
|
38
39
|
when Ray::Event::TYPE_QUIT then quit(ev)
|
|
39
|
-
when Ray::Event::
|
|
40
|
+
when Ray::Event::TYPE_FOCUS_GAIN then focus_gain(ev)
|
|
41
|
+
when Ray::Event::TYPE_FOCUS_LOSS then focus_loss(ev)
|
|
42
|
+
when Ray::Event::TYPE_MOUSE_ENTERED then mouse_entered(ev)
|
|
43
|
+
when Ray::Event::TYPE_MOUSE_LEFT then mouse_left(ev)
|
|
40
44
|
when Ray::Event::TYPE_MOUSEMOTION then mouse_motion(ev)
|
|
45
|
+
when Ray::Event::TYPE_MOUSEWHEELMOVED then wheel_motion(ev)
|
|
41
46
|
when Ray::Event::TYPE_MOUSEBUTTONDOWN then mouse_press(ev)
|
|
42
47
|
when Ray::Event::TYPE_MOUSEBUTTONUP then mouse_release(ev)
|
|
43
48
|
when Ray::Event::TYPE_KEYDOWN then key_press(ev)
|
|
@@ -46,6 +51,7 @@ module Ray
|
|
|
46
51
|
when Ray::Event::TYPE_JOYAXISMOTION then joy_motion(ev)
|
|
47
52
|
when Ray::Event::TYPE_JOYBUTTONDOWN then joy_press(ev)
|
|
48
53
|
when Ray::Event::TYPE_JOYBUTTONUP then joy_release(ev)
|
|
54
|
+
when Ray::Event::TYPE_TEXT_ENTERED then text_entered(ev)
|
|
49
55
|
else []
|
|
50
56
|
end
|
|
51
57
|
end
|
|
@@ -54,25 +60,40 @@ module Ray
|
|
|
54
60
|
[[:quit]]
|
|
55
61
|
end
|
|
56
62
|
|
|
57
|
-
def
|
|
58
|
-
[[
|
|
59
|
-
|
|
63
|
+
def focus_gain(ev)
|
|
64
|
+
[[:focus_gain]]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def focus_loss(ev)
|
|
68
|
+
[[:focus_loss]]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def mouse_entered(ev)
|
|
72
|
+
[[:mouse_entered]]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def mouse_left(ev)
|
|
76
|
+
[[:mouse_left]]
|
|
60
77
|
end
|
|
61
78
|
|
|
62
79
|
def mouse_motion(ev)
|
|
63
|
-
[[:mouse_motion,
|
|
80
|
+
[[:mouse_motion, Vector2[ev.mouse_x, ev.mouse_y]]]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def wheel_motion(ev)
|
|
84
|
+
[[:wheel_motion, Vector2[ev.mouse_x, ev.mouse_y], ev.wheel_delta]]
|
|
64
85
|
end
|
|
65
86
|
|
|
66
87
|
def mouse_press(ev)
|
|
67
88
|
[[:mouse_press,
|
|
68
89
|
MOUSE_BUTTONS[ev.mouse_button],
|
|
69
|
-
|
|
90
|
+
Vector2[ev.mouse_x, ev.mouse_y]]]
|
|
70
91
|
end
|
|
71
92
|
|
|
72
93
|
def mouse_release(ev)
|
|
73
94
|
[[:mouse_release,
|
|
74
95
|
MOUSE_BUTTONS[ev.mouse_button],
|
|
75
|
-
|
|
96
|
+
Vector2[ev.mouse_x, ev.mouse_y]]]
|
|
76
97
|
end
|
|
77
98
|
|
|
78
99
|
def key_press(ev)
|
|
@@ -84,7 +105,7 @@ module Ray
|
|
|
84
105
|
end
|
|
85
106
|
|
|
86
107
|
def resize(ev)
|
|
87
|
-
[[:window_resize,
|
|
108
|
+
[[:window_resize, Vector2[ev.window_w, ev.window_h]]]
|
|
88
109
|
end
|
|
89
110
|
|
|
90
111
|
def joy_motion(ev)
|
|
@@ -98,6 +119,21 @@ module Ray
|
|
|
98
119
|
def joy_release(ev)
|
|
99
120
|
[[:joy_release, ev.joystick_id, ev.joystick_button]]
|
|
100
121
|
end
|
|
122
|
+
|
|
123
|
+
def text_entered(ev)
|
|
124
|
+
text = ev.entered_text
|
|
125
|
+
|
|
126
|
+
# Set the right encoding, whcih depends on the native endianness.
|
|
127
|
+
if text.respond_to? :encoding
|
|
128
|
+
if BIG_ENDIAN
|
|
129
|
+
text.force_encoding "UTF-32BE"
|
|
130
|
+
else
|
|
131
|
+
text.force_encoding "UTF-32LE"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
[[:text_entered, text]]
|
|
136
|
+
end
|
|
101
137
|
end
|
|
102
138
|
end
|
|
103
139
|
end
|
data/lib/ray/dsl/handler.rb
CHANGED
|
@@ -2,8 +2,8 @@ module Ray
|
|
|
2
2
|
module DSL
|
|
3
3
|
# Used internally to call blocks registred with Ray::DSL::EventListener#on.
|
|
4
4
|
class Handler
|
|
5
|
-
def initialize(type, args, block)
|
|
6
|
-
@type, @args, @block = type, args, block
|
|
5
|
+
def initialize(type, group, args, block)
|
|
6
|
+
@type, @group, @args, @block = type, group, args, block
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def match?(event)
|
|
@@ -23,6 +23,7 @@ module Ray
|
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
attr_reader :type
|
|
26
|
+
attr_reader :group
|
|
26
27
|
attr_reader :args
|
|
27
28
|
|
|
28
29
|
private
|
data/lib/ray/dsl/matcher.rb
CHANGED
|
@@ -2,6 +2,8 @@ module Ray
|
|
|
2
2
|
# This is the module including all of your matchers as private methods,
|
|
3
3
|
# allowing you to use them when you call on.
|
|
4
4
|
module Matchers
|
|
5
|
+
module_function
|
|
6
|
+
|
|
5
7
|
# @return [DSL::Matcher] An anonymous matcher, using your block to
|
|
6
8
|
# know if the argument matches.
|
|
7
9
|
#
|
|
@@ -12,6 +14,17 @@ module Ray
|
|
|
12
14
|
def where(&block)
|
|
13
15
|
DSL::Matcher.new { |o| block.call(o) }
|
|
14
16
|
end
|
|
17
|
+
|
|
18
|
+
# @return [Ray::Key] A key object representing the key of that name
|
|
19
|
+
def key(name)
|
|
20
|
+
Key.new(name)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @return [Ray::KeyMod] A key_mod object representing the mod combination
|
|
24
|
+
# of that name
|
|
25
|
+
def key_mod(name)
|
|
26
|
+
KeyMod.new(name)
|
|
27
|
+
end
|
|
15
28
|
end
|
|
16
29
|
|
|
17
30
|
module DSL
|
|
@@ -40,14 +53,18 @@ module Ray
|
|
|
40
53
|
# Ray.describe_matcher(:match, :string) do |regex|
|
|
41
54
|
# lambda { |str| str =~ regex }
|
|
42
55
|
# end
|
|
43
|
-
def
|
|
56
|
+
def describe_matcher(name, &create_block)
|
|
44
57
|
Matchers.module_eval do
|
|
45
58
|
define_method(name) do |*args|
|
|
46
59
|
DSL::Matcher.new(&create_block.call(*args))
|
|
47
60
|
end
|
|
61
|
+
|
|
62
|
+
module_function name
|
|
48
63
|
end
|
|
49
64
|
end
|
|
50
65
|
|
|
66
|
+
module_function :describe_matcher
|
|
67
|
+
|
|
51
68
|
# @return [DSL::Matcher] A matcher matching anything (always true)
|
|
52
69
|
describe_matcher(:anything) do
|
|
53
70
|
lambda { |o| true }
|
|
@@ -110,8 +127,6 @@ module Ray
|
|
|
110
127
|
KEYS = Ray::Event.constants.inject({}) do |hash, const|
|
|
111
128
|
if const =~ /^KEY_(.+)$/
|
|
112
129
|
hash[$1.downcase.to_sym] = [Ray::Event.const_get(const)]
|
|
113
|
-
elsif const =~ /^PSP_BUTTON_(.+)$/
|
|
114
|
-
hash["psp_#{$1.downcase.to_sym}".to_sym] = [Ray::Event.const_get(const)]
|
|
115
130
|
end
|
|
116
131
|
|
|
117
132
|
hash
|
|
@@ -136,7 +151,6 @@ module Ray
|
|
|
136
151
|
KEYS[:mod] = [Ray::Event::KEY_RSHIFT, Ray::Event::KEY_LSHIFT,
|
|
137
152
|
Ray::Event::KEY_RCTRL, Ray::Event::KEY_LCTRL,
|
|
138
153
|
Ray::Event::KEY_RALT, Ray::Event::KEY_LALT,
|
|
139
|
-
Ray::Event::KEY_RMETA, Ray::Event::KEY_LMETA,
|
|
140
154
|
Ray::Event::KEY_RSUPER, Ray::Event::KEY_LSUPER]
|
|
141
155
|
|
|
142
156
|
KEYS[:arrow] = [Ray::Event::KEY_UP, Ray::Event::KEY_DOWN,
|
|
@@ -150,17 +164,47 @@ module Ray
|
|
|
150
164
|
hash
|
|
151
165
|
end
|
|
152
166
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
167
|
+
class Key
|
|
168
|
+
def initialize(name)
|
|
169
|
+
@symbol = name.to_sym
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def to_a
|
|
173
|
+
KEYS[@symbol]
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def to_sym
|
|
177
|
+
@symbol
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def ===(other)
|
|
181
|
+
to_a.include? other
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def inspect
|
|
185
|
+
"key(#{to_sym})"
|
|
186
|
+
end
|
|
158
187
|
end
|
|
159
188
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
189
|
+
class KeyMod
|
|
190
|
+
def initialize(name)
|
|
191
|
+
@symbol = name.to_sym
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def to_a
|
|
195
|
+
MOD[@symbol]
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def to_sym
|
|
199
|
+
@symbol
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def ===(other)
|
|
203
|
+
other.is_a?(Integer) && to_a.any? { |const| (o & const) != 0 }
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def inspect
|
|
207
|
+
"key_mod(#{to_sym})"
|
|
208
|
+
end
|
|
165
209
|
end
|
|
166
210
|
end
|