summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.yardoc/checksums8
-rw-r--r--.yardoc/object_typesbin5076 -> 5076 bytes
-rw-r--r--.yardoc/objects/root.datbin89478 -> 94929 bytes
-rw-r--r--include/raylib/core.h5
-rw-r--r--mrblib/color.rb2
-rw-r--r--mrblib/raylib.rb15
-rw-r--r--src/core.c83
-rw-r--r--src/raylib.c50
8 files changed, 114 insertions, 49 deletions
diff --git a/.yardoc/checksums b/.yardoc/checksums
index cd0eeb6..65ff816 100644
--- a/.yardoc/checksums
+++ b/.yardoc/checksums
@@ -1,5 +1,5 @@
mrblib/core.rb d58457d61a6737b2dbdd58671a45dd404e745b77
-mrblib/color.rb 8c4f4f37c275a91276feee2da1f199157f17777e
-mrblib/raylib.rb fbcdcf96e35dd357edb833327d61bf72ee396702
-src/core.c 205286b59e8a0bd65ebf695c482eb331dc2b4a36
-src/raylib.c 68ee756bb18a21e7663ac59cfbbb254d3523b61c
+mrblib/color.rb cf601fe4a21cf8d9c76faca9dee720bf54fde505
+mrblib/raylib.rb 12dcc2872a6ab8ab3411b891d1b5f1834ca3ceef
+src/core.c d1a045e9c516d16395c632bccf5a3a1a5ae59868
+src/raylib.c 6e2201eae6290f923e7e9455ed687c7b5cbf2d91
diff --git a/.yardoc/object_types b/.yardoc/object_types
index 0a74c5f..f9aa253 100644
--- a/.yardoc/object_types
+++ b/.yardoc/object_types
Binary files differ
diff --git a/.yardoc/objects/root.dat b/.yardoc/objects/root.dat
index bfb8913..c26c4fd 100644
--- a/.yardoc/objects/root.dat
+++ b/.yardoc/objects/root.dat
Binary files differ
diff --git a/include/raylib/core.h b/include/raylib/core.h
index c98c80d..7985fa1 100644
--- a/include/raylib/core.h
+++ b/include/raylib/core.h
@@ -11,7 +11,7 @@
#endif
-#define PREWRAPSTRUCT(var_name, type, target) type *var_name = (type *)DATA_PTR(target)
+#define PREWRAPSTRUCT(var_name, type, target) var_name = (type *)DATA_PTR(target)
#define WRAPSTRUCT(type, mrb_type, target, var_name) \
PREWRAPSTRUCT(var_name, type, target);\
@@ -19,11 +19,12 @@
mrb_data_init(target, NULL, &mrb_type);\
var_name = (type *)mrb_malloc(mrb, sizeof(type));\
-#define UNWRAPSTRUCT(type, mrb_type, target, var_name) type *var_name = DATA_GET_PTR(mrb, target, &mrb_type, type)
+#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;
void mrb_init_raylib_core(mrb_state*);
diff --git a/mrblib/color.rb b/mrblib/color.rb
index b4fa9c3..2625f34 100644
--- a/mrblib/color.rb
+++ b/mrblib/color.rb
@@ -60,7 +60,7 @@ module Raylib
end
end
- # Hash of all web colors
+ # Hash of all web colors, RayWhite, and Clear
ColorList = {
:clear=>{:r=>0, :g=>0, :b=>0, :a=>0},
:ray_white=>{:r=>245, :g=>245, :b=>245},
diff --git a/mrblib/raylib.rb b/mrblib/raylib.rb
index 5ad3e37..e53a15b 100644
--- a/mrblib/raylib.rb
+++ b/mrblib/raylib.rb
@@ -89,8 +89,19 @@ module Raylib
self.data_keys_pressed
end
- def scissor_mode(x: x, y: y, width: width, height: height, &block)
- self.begin_scissor_mode(x, y, width, height)
+ # 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
diff --git a/src/core.c b/src/core.c
index 4509cd5..e6b290f 100644
--- a/src/core.c
+++ b/src/core.c
@@ -4,6 +4,9 @@ const struct mrb_data_type Color_type = {
"Color", mrb_free
};
+const struct mrb_data_type Rectangle_type = {
+ "Rectangle", mrb_free
+};
/*
* @overload init_window(width: 800, height: 600, title: "Hello World from Raylib!")
@@ -72,17 +75,93 @@ mrb_clear_background(mrb_state* mrb, mrb_value self) {
const mrb_kwargs kwargs = { kw_num, 0, kw_names, kw_values, NULL };
mrb_get_args(mrb, "|o:", &color_obj, &kwargs);
+ if (mrb_undef_p(kw_values[0])) {
+ kw_values[0] = color_obj;
+ }
- Color *color_data = DATA_GET_PTR(mrb, color_obj, &Color_type, Color);
+ Color *color_data = DATA_GET_PTR(mrb, kw_values[0], &Color_type, Color);
ClearBackground(*color_data);
return mrb_nil_value();
}
+/*
+ * Setup canvas (framebuffer) to start drawing
+ * @return [Nil]
+ */
+static mrb_value
+mrb_begin_drawing(mrb_state* mrb, mrb_value self) {
+ BeginDrawing();
+ return mrb_nil_value();
+}
+
+/*
+ * End canvas drawing and swap buffers (double buffering)
+ * @return [Nil]
+ */
+static mrb_value
+mrb_end_drawing(mrb_state* mrb, mrb_value self) {
+ EndDrawing();
+ return mrb_nil_value();
+}
+/*
+ * Begin scissor mode (define screen area for following drawing)
+ * @overload begin_scissor_mode(x: 0, y: 0, width: 10, height: 10)
+ * @param x [Integer]
+ * @param y [Integer]
+ * @param width [Integer]
+ * @param height [Integer]
+ * @return [Nil]
+ */
+static mrb_value
+mrb_begin_scissor_mode(mrb_state* mrb, mrb_value self) {
+ mrb_int x = 0;
+ mrb_int y = 0;
+ mrb_int width = 10;
+ mrb_int height = 10;
+ //mrb_get_args(mrb, "iiii", &x, &y, &width, &height);
+
+
+ uint32_t kw_num = 4;
+ const mrb_sym kw_names[] = {
+ mrb_intern_lit(mrb, "x"),
+ mrb_intern_lit(mrb, "y"),
+ mrb_intern_lit(mrb, "width"),
+ mrb_intern_lit(mrb, "height"),
+ };
+ mrb_value kw_values[kw_num];
+ const mrb_kwargs kwargs = { kw_num, 0, kw_names, kw_values, NULL };
+ mrb_get_args(mrb, "|iiii:", &x, &y, &width, &height, &kwargs);
+
+ if (mrb_undef_p(kw_values[0]) && mrb_undef_p(kw_values[1]) && mrb_undef_p(kw_values[2]) && mrb_undef_p(kw_values[3])) {
+ // pass params to kwargs
+ kw_values[0] = mrb_fixnum_value(x);
+ kw_values[1] = mrb_fixnum_value(y);
+ kw_values[2] = mrb_fixnum_value(width);
+ kw_values[3] = mrb_fixnum_value(height);
+ }
+ 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();
+}
+
+/*
+ * End scissor mode
+ * @overload end_scissor_mode
+ * @return [Nil]
+ */
+static mrb_value
+mrb_end_scissor_mode(mrb_state* mrb, mrb_value self) {
+ EndScissorMode();
+ return mrb_nil_value();
+}
void
mrb_init_raylib_core(mrb_state* mrb) {
struct RClass *raylib = mrb_define_module(mrb, "Raylib");
mrb_define_module_function(mrb, raylib, "init_window", mrb_init_window, MRB_ARGS_OPT(3));
mrb_define_module_function(mrb, raylib, "window_should_close?", mrb_window_should_close, MRB_ARGS_NONE());
- mrb_define_module_function(mrb, raylib, "clear_background", mrb_clear_background, MRB_ARGS_REQ(1));
+ mrb_define_module_function(mrb, raylib, "clear_background", mrb_clear_background, MRB_ARGS_OPT(1));
+ mrb_define_module_function(mrb, raylib, "begin_drawing", mrb_begin_drawing, MRB_ARGS_NONE());
+ mrb_define_module_function(mrb, raylib, "end_drawing", mrb_end_drawing, MRB_ARGS_NONE());
+ mrb_define_module_function(mrb, raylib, "begin_scissor_mode", mrb_begin_scissor_mode, MRB_ARGS_REQ(4));
+ mrb_define_module_function(mrb, raylib, "end_scissor_mode", mrb_end_scissor_mode, MRB_ARGS_NONE());
}
diff --git a/src/raylib.c b/src/raylib.c
index 2da256b..dd69f96 100644
--- a/src/raylib.c
+++ b/src/raylib.c
@@ -47,9 +47,6 @@ static const struct mrb_data_type Vector2_type = {
"Vector2", mrb_free
};
-static const struct mrb_data_type Rectangle_type = {
- "Rectangle", mrb_free
-};
static const struct mrb_data_type NPatchInfo_type = {
"NPatchInfo", mrb_free
@@ -567,24 +564,6 @@ mrb_draw_texture_npatch(mrb_state* mrb, mrb_value self) {
}
static mrb_value
-mrb_begin_scissor_mode(mrb_state* mrb, mrb_value self) {
- mrb_int x;
- mrb_int y;
- mrb_int width;
- mrb_int height;
- mrb_get_args(mrb, "iiii", &x, &y, &width, &height);
-
- BeginScissorMode(x, y, width, height);
- return mrb_nil_value();
-}
-
-static mrb_value
-mrb_end_scissor_mode(mrb_state* mrb, mrb_value self) {
- EndScissorMode();
- return mrb_nil_value();
-}
-
-static mrb_value
mrb_begin_blend_mode(mrb_state* mrb, mrb_value self) {
mrb_int mode;
mrb_get_args(mrb, "i", &mode);
@@ -608,6 +587,7 @@ mrb_Color_initialize(mrb_state* mrb, mrb_value self) {
mrb_int a = 255;
mrb_get_args(mrb, "|iiii", &r, &g, &b, &a);
+ Color *color;
WRAPSTRUCT(Color, Color_type, self, color);
color->r = r;
@@ -621,12 +601,14 @@ mrb_Color_initialize(mrb_state* mrb, mrb_value self) {
static mrb_value
mrb_Color_get_red(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
return mrb_fixnum_value(color->r);
}
static mrb_value
mrb_Color_set_red(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
mrb_int r;
mrb_get_args(mrb, "i", &r);
@@ -637,12 +619,14 @@ mrb_Color_set_red(mrb_state* mrb, mrb_value self) {
static mrb_value
mrb_Color_get_green(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
return mrb_fixnum_value(color->g);
}
static mrb_value
mrb_Color_set_green(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
mrb_int g;
mrb_get_args(mrb, "i", &g);
@@ -653,6 +637,7 @@ mrb_Color_set_green(mrb_state* mrb, mrb_value self) {
static mrb_value
mrb_Color_get_blue(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
return mrb_fixnum_value(color->b);
@@ -660,6 +645,7 @@ mrb_Color_get_blue(mrb_state* mrb, mrb_value self) {
static mrb_value
mrb_Color_set_blue(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
mrb_int b;
mrb_get_args(mrb, "i", &b);
@@ -670,12 +656,14 @@ mrb_Color_set_blue(mrb_state* mrb, mrb_value self) {
static mrb_value
mrb_Color_get_alpha(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
return mrb_fixnum_value(color->a);
}
static mrb_value
mrb_Color_set_alpha(mrb_state* mrb, mrb_value self) {
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, self, color);
mrb_int a;
mrb_get_args(mrb, "i", &a);
@@ -832,24 +820,12 @@ mrb_draw_text(mrb_state* mrb, mrb_value self) {
mrb_get_args(mrb, "|ziiio", &text, &x, &y, &fontSize, &color_obj);
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, color_obj, color);
DrawText(text, x, y, fontSize, *color);
return mrb_nil_value();
}
-static mrb_value
-mrb_begin_drawing(mrb_state* mrb, mrb_value self) {
- BeginDrawing();
- return mrb_nil_value();
-}
-
-static mrb_value
-mrb_end_drawing(mrb_state* mrb, mrb_value self) {
- EndDrawing();
- return mrb_nil_value();
-}
-
-
static mrb_value
mrb_call_main_loop(mrb_state* mrb, mrb_value self) {
struct RClass *c = mrb_module_get(mrb, "Raylib");
@@ -976,6 +952,7 @@ mrb_Rectangle_draw_rectangle_rec(mrb_state* mrb, mrb_value self) {
mrb_value color_obj;
mrb_get_args(mrb, "o", &color_obj);
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, color_obj, color);
Rectangle *rec_self = DATA_GET_PTR(mrb, self, &Rectangle_type, Rectangle);
DrawRectangleRec(*rec_self, *color);
@@ -989,6 +966,7 @@ mrb_Rectangle_draw_rectangle_lines_ex(mrb_state* mrb, mrb_value self) {
mrb_float line_thick;
mrb_get_args(mrb, "fo", &line_thick, &color_obj);
+ Color *color;
UNWRAPSTRUCT(Color, Color_type, color_obj, color);
Rectangle *rec_self = DATA_GET_PTR(mrb, self, &Rectangle_type, Rectangle);
DrawRectangleLinesEx(*rec_self, line_thick, *color);
@@ -1003,8 +981,6 @@ mrb_mruby_raylib_gem_init(mrb_state* mrb) {
struct RClass *raylib = mrb_define_module(mrb, "Raylib");
mrb_define_module_function(mrb, raylib, "platform", mrb_platform, MRB_ARGS_NONE());
mrb_define_module_function(mrb, raylib, "_draw_text", mrb_draw_text, MRB_ARGS_OPT(5));
- mrb_define_module_function(mrb, raylib, "begin_drawing", mrb_begin_drawing, MRB_ARGS_NONE());
- mrb_define_module_function(mrb, raylib, "end_drawing", mrb_end_drawing, MRB_ARGS_NONE());
mrb_define_module_function(mrb, raylib, "call_main_loop", mrb_call_main_loop, MRB_ARGS_NONE());
mrb_define_module_function(mrb, raylib, "target_fps=", mrb_target_fps, MRB_ARGS_REQ(1));
mrb_define_module_function(mrb, raylib, "fps", mrb_fps, MRB_ARGS_NONE());
@@ -1026,8 +1002,6 @@ mrb_mruby_raylib_gem_init(mrb_state* mrb) {
mrb_define_module_function(mrb, raylib, "mouse_y", mrb_get_mouse_y, MRB_ARGS_NONE());
mrb_define_module_function(mrb, raylib, "mouse_position", mrb_get_mouse_position, MRB_ARGS_NONE());
mrb_define_module_function(mrb, raylib, "mouse_wheel", mrb_get_mouse_wheel_move, MRB_ARGS_NONE());
- mrb_define_module_function(mrb, raylib, "begin_scissor_mode", mrb_begin_scissor_mode, MRB_ARGS_REQ(4));
- mrb_define_module_function(mrb, raylib, "end_scissor_mode", mrb_end_scissor_mode, MRB_ARGS_NONE());
mrb_define_module_function(mrb, raylib, "begin_blend_mode", mrb_begin_blend_mode, MRB_ARGS_REQ(1));
mrb_define_module_function(mrb, raylib, "end_blend_mode", mrb_end_blend_mode, MRB_ARGS_NONE());