Blender  V2.93
mask_edit.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2012 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BKE_context.h"
25 #include "BKE_mask.h"
26 
27 #include "DNA_scene_types.h"
28 
29 #include "WM_api.h"
30 #include "WM_types.h"
31 
32 #include "ED_clip.h"
33 #include "ED_image.h"
34 #include "ED_mask.h" /* own include */
35 #include "ED_sequencer.h"
36 
37 #include "RNA_access.h"
38 
39 #include "mask_intern.h" /* own include */
40 
41 /* -------------------------------------------------------------------- */
46 {
48  if (area) {
49  switch (area->spacetype) {
50  case SPACE_CLIP:
52  case SPACE_SEQ:
54  case SPACE_IMAGE:
56  }
57  }
58  return false;
59 }
60 
62 {
64  if (area) {
65  switch (area->spacetype) {
66  case SPACE_CLIP:
68  case SPACE_SEQ:
70  case SPACE_IMAGE:
72  }
73  }
74  return false;
75 }
76 
79 /* -------------------------------------------------------------------- */
84 {
86 
87  /* mask layers */
90 
91  /* add */
96 
97  /* geometry */
101 
102  /* select */
112 
113  /* hide/reveal */
116 
117  /* feather */
119 
120  /* shape */
125 
126  /* relationships */
129 
130  /* shapekeys */
135 
136  /* layers */
138 
139  /* duplicate */
141 
142  /* clipboard */
145 }
146 
148 {
149  wmKeyMap *keymap = WM_keymap_ensure(keyconf, "Mask Editing", 0, 0);
150  keymap->poll = ED_maskedit_poll;
151 }
152 
154 {
156  wmOperatorTypeMacro *otmacro;
157 
158  ot = WM_operatortype_append_macro("MASK_OT_add_vertex_slide",
159  "Add Vertex and Slide",
160  "Add new vertex and slide it",
162  ot->description = "Add new vertex and slide it";
163  WM_operatortype_macro_define(ot, "MASK_OT_add_vertex");
164  otmacro = WM_operatortype_macro_define(ot, "MASK_OT_slide_point");
165  RNA_boolean_set(otmacro->ptr, "is_new_point", true);
166 
167  ot = WM_operatortype_append_macro("MASK_OT_add_feather_vertex_slide",
168  "Add Feather Vertex and Slide",
169  "Add new vertex to feather and slide it",
171  ot->description = "Add new feather vertex and slide it";
172  WM_operatortype_macro_define(ot, "MASK_OT_add_feather_vertex");
173  otmacro = WM_operatortype_macro_define(ot, "MASK_OT_slide_point");
174  RNA_boolean_set(otmacro->ptr, "slide_feather", true);
175 
176  ot = WM_operatortype_append_macro("MASK_OT_duplicate_move",
177  "Add Duplicate",
178  "Duplicate mask and move",
180  WM_operatortype_macro_define(ot, "MASK_OT_duplicate");
181  otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
182  RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
183  RNA_boolean_set(otmacro->ptr, "mirror", false);
184 }
185 
188 /* -------------------------------------------------------------------- */
193 {
194  SpaceClip *space_clip = CTX_wm_space_clip(C);
195  if (space_clip != NULL) {
196  ED_clip_view_lock_state_store(C, &state->space_clip_state);
197  }
198 }
199 
201 {
202  SpaceClip *space_clip = CTX_wm_space_clip(C);
203  if (space_clip != NULL) {
204  if ((space_clip->flag & SC_LOCK_SELECTION) == 0) {
205  /* Early output if the editor is not locked to selection.
206  * Avoids forced dependency graph evaluation here. */
207  return;
208  }
209 
210  /* Mask's lock-to-selection requires deformed splines to be evaluated to calculate bounds of
211  * points after animation has been evaluated. The restore-no-jump type of function does
212  * calculation of new offset for the view for an updated state of mask to cancel the offset out
213  * by modifying locked offset. In order to do such calculation mask needs to be evaluated after
214  * modification by an operator. */
216  (void)depsgraph;
217 
218  ED_clip_view_lock_state_restore_no_jump(C, &state->space_clip_state);
219  }
220 }
221 
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:899
struct Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1424
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
@ SPACE_CLIP
@ SPACE_SEQ
@ SPACE_IMAGE
@ SC_LOCK_SELECTION
bool ED_space_clip_maskedit_poll(struct bContext *C)
Definition: clip_editor.c:109
void ED_clip_view_lock_state_restore_no_jump(const struct bContext *C, const ClipViewLockState *state)
bool ED_space_clip_maskedit_mask_poll(struct bContext *C)
Definition: clip_editor.c:120
void ED_clip_view_lock_state_store(const struct bContext *C, ClipViewLockState *state)
bool ED_space_image_maskedit_mask_poll(struct bContext *C)
Definition: image_edit.c:522
bool ED_space_image_maskedit_poll(struct bContext *C)
Definition: image_edit.c:494
bool ED_space_sequencer_maskedit_poll(struct bContext *C)
bool ED_space_sequencer_maskedit_mask_poll(struct bContext *C)
#define C
Definition: RandGen.cpp:39
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
const Depsgraph * depsgraph
void MASK_OT_add_feather_vertex(wmOperatorType *ot)
Definition: mask_add.c:666
void MASK_OT_primitive_square_add(wmOperatorType *ot)
Definition: mask_add.c:872
void MASK_OT_primitive_circle_add(wmOperatorType *ot)
Definition: mask_add.c:841
void MASK_OT_add_vertex(wmOperatorType *ot)
Definition: mask_add.c:574
void ED_operatormacros_mask(void)
Definition: mask_edit.c:153
void ED_keymap_mask(wmKeyConfig *keyconf)
Definition: mask_edit.c:147
void ED_mask_view_lock_state_restore_no_jump(const bContext *C, const MaskViewLockState *state)
Definition: mask_edit.c:200
bool ED_maskedit_mask_poll(bContext *C)
Definition: mask_edit.c:61
bool ED_maskedit_poll(bContext *C)
Definition: mask_edit.c:45
void ED_mask_view_lock_state_store(const bContext *C, MaskViewLockState *state)
Definition: mask_edit.c:192
void ED_operatortypes_mask(void)
Definition: mask_edit.c:83
void MASK_OT_select(struct wmOperatorType *ot)
Definition: mask_select.c:410
void MASK_OT_new(struct wmOperatorType *ot)
Definition: mask_ops.c:121
void MASK_OT_shape_key_clear(struct wmOperatorType *ot)
void MASK_OT_select_circle(struct wmOperatorType *ot)
Definition: mask_select.c:755
void MASK_OT_slide_point(struct wmOperatorType *ot)
Definition: mask_ops.c:915
void MASK_OT_hide_view_clear(struct wmOperatorType *ot)
Definition: mask_ops.c:1748
void MASK_OT_hide_view_set(struct wmOperatorType *ot)
Definition: mask_ops.c:1809
void MASK_OT_duplicate(struct wmOperatorType *ot)
Definition: mask_ops.c:2055
void MASK_OT_select_less(struct wmOperatorType *ot)
Definition: mask_select.c:994
void MASK_OT_slide_spline_curvature(struct wmOperatorType *ot)
Definition: mask_ops.c:1307
void MASK_OT_delete(struct wmOperatorType *ot)
Definition: mask_ops.c:1503
void MASK_OT_layer_new(struct wmOperatorType *ot)
Definition: mask_ops.c:157
void MASK_OT_select_linked_pick(struct wmOperatorType *ot)
Definition: mask_select.c:820
void MASK_OT_switch_direction(struct wmOperatorType *ot)
Definition: mask_ops.c:1562
void MASK_OT_shape_key_rekey(struct wmOperatorType *ot)
void MASK_OT_handle_type_set(struct wmOperatorType *ot)
Definition: mask_ops.c:1695
void MASK_OT_normals_make_consistent(struct wmOperatorType *ot)
Definition: mask_ops.c:1625
void MASK_OT_shape_key_insert(struct wmOperatorType *ot)
Definition: mask_shapekey.c:77
void MASK_OT_select_more(struct wmOperatorType *ot)
Definition: mask_select.c:974
void MASK_OT_copy_splines(struct wmOperatorType *ot)
Definition: mask_ops.c:2086
void MASK_OT_shape_key_feather_reset(struct wmOperatorType *ot)
void MASK_OT_layer_remove(struct wmOperatorType *ot)
Definition: mask_ops.c:192
void MASK_OT_select_all(struct wmOperatorType *ot)
Definition: mask_select.c:234
void MASK_OT_feather_weight_clear(struct wmOperatorType *ot)
Definition: mask_ops.c:1861
void MASK_OT_parent_clear(struct wmOperatorType *ot)
void MASK_OT_layer_move(struct wmOperatorType *ot)
Definition: mask_ops.c:1929
void MASK_OT_select_lasso(struct wmOperatorType *ot)
Definition: mask_select.c:637
void MASK_OT_select_box(struct wmOperatorType *ot)
Definition: mask_select.c:514
void MASK_OT_cyclic_toggle(struct wmOperatorType *ot)
Definition: mask_ops.c:1347
void MASK_OT_paste_splines(struct wmOperatorType *ot)
Definition: mask_ops.c:2130
void MASK_OT_select_linked(struct wmOperatorType *ot)
Definition: mask_select.c:875
void MASK_OT_parent_set(struct wmOperatorType *ot)
static ulong state[N]
static void area(int d1, int d2, int e1, int e2, float weights[2])
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
Definition: rna_access.c:6272
bool(* poll)(struct bContext *)
const char * description
Definition: WM_types.h:726
wmOperatorType * ot
Definition: wm_files.c:3156
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition: wm_keymap.c:852
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))