summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.yardoc/checksums5
-rw-r--r--.yardoc/object_typesbin5043 -> 4924 bytes
-rw-r--r--.yardoc/objects/root.datbin103228 -> 99801 bytes
-rw-r--r--mrblib/core.rb7
-rw-r--r--mrblib/shapes.rb2
-rw-r--r--src/textures.c155
6 files changed, 63 insertions, 106 deletions
diff --git a/.yardoc/checksums b/.yardoc/checksums
index 3285097..133bc26 100644
--- a/.yardoc/checksums
+++ b/.yardoc/checksums
@@ -1,8 +1,9 @@
-mrblib/core.rb 3fa564deff611669b248016a9b339e1716087518
+mrblib/core.rb 1039b868b918485f263d7c275f8cdc4a1cb4d99b
mrblib/color.rb 57af07bba5ffe3db9b6c177aff1d05e6f09935ad
mrblib/raylib.rb f6186e04cd023af6139daa94fb9a18dcd08ff9cb
+mrblib/shapes.rb 7e19b395ceba8223e11d13b1e7a2b5163c32be93
mrblib/texture.rb d2218beaa256e2668f70ccdbd01eb494ed8915f0
src/core.c 104318a118d991d7e381b541222562709d8c4a58
src/types.c e6ff14e90b8d4ee08c7db7203b2a4e0deb3ab317
src/raylib.c f347e1f550958b7c5fb70e701b295486aff1f30d
-src/textures.c 7a0d22c21e7cc0989b5706e016fd2d8f0d924bd8
+src/textures.c a357a514f444a6aaafb4450cd085e2dc2c2a8b90
diff --git a/.yardoc/object_types b/.yardoc/object_types
index 735fa3b..b07443a 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 5bd278a..b2a0c85 100644
--- a/.yardoc/objects/root.dat
+++ b/.yardoc/objects/root.dat
Binary files differ
diff --git a/mrblib/core.rb b/mrblib/core.rb
index 8f93772..3b64622 100644
--- a/mrblib/core.rb
+++ b/mrblib/core.rb
@@ -1,4 +1,11 @@
module Raylib
+ class Vector2
+ class << self
+ def default
+ @default ||= self.new(0, 0)
+ end
+ end
+ end
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)
diff --git a/mrblib/shapes.rb b/mrblib/shapes.rb
new file mode 100644
index 0000000..94c4bf1
--- /dev/null
+++ b/mrblib/shapes.rb
@@ -0,0 +1,2 @@
+module Raylib
+end
diff --git a/src/textures.c b/src/textures.c
index 3742257..4126c21 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -52,6 +52,7 @@ mrb_Texture_get_width(mrb_state* mrb, mrb_value self) {
* @param width [Integer] The new width
* @overload w=(width)
* @param w [Integer] The new width
+ * @return [Integer]
*/
static mrb_value
mrb_Texture_set_width(mrb_state* mrb, mrb_value self) {
@@ -82,6 +83,7 @@ mrb_Texture_get_height(mrb_state* mrb, mrb_value self) {
* @param height [Integer] The new height
* @overload h=(height)
* @param h [Integer] The new height
+ * @return [Integer]
*/
static mrb_value
mrb_Texture_set_height(mrb_state* mrb, mrb_value self) {
@@ -132,136 +134,83 @@ mrb_Texture_get_id(mrb_state* mrb, mrb_value self) {
/*
* Draw the texture
- * @overload draw(x: 0, y: 0, tint: Rl::Color.white)
- * @param x [Integer] x position of the drawn texture.
- * @param y [Integer] y position of the drawn texture.
- * @param tint [Integer] The color the drawn texture is tinted(white is no tint).
- * @overload draw(source: Rl::Rectangle.new(0, 0, texture.width, texture.height), x: 0, y: 0, origin: Rl::Vector2.new(0,0), rotation: 0, tint: Rl::Color.white)
+ * @overload draw(source: Rl::Rectangle.new(0,0,texture.width,texture.height), dest: Rl::Rectangle.new(0,0,texture.width,texture.height), origin: Rl::Vector2.default, rotation: 0, tint: Rl::Color.white)
+ * @param tint [Color] The color the drawn texture is tinted(white is 'no tint').
* @param source [Rectangle] Which section of the texture is to be drawn, the default is the entire texture.
- * @param origin [Vector2] Offset of the drawn texture.
+ * @param origin [Vector2] Offset of the drawn texture. Default is no offset.
* @param rotation [Float] How much the texture is rotated when drawn(In radians).
- * @overload draw(source: Rl::Rectangle.new(0,0,texture.width,texture.height), dest: Rl::Rectangle.new(0,0,texture.width,texture.height), origin: Rl::Vector2.new(0,0), rotation: 0, tint: Rl::Color.white)
- * @param dest [Rectangle] Where the texture is to be drawn on the screen(This can scale the texture)
+ * @param dest [Rectangle] Where the texture is to be drawn on the screen(This can scale the texture). Default is the size of the texture.
* @return [Nil]
*/
static mrb_value
-mrb_draw_texture(mrb_state* mrb, mrb_value self) {
- mrb_int x = 0;
- mrb_int y = 0;
- struct RClass *raylib = mrb_module_get(mrb, "Raylib");
- struct RClass *color = mrb_class_get_under(mrb, raylib, Color_type.struct_name);
- mrb_value tint_obj = mrb_funcall(mrb, mrb_obj_value(color), "white", 0);
+mrb_Texture_draw_texture(mrb_state* mrb, mrb_value self) {
+ struct RClass *raylib;// = mrb_module_get(mrb, "Raylib");
+ Rectangle source = {0};
+ Rectangle dest = {0};
+ float rotation = 0.0;
+ Texture *texture_data;
+ UNWRAPSTRUCT(Texture, Texture_type, self, texture_data);
+ //mrb_value tint_obj = mrb_funcall(mrb, mrb_obj_value(color), "white", 0);
//Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint
uint32_t kw_num = 7;
- const mrb_sym kw_names[] = {
+ const mrb_sym kw_names[] = {
mrb_intern_lit(mrb, "source"),
- mrb_intern_lit(mrb, "x"),
- mrb_intern_lit(mrb, "y"),
mrb_intern_lit(mrb, "dest"),
mrb_intern_lit(mrb, "origin"),
mrb_intern_lit(mrb, "rotation"),
mrb_intern_lit(mrb, "tint"),
-
};
mrb_value kw_values[kw_num];
const mrb_kwargs kwargs = { kw_num, 0, kw_names, kw_values, NULL };
- mrb_get_args(mrb, "|iio:", &x, &y, &tint_obj, &kwargs);
+ mrb_get_args(mrb, "|:", &kwargs);
- // if dest exists
- if (!(mrb_undef_p(kw_values[3]))) {
- //x = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[3]));
- }
- // use it
- // else check if x/y exist
- if (!(mrb_undef_p(kw_values[1]) && mrb_undef_p(kw_values[2]))) {
- //x = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[1]));
- }
- // use them
- // else
- // use arg x/y
- // end
- // if source
+ // if source defined
if (!(mrb_undef_p(kw_values[0]))) {
- //x = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[0]));
- }
- // use it
- // elsea
- // use texture values
- // end
- // if tint exists
- if (!(mrb_undef_p(kw_values[6]))) {
- //x = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[6]));
- }
- // use it
- // else
- // use arg
- // end
- // if origin etc.
- if (!(mrb_undef_p(kw_values[4]))) {
- //x = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[0]));
- }
- // if rotation etc.
- if (!(mrb_undef_p(kw_values[5]))) {
- //x = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[0]));
+ Rectangle *temp_rec;
+ UNWRAPSTRUCT(Rectangle, Rectangle_type, kw_values[0], temp_rec);
+ source = *temp_rec;
+ } else {
+ source = (struct Rectangle){ 0, 0, texture_data->width, texture_data->height };
}
- if (!(mrb_undef_p(kw_values[0]))) {
- x = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[0]));
- }
+ // if dest defined
if (!(mrb_undef_p(kw_values[1]))) {
- y = mrb_fixnum(mrb_ensure_int_type(mrb, kw_values[1]));
- }
- if (!(mrb_undef_p(kw_values[2]))) {
- tint_obj = kw_values[2];
+ Rectangle *temp_rec;
+ UNWRAPSTRUCT(Rectangle, Rectangle_type, kw_values[1], temp_rec);
+ dest = *temp_rec;
+ } else {
+ dest = (struct Rectangle){ 0, 0, texture_data->width, texture_data->height };
}
+ // if origin undefined
+ if ((mrb_undef_p(kw_values[2]))) {
+ raylib = mrb_module_get(mrb, "Raylib");
+ struct RClass *vector2 = mrb_class_get_under(mrb, raylib, Vector2_type.struct_name);
+ kw_values[2] = mrb_funcall(mrb, mrb_obj_value(vector2), "default", 0);
+ }
- Texture *texture_data;
- UNWRAPSTRUCT(Texture, Texture_type, self, texture_data);
-
- Color *tint_data;
- UNWRAPSTRUCT(Color, Color_type, tint_obj, tint_data);
-
- DrawTexture(*texture_data, x, y, *tint_data);
-
- return mrb_nil_value();
-}
-
-static mrb_value
-mrb_draw_texture_ex(mrb_state* mrb, mrb_value self) {
- mrb_value texture_obj;
- mrb_value pos_obj;
- mrb_float rotation;
- mrb_float scale;
- mrb_value tint_obj;
- mrb_get_args(mrb, "ooffo", &texture_obj, &pos_obj, &rotation, &scale, &tint_obj);
+ // if rotation defined
+ if (!(mrb_undef_p(kw_values[3]))) {
+ rotation = mrb_as_float(mrb, kw_values[3]) / 0.017453;
+ }
- Texture *texture_data = DATA_GET_PTR(mrb, texture_obj, &Texture_type, Texture);
- Vector2 *pos_data = DATA_GET_PTR(mrb, pos_obj, &Vector2_type, Vector2);
- Color *tint_data = DATA_GET_PTR(mrb, tint_obj, &Color_type, Color);
+ // if color undefined
+ if ((mrb_undef_p(kw_values[4]))) {
+ raylib = mrb_module_get(mrb, "Raylib"); // needs to be called again or else segfault
+ struct RClass *color = mrb_class_get_under(mrb, raylib, Color_type.struct_name);
+ kw_values[4] = mrb_funcall(mrb, mrb_obj_value(color), "white", 0);
+ }
- DrawTextureEx(*texture_data, *pos_data, rotation, scale, *tint_data);
- return mrb_nil_value();
-}
-static mrb_value
-mrb_draw_texture_pro(mrb_state* mrb, mrb_value self) {
- mrb_value texture_obj;
- mrb_value pos_obj;
- mrb_value source_rec_obj;
- mrb_value dest_rec_obj;
- mrb_float rotation;
- mrb_value tint_obj;
- mrb_get_args(mrb, "oooofo", &texture_obj, &source_rec_obj, &dest_rec_obj, &pos_obj, &rotation, &tint_obj);
+ Color *tint_data;
+ UNWRAPSTRUCT(Color, Color_type, kw_values[4], tint_data);
- Texture *texture_data = DATA_GET_PTR(mrb, texture_obj, &Texture_type, Texture);
- Vector2 *pos_data = DATA_GET_PTR(mrb, pos_obj, &Vector2_type, Vector2);
- Rectangle *source_rec_data = DATA_GET_PTR(mrb, source_rec_obj, &Rectangle_type, Rectangle);
- Rectangle *dest_rec_data = DATA_GET_PTR(mrb, dest_rec_obj, &Rectangle_type, Rectangle);
- Color *tint_data = DATA_GET_PTR(mrb, tint_obj, &Color_type, Color);
+ Vector2 *vector2_data;
+ UNWRAPSTRUCT(Vector2, Vector2_type, kw_values[2], vector2_data);
- DrawTexturePro(*texture_data, *source_rec_data, *dest_rec_data, *pos_data, rotation, *tint_data);
+ //Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint
+ DrawTexturePro(*texture_data, source, dest, *vector2_data, rotation, *tint_data);
return mrb_nil_value();
}
@@ -284,8 +233,6 @@ mrb_init_raylib_textures(mrb_state* mrb) {
mrb_define_method(mrb, texture_class, "id", mrb_Texture_get_id, MRB_ARGS_NONE());
//mrb_define_method(mrb, texture_class, "mipmaps", mrb_Texture_get_mipmaps, MRB_ARGS_NONE());
//mrb_define_method(mrb, texture_class, "format", mrb_Texture_get_format, MRB_ARGS_NONE());
- mrb_define_module_function(mrb, texture_class, "draw", mrb_draw_texture, MRB_ARGS_OPT(3));
- mrb_define_module_function(mrb, raylib, "_draw_texture_ex", mrb_draw_texture_ex, MRB_ARGS_OPT(4));
- mrb_define_module_function(mrb, raylib, "_draw_texture_pro", mrb_draw_texture_pro, MRB_ARGS_OPT(5));
+ mrb_define_method(mrb, texture_class, "draw", mrb_Texture_draw_texture, MRB_ARGS_OPT(3));
}