Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_image/image_ops.c
| Show First 20 Lines • Show All 941 Lines • ▼ Show 20 Lines | |||||
| } ImageFrame; | } ImageFrame; | ||||
| static void image_open_init(bContext *C, wmOperator *op) | static void image_open_init(bContext *C, wmOperator *op) | ||||
| { | { | ||||
| ImageOpenData *iod; | ImageOpenData *iod; | ||||
| op->customdata = iod = MEM_callocN(sizeof(ImageOpenData), __func__); | op->customdata = iod = MEM_callocN(sizeof(ImageOpenData), __func__); | ||||
| iod->iuser = CTX_data_pointer_get_type(C, "image_user", &RNA_ImageUser).data; | iod->iuser = CTX_data_pointer_get_type(C, "image_user", &RNA_ImageUser).data; | ||||
| uiIDContextProperty(C, &iod->pprop.ptr, &iod->pprop.prop); | UI_context_active_but_prop_get_templateID(C, &iod->pprop.ptr, &iod->pprop.prop); | ||||
| } | } | ||||
| static void image_open_cancel(bContext *UNUSED(C), wmOperator *op) | static void image_open_cancel(bContext *UNUSED(C), wmOperator *op) | ||||
| { | { | ||||
| MEM_freeN(op->customdata); | MEM_freeN(op->customdata); | ||||
| op->customdata = NULL; | op->customdata = NULL; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Lines | if (tex && tex->type == TEX_IMAGE) | ||||
| ima = tex->ima; | ima = tex->ima; | ||||
| } | } | ||||
| if (ima == NULL) { | if (ima == NULL) { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| /* hook into UI */ | /* hook into UI */ | ||||
| uiIDContextProperty(C, &ptr, &prop); | UI_context_active_but_prop_get_templateID(C, &ptr, &prop); | ||||
| if (prop) { | if (prop) { | ||||
| PointerRNA oldptr; | PointerRNA oldptr; | ||||
| Image *oldima; | Image *oldima; | ||||
| oldptr = RNA_property_pointer_get(&ptr, prop); | oldptr = RNA_property_pointer_get(&ptr, prop); | ||||
| oldima = (Image *)oldptr.id.data; | oldima = (Image *)oldptr.id.data; | ||||
| /* unlikely to fail but better avoid strange crash */ | /* unlikely to fail but better avoid strange crash */ | ||||
| ▲ Show 20 Lines • Show All 783 Lines • ▼ Show 20 Lines | if (!alpha) | ||||
| color[3] = 1.0f; | color[3] = 1.0f; | ||||
| ima = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color); | ima = BKE_image_add_generated(bmain, width, height, name, alpha ? 32 : 24, floatbuf, gen_type, color); | ||||
| if (!ima) | if (!ima) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| /* hook into UI */ | /* hook into UI */ | ||||
| uiIDContextProperty(C, &ptr, &prop); | UI_context_active_but_prop_get_templateID(C, &ptr, &prop); | ||||
| if (prop) { | if (prop) { | ||||
| /* when creating new ID blocks, use is already 1, but RNA | /* when creating new ID blocks, use is already 1, but RNA | ||||
| * pointer se also increases user, so this compensates it */ | * pointer se also increases user, so this compensates it */ | ||||
| ima->id.us--; | ima->id.us--; | ||||
| RNA_id_pointer_create(&ima->id, &idptr); | RNA_id_pointer_create(&ima->id, &idptr); | ||||
| RNA_property_pointer_set(&ptr, prop, idptr); | RNA_property_pointer_set(&ptr, prop, idptr); | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | static int image_new_exec(bContext *C, wmOperator *op) | ||||
| BKE_image_signal(ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_USER_NEW_IMAGE); | BKE_image_signal(ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_USER_NEW_IMAGE); | ||||
| WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima); | WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima); | ||||
| return OPERATOR_FINISHED; | return OPERATOR_FINISHED; | ||||
| } | } | ||||
| /* XXX, Ton is not a fan of OK buttons but using this function to avoid undo/redo bug while in mesh-editmode, - campbell */ | /* XXX, Ton is not a fan of OK buttons but using this function to avoid undo/redo bug while in mesh-editmode, - campbell */ | ||||
| /* XXX Note: the WM_operator_props_dialog_popup() doesn't work for uiIDContextProperty(), image is not being that way */ | /* XXX Note: the WM_operator_props_dialog_popup() doesn't work for UI_context_active_but_prop_get_templateID(), image is not being that way */ | ||||
| static int image_new_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | static int image_new_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| { | { | ||||
| /* Better for user feedback. */ | /* Better for user feedback. */ | ||||
| RNA_string_set(op->ptr, "name", DATA_(IMA_DEF_NAME)); | RNA_string_set(op->ptr, "name", DATA_(IMA_DEF_NAME)); | ||||
| return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y); | return WM_operator_props_dialog_popup(C, op, 15 * UI_UNIT_X, 5 * UI_UNIT_Y); | ||||
| } | } | ||||
| void IMAGE_OT_new(wmOperatorType *ot) | void IMAGE_OT_new(wmOperatorType *ot) | ||||
| ▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | static int image_pack_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) | ||||
| const bool as_png = RNA_boolean_get(op->ptr, "as_png"); | const bool as_png = RNA_boolean_get(op->ptr, "as_png"); | ||||
| if (!image_pack_test(C, op)) | if (!image_pack_test(C, op)) | ||||
| return OPERATOR_CANCELLED; | return OPERATOR_CANCELLED; | ||||
| ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); | ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); | ||||
| if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) { | if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) { | ||||
| pup = uiPupMenuBegin(C, IFACE_("OK"), ICON_QUESTION); | pup = UI_popup_menu_begin(C, IFACE_("OK"), ICON_QUESTION); | ||||
| layout = uiPupMenuLayout(pup); | layout = UI_popup_menu_layout(pup); | ||||
| uiItemBooleanO(layout, IFACE_("Can't pack edited image from disk, pack as internal PNG?"), ICON_NONE, | uiItemBooleanO(layout, IFACE_("Can't pack edited image from disk, pack as internal PNG?"), ICON_NONE, | ||||
| op->idname, "as_png", 1); | op->idname, "as_png", 1); | ||||
| uiPupMenuEnd(C, pup); | UI_popup_menu_end(C, pup); | ||||
| BKE_image_release_ibuf(ima, ibuf, NULL); | BKE_image_release_ibuf(ima, ibuf, NULL); | ||||
| return OPERATOR_INTERFACE; | return OPERATOR_INTERFACE; | ||||
| } | } | ||||
| BKE_image_release_ibuf(ima, ibuf, NULL); | BKE_image_release_ibuf(ima, ibuf, NULL); | ||||
| ▲ Show 20 Lines • Show All 925 Lines • Show Last 20 Lines | |||||