From 5bc6f6f32c798f430337a696253b5153e72efa2c Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Fri, 15 Aug 2014 22:53:42 +0200 Subject: [PATCH] Etc: Implement missing RGSS3 functionality (and bind in MRI) --- binding-mri/etc-binding.cpp | 29 +++++++++++++++++++++++------ src/etc.cpp | 30 ++++++++++++++++++++++++++++++ src/etc.h | 5 +++++ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/binding-mri/etc-binding.cpp b/binding-mri/etc-binding.cpp index 4269da8..91c250f 100644 --- a/binding-mri/etc-binding.cpp +++ b/binding-mri/etc-binding.cpp @@ -79,9 +79,17 @@ EQUAL_FUN(Rect) #define INIT_FUN(Klass, param_type, param_t_s, last_param_def) \ RB_METHOD(Klass##Initialize) \ { \ - param_type p1, p2, p3, p4 = last_param_def; \ - rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \ - Klass *k = new Klass(p1, p2, p3, p4); \ + Klass *k; \ + if (argc == 0) \ + { \ + k = new Klass(); \ + } \ + else \ + { \ + param_type p1, p2, p3, p4 = last_param_def; \ + rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \ + k = new Klass(p1, p2, p3, p4); \ + } \ setPrivateData(self, k); \ return self; \ } @@ -93,10 +101,19 @@ INIT_FUN(Rect, int, "iiii", 0) #define SET_FUN(Klass, param_type, param_t_s, last_param_def) \ RB_METHOD(Klass##Set) \ { \ - param_type p1, p2, p3, p4 = last_param_def; \ - rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \ Klass *k = getPrivateData(self); \ - k->set(p1, p2, p3, p4); \ + if (argc == 1) \ + { \ + VALUE otherObj = argv[0]; \ + Klass *other = getPrivateDataCheck(otherObj, Klass##Type); \ + k->set(*other); \ + } \ + else \ + { \ + param_type p1, p2, p3, p4 = last_param_def; \ + rb_get_args(argc, argv, param_t_s, &p1, &p2, &p3, &p4 RB_ARG_END); \ + k->set(p1, p2, p3, p4); \ + } \ return self; \ } diff --git a/src/etc.cpp b/src/etc.cpp index 4eaad9d..7764c85 100644 --- a/src/etc.cpp +++ b/src/etc.cpp @@ -78,6 +78,15 @@ void Color::set(double red, double green, double blue, double alpha) updateInternal(); } +void Color::set(const Color &other) +{ + red = other.red; + green = other.green; + blue = other.blue; + alpha = other.alpha; + norm = other.norm; +} + void Color::setRed(double value) { red = value; @@ -183,6 +192,17 @@ void Tone::set(double red, double green, double blue, double gray) valueChanged(); } +void Tone::set(const Tone &other) +{ + red = other.red; + green= other.green; + blue = other.blue; + gray = other.gray; + norm = other.norm; + + valueChanged(); +} + void Tone::setRed(double value) { red = value; @@ -295,6 +315,16 @@ void Rect::set(int x, int y, int w, int h) valueChanged(); } +void Rect::set(const Rect &other) +{ + x = other.x; + y = other.y; + width = other.width; + height = other.height; + + valueChanged(); +} + void Rect::empty() { if (!(x || y || width || height)) diff --git a/src/etc.h b/src/etc.h index 3e17acf..d977569 100644 --- a/src/etc.h +++ b/src/etc.h @@ -56,6 +56,8 @@ struct Color : public Serializable void updateExternal(); void set(double red, double green, double blue, double alpha); + void set(const Color &other); + void setRed(double value); void setGreen(double value); void setBlue(double value); @@ -104,6 +106,8 @@ struct Tone : public Serializable void updateInternal(); void set(double red, double green, double blue, double gray); + void set(const Tone &other); + void setRed(double value); void setGreen(double value); void setBlue(double value); @@ -155,6 +159,7 @@ struct Rect : public Serializable bool operator==(const Rect &o) const; void operator=(const IntRect &rect); void set(int x, int y, int w, int h); + void set(const Rect &other); FloatRect toFloatRect() const {