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"
45 #include "BKE_context.h"
46 #include "BKE_depsgraph.h"
47 #include "BKE_screen.h"
48 #include "BKE_movieclip.h"
49 #include "BKE_tracking.h"
52 #include "ED_gpencil.h"
54 #include "UI_interface.h"
55 #include "UI_resources.h"
57 #include "RNA_access.h"
62 #include "clip_intern.h" // own include
66 static int clip_grease_pencil_panel_poll(const bContext *C, PanelType *UNUSED(pt))
68 SpaceClip *sc = CTX_wm_space_clip(C);
73 void ED_clip_buttons_register(ARegionType *art)
77 pt = MEM_callocN(sizeof(PanelType), "spacetype clip panel gpencil");
78 strcpy(pt->idname, "CLIP_PT_gpencil");
79 strcpy(pt->label, "Grease Pencil");
80 pt->draw = gpencil_panel_standard;
81 pt->flag |= PNL_DEFAULT_CLOSED;
82 pt->poll = clip_grease_pencil_panel_poll;
83 BLI_addtail(&art->paneltypes, pt);
86 /********************* MovieClip Template ************************/
88 void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, int compact)
93 uiLayout *row, *split;
99 prop = RNA_struct_find_property(ptr, propname);
101 printf("%s: property not found: %s.%s\n",
102 __func__, RNA_struct_identifier(ptr->type), propname);
106 if (RNA_property_type(prop) != PROP_POINTER) {
107 printf("%s: expected pointer property for %s.%s\n",
108 __func__, RNA_struct_identifier(ptr->type), propname);
112 clipptr = RNA_property_pointer_get(ptr, prop);
115 uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
118 uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
121 row = uiLayoutRow(layout, 0);
122 block = uiLayoutGetBlock(row);
123 uiDefBut(block, LABEL, 0, "File Path:", 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
125 row = uiLayoutRow(layout, 0);
126 split = uiLayoutSplit(row, 0.0, 0);
127 row = uiLayoutRow(split, 1);
129 uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
130 uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
134 /********************* Track Template ************************/
136 void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname)
139 PointerRNA scopesptr;
142 MovieClipScopes *scopes;
147 prop = RNA_struct_find_property(ptr, propname);
149 printf("%s: property not found: %s.%s\n",
150 __func__, RNA_struct_identifier(ptr->type), propname);
154 if (RNA_property_type(prop) != PROP_POINTER) {
155 printf("%s: expected pointer property for %s.%s\n",
156 __func__, RNA_struct_identifier(ptr->type), propname);
160 scopesptr = RNA_property_pointer_get(ptr, prop);
161 scopes = (MovieClipScopes *)scopesptr.data;
163 rect.xmin = 0; rect.xmax = 200;
164 rect.ymin = 0; rect.ymax = 120;
166 block = uiLayoutAbsoluteBlock(layout);
168 scopes->track_preview_height = (scopes->track_preview_height<=UI_UNIT_Y)?UI_UNIT_Y:scopes->track_preview_height;
170 uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, rect.xmax-rect.xmin, scopes->track_preview_height, scopes, 0, 0, 0, 0, "");
173 /********************* Marker Template ************************/
175 #define B_MARKER_POS 3
176 #define B_MARKER_OFFSET 4
177 #define B_MARKER_PAT_DIM 5
178 #define B_MARKER_SEARCH_POS 6
179 #define B_MARKER_SEARCH_DIM 7
180 #define B_MARKER_FLAG 8
183 int compact; /* compact mode */
186 MovieClipUser *user; /* user of clip */
187 MovieTrackingTrack *track;
189 int framenr; /* current frame number */
190 float marker_pos[2]; /* position of marker in pixel coords */
191 float track_pat[2]; /* position and dimensions of marker pattern in pixel coords */
192 float track_offset[2]; /* offset of "parenting" point */
193 float track_search_pos[2], track_search[2]; /* position and dimensions of marker search in pixel coords */
194 int marker_flag; /* marker's flags */
197 static void to_pixel_space(float r[2], float a[2], int width, int height)
204 static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
206 MarkerUpdateCb *cb = (MarkerUpdateCb*) arg_cb;
207 MovieTrackingMarker *marker;
212 marker = BKE_tracking_ensure_marker(cb->track, cb->framenr);
214 marker->flag = cb->marker_flag;
216 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, NULL);
219 static void marker_block_handler(bContext *C, void *arg_cb, int event)
221 MarkerUpdateCb *cb = (MarkerUpdateCb*) arg_cb;
222 MovieTrackingMarker *marker;
223 int width, height, ok = FALSE;
225 BKE_movieclip_get_size(cb->clip, cb->user, &width, &height);
227 marker = BKE_tracking_ensure_marker(cb->track, cb->framenr);
229 if (event == B_MARKER_POS) {
230 marker->pos[0] = cb->marker_pos[0]/width;
231 marker->pos[1] = cb->marker_pos[1]/height;
233 /* to update position of "parented" objects */
234 DAG_id_tag_update(&cb->clip->id, 0);
235 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL);
239 else if (event == B_MARKER_PAT_DIM) {
240 float dim[2], pat_dim[2];
242 sub_v2_v2v2(pat_dim, cb->track->pat_max, cb->track->pat_min);
244 dim[0] = cb->track_pat[0] / width;
245 dim[1] = cb->track_pat[1] / height;
247 sub_v2_v2(dim, pat_dim);
248 mul_v2_fl(dim, 0.5f);
250 cb->track->pat_min[0] -= dim[0];
251 cb->track->pat_min[1] -= dim[1];
253 cb->track->pat_max[0] += dim[0];
254 cb->track->pat_max[1] += dim[1];
256 BKE_tracking_clamp_track(cb->track, CLAMP_PAT_DIM);
260 else if (event == B_MARKER_SEARCH_POS) {
261 float delta[2], side[2];
263 sub_v2_v2v2(side, cb->track->search_max, cb->track->search_min);
264 mul_v2_fl(side, 0.5f);
266 delta[0] = cb->track_search_pos[0] / width;
267 delta[1] = cb->track_search_pos[1] / height;
269 sub_v2_v2v2(cb->track->search_min, delta, side);
270 add_v2_v2v2(cb->track->search_max, delta, side);
272 BKE_tracking_clamp_track(cb->track, CLAMP_SEARCH_POS);
276 else if (event == B_MARKER_SEARCH_DIM) {
277 float dim[2], search_dim[2];
279 sub_v2_v2v2(search_dim, cb->track->search_max, cb->track->search_min);
281 dim[0] = cb->track_search[0]/width;
282 dim[1] = cb->track_search[1]/height;
284 sub_v2_v2(dim, search_dim);
285 mul_v2_fl(dim, 0.5f);
287 cb->track->search_min[0]-= dim[0];
288 cb->track->search_min[1]-= dim[1];
290 cb->track->search_max[0]+= dim[0];
291 cb->track->search_max[1]+= dim[1];
293 BKE_tracking_clamp_track(cb->track, CLAMP_SEARCH_DIM);
297 else if (event == B_MARKER_FLAG) {
298 marker->flag = cb->marker_flag;
302 else if (event == B_MARKER_OFFSET) {
303 float offset[2], delta[2];
306 offset[0] = cb->track_offset[0] / width;
307 offset[1] = cb->track_offset[1] / height;
309 sub_v2_v2v2(delta, offset, cb->track->offset);
310 copy_v2_v2(cb->track->offset, offset);
312 for (i = 0; i < cb->track->markersnr; i++)
313 sub_v2_v2(cb->track->markers[i].pos, delta);
315 /* to update position of "parented" objects */
316 DAG_id_tag_update(&cb->clip->id, 0);
317 WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, NULL);
323 WM_event_add_notifier(C, NC_MOVIECLIP|NA_EDITED, cb->clip);
326 void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr, PointerRNA *trackptr, int compact)
334 MovieTrackingTrack *track;
335 MovieTrackingMarker *marker;
342 prop = RNA_struct_find_property(ptr, propname);
344 printf("%s: property not found: %s.%s\n",
345 __func__, RNA_struct_identifier(ptr->type), propname);
349 if (RNA_property_type(prop) != PROP_POINTER) {
350 printf("%s: expected pointer property for %s.%s\n",
351 __func__, RNA_struct_identifier(ptr->type), propname);
355 clipptr = RNA_property_pointer_get(ptr, prop);
356 clip = (MovieClip *)clipptr.data;
357 user = userptr->data;
358 track = trackptr->data;
360 marker = BKE_tracking_get_marker(track, user->framenr);
362 cb = MEM_callocN(sizeof(MarkerUpdateCb), "uiTemplateMarker update_cb");
363 cb->compact = compact;
367 cb->marker_flag = marker->flag;
368 cb->framenr = user->framenr;
371 block = uiLayoutGetBlock(layout);
373 if (cb->marker_flag & MARKER_DISABLED)
374 tip= "Marker is disabled at current frame";
376 tip= "Marker is enabled at current frame";
378 bt = uiDefIconButBitI(block, TOGN, MARKER_DISABLED, 0, ICON_RESTRICT_VIEW_OFF, 0, 0, 20, 20, &cb->marker_flag, 0, 0, 1, 0, tip);
379 uiButSetNFunc(bt, marker_update_cb, cb, NULL);
382 int width, height, step, digits;
383 float pat_dim[2], pat_pos[2], search_dim[2], search_pos[2];
386 BKE_movieclip_get_size(clip, user, &width, &height);
388 if (track->flag & TRACK_LOCKED) {
389 uiLayoutSetActive(layout, 0);
390 block = uiLayoutAbsoluteBlock(layout);
391 uiDefBut(block, LABEL, 0, "Track is locked", 0, 0, 300, 19, NULL, 0, 0, 0, 0, "");
399 sub_v2_v2v2(pat_dim, track->pat_max, track->pat_min);
400 sub_v2_v2v2(search_dim, track->search_max, track->search_min);
402 add_v2_v2v2(search_pos, track->search_max, track->search_min);
403 mul_v2_fl(search_pos, 0.5);
405 add_v2_v2v2(pat_pos, track->pat_max, track->pat_min);
406 mul_v2_fl(pat_pos, 0.5);
408 to_pixel_space(cb->marker_pos, marker->pos, width, height);
409 to_pixel_space(cb->track_pat, pat_dim, width, height);
410 to_pixel_space(cb->track_search, search_dim, width, height);
411 to_pixel_space(cb->track_search_pos, search_pos, width, height);
412 to_pixel_space(cb->track_offset, track->offset, width, height);
414 cb->marker_flag = marker->flag;
416 block= uiLayoutAbsoluteBlock(layout);
417 uiBlockSetHandleFunc(block, marker_block_handler, cb);
418 uiBlockSetNFunc(block, marker_update_cb, cb, NULL);
420 if (cb->marker_flag & MARKER_DISABLED)
421 tip= "Marker is disabled at current frame";
423 tip= "Marker is enabled at current frame";
425 uiDefButBitI(block, OPTIONN, MARKER_DISABLED, B_MARKER_FLAG, "Enabled", 10, 190, 145, 19, &cb->marker_flag,
428 col = uiLayoutColumn(layout, 1);
429 uiLayoutSetActive(col, (cb->marker_flag&MARKER_DISABLED)==0);
431 block = uiLayoutAbsoluteBlock(col);
432 uiBlockBeginAlign(block);
434 uiDefBut(block, LABEL, 0, "Position:", 0, 190, 300, 19, NULL, 0, 0, 0, 0, "");
435 uiDefButF(block, NUM, B_MARKER_POS, "X:", 10, 171, 145, 19, &cb->marker_pos[0],
436 -10*width, 10.0*width, step, digits, "X-position of marker at frame in screen coordinates");
437 uiDefButF(block, NUM, B_MARKER_POS, "Y:", 165, 171, 145, 19, &cb->marker_pos[1],
438 -10*height, 10.0*height, step, digits, "Y-position of marker at frame in screen coordinates");
440 uiDefBut(block, LABEL, 0, "Offset:", 0, 152, 300, 19, NULL, 0, 0, 0, 0, "");
441 uiDefButF(block, NUM, B_MARKER_OFFSET, "X:", 10, 133, 145, 19, &cb->track_offset[0],
442 -10*width, 10.0*width, step, digits, "X-offset to parenting point");
443 uiDefButF(block, NUM, B_MARKER_OFFSET, "Y:", 165, 133, 145, 19, &cb->track_offset[1],
444 -10*height, 10.0*height, step, digits, "Y-offset to parenting point");
446 uiDefBut(block, LABEL, 0, "Pattern Area:", 0, 114, 300, 19, NULL, 0, 0, 0, 0, "");
447 uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Width:", 10, 95, 300, 19, &cb->track_pat[0], 3.0f,
448 10.0*width, step, digits, "Width of marker's pattern in screen coordinates");
449 uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Height:", 10, 76, 300, 19, &cb->track_pat[1], 3.0f,
450 10.0*height, step, digits, "Height of marker's pattern in screen coordinates");
452 uiDefBut(block, LABEL, 0, "Search Area:", 0, 57, 300, 19, NULL, 0, 0, 0, 0, "");
453 uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "X:", 10, 38, 145, 19, &cb->track_search_pos[0],
454 -width, width, step, digits, "X-position of search at frame relative to marker's position");
455 uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "Y:", 165, 38, 145, 19, &cb->track_search_pos[1],
456 -height, height, step, digits, "X-position of search at frame relative to marker's position");
457 uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Width:", 10, 19, 300, 19, &cb->track_search[0], 3.0f,
458 10.0*width, step, digits, "Width of marker's search in screen soordinates");
459 uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Height:", 10, 0, 300, 19, &cb->track_search[1], 3.0f,
460 10.0*height, step, digits, "Height of marker's search in screen soordinates");
462 uiBlockEndAlign(block);