diff options
Diffstat (limited to 'source/blender/editors/space_image/image_ops.c')
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 221 |
1 files changed, 129 insertions, 92 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 72405a51aca..0c34c0cc756 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -244,6 +244,70 @@ static bool image_not_packed_poll(bContext *C) return (ima && BLI_listbase_is_empty(&ima->packedfiles)); } +static void image_view_all(struct SpaceImage *sima, struct ARegion *region, struct wmOperator *op) +{ + float aspx, aspy, zoomx, zoomy, w, h; + int width, height; + const bool fit_view = RNA_boolean_get(op->ptr, "fit_view"); + + ED_space_image_get_size(sima, &width, &height); + ED_space_image_get_aspect(sima, &aspx, &aspy); + + w = width * aspx; + h = height * aspy; + + float xof = 0.0f, yof = 0.0f; + if ((sima->image == NULL) || (sima->image->source == IMA_SRC_TILED)) { + /* Extend the shown area to cover all UDIM tiles. */ + int x_tiles, y_tiles; + if (sima->image == NULL) { + x_tiles = sima->tile_grid_shape[0]; + y_tiles = sima->tile_grid_shape[1]; + } + else { + x_tiles = y_tiles = 1; + LISTBASE_FOREACH (ImageTile *, tile, &sima->image->tiles) { + int tile_x = (tile->tile_number - 1001) % 10; + int tile_y = (tile->tile_number - 1001) / 10; + x_tiles = max_ii(x_tiles, tile_x + 1); + y_tiles = max_ii(y_tiles, tile_y + 1); + } + } + xof = 0.5f * (x_tiles - 1.0f) * w; + yof = 0.5f * (y_tiles - 1.0f) * h; + w *= x_tiles; + h *= y_tiles; + } + + /* check if the image will fit in the image with (zoom == 1) */ + width = BLI_rcti_size_x(®ion->winrct) + 1; + height = BLI_rcti_size_y(®ion->winrct) + 1; + + if (fit_view) { + const int margin = 5; /* margin from border */ + + zoomx = (float)width / (w + 2 * margin); + zoomy = (float)height / (h + 2 * margin); + + sima_zoom_set(sima, region, min_ff(zoomx, zoomy), NULL, false); + } + else { + if ((w >= width || h >= height) && (width > 0 && height > 0)) { + zoomx = (float)width / w; + zoomy = (float)height / h; + + /* find the zoom value that will fit the image in the image space */ + sima_zoom_set(sima, region, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL, false); + } + else { + sima_zoom_set(sima, region, 1.0f, NULL, false); + } + } + + sima->xof = xof; + sima->yof = yof; +} + bool space_image_main_region_poll(bContext *C) { SpaceImage *sima = CTX_wm_space_image(C); @@ -736,70 +800,12 @@ static int image_view_all_exec(bContext *C, wmOperator *op) { SpaceImage *sima; ARegion *region; - float aspx, aspy, zoomx, zoomy, w, h; - int width, height; - const bool fit_view = RNA_boolean_get(op->ptr, "fit_view"); /* retrieve state */ sima = CTX_wm_space_image(C); region = CTX_wm_region(C); - ED_space_image_get_size(sima, &width, &height); - ED_space_image_get_aspect(sima, &aspx, &aspy); - - w = width * aspx; - h = height * aspy; - - float xof = 0.0f, yof = 0.0f; - if ((sima->image == NULL) || (sima->image->source == IMA_SRC_TILED)) { - /* Extend the shown area to cover all UDIM tiles. */ - int x_tiles, y_tiles; - if (sima->image == NULL) { - x_tiles = sima->tile_grid_shape[0]; - y_tiles = sima->tile_grid_shape[1]; - } - else { - x_tiles = y_tiles = 1; - LISTBASE_FOREACH (ImageTile *, tile, &sima->image->tiles) { - int tile_x = (tile->tile_number - 1001) % 10; - int tile_y = (tile->tile_number - 1001) / 10; - x_tiles = max_ii(x_tiles, tile_x + 1); - y_tiles = max_ii(y_tiles, tile_y + 1); - } - } - xof = 0.5f * (x_tiles - 1.0f) * w; - yof = 0.5f * (y_tiles - 1.0f) * h; - w *= x_tiles; - h *= y_tiles; - } - - /* check if the image will fit in the image with (zoom == 1) */ - width = BLI_rcti_size_x(®ion->winrct) + 1; - height = BLI_rcti_size_y(®ion->winrct) + 1; - - if (fit_view) { - const int margin = 5; /* margin from border */ - - zoomx = (float)width / (w + 2 * margin); - zoomy = (float)height / (h + 2 * margin); - - sima_zoom_set(sima, region, min_ff(zoomx, zoomy), NULL, false); - } - else { - if ((w >= width || h >= height) && (width > 0 && height > 0)) { - zoomx = (float)width / w; - zoomy = (float)height / h; - - /* find the zoom value that will fit the image in the image space */ - sima_zoom_set(sima, region, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), NULL, false); - } - else { - sima_zoom_set(sima, region, 1.0f, NULL, false); - } - } - - sima->xof = xof; - sima->yof = yof; + image_view_all(sima, region, op); ED_region_tag_redraw(region); @@ -830,6 +836,49 @@ void IMAGE_OT_view_all(wmOperatorType *ot) /** \} */ /* -------------------------------------------------------------------- */ +/** \name Cursor To Center View Operator + * \{ */ + +static int view_cursor_center_exec(bContext *C, wmOperator *op) +{ + SpaceImage *sima; + ARegion *region; + + sima = CTX_wm_space_image(C); + region = CTX_wm_region(C); + + image_view_all(sima, region, op); + + sima->cursor[0] = 0.5f; + sima->cursor[1] = 0.5f; + + /* Needed for updating the cursor. */ + WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, NULL); + + return OPERATOR_FINISHED; +} + +void IMAGE_OT_view_cursor_center(wmOperatorType *ot) +{ + PropertyRNA *prop; + + /* identifiers */ + ot->name = "Cursor To Center View"; + ot->description = "Set 2D Cursor To Center View location"; + ot->idname = "IMAGE_OT_view_cursor_center"; + + /* api callbacks */ + ot->exec = view_cursor_center_exec; + ot->poll = ED_space_image_cursor_poll; + + /* properties */ + prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ /** \name Center View To Cursor Operator * \{ */ @@ -1262,7 +1311,6 @@ static int image_open_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Object *obedit = CTX_data_edit_object(C); ImageUser *iuser = NULL; - ImageOpenData *iod = op->customdata; Image *ima = NULL; int frame_seq_len = 0; int frame_ofs = 1; @@ -1296,7 +1344,7 @@ static int image_open_exec(bContext *C, wmOperator *op) } /* hook into UI */ - iod = op->customdata; + ImageOpenData *iod = op->customdata; if (iod->pprop.prop) { /* when creating new ID blocks, use is already 1, but RNA @@ -1435,12 +1483,11 @@ static void image_open_draw(bContext *UNUSED(C), wmOperator *op) uiLayout *layout = op->layout; ImageOpenData *iod = op->customdata; ImageFormatData *imf = &iod->im_format; - PointerRNA imf_ptr, ptr; + PointerRNA imf_ptr; /* main draw call */ - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); uiDefAutoButsRNA( - layout, &ptr, image_open_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false); + layout, op->ptr, image_open_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false); /* image template */ RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr); @@ -1955,7 +2002,7 @@ static void image_save_as_draw(bContext *UNUSED(C), wmOperator *op) { uiLayout *layout = op->layout; ImageSaveData *isd = op->customdata; - PointerRNA imf_ptr, ptr; + PointerRNA imf_ptr; const bool is_multiview = RNA_boolean_get(op->ptr, "show_multiview"); /* image template */ @@ -1963,9 +2010,8 @@ static void image_save_as_draw(bContext *UNUSED(C), wmOperator *op) uiTemplateImageSettings(layout, &imf_ptr, false); /* main draw call */ - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); uiDefAutoButsRNA( - layout, &ptr, image_save_as_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false); + layout, op->ptr, image_save_as_draw_check_prop, NULL, NULL, UI_BUT_LABEL_ALIGN_NONE, false); /* multiview template */ if (is_multiview) { @@ -2567,33 +2613,30 @@ static void image_new_draw(bContext *UNUSED(C), wmOperator *op) { uiLayout *col; uiLayout *layout = op->layout; - PointerRNA ptr; #if 0 Scene *scene = CTX_data_scene(C); const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0; #endif - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - /* copy of WM_operator_props_dialog_popup() layout */ uiLayoutSetPropSep(layout, true); uiLayoutSetPropDecorate(layout, false); col = uiLayoutColumn(layout, false); - uiItemR(col, &ptr, "name", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "width", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "height", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "color", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "alpha", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "generated_type", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "float", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "tiled", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "name", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "width", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "height", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "color", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "alpha", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "generated_type", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "float", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "tiled", 0, NULL, ICON_NONE); #if 0 if (is_multiview) { uiItemL(col[0], "", ICON_NONE); - uiItemR(col[1], &ptr, "use_stereo_3d", 0, NULL, ICON_NONE); + uiItemR(col[1], op->ptr, "use_stereo_3d", 0, NULL, ICON_NONE); } #endif } @@ -3943,21 +3986,18 @@ static void tile_add_draw(bContext *UNUSED(C), wmOperator *op) { uiLayout *col; uiLayout *layout = op->layout; - PointerRNA ptr; - - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); uiLayoutSetPropSep(layout, true); uiLayoutSetPropDecorate(layout, false); col = uiLayoutColumn(layout, false); - uiItemR(col, &ptr, "number", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "count", 0, NULL, ICON_NONE); - uiItemR(col, &ptr, "label", 0, NULL, ICON_NONE); - uiItemR(layout, &ptr, "fill", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "number", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "count", 0, NULL, ICON_NONE); + uiItemR(col, op->ptr, "label", 0, NULL, ICON_NONE); + uiItemR(layout, op->ptr, "fill", 0, NULL, ICON_NONE); - if (RNA_boolean_get(&ptr, "fill")) { - draw_fill_tile(&ptr, layout); + if (RNA_boolean_get(op->ptr, "fill")) { + draw_fill_tile(op->ptr, layout); } } @@ -4077,10 +4117,7 @@ static int tile_fill_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e static void tile_fill_draw(bContext *UNUSED(C), wmOperator *op) { - PointerRNA ptr; - RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); - - draw_fill_tile(&ptr, op->layout); + draw_fill_tile(op->ptr, op->layout); } void IMAGE_OT_tile_fill(wmOperatorType *ot) |