generalize mask poll functions and sequencer mask code.
This commit is contained in:
@@ -798,6 +798,61 @@ static void UNUSED_FUNCTION(set_special_seq_update) (int val)
|
||||
else special_seq_update = NULL;
|
||||
}
|
||||
|
||||
static void sequencer_main_area_draw_mask(const bContext *C, Scene *scene, ARegion *ar)
|
||||
{
|
||||
Mask *mask = BKE_sequencer_mask_get(scene);
|
||||
|
||||
if (mask) {
|
||||
struct View2D *v2d = &ar->v2d;
|
||||
|
||||
int x, y;
|
||||
int width, height;
|
||||
float zoomx, zoomy;
|
||||
|
||||
/* frame image */
|
||||
float maxdim;
|
||||
float xofs, yofs;
|
||||
|
||||
/* find window pixel coordinates of origin */
|
||||
UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
|
||||
|
||||
width = v2d->tot.xmax - v2d->tot.xmin;
|
||||
height = v2d->tot.ymax - v2d->tot.ymin;
|
||||
|
||||
zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin));
|
||||
zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin));
|
||||
|
||||
x += v2d->tot.xmin * zoomx;
|
||||
y += v2d->tot.ymin * zoomy;
|
||||
|
||||
/* frame the image */
|
||||
maxdim = maxf(width, height);
|
||||
if (width == height) {
|
||||
xofs = yofs = 0;
|
||||
}
|
||||
else if (width < height) {
|
||||
xofs = ((height - width) / -2.0f) * zoomx;
|
||||
yofs = 0.0f;
|
||||
}
|
||||
else { /* (width > height) */
|
||||
xofs = 0.0f;
|
||||
yofs = ((width - height) / -2.0f) * zoomy;
|
||||
}
|
||||
|
||||
/* apply transformation so mask editing tools will assume drawing from the origin in normalized space */
|
||||
glPushMatrix();
|
||||
glTranslatef(x + xofs, y + yofs, 0);
|
||||
glScalef(maxdim * zoomx, maxdim * zoomy, 0);
|
||||
|
||||
ED_mask_draw((bContext *)C, 0, 0); // sc->mask_draw_flag, sc->mask_draw_type
|
||||
|
||||
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq, int cfra, int frame_ofs)
|
||||
{
|
||||
struct Main *bmain = CTX_data_main(C);
|
||||
@@ -992,54 +1047,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
|
||||
|
||||
//if (sc->mode == SC_MODE_MASKEDIT) {
|
||||
if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
|
||||
Sequence *seq_act = BKE_sequencer_active_get(scene);
|
||||
|
||||
if (seq_act && seq_act->type == SEQ_TYPE_MASK && seq_act->mask) {
|
||||
int x, y;
|
||||
int width, height;
|
||||
float zoomx, zoomy;
|
||||
|
||||
/* frame image */
|
||||
float maxdim;
|
||||
float xofs, yofs;
|
||||
|
||||
/* find window pixel coordinates of origin */
|
||||
UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &x, &y);
|
||||
|
||||
width = v2d->tot.xmax - v2d->tot.xmin;
|
||||
height = v2d->tot.ymax - v2d->tot.ymin;
|
||||
|
||||
zoomx = (float)(ar->winrct.xmax - ar->winrct.xmin + 1) / (float)((ar->v2d.cur.xmax - ar->v2d.cur.xmin));
|
||||
zoomy = (float)(ar->winrct.ymax - ar->winrct.ymin + 1) / (float)((ar->v2d.cur.ymax - ar->v2d.cur.ymin));
|
||||
|
||||
x += v2d->tot.xmin * zoomx;
|
||||
y += v2d->tot.ymin * zoomy;
|
||||
|
||||
/* frame the image */
|
||||
maxdim = maxf(width, height);
|
||||
if (width == height) {
|
||||
xofs = yofs = 0;
|
||||
}
|
||||
else if (width < height) {
|
||||
xofs = ((height - width) / -2.0f) * zoomx;
|
||||
yofs = 0.0f;
|
||||
}
|
||||
else { /* (width > height) */
|
||||
xofs = 0.0f;
|
||||
yofs = ((width - height) / -2.0f) * zoomy;
|
||||
}
|
||||
|
||||
/* apply transformation so mask editing tools will assume drawing from the origin in normalized space */
|
||||
glPushMatrix();
|
||||
glTranslatef(x + xofs, y + yofs, 0);
|
||||
glScalef(maxdim * zoomx, maxdim * zoomy, 0);
|
||||
|
||||
ED_mask_draw((bContext *)C, 0, 0); // sc->mask_draw_flag, sc->mask_draw_type
|
||||
|
||||
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
sequencer_main_area_draw_mask(C, scene, ar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -466,6 +466,33 @@ void recurs_sel_seq(Sequence *seqm)
|
||||
}
|
||||
}
|
||||
|
||||
int ED_space_sequencer_maskedit_mask_poll(bContext *C)
|
||||
{
|
||||
/* in this case both funcs are the same, for clip editor not */
|
||||
return ED_space_sequencer_maskedit_poll(C);
|
||||
}
|
||||
|
||||
int ED_space_sequencer_check_show_maskedit(SpaceSeq *sseq, Scene *scene)
|
||||
{
|
||||
if (sseq && sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
|
||||
return (BKE_sequencer_mask_get(scene) != NULL);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int ED_space_sequencer_maskedit_poll(bContext *C)
|
||||
{
|
||||
SpaceSeq *sseq = CTX_wm_space_seq(C);
|
||||
|
||||
if (sseq) {
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
return ED_space_sequencer_check_show_maskedit(sseq, scene);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int seq_effect_find_selected(Scene *scene, Sequence *activeseq, int type, Sequence **selseq1, Sequence **selseq2, Sequence **selseq3, const char **error_str)
|
||||
{
|
||||
Editing *ed = BKE_sequencer_editing_get(scene, FALSE);
|
||||
|
||||
@@ -300,7 +300,10 @@ static void sequencer_main_area_init(wmWindowManager *wm, ARegion *ar)
|
||||
ListBase *lb;
|
||||
|
||||
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
|
||||
|
||||
|
||||
// keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
|
||||
// WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
|
||||
|
||||
keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
|
||||
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
|
||||
|
||||
@@ -409,9 +412,9 @@ static int sequencer_context(const bContext *C, const char *member, bContextData
|
||||
return TRUE;
|
||||
}
|
||||
else if (CTX_data_equals(member, "edit_mask")) {
|
||||
Sequence *seq_act = BKE_sequencer_active_get(scene);
|
||||
if (seq_act && seq_act->type == SEQ_TYPE_MASK && seq_act->mask) {
|
||||
CTX_data_id_pointer_set(result, &seq_act->mask->id);
|
||||
Mask *mask = BKE_sequencer_mask_get(scene);
|
||||
if (mask) {
|
||||
CTX_data_id_pointer_set(result, &mask->id);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -468,6 +471,9 @@ static void sequencer_preview_area_init(wmWindowManager *wm, ARegion *ar)
|
||||
|
||||
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
|
||||
|
||||
// keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
|
||||
// WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
|
||||
|
||||
keymap = WM_keymap_find(wm->defaultconf, "SequencerCommon", SPACE_SEQ, 0);
|
||||
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user