diff options
author | Matt Ebb <matt@mke3.net> | 2010-04-04 04:21:37 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-04-04 04:21:37 +0400 |
commit | 4021db8af82bb96ecd727e1a3374367f189ce415 (patch) | |
tree | 5d6f17a343de82b37e34074b707dcdcadfe935c2 /source/blender/editors | |
parent | 069e955a1d07a8f5fd83ac7777e6df8c918570b6 (diff) |
Added a new 'straight line' gesture type that can be used in any operator.
Use this for image editor Line Sample tool, rather than custom modal operator/
custom drawing.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/space_image/image_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_image/image_ops.c | 103 |
2 files changed, 22 insertions, 82 deletions
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h index 8c8a8f76710..c038f58375c 100644 --- a/source/blender/editors/space_image/image_intern.h +++ b/source/blender/editors/space_image/image_intern.h @@ -55,7 +55,6 @@ void IMAGE_OT_toolbox(struct wmOperatorType *ot); void draw_image_main(struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene); void draw_image_info(struct ARegion *ar, int channels, int x, int y, char *cp, float *fp, int *zp, float *zpf); void draw_image_grease_pencil(struct bContext *C, short onlyv2d); -void draw_image_line(struct ARegion *ar, int x1, int y1, int x2, int y2); /* image_ops.c */ int space_image_main_area_poll(struct bContext *C); diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index a223e2481fc..c9daeb09f25 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -1634,27 +1634,20 @@ void IMAGE_OT_sample(wmOperatorType *ot) } /******************** sample line operator ********************/ -typedef struct ImageSampleLineInfo { - ARegionType *art; - void *draw_handle; - int started; - int x_start, y_start, x_stop, y_stop; -} ImageSampleLineInfo; - -static void sample_line_draw(const bContext *C, ARegion *ar, void *arg_info) -{ - ImageSampleLineInfo *info= arg_info; - draw_image_line(ar, info->x_start, info->y_start, info->x_stop, info->y_stop); -} - -static void sample_line_apply(bContext *C, wmOperator *op) +static int sample_line_exec(bContext *C, wmOperator *op) { SpaceImage *sima= CTX_wm_space_image(C); - ImageSampleLineInfo *info= op->customdata; ARegion *ar= CTX_wm_region(C); + + int x_start= RNA_int_get(op->ptr, "xstart"); + int y_start= RNA_int_get(op->ptr, "ystart"); + int x_end= RNA_int_get(op->ptr, "xend"); + int y_end= RNA_int_get(op->ptr, "yend"); + void *lock; ImBuf *ibuf= ED_space_image_acquire_buffer(sima, &lock); Histogram *hist= &sima->sample_line_hist; + float x1f, y1f, x2f, y2f; int x1, y1, x2, y2; int i, x, y; @@ -1663,16 +1656,16 @@ static void sample_line_apply(bContext *C, wmOperator *op) if (ibuf == NULL) { ED_space_image_release_buffer(sima, lock); - return; + return OPERATOR_CANCELLED; } /* hmmmm */ if (ibuf->channels < 3) { ED_space_image_release_buffer(sima, lock); - return; + return OPERATOR_CANCELLED; } - UI_view2d_region_to_view(&ar->v2d, info->x_start, info->y_start, &x1f, &y1f); - UI_view2d_region_to_view(&ar->v2d, info->x_stop, info->y_stop, &x2f, &y2f); + UI_view2d_region_to_view(&ar->v2d, x_start, y_start, &x1f, &y1f); + UI_view2d_region_to_view(&ar->v2d, x_end, y_end, &x2f, &y2f); x1= 0.5f+ x1f*ibuf->x; x2= 0.5f+ x2f*ibuf->x; y1= 0.5f+ y1f*ibuf->y; @@ -1707,74 +1700,20 @@ static void sample_line_apply(bContext *C, wmOperator *op) hist->ok=1; ED_space_image_release_buffer(sima, lock); -} - -static void sample_line_exit(bContext *C, wmOperator *op) -{ - ImageSampleLineInfo *info= op->customdata; - ED_region_draw_cb_exit(info->art, info->draw_handle); ED_area_tag_redraw(CTX_wm_area(C)); - MEM_freeN(info); + + return OPERATOR_FINISHED; } static int sample_line_invoke(bContext *C, wmOperator *op, wmEvent *event) { SpaceImage *sima= CTX_wm_space_image(C); - ImageSampleLineInfo *info; - + if(!ED_space_image_has_buffer(sima)) return OPERATOR_CANCELLED; - info= MEM_callocN(sizeof(ImageSampleLineInfo), "ImageSampleLineInfo"); - info->started= 0; - op->customdata= info; - - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; -} - -static int sample_line_modal(bContext *C, wmOperator *op, wmEvent *event) -{ - ImageSampleLineInfo *info= op->customdata; - ARegion *ar= CTX_wm_region(C); - - switch(event->type) { - case LEFTMOUSE: - if (info->started == 0) { - info->x_start = event->mval[0]; - info->y_start = event->mval[1]; - info->art= ar->type; - info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_line_draw, info, REGION_DRAW_POST_PIXEL); - info->started = 1; - } else { - sample_line_apply(C, op); - sample_line_exit(C, op); - return OPERATOR_FINISHED; - } - break; - case RIGHTMOUSE: // XXX hardcoded - case ESCKEY: - sample_line_exit(C, op); - return OPERATOR_CANCELLED; - case MOUSEMOVE: - if (info->started == 1) { - info->x_stop = event->mval[0]; - info->y_stop = event->mval[1]; - ED_area_tag_redraw(CTX_wm_area(C)); - sample_line_apply(C, op); - } - break; - } - - return OPERATOR_RUNNING_MODAL; -} - -static int sample_line_cancel(bContext *C, wmOperator *op) -{ - sample_line_exit(C, op); - return OPERATOR_CANCELLED; + return WM_gesture_straightline_invoke(C, op, event); } void IMAGE_OT_sample_line(wmOperatorType *ot) @@ -1785,12 +1724,14 @@ void IMAGE_OT_sample_line(wmOperatorType *ot) /* api callbacks */ ot->invoke= sample_line_invoke; - ot->modal= sample_line_modal; - ot->cancel= sample_line_cancel; + ot->modal= WM_gesture_straightline_modal; + ot->exec= sample_line_exec; ot->poll= space_image_main_area_poll; - + /* flags */ - ot->flag= OPTYPE_BLOCKING; + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; + + WM_operator_properties_gesture_straightline(ot, CURSOR_EDIT); } /******************** set curve point operator ********************/ |