summaryrefslogtreecommitdiff
path: root/rotord/src/nodes_drawing.h
diff options
context:
space:
mode:
Diffstat (limited to 'rotord/src/nodes_drawing.h')
-rw-r--r--rotord/src/nodes_drawing.h109
1 files changed, 38 insertions, 71 deletions
diff --git a/rotord/src/nodes_drawing.h b/rotord/src/nodes_drawing.h
index 81ef590..c44527d 100644
--- a/rotord/src/nodes_drawing.h
+++ b/rotord/src/nodes_drawing.h
@@ -5,60 +5,50 @@
#include <cairo.h>
namespace Rotor {
- class Draw_node: public Image_node { //base class for drawing with cairo
+ class Draw_node: public Image_node {
public:
- Draw_node(){image=nullptr;};
- Draw_node(map<string,string> &settings) {
- image=nullptr;
+ Draw_node(){
+ create_image_input("image input","Image input");
+ //no title or description as it isn't intended for the user
};
- ~Draw_node(){ if (image) delete image;};
+ Draw_node(map<string,string> &settings):Draw_node() {
+ };
+ ~Draw_node(){};
Draw_node* clone(map<string,string> &_settings) { return new Draw_node(_settings);};
virtual void vector_output(cairo_t * cr,const Frame_spec &frame){};
Image *output(const Frame_spec &frame){
- //get new or input image to draw upon
- if (image_inputs.size()) {
- if (image_inputs[0]->connection){
- //copy incoming image **writable
- if (image) delete image;
- image=(((Image_node*)image_inputs[0]->connection)->get_output(frame))->clone();
- }
- else {
- if (!image) image =new Image();
- image->setup(frame.w,frame.h);
- }
+ Image *in=image_inputs[0]->get(frame);
+ if (in){
+ image=(*in);
}
- else {
- if (!image) image =new Image();
- image->setup(frame.w,frame.h); //do this twice or use a goto
- }
//convert to 32 bit - this can probably be optimised further
cv::Mat chans;
- cv::cvtColor(image->rgb, chans, CV_BGR2RGBA, 4);
+ cv::cvtColor(image.rgb, chans, CV_BGR2RGBA, 4);
cairo_surface_t * cs = cairo_image_surface_create_for_data (chans.data,
CAIRO_FORMAT_RGB24,
- image->w,
- image->h,
- image->w*4);
+ image.w,
+ image.h,
+ image.w*4);
cairo_t * cr = cairo_create (cs);
//do any kind of vector drawing
vector_output(cr,frame);
//convert frame back to 24 bits
- cv::cvtColor(chans,image->rgb,CV_RGBA2BGR,3);
+ cv::cvtColor(chans,image.rgb,CV_RGBA2BGR,3);
cairo_destroy(cr);
cairo_surface_destroy(cs);
- return image;
+ return &image;
}
private:
- Image *image; //is an image generator
};
class Hello_draw: public Draw_node {
public:
- Hello_draw(){image=nullptr;};
+ Hello_draw(){
+ //no title or description as it isn't intended for the user
+ };
Hello_draw(map<string,string> &settings) {
- image=nullptr;
base_settings(settings);
};
- ~Hello_draw(){ if (image) delete image;};
+ ~Hello_draw(){};
Hello_draw* clone(map<string,string> &_settings) { return new Hello_draw(_settings);};
void vector_output(cairo_t * cr,const Frame_spec &frame){
cairo_text_extents_t te;
@@ -72,54 +62,36 @@ namespace Rotor {
cairo_fill(cr);
}
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<string,string> &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;
+ Shape(){
+ title="Shape";
+ description="Draws filled shapes";
+ create_parameter("x","number","X coordinate","X",0.0f);
+ create_parameter("y","number","Y coordinate","Y",0.0f);
+ create_parameter("scale","number","Scale","Scale",1.0f);
+ create_parameter("rotation","number","Rotation","Rotation",0.0f);
+ create_attribute("colour","Colour to fill","Colour","FFFFFF");
+ create_attribute("shape","Shape to draw","Shape","square",{"circle","square","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(map<string,string> &settings):Shape() {
+ base_settings(settings);
+ colour=Colour(attributes["colour"]->value);
};
- ~Shape(){ if (image) delete image;};
+ ~Shape(){};
Shape* clone(map<string,string> &_settings) { return new Shape(_settings);};
void vector_output(cairo_t * cr,const Frame_spec &frame){
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) {
+ cairo_translate(cr, parameters["x"]->value * frame.w, parameters["y"]->value * frame.h);
+ cairo_scale(cr, parameters["scale"]->value , parameters["scale"]->value );
+ cairo_rotate(cr,(parameters["rotation"]->value/180.0f)*M_PI);
+ switch(attributes["shape"]->intVal) {
case SHAPE_square:
cairo_rectangle(cr,-frame.w/2,-frame.w/2,frame.w,frame.w);
break;
@@ -138,13 +110,8 @@ namespace Rotor {
cairo_fill(cr);
}
private:
- Image *image; //is an image generator
- int shape;
- float scale;
- float rotation;
- float x,y;
Colour colour;
};
}
-#endif \ No newline at end of file
+#endif