Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_image/image_ops.c
| Show First 20 Lines • Show All 728 Lines • ▼ Show 20 Lines | void IMAGE_OT_view_ndof(wmOperatorType *ot) | ||||
| /* flags */ | /* flags */ | ||||
| ot->flag = OPTYPE_LOCK_BYPASS; | ot->flag = OPTYPE_LOCK_BYPASS; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| #endif /* WITH_INPUT_NDOF */ | #endif /* WITH_INPUT_NDOF */ | ||||
| /* -------------------------------------------------------------------- */ | void ED_image_view_all(struct SpaceImage *sima, | ||||
| /** \name View All Operator | const struct ARegion *region, | ||||
| * \{ */ | struct wmOperator *op) | ||||
campbellbarton: This could be moved to `View Navigation Utilities`, currently this isn't in a group. | |||||
| /* Updates the fields of the View2D member of the SpaceImage struct. | |||||
| * Default behavior is to reset the position of the image and set the zoom to 1 | |||||
| * If the image will not fit within the window rectangle, the zoom is adjusted */ | |||||
| static int image_view_all_exec(bContext *C, wmOperator *op) | |||||
| { | { | ||||
| SpaceImage *sima; | |||||
| ARegion *region; | |||||
| float aspx, aspy, zoomx, zoomy, w, h; | float aspx, aspy, zoomx, zoomy, w, h; | ||||
| int width, height; | int width, height; | ||||
| const bool fit_view = RNA_boolean_get(op->ptr, "fit_view"); | 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_size(sima, &width, &height); | ||||
| ED_space_image_get_aspect(sima, &aspx, &aspy); | ED_space_image_get_aspect(sima, &aspx, &aspy); | ||||
| w = width * aspx; | w = width * aspx; | ||||
| h = height * aspy; | h = height * aspy; | ||||
| float xof = 0.0f, yof = 0.0f; | float xof = 0.0f, yof = 0.0f; | ||||
| if ((sima->image == NULL) || (sima->image->source == IMA_SRC_TILED)) { | if ((sima->image == NULL) || (sima->image->source == IMA_SRC_TILED)) { | ||||
| Show All 40 Lines | else { | ||||
| } | } | ||||
| else { | else { | ||||
| sima_zoom_set(sima, region, 1.0f, NULL, false); | sima_zoom_set(sima, region, 1.0f, NULL, false); | ||||
| } | } | ||||
| } | } | ||||
| sima->xof = xof; | sima->xof = xof; | ||||
| sima->yof = yof; | sima->yof = yof; | ||||
| } | |||||
| /* -------------------------------------------------------------------- */ | |||||
| /** \name View All Operator | |||||
| * \{ */ | |||||
| /* Updates the fields of the View2D member of the SpaceImage struct. | |||||
| * Default behavior is to reset the position of the image and set the zoom to 1 | |||||
| * If the image will not fit within the window rectangle, the zoom is adjusted */ | |||||
| static int image_view_all_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| SpaceImage *sima; | |||||
| ARegion *region; | |||||
| /* retrieve state */ | |||||
| sima = CTX_wm_space_image(C); | |||||
| region = CTX_wm_region(C); | |||||
| ED_image_view_all(sima, region, op); | |||||
| ED_region_tag_redraw(region); | ED_region_tag_redraw(region); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| void IMAGE_OT_view_all(wmOperatorType *ot) | void IMAGE_OT_view_all(wmOperatorType *ot) | ||||
| { | { | ||||
| Show All 14 Lines | void IMAGE_OT_view_all(wmOperatorType *ot) | ||||
| /* properties */ | /* properties */ | ||||
| prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport"); | prop = RNA_def_boolean(ot->srna, "fit_view", 0, "Fit View", "Fit frame to the viewport"); | ||||
| RNA_def_property_flag(prop, PROP_SKIP_SAVE); | RNA_def_property_flag(prop, PROP_SKIP_SAVE); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Cursor To Center View Operator | |||||
| * \{ */ | |||||
| static int view_cursor_center_exec(bContext *C, wmOperator *op) | |||||
| { | |||||
| SpaceImage *sima; | |||||
Not Done Inline ActionsNormally we don't call exec functions directly, this should be moved into a utility function. campbellbarton: Normally we don't call exec functions directly, this should be moved into a utility function. | |||||
| ARegion *region; | |||||
| sima = CTX_wm_space_image(C); | |||||
| region = CTX_wm_region(C); | |||||
| ED_image_view_all(sima, region, op); | |||||
Not Done Inline ActionsPoll will catch this, if not, the exec function would have already crashed - from calling view all above. campbellbarton: Poll will catch this, if not, the exec function would have already crashed - from calling view… | |||||
| sima->cursor[0] = 0.5f; | |||||
| sima->cursor[1] = 0.5f; | |||||
| 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 | /** \name Center View To Cursor Operator | ||||
| * \{ */ | * \{ */ | ||||
| static int view_center_cursor_exec(bContext *C, wmOperator *UNUSED(op)) | static int view_center_cursor_exec(bContext *C, wmOperator *UNUSED(op)) | ||||
| { | { | ||||
| SpaceImage *sima = CTX_wm_space_image(C); | SpaceImage *sima = CTX_wm_space_image(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| ▲ Show 20 Lines • Show All 3,172 Lines • Show Last 20 Lines | |||||
This could be moved to View Navigation Utilities, currently this isn't in a group.