diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index c1b888fcf83..a9e5e871669 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -707,12 +707,20 @@ static void node_composit_buts_crop(uiLayout *layout, bContext *C, PointerRNA *p uiLayout *col; uiItemR(layout, ptr, "use_crop_size", 0, NULL, 0); - + uiItemR(layout, ptr, "relative", 0, NULL, 0); + col= uiLayoutColumn(layout, 1); - uiItemR(col, ptr, "min_x", 0, "Left", 0); - uiItemR(col, ptr, "max_x", 0, "Right", 0); - uiItemR(col, ptr, "min_y", 0, "Up", 0); - uiItemR(col, ptr, "max_y", 0, "Down", 0); + if (RNA_boolean_get(ptr, "relative")){ + uiItemR(col, ptr, "rel_min_x", 0, "Left", 0); + uiItemR(col, ptr, "rel_max_x", 0, "Right", 0); + uiItemR(col, ptr, "rel_min_y", 0, "Up", 0); + uiItemR(col, ptr, "rel_max_y", 0, "Down", 0); + } else { + uiItemR(col, ptr, "min_x", 0, "Left", 0); + uiItemR(col, ptr, "max_x", 0, "Right", 0); + uiItemR(col, ptr, "min_y", 0, "Up", 0); + uiItemR(col, ptr, "max_y", 0, "Down", 0); + } } static void node_composit_buts_splitviewer(uiLayout *layout, bContext *C, PointerRNA *ptr) diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index e3ac90bf881..fe422bfa689 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -255,6 +255,7 @@ typedef struct NodeChroma { typedef struct NodeTwoXYs { short x1, x2, y1, y2; + float fac_x1, fac_x2, fac_y1, fac_y2; } NodeTwoXYs; typedef struct NodeTwoFloats { diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 71469f7dd31..5044518ca93 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1637,7 +1637,12 @@ static void def_cmp_crop(StructRNA *srna) RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1); RNA_def_property_ui_text(prop, "Crop Image Size", "Whether to crop the size of the input image"); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); - + + prop = RNA_def_property(srna, "relative", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1); + RNA_def_property_ui_text(prop, "Relative", "Use relative values to crop image"); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + RNA_def_struct_sdna_from(srna, "NodeTwoXYs", "storage"); prop = RNA_def_property(srna, "min_x", PROP_INT, PROP_NONE); @@ -1663,6 +1668,30 @@ static void def_cmp_crop(StructRNA *srna) RNA_def_property_range(prop, 0, 10000); RNA_def_property_ui_text(prop, "Y2", ""); RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "rel_min_x", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "fac_x1"); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "X1", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "rel_max_x", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "fac_x2"); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "X2", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "rel_min_y", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "fac_y1"); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Y1", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "rel_max_y", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "fac_y2"); + RNA_def_property_range(prop, 0.0, 1.0); + RNA_def_property_ui_text(prop, "Y2", ""); + RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update"); } static void def_cmp_dblur(StructRNA *srna) diff --git a/source/blender/nodes/intern/CMP_nodes/CMP_crop.c b/source/blender/nodes/intern/CMP_nodes/CMP_crop.c index c2edb3dd52f..dd5ce88bd36 100644 --- a/source/blender/nodes/intern/CMP_nodes/CMP_crop.c +++ b/source/blender/nodes/intern/CMP_nodes/CMP_crop.c @@ -48,7 +48,14 @@ static void node_composit_exec_crop(void *data, bNode *node, bNodeStack **in, bN CompBuf *stackbuf; int x, y; float *srcfp, *outfp; - rcti outputrect; + rcti outputrect; + + if(node->custom2) { + ntxy->x1= cbuf->x* ntxy->fac_x1; + ntxy->x2= cbuf->x* ntxy->fac_x2; + ntxy->y1= cbuf->y* ntxy->fac_y1; + ntxy->y2= cbuf->y* ntxy->fac_y2; + } /* check input image size */ if(cbuf->x <= ntxy->x1 + 1)