mask parenting operator, and clear parenting. (Ctrl+P, Alt+P)

- also use offset now with parenting.
- draw line from point to parent.
This commit is contained in:
Campbell Barton
2012-05-21 11:09:53 +00:00
parent 130e7ab6f4
commit ebd87e18df
6 changed files with 230 additions and 2 deletions

View File

@@ -757,7 +757,7 @@ void BKE_mask_coord_to_movieclip(MovieClip *clip, MovieClipUser *user, float r_c
}
}
static void evaluate_mask_parent(MaskParent *parent, float ctime, float co[2])
static void evaluate_mask_parent(MaskParent *parent, float ctime, float r_co[2])
{
if (!parent)
return;
@@ -779,7 +779,8 @@ static void evaluate_mask_parent(MaskParent *parent, float ctime, float co[2])
if (track) {
MovieTrackingMarker *marker = BKE_tracking_get_marker(track, ctime);
BKE_mask_coord_from_movieclip(clip, &user, co, marker->pos);
BKE_mask_coord_from_movieclip(clip, &user, r_co, marker->pos);
add_v2_v2(r_co, parent->offset);
}
}
}

View File

@@ -40,6 +40,7 @@ set(SRC
mask_draw.c
mask_editor.c
mask_ops.c
mask_relationships.c
mask_intern.h
)

View File

@@ -62,6 +62,36 @@ static void set_spline_color(MaskObject *maskobj, MaskSpline *spline)
}
}
static void draw_spline_parents(MaskObject *UNUSED(maskobj), MaskSpline *spline)
{
int i;
if (!spline->tot_point)
return;
glColor3ub(0, 0, 0);
glEnable(GL_LINE_STIPPLE);
glLineStipple(1, 0xAAAA);
glBegin(GL_LINES);
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
if (point->parent.flag & MASK_PARENT_ACTIVE) {
glVertex2f(point->bezt.vec[1][0],
point->bezt.vec[1][1]);
glVertex2f(point->bezt.vec[1][0] - point->parent.offset[0],
point->bezt.vec[1][1] - point->parent.offset[1]);
}
}
glEnd();
glDisable(GL_LINE_STIPPLE);
}
/* return non-zero if spline is selected */
static void draw_spline_points(MaskObject *maskobj, MaskSpline *spline)
{
@@ -227,6 +257,8 @@ static void draw_maskobjs(Mask *mask)
/* draw curve itself first... */
draw_spline_curve(maskobj, spline);
draw_spline_parents(maskobj, spline);
/* ...and then handles over the curve so they're nicely visible */
draw_spline_points(maskobj, spline);
}

View File

@@ -163,6 +163,10 @@ void ED_operatortypes_mask(void)
WM_operatortype_append(MASK_OT_slide_point);
WM_operatortype_append(MASK_OT_cyclic_toggle);
WM_operatortype_append(MASK_OT_handle_type_set);
/* relationships */
WM_operatortype_append(MASK_OT_parent_set);
WM_operatortype_append(MASK_OT_parent_clear);
}
void ED_keymap_mask(wmKeyConfig *keyconf)
@@ -196,6 +200,10 @@ void ED_keymap_mask(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "MASK_OT_slide_point", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "MASK_OT_handle_type_set", VKEY, KM_PRESS, 0, 0);
/* relationships */
WM_keymap_add_item(keymap, "MASK_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "MASK_OT_parent_set", PKEY, KM_PRESS, KM_ALT, 0);
transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
}

View File

@@ -56,6 +56,10 @@ void MASK_OT_delete(struct wmOperatorType *ot);
void MASK_OT_handle_type_set(struct wmOperatorType *ot);
/* mask_relationships.c */
void MASK_OT_parent_set(struct wmOperatorType *ot);
void MASK_OT_parent_clear(struct wmOperatorType *ot);
/* mask_editor.c */
int ED_maskediting_poll(struct bContext *C);
int ED_maskediting_mask_poll(struct bContext *C);

View File

@@ -0,0 +1,182 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2012 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation,
* Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/mask/mask_ops.c
* \ingroup edmask
*/
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_depsgraph.h"
#include "BKE_mask.h"
#include "BKE_tracking.h"
#include "DNA_mask_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h" /* SELECT */
#include "WM_api.h"
#include "WM_types.h"
#include "ED_screen.h"
#include "ED_mask.h"
#include "ED_clip.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "mask_intern.h" /* own include */
static int mask_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
{
Mask *mask = CTX_data_edit_mask(C);
MaskObject *maskobj;
for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
MaskSpline *spline;
int i;
for (spline = maskobj->splines.first; spline; spline = spline->next) {
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
if (MASKPOINT_ISSEL(point)) {
point->parent.flag &= ~MASK_PARENT_ACTIVE;
}
}
}
}
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
DAG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
void MASK_OT_parent_clear(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Clear Parent";
ot->description = "Clear the masks parenting";
ot->idname = "MASK_OT_parent_clear";
/* api callbacks */
ot->invoke = WM_menu_invoke;
ot->exec = mask_parent_clear_exec;
ot->poll = ED_operator_object_active_editable;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
static int mask_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
{
Mask *mask = CTX_data_edit_mask(C);
MaskObject *maskobj;
/* parent info */
SpaceClip *sc;
MovieClip *clip;
MovieTrackingTrack *track;
MovieTrackingMarker *marker;
MovieTrackingObject *tracking;
/* done */
float parmask_pos[2];
if ((NULL == (sc = CTX_wm_space_clip(C))) ||
(NULL == (clip = sc->clip)) ||
(NULL == (track = clip->tracking.act_track)) ||
(NULL == (marker = BKE_tracking_get_marker(track, sc->user.framenr))) ||
(NULL == (tracking = BKE_tracking_active_object(&clip->tracking))))
{
return OPERATOR_CANCELLED;
}
BKE_mask_coord_from_movieclip(clip, &sc->user, parmask_pos, marker->pos);
for (maskobj = mask->maskobjs.first; maskobj; maskobj = maskobj->next) {
MaskSpline *spline;
int i;
for (spline = maskobj->splines.first; spline; spline = spline->next) {
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &spline->points[i];
if (MASKPOINT_ISSEL(point)) {
BezTriple *bezt = &point->bezt;
float tvec[2];
point->parent.id_type = ID_MC;
point->parent.id = &clip->id;
strcpy(point->parent.parent, tracking->name);
strcpy(point->parent.sub_parent, track->name);
point->parent.flag |= MASK_PARENT_ACTIVE;
sub_v2_v2v2(tvec, parmask_pos, bezt->vec[1]);
add_v2_v2(bezt->vec[0], tvec);
add_v2_v2(bezt->vec[1], tvec);
add_v2_v2(bezt->vec[2], tvec);
negate_v2_v2(point->parent.offset, tvec);
}
}
}
}
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
DAG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
/** based on #OBJECT_OT_parent_set */
void MASK_OT_parent_set(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Make Parent";
ot->description = "Set the masks parenting";
ot->idname = "MASK_OT_parent_set";
/* api callbacks */
//ot->invoke = mask_parent_set_invoke;
ot->exec = mask_parent_set_exec;
ot->poll = ED_operator_object_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}