soc-2008-mxcurioni: merged changes to revision 23516
[blender.git] / source / blender / editors / sculpt_paint / paint_stroke.c
index 715399af88805f4151d4ead5dc8efba3505ccb81..b83352ae70cc1155230ca21221a5a0962539492b 100644 (file)
@@ -43,6 +43,8 @@
 
 #include "BLI_arithb.h"
 
+#include "PIL_time.h"
+
 #include "BIF_gl.h"
 #include "BIF_glutil.h"
 
@@ -57,6 +59,7 @@
 typedef struct PaintStroke {
        void *mode_data;
        void *smooth_stroke_cursor;
+       wmTimer *timer;
 
        /* Cached values */
        ViewContext vc;
@@ -227,15 +230,22 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
        PaintStroke *stroke = op->customdata;
        float mouse[2];
 
+       if(event->type == TIMER && (event->customdata != stroke->timer))
+               return OPERATOR_RUNNING_MODAL;
+
        if(!stroke->stroke_started) {
                stroke->last_mouse_position[0] = event->x;
                stroke->last_mouse_position[1] = event->y;
                stroke->stroke_started = stroke->test_start(C, op, event);
 
-               if(stroke->stroke_started)
+               if(stroke->stroke_started) {
                        stroke->smooth_stroke_cursor =
                                WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke);
 
+                       if(stroke->brush->flag & BRUSH_AIRBRUSH)
+                               stroke->timer = WM_event_add_window_timer(CTX_wm_window(C), TIMER, stroke->brush->rate);
+               }
+
                ED_region_tag_redraw(ar);
        }
 
@@ -253,10 +263,15 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
        }
 
        /* TODO: fix hardcoded event here */
-       if(event->type == LEFTMOUSE && event->val == 0) {
+       if(event->type == LEFTMOUSE && event->val == KM_RELEASE) {
+               /* Exit stroke, free data */
+
                if(stroke->smooth_stroke_cursor)
                        WM_paint_cursor_end(CTX_wm_manager(C), stroke->smooth_stroke_cursor);
 
+               if(stroke->timer)
+                       WM_event_remove_window_timer(CTX_wm_window(C), stroke->timer);
+
                stroke->done(C, stroke);
                MEM_freeN(stroke);
                return OPERATOR_FINISHED;