forked from bartvdbraak/blender
mask/image editor now works for border select and lasso
This commit is contained in:
parent
c8ce3b76ff
commit
77e7ca6aa8
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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));
|
||||
|
@ -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? */
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user