sdl2_ffi 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -59
- data/lib/sdl2.rb +52 -15
- data/lib/sdl2/application.rb +71 -0
- data/lib/sdl2/audio.rb +72 -24
- data/lib/sdl2/clipboard.rb +9 -3
- data/lib/sdl2/color.rb +8 -3
- data/lib/sdl2/cpuinfo.rb +30 -10
- data/lib/sdl2/engine.rb +52 -0
- data/lib/sdl2/engine/block_engine.rb +27 -0
- data/lib/sdl2/engine/engines.rb +46 -0
- data/lib/sdl2/error.rb +9 -3
- data/lib/sdl2/events.rb +68 -6
- data/lib/sdl2/gamecontroller.rb +60 -20
- data/lib/sdl2/gem_version.rb +1 -1
- data/lib/sdl2/gesture.rb +12 -4
- data/lib/sdl2/haptic.rb +90 -30
- data/lib/sdl2/hints.rb +12 -4
- data/lib/sdl2/image.rb +85 -3
- data/lib/sdl2/init.rb +15 -5
- data/lib/sdl2/joystick.rb +63 -21
- data/lib/sdl2/keyboard.rb +101 -17
- data/lib/sdl2/keycode.rb +72 -72
- data/lib/sdl2/library.rb +7 -0
- data/lib/sdl2/log.rb +78 -21
- data/lib/sdl2/mixer.rb +651 -0
- data/lib/sdl2/mixer/chunk.rb +47 -0
- data/lib/sdl2/mixer/lib_paths.rb +8 -0
- data/lib/sdl2/mouse.rb +39 -13
- data/lib/sdl2/pixels.rb +39 -13
- data/lib/sdl2/point.rb +29 -0
- data/lib/sdl2/power.rb +3 -1
- data/lib/sdl2/rect.rb +94 -19
- data/lib/sdl2/render.rb +156 -52
- data/lib/sdl2/rwops.rb +60 -20
- data/lib/sdl2/surface.rb +85 -28
- data/lib/sdl2/syswm.rb +3 -1
- data/lib/sdl2/timer.rb +18 -6
- data/lib/sdl2/touch.rb +12 -4
- data/lib/sdl2/ttf.rb +153 -59
- data/lib/sdl2/ttf/font.rb +21 -5
- data/lib/sdl2/version.rb +9 -3
- data/lib/sdl2/video.rb +210 -70
- data/lib/sdl2/window.rb +9 -3
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/draws_the_message_to_the_screen.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_07_true_type_fonts/writes_a_message_to_a_surface.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/defaults_to_mouse_out.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/has_a_button_sheet.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_down.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_in.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_out.approved.png +0 -0
- data/spec/fixtures/approvals/lazyfoonet_lesson_09_mouse_events/shows_mouse_up.approved.png +0 -0
- data/spec/fixtures/images/button_sheet.png +0 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_01_hello_world_spec.rb +9 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_03_extension_libraries_spec.rb +1 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_04_event_driven_programming_spec.rb +4 -3
- data/spec/functional/lazy_foo_tutorial/lazy_foo_05_color_keying_spec.rb +1 -1
- data/spec/functional/lazy_foo_tutorial/lazy_foo_06_clip_blitting_and_sprite_sheets_spec.rb +4 -3
- data/spec/functional/lazy_foo_tutorial/lazy_foo_07_true_type_fonts_spec.rb +4 -2
- data/spec/functional/lazy_foo_tutorial/lazy_foo_08_key_presses_spec.rb +10 -22
- data/spec/functional/lazy_foo_tutorial/lazy_foo_09_mouse_events_spec.rb +121 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_10_key_states_spec.rb +30 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_11_playing_sounds_spec.rb +116 -0
- data/spec/functional/lazy_foo_tutorial/lazy_foo_12_timing_spec.rb +57 -0
- data/spec/spec_helper.rb +3 -1
- metadata +31 -2
data/lib/sdl2/color.rb
CHANGED
@@ -11,14 +11,19 @@ module SDL2
|
|
11
11
|
|
12
12
|
member_readers *members
|
13
13
|
member_writers *members
|
14
|
-
|
14
|
+
|
15
|
+
def self.create(values = {})
|
16
|
+
values[:a] ||= ALPHA_OPAQUE
|
17
|
+
super(values)
|
18
|
+
end
|
19
|
+
|
15
20
|
# If possible, convert argument into a SDL::Color
|
16
21
|
def self.cast(something)
|
17
22
|
if something.kind_of? Array
|
18
23
|
something.map!(&:to_i)
|
19
24
|
result = new
|
20
25
|
result.set(*something)
|
21
|
-
|
26
|
+
|
22
27
|
return result
|
23
28
|
else
|
24
29
|
return super
|
@@ -37,7 +42,7 @@ module SDL2
|
|
37
42
|
self.send("#{c}=", color.send(c))
|
38
43
|
end
|
39
44
|
end
|
40
|
-
|
45
|
+
|
41
46
|
def to_a
|
42
47
|
[r, g, b, a]
|
43
48
|
end
|
data/lib/sdl2/cpuinfo.rb
CHANGED
@@ -4,15 +4,35 @@ module SDL2
|
|
4
4
|
|
5
5
|
CACHELINE_SIZE = 128
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
##
|
8
|
+
#
|
9
|
+
api :SDL_GetCPUCount, [], :int
|
10
|
+
##
|
11
|
+
#
|
12
|
+
api :SDL_GetCPUCacheLineSize, [], :int
|
13
|
+
##
|
14
|
+
#
|
15
|
+
api :SDL_HasRDTSC, [], :bool
|
16
|
+
##
|
17
|
+
#
|
18
|
+
api :SDL_HasAltiVec, [], :bool
|
19
|
+
##
|
20
|
+
#
|
21
|
+
api :SDL_Has3DNow, [], :bool
|
22
|
+
##
|
23
|
+
#
|
24
|
+
api :SDL_HasSSE, [], :bool
|
25
|
+
##
|
26
|
+
#
|
27
|
+
api :SDL_HasSSE2, [], :bool
|
28
|
+
##
|
29
|
+
#
|
30
|
+
api :SDL_HasSSE3, [], :bool
|
31
|
+
##
|
32
|
+
#
|
33
|
+
api :SDL_HasSSE41, [], :bool
|
34
|
+
##
|
35
|
+
#
|
36
|
+
api :SDL_HasSSE42, [], :bool
|
17
37
|
|
18
38
|
end
|
data/lib/sdl2/engine.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'sdl2'
|
2
|
+
|
3
|
+
module SDL2
|
4
|
+
|
5
|
+
# Input/Output engine.
|
6
|
+
class Engine
|
7
|
+
|
8
|
+
def initialize(opts = {})
|
9
|
+
|
10
|
+
# TODO: ??
|
11
|
+
end
|
12
|
+
|
13
|
+
def quit()
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :surface
|
18
|
+
|
19
|
+
def on_handlers
|
20
|
+
@on_handlers ||= {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def on(*args, &block)
|
24
|
+
raise "Must specify EVENTTYPEs to handle" if args.empty?
|
25
|
+
raise "Must give block to call on event" if args.empty? unless block.nil?
|
26
|
+
args.each do |event_hash|
|
27
|
+
raise "Expected Hash: #{event_hash.inspect}" unless event_hash.kind_of? Hash
|
28
|
+
on_handlers[event_hash] = block
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def handle_event(event)
|
33
|
+
|
34
|
+
on_handlers.each_pair do |event_hash, handler|
|
35
|
+
|
36
|
+
return true if handler.call(event) if event == event_hash
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
return false # if we get to here.
|
41
|
+
end
|
42
|
+
|
43
|
+
# This routine should be overriden.
|
44
|
+
def paint_to(surface)
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sdl2/engine'
|
2
|
+
|
3
|
+
module SDL2
|
4
|
+
|
5
|
+
class Engine
|
6
|
+
|
7
|
+
class BlockEngine < Engine
|
8
|
+
|
9
|
+
def initialize(opts={})
|
10
|
+
super(opts)
|
11
|
+
painter = opts[:painter]
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :painter
|
15
|
+
|
16
|
+
def paint_to(surface)
|
17
|
+
unless painter.nil?
|
18
|
+
return painter.call(surface)
|
19
|
+
else
|
20
|
+
return super(surface)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'sdl2/engine'
|
2
|
+
|
3
|
+
module SDL2
|
4
|
+
|
5
|
+
# An engine multiplexor.
|
6
|
+
# Only has one focus, but that focus can change.
|
7
|
+
class Engine::Engines < Engine
|
8
|
+
|
9
|
+
def initialize(opts)
|
10
|
+
super(opts)
|
11
|
+
@engines = [] #opts[:engines] || []
|
12
|
+
@current_idx = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :engines
|
16
|
+
|
17
|
+
def current_engine
|
18
|
+
@engines[@current_idx]
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle_event(event)
|
22
|
+
return true if super(event) # self swallowed event.
|
23
|
+
if current_engine
|
24
|
+
puts "Passing to current engine."if SDL2::PrintDebug
|
25
|
+
return true if current_engine.handle_event(event)
|
26
|
+
end
|
27
|
+
puts "Unable to handle"if SDL2::PrintDebug
|
28
|
+
return false # if we get to here.
|
29
|
+
end
|
30
|
+
|
31
|
+
def paint_to(surface)
|
32
|
+
if ce = current_engine
|
33
|
+
return ce.paint_to(surface)
|
34
|
+
else
|
35
|
+
return false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def quit()
|
40
|
+
@engines.each(&:quit)
|
41
|
+
super()
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/sdl2/error.rb
CHANGED
@@ -2,8 +2,14 @@ require 'sdl2'
|
|
2
2
|
|
3
3
|
module SDL2
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
##
|
6
|
+
#
|
7
|
+
api :SDL_ClearError, [], :void
|
8
|
+
##
|
9
|
+
#
|
10
|
+
api :SDL_GetError, [], :string
|
11
|
+
##
|
12
|
+
#
|
13
|
+
api :SDL_SetError, [:string, :varargs], :int
|
8
14
|
|
9
15
|
end
|
data/lib/sdl2/events.rb
CHANGED
@@ -77,12 +77,14 @@ module SDL2
|
|
77
77
|
|
78
78
|
class AbstractEvent < Struct
|
79
79
|
SHARED = [:type, :event_type, :timestamp, :uint32]
|
80
|
+
|
80
81
|
end
|
81
82
|
|
82
83
|
# Fields shared by every event
|
83
84
|
class CommonEvent < AbstractEvent
|
84
85
|
|
85
86
|
layout *SHARED
|
87
|
+
|
86
88
|
end
|
87
89
|
|
88
90
|
# Window state change event data (event.window.*)
|
@@ -439,20 +441,48 @@ module SDL2
|
|
439
441
|
end
|
440
442
|
return tmp_event # May be nil if SDL2.poll_event fails.
|
441
443
|
end
|
442
|
-
|
444
|
+
|
445
|
+
def self.push(event)
|
446
|
+
event = Event.cast(event)
|
447
|
+
SDL2.push_event!(event)
|
448
|
+
end
|
449
|
+
|
443
450
|
def self.cast(something)
|
444
451
|
if something.kind_of? AbstractEvent
|
445
452
|
return self.new(something.pointer)
|
453
|
+
elsif something.kind_of? Hash
|
454
|
+
raise "Must have type : #{something.inspect}" unless something.has_key? :type
|
455
|
+
tmp = self.new
|
456
|
+
fields = members & something.keys
|
457
|
+
fields.each do |field|
|
458
|
+
if tmp[field].kind_of? Struct and something[field].kind_of? Hash
|
459
|
+
tmp[field].update_members(something[field])
|
460
|
+
else
|
461
|
+
tmp[field] = something[field]
|
462
|
+
end
|
463
|
+
end
|
464
|
+
return tmp
|
446
465
|
else
|
447
466
|
raise "Is not an AbstractEvent!: #{something.inspect}"
|
448
467
|
end
|
449
468
|
end
|
450
469
|
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
470
|
+
def ==(other)
|
471
|
+
if other.kind_of?(Hash)
|
472
|
+
# False if there are fields that do not exist
|
473
|
+
return false unless (other.keys - members).empty?
|
474
|
+
|
475
|
+
(other.keys & members).each do |field|
|
476
|
+
return false unless self[field] == other[field]
|
477
|
+
end
|
478
|
+
|
479
|
+
return true #if we get this far
|
480
|
+
|
481
|
+
else
|
482
|
+
|
483
|
+
return super(other)
|
484
|
+
|
485
|
+
end
|
456
486
|
end
|
457
487
|
|
458
488
|
end
|
@@ -468,15 +498,33 @@ module SDL2
|
|
468
498
|
|
469
499
|
##
|
470
500
|
# :class-method: peep_events
|
501
|
+
##
|
502
|
+
#
|
471
503
|
api :SDL_PeepEvents, [Event.by_ref, :count, :eventaction, :uint32, :uint32], :int
|
504
|
+
##
|
505
|
+
#
|
472
506
|
api :SDL_HasEvent, [:uint32], :bool
|
507
|
+
##
|
508
|
+
#
|
473
509
|
api :SDL_HasEvents, [:uint32, :uint32], :bool
|
510
|
+
##
|
511
|
+
#
|
474
512
|
api :SDL_FlushEvent, [:uint32], :void
|
513
|
+
##
|
514
|
+
#
|
475
515
|
api :SDL_FlushEvents, [:uint32, :uint32], :void
|
516
|
+
##
|
517
|
+
#
|
476
518
|
api :SDL_PollEvent, [Event.by_ref], :int
|
477
519
|
boolean? :poll_event, TRUE_WHEN_ONE
|
520
|
+
##
|
521
|
+
#
|
478
522
|
api :SDL_WaitEvent, [Event.by_ref], :int
|
523
|
+
##
|
524
|
+
#
|
479
525
|
api :SDL_WaitEventTimeout, [Event.by_ref, :count], :int
|
526
|
+
##
|
527
|
+
#
|
480
528
|
api :SDL_PushEvent, [Event.by_ref], :int, {error: true, filter: TRUE_WHEN_ONE}
|
481
529
|
|
482
530
|
##
|
@@ -488,10 +536,20 @@ module SDL2
|
|
488
536
|
layout :callback, :event_filter
|
489
537
|
end
|
490
538
|
|
539
|
+
##
|
540
|
+
#
|
491
541
|
api :SDL_SetEventFilter, [:event_filter, :pointer], :void
|
542
|
+
##
|
543
|
+
#
|
492
544
|
api :SDL_GetEventFilter, [:pointer, :pointer], :bool
|
545
|
+
##
|
546
|
+
#
|
493
547
|
api :SDL_AddEventWatch, [:event_filter, :pointer], :void
|
548
|
+
##
|
549
|
+
#
|
494
550
|
api :SDL_DelEventWatch, [:event_filter, :pointer], :void
|
551
|
+
##
|
552
|
+
#
|
495
553
|
api :SDL_FilterEvents, [:event_filter, :pointer], :void
|
496
554
|
|
497
555
|
# Enumeration of event_state query
|
@@ -505,6 +563,8 @@ module SDL2
|
|
505
563
|
|
506
564
|
enum :event_state, EVENTSTATE.flatten_consts
|
507
565
|
|
566
|
+
##
|
567
|
+
#
|
508
568
|
##
|
509
569
|
#
|
510
570
|
api :SDL_EventState, [:uint32, :event_state], :uint8
|
@@ -513,5 +573,7 @@ module SDL2
|
|
513
573
|
event_state(type, EVENTSTATE::QUERY)
|
514
574
|
end
|
515
575
|
|
576
|
+
##
|
577
|
+
#
|
516
578
|
api :SDL_RegisterEvents, [:count], :uint32
|
517
579
|
end
|
data/lib/sdl2/gamecontroller.rb
CHANGED
@@ -30,33 +30,73 @@ module SDL2
|
|
30
30
|
|
31
31
|
end#GameController
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
##
|
34
|
+
#
|
35
|
+
api :SDL_GameControllerAddMapping, [:string], :int
|
36
|
+
##
|
37
|
+
#
|
38
|
+
api :SDL_GameControllerMappingForGUID, [JoystickGUID.by_value], :string
|
39
|
+
##
|
40
|
+
#
|
41
|
+
api :SDL_GameControllerMapping, [GameController.by_ref], :string
|
42
|
+
##
|
43
|
+
#
|
44
|
+
api :SDL_IsGameController, [:joystick_index], :bool
|
45
|
+
##
|
46
|
+
#
|
47
|
+
api :SDL_GameControllerNameForIndex, [:joystick_index], :string
|
48
|
+
##
|
49
|
+
#
|
50
|
+
api :SDL_GameControllerOpen, [:joystick_index], :string
|
51
|
+
##
|
52
|
+
#
|
53
|
+
api :SDL_GameControllerName, [GameController.by_ref], :string
|
54
|
+
##
|
55
|
+
#
|
56
|
+
api :SDL_GameControllerGetAttached, [GameController.by_ref], :bool
|
57
|
+
##
|
58
|
+
#
|
59
|
+
api :SDL_GameControllerGetJoystick, [GameController.by_ref], Joystick.by_ref
|
60
|
+
##
|
61
|
+
#
|
62
|
+
api :SDL_GameControllerEventState, [:int], :int
|
63
|
+
##
|
64
|
+
#
|
65
|
+
api :SDL_GameControllerUpdate, [], :void
|
44
66
|
|
45
67
|
enum :game_controller_axis, [:INVALID, -1, :LEFTX, :LEFTY, :RIGHTX, :RIGHTY, :TRIGGERLEFT, :TRIGGERRIGHT, :MAX]
|
46
68
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
69
|
+
##
|
70
|
+
#
|
71
|
+
api :SDL_GameControllerGetAxisFromString, [:string], :game_controller_axis
|
72
|
+
##
|
73
|
+
#
|
74
|
+
api :SDL_GameControllerGetStringForAxis, [:game_controller_axis], :string
|
75
|
+
##
|
76
|
+
#
|
77
|
+
api :SDL_GameControllerGetBindForAxis, [GameController.by_ref, :game_controller_axis], GameController::ButtonBind
|
78
|
+
##
|
79
|
+
#
|
80
|
+
api :SDL_GameControllerGetAxis, [GameController.by_ref, :game_controller_axis], :int16
|
51
81
|
|
52
82
|
enum :game_controller_button, [:INVLIAD, -1,
|
53
83
|
:A, :B, :X, :Y, :BACK, :GUIDE, :START,
|
54
84
|
:LEFTSTICK, :RIGHTSTICK, :LEFTSHOULDER, :RIGHTSHOULDER,
|
55
85
|
:DPAD_UP, :DPAD_DOWN, :DPAD_LEFT, :DPAD_RIGHT]
|
56
86
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
87
|
+
##
|
88
|
+
#
|
89
|
+
api :SDL_GameControllerGetButtonFromString, [:string], :game_controller_button
|
90
|
+
##
|
91
|
+
#
|
92
|
+
api :SDL_GameControllerGetStringForButton, [:game_controller_button], :string
|
93
|
+
##
|
94
|
+
#
|
95
|
+
api :SDL_GameControllerGetBindForButton, [GameController.by_ref, :game_controller_button], GameController::ButtonBind
|
96
|
+
##
|
97
|
+
#
|
98
|
+
api :SDL_GameControllerGetButton, [GameController.by_ref, :game_controller_button], :uint8
|
99
|
+
##
|
100
|
+
#
|
101
|
+
api :SDL_GameControllerClose, [GameController.by_ref], :void
|
62
102
|
end
|