diff options
Diffstat (limited to 'source/blender/editors/space_image/space_image.c')
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 95 |
1 files changed, 77 insertions, 18 deletions
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index bac3b9f8df7..54037059cc3 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -44,10 +44,15 @@ #include "BKE_colortools.h" #include "BKE_context.h" +#include "BKE_editmesh.h" #include "BKE_image.h" +#include "BKE_layer.h" #include "BKE_library.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_material.h" + +#include "DEG_depsgraph.h" #include "IMB_imbuf_types.h" @@ -59,6 +64,7 @@ #include "ED_space_api.h" #include "ED_screen.h" #include "ED_uvedit.h" +#include "ED_transform.h" #include "BIF_gl.h" @@ -275,7 +281,7 @@ static void image_operatortypes(void) WM_operatortype_append(IMAGE_OT_change_frame); - WM_operatortype_append(IMAGE_OT_read_renderlayers); + WM_operatortype_append(IMAGE_OT_read_viewlayers); WM_operatortype_append(IMAGE_OT_render_border); WM_operatortype_append(IMAGE_OT_clear_render_border); } @@ -289,7 +295,7 @@ static void image_keymap(struct wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "IMAGE_OT_open", OKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "IMAGE_OT_reload", RKEY, KM_PRESS, KM_ALT, 0); - WM_keymap_add_item(keymap, "IMAGE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "IMAGE_OT_read_viewlayers", RKEY, KM_PRESS, KM_CTRL, 0); WM_keymap_add_item(keymap, "IMAGE_OT_save", SKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "IMAGE_OT_save_as", F3KEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "IMAGE_OT_properties", NKEY, KM_PRESS, 0, 0); @@ -435,23 +441,22 @@ static void image_refresh(const bContext *C, ScrArea *sa) else { /* old shading system, we set texface */ if (em && EDBM_uv_check(em)) { - MTexPoly *tf; - if (EDBM_uv_active_face_get(em, sloppy, selected, &tf)) { + BMFace *efa = BM_mesh_active_face_get(em->bm, sloppy, selected); + + if (efa) { /* don't need to check for pin here, see above */ - sima->image = tf->tpage; - - if ((sima->flag & SI_EDITTILE) == 0) { - sima->curtile = tf->tile; - } + Image *image = BKE_object_material_edit_image_get(obedit, efa->mat_nr); + + sima->image = image; } } } } } -static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn) +static void image_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *scene, + WorkSpace *workspace) { - Scene *scene = sc->scene; SpaceImage *sima = (SpaceImage *)sa->spacedata.first; /* context changes */ @@ -544,7 +549,8 @@ static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn) case ND_TRANSFORM: case ND_MODIFIER: { - Object *ob = OBACT; + ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace); + Object *ob = OBACT(view_layer); if (ob && (ob == wmn->reference) && (ob->mode & OB_MODE_EDIT)) { if (sima->lock && (sima->flag & SI_DRAWSHADOW)) { ED_area_tag_refresh(sa); @@ -596,6 +602,27 @@ static int image_context(const bContext *C, const char *member, bContextDataResu return 0; } +static void IMAGE_WGT_manipulator2d(wmManipulatorGroupType *wgt) +{ + wgt->name = "UV Transform Manipulator"; + wgt->idname = "IMAGE_WGT_manipulator2d"; + + wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT; + + wgt->poll = ED_widgetgroup_manipulator2d_poll; + wgt->setup = ED_widgetgroup_manipulator2d_setup; + wgt->refresh = ED_widgetgroup_manipulator2d_refresh; + wgt->draw_prepare = ED_widgetgroup_manipulator2d_draw_prepare; +} + +static void image_widgets(void) +{ + wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure( + &(const struct wmManipulatorMapType_Params){SPACE_IMAGE, RGN_TYPE_WINDOW}); + + WM_manipulatorgrouptype_append_and_link(mmap_type, IMAGE_WGT_manipulator2d); +} + /************************** main region ***************************/ /* sets up the fields of the View2D from zoom and offset */ @@ -659,6 +686,16 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar) // image space manages own v2d // UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy); + /* manipulators */ + if (ar->manipulator_map == NULL) { + const struct wmManipulatorMapType_Params wmap_params = { + .spaceid = SPACE_IMAGE, + .regionid = RGN_TYPE_WINDOW, + }; + ar->manipulator_map = WM_manipulatormap_new_from_type(&wmap_params); + } + WM_manipulatormap_add_handlers(ar, ar->manipulator_map); + /* mask polls mode */ keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); @@ -684,7 +721,6 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar) WM_event_add_keymap_handler(&ar->handlers, keymap); keymap = WM_keymap_find(wm->defaultconf, "Image", SPACE_IMAGE, 0); WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct); - } static void image_main_region_draw(const bContext *C, ARegion *ar) @@ -693,9 +729,11 @@ static void image_main_region_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); + Depsgraph *depsgraph = CTX_data_depsgraph(C); Mask *mask = NULL; bool curve = false; Scene *scene = CTX_data_scene(C); + ViewLayer *view_layer = CTX_data_view_layer(C); View2D *v2d = &ar->v2d; //View2DScrollers *scrollers; float col[3]; @@ -721,7 +759,7 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW); - ED_uvedit_draw_main(sima, ar, scene, obedit, obact); + ED_uvedit_draw_main(sima, ar, scene, view_layer, obedit, obact, depsgraph); /* check for mask (delay draw) */ if (ED_space_image_show_uvedit(sima, obedit)) { @@ -790,6 +828,8 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); } + WM_manipulatormap_draw(ar->manipulator_map, C, WM_MANIPULATORMAP_DRAWSTEP_2D); + draw_image_cache(C, ar); /* scrollers? */ @@ -800,10 +840,16 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) #endif } -static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar, wmNotifier *wmn) +static void image_main_region_listener( + bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { + case NC_GEOM: + if (ELEM(wmn->data, ND_DATA, ND_SELECT)) + WM_manipulatormap_tag_refresh(ar->manipulator_map); + break; case NC_GPENCIL: if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) ED_region_tag_redraw(ar); @@ -813,6 +859,7 @@ static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion case NC_IMAGE: if (wmn->action == NA_PAINTING) ED_region_tag_redraw(ar); + WM_manipulatormap_tag_refresh(ar->manipulator_map); break; case NC_MATERIAL: if (wmn->data == ND_SHADING_LINKS) { @@ -822,6 +869,11 @@ static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion ED_region_tag_redraw(ar); } break; + case NC_SCREEN: + if (ELEM(wmn->data, ND_LAYER)) { + ED_region_tag_redraw(ar); + } + break; } } @@ -844,7 +896,9 @@ static void image_buttons_region_draw(const bContext *C, ARegion *ar) ED_region_panels(C, ar, NULL, -1, true); } -static void image_buttons_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) +static void image_buttons_region_listener( + bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { @@ -917,7 +971,9 @@ static void image_tools_region_draw(const bContext *C, ARegion *ar) ED_region_panels(C, ar, NULL, -1, true); } -static void image_tools_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) +static void image_tools_region_listener( + bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { @@ -968,7 +1024,9 @@ static void image_header_region_draw(const bContext *C, ARegion *ar) ED_region_header(C, ar); } -static void image_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn) +static void image_header_region_listener( + bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, + wmNotifier *wmn, const Scene *UNUSED(scene)) { /* context changes */ switch (wmn->category) { @@ -1037,6 +1095,7 @@ void ED_spacetype_image(void) st->refresh = image_refresh; st->listener = image_listener; st->context = image_context; + st->manipulators = image_widgets; st->id_remap = image_id_remap; /* regions: main window */ |