Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_image/image_ops.c
| Show First 20 Lines • Show All 736 Lines • ▼ Show 20 Lines | |||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name View All Operator | /** \name View All Operator | ||||
| * \{ */ | * \{ */ | ||||
| /* Updates the fields of the View2D member of the SpaceImage struct. | /* 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 | * 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 */ | * If the image will not fit within the window rectangle, the zoom is adjusted */ | ||||
| static int image_view_all_exec(bContext *C, wmOperator *op) | static int image_view_all_exec(bContext *C, wmOperator *op) | ||||
campbellbarton: This could be moved to `View Navigation Utilities`, currently this isn't in a group. | |||||
| { | { | ||||
| SpaceImage *sima; | SpaceImage *sima; | ||||
| ARegion *region; | 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 */ | /* retrieve state */ | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 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) | |||||
| { | |||||
| image_view_all_exec(C, op); | |||||
campbellbartonUnsubmitted 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. | |||||
| SpaceImage *sima = CTX_wm_space_image(C); | |||||
| if (!sima) { | |||||
| return OPERATOR_CANCELLED; | |||||
| } | |||||
campbellbartonUnsubmitted 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.