dxruby_sdl 0.0.1
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.
- checksums.yaml +15 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +20 -0
- data/.ruby-version +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LEGAL +11 -0
- data/LICENSE +20 -0
- data/README.md +57 -0
- data/Rakefile +17 -0
- data/dxruby_sdl.gemspec +30 -0
- data/lib/dxruby.rb +5 -0
- data/lib/dxruby_sdl/color.rb +23 -0
- data/lib/dxruby_sdl/font.rb +37 -0
- data/lib/dxruby_sdl/image.rb +54 -0
- data/lib/dxruby_sdl/version.rb +5 -0
- data/lib/dxruby_sdl/window/fpstimer.rb +91 -0
- data/lib/dxruby_sdl/window.rb +61 -0
- data/lib/dxruby_sdl.rb +13 -0
- data/spec/dxruby_sdl/color_spec.rb +41 -0
- data/spec/dxruby_sdl/font_spec.rb +13 -0
- data/spec/dxruby_sdl/image_spec.rb +54 -0
- data/spec/dxruby_sdl/window_spec.rb +117 -0
- data/spec/dxruby_sdl_spec.rb +31 -0
- data/spec/fixtures/logo.jpg +0 -0
- data/spec/fixtures/logo.png +0 -0
- data/spec/spec_helper.rb +7 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NzJhYzhjNTM0MzdmNTA3NGYzZmU0ZjM0ZmM5Nzg5ZWFmZTQxODI5Mw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Y2Y2ZWIxMmM1Mjc2NTM2OWNmMjE1MjViNDI2NTNmZGVkZmQ4NjgyYw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmY1YmJhNmUzMDI3ZjVhZjRhZTk4M2NhMGE1NTI1OTI5MmFjZjAwYTc5NjI4
|
10
|
+
NGNmYTczNjViMzVhZDQxZjk1OGQ1MGQ5ZjllYjI3Yjc3YmRlNDE2NDBmOTcw
|
11
|
+
YjQ3ZTRiYTQ4N2UwM2RhZDZkOTRjY2I5YzQ5YTNkMGE5NzRjMTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDI5Nzg3NGYxZmRjOTU2YmVlMDJhZjQwNWFjMjFlMWY1ODVmMTNiNjYyNTVk
|
14
|
+
YjJmNDgxZTkyN2VjYzJjZGY4YzkyNjQzM2Y0ZWRkYmI5ZmFhM2NmZDRhZDll
|
15
|
+
OTc1M2MwODY2OGU5NDNhZWE4ZjlkODBlYzg4ZjA4NGQzYmE0MjQ=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
MethodLength:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
HandleExceptions:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Blocks:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
FavorUnlessOverNegatedIf:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
IfUnlessModifier:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
RedundantReturn:
|
20
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p448
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LEGAL
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
LEGAL NOTICE INFORMATION
|
2
|
+
------------------------
|
3
|
+
|
4
|
+
All the files in this distribution are covered under either the
|
5
|
+
dxruby_sdl's license (see the file LICENSE) except some files
|
6
|
+
mentioned below.
|
7
|
+
|
8
|
+
lib/dxruby_sdl/window/fpstimer.rb:
|
9
|
+
|
10
|
+
FPSTimer (Original name is FPSTimerSample) class is implemented in
|
11
|
+
http://www.kmc.gr.jp/~ohai/fpstimer.rb.
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 TAKAO Kouji
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# dxruby_sdl
|
2
|
+
|
3
|
+
[](https://travis-ci.org/takaokouji/dxruby_sdl)
|
4
|
+
[](https://coveralls.io/r/takaokouji/dxruby_sdl?branch=master)
|
5
|
+
[](https://gemnasium.com/takaokouji/dxruby_sdl)
|
6
|
+
[](https://codeclimate.com/github/takaokouji/dxruby_sdl)
|
7
|
+
|
8
|
+
`dxruby_sdl` is a ruby library for 2D graphics and game. It has same
|
9
|
+
DXRuby API. It use SDL/Ruby.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
### SDL & SGE
|
14
|
+
|
15
|
+
#### Mac OS X with MacPorts
|
16
|
+
|
17
|
+
SDL
|
18
|
+
|
19
|
+
sudo port install libsdl libsdl_image libsdl_mixer libsdl_sound libsdl_ttf
|
20
|
+
|
21
|
+
SGE
|
22
|
+
|
23
|
+
curl -O http://www.digitalfanatics.org/cal/sge/files/sge030809.tar.gz
|
24
|
+
tar xvzf sge030809.tar.gz
|
25
|
+
cd sge030809
|
26
|
+
curl https://gist.github.com/steved555/963525/raw/7b638e4100f9dd1a9d00560b98ea2ddd4375b2b0/sge_030809_freetype.patch | patch
|
27
|
+
curl https://gist.github.com/steved555/963524/raw/c03396e1fb8bb87e9f4ba92597d087f730c6c48b/sge_030809_cmap.patch | patch
|
28
|
+
curl https://gist.github.com/steved555/963522/raw/5b277a0a6b08a1c077fbe2c96eead4ef1d761856/sge-030809-build.patch | patch
|
29
|
+
sed -i -e 's/-soname/-install_name/g' Makefile
|
30
|
+
make
|
31
|
+
sudo make install
|
32
|
+
|
33
|
+
### dxruby_sdl
|
34
|
+
|
35
|
+
Add this line to your application's Gemfile:
|
36
|
+
|
37
|
+
gem 'dxruby_sdl'
|
38
|
+
|
39
|
+
And then execute:
|
40
|
+
|
41
|
+
$ bundle
|
42
|
+
|
43
|
+
Or install it yourself as:
|
44
|
+
|
45
|
+
$ gem install dxruby_sdl
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
see http://dxruby.sourceforge.jp/ (in Japanese).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
if /darwin/ =~ RUBY_PLATFORM
|
5
|
+
task :spec do
|
6
|
+
sh "rsdl -S rspec #{ENV['SPEC_OPTS']} #{ENV['SPEC']}"
|
7
|
+
end
|
8
|
+
else
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
end
|
11
|
+
|
12
|
+
task :rubocop do
|
13
|
+
files = `git ls-files | grep -e '.rb$'`
|
14
|
+
sh "rubocop #{files.split(/\s+/m).join(' ')}"
|
15
|
+
end
|
16
|
+
|
17
|
+
task :default => [:rubocop, :spec]
|
data/dxruby_sdl.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dxruby_sdl/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dxruby_sdl'
|
8
|
+
spec.version = DXRubySDL::VERSION
|
9
|
+
spec.authors = ['Kouji Takao']
|
10
|
+
spec.email = ['kouji.takao@gmail.com']
|
11
|
+
spec.description = %q{`dxruby-sdl` is a ruby library for 2D graphics and game. It has same DXRuby API. It use SDL/Ruby.}
|
12
|
+
spec.summary = %q{2D graphics and game library}
|
13
|
+
spec.homepage = 'https://github.com/takaokouji/dxruby-sdl'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'coveralls'
|
25
|
+
spec.add_development_dependency 'travis-lint'
|
26
|
+
spec.add_development_dependency 'rubocop'
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'rubysdl'
|
29
|
+
spec.add_runtime_dependency 'rsdl' if /darwin/ =~ RUBY_PLATFORM
|
30
|
+
end
|
data/lib/dxruby.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DXRubySDL
|
4
|
+
module Color
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def to_sdl_color(color)
|
8
|
+
if color.length == 4
|
9
|
+
return color[0..2]
|
10
|
+
else
|
11
|
+
color
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_sdl_alpha(color)
|
16
|
+
if color.length == 4
|
17
|
+
return color[3]
|
18
|
+
else
|
19
|
+
return 255
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DXRubySDL
|
4
|
+
class Font
|
5
|
+
attr_reader :size
|
6
|
+
attr_reader :_ttf
|
7
|
+
|
8
|
+
def initialize(size, fontname = '', hash = {})
|
9
|
+
@size = size
|
10
|
+
|
11
|
+
if !SDL::TTF.init?
|
12
|
+
SDL::TTF.init
|
13
|
+
end
|
14
|
+
if !(path = FONTS[fontname.downcase])
|
15
|
+
path = FONTS.first.last
|
16
|
+
end
|
17
|
+
@_ttf = SDL::TTF.open(path, size)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# :nocov:
|
23
|
+
if /darwin/ =~ RUBY_PLATFORM
|
24
|
+
FONTS = {
|
25
|
+
'osaka' => '/Library/Fonts/osaka.ttf',
|
26
|
+
'IPA ゴシック' => '/Library/Fonts/ipag.ttf',
|
27
|
+
'IPA Pゴシック' => '/Library/Fonts/ipagp.ttf',
|
28
|
+
}
|
29
|
+
elsif /linux/ =~ RUBY_PLATFORM
|
30
|
+
FONTS = {
|
31
|
+
'IPA ゴシック' => '/usr/share/fonts/opentype/ipafont-gothic/ipag.ttf',
|
32
|
+
'IPA Pゴシック' => '/usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf',
|
33
|
+
}
|
34
|
+
end
|
35
|
+
# :nocov:
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module DXRubySDL
|
4
|
+
class Image
|
5
|
+
include Color
|
6
|
+
|
7
|
+
attr_reader :_surface
|
8
|
+
|
9
|
+
def initialize(width, height, color = [0, 0, 0, 0])
|
10
|
+
@color = color
|
11
|
+
|
12
|
+
if width == 0 && height == 0
|
13
|
+
return
|
14
|
+
end
|
15
|
+
|
16
|
+
@_surface =
|
17
|
+
SDL::Surface.new(SDL::SWSURFACE, width, height, Window._screen)
|
18
|
+
@_surface.fill_rect(0, 0, width, height, @color)
|
19
|
+
end
|
20
|
+
|
21
|
+
def width
|
22
|
+
return @_surface.w
|
23
|
+
end
|
24
|
+
|
25
|
+
def height
|
26
|
+
return @_surface.h
|
27
|
+
end
|
28
|
+
|
29
|
+
def line(x1, y1, x2, y2, color)
|
30
|
+
@_surface.draw_line(x1, y1, x2, y2,
|
31
|
+
to_sdl_color(color), true, to_sdl_alpha(color))
|
32
|
+
end
|
33
|
+
|
34
|
+
def circle(x, y, r, color)
|
35
|
+
@_surface.draw_circle(x, y, r, to_sdl_color(color), false, true,
|
36
|
+
to_sdl_alpha(color))
|
37
|
+
end
|
38
|
+
|
39
|
+
def box(x1, y1, x2, y2, color)
|
40
|
+
x = x1 < x2 ? x1 : x2
|
41
|
+
w = (x2 - x1).abs
|
42
|
+
y = y1 < y2 ? y1 : y2
|
43
|
+
h = (y2 - y1).abs
|
44
|
+
@_surface.draw_rect(x, y, w, h, to_sdl_color(color))
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.load(filename, x = nil, y = nil, width = nil, height = nil)
|
48
|
+
image = new(0, 0)
|
49
|
+
surface = SDL::Surface.load(filename)
|
50
|
+
image.instance_variable_set('@_surface', surface)
|
51
|
+
return image
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'singleton'
|
4
|
+
|
5
|
+
module DXRubySDL
|
6
|
+
module Window
|
7
|
+
# FPSTimer is copied from http://www.kmc.gr.jp/~ohai/fpstimer.rb.
|
8
|
+
class FPSTimer
|
9
|
+
include Singleton
|
10
|
+
|
11
|
+
FPS_COUNT = 10
|
12
|
+
|
13
|
+
attr_accessor :fps
|
14
|
+
attr_reader :real_fps, :total_skip
|
15
|
+
attr_reader :count_sleep
|
16
|
+
# +fps+ is the number of frames per second that you want to keep,
|
17
|
+
# +accurary+ is the accurary of sleep/SDL.delay in milisecond
|
18
|
+
def initialize(fps = 60, accurary = 10, skip_limit = 15)
|
19
|
+
@fps = fps
|
20
|
+
@accurary = accurary / 1000.0
|
21
|
+
@skip_limit = skip_limit
|
22
|
+
end
|
23
|
+
|
24
|
+
# reset timer, you should call just before starting loop
|
25
|
+
def reset
|
26
|
+
@old = get_ticks
|
27
|
+
@skip = 0
|
28
|
+
@real_fps = @fps
|
29
|
+
@frame_count = 0
|
30
|
+
@fps_old = @old
|
31
|
+
@count_sleep = 0
|
32
|
+
@total_skip = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
# execute given block and wait
|
36
|
+
def wait_frame
|
37
|
+
now = get_ticks
|
38
|
+
nxt = @old + (1.0 / @fps)
|
39
|
+
if nxt > now
|
40
|
+
yield
|
41
|
+
@skip = 0
|
42
|
+
wait(nxt)
|
43
|
+
@old = nxt
|
44
|
+
elsif @skip > @skip_limit
|
45
|
+
# :nocov:
|
46
|
+
yield
|
47
|
+
@skip = 0
|
48
|
+
@old = get_ticks
|
49
|
+
# :nocov:
|
50
|
+
else
|
51
|
+
# :nocov:
|
52
|
+
@skip += 1
|
53
|
+
@total_skip += 1
|
54
|
+
@old = nxt
|
55
|
+
# :nocov:
|
56
|
+
end
|
57
|
+
|
58
|
+
calc_real_fps
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def wait(nxt)
|
64
|
+
while nxt > get_ticks + @accurary
|
65
|
+
sleep(@accurary - 0.005)
|
66
|
+
@count_sleep += 1
|
67
|
+
end
|
68
|
+
|
69
|
+
while nxt > get_ticks
|
70
|
+
# busy loop, do nothing
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_ticks
|
75
|
+
SDL.getTicks / 1000.0
|
76
|
+
end
|
77
|
+
|
78
|
+
def calc_real_fps
|
79
|
+
@frame_count += 1
|
80
|
+
if @frame_count >= FPS_COUNT
|
81
|
+
# :nocov:
|
82
|
+
@frame_count = 0
|
83
|
+
now = get_ticks
|
84
|
+
@real_fps = FPS_COUNT / (now - @fps_old)
|
85
|
+
@fps_old = now
|
86
|
+
# :nocov:
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'dxruby_sdl/window/fpstimer'
|
4
|
+
|
5
|
+
module DXRubySDL
|
6
|
+
module Window
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def _screen
|
10
|
+
return SDL::Screen.get
|
11
|
+
rescue SDL::Error
|
12
|
+
return SDL::Screen.open(DEFAULTS[:width], DEFAULTS[:height], 16,
|
13
|
+
SDL::SWSURFACE)
|
14
|
+
end
|
15
|
+
|
16
|
+
def loop(&block)
|
17
|
+
_screen.fill_rect(0, 0, DEFAULTS[:width], DEFAULTS[:height],
|
18
|
+
DEFAULTS[:background_color])
|
19
|
+
_screen.update_rect(0, 0, 0, 0)
|
20
|
+
|
21
|
+
timer = FPSTimer.instance
|
22
|
+
timer.reset
|
23
|
+
|
24
|
+
Kernel.loop do
|
25
|
+
while (event = SDL::Event.poll)
|
26
|
+
case event
|
27
|
+
when SDL::Event::Quit
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
timer.wait_frame do
|
33
|
+
yield
|
34
|
+
_screen.update_rect(0, 0, 0, 0)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def draw(x, y, image, z = 0)
|
40
|
+
_screen.put(image._surface, x, y)
|
41
|
+
end
|
42
|
+
|
43
|
+
def draw_font(x, y, string, font, hash = {})
|
44
|
+
if hash[:color]
|
45
|
+
r, g, b = *hash[:color]
|
46
|
+
else
|
47
|
+
r, g, b = 255, 255, 255
|
48
|
+
end
|
49
|
+
font._ttf.draw_blended_utf8(_screen, string, x, y, r, g, b)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
DEFAULTS = {
|
55
|
+
width: 640,
|
56
|
+
height: 480,
|
57
|
+
background_color: [0, 0, 0],
|
58
|
+
}
|
59
|
+
private_constant :DEFAULTS
|
60
|
+
end
|
61
|
+
end
|
data/lib/dxruby_sdl.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DXRubySDL::Color, 'カラーを変換するモジュール' do
|
5
|
+
describe '#to_sdl_color', 'DXRubyのカラー情報をSDLのカラー情報に変換する' do
|
6
|
+
subject { described_class.to_sdl_color(color) }
|
7
|
+
|
8
|
+
expected = [0, 125, 255]
|
9
|
+
context "引数が3つの要素の配列(#{expected.inspect})の場合" do
|
10
|
+
let(:color) { [0, 125, 255] }
|
11
|
+
|
12
|
+
it { should be(color) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "引数が4つの要素の配列で最初の3つが(#{expected.inspect})の場合" do
|
16
|
+
let(:color) { expected + [0] }
|
17
|
+
|
18
|
+
it { should eq(expected) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#to_sdl_alpha', 'カラー情報からアルファ値を抽出する' do
|
23
|
+
subject { described_class.to_sdl_alpha(color) }
|
24
|
+
|
25
|
+
context '引数が3つの要素の配列の場合' do
|
26
|
+
let(:color) { [0, 125, 255] }
|
27
|
+
|
28
|
+
it '常に255を返す' do
|
29
|
+
should eq(255)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
[0, 125, 255].each do |expected|
|
34
|
+
context "引数が4つの要素の配列で最後の値が#{expected}の場合" do
|
35
|
+
let(:color) { [0, 125, 255, expected] }
|
36
|
+
|
37
|
+
it { should eq(expected) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DXRubySDL::Font, 'フォントを表すクラス' do
|
5
|
+
describe '.new' do
|
6
|
+
given = 32
|
7
|
+
context "大きさ(#{given.inspect})を指定した場合" do
|
8
|
+
subject { DXRubySDL::Font.new(given) }
|
9
|
+
|
10
|
+
its(:size) { should eq(given) }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DXRubySDL::Image, '画像を表すクラス' do
|
5
|
+
let(:image) { DXRubySDL::Image.new(640, 480) }
|
6
|
+
|
7
|
+
describe '.new' do
|
8
|
+
context '幅と高さを指定した場合' do
|
9
|
+
subject { image }
|
10
|
+
|
11
|
+
its(:width) { should eq(640) }
|
12
|
+
its(:height) { should eq(480) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.load' do
|
17
|
+
subject {
|
18
|
+
path = File.expand_path("../../fixtures/#{filename}", __FILE__)
|
19
|
+
DXRubySDL::Image.load(path)
|
20
|
+
}
|
21
|
+
|
22
|
+
context 'PNG形式のファイルの場合' do
|
23
|
+
let(:filename) { 'logo.png' }
|
24
|
+
|
25
|
+
its(:width) { should eq(518) }
|
26
|
+
its(:height) { should eq(232) }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'JPG形式のファイルの場合' do
|
30
|
+
let(:filename) { 'logo.jpg' }
|
31
|
+
|
32
|
+
its(:width) { should eq(518) }
|
33
|
+
its(:height) { should eq(232) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#line' do
|
38
|
+
it '呼び出すことができる' do
|
39
|
+
image.line(0, 0, 100, 100, [255, 255, 255])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#circle' do
|
44
|
+
it '呼び出すことができる' do
|
45
|
+
image.circle(50, 50, 25, [255, 255, 255])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#box' do
|
50
|
+
it '呼び出すことができる' do
|
51
|
+
image.box(0, 0, 100, 100, [255, 255, 255])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DXRubySDL::Window do
|
5
|
+
context 'デフォルトの設定の場合' do
|
6
|
+
default = {
|
7
|
+
width: 640,
|
8
|
+
height: 480,
|
9
|
+
background_color: [0, 0, 0],
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:width) { default[:width] }
|
13
|
+
let(:height) { default[:height] }
|
14
|
+
let(:background_color) { default[:background_color] }
|
15
|
+
|
16
|
+
describe '.loop', 'メインループ' do
|
17
|
+
it "サイズが#{default[:width]}x#{default[:height]}、" \
|
18
|
+
"背景がRGB(#{default[:background_color].join(", ")})の" \
|
19
|
+
"ウィンドウを表示して、ESCキーを入力するまで待つ" do
|
20
|
+
expect {
|
21
|
+
DXRubySDL::Window.loop do
|
22
|
+
SDL::Event.push(SDL::Event::Quit.new)
|
23
|
+
end
|
24
|
+
}.to raise_error(SystemExit)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.draw', 'Imageオブジェクトを描画する' do
|
29
|
+
subject do
|
30
|
+
expect {
|
31
|
+
DXRubySDL::Window.loop do
|
32
|
+
DXRubySDL::Window.draw(0, 0, image)
|
33
|
+
SDL::Event.push(SDL::Event::Quit.new)
|
34
|
+
end
|
35
|
+
}.to raise_error(SystemExit)
|
36
|
+
end
|
37
|
+
|
38
|
+
context '(0, 0)-(100,100)の白い線を描いたImageオブジェクトを指定した場合' do
|
39
|
+
let!(:image) {
|
40
|
+
i = DXRubySDL::Image.new(640, 480)
|
41
|
+
i.line(0, 0, 100, 100, [255, 255, 255])
|
42
|
+
i
|
43
|
+
}
|
44
|
+
|
45
|
+
it '白い線を描画する' do
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context '(0, 0)-(100,100)の矩形を描いたImageオブジェクトを指定した場合' do
|
51
|
+
let!(:image) {
|
52
|
+
i = DXRubySDL::Image.new(640, 480)
|
53
|
+
i.box(0, 0, 100, 100, [255, 255, 255])
|
54
|
+
i
|
55
|
+
}
|
56
|
+
|
57
|
+
it '矩形を描画する' do
|
58
|
+
subject
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context '(50, 50)、半径25の円を描いたImageオブジェクトを指定した場合' do
|
63
|
+
let!(:image) {
|
64
|
+
i = DXRubySDL::Image.new(640, 480)
|
65
|
+
i.circle(50, 50, 25, [255, 255, 255])
|
66
|
+
i
|
67
|
+
}
|
68
|
+
|
69
|
+
it '円を描画する' do
|
70
|
+
subject
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context '画像を読み込んだImageオブジェクトを指定した場合' do
|
75
|
+
it '画像を描画する' do
|
76
|
+
expect {
|
77
|
+
path = File.expand_path('../../fixtures/logo.png', __FILE__)
|
78
|
+
i = DXRubySDL::Image.load(path)
|
79
|
+
DXRubySDL::Window.loop do
|
80
|
+
DXRubySDL::Window.draw(0, 0, i)
|
81
|
+
SDL::Event.push(SDL::Event::Quit.new)
|
82
|
+
end
|
83
|
+
}.to raise_error(SystemExit)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '.draw_font', '文字列を描画する' do
|
89
|
+
context 'サイズのみを設定したフォントを指定した場合' do
|
90
|
+
let!(:font) { DXRubySDL::Font.new(32) }
|
91
|
+
let(:args) { [0, 0, 'やあ', font] }
|
92
|
+
|
93
|
+
subject do
|
94
|
+
expect {
|
95
|
+
DXRubySDL::Window.loop do
|
96
|
+
DXRubySDL::Window.draw_font(*args)
|
97
|
+
SDL::Event.push(SDL::Event::Quit.new)
|
98
|
+
end
|
99
|
+
}.to raise_error(SystemExit)
|
100
|
+
end
|
101
|
+
|
102
|
+
it '文字列を描画する' do
|
103
|
+
subject
|
104
|
+
end
|
105
|
+
|
106
|
+
hash = { color: [255, 0, 0] }
|
107
|
+
context "第5引数に色(#{hash.inspect})を指定した場合" do
|
108
|
+
let(:args) { [0, 0, 'やあ', font, hash] }
|
109
|
+
|
110
|
+
it '文字列を描画する' do
|
111
|
+
subject
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe DXRubySDL do
|
5
|
+
describe '::VERSION' do
|
6
|
+
subject { described_class::VERSION }
|
7
|
+
|
8
|
+
it { should be_instance_of(String) }
|
9
|
+
it { should match(/\A[0-9]\.[0-9]+\.[0-9]+\z/) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'require \'dxruby\'' do
|
13
|
+
before do
|
14
|
+
require 'dxruby'
|
15
|
+
end
|
16
|
+
|
17
|
+
%w[
|
18
|
+
Window
|
19
|
+
Image
|
20
|
+
Font
|
21
|
+
].each do |klass_name|
|
22
|
+
it "トップレベルに#{klass_name}が定義されている" do
|
23
|
+
expect {
|
24
|
+
# rubocop:disable Eval
|
25
|
+
eval("::#{klass_name}")
|
26
|
+
# rubocop:enable Eval
|
27
|
+
}.not_to raise_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
Binary file
|
Binary file
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,192 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dxruby_sdl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kouji Takao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: travis-lint
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubysdl
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rsdl
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: ! '`dxruby-sdl` is a ruby library for 2D graphics and game. It has same
|
126
|
+
DXRuby API. It use SDL/Ruby.'
|
127
|
+
email:
|
128
|
+
- kouji.takao@gmail.com
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- .gitignore
|
134
|
+
- .rspec
|
135
|
+
- .rubocop.yml
|
136
|
+
- .ruby-version
|
137
|
+
- .travis.yml
|
138
|
+
- Gemfile
|
139
|
+
- LEGAL
|
140
|
+
- LICENSE
|
141
|
+
- README.md
|
142
|
+
- Rakefile
|
143
|
+
- dxruby_sdl.gemspec
|
144
|
+
- lib/dxruby.rb
|
145
|
+
- lib/dxruby_sdl.rb
|
146
|
+
- lib/dxruby_sdl/color.rb
|
147
|
+
- lib/dxruby_sdl/font.rb
|
148
|
+
- lib/dxruby_sdl/image.rb
|
149
|
+
- lib/dxruby_sdl/version.rb
|
150
|
+
- lib/dxruby_sdl/window.rb
|
151
|
+
- lib/dxruby_sdl/window/fpstimer.rb
|
152
|
+
- spec/dxruby_sdl/color_spec.rb
|
153
|
+
- spec/dxruby_sdl/font_spec.rb
|
154
|
+
- spec/dxruby_sdl/image_spec.rb
|
155
|
+
- spec/dxruby_sdl/window_spec.rb
|
156
|
+
- spec/dxruby_sdl_spec.rb
|
157
|
+
- spec/fixtures/logo.jpg
|
158
|
+
- spec/fixtures/logo.png
|
159
|
+
- spec/spec_helper.rb
|
160
|
+
homepage: https://github.com/takaokouji/dxruby-sdl
|
161
|
+
licenses:
|
162
|
+
- MIT
|
163
|
+
metadata: {}
|
164
|
+
post_install_message:
|
165
|
+
rdoc_options: []
|
166
|
+
require_paths:
|
167
|
+
- lib
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ! '>='
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ! '>='
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
requirements: []
|
179
|
+
rubyforge_project:
|
180
|
+
rubygems_version: 2.0.7
|
181
|
+
signing_key:
|
182
|
+
specification_version: 4
|
183
|
+
summary: 2D graphics and game library
|
184
|
+
test_files:
|
185
|
+
- spec/dxruby_sdl/color_spec.rb
|
186
|
+
- spec/dxruby_sdl/font_spec.rb
|
187
|
+
- spec/dxruby_sdl/image_spec.rb
|
188
|
+
- spec/dxruby_sdl/window_spec.rb
|
189
|
+
- spec/dxruby_sdl_spec.rb
|
190
|
+
- spec/fixtures/logo.jpg
|
191
|
+
- spec/fixtures/logo.png
|
192
|
+
- spec/spec_helper.rb
|