2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2011 Blender Foundation.
19 * All rights reserved.
22 * Contributor(s): Blender Foundation,
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file blender/editors/space_clip/clip_buttons.c
35 #include "MEM_guardedalloc.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
42 #include "BLI_utildefines.h"
43 #include "BLI_listbase.h"
46 #include "BLF_translation.h"
48 #include "BKE_context.h"
49 #include "BKE_depsgraph.h"
50 #include "BKE_screen.h"
51 #include "BKE_movieclip.h"
52 #include "BKE_tracking.h"
55 #include "ED_gpencil.h"
57 #include "UI_interface.h"
58 #include "UI_resources.h"
60 #include "RNA_access.h"
65 #include "clip_intern.h" /* own include */
69 static int clip_grease_pencil_panel_poll(const bContext *C, PanelType *UNUSED(pt))
71 SpaceClip *sc = CTX_wm_space_clip(C);
73 return sc->view == SC_VIEW_CLIP;
76 void ED_clip_buttons_register(ARegionType *art)
80 pt = MEM_callocN(sizeof(PanelType), "spacetype clip panel gpencil");
81 strcpy(pt->idname, "CLIP_PT_gpencil");
82 strcpy(pt->label, "Grease Pencil");
83 pt->draw_header = gpencil_panel_standard_header;
84 pt->draw = gpencil_panel_standard;
85 pt->flag |= PNL_DEFAULT_CLOSED;
86 pt->poll = clip_grease_pencil_panel_poll;
87 BLI_addtail(&art->paneltypes, pt);
90 /********************* MovieClip Template ************************/
92 void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, int compact)
97 uiLayout *row, *split;
103 prop = RNA_struct_find_property(ptr, propname);
105 printf("%s: property not found: %s.%s\n",
106 __func__, RNA_struct_identifier(ptr->type), propname);
110 if (RNA_property_type(prop) != PROP_POINTER) {
111 printf("%s: expected pointer property for %s.%s\n",
112 __func__, RNA_struct_identifier(ptr->type), propname);
116 clipptr = RNA_property_pointer_get(ptr, prop);
119 uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
122 uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
127 row = uiLayoutRow(layout, FALSE);
128 block = uiLayoutGetBlock(row);
129 uiDefBut(block, LABEL, 0, IFACE_("File Path:"), 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
131 row = uiLayoutRow(layout, FALSE);
132 split = uiLayoutSplit(row, 0.0f, FALSE);
133 row = uiLayoutRow(split, TRUE);
135 uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
136 uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
138 col = uiLayoutColumn(layout, FALSE);
139 uiTemplateColorspaceSettings(col, &clipptr, "colorspace_settings");
143 /********************* Track Template ************************/
145 void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname)
148 PointerRNA scopesptr;
151 MovieClipScopes *scopes;
156 prop = RNA_struct_find_property(ptr, propname);
158 printf("%s: property not found: %s.%s\n",
159 __func__, RNA_struct_identifier(ptr->type), propname);
163 if (RNA_property_type(prop) != PROP_POINTER) {
164 printf("%s: expected pointer property for %s.%s\n",
165 __func__, RNA_struct_identifier(ptr->type), propname);
169 scopesptr = RNA_property_pointer_get(ptr, prop);
170 scopes = (MovieClipScopes *)scopesptr.data;
172 rect.xmin = 0; rect.xmax = 10.0f * UI_UNIT_X;
173 rect.ymin = 0; rect.ymax = 6.0f * UI_UNIT_Y;
175 block = uiLayoutAbsoluteBlock(layout);
177 scopes->track_preview_height =
178 (scopes->track_preview_height <= 20) ? 20 : scopes->track_preview_height;
180 uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, BLI_rctf_size_x(&rect),
181 scopes->track_preview_height * UI_DPI_FAC, scopes, 0, 0, 0, 0, "");
184 /********************* Marker Template ************************/
186 #define B_MARKER_POS 3
187 #define B_MARKER_OFFSET 4
188 #define B_MARKER_PAT_DIM 5
189 #define B_MARKER_SEARCH_POS 6
190 #define B_MARKER_SEARCH_DIM 7
191 #define B_MARKER_FLAG 8
194 int compact; /* compact mode */
197 MovieClipUser *user; /* user of clip */
198 MovieTrackingTrack *track;
199 MovieTrackingMarker *marker;
201 int framenr; /* current frame number */
202 float marker_pos[2]; /* position of marker in pixel coords */
203 float marker_pat[2]; /* position and dimensions of marker pattern in pixel coords */
204 float track_offset[2]; /* offset of "parenting" point */
205 float marker_search_pos[2], marker_search[2]; /* position and dimensions of marker search in pixel coords */
206 int marker_flag; /* marker's flags */
209 static void to_pixel_space(float r[2], float a[2], int width, int height)
216 static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
218 MarkerUpdateCb *cb = (MarkerUpdateCb *) arg_cb;
219 MovieTrackingMarker *marker;
224 marker = BKE_tracking_marker_ensure(cb->track, cb->framenr);
226 marker->flag = cb->marker_flag;
228 WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
231 static void marker_block_handler(bContext *C, void *arg_cb, int event)
233 MarkerUpdateCb *cb = (MarkerUpdateCb *) arg_cb;
234 MovieTrackingMarker *marker;
235 int width, height, ok = FALSE;
237 BKE_movieclip_get_size(cb->clip, cb->user, &width, &height);
239 marker = BKE_tracking_marker_ensure(cb->track, cb->framenr);
241 if (event == B_MARKER_POS) {
242 marker->pos[0] = cb->marker_pos[0] / width;
243 marker->pos[1] = cb->marker_pos[1] / height;
245 /* to update position of "parented" objects */
246 DAG_id_tag_update(&cb->clip->id, 0);
247 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
251 else if (event == B_MARKER_PAT_DIM) {
252 float dim[2], pat_dim[2], pat_min[2], pat_max[2];
253 float scale_x, scale_y;
256 BKE_tracking_marker_pattern_minmax(cb->marker, pat_min, pat_max);
258 sub_v2_v2v2(pat_dim, pat_max, pat_min);
260 dim[0] = cb->marker_pat[0] / width;
261 dim[1] = cb->marker_pat[1] / height;
263 scale_x = dim[0] / pat_dim[0];
264 scale_y = dim[1] / pat_dim[1];
266 for (a = 0; a < 4; a++) {
267 cb->marker->pattern_corners[a][0] *= scale_x;
268 cb->marker->pattern_corners[a][1] *= scale_y;
271 BKE_tracking_marker_clamp(cb->marker, CLAMP_PAT_DIM);
275 else if (event == B_MARKER_SEARCH_POS) {
276 float delta[2], side[2];
278 sub_v2_v2v2(side, cb->marker->search_max, cb->marker->search_min);
279 mul_v2_fl(side, 0.5f);
281 delta[0] = cb->marker_search_pos[0] / width;
282 delta[1] = cb->marker_search_pos[1] / height;
284 sub_v2_v2v2(cb->marker->search_min, delta, side);
285 add_v2_v2v2(cb->marker->search_max, delta, side);
287 BKE_tracking_marker_clamp(cb->marker, CLAMP_SEARCH_POS);
291 else if (event == B_MARKER_SEARCH_DIM) {
292 float dim[2], search_dim[2];
294 sub_v2_v2v2(search_dim, cb->marker->search_max, cb->marker->search_min);
296 dim[0] = cb->marker_search[0] / width;
297 dim[1] = cb->marker_search[1] / height;
299 sub_v2_v2(dim, search_dim);
300 mul_v2_fl(dim, 0.5f);
302 cb->marker->search_min[0] -= dim[0];
303 cb->marker->search_min[1] -= dim[1];
305 cb->marker->search_max[0] += dim[0];
306 cb->marker->search_max[1] += dim[1];
308 BKE_tracking_marker_clamp(cb->marker, CLAMP_SEARCH_DIM);
312 else if (event == B_MARKER_FLAG) {
313 marker->flag = cb->marker_flag;
317 else if (event == B_MARKER_OFFSET) {
318 float offset[2], delta[2];
321 offset[0] = cb->track_offset[0] / width;
322 offset[1] = cb->track_offset[1] / height;
324 sub_v2_v2v2(delta, offset, cb->track->offset);
325 copy_v2_v2(cb->track->offset, offset);
327 for (i = 0; i < cb->track->markersnr; i++)
328 sub_v2_v2(cb->track->markers[i].pos, delta);
330 /* to update position of "parented" objects */
331 DAG_id_tag_update(&cb->clip->id, 0);
332 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
338 WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, cb->clip);
341 void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr,
342 PointerRNA *trackptr, int compact)
350 MovieTrackingTrack *track;
351 MovieTrackingMarker *marker;
354 float pat_min[2], pat_max[2];
359 prop = RNA_struct_find_property(ptr, propname);
361 printf("%s: property not found: %s.%s\n",
362 __func__, RNA_struct_identifier(ptr->type), propname);
366 if (RNA_property_type(prop) != PROP_POINTER) {
367 printf("%s: expected pointer property for %s.%s\n",
368 __func__, RNA_struct_identifier(ptr->type), propname);
372 clipptr = RNA_property_pointer_get(ptr, prop);
373 clip = (MovieClip *)clipptr.data;
374 user = userptr->data;
375 track = trackptr->data;
377 marker = BKE_tracking_marker_get(track, user->framenr);
379 cb = MEM_callocN(sizeof(MarkerUpdateCb), "uiTemplateMarker update_cb");
380 cb->compact = compact;
385 cb->marker_flag = marker->flag;
386 cb->framenr = user->framenr;
389 block = uiLayoutGetBlock(layout);
391 if (cb->marker_flag & MARKER_DISABLED)
392 tip = TIP_("Marker is disabled at current frame");
394 tip = TIP_("Marker is enabled at current frame");
396 bt = uiDefIconButBitI(block, TOGN, MARKER_DISABLED, 0, ICON_RESTRICT_VIEW_OFF, 0, 0, UI_UNIT_X, UI_UNIT_Y,
397 &cb->marker_flag, 0, 0, 1, 0, tip);
398 uiButSetNFunc(bt, marker_update_cb, cb, NULL);
401 int width, height, step, digits;
402 float pat_dim[2], search_dim[2], search_pos[2];
405 BKE_movieclip_get_size(clip, user, &width, &height);
407 if (track->flag & TRACK_LOCKED) {
408 uiLayoutSetActive(layout, FALSE);
409 block = uiLayoutAbsoluteBlock(layout);
410 uiDefBut(block, LABEL, 0, IFACE_("Track is locked"), 0, 0, UI_UNIT_X*15.0f, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
418 BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
420 sub_v2_v2v2(pat_dim, pat_max, pat_min);
421 sub_v2_v2v2(search_dim, marker->search_max, marker->search_min);
423 add_v2_v2v2(search_pos, marker->search_max, marker->search_min);
424 mul_v2_fl(search_pos, 0.5);
426 to_pixel_space(cb->marker_pos, marker->pos, width, height);
427 to_pixel_space(cb->marker_pat, pat_dim, width, height);
428 to_pixel_space(cb->marker_search, search_dim, width, height);
429 to_pixel_space(cb->marker_search_pos, search_pos, width, height);
430 to_pixel_space(cb->track_offset, track->offset, width, height);
432 cb->marker_flag = marker->flag;
434 block = uiLayoutAbsoluteBlock(layout);
435 uiBlockSetHandleFunc(block, marker_block_handler, cb);
436 uiBlockSetNFunc(block, marker_update_cb, cb, NULL);
438 if (cb->marker_flag & MARKER_DISABLED)
439 tip = TIP_("Marker is disabled at current frame");
441 tip = TIP_("Marker is enabled at current frame");
443 uiDefButBitI(block, OPTIONN, MARKER_DISABLED, B_MARKER_FLAG, IFACE_("Enabled"), 10, 190, 145, 19,
444 &cb->marker_flag, 0, 0, 0, 0, tip);
446 col = uiLayoutColumn(layout, TRUE);
447 uiLayoutSetActive(col, (cb->marker_flag & MARKER_DISABLED) == 0);
449 block = uiLayoutAbsoluteBlock(col);
450 uiBlockBeginAlign(block);
452 uiDefBut(block, LABEL, 0, IFACE_("Position:"), 0, 190, 300, 19, NULL, 0, 0, 0, 0, "");
453 uiDefButF(block, NUM, B_MARKER_POS, IFACE_("X:"), 10, 171, 145, 19, &cb->marker_pos[0],
454 -10 * width, 10.0 * width, step, digits, TIP_("X-position of marker at frame in screen coordinates"));
455 uiDefButF(block, NUM, B_MARKER_POS, IFACE_("Y:"), 165, 171, 145, 19, &cb->marker_pos[1],
456 -10 * height, 10.0 * height, step, digits,
457 TIP_("Y-position of marker at frame in screen coordinates"));
459 uiDefBut(block, LABEL, 0, IFACE_("Offset:"), 0, 152, 300, 19, NULL, 0, 0, 0, 0, "");
460 uiDefButF(block, NUM, B_MARKER_OFFSET, IFACE_("X:"), 10, 133, 145, 19, &cb->track_offset[0],
461 -10 * width, 10.0 * width, step, digits, TIP_("X-offset to parenting point"));
462 uiDefButF(block, NUM, B_MARKER_OFFSET, IFACE_("Y:"), 165, 133, 145, 19, &cb->track_offset[1],
463 -10 * height, 10.0 * height, step, digits, TIP_("Y-offset to parenting point"));
465 uiDefBut(block, LABEL, 0, IFACE_("Pattern Area:"), 0, 114, 300, 19, NULL, 0, 0, 0, 0, "");
466 uiDefButF(block, NUM, B_MARKER_PAT_DIM, IFACE_("Width:"), 10, 95, 300, 19, &cb->marker_pat[0], 3.0f,
467 10.0 * width, step, digits, TIP_("Width of marker's pattern in screen coordinates"));
468 uiDefButF(block, NUM, B_MARKER_PAT_DIM, IFACE_("Height:"), 10, 76, 300, 19, &cb->marker_pat[1], 3.0f,
469 10.0 * height, step, digits, TIP_("Height of marker's pattern in screen coordinates"));
471 uiDefBut(block, LABEL, 0, IFACE_("Search Area:"), 0, 57, 300, 19, NULL, 0, 0, 0, 0, "");
472 uiDefButF(block, NUM, B_MARKER_SEARCH_POS, IFACE_("X:"), 10, 38, 145, 19, &cb->marker_search_pos[0],
473 -width, width, step, digits, TIP_("X-position of search at frame relative to marker's position"));
474 uiDefButF(block, NUM, B_MARKER_SEARCH_POS, IFACE_("Y:"), 165, 38, 145, 19, &cb->marker_search_pos[1],
475 -height, height, step, digits, TIP_("Y-position of search at frame relative to marker's position"));
476 uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, IFACE_("Width:"), 10, 19, 300, 19, &cb->marker_search[0], 3.0f,
477 10.0 * width, step, digits, TIP_("Width of marker's search in screen coordinates"));
478 uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, IFACE_("Height:"), 10, 0, 300, 19, &cb->marker_search[1], 3.0f,
479 10.0 * height, step, digits, TIP_("Height of marker's search in screen coordinates"));
481 uiBlockEndAlign(block);