From 6459c5b29a3b9600207533cba5a674b90edd509d Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 31 Jul 2013 17:08:31 +0100 Subject: shape node finished --- rotord/src/nodes_drawing.h | 66 +++++++++++++++++++++++++++++++++++++++------- rotord/src/rotor.h | 9 +++++++ 2 files changed, 66 insertions(+), 9 deletions(-) (limited to 'rotord/src') diff --git a/rotord/src/nodes_drawing.h b/rotord/src/nodes_drawing.h index 4d3b515..81ef590 100644 --- a/rotord/src/nodes_drawing.h +++ b/rotord/src/nodes_drawing.h @@ -5,7 +5,7 @@ #include namespace Rotor { - class Draw_node: public Image_node { + class Draw_node: public Image_node { //base class for drawing with cairo public: Draw_node(){image=nullptr;}; Draw_node(map &settings) { @@ -74,28 +74,76 @@ namespace Rotor { private: Image *image; //is an image generator }; +#define SHAPE_circle 1 +#define SHAPE_square 2 +#define SHAPE_triangle 3 class Shape: public Draw_node { public: Shape(){image=nullptr;}; Shape(map &settings) { image=nullptr; base_settings(settings); + scale=find_setting(settings,"scale",1.0f); + rotation=find_setting(settings,"rotation",0.0f); + x=find_setting(settings,"x",0.0f); + y=find_setting(settings,"y",0.0f); + colour=Colour(find_setting(settings,"colour","FFFFFF")); + string _shape=find_setting(settings,"shape","square"); + if (_shape=="circle") shape=SHAPE_circle; + if (_shape=="square") shape=SHAPE_square; + if (_shape=="triangle") shape=SHAPE_triangle; + }; + void link_params() { + for (auto p:parameter_inputs){ + if (p->parameter=="scale") { + p->receiver=&scale; + } + if (p->parameter=="rotation") { + p->receiver=&rotation; + } + if (p->parameter=="x") { + p->receiver=&x; + } + if (p->parameter=="y") { + p->receiver=&y; + } + } + }; ~Shape(){ if (image) delete image;}; Shape* clone(map &_settings) { return new Shape(_settings);}; void vector_output(cairo_t * cr,const Frame_spec &frame){ - cairo_text_extents_t te; - cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); - cairo_select_font_face (cr, "Georgia", - CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size (cr, 50); - cairo_text_extents(cr, "hello, world!", &te); - cairo_move_to (cr,(frame.w-te.width)/2,(frame.h-te.height)/2); - cairo_show_text (cr, "hello, world!"); + cairo_set_source_rgb(cr, colour.Rfloat(),colour.Gfloat(),colour.Bfloat()); + cairo_save(cr); //not really even necessary? + cairo_translate(cr, frame.w/2, frame.h/2); + cairo_translate(cr, x * frame.w, y * frame.h); + cairo_scale(cr, scale , scale ); + cairo_rotate(cr,(rotation/180.0f)*M_PI); + switch(shape) { + case SHAPE_square: + cairo_rectangle(cr,-frame.w/2,-frame.w/2,frame.w,frame.w); + break; + case SHAPE_circle: + cairo_arc(cr,0,0,frame.w/2,0.0, 2 * M_PI); + break; + case SHAPE_triangle: + //subtracting PI/2 =(1.5*PI)/3 so the triangle is pointing up + cairo_line_to(cr,0,-frame.w/2); + cairo_line_to(cr,cos((0.5 * M_PI)/3)*frame.w/2,sin((0.5 * M_PI)/3)*frame.w/2); + cairo_line_to(cr,cos((2.5 * M_PI)/3)*frame.w/2,sin((2.5 * M_PI)/3)*frame.w/2); + cairo_close_path(cr); + break; + } + cairo_restore (cr); //not really even necessary? cairo_fill(cr); } private: Image *image; //is an image generator + int shape; + float scale; + float rotation; + float x,y; + Colour colour; }; } diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index ac11b9c..62dfb39 100755 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -174,6 +174,15 @@ namespace Rotor { g=(uint8_t)ofHexToChar(s.substr(2,2)); b=(uint8_t)ofHexToChar(s.substr(4,2)); } + float Rfloat(){ + return ((float)r)/255.0f; + } + float Gfloat(){ + return ((float)g)/255.0f; + } + float Bfloat(){ + return ((float)b)/255.0f; + } uint8_t r,g,b; }; -- cgit v1.2.3