Revision: 58808
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58808
Author:   psy-fi
Date:     2013-08-01 17:18:17 +0000 (Thu, 01 Aug 2013)
Log Message:
-----------
WIP. gradient code

Modified Paths:
--------------
    branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
    
branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c

Modified: branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py        
2013-08-01 17:18:08 UTC (rev 58807)
+++ branches/soc-2013-paint/release/scripts/startup/bl_ui/space_image.py        
2013-08-01 17:18:17 UTC (rev 58808)
@@ -971,6 +971,7 @@
 
         col = layout.column()
         col.operator("paint.bucket_fill")
+        col.operator("paint.gradient_fill")
 
 
 

Modified: 
branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- 
branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py   
    2013-08-01 17:18:08 UTC (rev 58807)
+++ 
branches/soc-2013-paint/release/scripts/startup/bl_ui/space_view3d_toolbar.py   
    2013-08-01 17:18:17 UTC (rev 58808)
@@ -1279,6 +1279,7 @@
 
         col = layout.column()
         col.operator("paint.bucket_fill")
+        col.operator("paint.gradient_fill")
 
 
 class VIEW3D_PT_imagepaint_options(View3DPaintPanel):

Modified: 
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c   
2013-08-01 17:18:08 UTC (rev 58807)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image.c   
2013-08-01 17:18:17 UTC (rev 58808)
@@ -1340,14 +1340,65 @@
        RNA_def_float_color(ot->srna, "color", 3, NULL, 0.0, 1.0, "Color", 
"Color for bucket fill", 0.0, 1.0);
 }
 
-static int gradient_fill_exec(bContext *C, wmOperator *UNUSED(op))
+typedef struct GradientFillData {
+       int mouse_init[2];
+//     int x_init, y_init;
+       bool started;
+       void *cursor;
+} GradientFillData;
+
+static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void 
*customdata) {
+       GradientFillData *data = (GradientFillData *)customdata;
+
+       if (data && data->started) {
+               glEnable(GL_LINE_SMOOTH);
+               glEnable(GL_BLEND);
+
+               glColor4ub(0, 0, 0, 255);
+               sdrawline(x, y, data->mouse_init[0], data->mouse_init[1]);
+
+               glDisable(GL_BLEND);
+               glDisable(GL_LINE_SMOOTH);
+       }
+}
+
+static int gradient_fill_invoke(struct bContext *C, struct wmOperator *op, 
const struct wmEvent *UNUSED(event))
 {
-       PaintMode mode = BKE_paintmode_get_active_from_context(C);
+       GradientFillData *data = MEM_mallocN(sizeof(*data), "Gradient Fill 
data");
 
-       return OPERATOR_FINISHED;
+       data->started = false;
+       op->customdata = data;
+
+       data->cursor = WM_paint_cursor_activate(CTX_wm_manager(C), 
image_paint_poll, gradient_draw_line, data);
+       WM_event_add_modal_handler(C, op);
+
+       return OPERATOR_RUNNING_MODAL;
 }
 
+static int gradient_fill_modal(struct bContext *C, struct wmOperator *op, 
const struct wmEvent *event)
+{
+       wmWindow *window = CTX_wm_window(C);
+       ARegion *ar = CTX_wm_region(C);
 
+       GradientFillData *data = op->customdata;
+
+       if (event->type == LEFTMOUSE) {
+               if (event->val == KM_PRESS) {
+                       copy_v2_v2_int(data->mouse_init, event->mval);
+                       data->started = true;
+               }
+               else if (event->val == KM_RELEASE) {
+                       WM_paint_cursor_end(CTX_wm_manager(C), data->cursor);
+                       MEM_freeN(data);
+                       return OPERATOR_FINISHED;
+               }
+       }
+
+       WM_paint_cursor_tag_redraw(window, ar);
+
+       return OPERATOR_RUNNING_MODAL;
+}
+
 void PAINT_OT_gradient_fill(wmOperatorType *ot)
 {
        /* identifiers */
@@ -1356,7 +1407,8 @@
        ot->description = "Fill canvas with a gradient";
 
        /* api callbacks */
-       ot->exec = gradient_fill_exec;
+       ot->invoke = gradient_fill_invoke;
+       ot->modal = gradient_fill_modal;
        ot->poll = image_paint_poll;
 
        /* flags */

Modified: 
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c  
2013-08-01 17:18:08 UTC (rev 58807)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_stroke.c  
2013-08-01 17:18:17 UTC (rev 58808)
@@ -74,7 +74,7 @@
 
 typedef struct PaintStroke {
        void *mode_data;
-       void *smooth_stroke_cursor;
+       void *stroke_cursor;
        wmTimer *timer;
 
        /* Cached values */
@@ -618,8 +618,8 @@
                        stroke->timer);
        }
 
-       if (stroke->smooth_stroke_cursor)
-               WM_paint_cursor_end(CTX_wm_manager(C), 
stroke->smooth_stroke_cursor);
+       if (stroke->stroke_cursor)
+               WM_paint_cursor_end(CTX_wm_manager(C), stroke->stroke_cursor);
 
        BLI_freelistN(&stroke->line);
 
@@ -793,7 +793,7 @@
        /* one time initialization */
        if (!stroke->stroke_init) {
                if (paint_supports_smooth_stroke(br, mode))
-                       stroke->smooth_stroke_cursor =
+                       stroke->stroke_cursor =
                            WM_paint_cursor_activate(CTX_wm_manager(C), 
paint_poll, paint_draw_smooth_cursor, stroke);
 
                stroke->stroke_init = true;
@@ -813,7 +813,7 @@
 
                        if (br->flag & BRUSH_LINE) {
                                LinePoint *p = MEM_callocN(sizeof(*p), 
"line_stroke_point");
-                               stroke->smooth_stroke_cursor =
+                               stroke->stroke_cursor =
                                        
WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_line_cursor, 
stroke);
 
                                BLI_addtail(&stroke->line, p);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to