initial commit for supporting masks in the image view, currently active seq strip is used as the mask source.
also unify mask drawing code for clip/sequencer/image
This commit is contained in:
@@ -35,13 +35,22 @@ struct wmKeyConfig;
|
||||
struct MaskLayer;
|
||||
struct MaskLayerShape;
|
||||
|
||||
/* mask_editor.c */
|
||||
/* mask_edit.c */
|
||||
void ED_mask_size(const struct bContext *C, int *width, int *height);
|
||||
void ED_mask_aspect(const struct bContext *C, float *aspx, float *aspy);
|
||||
|
||||
void ED_operatortypes_mask(void);
|
||||
void ED_keymap_mask(struct wmKeyConfig *keyconf);
|
||||
void ED_operatormacros_mask(void);
|
||||
|
||||
/* mask_draw.c */
|
||||
void ED_mask_draw(const bContext *C, const char draw_flag, const char draw_type);
|
||||
void ED_mask_draw_region(struct Mask *mask, struct ARegion *ar,
|
||||
const char draw_flag, const char draw_type,
|
||||
int width, int height,
|
||||
const short do_scale_applied, const short do_post_draw,
|
||||
float stabmat[4][4],
|
||||
const bContext *C);
|
||||
|
||||
/* mask_shapekey.c */
|
||||
void ED_mask_layer_shape_auto_key(struct MaskLayer *masklay, const int frame);
|
||||
|
||||
@@ -32,17 +32,21 @@
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_math.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_mask.h"
|
||||
|
||||
#include "DNA_mask_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_object_types.h" /* SELECT */
|
||||
|
||||
#include "ED_mask.h" /* own include */
|
||||
#include "ED_space_api.h"
|
||||
#include "BIF_gl.h"
|
||||
|
||||
#include "UI_resources.h"
|
||||
#include "UI_view2d.h"
|
||||
|
||||
#include "mask_intern.h" /* own include */
|
||||
|
||||
@@ -462,3 +466,73 @@ void ED_mask_draw(const bContext *C,
|
||||
|
||||
draw_masklays(mask, draw_flag, draw_type, width, height);
|
||||
}
|
||||
|
||||
/* sets up the opengl context.
|
||||
* width, height are to match the values from ED_mask_size() */
|
||||
void ED_mask_draw_region(Mask *mask, ARegion *ar,
|
||||
const char draw_flag, const char draw_type,
|
||||
int width, int height,
|
||||
const short do_scale_applied, const short do_post_draw,
|
||||
float stabmat[4][4], /* optional - only used by clip */
|
||||
const bContext *C /* optional - only used when do_post_draw is set */
|
||||
)
|
||||
{
|
||||
struct View2D *v2d = &ar->v2d;
|
||||
|
||||
int x, y;
|
||||
int w, h;
|
||||
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);
|
||||
|
||||
w = v2d->tot.xmax - v2d->tot.xmin;
|
||||
h = 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));
|
||||
|
||||
if (do_scale_applied) {
|
||||
zoomx /= width;
|
||||
zoomy /= height;
|
||||
}
|
||||
|
||||
x += v2d->tot.xmin * zoomx;
|
||||
y += v2d->tot.ymin * zoomy;
|
||||
|
||||
/* frame the image */
|
||||
maxdim = maxf(w, h);
|
||||
if (w == h) {
|
||||
xofs = yofs = 0;
|
||||
}
|
||||
else if (w < h) {
|
||||
xofs = ((h - w) / -2.0f) * zoomx;
|
||||
yofs = 0.0f;
|
||||
}
|
||||
else { /* (width > height) */
|
||||
xofs = 0.0f;
|
||||
yofs = ((w - h) / -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);
|
||||
|
||||
if (stabmat) {
|
||||
glMultMatrixf(stabmat);
|
||||
}
|
||||
|
||||
/* draw! */
|
||||
draw_masklays(mask, draw_flag, draw_type, width, height);
|
||||
|
||||
if (do_post_draw) {
|
||||
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "ED_screen.h"
|
||||
#include "ED_mask.h" /* own include */
|
||||
#include "ED_image.h"
|
||||
#include "ED_object.h" /* ED_keymap_proportional_maskmode only */
|
||||
#include "ED_clip.h"
|
||||
#include "ED_sequencer.h"
|
||||
@@ -143,15 +144,25 @@ void ED_mask_size(const bContext *C, int *width, int *height)
|
||||
{
|
||||
ScrArea *sa = CTX_wm_area(C);
|
||||
if (sa && sa->spacedata.first) {
|
||||
if (sa->spacetype == SPACE_CLIP) {
|
||||
ED_space_clip_get_size(C, width, height);
|
||||
return;
|
||||
}
|
||||
else if (sa->spacetype == SPACE_SEQ) {
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
*width = (scene->r.size * scene->r.xsch) / 100;
|
||||
*height = (scene->r.size * scene->r.ysch) / 100;
|
||||
return;
|
||||
switch (sa->spacetype) {
|
||||
case SPACE_CLIP:
|
||||
{
|
||||
ED_space_clip_get_size(C, width, height);
|
||||
return;
|
||||
}
|
||||
case SPACE_SEQ:
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
*width = (scene->r.size * scene->r.xsch) / 100;
|
||||
*height = (scene->r.size * scene->r.ysch) / 100;
|
||||
return;
|
||||
}
|
||||
case SPACE_IMAGE:
|
||||
{
|
||||
SpaceImage *sima = sa->spacedata.first;
|
||||
ED_space_image_size(sima, width, height);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -99,9 +99,6 @@ void ED_mask_select_flush_all(struct Mask *mask);
|
||||
int ED_maskedit_poll(struct bContext *C);
|
||||
int ED_maskedit_mask_poll(struct bContext *C);
|
||||
|
||||
void ED_mask_size(const struct bContext *C, int *width, int *height);
|
||||
void ED_mask_aspect(const struct bContext *C, float *aspx, float *aspy);
|
||||
|
||||
void ED_mask_pixelspace_factor(const struct bContext *C, float *scalex, float *scaley);
|
||||
void ED_mask_mouse_pos(const struct bContext *C, struct wmEvent *event, float co[2]);
|
||||
|
||||
|
||||
@@ -1077,50 +1077,6 @@ static void clip_main_area_init(wmWindowManager *wm, ARegion *ar)
|
||||
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
|
||||
}
|
||||
|
||||
static void clip_main_area_draw_mask(const bContext *C, ARegion *ar)
|
||||
{
|
||||
SpaceClip *sc = CTX_wm_space_clip(C);
|
||||
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);
|
||||
|
||||
ED_space_clip_get_size(C, &width, &height);
|
||||
ED_space_clip_get_zoom(C, &zoomx, &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);
|
||||
glMultMatrixf(sc->stabmat);
|
||||
|
||||
ED_mask_draw(C, sc->mask_draw_flag, sc->mask_draw_type);
|
||||
|
||||
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static void clip_main_area_draw(const bContext *C, ARegion *ar)
|
||||
{
|
||||
/* draw entirely, view changes should be handled here */
|
||||
@@ -1158,7 +1114,19 @@ static void clip_main_area_draw(const bContext *C, ARegion *ar)
|
||||
clip_draw_main(C, ar);
|
||||
|
||||
if (sc->mode == SC_MODE_MASKEDIT) {
|
||||
clip_main_area_draw_mask(C, ar);
|
||||
|
||||
Mask *mask = CTX_data_edit_mask(C);
|
||||
if (mask) {
|
||||
int width, height;
|
||||
ED_mask_size(C, &width, &height);
|
||||
ED_mask_draw_region(mask, ar,
|
||||
sc->mask_draw_flag, sc->mask_draw_type,
|
||||
width, height,
|
||||
TRUE, TRUE,
|
||||
sc->stabmat, C);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Grease Pencil */
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_mask_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
@@ -53,10 +54,12 @@
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_screen.h"
|
||||
#include "BKE_tessmesh.h"
|
||||
#include "BKE_sequencer.h"
|
||||
|
||||
#include "IMB_imbuf_types.h"
|
||||
|
||||
#include "ED_image.h"
|
||||
#include "ED_mask.h"
|
||||
#include "ED_mesh.h"
|
||||
#include "ED_space_api.h"
|
||||
#include "ED_screen.h"
|
||||
@@ -580,7 +583,6 @@ static void image_dropboxes(void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void image_refresh(const bContext *C, ScrArea *UNUSED(sa))
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
@@ -693,7 +695,7 @@ static void image_listener(ScrArea *sa, wmNotifier *wmn)
|
||||
}
|
||||
}
|
||||
|
||||
const char *image_context_dir[] = {"edit_image", NULL};
|
||||
const char *image_context_dir[] = {"edit_image", "edit_mask", NULL};
|
||||
|
||||
static int image_context(const bContext *C, const char *member, bContextDataResult *result)
|
||||
{
|
||||
@@ -706,7 +708,14 @@ static int image_context(const bContext *C, const char *member, bContextDataResu
|
||||
CTX_data_id_pointer_set(result, (ID *)ED_space_image(sima));
|
||||
return 1;
|
||||
}
|
||||
|
||||
else if (CTX_data_equals(member, "edit_mask")) {
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Mask *mask = BKE_sequencer_mask_get(scene); /* XXX */
|
||||
if (mask) {
|
||||
CTX_data_id_pointer_set(result, &mask->id);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -815,7 +824,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
|
||||
|
||||
/* we set view2d from own zoom and offset each time */
|
||||
image_main_area_set_view2d(sima, ar);
|
||||
|
||||
|
||||
/* we draw image in pixelspace */
|
||||
draw_image_main(sima, ar, scene);
|
||||
|
||||
@@ -836,6 +845,19 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
|
||||
/* draw Grease Pencil - screen space only */
|
||||
draw_image_grease_pencil((bContext *)C, 0);
|
||||
|
||||
{
|
||||
Mask *mask = BKE_sequencer_mask_get(scene); /* XXX */
|
||||
if (mask) {
|
||||
int width, height;
|
||||
ED_mask_size(C, &width, &height);
|
||||
ED_mask_draw_region(mask, ar,
|
||||
0, 0, /* TODO */
|
||||
width, height,
|
||||
TRUE, FALSE,
|
||||
NULL, C);
|
||||
}
|
||||
}
|
||||
|
||||
/* scrollers? */
|
||||
#if 0
|
||||
scrollers = UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_VALUES, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
|
||||
|
||||
@@ -798,61 +798,6 @@ 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);
|
||||
@@ -1047,7 +992,17 @@ 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) {
|
||||
sequencer_main_area_draw_mask(C, scene, ar);
|
||||
Mask *mask = BKE_sequencer_mask_get(scene);
|
||||
|
||||
if (mask) {
|
||||
int width, height;
|
||||
ED_mask_size(C, &width, &height);
|
||||
ED_mask_draw_region(mask, ar,
|
||||
0, 0, /* TODO */
|
||||
width, height,
|
||||
FALSE, TRUE,
|
||||
NULL, C);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user