diff options
Diffstat (limited to 'source/blender/editors/space_image/image_ops.c')
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 107 |
1 files changed, 65 insertions, 42 deletions
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index 19fe795bb58..4a732c5812b 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -25,6 +25,11 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/editors/space_image/image_ops.c + * \ingroup spimage + */ + + #include <stddef.h> #include <string.h> #include <stdlib.h> @@ -66,6 +71,7 @@ #include "bmesh.h" #include "ED_image.h" +#include "ED_render.h" #include "ED_screen.h" #include "ED_space_api.h" #include "ED_uvedit.h" @@ -174,6 +180,7 @@ int space_image_main_area_poll(bContext *C) typedef struct ViewPanData { float x, y; float xof, yof; + int event_type; } ViewPanData; static void view_pan_init(bContext *C, wmOperator *op, wmEvent *event) @@ -188,6 +195,7 @@ static void view_pan_init(bContext *C, wmOperator *op, wmEvent *event) vpd->y= event->y; vpd->xof= sima->xof; vpd->yof= sima->yof; + vpd->event_type= event->type; WM_event_add_modal_handler(C, op); } @@ -264,9 +272,8 @@ static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event) RNA_float_set_array(op->ptr, "offset", offset); view_pan_exec(C, op); break; - case MIDDLEMOUSE: - case LEFTMOUSE: - if(event->val==KM_RELEASE) { + default: + if(event->type==vpd->event_type && event->val==KM_RELEASE) { view_pan_exit(C, op, 0); return OPERATOR_FINISHED; } @@ -308,6 +315,7 @@ void IMAGE_OT_view_pan(wmOperatorType *ot) typedef struct ViewZoomData { float x, y; float zoom; + int event_type; } ViewZoomData; static void view_zoom_init(bContext *C, wmOperator *op, wmEvent *event) @@ -321,7 +329,8 @@ static void view_zoom_init(bContext *C, wmOperator *op, wmEvent *event) vpd->x= event->x; vpd->y= event->y; vpd->zoom= sima->zoom; - + vpd->event_type= event->type; + WM_event_add_modal_handler(C, op); } @@ -367,7 +376,7 @@ static int view_zoom_invoke(bContext *C, wmOperator *op, wmEvent *event) ARegion *ar= CTX_wm_region(C); float factor; - factor= 1.0 + (event->x-event->prevx+event->y-event->prevy)/300.0f; + factor= 1.0f + (event->x-event->prevx+event->y-event->prevy)/300.0f; RNA_float_set(op->ptr, "factor", factor); sima_zoom_set(sima, ar, sima->zoom*factor); ED_region_tag_redraw(CTX_wm_region(C)); @@ -389,14 +398,13 @@ static int view_zoom_modal(bContext *C, wmOperator *op, wmEvent *event) switch(event->type) { case MOUSEMOVE: - factor= 1.0 + (vpd->x-event->x+vpd->y-event->y)/300.0f; + factor= 1.0f + (vpd->x-event->x+vpd->y-event->y)/300.0f; RNA_float_set(op->ptr, "factor", factor); sima_zoom_set(sima, ar, vpd->zoom*factor); ED_region_tag_redraw(CTX_wm_region(C)); break; - case MIDDLEMOUSE: - case LEFTMOUSE: - if(event->val==KM_RELEASE) { + default: + if(event->type==vpd->event_type && event->val==KM_RELEASE) { view_zoom_exit(C, op, 0); return OPERATOR_FINISHED; } @@ -518,10 +526,10 @@ static int view_selected_exec(bContext *C, wmOperator *UNUSED(op)) d[0]= max[0] - min[0]; d[1]= max[1] - min[1]; - size= 0.5*MAX2(d[0], d[1])*MAX2(width, height)/256.0f; + size= 0.5f*MAX2(d[0], d[1])*MAX2(width, height)/256.0f; - if(size<=0.01) size= 0.01; - sima_zoom_set(sima, ar, 0.7/size); + if(size<=0.01f) size= 0.01f; + sima_zoom_set(sima, ar, 0.7f/size); ED_region_tag_redraw(CTX_wm_region(C)); @@ -746,6 +754,9 @@ static int open_exec(bContext *C, wmOperator *op) iuser->fie_ima= 2; } + /* XXX unpackImage frees image buffers */ + ED_preview_kill_jobs(C); + BKE_image_signal(ima, iuser, IMA_SIGNAL_RELOAD); WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima); @@ -791,7 +802,7 @@ static int open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) void IMAGE_OT_open(wmOperatorType *ot) { /* identifiers */ - ot->name= "Open"; + ot->name= "Open Image"; ot->idname= "IMAGE_OT_open"; /* api callbacks */ @@ -819,6 +830,9 @@ static int replace_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "filepath", str); BLI_strncpy(sima->image->name, str, sizeof(sima->image->name)); /* we cant do much if the str is longer then 240 :/ */ + /* XXX unpackImage frees image buffers */ + ED_preview_kill_jobs(C); + BKE_image_signal(sima->image, &sima->iuser, IMA_SIGNAL_RELOAD); WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, sima->image); @@ -846,7 +860,7 @@ static int replace_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) void IMAGE_OT_replace(wmOperatorType *ot) { /* identifiers */ - ot->name= "Replace"; + ot->name= "Replace Image"; ot->idname= "IMAGE_OT_replace"; /* api callbacks */ @@ -1066,7 +1080,7 @@ static int save_as_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) void IMAGE_OT_save_as(wmOperatorType *ot) { /* identifiers */ - ot->name= "Save As"; + ot->name= "Save As Image"; ot->idname= "IMAGE_OT_save_as"; /* api callbacks */ @@ -1137,7 +1151,7 @@ static int save_exec(bContext *C, wmOperator *op) void IMAGE_OT_save(wmOperatorType *ot) { /* identifiers */ - ot->name= "Save"; + ot->name= "Save Image"; ot->idname= "IMAGE_OT_save"; /* api callbacks */ @@ -1235,6 +1249,9 @@ static int reload_exec(bContext *C, wmOperator *UNUSED(op)) if(!ima) return OPERATOR_CANCELLED; + /* XXX unpackImage frees image buffers */ + ED_preview_kill_jobs(C); + // XXX other users? BKE_image_signal(ima, (sima)? &sima->iuser: NULL, IMA_SIGNAL_RELOAD); @@ -1246,7 +1263,7 @@ static int reload_exec(bContext *C, wmOperator *UNUSED(op)) void IMAGE_OT_reload(wmOperatorType *ot) { /* identifiers */ - ot->name= "Reload"; + ot->name= "Reload Image"; ot->idname= "IMAGE_OT_reload"; /* api callbacks */ @@ -1328,7 +1345,7 @@ void IMAGE_OT_new(wmOperatorType *ot) static float default_color[4]= {0.0f, 0.0f, 0.0f, 1.0f}; /* identifiers */ - ot->name= "New"; + ot->name= "New Image"; ot->idname= "IMAGE_OT_new"; /* api callbacks */ @@ -1336,7 +1353,7 @@ void IMAGE_OT_new(wmOperatorType *ot) ot->invoke= image_new_invoke; /* flags */ - ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + ot->flag= OPTYPE_UNDO; /* properties */ RNA_def_string(ot->srna, "name", "untitled", 21, "Name", "Image datablock name."); @@ -1365,19 +1382,18 @@ static int image_invert_exec(bContext *C, wmOperator *op) { Image *ima= CTX_data_edit_image(C); ImBuf *ibuf= BKE_image_get_ibuf(ima, NULL); - + // flags indicate if this channel should be inverted - short r,g,b,a; - int i, dirty = 0; - + const short r= RNA_boolean_get(op->ptr, "invert_r"); + const short g= RNA_boolean_get(op->ptr, "invert_g"); + const short b= RNA_boolean_get(op->ptr, "invert_b"); + const short a= RNA_boolean_get(op->ptr, "invert_a"); + + int i; + if( ibuf == NULL) // TODO: this should actually never happen, but does for render-results -> cleanup return OPERATOR_CANCELLED; - - r = RNA_boolean_get(op->ptr, "invert_r"); - g = RNA_boolean_get(op->ptr, "invert_g"); - b = RNA_boolean_get(op->ptr, "invert_b"); - a = RNA_boolean_get(op->ptr, "invert_a"); - + /* TODO: make this into an IMB_invert_channels(ibuf,r,g,b,a) method!? */ if (ibuf->rect_float) { @@ -1388,8 +1404,10 @@ static int image_invert_exec(bContext *C, wmOperator *op) if( b ) fp[2] = 1.0f - fp[2]; if( a ) fp[3] = 1.0f - fp[3]; } - dirty = 1; - IMB_rect_from_float(ibuf); + + if(ibuf->rect) { + IMB_rect_from_float(ibuf); + } } else if(ibuf->rect) { @@ -1400,16 +1418,14 @@ static int image_invert_exec(bContext *C, wmOperator *op) if( b ) cp[2] = 255 - cp[2]; if( a ) cp[3] = 255 - cp[3]; } - dirty = 1; } - else + else { return OPERATOR_CANCELLED; + } - ibuf->userflags |= IB_BITMAPDIRTY; // mark as modified + ibuf->userflags |= IB_BITMAPDIRTY; WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima); - return OPERATOR_FINISHED; - } void IMAGE_OT_invert(wmOperatorType *ot) @@ -1490,7 +1506,7 @@ static int pack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) if(!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) { pup= uiPupMenuBegin(C, "OK", ICON_QUESTION); layout= uiPupMenuLayout(pup); - uiItemBooleanO(layout, "Can't pack edited image from disk. Pack as internal PNG?", ICON_NULL, op->idname, "as_png", 1); + uiItemBooleanO(layout, "Can't pack edited image from disk. Pack as internal PNG?", ICON_NONE, op->idname, "as_png", 1); uiPupMenuEnd(C, pup); return OPERATOR_CANCELLED; @@ -1502,7 +1518,7 @@ static int pack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) void IMAGE_OT_pack(wmOperatorType *ot) { /* identifiers */ - ot->name= "Pack"; + ot->name= "Pack Image"; ot->description= "Pack an image as embedded data into the .blend file"; ot->idname= "IMAGE_OT_pack"; @@ -1542,7 +1558,10 @@ static int image_unpack_exec(bContext *C, wmOperator *op) if(G.fileflags & G_AUTOPACK) BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save."); - + + /* XXX unpackImage frees image buffers */ + ED_preview_kill_jobs(C); + unpackImage(op->reports, ima, method); WM_event_add_notifier(C, NC_IMAGE|NA_EDITED, ima); @@ -1576,7 +1595,7 @@ static int image_unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(even void IMAGE_OT_unpack(wmOperatorType *ot) { /* identifiers */ - ot->name= "Unpack"; + ot->name= "Unpack Image"; ot->description= "Save an image packed in the .blend file to disk"; ot->idname= "IMAGE_OT_unpack"; @@ -1640,7 +1659,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event) my= event->y - ar->winrct.ymin; UI_view2d_region_to_view(&ar->v2d, mx, my, &fx, &fy); - if(fx>=0.0 && fy>=0.0 && fx<1.0 && fy<1.0) { + if(fx>=0.0f && fy>=0.0f && fx<1.0f && fy<1.0f) { float *fp; char *cp; int x= (int)(fx*ibuf->x), y= (int)(fy*ibuf->y); @@ -1788,7 +1807,7 @@ static int sample_cancel(bContext *C, wmOperator *op) void IMAGE_OT_sample(wmOperatorType *ot) { /* identifiers */ - ot->name= "Sample"; + ot->name= "Sample Color"; ot->idname= "IMAGE_OT_sample"; /* api callbacks */ @@ -2120,6 +2139,10 @@ static int cycle_render_slot_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL); + /* no undo push for browsing existing */ + if(ima->renders[ima->render_slot] || ima->render_slot==ima->last_render_slot) + return OPERATOR_CANCELLED; + return OPERATOR_FINISHED; } |