Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ebb <matt@mke3.net>2010-04-04 04:21:37 +0400
committerMatt Ebb <matt@mke3.net>2010-04-04 04:21:37 +0400
commit4021db8af82bb96ecd727e1a3374367f189ce415 (patch)
tree5d6f17a343de82b37e34074b707dcdcadfe935c2 /source/blender/editors/space_image/image_ops.c
parent069e955a1d07a8f5fd83ac7777e6df8c918570b6 (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/space_image/image_ops.c')
-rw-r--r--source/blender/editors/space_image/image_ops.c103
1 files changed, 22 insertions, 81 deletions
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 ********************/