summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-02-08 03:12:31 -0500
committerrealtradam <[email protected]>2022-02-08 03:12:31 -0500
commit864c710a510be8e318023e34565209f9a24a3ac7 (patch)
treef42c172c290df6ba587042f978747dc4f88ba352
parent187cab9f77a6274ba4e5bb9c012fca5549c020fb (diff)
downloadmruby-raylib-864c710a510be8e318023e34565209f9a24a3ac7.tar.gz
mruby-raylib-864c710a510be8e318023e34565209f9a24a3ac7.zip
move stuff to types.h
-rw-r--r--include/mruby-raylib/core.h14
-rw-r--r--include/mruby-raylib/textures.h11
-rw-r--r--include/mruby-raylib/types.h (renamed from include/raylib/core.h)25
-rw-r--r--mrbgem.rake2
-rw-r--r--mrblib/color.rb7
-rw-r--r--mrblib/core.rb18
-rw-r--r--mrblib/raylib.rb18
-rw-r--r--src/core.c18
-rw-r--r--src/raylib.c49
-rw-r--r--src/types.c52
10 files changed, 122 insertions, 92 deletions
diff --git a/include/mruby-raylib/core.h b/include/mruby-raylib/core.h
new file mode 100644
index 0000000..c0e6815
--- /dev/null
+++ b/include/mruby-raylib/core.h
@@ -0,0 +1,14 @@
+#ifndef MRUBY_RAYLIB_CORE_H
+#define MRUBY_RAYLIB_CORE_H
+#include "mruby-raylib/types.h"
+#include <mruby/string.h>
+#include <mruby/numeric.h>
+#include <stdlib.h>
+#if defined(PLATFORM_WEB)
+#include <emscripten/emscripten.h>
+#endif
+
+void mrb_init_raylib_core(mrb_state*);
+
+#endif /* end of include guard MRUBY_RAYLIB_CORE_H */
+
diff --git a/include/mruby-raylib/textures.h b/include/mruby-raylib/textures.h
new file mode 100644
index 0000000..01bc0a6
--- /dev/null
+++ b/include/mruby-raylib/textures.h
@@ -0,0 +1,11 @@
+#ifndef MRUBY_RAYLIB_TEXTURES_H
+#define MRUBY_RAYLIB_TEXTURES_H
+#include <raylib.h>
+#include <mruby.h>
+#include <mruby/string.h>
+#include <mruby/data.h>
+#include <mruby/numeric.h>
+#include <stdlib.h>
+#include "mruby-raylib/core.h"
+
+#endif
diff --git a/include/raylib/core.h b/include/mruby-raylib/types.h
index 7985fa1..f6f5b67 100644
--- a/include/raylib/core.h
+++ b/include/mruby-raylib/types.h
@@ -1,15 +1,7 @@
-#ifndef MRUBY_RAYLIB_CORE_H
-#define MRUBY_RAYLIB_CORE_H
-#include <raylib.h>
+#ifndef MRUBY_RAYLIB_TYPES_H
+#define MRUBY_RAYLIB_TYPES_H
#include <mruby.h>
-#include <mruby/string.h>
#include <mruby/data.h>
-#include <mruby/numeric.h>
-#include <stdlib.h>
-#if defined(PLATFORM_WEB)
-#include <emscripten/emscripten.h>
-#endif
-
#define PREWRAPSTRUCT(var_name, type, target) var_name = (type *)DATA_PTR(target)
@@ -21,12 +13,17 @@
#define UNWRAPSTRUCT(type, mrb_type, target, var_name) var_name = DATA_GET_PTR(mrb, target, &mrb_type, type)
-
-
extern const struct mrb_data_type Color_type;
extern const struct mrb_data_type Rectangle_type;
+extern const struct mrb_data_type Texture_type;
+extern const struct mrb_data_type Sound_type;
+extern const struct mrb_data_type Music_type;
+extern const struct mrb_data_type Vector2_type;
+extern const struct mrb_data_type NPatchInfo_type;
-void mrb_init_raylib_core(mrb_state*);
+void helper_texture_free(mrb_state*, void*);
+void helper_sound_free(mrb_state*, void*);
+void helper_music_free(mrb_state*, void*);
-#endif /* end of include guard MRUBY_RAYLIB_CORE_H */
+#endif /* end of include guard MRUBY_RAYLIB_TYPES_H */
diff --git a/mrbgem.rake b/mrbgem.rake
index e77cc5d..3e7f338 100644
--- a/mrbgem.rake
+++ b/mrbgem.rake
@@ -1,4 +1,4 @@
-MRuby::Gem::Specification.new('mruby_raylib') do |spec|
+MRuby::Gem::Specification.new('mruby-raylib') do |spec|
spec.license = 'MIT'
spec.author = 'Tradam and Arnold'
diff --git a/mrblib/color.rb b/mrblib/color.rb
index 2625f34..c936f0d 100644
--- a/mrblib/color.rb
+++ b/mrblib/color.rb
@@ -58,6 +58,13 @@ module Raylib
end
self.send(result)
end
+
+ def clone
+ Raylib::Color.new(r: self.r,
+ g: self.g,
+ b: self.b,
+ a: self.a)
+ end
end
# Hash of all web colors, RayWhite, and Clear
diff --git a/mrblib/core.rb b/mrblib/core.rb
index 5d27566..8f93772 100644
--- a/mrblib/core.rb
+++ b/mrblib/core.rb
@@ -1,6 +1,20 @@
module Raylib
- class Color
- class << self
+ class << self
+ # The code block version of {Raylib.begin_scissor_mode} and {Raylib.end_scissor_mode}
+ # @overload scissor_mode(x: 0, y: 0, width: 10, height: 10, &block)
+ # @param x [Integer]
+ # @param y [Integer]
+ # @param width [Integer]
+ # @param height [Integer]
+ # @param block [Proc] The code to be executed in the scissor mode
+ def scissor_mode(*args, x: 0, y: 0, width: 10, height: 10, &block)
+ if args.length == 4
+ self.begin_scissor_mode(args[0], args[1], args[2], args[3])
+ else
+ self.begin_scissor_mode(x: x, y: y, width: width, height: height)
+ end
+ yield
+ self.end_scissor_mode
end
end
end
diff --git a/mrblib/raylib.rb b/mrblib/raylib.rb
index e53a15b..0e60abf 100644
--- a/mrblib/raylib.rb
+++ b/mrblib/raylib.rb
@@ -59,7 +59,6 @@ module Raylib
self.defined_loop.call
end
-
def draw_text(text:, x:, y:, font_size:, color: Rl::Color.new(255,255,255,255))
self._draw_text(text, x, y, font_size, color)
end
@@ -89,23 +88,6 @@ module Raylib
self.data_keys_pressed
end
- # The code block version of {Raylib.begin_scissor_mode} and {Raylib.end_scissor_mode}
- # @overload scissor_mode(x: 0, y: 0, width: 10, height: 10, &block)
- # @param x [Integer]
- # @param y [Integer]
- # @param width [Integer]
- # @param height [Integer]
- # @param block [Proc] The code to be executed in the scissor mode
- def scissor_mode(*args, x: 0, y: 0, width: 10, height: 10, &block)
- if args.length == 4
- self.begin_scissor_mode(args[0], args[1], args[2], args[3])
- else
- self.begin_scissor_mode(x, y, width, height)
- end
- yield
- self.end_scissor_mode
- end
-
def draw(clear_color: nil, &block)
self.clear_background(clear_color) if clear_color
self.begin_drawing
diff --git a/src/core.c b/src/core.c
index e6b290f..96df1ae 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1,13 +1,6 @@
-#include "raylib/core.h"
-
-const struct mrb_data_type Color_type = {
- "Color", mrb_free
-};
-
-const struct mrb_data_type Rectangle_type = {
- "Rectangle", mrb_free
-};
-
+#include "mruby-raylib/core.h"
+#include "mruby-raylib/types.h"
+#include <raylib.h>
/*
* @overload init_window(width: 800, height: 600, title: "Hello World from Raylib!")
* @param width [Integer]
@@ -138,6 +131,11 @@ mrb_begin_scissor_mode(mrb_state* mrb, mrb_value self) {
kw_values[1] = mrb_fixnum_value(y);
kw_values[2] = mrb_fixnum_value(width);
kw_values[3] = mrb_fixnum_value(height);
+ } else {
+ kw_values[0] = mrb_ensure_int_type(mrb, kw_values[0]);
+ kw_values[1] = mrb_ensure_int_type(mrb, kw_values[1]);
+ kw_values[2] = mrb_ensure_int_type(mrb, kw_values[2]);
+ kw_values[3] = mrb_ensure_int_type(mrb, kw_values[3]);
}
BeginScissorMode(mrb_fixnum(kw_values[0]), mrb_fixnum(kw_values[1]), mrb_fixnum(kw_values[2]), mrb_fixnum(kw_values[3]));
return mrb_nil_value();
diff --git a/src/raylib.c b/src/raylib.c
index dd69f96..56bdf96 100644
--- a/src/raylib.c
+++ b/src/raylib.c
@@ -1,12 +1,11 @@
+#include "mruby-raylib/types.h"
+#include "mruby-raylib/core.h"
#include <raylib.h>
-#include <mruby.h>
#include <mruby/array.h>
-#include <mruby/data.h>
#include <mruby/class.h>
#include <mruby/numeric.h>
#include <mruby/string.h>
#include <stdlib.h>
-#include "raylib/core.h"
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
@@ -14,54 +13,10 @@
#if defined(PLATFORM_WEB)
void execute_emscripten_block(void*);
#endif
-void helper_texture_free(mrb_state*, void*);
-void helper_sound_free(mrb_state*, void*);
-void helper_music_free(mrb_state*, void*);
bool check_collision_circle_rec(mrb_state* mrb, mrb_value circle_obj, mrb_value rec_obj);
-static const struct mrb_data_type Texture_type = {
- "Texture", helper_texture_free
-};
-
-void
-helper_texture_free(mrb_state* mrb, void*ptr) {
- Texture *texture = (Texture*)ptr;
- UnloadTexture(*texture);
- mrb_free(mrb, ptr);
-}
-
-static const struct mrb_data_type Sound_type = {
- "Sound", helper_sound_free
-};
-
-void
-helper_sound_free(mrb_state* mrb, void*ptr) {
- Sound *sound = (Sound*)ptr;
- UnloadSound(*sound);
- mrb_free(mrb, ptr);
-}
-
-static const struct mrb_data_type Vector2_type = {
- "Vector2", mrb_free
-};
-
-
-static const struct mrb_data_type NPatchInfo_type = {
- "NPatchInfo", mrb_free
-};
-
-static const struct mrb_data_type Music_type = {
- "Music", helper_music_free
-};
-
-void
-helper_music_free(mrb_state* mrb, void*ptr) {
- Music *music = (Music*)ptr;
- UnloadMusicStream(*music);
- mrb_free(mrb, ptr);
-}
static mrb_value
diff --git a/src/types.c b/src/types.c
new file mode 100644
index 0000000..c1b3e34
--- /dev/null
+++ b/src/types.c
@@ -0,0 +1,52 @@
+#include "mruby-raylib/types.h"
+#include <raylib.h>
+
+const struct mrb_data_type Color_type = {
+ "Color", mrb_free
+};
+
+const struct mrb_data_type Rectangle_type = {
+ "Rectangle", mrb_free
+};
+
+const struct mrb_data_type Texture_type = {
+ "Texture", helper_texture_free
+};
+
+void
+helper_texture_free(mrb_state* mrb, void*ptr) {
+ Texture *texture = (Texture*)ptr;
+ UnloadTexture(*texture);
+ mrb_free(mrb, ptr);
+}
+
+const struct mrb_data_type Sound_type = {
+ "Sound", helper_sound_free
+};
+
+void
+helper_sound_free(mrb_state* mrb, void*ptr) {
+ Sound *sound = (Sound*)ptr;
+ UnloadSound(*sound);
+ mrb_free(mrb, ptr);
+}
+
+const struct mrb_data_type Music_type = {
+ "Music", helper_music_free
+};
+
+void
+helper_music_free(mrb_state* mrb, void*ptr) {
+ Music *music = (Music*)ptr;
+ UnloadMusicStream(*music);
+ mrb_free(mrb, ptr);
+}
+
+const struct mrb_data_type Vector2_type = {
+ "Vector2", mrb_free
+};
+
+const struct mrb_data_type NPatchInfo_type = {
+ "NPatchInfo", mrb_free
+};
+