ruby2d 0.2.0 → 0.2.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 +4 -4
- data/ext/ruby2d/extconf.rb +51 -52
- data/ext/ruby2d/ruby2d.c +10 -9
- data/lib/ruby2d/text.rb +14 -13
- data/lib/ruby2d/version.rb +1 -1
- data/lib/ruby2d/window.rb +9 -10
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52638279e5a91e2a8143e0a9485e0889d784757a
|
4
|
+
data.tar.gz: e3ed2e07e45e3a7ba53a7a8dae3ab625be09a444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00cf4e903c49e0cc3889a6cd8f6452d99773ba8b8af74c3d6d150c17bf552045745a96b0a477a1330c682f7bd3f9ce5c3bff7f179b0068f081a88f9a8a7d1fd9
|
7
|
+
data.tar.gz: f07cbe0a69a6c75209c24e1f4f514aa4d994ca678d3ac2371aae7fcfda08ebb529c4684abc55f85c9ea47d02c3b60043e787db08b3cc70138de79e50236cb169
|
data/ext/ruby2d/extconf.rb
CHANGED
@@ -1,84 +1,83 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
+
S2D_VERSION = '0.2.1' # Minimum Simple 2D version required
|
4
|
+
$errors = []
|
5
|
+
|
3
6
|
class String
|
4
7
|
def colorize(c); "\e[#{c}m#{self}\e[0m" end
|
5
|
-
def
|
6
|
-
def
|
8
|
+
def bold; colorize('1') end
|
9
|
+
def red; colorize('1;31') end
|
7
10
|
end
|
8
11
|
|
9
|
-
def print_errors
|
12
|
+
def print_errors
|
10
13
|
puts "
|
11
|
-
#{"== Ruby 2D Installation Errors
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
#{"== #{"Ruby 2D Installation Errors".red} =====================================\n"}
|
15
|
+
#{$errors.join("\n ")}\n
|
16
|
+
#{"===================================================================="}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def check_s2d_version
|
20
|
+
unless Gem::Version.new(`simple2d --version`) >= Gem::Version.new(S2D_VERSION)
|
21
|
+
$errors << "Simple 2D needs to be updated for this version of Ruby 2D." <<
|
22
|
+
"Run the following, then try reinstalling this gem:\n" <<
|
23
|
+
" simple2d update".bold
|
24
|
+
print_errors
|
25
|
+
exit
|
26
|
+
end
|
18
27
|
end
|
19
28
|
|
20
|
-
errors = []
|
21
29
|
|
22
30
|
# Install Simple 2D on supported platforms
|
23
31
|
|
24
32
|
# OS X
|
25
33
|
if RUBY_PLATFORM =~ /darwin/
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
`brew install simple2d`
|
41
|
-
end
|
34
|
+
|
35
|
+
# Simple 2D not installed
|
36
|
+
if `which simple2d`.empty?
|
37
|
+
|
38
|
+
# Homebrew not installed
|
39
|
+
if `which brew`.empty?
|
40
|
+
$errors << "Ruby 2D uses a native library called Simple 2D." <<
|
41
|
+
"On OS X, this can be installed using Homebrew.\n" <<
|
42
|
+
"First, install #{"Homebrew".bold}. See instructions at #{"http://brew.sh".bold}" <<
|
43
|
+
"Then, run the following:\n" <<
|
44
|
+
" brew tap simple2d/tap".bold <<
|
45
|
+
" brew install simple2d".bold
|
46
|
+
print_errors
|
47
|
+
exit
|
42
48
|
|
43
|
-
#
|
49
|
+
# Homebrew installed, instruct to install Simple 2D
|
44
50
|
else
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# `brew update`
|
52
|
-
# `brew upgrade simple2d`
|
53
|
-
|
54
|
-
`brew untap simple2d/tap`
|
55
|
-
`brew tap simple2d/tap`
|
56
|
-
`brew upgrade simple2d`
|
57
|
-
end
|
51
|
+
$errors << "Ruby 2D uses a native library called Simple 2D." <<
|
52
|
+
"Install with Homebrew using:\n" <<
|
53
|
+
" brew tap simple2d/tap".bold <<
|
54
|
+
" brew install simple2d".bold
|
55
|
+
print_errors
|
56
|
+
exit
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
60
|
# Linux
|
62
61
|
elsif RUBY_PLATFORM =~ /linux/
|
63
|
-
|
62
|
+
|
63
|
+
# Simple 2D not installed
|
64
64
|
if `which simple2d`.empty?
|
65
|
-
errors << "Ruby 2D uses a library called Simple 2D
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
print_errors(errors)
|
65
|
+
$errors << "Ruby 2D uses a native library called Simple 2D.\n" <<
|
66
|
+
"To install Simple 2D on Linux, follow the instructions" <<
|
67
|
+
"in the README: #{"https://github.com/simple2d/simple2d".bold}"
|
68
|
+
print_errors
|
70
69
|
exit
|
71
70
|
end
|
72
71
|
|
73
|
-
|
74
|
-
elsif RUBY_PLATFORM =~ /mingw/
|
75
|
-
puts "Ruby 2D doesn't support Windows yet :("
|
76
|
-
exit
|
72
|
+
$CFLAGS << ' -std=c99'
|
77
73
|
end
|
78
74
|
|
75
|
+
# Simple 2D installed, check version
|
76
|
+
check_s2d_version
|
77
|
+
|
79
78
|
# Configure Simple 2D and create Makefile
|
80
79
|
|
81
80
|
$LDFLAGS << ' ' << `simple2d --libs`
|
82
|
-
$LDFLAGS.gsub!(/\n/, ' ') #
|
81
|
+
$LDFLAGS.gsub!(/\n/, ' ') # Remove newlines in flags, they cause problems
|
83
82
|
|
84
83
|
create_makefile('ruby2d/ruby2d')
|
data/ext/ruby2d/ruby2d.c
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
VALUE self;
|
12
12
|
|
13
13
|
// Simple 2D window
|
14
|
-
|
14
|
+
S2D_Window *window;
|
15
15
|
|
16
16
|
// Ruby data types
|
17
17
|
static VALUE ruby2d_module;
|
@@ -20,13 +20,13 @@ static VALUE c_data_klass;
|
|
20
20
|
|
21
21
|
// Structures for Ruby 2D classes
|
22
22
|
struct image_data {
|
23
|
-
|
23
|
+
S2D_Image *img;
|
24
24
|
};
|
25
25
|
struct text_data {
|
26
|
-
|
26
|
+
S2D_Text *txt;
|
27
27
|
};
|
28
28
|
struct sound_data {
|
29
|
-
|
29
|
+
S2D_Sound *snd;
|
30
30
|
};
|
31
31
|
|
32
32
|
|
@@ -215,8 +215,8 @@ void render() {
|
|
215
215
|
struct image_data *data;
|
216
216
|
Data_Get_Struct(rb_iv_get(el, "@data"), struct image_data, data);
|
217
217
|
|
218
|
-
data->img
|
219
|
-
data->img
|
218
|
+
data->img->x = NUM2DBL(rb_iv_get(el, "@x"));
|
219
|
+
data->img->y = NUM2DBL(rb_iv_get(el, "@y"));
|
220
220
|
S2D_DrawImage(data->img);
|
221
221
|
}
|
222
222
|
break;
|
@@ -234,8 +234,8 @@ void render() {
|
|
234
234
|
struct text_data *data;
|
235
235
|
Data_Get_Struct(rb_iv_get(el, "@data"), struct text_data, data);
|
236
236
|
|
237
|
-
data->txt
|
238
|
-
data->txt
|
237
|
+
data->txt->x = NUM2DBL(rb_iv_get(el, "@x"));
|
238
|
+
data->txt->y = NUM2DBL(rb_iv_get(el, "@y"));
|
239
239
|
S2D_DrawText(data->txt);
|
240
240
|
}
|
241
241
|
break;
|
@@ -253,9 +253,10 @@ static VALUE ruby2d_show(VALUE s) {
|
|
253
253
|
char *title = RSTRING_PTR(rb_iv_get(self, "@title"));
|
254
254
|
int width = NUM2INT(rb_iv_get(self, "@width"));
|
255
255
|
int height = NUM2INT(rb_iv_get(self, "@height"));
|
256
|
+
int flags = 0;
|
256
257
|
|
257
258
|
window = S2D_CreateWindow(
|
258
|
-
title, width, height, update, render,
|
259
|
+
title, width, height, update, render, flags
|
259
260
|
);
|
260
261
|
|
261
262
|
window->on_key = on_key;
|
data/lib/ruby2d/text.rb
CHANGED
@@ -5,20 +5,17 @@ module Ruby2D
|
|
5
5
|
|
6
6
|
attr_accessor :x, :y, :size, :text
|
7
7
|
|
8
|
-
def initialize(x=0, y=0, size=20,
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
else
|
13
|
-
@font = font
|
14
|
-
end
|
8
|
+
def initialize(x=0, y=0, size=20, msg="Hello World!", font="Arial", c="white")
|
9
|
+
|
10
|
+
if File.exists? font
|
11
|
+
@font = font
|
15
12
|
else
|
16
13
|
@font = resolve_path(font)
|
17
14
|
end
|
18
15
|
|
19
16
|
@type_id = 4
|
20
17
|
@x, @y, @size = x, y, size
|
21
|
-
@text, @color =
|
18
|
+
@text, @color = msg, c
|
22
19
|
update_color(c)
|
23
20
|
|
24
21
|
if defined? Ruby2D::DSL
|
@@ -44,14 +41,18 @@ module Ruby2D
|
|
44
41
|
private
|
45
42
|
|
46
43
|
def resolve_path(font)
|
47
|
-
# TODO: Consider CSS names, like 'serif', 'san-serif', 'monospace'
|
48
44
|
if RUBY_PLATFORM =~ /darwin/
|
49
45
|
font_path = "/Library/Fonts/#{font}.ttf"
|
50
|
-
|
51
|
-
|
52
|
-
|
46
|
+
else
|
47
|
+
# Linux
|
48
|
+
font_path = "/usr/share/fonts/truetype/#{font}.ttf"
|
49
|
+
end
|
50
|
+
|
51
|
+
unless File.exists? font_path
|
52
|
+
raise Error, "Cannot find system font"
|
53
|
+
else
|
54
|
+
font_path
|
53
55
|
end
|
54
|
-
font_path
|
55
56
|
end
|
56
57
|
|
57
58
|
def update_color(c)
|
data/lib/ruby2d/version.rb
CHANGED
data/lib/ruby2d/window.rb
CHANGED
@@ -38,16 +38,15 @@ module Ruby2D
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def set(opts)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
@
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
@height = opts[:height]
|
41
|
+
valid_keys = [:title, :width, :height]
|
42
|
+
valid_opts = opts.reject { |k| !valid_keys.include?(k) }
|
43
|
+
if !valid_opts.empty?
|
44
|
+
@title = valid_opts[:title]
|
45
|
+
@width = valid_opts[:width]
|
46
|
+
@height = valid_opts[:height]
|
47
|
+
return true
|
48
|
+
else
|
49
|
+
return false
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Black
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -70,8 +70,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
72
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.
|
73
|
+
rubygems_version: 2.6.3
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Ruby 2D
|
77
77
|
test_files: []
|
78
|
+
has_rdoc:
|