[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49182] trunk/blender/source/blender/ editors: initial commit for supporting masks in the image view, currently active seq strip is used as the mask source.

Campbell Barton ideasman42 at gmail.com
Tue Jul 24 21:29:25 CEST 2012


Revision: 49182
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49182
Author:   campbellbarton
Date:     2012-07-24 19:29:24 +0000 (Tue, 24 Jul 2012)
Log Message:
-----------
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

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_mask.h
    trunk/blender/source/blender/editors/mask/mask_draw.c
    trunk/blender/source/blender/editors/mask/mask_edit.c
    trunk/blender/source/blender/editors/mask/mask_intern.h
    trunk/blender/source/blender/editors/space_clip/space_clip.c
    trunk/blender/source/blender/editors/space_image/space_image.c
    trunk/blender/source/blender/editors/space_sequencer/sequencer_draw.c

Modified: trunk/blender/source/blender/editors/include/ED_mask.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_mask.h	2012-07-24 18:08:17 UTC (rev 49181)
+++ trunk/blender/source/blender/editors/include/ED_mask.h	2012-07-24 19:29:24 UTC (rev 49182)
@@ -35,13 +35,22 @@
 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);

Modified: trunk/blender/source/blender/editors/mask/mask_draw.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_draw.c	2012-07-24 18:08:17 UTC (rev 49181)
+++ trunk/blender/source/blender/editors/mask/mask_draw.c	2012-07-24 19:29:24 UTC (rev 49182)
@@ -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 @@
 
 	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();
+}

Modified: trunk/blender/source/blender/editors/mask/mask_edit.c
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_edit.c	2012-07-24 18:08:17 UTC (rev 49181)
+++ trunk/blender/source/blender/editors/mask/mask_edit.c	2012-07-24 19:29:24 UTC (rev 49182)
@@ -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,16 +144,26 @@
 {
 	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;
+		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;
+			}
 		}
-		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;
-		}
 	}
 
 	/* possible other spaces from which mask editing is available */

Modified: trunk/blender/source/blender/editors/mask/mask_intern.h
===================================================================
--- trunk/blender/source/blender/editors/mask/mask_intern.h	2012-07-24 18:08:17 UTC (rev 49181)
+++ trunk/blender/source/blender/editors/mask/mask_intern.h	2012-07-24 19:29:24 UTC (rev 49182)
@@ -99,9 +99,6 @@
 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]);
 

Modified: trunk/blender/source/blender/editors/space_clip/space_clip.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-07-24 18:08:17 UTC (rev 49181)
+++ trunk/blender/source/blender/editors/space_clip/space_clip.c	2012-07-24 19:29:24 UTC (rev 49182)
@@ -1077,50 +1077,6 @@
 	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 @@
 	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 */

Modified: trunk/blender/source/blender/editors/space_image/space_image.c
===================================================================
--- trunk/blender/source/blender/editors/space_image/space_image.c	2012-07-24 18:08:17 UTC (rev 49181)
+++ trunk/blender/source/blender/editors/space_image/space_image.c	2012-07-24 19:29:24 UTC (rev 49182)
@@ -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_refresh(const bContext *C, ScrArea *UNUSED(sa))
 {
 	Scene *scene = CTX_data_scene(C);
@@ -693,7 +695,7 @@
 	}
 }
 
-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 @@
 		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 @@
 
 	/* 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 @@
 	/* 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 */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list