Skip to content

Commit

Permalink
add Draw#line method
Browse files Browse the repository at this point in the history
Example:

    shape = MG::Draw.new
    shape.line([50, 100], [1000, 200], 5.0, [0.8, 0.8, 0.8, 1.0])
    add shape
  • Loading branch information
Watson1978 committed Mar 1, 2016
1 parent bde192c commit 972fd11
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,26 @@ draw_rect(VALUE rcv, SEL sel, int argc, VALUE *argv)
return rcv;
}

/// @method #line(origin, destination, thickness, color)
/// Draws a line at the given position with the given color.
/// @param origin [Point] the position where to start drawing (lower-left).
/// @param destination [Point] the position where to end drawing (higher-right).
/// @param thickness [Float] the line thickness.
/// @param color [Color] the color to use to draw.
/// @return [Draw] the receiver.

static VALUE
draw_line(VALUE rcv, SEL sel, int argc, VALUE *argv)
{
VALUE origin = Qnil, destination = Qnil, thickness = Qnil, color = Qnil;
rb_scan_args(argc, argv, "4", &origin, &destination, &thickness, &color);
DRAW(rcv)->drawSegment(rb_any_to_ccvec2(origin),
rb_any_to_ccvec2(destination),
NUM2DBL(thickness),
cocos2d::Color4F(rb_any_to_cccolor4(color)));
return rcv;
}

extern "C"
void
Init_Node(void)
Expand Down Expand Up @@ -437,4 +457,5 @@ Init_Node(void)
rb_define_singleton_method(rb_cDrawNode, "alloc", draw_alloc, 0);
rb_define_method(rb_cDrawNode, "dot", draw_dot, 3);
rb_define_method(rb_cDrawNode, "rect", draw_rect, -1);
rb_define_method(rb_cDrawNode, "line", draw_line, -1);
}

0 comments on commit 972fd11

Please # to comment.