1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
/*
* ***** 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) 2011 Blender Foundation.
* All rights reserved.
*
*
* Contributor(s): Blender Foundation,
* Sergey Sharybin
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/editors/space_clip/clip_buttons.c
* \ingroup spclip
*/
#include <string.h>
#include <stdio.h>
#include "MEM_guardedalloc.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BKE_context.h"
#include "BKE_depsgraph.h"
#include "BKE_screen.h"
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
#include "ED_clip.h"
#include "ED_gpencil.h"
#include "UI_interface.h"
#include "UI_resources.h"
#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
#include "clip_intern.h" /* own include */
/* Panels */
static int clip_grease_pencil_panel_poll(const bContext *C, PanelType *UNUSED(pt))
{
SpaceClip *sc = CTX_wm_space_clip(C);
return sc->view == SC_VIEW_CLIP;
}
void ED_clip_buttons_register(ARegionType *art)
{
PanelType *pt;
pt = MEM_callocN(sizeof(PanelType), "spacetype clip panel gpencil");
strcpy(pt->idname, "CLIP_PT_gpencil");
strcpy(pt->label, "Grease Pencil");
pt->draw = gpencil_panel_standard;
pt->flag |= PNL_DEFAULT_CLOSED;
pt->poll = clip_grease_pencil_panel_poll;
BLI_addtail(&art->paneltypes, pt);
}
/********************* MovieClip Template ************************/
void uiTemplateMovieClip(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, int compact)
{
PropertyRNA *prop;
PointerRNA clipptr;
MovieClip *clip;
uiLayout *row, *split;
uiBlock *block;
if (!ptr->data)
return;
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
printf("%s: property not found: %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
if (RNA_property_type(prop) != PROP_POINTER) {
printf("%s: expected pointer property for %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
clipptr = RNA_property_pointer_get(ptr, prop);
clip = clipptr.data;
uiLayoutSetContextPointer(layout, "edit_movieclip", &clipptr);
if (!compact)
uiTemplateID(layout, C, ptr, propname, NULL, "CLIP_OT_open", NULL);
if (clip) {
row = uiLayoutRow(layout, 0);
block = uiLayoutGetBlock(row);
uiDefBut(block, LABEL, 0, "File Path:", 0, 19, 145, 19, NULL, 0, 0, 0, 0, "");
row = uiLayoutRow(layout, 0);
split = uiLayoutSplit(row, 0.0, 0);
row = uiLayoutRow(split, 1);
uiItemR(row, &clipptr, "filepath", 0, "", ICON_NONE);
uiItemO(row, "", ICON_FILE_REFRESH, "clip.reload");
}
}
/********************* Track Template ************************/
void uiTemplateTrack(uiLayout *layout, PointerRNA *ptr, const char *propname)
{
PropertyRNA *prop;
PointerRNA scopesptr;
uiBlock *block;
rctf rect;
MovieClipScopes *scopes;
if (!ptr->data)
return;
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
printf("%s: property not found: %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
if (RNA_property_type(prop) != PROP_POINTER) {
printf("%s: expected pointer property for %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
scopesptr = RNA_property_pointer_get(ptr, prop);
scopes = (MovieClipScopes *)scopesptr.data;
rect.xmin = 0; rect.xmax = 200;
rect.ymin = 0; rect.ymax = 120;
block = uiLayoutAbsoluteBlock(layout);
scopes->track_preview_height = (scopes->track_preview_height <= UI_UNIT_Y) ? UI_UNIT_Y : scopes->track_preview_height;
uiDefBut(block, TRACKPREVIEW, 0, "", rect.xmin, rect.ymin, rect.xmax - rect.xmin,
scopes->track_preview_height, scopes, 0, 0, 0, 0, "");
}
/********************* Marker Template ************************/
#define B_MARKER_POS 3
#define B_MARKER_OFFSET 4
#define B_MARKER_PAT_DIM 5
#define B_MARKER_SEARCH_POS 6
#define B_MARKER_SEARCH_DIM 7
#define B_MARKER_FLAG 8
typedef struct {
int compact; /* compact mode */
MovieClip *clip;
MovieClipUser *user; /* user of clip */
MovieTrackingTrack *track;
MovieTrackingMarker *marker;
int framenr; /* current frame number */
float marker_pos[2]; /* position of marker in pixel coords */
float marker_pat[2]; /* position and dimensions of marker pattern in pixel coords */
float track_offset[2]; /* offset of "parenting" point */
float marker_search_pos[2], marker_search[2]; /* position and dimensions of marker search in pixel coords */
int marker_flag; /* marker's flags */
} MarkerUpdateCb;
static void to_pixel_space(float r[2], float a[2], int width, int height)
{
copy_v2_v2(r, a);
r[0] *= width;
r[1] *= height;
}
static void marker_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
{
MarkerUpdateCb *cb = (MarkerUpdateCb *) arg_cb;
MovieTrackingMarker *marker;
if (!cb->compact)
return;
marker = BKE_tracking_ensure_marker(cb->track, cb->framenr);
marker->flag = cb->marker_flag;
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
}
static void marker_block_handler(bContext *C, void *arg_cb, int event)
{
MarkerUpdateCb *cb = (MarkerUpdateCb *) arg_cb;
MovieTrackingMarker *marker;
int width, height, ok = FALSE;
BKE_movieclip_get_size(cb->clip, cb->user, &width, &height);
marker = BKE_tracking_ensure_marker(cb->track, cb->framenr);
if (event == B_MARKER_POS) {
marker->pos[0] = cb->marker_pos[0] / width;
marker->pos[1] = cb->marker_pos[1] / height;
/* to update position of "parented" objects */
DAG_id_tag_update(&cb->clip->id, 0);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
ok = TRUE;
}
else if (event == B_MARKER_PAT_DIM) {
float dim[2], pat_dim[2], pat_min[2], pat_max[2];
float scale_x, scale_y;
int a;
BKE_tracking_marker_pattern_minmax(cb->marker, pat_min, pat_max);
sub_v2_v2v2(pat_dim, pat_max, pat_min);
dim[0] = cb->marker_pat[0] / width;
dim[1] = cb->marker_pat[1] / height;
scale_x = dim[0] / pat_dim[0];
scale_y = dim[1] / pat_dim[1];
for (a = 0; a < 4; a++) {
cb->marker->pattern_corners[a][0] *= scale_x;
cb->marker->pattern_corners[a][1] *= scale_y;
}
BKE_tracking_clamp_marker(cb->marker, CLAMP_PAT_DIM);
ok = TRUE;
}
else if (event == B_MARKER_SEARCH_POS) {
float delta[2], side[2];
sub_v2_v2v2(side, cb->marker->search_max, cb->marker->search_min);
mul_v2_fl(side, 0.5f);
delta[0] = cb->marker_search_pos[0] / width;
delta[1] = cb->marker_search_pos[1] / height;
sub_v2_v2v2(cb->marker->search_min, delta, side);
add_v2_v2v2(cb->marker->search_max, delta, side);
BKE_tracking_clamp_marker(cb->marker, CLAMP_SEARCH_POS);
ok = TRUE;
}
else if (event == B_MARKER_SEARCH_DIM) {
float dim[2], search_dim[2];
sub_v2_v2v2(search_dim, cb->marker->search_max, cb->marker->search_min);
dim[0] = cb->marker_search[0] / width;
dim[1] = cb->marker_search[1] / height;
sub_v2_v2(dim, search_dim);
mul_v2_fl(dim, 0.5f);
cb->marker->search_min[0] -= dim[0];
cb->marker->search_min[1] -= dim[1];
cb->marker->search_max[0] += dim[0];
cb->marker->search_max[1] += dim[1];
BKE_tracking_clamp_marker(cb->marker, CLAMP_SEARCH_DIM);
ok = TRUE;
}
else if (event == B_MARKER_FLAG) {
marker->flag = cb->marker_flag;
ok = TRUE;
}
else if (event == B_MARKER_OFFSET) {
float offset[2], delta[2];
int i;
offset[0] = cb->track_offset[0] / width;
offset[1] = cb->track_offset[1] / height;
sub_v2_v2v2(delta, offset, cb->track->offset);
copy_v2_v2(cb->track->offset, offset);
for (i = 0; i < cb->track->markersnr; i++)
sub_v2_v2(cb->track->markers[i].pos, delta);
/* to update position of "parented" objects */
DAG_id_tag_update(&cb->clip->id, 0);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
ok = TRUE;
}
if (ok)
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, cb->clip);
}
void uiTemplateMarker(uiLayout *layout, PointerRNA *ptr, const char *propname, PointerRNA *userptr,
PointerRNA *trackptr, int compact)
{
PropertyRNA *prop;
uiBlock *block;
uiBut *bt;
PointerRNA clipptr;
MovieClip *clip;
MovieClipUser *user;
MovieTrackingTrack *track;
MovieTrackingMarker *marker;
MarkerUpdateCb *cb;
const char *tip;
float pat_min[2], pat_max[2];
if (!ptr->data)
return;
prop = RNA_struct_find_property(ptr, propname);
if (!prop) {
printf("%s: property not found: %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
if (RNA_property_type(prop) != PROP_POINTER) {
printf("%s: expected pointer property for %s.%s\n",
__func__, RNA_struct_identifier(ptr->type), propname);
return;
}
clipptr = RNA_property_pointer_get(ptr, prop);
clip = (MovieClip *)clipptr.data;
user = userptr->data;
track = trackptr->data;
marker = BKE_tracking_get_marker(track, user->framenr);
cb = MEM_callocN(sizeof(MarkerUpdateCb), "uiTemplateMarker update_cb");
cb->compact = compact;
cb->clip = clip;
cb->user = user;
cb->track = track;
cb->marker = marker;
cb->marker_flag = marker->flag;
cb->framenr = user->framenr;
if (compact) {
block = uiLayoutGetBlock(layout);
if (cb->marker_flag & MARKER_DISABLED)
tip = "Marker is disabled at current frame";
else
tip = "Marker is enabled at current frame";
bt = uiDefIconButBitI(block, TOGN, MARKER_DISABLED, 0, ICON_RESTRICT_VIEW_OFF, 0, 0, 20, 20,
&cb->marker_flag, 0, 0, 1, 0, tip);
uiButSetNFunc(bt, marker_update_cb, cb, NULL);
}
else {
int width, height, step, digits;
float pat_dim[2], search_dim[2], search_pos[2];
uiLayout *col;
BKE_movieclip_get_size(clip, user, &width, &height);
if (track->flag & TRACK_LOCKED) {
uiLayoutSetActive(layout, 0);
block = uiLayoutAbsoluteBlock(layout);
uiDefBut(block, LABEL, 0, "Track is locked", 0, 0, 300, 19, NULL, 0, 0, 0, 0, "");
return;
}
step = 100;
digits = 2;
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
sub_v2_v2v2(pat_dim, pat_max, pat_min);
sub_v2_v2v2(search_dim, marker->search_max, marker->search_min);
add_v2_v2v2(search_pos, marker->search_max, marker->search_min);
mul_v2_fl(search_pos, 0.5);
to_pixel_space(cb->marker_pos, marker->pos, width, height);
to_pixel_space(cb->marker_pat, pat_dim, width, height);
to_pixel_space(cb->marker_search, search_dim, width, height);
to_pixel_space(cb->marker_search_pos, search_pos, width, height);
to_pixel_space(cb->track_offset, track->offset, width, height);
cb->marker_flag = marker->flag;
block = uiLayoutAbsoluteBlock(layout);
uiBlockSetHandleFunc(block, marker_block_handler, cb);
uiBlockSetNFunc(block, marker_update_cb, cb, NULL);
if (cb->marker_flag & MARKER_DISABLED)
tip = "Marker is disabled at current frame";
else
tip = "Marker is enabled at current frame";
uiDefButBitI(block, OPTIONN, MARKER_DISABLED, B_MARKER_FLAG, "Enabled", 10, 190, 145, 19, &cb->marker_flag,
0, 0, 0, 0, tip);
col = uiLayoutColumn(layout, 1);
uiLayoutSetActive(col, (cb->marker_flag & MARKER_DISABLED) == 0);
block = uiLayoutAbsoluteBlock(col);
uiBlockBeginAlign(block);
uiDefBut(block, LABEL, 0, "Position:", 0, 190, 300, 19, NULL, 0, 0, 0, 0, "");
uiDefButF(block, NUM, B_MARKER_POS, "X:", 10, 171, 145, 19, &cb->marker_pos[0],
-10 * width, 10.0 * width, step, digits, "X-position of marker at frame in screen coordinates");
uiDefButF(block, NUM, B_MARKER_POS, "Y:", 165, 171, 145, 19, &cb->marker_pos[1],
-10 * height, 10.0 * height, step, digits, "Y-position of marker at frame in screen coordinates");
uiDefBut(block, LABEL, 0, "Offset:", 0, 152, 300, 19, NULL, 0, 0, 0, 0, "");
uiDefButF(block, NUM, B_MARKER_OFFSET, "X:", 10, 133, 145, 19, &cb->track_offset[0],
-10 * width, 10.0 * width, step, digits, "X-offset to parenting point");
uiDefButF(block, NUM, B_MARKER_OFFSET, "Y:", 165, 133, 145, 19, &cb->track_offset[1],
-10 * height, 10.0 * height, step, digits, "Y-offset to parenting point");
uiDefBut(block, LABEL, 0, "Pattern Area:", 0, 114, 300, 19, NULL, 0, 0, 0, 0, "");
uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Width:", 10, 95, 300, 19, &cb->marker_pat[0], 3.0f,
10.0 * width, step, digits, "Width of marker's pattern in screen coordinates");
uiDefButF(block, NUM, B_MARKER_PAT_DIM, "Height:", 10, 76, 300, 19, &cb->marker_pat[1], 3.0f,
10.0 * height, step, digits, "Height of marker's pattern in screen coordinates");
uiDefBut(block, LABEL, 0, "Search Area:", 0, 57, 300, 19, NULL, 0, 0, 0, 0, "");
uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "X:", 10, 38, 145, 19, &cb->marker_search_pos[0],
-width, width, step, digits, "X-position of search at frame relative to marker's position");
uiDefButF(block, NUM, B_MARKER_SEARCH_POS, "Y:", 165, 38, 145, 19, &cb->marker_search_pos[1],
-height, height, step, digits, "X-position of search at frame relative to marker's position");
uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Width:", 10, 19, 300, 19, &cb->marker_search[0], 3.0f,
10.0 * width, step, digits, "Width of marker's search in screen soordinates");
uiDefButF(block, NUM, B_MARKER_SEARCH_DIM, "Height:", 10, 0, 300, 19, &cb->marker_search[1], 3.0f,
10.0 * height, step, digits, "Height of marker's search in screen soordinates");
uiBlockEndAlign(block);
}
}
|