ruby2d 0.5.1 → 0.6.0
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/bin/ruby2d +15 -11
- data/ext/ruby2d/extconf.rb +2 -2
- data/ext/ruby2d/ruby2d-opal.rb +1 -1
- data/ext/ruby2d/ruby2d.c +92 -34
- data/lib/ruby2d.rb +2 -2
- data/lib/ruby2d/circle.rb +29 -0
- data/lib/ruby2d/color.rb +14 -13
- data/lib/ruby2d/dsl.rb +12 -9
- data/lib/ruby2d/exceptions.rb +1 -1
- data/lib/ruby2d/image.rb +5 -4
- data/lib/ruby2d/line.rb +9 -5
- data/lib/ruby2d/music.rb +8 -2
- data/lib/ruby2d/quad.rb +6 -6
- data/lib/ruby2d/rectangle.rb +6 -8
- data/lib/ruby2d/renderable.rb +25 -9
- data/lib/ruby2d/sound.rb +3 -2
- data/lib/ruby2d/sprite.rb +200 -61
- data/lib/ruby2d/square.rb +4 -4
- data/lib/ruby2d/text.rb +4 -4
- data/lib/ruby2d/triangle.rb +4 -4
- data/lib/ruby2d/version.rb +2 -2
- data/lib/ruby2d/window.rb +153 -24
- metadata +6 -8
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcuserdata/Tom.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/assets/ios/MyApp.xcodeproj/xcuserdata/Tom.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
- data/lib/ruby2d/application.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbdaa086d718eacee3d9af77fd86b464ebf8cbb4db4bfbf796663c6fbbbd491c
|
4
|
+
data.tar.gz: 6167710b57e59b5635b3818687ca94175b98ab7d05c94bbd55d9fbf6744f299b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8e81e3f9313feaeda6e45e24b06c8bcf7c4e1436635dc06ea8504448a6f8734174c3c2c55fc6678ff2e48522aebe1bd8e6d9ab8aa670da683373473f7f8270
|
7
|
+
data.tar.gz: 4f31cf8d067c851de3a043a7716803e42c37bb4144a55087fce61b2270e53dc94130a3e87b6943b7e07625b4024c7640a9c357bbc5d15253cda8adacd1e95d74
|
data/bin/ruby2d
CHANGED
@@ -18,10 +18,10 @@ end
|
|
18
18
|
'exceptions',
|
19
19
|
'color',
|
20
20
|
'window',
|
21
|
-
'application',
|
22
21
|
'dsl',
|
23
22
|
'quad',
|
24
23
|
'line',
|
24
|
+
'circle',
|
25
25
|
'rectangle',
|
26
26
|
'square',
|
27
27
|
'triangle',
|
@@ -60,8 +60,8 @@ def make_lib
|
|
60
60
|
end
|
61
61
|
|
62
62
|
lib << "
|
63
|
-
include Ruby2D
|
64
|
-
|
63
|
+
include Ruby2D
|
64
|
+
extend Ruby2D::DSL\n"
|
65
65
|
|
66
66
|
File.write('build/lib.rb', lib)
|
67
67
|
end
|
@@ -87,13 +87,16 @@ def build_native(rb_file)
|
|
87
87
|
exit
|
88
88
|
end
|
89
89
|
|
90
|
+
# Add debugging information to produce backtrace
|
91
|
+
if @debug then debug_flag = '-g' end
|
92
|
+
|
90
93
|
# Assemble the Ruby 2D library in one `.rb` file and compile to bytecode
|
91
94
|
make_lib
|
92
|
-
`mrbc -Bruby2d_lib -obuild/lib.c build/lib.rb`
|
95
|
+
`mrbc #{debug_flag} -Bruby2d_lib -obuild/lib.c build/lib.rb`
|
93
96
|
|
94
97
|
# Read the provided Ruby source file, copy to build dir and compile to bytecode
|
95
98
|
File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
|
96
|
-
`mrbc -Bruby2d_app -obuild/src.c build/src.rb`
|
99
|
+
`mrbc #{debug_flag} -Bruby2d_app -obuild/src.c build/src.rb`
|
97
100
|
|
98
101
|
# Combine contents of C source files and bytecode into one file
|
99
102
|
open('build/app.c', 'w') do |f|
|
@@ -165,13 +168,16 @@ def build_apple(rb_file, device)
|
|
165
168
|
exit
|
166
169
|
end
|
167
170
|
|
171
|
+
# Add debugging information to produce backtrace
|
172
|
+
if @debug then debug_flag = '-g' end
|
173
|
+
|
168
174
|
# Assemble the Ruby 2D library in one `.rb` file and compile to bytecode
|
169
175
|
make_lib
|
170
|
-
`mrbc -Bruby2d_lib -obuild/lib.c build/lib.rb`
|
176
|
+
`mrbc #{debug_flag} -Bruby2d_lib -obuild/lib.c build/lib.rb`
|
171
177
|
|
172
178
|
# Read the provided Ruby source file, copy to build dir and compile to bytecode
|
173
179
|
File.open('build/src.rb', 'w') { |file| file << strip_require(rb_file) }
|
174
|
-
`mrbc -Bruby2d_app -obuild/src.c build/src.rb`
|
180
|
+
`mrbc #{debug_flag} -Bruby2d_app -obuild/src.c build/src.rb`
|
175
181
|
|
176
182
|
# Copy over iOS project
|
177
183
|
FileUtils.cp_r "#{@gem_dir}/assets/#{device}", "build"
|
@@ -249,7 +255,7 @@ def launch_apple(device)
|
|
249
255
|
puts "No iOS app built!"
|
250
256
|
exit
|
251
257
|
end
|
252
|
-
puts `simple2d simulator --open "iPhone
|
258
|
+
puts `simple2d simulator --open "iPhone XR" &&
|
253
259
|
simple2d simulator --install "build/ios/build/Release-iphonesimulator/MyApp.app" &&
|
254
260
|
simple2d simulator --launch "Ruby2D.MyApp"`
|
255
261
|
when 'tvos'
|
@@ -257,7 +263,7 @@ def launch_apple(device)
|
|
257
263
|
puts "No tvOS app built!"
|
258
264
|
exit
|
259
265
|
end
|
260
|
-
puts `simple2d simulator --open "Apple TV" &&
|
266
|
+
puts `simple2d simulator --open "Apple TV 4K" &&
|
261
267
|
simple2d simulator --install "build/tvos/build/Release-appletvsimulator/MyApp.app" &&
|
262
268
|
simple2d simulator --launch "Ruby2D.MyApp"`
|
263
269
|
end
|
@@ -325,8 +331,6 @@ Choose an option with the #{"simulator".bold} command:
|
|
325
331
|
--log <app> Stream log for the app only, given the app name
|
326
332
|
--log-errors Stream log containing only error messages\n\n"
|
327
333
|
|
328
|
-
# puts ARGV.inspect
|
329
|
-
|
330
334
|
case ARGV[0]
|
331
335
|
when 'build'
|
332
336
|
if ARGV.delete '--debug' then @debug = true end
|
data/ext/ruby2d/extconf.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
-
S2D_VERSION = '0.
|
3
|
+
S2D_VERSION = '1.0.1' # Simple 2D minimum version required
|
4
4
|
$errors = []
|
5
5
|
|
6
6
|
class String
|
@@ -76,6 +76,6 @@ check_s2d_version
|
|
76
76
|
# Add flags
|
77
77
|
$CFLAGS << ' -std=c11 -I/usr/local/include'
|
78
78
|
$LDFLAGS << ' ' << `bash simple2d --libs`
|
79
|
-
$LDFLAGS.gsub!(/\n/, ' ') #
|
79
|
+
$LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they cause problems
|
80
80
|
|
81
81
|
create_makefile('ruby2d/ruby2d')
|
data/ext/ruby2d/ruby2d-opal.rb
CHANGED
data/ext/ruby2d/ruby2d.c
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
//
|
1
|
+
// Native C extension for Ruby and MRuby
|
2
2
|
|
3
3
|
// Simple 2D includes
|
4
4
|
#if RUBY2D_IOS_TVOS
|
@@ -62,8 +62,8 @@
|
|
62
62
|
#define r_ary_entry(ary, pos) mrb_ary_entry(ary, pos)
|
63
63
|
#define r_data_wrap_struct(name, data) mrb_obj_value(Data_Wrap_Struct(mrb, mrb->object_class, &name##_data_type, data))
|
64
64
|
#define r_data_get_struct(self, var, mrb_type, rb_type, data) Data_Get_Struct(mrb, r_iv_get(self, var), mrb_type, data)
|
65
|
-
#define r_define_module(name)
|
66
|
-
#define r_define_class(module, name)
|
65
|
+
#define r_define_module(name) mrb_define_module(mrb, name)
|
66
|
+
#define r_define_class(module, name) mrb_define_class_under(mrb, module, name, mrb->object_class)
|
67
67
|
#define r_define_method(class, name, function, args) mrb_define_method(mrb, class, name, function, args)
|
68
68
|
#define r_args_none (MRB_ARGS_NONE())
|
69
69
|
#define r_args_req(n) MRB_ARGS_REQ(n)
|
@@ -152,18 +152,6 @@ double normalize_controller_axis(int val) {
|
|
152
152
|
}
|
153
153
|
|
154
154
|
|
155
|
-
/*
|
156
|
-
* File#exists? for MRuby
|
157
|
-
*/
|
158
|
-
#if MRUBY
|
159
|
-
static R_VAL file_exists(mrb_state* mrb, R_VAL self) {
|
160
|
-
mrb_value path;
|
161
|
-
mrb_get_args(mrb, "o", &path);
|
162
|
-
return S2D_FileExists(RSTRING_PTR(path)) ? R_TRUE : R_FALSE;
|
163
|
-
}
|
164
|
-
#endif
|
165
|
-
|
166
|
-
|
167
155
|
/*
|
168
156
|
* Ruby2D::Triangle#ext_render
|
169
157
|
*/
|
@@ -295,6 +283,31 @@ static R_VAL ruby2d_line_ext_render(R_VAL self) {
|
|
295
283
|
}
|
296
284
|
|
297
285
|
|
286
|
+
/*
|
287
|
+
* Ruby2D::Circle#ext_render
|
288
|
+
*/
|
289
|
+
#if MRUBY
|
290
|
+
static R_VAL ruby2d_circle_ext_render(mrb_state* mrb, R_VAL self) {
|
291
|
+
#else
|
292
|
+
static R_VAL ruby2d_circle_ext_render(R_VAL self) {
|
293
|
+
#endif
|
294
|
+
R_VAL c = r_iv_get(self, "@color");
|
295
|
+
|
296
|
+
S2D_DrawCircle(
|
297
|
+
NUM2DBL(r_iv_get(self, "@x")),
|
298
|
+
NUM2DBL(r_iv_get(self, "@y")),
|
299
|
+
NUM2DBL(r_iv_get(self, "@radius")),
|
300
|
+
NUM2DBL(r_iv_get(self, "@sectors")),
|
301
|
+
NUM2DBL(r_iv_get(c, "@r")),
|
302
|
+
NUM2DBL(r_iv_get(c, "@g")),
|
303
|
+
NUM2DBL(r_iv_get(c, "@b")),
|
304
|
+
NUM2DBL(r_iv_get(c, "@a"))
|
305
|
+
);
|
306
|
+
|
307
|
+
return R_NIL;
|
308
|
+
}
|
309
|
+
|
310
|
+
|
298
311
|
/*
|
299
312
|
* Ruby2D::Image#ext_init
|
300
313
|
* Initialize image structure data
|
@@ -340,6 +353,8 @@ static R_VAL ruby2d_image_ext_render(R_VAL self) {
|
|
340
353
|
if (r_test(w)) img->width = NUM2INT(w);
|
341
354
|
if (r_test(h)) img->height = NUM2INT(h);
|
342
355
|
|
356
|
+
S2D_RotateImage(img, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER);
|
357
|
+
|
343
358
|
R_VAL c = r_iv_get(self, "@color");
|
344
359
|
img->color.r = NUM2DBL(r_iv_get(c, "@r"));
|
345
360
|
img->color.g = NUM2DBL(r_iv_get(c, "@g"));
|
@@ -361,7 +376,7 @@ static void free_image(mrb_state *mrb, void *p_) {
|
|
361
376
|
#else
|
362
377
|
static void free_image(S2D_Image *img) {
|
363
378
|
#endif
|
364
|
-
S2D_Log(S2D_INFO, "Free image
|
379
|
+
S2D_Log(S2D_INFO, "Free image `%s` at %i, %i", img->path, img->x, img->y);
|
365
380
|
S2D_FreeImage(img);
|
366
381
|
}
|
367
382
|
|
@@ -379,7 +394,11 @@ static R_VAL ruby2d_sprite_ext_init(R_VAL self, R_VAL path) {
|
|
379
394
|
#endif
|
380
395
|
S2D_Log(S2D_INFO, "Init sprite: %s", RSTRING_PTR(path));
|
381
396
|
S2D_Sprite *spr = S2D_CreateSprite(RSTRING_PTR(path));
|
397
|
+
|
398
|
+
r_iv_set(self, "@img_width" , INT2NUM(spr->width));
|
399
|
+
r_iv_set(self, "@img_height", INT2NUM(spr->height));
|
382
400
|
r_iv_set(self, "@data", r_data_wrap_struct(sprite, spr));
|
401
|
+
|
383
402
|
return R_NIL;
|
384
403
|
}
|
385
404
|
|
@@ -392,18 +411,28 @@ static R_VAL ruby2d_sprite_ext_render(mrb_state* mrb, R_VAL self) {
|
|
392
411
|
#else
|
393
412
|
static R_VAL ruby2d_sprite_ext_render(R_VAL self) {
|
394
413
|
#endif
|
414
|
+
r_funcall(self, "update", 0);
|
415
|
+
|
395
416
|
S2D_Sprite *spr;
|
396
417
|
r_data_get_struct(self, "@data", &sprite_data_type, S2D_Sprite, spr);
|
397
418
|
|
398
|
-
spr->x = NUM2DBL(r_iv_get(self, "@
|
399
|
-
spr->y = NUM2DBL(r_iv_get(self, "@
|
419
|
+
spr->x = NUM2DBL(r_iv_get(self, "@flip_x"));
|
420
|
+
spr->y = NUM2DBL(r_iv_get(self, "@flip_y"));
|
421
|
+
|
422
|
+
R_VAL w = r_iv_get(self, "@flip_width");
|
423
|
+
if (r_test(w)) spr->width = NUM2DBL(w);
|
424
|
+
|
425
|
+
R_VAL h = r_iv_get(self, "@flip_height");
|
426
|
+
if (r_test(h)) spr->height = NUM2DBL(h);
|
427
|
+
|
428
|
+
S2D_RotateSprite(spr, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER);
|
400
429
|
|
401
430
|
S2D_ClipSprite(
|
402
431
|
spr,
|
403
432
|
NUM2INT(r_iv_get(self, "@clip_x")),
|
404
433
|
NUM2INT(r_iv_get(self, "@clip_y")),
|
405
|
-
NUM2INT(r_iv_get(self, "@
|
406
|
-
NUM2INT(r_iv_get(self, "@
|
434
|
+
NUM2INT(r_iv_get(self, "@clip_width")),
|
435
|
+
NUM2INT(r_iv_get(self, "@clip_height"))
|
407
436
|
);
|
408
437
|
|
409
438
|
S2D_DrawSprite(spr);
|
@@ -421,7 +450,7 @@ static void free_sprite(mrb_state *mrb, void *p_) {
|
|
421
450
|
#else
|
422
451
|
static void free_sprite(S2D_Sprite *spr) {
|
423
452
|
#endif
|
424
|
-
S2D_Log(S2D_INFO, "Free sprite
|
453
|
+
S2D_Log(S2D_INFO, "Free sprite `%s` at %i, %i", spr->path, spr->x, spr->y);
|
425
454
|
S2D_FreeSprite(spr);
|
426
455
|
}
|
427
456
|
|
@@ -487,6 +516,8 @@ static R_VAL ruby2d_text_ext_render(R_VAL self) {
|
|
487
516
|
txt->x = NUM2DBL(r_iv_get(self, "@x"));
|
488
517
|
txt->y = NUM2DBL(r_iv_get(self, "@y"));
|
489
518
|
|
519
|
+
S2D_RotateText(txt, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER);
|
520
|
+
|
490
521
|
R_VAL c = r_iv_get(self, "@color");
|
491
522
|
txt->color.r = NUM2DBL(r_iv_get(c, "@r"));
|
492
523
|
txt->color.g = NUM2DBL(r_iv_get(c, "@g"));
|
@@ -508,7 +539,7 @@ static void free_text(mrb_state *mrb, void *p_) {
|
|
508
539
|
#else
|
509
540
|
static void free_text(S2D_Text *txt) {
|
510
541
|
#endif
|
511
|
-
S2D_Log(S2D_INFO, "Free text
|
542
|
+
S2D_Log(S2D_INFO, "Free text \"%s\" with font `%s`", txt->msg, txt->font);
|
512
543
|
S2D_FreeText(txt);
|
513
544
|
}
|
514
545
|
|
@@ -555,7 +586,7 @@ static void free_sound(mrb_state *mrb, void *p_) {
|
|
555
586
|
#else
|
556
587
|
static void free_sound(S2D_Sound *snd) {
|
557
588
|
#endif
|
558
|
-
S2D_Log(S2D_INFO, "Free sound");
|
589
|
+
S2D_Log(S2D_INFO, "Free sound `%s`", snd->path);
|
559
590
|
S2D_FreeSound(snd);
|
560
591
|
}
|
561
592
|
|
@@ -656,7 +687,7 @@ static void free_music(mrb_state *mrb, void *p_) {
|
|
656
687
|
#else
|
657
688
|
static void free_music(S2D_Music *mus) {
|
658
689
|
#endif
|
659
|
-
S2D_Log(S2D_INFO, "Free music");
|
690
|
+
S2D_Log(S2D_INFO, "Free music `%s`", mus->path);
|
660
691
|
S2D_FreeMusic(mus);
|
661
692
|
}
|
662
693
|
|
@@ -895,6 +926,22 @@ static R_VAL ruby2d_window_ext_get_display_dimensions(R_VAL self) {
|
|
895
926
|
}
|
896
927
|
|
897
928
|
|
929
|
+
/*
|
930
|
+
* Ruby2D::Window#ext_add_controller_mappings
|
931
|
+
*/
|
932
|
+
#if MRUBY
|
933
|
+
static R_VAL ruby2d_window_ext_add_controller_mappings(mrb_state* mrb, R_VAL self) {
|
934
|
+
mrb_value path;
|
935
|
+
mrb_get_args(mrb, "o", &path);
|
936
|
+
#else
|
937
|
+
static R_VAL ruby2d_window_ext_add_controller_mappings(R_VAL self, R_VAL path) {
|
938
|
+
#endif
|
939
|
+
S2D_Log(S2D_INFO, "Adding controller mappings from `%s`", RSTRING_PTR(path));
|
940
|
+
S2D_AddControllerMappingsFromFile(RSTRING_PTR(path));
|
941
|
+
return R_NIL;
|
942
|
+
}
|
943
|
+
|
944
|
+
|
898
945
|
/*
|
899
946
|
* Ruby2D::Window#ext_show
|
900
947
|
*/
|
@@ -905,23 +952,27 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
|
|
905
952
|
#endif
|
906
953
|
ruby2d_window = self;
|
907
954
|
|
955
|
+
// Set Simple 2D diagnostics
|
908
956
|
if (r_test(r_iv_get(self, "@diagnostics"))) {
|
909
957
|
S2D_Diagnostics(true);
|
910
958
|
}
|
911
959
|
|
912
|
-
//
|
913
|
-
|
914
|
-
if (S2D_FileExists(controller_mappings_path)) {
|
915
|
-
S2D_LoadControllerMappingsFromFile(controller_mappings_path);
|
916
|
-
}
|
960
|
+
// Add controller mappings from file
|
961
|
+
r_funcall(self, "add_controller_mappings", 0);
|
917
962
|
|
918
963
|
// Get window attributes
|
919
964
|
char *title = RSTRING_PTR(r_iv_get(self, "@title"));
|
920
965
|
int width = NUM2INT(r_iv_get(self, "@width"));
|
921
966
|
int height = NUM2INT(r_iv_get(self, "@height"));
|
922
|
-
int
|
967
|
+
int fps_cap = NUM2INT(r_iv_get(self, "@fps_cap"));
|
968
|
+
|
969
|
+
// Get the window icon
|
970
|
+
char *icon = NULL;
|
971
|
+
R_VAL iv_icon = r_iv_get(self, "@icon");
|
972
|
+
if (r_test(iv_icon)) icon = RSTRING_PTR(iv_icon);
|
923
973
|
|
924
974
|
// Get window flags
|
975
|
+
int flags = 0;
|
925
976
|
if (r_test(r_iv_get(self, "@resizable"))) {
|
926
977
|
flags = flags | S2D_RESIZABLE;
|
927
978
|
}
|
@@ -951,6 +1002,8 @@ static R_VAL ruby2d_window_ext_show(R_VAL self) {
|
|
951
1002
|
|
952
1003
|
window->viewport.width = viewport_width;
|
953
1004
|
window->viewport.height = viewport_height;
|
1005
|
+
window->fps_cap = fps_cap;
|
1006
|
+
window->icon = icon;
|
954
1007
|
window->on_key = on_key;
|
955
1008
|
window->on_mouse = on_mouse;
|
956
1009
|
window->on_controller = on_controller;
|
@@ -983,10 +1036,6 @@ int main() {
|
|
983
1036
|
// Load the Ruby 2D library
|
984
1037
|
mrb_load_irep(mrb, ruby2d_lib);
|
985
1038
|
|
986
|
-
// Add missing MRuby classes, methods
|
987
|
-
R_CLASS file_class = mrb_define_class(mrb, "File", mrb->object_class);
|
988
|
-
mrb_define_class_method(mrb, file_class, "exists?", file_exists, r_args_req(1));
|
989
|
-
|
990
1039
|
#else
|
991
1040
|
/*
|
992
1041
|
* Ruby C extension init
|
@@ -1015,6 +1064,12 @@ void Init_ruby2d() {
|
|
1015
1064
|
// Ruby2D::Line#ext_render
|
1016
1065
|
r_define_method(ruby2d_line_class, "ext_render", ruby2d_line_ext_render, r_args_none);
|
1017
1066
|
|
1067
|
+
// Ruby2D::Circle
|
1068
|
+
R_CLASS ruby2d_circle_class = r_define_class(ruby2d_module, "Circle");
|
1069
|
+
|
1070
|
+
// Ruby2D::Circle#ext_render
|
1071
|
+
r_define_method(ruby2d_circle_class, "ext_render", ruby2d_circle_ext_render, r_args_none);
|
1072
|
+
|
1018
1073
|
// Ruby2D::Image
|
1019
1074
|
R_CLASS ruby2d_image_class = r_define_class(ruby2d_module, "Image");
|
1020
1075
|
|
@@ -1081,6 +1136,9 @@ void Init_ruby2d() {
|
|
1081
1136
|
// Ruby2D::Window#ext_get_display_dimensions
|
1082
1137
|
r_define_method(ruby2d_window_class, "ext_get_display_dimensions", ruby2d_window_ext_get_display_dimensions, r_args_none);
|
1083
1138
|
|
1139
|
+
// Ruby2D::Window#ext_add_controller_mappings
|
1140
|
+
r_define_method(ruby2d_window_class, "ext_add_controller_mappings", ruby2d_window_ext_add_controller_mappings, r_args_req(1));
|
1141
|
+
|
1084
1142
|
// Ruby2D::Window#ext_show
|
1085
1143
|
r_define_method(ruby2d_window_class, "ext_show", ruby2d_window_ext_show, r_args_none);
|
1086
1144
|
|
data/lib/ruby2d.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
#
|
1
|
+
# Ruby2D module and native extension loader, adds DSL
|
2
2
|
|
3
3
|
require 'ruby2d/renderable'
|
4
4
|
require 'ruby2d/exceptions'
|
5
5
|
require 'ruby2d/color'
|
6
6
|
require 'ruby2d/window'
|
7
|
-
require 'ruby2d/application'
|
8
7
|
require 'ruby2d/dsl'
|
9
8
|
require 'ruby2d/quad'
|
10
9
|
require 'ruby2d/line'
|
10
|
+
require 'ruby2d/circle'
|
11
11
|
require 'ruby2d/rectangle'
|
12
12
|
require 'ruby2d/square'
|
13
13
|
require 'ruby2d/triangle'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Ruby2D::Circle
|
2
|
+
|
3
|
+
module Ruby2D
|
4
|
+
class Circle
|
5
|
+
include Renderable
|
6
|
+
|
7
|
+
attr_reader :color
|
8
|
+
attr_accessor :x, :y, :radius, :sectors
|
9
|
+
|
10
|
+
def initialize(opts = {})
|
11
|
+
@x = opts[:x] || 25
|
12
|
+
@y = opts[:y] || 25
|
13
|
+
@z = opts[:z] || 0
|
14
|
+
@radius = opts[:radius] || 25
|
15
|
+
@sectors = opts[:sectors] || 20
|
16
|
+
self.color = opts[:color] || 'white'
|
17
|
+
add
|
18
|
+
end
|
19
|
+
|
20
|
+
def color=(c)
|
21
|
+
@color = Color.from(c)
|
22
|
+
end
|
23
|
+
|
24
|
+
def contains?(x, y)
|
25
|
+
Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/ruby2d/color.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
-
#
|
1
|
+
# Ruby2D::Color
|
2
2
|
|
3
3
|
module Ruby2D
|
4
4
|
class Color
|
5
|
+
|
5
6
|
# Color::Set represents an array of colors
|
6
7
|
class Set
|
7
8
|
def initialize(colors)
|
8
|
-
@colors = colors.map{|c| Color.new(c)}
|
9
|
+
@colors = colors.map { |c| Color.new(c) }
|
9
10
|
end
|
10
11
|
|
11
12
|
def [](i)
|
@@ -25,7 +26,7 @@ module Ruby2D
|
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
|
29
|
+
attr_accessor :r, :g, :b, :a
|
29
30
|
|
30
31
|
# Based on clrs.cc
|
31
32
|
@@colors = {
|
@@ -83,31 +84,28 @@ module Ruby2D
|
|
83
84
|
|
84
85
|
# Array of Floats from 0.0..1.0
|
85
86
|
c.class == Array && c.length == 4 &&
|
86
|
-
c.all? { |el|
|
87
|
-
el.is_a?(Numeric)
|
88
|
-
}
|
87
|
+
c.all? { |el| el.is_a?(Numeric) }
|
89
88
|
end
|
90
89
|
|
90
|
+
# Create a color from whatever is provided
|
91
91
|
def self.from(input)
|
92
|
-
# If a valid array of colors, return a Color::Set with those colors
|
93
|
-
# Else return single color
|
92
|
+
# If a valid array of colors, return a `Color::Set` with those colors
|
94
93
|
if input.is_a? Array and input.all? { |el| Color.is_valid? el }
|
95
94
|
Color::Set.new(input)
|
95
|
+
# Otherwise, return single color
|
96
96
|
else
|
97
97
|
Color.new(input)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
+
# Convenience methods to alias `opacity` to `@a`
|
101
102
|
def opacity; @a end
|
102
|
-
|
103
|
-
def opacity=(opacity)
|
104
|
-
@a = opacity
|
105
|
-
end
|
103
|
+
def opacity=(opacity); @a = opacity end
|
106
104
|
|
107
105
|
private
|
108
106
|
|
109
|
-
# TODO: Only `Number` supported in JS
|
110
107
|
# Convert from Fixnum (0..255) to Float (0.0..1.0)
|
108
|
+
# TODO: Only `Number` is supported in JS
|
111
109
|
def to_f(a)
|
112
110
|
b = []
|
113
111
|
a.each do |n|
|
@@ -130,4 +128,7 @@ module Ruby2D
|
|
130
128
|
end
|
131
129
|
|
132
130
|
end
|
131
|
+
|
132
|
+
# Allow British English spelling of color
|
133
|
+
Colour = Color
|
133
134
|
end
|