mask/image editor now works for border select and lasso
authorCampbell Barton <ideasman42@gmail.com>
Thu, 26 Jul 2012 09:54:52 +0000 (09:54 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 26 Jul 2012 09:54:52 +0000 (09:54 +0000)
release/scripts/startup/bl_ui/space_image.py
source/blender/editors/include/ED_image.h
source/blender/editors/include/ED_mask.h
source/blender/editors/include/ED_uvedit.h
source/blender/editors/mask/mask_edit.c
source/blender/editors/mask/mask_intern.h
source/blender/editors/mask/mask_select.c
source/blender/editors/space_image/image_edit.c
source/blender/editors/space_image/space_image.c
source/blender/editors/uvedit/uvedit_draw.c
source/blender/makesdna/DNA_space_types.h

index d8af9e2e5a4de44423c05cda0d13444996046217..b72e8273e831e7ddb44168ddfc7cda595a53c6aa 100644 (file)
@@ -409,6 +409,10 @@ class IMAGE_HT_header(Header):
             row = layout.row()
             row.template_ID(sima, "mask", new="mask.new")
 
+            # reused for mask
+            uvedit = sima.uv_editor
+            layout.prop(uvedit, "pivot_point", text="", icon_only=True)
+
         if ima:
             # layers
             layout.template_image_layers(ima, iuser)
index 393a400b7bdb2d460c19cf2543c1797a110d4cdf..6edbe33de329eda13fe8a3a16215ea7313d12e3b 100644 (file)
@@ -63,6 +63,8 @@ void ED_image_get_size(struct Image *ima, int *width, int *height);
 void ED_image_get_aspect(struct Image *ima, float *aspx, float *aspy);
 void ED_image_get_uv_aspect(struct Image *ima, float *aspx, float *aspy);
 void ED_image_mouse_pos(struct SpaceImage *sima, struct ARegion *ar, struct wmEvent *event, float co[2]);
+void ED_image_point_pos(struct SpaceImage *sima, struct ARegion *ar, float x, float y, float *xr, float *yr);
+void ED_image_point_pos__reverse(struct SpaceImage *sima, struct ARegion *ar, const float co[2], float r_co[2]);
 
 int ED_space_image_show_render(struct SpaceImage *sima);
 int ED_space_image_show_paint(struct SpaceImage *sima);
index e155f6a9d0293da39799cbd5301838c6a6c259e7..758fe6367bb9caafe17c337c7d35c78defb1b2fc 100644 (file)
@@ -37,6 +37,7 @@ struct MaskLayerShape;
 
 /* mask_edit.c */
 void ED_mask_size(const struct bContext *C, int *width, int *height);
+void ED_mask_zoom(const struct bContext *C, float *zoomx, float *zoomy);
 void ED_mask_aspect(const struct bContext *C, float *aspx, float *aspy);
 
 void ED_operatortypes_mask(void);
index 2427ed1a3338c87e527c76839abd539d0d20d162..56f8a455c526fd0fc9603aa6ab16e3d2187ccb40 100644 (file)
@@ -85,6 +85,7 @@ void ED_uvedit_live_unwrap(struct Scene *scene, struct Object *obedit);
 void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel);
 
 /* uvedit_draw.c */
+void draw_image_cursor(struct SpaceImage *sima, struct ARegion *ar);
 void draw_uvedit_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene, struct Object *obedit, struct Object *obact);
 
 /* uvedit_buttons.c */
index 6a5e5c03345d3bcb36dec19858358c73d91359e3..0491b164fec830de57970fae007a68f5868c6f3d 100644 (file)
@@ -155,8 +155,15 @@ void ED_mask_point_pos(const bContext *C, float x, float y, float *xr, float *yr
                                break;
                        case SPACE_IMAGE:
                        {
-                               //SpaceImage *sima = sa->spacedata.first;
-                               zero_v2(co); /* MASKTODO */
+                               int width, height;
+                               float frame_size[2];
+                               SpaceImage *sima = sa->spacedata.first;
+                               ARegion *ar = CTX_wm_region(C);
+                               ED_space_image_get_size(sima, &width, &height);
+                               frame_size[0] = width;
+                               frame_size[1] = height;
+                               ED_image_point_pos(sima, ar, x, y, &co[0], &co[1]);
+                               BKE_mask_coord_from_frame(co, co, frame_size);
                                break;
                        }
                        default:
@@ -195,8 +202,21 @@ void ED_mask_point_pos__reverse(const bContext *C, float x, float y, float *xr,
                                zero_v2(co); /* MASKTODO */
                                break;
                        case SPACE_IMAGE:
-                               zero_v2(co); /* MASKTODO */
+                       {
+                               int width, height;
+                               float frame_size[2];
+                               SpaceImage *sima = sa->spacedata.first;
+                               ARegion *ar = CTX_wm_region(C);
+                               ED_space_image_get_size(sima, &width, &height);
+                               frame_size[0] = width;
+                               frame_size[1] = height;
+
+                               co[0] = x;
+                               co[1] = y;
+                               BKE_mask_coord_to_frame(co, co, frame_size);
+                               ED_image_point_pos__reverse(sima, ar, co, co);
                                break;
+                       }
                        default:
                                /* possible other spaces from which mask editing is available */
                                BLI_assert(0);
@@ -251,6 +271,41 @@ void ED_mask_size(const bContext *C, int *width, int *height)
        }
 }
 
+void ED_mask_zoom(const bContext *C, float *zoomx, float *zoomy)
+{
+       ScrArea *sa = CTX_wm_area(C);
+       if (sa && sa->spacedata.first) {
+               switch (sa->spacetype) {
+                       case SPACE_CLIP:
+                       {
+                               ED_space_clip_get_zoom(C, zoomx, zoomy);
+                               break;
+                       }
+                       case SPACE_SEQ:
+                       {
+                               *zoomx = *zoomy = 1.0f;
+                               break;
+                       }
+                       case SPACE_IMAGE:
+                       {
+                               SpaceImage *sima = sa->spacedata.first;
+                               ARegion *ar = CTX_wm_region(C);
+                               ED_space_image_get_zoom(sima, ar, zoomx, zoomy);
+                               break;
+                       }
+                       default:
+                               /* possible other spaces from which mask editing is available */
+                               BLI_assert(0);
+                               *zoomx = *zoomy = 1.0f;
+                               break;
+               }
+       }
+       else {
+               BLI_assert(0);
+               *zoomx = *zoomy = 1.0f;
+       }
+}
+
 void ED_mask_aspect(const bContext *C, float *aspx, float *aspy)
 {
        ScrArea *sa = CTX_wm_area(C);
@@ -472,6 +527,8 @@ void ED_keymap_mask(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "MASK_OT_shape_key_insert", IKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "MASK_OT_shape_key_clear", IKEY, KM_PRESS, KM_ALT, 0);
 
+       /* for image editor only */
+       WM_keymap_add_item(keymap, "UV_OT_cursor_set", ACTIONMOUSE, KM_PRESS, 0, 0);
 
        transform_keymap_for_space(keyconf, keymap, SPACE_CLIP);
 }
index 70dafc963ec04a0f03796c00f3f138131fd167fa..b4ff4bc5b31c9f620faa114657e1634f925e9aca 100644 (file)
@@ -105,6 +105,9 @@ void ED_mask_mouse_pos(const struct bContext *C, struct wmEvent *event, float co
 void ED_mask_point_pos(const struct bContext *C, float x, float y, float *xr, float *yr);
 void ED_mask_point_pos__reverse(const struct bContext *C, float x, float y, float *xr, float *yr);
 
+void ED_mask_get_zoom(const bContext *C, float *zoomx, float *zoomy);
+void ED_mask_get_size(const bContext *C, float *zoomx, float *zoomy);
+
 /* mask_shapekey.c */
 void MASK_OT_shape_key_insert(struct wmOperatorType *ot);
 void MASK_OT_shape_key_clear(struct wmOperatorType *ot);
index c7f917548ce7edab6d6d734d0884e2e05c412c7d..565beaf34ef1b659ff6b8724b938940ecb16645b 100644 (file)
@@ -592,10 +592,9 @@ static int circle_select_exec(bContext *C, wmOperator *op)
 
        mode = RNA_int_get(op->ptr, "gesture_mode");
 
-       /* TODO - make generic! - this is SpaceClip only! */
        /* compute ellipse and position in unified coordinates */
-       ED_space_clip_get_size(C, &width, &height);
-       ED_space_clip_get_zoom(C, &zoomx, &zoomy);
+       ED_mask_size(C, &width, &height);
+       ED_mask_zoom(C, &zoomx, &zoomy);
        width = height = MAX2(width, height);
 
        ellipse[0] = width * zoomx / radius;
@@ -639,7 +638,6 @@ static int circle_select_exec(bContext *C, wmOperator *op)
        return OPERATOR_CANCELLED;
 }
 
-/* MASKTODO - image space */
 void MASK_OT_select_circle(wmOperatorType *ot)
 {
        /* identifiers */
index f80210fe4d7cba1edf4e81858dfe416ef7420a76..927f65f239b0188982b5111d0ac683cc44dd4886 100644 (file)
@@ -266,6 +266,34 @@ void ED_image_mouse_pos(SpaceImage *sima, ARegion *ar, wmEvent *event, float co[
        co[1] = ((event->mval[1] - sy) / zoomy) / height;
 }
 
+void ED_image_point_pos(SpaceImage *sima, ARegion *ar, float x, float y, float *xr, float *yr)
+{
+       int sx, sy, width, height;
+       float zoomx, zoomy;
+
+       ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+       ED_space_image_get_size(sima, &width, &height);
+
+       UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+
+       *xr = ((x - sx) / zoomx) / width;
+       *yr = ((y - sy) / zoomy) / height;
+}
+
+void ED_image_point_pos__reverse(SpaceImage *sima, ARegion *ar, const float co[2], float r_co[2])
+{
+       float zoomx, zoomy;
+       int width, height;
+       int sx, sy;
+
+       UI_view2d_to_region_no_clip(&ar->v2d, 0.0f, 0.0f, &sx, &sy);
+       ED_space_image_get_size(sima, &width, &height);
+       ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
+
+       r_co[0] = (co[0] * width  * zoomx) + (float)sx;
+       r_co[1] = (co[1] * height * zoomy) + (float)sy;
+}
+
 int ED_space_image_show_render(SpaceImage *sima)
 {
        return (sima->image && ELEM(sima->image->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE));
index 3c9c46c1c75e0327ecacb0ffdd72a1058e321056..55e22a999bce0a5001f8aafb778ecddf2e684955 100644 (file)
@@ -585,6 +585,7 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
        SpaceImage *sima = CTX_wm_space_image(C);
        Object *obact = CTX_data_active_object(C);
        Object *obedit = CTX_data_edit_object(C);
+       Mask *mask = NULL;
        Scene *scene = CTX_data_scene(C);
        View2D *v2d = &ar->v2d;
        //View2DScrollers *scrollers;
@@ -611,6 +612,15 @@ static void image_main_area_draw(const bContext *C, ARegion *ar)
        UI_view2d_view_ortho(v2d);
        draw_uvedit_main(sima, ar, scene, obedit, obact);
 
+       /* check for mask (delay draw) */
+       if (obedit) {
+               /* pass */
+       }
+       else if (sima->mode == SI_MODE_MASK) {
+               mask = ED_space_image_get_mask(sima);
+               draw_image_cursor(sima, ar);
+       }
+
        ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
 
        /* Grease Pencil too (in addition to UV's) */
@@ -624,17 +634,16 @@ 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 = ED_space_image_get_mask(sima);
-               if (mask) {
-                       int width, height;
-                       ED_mask_size(C, &width, &height);
-                       ED_mask_draw_region(mask, ar,
-                                           sima->mask_info.draw_flag, sima->mask_info.draw_type,
-                                           width, height,
-                                           TRUE, FALSE,
-                                           NULL, C);
-               }
+       if (mask) {
+               int width, height;
+               ED_mask_size(C, &width, &height);
+               ED_mask_draw_region(mask, ar,
+                                   sima->mask_info.draw_flag, sima->mask_info.draw_type,
+                                   width, height,
+                                   TRUE, FALSE,
+                                   NULL, C);
+
+               draw_image_cursor(sima, ar);
        }
 
        /* scrollers? */
index 55dfbc8a0df62341929d4e808ce134f6c68cc290..1f78bc6bddf695eed4bed882fcd9b9b2db354769 100644 (file)
@@ -63,7 +63,7 @@
 
 #include "uvedit_intern.h"
 
-static void drawcursor_sima(SpaceImage *sima, ARegion *ar)
+void draw_image_cursor(SpaceImage *sima, ARegion *ar)
 {
        float zoomx, zoomy, w, h;
        int width, height;
@@ -889,7 +889,7 @@ void draw_uvedit_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedi
                        draw_uvs_texpaint(sima, scene, obact);
 
                if (show_uvedit && !(toolsettings->use_uv_sculpt))
-                       drawcursor_sima(sima, ar);
+                       draw_image_cursor(sima, ar);
        }
 }
 
index 49ea9af31e40d7ea03cc4e4834e759a8dd59ae29..ca2917cb03b485af095fd998f309541357680915 100644 (file)
@@ -722,7 +722,7 @@ typedef enum eSpaceImage_UVDT_Stretch {
 typedef enum eSpaceImage_Mode {
        SI_MODE_VIEW  = 0,
        SI_MODE_PAINT = 1,
-       SI_MODE_MASK  = 2
+       SI_MODE_MASK  = 2   /* note: mesh edit mode overrides mask */
 } eSpaceImage_Mode;
 
 /* SpaceImage->sticky