#include "reflex/ruby/style.h" #include #include #include "reflex/ruby/selector.h" #include "defs.h" #include "selector.h" RUCY_DEFINE_VALUE_FROM_TO(Reflex::Style) #define THIS to< Reflex::Style*>(self) #define C_THIS to(self) #define CHECK RUCY_CHECK_OBJ(Reflex::Style, self) static VALUE alloc(VALUE klass) { return new_type(klass); } static VALUE initialize_copy(VALUE self, VALUE obj) { CHECK; *THIS = to(obj); return self; } static VALUE set_flow(VALUE self) { CHECK; check_arg_count(__FILE__, __LINE__, "Style#set_flow", argc, 1, 2); if (argv[0].is_nil()) { if (argc >= 2 && !argv[1].is_nil()) argument_error(__FILE__, __LINE__); THIS->clear_flow(); } else { THIS->set_flow( (Reflex::Style::Flow) to(argv[0]), argc >= 2 ? (Reflex::Style::Flow) to(argv[1]) : Reflex::Style::FLOW_NONE); } return value(argc, argv); } static VALUE get_flow(VALUE self) { CHECK; Reflex::Style::Flow main, sub; THIS->get_flow(&main, &sub); return array(main, sub); } static VALUE set_width(VALUE self, VALUE width) { CHECK; if (width.is_nil()) THIS->clear_width(); else THIS->set_width(to(width)); return width; } static VALUE get_width(VALUE self) { CHECK; return value(THIS->width()); } static VALUE set_height(VALUE self, VALUE height) { CHECK; if (height.is_nil()) THIS->clear_height(); else THIS->set_height(to(height)); return height; } static VALUE get_height(VALUE self) { CHECK; return value(THIS->height()); } static VALUE set_size(VALUE self) { CHECK; check_arg_count(__FILE__, __LINE__, "Style#set_size", argc, 1, 2); set_width( self, argv[0]); set_height(self, argc >= 2 ? argv[1] : argv[0]); return value(argc, argv); } static VALUE get_size(VALUE self) { CHECK; return array( get_width(self), get_height(self)); } static VALUE set_left(VALUE self, VALUE left) { CHECK; if (left.is_nil()) THIS->clear_left(); else THIS->set_left(to(left)); return left; } static VALUE get_left(VALUE self) { CHECK; return value(THIS->left()); } static VALUE set_top(VALUE self, VALUE top) { CHECK; if (top.is_nil()) THIS->clear_top(); else THIS->set_top(to(top)); return top; } static VALUE get_top(VALUE self) { CHECK; return value(THIS->top()); } static VALUE set_right(VALUE self, VALUE right) { CHECK; if (right.is_nil()) THIS->clear_right(); else THIS->set_right(to(right)); return right; } static VALUE get_right(VALUE self) { CHECK; return value(THIS->right()); } static VALUE set_bottom(VALUE self, VALUE bottom) { CHECK; if (bottom.is_nil()) THIS->clear_bottom(); else THIS->set_bottom(to(bottom)); return bottom; } static VALUE get_bottom(VALUE self) { CHECK; return value(THIS->bottom()); } static VALUE set_position(VALUE self, VALUE left, VALUE top, VALUE right, VALUE bottom) { CHECK; set_left( self, left); set_top( self, top); set_right( self, right); set_bottom(self, bottom); return array(left, top, right, bottom); } static VALUE get_position(VALUE self) { CHECK; return array( get_left(self), get_top(self), get_right(self), get_bottom(self)); } static VALUE set_margin_left(VALUE self, VALUE left) { CHECK; if (left.is_nil()) THIS->clear_margin_left(); else THIS->set_margin_left(to(left)); return left; } static VALUE get_margin_left(VALUE self) { CHECK; return value(THIS->margin_left()); } static VALUE set_margin_top(VALUE self, VALUE top) { CHECK; if (top.is_nil()) THIS->clear_margin_top(); else THIS->set_margin_top(to(top)); return top; } static VALUE get_margin_top(VALUE self) { CHECK; return value(THIS->margin_top()); } static VALUE set_margin_right(VALUE self, VALUE right) { CHECK; if (right.is_nil()) THIS->clear_margin_right(); else THIS->set_margin_right(to(right)); return right; } static VALUE get_margin_right(VALUE self) { CHECK; return value(THIS->margin_right()); } static VALUE set_margin_bottom(VALUE self, VALUE bottom) { CHECK; if (bottom.is_nil()) THIS->clear_margin_bottom(); else THIS->set_margin_bottom(to(bottom)); return bottom; } static VALUE get_margin_bottom(VALUE self) { CHECK; return value(THIS->margin_bottom()); } static VALUE set_margin(VALUE self, VALUE left, VALUE top, VALUE right, VALUE bottom) { CHECK; set_margin_left( self, left); set_margin_top( self, top); set_margin_right( self, right); set_margin_bottom(self, bottom); return array(left, top, right, bottom); } static VALUE get_margin(VALUE self) { CHECK; return array( get_margin_left(self), get_margin_top(self), get_margin_right(self), get_margin_bottom(self)); } static VALUE set_padding_left(VALUE self, VALUE left) { CHECK; if (left.is_nil()) THIS->clear_padding_left(); else THIS->set_padding_left(to(left)); return left; } static VALUE get_padding_left(VALUE self) { CHECK; return value(THIS->padding_left()); } static VALUE set_padding_top(VALUE self, VALUE top) { CHECK; if (top.is_nil()) THIS->clear_padding_top(); else THIS->set_padding_top(to(top)); return top; } static VALUE get_padding_top(VALUE self) { CHECK; return value(THIS->padding_top()); } static VALUE set_padding_right(VALUE self, VALUE right) { CHECK; if (right.is_nil()) THIS->clear_padding_right(); else THIS->set_padding_right(to(right)); return right; } static VALUE get_padding_right(VALUE self) { CHECK; return value(THIS->padding_right()); } static VALUE set_padding_bottom(VALUE self, VALUE bottom) { CHECK; if (bottom.is_nil()) THIS->clear_padding_bottom(); else THIS->set_padding_bottom(to(bottom)); return bottom; } static VALUE get_padding_bottom(VALUE self) { CHECK; return value(THIS->padding_bottom()); } static VALUE set_padding(VALUE self, VALUE left, VALUE top, VALUE right, VALUE bottom) { CHECK; set_padding_left( self, left); set_padding_top( self, top); set_padding_right( self, right); set_padding_bottom(self, bottom); return array(left, top, right, bottom); } static VALUE get_padding(VALUE self) { CHECK; return array( get_padding_left(self), get_padding_top(self), get_padding_right(self), get_padding_bottom(self)); } static VALUE set_center_x(VALUE self, VALUE x) { CHECK; if (x.is_nil()) THIS->clear_center_x(); else THIS->set_center_x(to(x)); return x; } static VALUE get_center_x(VALUE self) { CHECK; return value(THIS->center_x()); } static VALUE set_center_y(VALUE self, VALUE y) { CHECK; if (y.is_nil()) THIS->clear_center_y(); else THIS->set_center_y(to(y)); return y; } static VALUE get_center_y(VALUE self) { CHECK; return value(THIS->center_y()); } static VALUE set_center(VALUE self, VALUE x, VALUE y) { CHECK; set_center_x(self, x); set_center_y(self, y); return array(x, y); } static VALUE get_center(VALUE self) { CHECK; return array( get_center_x(self), get_center_y(self)); } static VALUE set_foreground_fill(VALUE self) { CHECK; check_arg_count( __FILE__, __LINE__, "Style#set_foreground_fill", argc, 1, 2, 3, 4); if (argv[0].is_nil()) { if (argc != 1) argument_error(__FILE__, __LINE__); THIS->clear_foreground_fill(); return argv[0]; } else { Reflex::Color color = to(argc, argv); THIS->set_foreground_fill(color); return value(color); } } static VALUE set_foreground_stroke(VALUE self) { CHECK; check_arg_count( __FILE__, __LINE__, "Style#set_foreground_stroke", argc, 1, 2, 3, 4); if (argv[0].is_nil()) { if (argc != 1) argument_error(__FILE__, __LINE__); THIS->clear_foreground_stroke(); return argv[0]; } else { Reflex::Color color = to(argc, argv); THIS->set_foreground_stroke(color); return value(color); } } static VALUE set_foreground_stroke_width(VALUE self, VALUE width) { CHECK; if (width.is_nil()) THIS->clear_foreground_stroke_width(); else THIS->set_foreground_stroke_width(to(width)); return width; } static VALUE set_background_fill(VALUE self) { CHECK; check_arg_count( __FILE__, __LINE__, "Style#set_background_fill", argc, 1, 2, 3, 4); if (argv[0].is_nil()) { if (argc != 1) argument_error(__FILE__, __LINE__); THIS->clear_background_fill(); return argv[0]; } else { Reflex::Color color = to(argc, argv); THIS->set_background_fill(color); return value(color); } } static VALUE set_background_stroke(VALUE self) { CHECK; check_arg_count( __FILE__, __LINE__, "Style#set_background_stroke", argc, 1, 2, 3, 4); if (argv[0].is_nil()) { if (argc != 1) argument_error(__FILE__, __LINE__); THIS->clear_background_stroke(); return argv[0]; } else { Reflex::Color color = to(argc, argv); THIS->set_background_stroke(color); return value(color); } } static VALUE set_background_stroke_width(VALUE self, VALUE width) { CHECK; if (width.is_nil()) THIS->clear_background_stroke_width(); else THIS->set_background_stroke_width(to(width)); return width; } static VALUE get_foreground_fill(VALUE self) { CHECK; return value(THIS->foreground_fill()); } static VALUE get_foreground_stroke(VALUE self) { CHECK; return value(THIS->foreground_stroke()); } static VALUE get_foreground_stroke_width(VALUE self) { CHECK; return value(THIS->foreground_stroke_width()); } static VALUE get_background_fill(VALUE self) { CHECK; return value(THIS->background_fill()); } static VALUE get_background_stroke(VALUE self) { CHECK; return value(THIS->background_stroke()); } static VALUE get_background_stroke_width(VALUE self) { CHECK; return value(THIS->background_stroke_width()); } static VALUE set_image(VALUE self, VALUE image) { CHECK; if (image.is_nil()) THIS->clear_image(); else THIS->set_image(to(image)); return image; } static VALUE get_image(VALUE self) { CHECK; return THIS->image() ? value(THIS->image()) : nil(); } static VALUE equal(VALUE self, VALUE style) { CHECK; return value(*THIS == to(style)); } static Class cStyle; void Init_reflex_style () { Module mReflex = rb_define_module("Reflex"); cStyle = rb_define_class_under(mReflex, "Style", rb_cObject); rb_define_alloc_func(cStyle, alloc); rb_define_private_method(cStyle, "initialize_copy", RUBY_METHOD_FUNC(initialize_copy), 1); rb_define_method(cStyle, "set_flow", RUBY_METHOD_FUNC(set_flow), -1); rb_define_method(cStyle, "get_flow", RUBY_METHOD_FUNC(get_flow), 0); rb_define_method(cStyle, "width=", RUBY_METHOD_FUNC(set_width), 1); rb_define_method(cStyle, "width", RUBY_METHOD_FUNC(get_width), 0); rb_define_method(cStyle, "height=", RUBY_METHOD_FUNC(set_height), 1); rb_define_method(cStyle, "height", RUBY_METHOD_FUNC(get_height), 0); rb_define_method(cStyle, "size=", RUBY_METHOD_FUNC(set_size), -1); rb_define_method(cStyle, "size", RUBY_METHOD_FUNC(get_size), 0); rb_define_method(cStyle, "left=", RUBY_METHOD_FUNC(set_left), 1); rb_define_method(cStyle, "left", RUBY_METHOD_FUNC(get_left), 0); rb_define_method(cStyle, "top=", RUBY_METHOD_FUNC(set_top), 1); rb_define_method(cStyle, "top", RUBY_METHOD_FUNC(get_top), 0); rb_define_method(cStyle, "right=", RUBY_METHOD_FUNC(set_right), 1); rb_define_method(cStyle, "right", RUBY_METHOD_FUNC(get_right), 0); rb_define_method(cStyle, "bottom=", RUBY_METHOD_FUNC(set_bottom), 1); rb_define_method(cStyle, "bottom", RUBY_METHOD_FUNC(get_bottom), 0); rb_define_method(cStyle, "position=", RUBY_METHOD_FUNC(set_position), 4); rb_define_method(cStyle, "position", RUBY_METHOD_FUNC(get_position), 0); rb_define_method(cStyle, "margin_left=", RUBY_METHOD_FUNC(set_margin_left), 1); rb_define_method(cStyle, "margin_left", RUBY_METHOD_FUNC(get_margin_left), 0); rb_define_method(cStyle, "margin_top=", RUBY_METHOD_FUNC(set_margin_top), 1); rb_define_method(cStyle, "margin_top", RUBY_METHOD_FUNC(get_margin_top), 0); rb_define_method(cStyle, "margin_right=", RUBY_METHOD_FUNC(set_margin_right), 1); rb_define_method(cStyle, "margin_right", RUBY_METHOD_FUNC(get_margin_right), 0); rb_define_method(cStyle, "margin_bottom=", RUBY_METHOD_FUNC(set_margin_bottom), 1); rb_define_method(cStyle, "margin_bottom", RUBY_METHOD_FUNC(get_margin_bottom), 0); rb_define_method(cStyle, "margin=", RUBY_METHOD_FUNC(set_margin), 4); rb_define_method(cStyle, "margin", RUBY_METHOD_FUNC(get_margin), 0); rb_define_method(cStyle, "padding_left=", RUBY_METHOD_FUNC(set_padding_left), 1); rb_define_method(cStyle, "padding_left", RUBY_METHOD_FUNC(get_padding_left), 0); rb_define_method(cStyle, "padding_top=", RUBY_METHOD_FUNC(set_padding_top), 1); rb_define_method(cStyle, "padding_top", RUBY_METHOD_FUNC(get_padding_top), 0); rb_define_method(cStyle, "padding_right=", RUBY_METHOD_FUNC(set_padding_right), 1); rb_define_method(cStyle, "padding_right", RUBY_METHOD_FUNC(get_padding_right), 0); rb_define_method(cStyle, "padding_bottom=", RUBY_METHOD_FUNC(set_padding_bottom), 1); rb_define_method(cStyle, "padding_bottom", RUBY_METHOD_FUNC(get_padding_bottom), 0); rb_define_method(cStyle, "padding=", RUBY_METHOD_FUNC(set_padding), 4); rb_define_method(cStyle, "padding", RUBY_METHOD_FUNC(get_padding), 0); rb_define_method(cStyle, "center_x=", RUBY_METHOD_FUNC(set_center_x), 1); rb_define_method(cStyle, "center_x", RUBY_METHOD_FUNC(get_center_x), 0); rb_define_method(cStyle, "center_y=", RUBY_METHOD_FUNC(set_center_y), 1); rb_define_method(cStyle, "center_y", RUBY_METHOD_FUNC(get_center_y), 0); rb_define_method(cStyle, "center=", RUBY_METHOD_FUNC(set_center), 2); rb_define_method(cStyle, "center", RUBY_METHOD_FUNC(get_center), 0); rb_define_method(cStyle, "foreground_fill=", RUBY_METHOD_FUNC(set_foreground_fill), -1); rb_define_method(cStyle, "foreground_fill", RUBY_METHOD_FUNC(get_foreground_fill), 0); rb_define_method(cStyle, "foreground_stroke=", RUBY_METHOD_FUNC(set_foreground_stroke), -1); rb_define_method(cStyle, "foreground_stroke", RUBY_METHOD_FUNC(get_foreground_stroke), 0); rb_define_method(cStyle, "foreground_stroke_width=", RUBY_METHOD_FUNC(set_foreground_stroke_width), 1); rb_define_method(cStyle, "foreground_stroke_width", RUBY_METHOD_FUNC(get_foreground_stroke_width), 0); rb_define_method(cStyle, "background_fill=", RUBY_METHOD_FUNC(set_background_fill), -1); rb_define_method(cStyle, "background_fill", RUBY_METHOD_FUNC(get_background_fill), 0); rb_define_method(cStyle, "background_stroke=", RUBY_METHOD_FUNC(set_background_stroke), -1); rb_define_method(cStyle, "background_stroke", RUBY_METHOD_FUNC(get_background_stroke), 0); rb_define_method(cStyle, "background_stroke_width=", RUBY_METHOD_FUNC(set_background_stroke_width), 1); rb_define_method(cStyle, "background_stroke_width", RUBY_METHOD_FUNC(get_background_stroke_width), 0); rb_define_method(cStyle, "image=", RUBY_METHOD_FUNC(set_image), 1); rb_define_method(cStyle, "image", RUBY_METHOD_FUNC(get_image), 0); cStyle.define_method("==", equal); cStyle.define_const("FLOW_NONE", Reflex::Style::FLOW_NONE); cStyle.define_const("FLOW_DOWN", Reflex::Style::FLOW_DOWN); cStyle.define_const("FLOW_RIGHT", Reflex::Style::FLOW_RIGHT); cStyle.define_const("FLOW_UP", Reflex::Style::FLOW_UP); cStyle.define_const("FLOW_LEFT", Reflex::Style::FLOW_LEFT); define_selector_methods(cStyle); } namespace Reflex { Class style_class () { return cStyle; } }// Reflex