sdl2-win93 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.dir-locals.el +2 -0
  3. data/.github/workflows/gempush.yml +29 -0
  4. data/.gitignore +14 -0
  5. data/COPYING.txt +165 -0
  6. data/Gemfile +4 -0
  7. data/Gemfile.lock +24 -0
  8. data/Makefile +4 -0
  9. data/README.md +36 -0
  10. data/Rakefile +51 -0
  11. data/doc/po/ja.po +10357 -0
  12. data/ext/sdl2_ext/clipboard.c +61 -0
  13. data/ext/sdl2_ext/color.c +103 -0
  14. data/ext/sdl2_ext/color.h +4 -0
  15. data/ext/sdl2_ext/event.c +1298 -0
  16. data/ext/sdl2_ext/extconf.rb +22 -0
  17. data/ext/sdl2_ext/filesystem.c +63 -0
  18. data/ext/sdl2_ext/gamecontroller.c +408 -0
  19. data/ext/sdl2_ext/gamecontroller.c.m4 +408 -0
  20. data/ext/sdl2_ext/gl.c +351 -0
  21. data/ext/sdl2_ext/gl.c.m4 +351 -0
  22. data/ext/sdl2_ext/hint.c +99 -0
  23. data/ext/sdl2_ext/joystick.c +339 -0
  24. data/ext/sdl2_ext/joystick.c.m4 +339 -0
  25. data/ext/sdl2_ext/key.c +1302 -0
  26. data/ext/sdl2_ext/key.c.m4 +833 -0
  27. data/ext/sdl2_ext/main.c +258 -0
  28. data/ext/sdl2_ext/messagebox.c +233 -0
  29. data/ext/sdl2_ext/mixer.c +1205 -0
  30. data/ext/sdl2_ext/mixer.c.m4 +1205 -0
  31. data/ext/sdl2_ext/mouse.c +286 -0
  32. data/ext/sdl2_ext/rubysdl2_internal.h +127 -0
  33. data/ext/sdl2_ext/timer.c +63 -0
  34. data/ext/sdl2_ext/ttf.c +376 -0
  35. data/ext/sdl2_ext/ttf.c.m4 +376 -0
  36. data/ext/sdl2_ext/video.c +4093 -0
  37. data/ext/sdl2_ext/video.c.m4 +3867 -0
  38. data/lib/sdl2.rb +3 -0
  39. data/lib/sdl2/event.rb +55 -0
  40. data/lib/sdl2/version.rb +8 -0
  41. data/sample/chunk_destroy.rb +16 -0
  42. data/sample/gfxprimitives.rb +54 -0
  43. data/sample/icon.bmp +0 -0
  44. data/sample/memory_test/m1.rb +28 -0
  45. data/sample/memory_test/m2.rb +18 -0
  46. data/sample/memory_test/m3.rb +12 -0
  47. data/sample/message_box.rb +33 -0
  48. data/sample/music_player.rb +137 -0
  49. data/sample/playwave.rb +19 -0
  50. data/sample/primitives.rb +32 -0
  51. data/sample/test_clipboard.rb +16 -0
  52. data/sample/test_controller.rb +62 -0
  53. data/sample/test_joystick.rb +53 -0
  54. data/sample/test_keyboard.rb +52 -0
  55. data/sample/test_mouse.rb +50 -0
  56. data/sample/test_surface.rb +13 -0
  57. data/sample/test_ttf.rb +82 -0
  58. data/sample/test_video.rb +59 -0
  59. data/sample/testgl.rb +175 -0
  60. data/sample/testsprite.rb +296 -0
  61. data/sample/testspriteminimal.rb +75 -0
  62. data/sample/timer.rb +11 -0
  63. data/sample/version.rb +12 -0
  64. data/sample/video_info.rb +64 -0
  65. data/sdl2-win93.gemspec +31 -0
  66. metadata +158 -0
@@ -0,0 +1,3 @@
1
+ require 'sdl2_ext'
2
+ require 'sdl2/version'
3
+ require 'sdl2/event'
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL2
4
+ class Event
5
+ class Window
6
+ def inspect
7
+ # TODO: this is compressible with a dyanmic filled hash
8
+ event_inspect =
9
+ case event
10
+ when NONE then "NONE"
11
+ when SHOWN then "SHOWN"
12
+ when HIDDEN then "HIDDEN"
13
+ when EXPOSED then "EXPOSED"
14
+ when MOVED then "MOVED(#{data1}, #{data2})"
15
+ when RESIZED then "RESIZED(#{data1}, #{data2})"
16
+ when SIZE_CHANGED then "SIZE_CHANGED(#{data1}, #{data2})"
17
+ when MINIMIZED then "MINIMIZED"
18
+ when MAXIMIZED then "MAXIMIZED"
19
+ when RESTORED then "RESTORED"
20
+ when ENTER then "ENTER"
21
+ when LEAVE then "LEAVE"
22
+ when FOCUS_GAINED then "FOCUS_GAINED"
23
+ when FOCUS_LOST then "FOCUS_LOST"
24
+ when CLOSE then "CLOSE"
25
+ else "UNKNOWN(#{event})(#{data1}, #{data2})"
26
+ end
27
+
28
+ "<#{self.class.inspect}: " \
29
+ "timestamp=#{timestamp.inspect} " \
30
+ "window_id=#{window_id.inspect} " \
31
+ "event=#{event_inspect}>"
32
+ end
33
+ end
34
+
35
+ class TextInput
36
+ def inspect
37
+ "<#{self.class.inspect}: " \
38
+ "timestamp=#{timestamp.inspect} " \
39
+ "window_id=#{window_id.inspect} " \
40
+ "text=#{text.inspect}>"
41
+ end
42
+ end
43
+
44
+ class Keyboard
45
+ def inspect
46
+ "<#{self.class.inspect}: " \
47
+ "timestamp=#{timestamp.inspect} " \
48
+ "window_id=#{window_id.inspect} " \
49
+ "repeat=#{repeat.inspect} " \
50
+ "scancode=#{SDL2::Key::Scan.name_of(scancode).inspect} " \
51
+ "sym=#{SDL2::Key.name_of(sym).inspect}>"
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SDL2
4
+ # Version string of Ruby/SDL2
5
+ VERSION = "1.0.0"
6
+ # Version of Ruby/SDL2, [major, minor, patch level]
7
+ VERSION_NUMBER = VERSION.split(".").map(&:to_i)
8
+ end
@@ -0,0 +1,16 @@
1
+ require 'sdl2'
2
+
3
+ SDL2::init(SDL2::INIT_AUDIO)
4
+
5
+ SDL2::Mixer.init(SDL2::Mixer::INIT_FLAC|SDL2::Mixer::INIT_MP3|SDL2::Mixer::INIT_OGG)
6
+
7
+
8
+ SDL2::Mixer.open(22050, SDL2::Mixer::DEFAULT_FORMAT, 2, 512)
9
+
10
+ chunk = SDL2::Mixer::Chunk.load(ARGV[0])
11
+ p chunk; chunk.destroy; p chunk; p chunk.destroy?
12
+
13
+ mus = SDL2::Mixer::Music.load(ARGV[0])
14
+ p mus; mus.destroy; p mus; p mus.destroy?
15
+
16
+ GC.start
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "sdl2"
5
+
6
+ SDL2.init(SDL2::INIT_VIDEO | SDL2::INIT_EVENTS)
7
+
8
+ window = SDL2::Window.create("gfxtestsprite",
9
+ SDL2::Window::POS_CENTERED, SDL2::Window::POS_CENTERED, 640, 480, SDL2::Window::Flags::ALLOW_HIGHDPI)
10
+ renderer = window.create_renderer(-1, 0)
11
+
12
+ renderer.draw_color = 0xFF0000_FF
13
+ renderer.draw_line(0, 0, 640, 480)
14
+ renderer.draw_line_aa(10, 0, 640, 470)
15
+ renderer.draw_color = 0xFFFF00_FF
16
+ renderer.draw_point(200, 200)
17
+ renderer.draw_color = 0x00FFFF_FF
18
+ renderer.draw_rect(SDL2::Rect.new(500, 20, 40, 60))
19
+ renderer.fill_rect(SDL2::Rect.new(20, 400, 60, 40))
20
+ renderer.fill_rect(SDL2::Rect.new(400, 20, 40, 60))
21
+ renderer.fill_rect(SDL2::Rect.new(120, 400, 60, 40))
22
+ renderer.draw_color = 0xFFFFFF_FF
23
+ renderer.draw_rounded_rect(120, 400, 60, 40, 16)
24
+ renderer.draw_color = 0xFF00FF_FF
25
+ renderer.draw_rounded_rect(400, 20, 40, 60, 16)
26
+ renderer.fill_rounded_rect(120, 400, 60, 40, 16)
27
+ renderer.fill_rounded_rect(220, 400, 60, 40, 16)
28
+ renderer.draw_color = 0xFFFFFF_FF
29
+ renderer.draw_rounded_rect(220, 400, 60, 40, 16)
30
+ renderer.fill_pie(320, 400, 8, 0, 359)
31
+ renderer.draw_color = 0x00FFFF_FF
32
+ renderer.draw_ellipse(70, 70, 15, 15)
33
+ renderer.draw_blend_mode = SDL2::BlendMode::ADD
34
+ renderer.draw_color = 0xFF0000_FF
35
+ renderer.draw_rect(SDL2::Rect.new(40, 420, 60, 40))
36
+ renderer.draw_blend_mode = SDL2::BlendMode::BLEND
37
+ renderer.draw_color = 0xFFFFFF_66
38
+ renderer.fill_rounded_rect(500, 100, 200, 200, 85)
39
+
40
+ renderer.present
41
+
42
+ loop do
43
+ while (event = SDL2::Event.poll)
44
+ case event
45
+ when SDL2::Event::KeyDown
46
+ exit if event.scancode == SDL2::Key::Scan::ESCAPE
47
+ when SDL2::Event::Quit
48
+ exit
49
+ end
50
+ end
51
+
52
+ renderer.present
53
+ sleep 0.02
54
+ end
Binary file
@@ -0,0 +1,28 @@
1
+ require "sdl2"
2
+
3
+ SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
4
+
5
+ window = SDL2::Window.create("testsprite",
6
+ SDL2::Window::POS_CENTERED, SDL2::Window::POS_CENTERED,
7
+ 640, 480, 0)
8
+
9
+ def f2(renderer)
10
+ surface = SDL2::Surface.load_bmp("icon.bmp")
11
+ 10.times { renderer.create_texture_from(surface) }
12
+ p renderer.debug_info
13
+ end
14
+
15
+ def f1(window)
16
+ renderer = window.create_renderer(-1, 0)
17
+ p window.debug_info
18
+ p renderer.debug_info
19
+ f2(renderer)
20
+ GC.start
21
+ p renderer.debug_info
22
+ end
23
+
24
+ f1(window)
25
+ GC.start
26
+ p window.debug_info
27
+
28
+
@@ -0,0 +1,18 @@
1
+ require "sdl2"
2
+
3
+ SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
4
+
5
+ $window = SDL2::Window.create("testsprite", 0, 0, 128, 128, 0)
6
+
7
+ def f
8
+ renderer = $window.create_renderer(-1, 0)
9
+ surface = SDL2::Surface.load_bmp("icon.bmp")
10
+ a = Array.new(10) { renderer.create_texture_from(surface) }
11
+ p a.map{|tex| tex.debug_info }
12
+ p renderer.debug_info
13
+ a
14
+ end
15
+
16
+ a = f
17
+ GC.start
18
+ p a.map{|tex| tex.debug_info }
@@ -0,0 +1,12 @@
1
+ require "sdl2"
2
+
3
+ SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
4
+
5
+ window = SDL2::Window.create("testsprite",
6
+ SDL2::Window::POS_CENTERED, SDL2::Window::POS_CENTERED,
7
+ 640, 480, 0)
8
+ renderer = window.create_renderer(-1, 0)
9
+ surface = SDL2::Surface.load_bmp("icon.bmp")
10
+ 10.times { renderer.create_texture_from(surface) }
11
+
12
+ window.destroy
@@ -0,0 +1,33 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'sdl2'
3
+
4
+ SDL2::MessageBox.show_simple_box(SDL2::MessageBox::ERROR, "Error",
5
+ "This is the error message box", nil)
6
+
7
+ button = SDL2::MessageBox.show(flags: SDL2::MessageBox::WARNING,
8
+ window: nil,
9
+ title: "警告ウインドウ",
10
+ message: "ここに警告文が出ます",
11
+ buttons: [ { # flags is ignored
12
+ id: 0,
13
+ text: "いいえ",
14
+ },
15
+ {flags: SDL2::MessageBox::BUTTON_RETURNKEY_DEFAULT,
16
+ id: 1,
17
+ text: "はい",
18
+ },
19
+ {flags: SDL2::MessageBox::BUTTON_ESCAPEKEY_DEFAULT,
20
+ id: 2,
21
+ text: "キャンセル",
22
+ },
23
+ ],
24
+ color_scheme: {
25
+ bg: [255, 0, 0],
26
+ text: [0, 255, 0],
27
+ button_border: [255, 0, 0],
28
+ button_bg: [0, 0, 255],
29
+ button_selected: [255, 0, 0]
30
+ }
31
+ )
32
+ p button
33
+
@@ -0,0 +1,137 @@
1
+ begin
2
+ require 'sdl2'
3
+ rescue LoadError
4
+ $LOAD_PATH.unshift File.expand_path File.join(__dir__, '../lib')
5
+ retry
6
+ end
7
+
8
+ class TextureForText
9
+ def initialize(renderer, font)
10
+ @renderer = renderer
11
+ @text_surfaces = {}
12
+ @font = font
13
+ @texture = nil
14
+ end
15
+
16
+ def add_text(text)
17
+ @text_surfaces[text] = @font.render_blended(text, [0xff, 0xff, 0xff])
18
+ end
19
+
20
+ def creat_texture!
21
+ @text_rects = Hash.new
22
+ h = @text_surfaces.inject(0){|y, (text, surface)|
23
+ @text_rects[text] = SDL2::Rect[0, y, surface.w, surface.h]
24
+ y + surface.h
25
+ }
26
+ w = @text_rects.values.map(&:w).max
27
+
28
+ tmp_surface = SDL2::Surface.new(w, h, 32)
29
+ @text_surfaces.each do |text, surface|
30
+ SDL2::Surface.blit(surface, nil, tmp_surface, @text_rects[text])
31
+ end
32
+ @texture = @renderer.create_texture_from(tmp_surface)
33
+ tmp_surface.destroy
34
+
35
+ @text_surfaces = nil
36
+ end
37
+
38
+ def box_for(text)
39
+ @text_rects[text]
40
+ end
41
+
42
+ def render(text, dst)
43
+ srcrect = @text_rects[text]
44
+ dst = SDL2::Rect[dst.x, dst.y, srcrect.w, srcrect.h] if dst.is_a?(SDL2::Point)
45
+ @renderer.copy(@texture, srcrect, dst)
46
+ end
47
+
48
+ attr_reader :texture
49
+ end
50
+
51
+ class MusicPlayer
52
+ def run(argv)
53
+ file = argv.shift
54
+
55
+ SDL2.init(SDL2::INIT_EVERYTHING)
56
+ SDL2::Mixer.init(SDL2::Mixer::INIT_FLAC|SDL2::Mixer::INIT_MODPLUG|
57
+ SDL2::Mixer::INIT_MP3|SDL2::Mixer::INIT_OGG)
58
+ SDL2::Mixer.open(44100, SDL2::Mixer::DEFAULT_FORMAT, 2, 512)
59
+ SDL2::TTF.init
60
+
61
+ @window = SDL2::Window.create("music player sample by Ruby/SDL2", 0, 0, 640, 480, 0)
62
+ @renderer = @window.create_renderer(-1, 0)
63
+ @music = SDL2::Mixer::Music.load(file)
64
+ font = SDL2::TTF.open("font.ttf", 24)
65
+
66
+ @texts = TextureForText.new(@renderer, font)
67
+ @texts.add_text(file)
68
+ @texts.add_text("playing")
69
+ @texts.add_text("playing (fade in)")
70
+ @texts.add_text("stopping")
71
+ @texts.add_text("fade out")
72
+ @texts.add_text("pause")
73
+ @texts.creat_texture!
74
+
75
+ loop do
76
+ while event = SDL2::Event.poll
77
+ handle_event(event)
78
+ end
79
+
80
+ @renderer.draw_color = [0, 0, 0]
81
+ @renderer.clear
82
+
83
+ @texts.render(file, SDL2::Point[20, 20])
84
+ @texts.render(playing_state, SDL2::Point[20, 120])
85
+
86
+ @renderer.present
87
+ sleep 0.01
88
+ end
89
+ end
90
+
91
+ def handle_event(event)
92
+ case event
93
+ when SDL2::Event::Quit
94
+ exit
95
+ when SDL2::Event::KeyDown
96
+ keydown(event)
97
+ end
98
+ end
99
+
100
+ def keydown(event)
101
+ match_keydown("ESCAPE", event){ exit }
102
+ match_keydown("p", event) { SDL2::Mixer::MusicChannel.play(@music, 1) }
103
+ match_keydown("h", event) { SDL2::Mixer::MusicChannel.halt }
104
+ match_keydown("r", event) { SDL2::Mixer::MusicChannel.rewind }
105
+ match_keydown("o", event) { SDL2::Mixer::MusicChannel.fade_out(1000) }
106
+ match_keydown("i", event) { SDL2::Mixer::MusicChannel.fade_in(@music, 1, 1000) }
107
+ match_keydown("SPACE", event) {
108
+ if SDL2::Mixer::MusicChannel.pause?
109
+ SDL2::Mixer::MusicChannel.resume
110
+ else
111
+ SDL2::Mixer::MusicChannel.pause
112
+ end
113
+ }
114
+ end
115
+
116
+ def match_keydown(key, event)
117
+ sym = SDL2::Key.keycode_from_name(key)
118
+ yield if event.sym == sym
119
+ end
120
+
121
+ def playing_state
122
+ return "stopping" if !SDL2::Mixer::MusicChannel.play?
123
+ return "pause" if SDL2::Mixer::MusicChannel.pause?
124
+ case SDL2::Mixer::MusicChannel.fading
125
+ when SDL2::Mixer::NO_FADING
126
+ return "playing"
127
+ when SDL2::Mixer::FADING_IN
128
+ return "playing (fade in)"
129
+ when SDL2::Mixer::FADING_OUT
130
+ return "fade out"
131
+ end
132
+ end
133
+ end
134
+
135
+
136
+ MusicPlayer.new.run(ARGV)
137
+
@@ -0,0 +1,19 @@
1
+ # ruby playwave.rb sample.wav
2
+ require 'sdl2'
3
+
4
+ SDL2::init(SDL2::INIT_AUDIO)
5
+
6
+ SDL2::Mixer.init(SDL2::Mixer::INIT_FLAC|SDL2::Mixer::INIT_MP3|SDL2::Mixer::INIT_OGG)
7
+ SDL2::Mixer.open(22050, SDL2::Mixer::DEFAULT_FORMAT, 2, 512)
8
+
9
+ p SDL2::Mixer::Chunk.decoders
10
+ p SDL2::Mixer::Music.decoders
11
+ wave = SDL2::Mixer::Chunk.load(ARGV[0])
12
+
13
+ SDL2::Mixer::Channels.fade_in(0, wave, 0, 600)
14
+
15
+ while SDL2::Mixer::Channels.play?(0)
16
+ sleep 1
17
+ end
18
+
19
+
@@ -0,0 +1,32 @@
1
+ require "sdl2"
2
+
3
+ SDL2.init(SDL2::INIT_VIDEO|SDL2::INIT_EVENTS)
4
+
5
+ window = SDL2::Window.create("testsprite",
6
+ SDL2::Window::POS_CENTERED, SDL2::Window::POS_CENTERED,
7
+ 640, 480, 0)
8
+ renderer = window.create_renderer(-1, 0)
9
+
10
+ renderer.draw_color = [255, 0, 0, 255]
11
+ renderer.draw_line(0,0,640,480)
12
+ renderer.draw_color = [255, 255, 0]
13
+ renderer.draw_point(200, 200)
14
+ renderer.draw_color = [0, 255, 255]
15
+ renderer.draw_rect(SDL2::Rect.new(500, 20, 40, 60))
16
+ renderer.fill_rect(SDL2::Rect.new(20, 400, 60, 40))
17
+ renderer.draw_blend_mode = SDL2::BlendMode::ADD
18
+ renderer.draw_color = [255, 0, 0]
19
+ renderer.draw_rect(SDL2::Rect.new(40, 420, 60, 40))
20
+
21
+ renderer.present
22
+
23
+ loop do
24
+ while ev = SDL2::Event.poll
25
+ if SDL2::Event::KeyDown === ev && ev.scancode == SDL2::Key::Scan::ESCAPE
26
+ exit
27
+ end
28
+ end
29
+
30
+ renderer.present
31
+ sleep 0.1
32
+ end
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'sdl2'
3
+ rescue LoadError
4
+ $LOAD_PATH.unshift File.expand_path File.join(__dir__, '../lib')
5
+ retry
6
+ end
7
+
8
+ SDL2.init(SDL2::INIT_EVERYTHING)
9
+ window = SDL2::Window.create("clipboard", 0, 0, 640, 480, 0)
10
+
11
+ # you can call clipboard functions after creating window (on X11)
12
+ p SDL2::Clipboard.has_text?
13
+ p SDL2::Clipboard.text
14
+ # text= is not reliable on X11 environment
15
+
16
+