diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-08-20 09:13:07 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-08-20 09:13:07 +0400 |
commit | 7dfc1317acc63aea67d4ebd5db8d64c5bef4b8c8 (patch) | |
tree | 237369f278ba522425356ccf1b2082c911493582 /source/blender/editors/sculpt_paint/paint_stroke.c | |
parent | 2878eed1c125d07bcfc893eb04d1307c6aa19e3a (diff) |
2.5/Paint:
* Converted vertex paint to use the new stroke system. Now supports the same smooth stroke and stroke spacing as sculpt mode.
* Refactored the paint cursor a bit, just sculpt for now but other modes soon.
* A couple warning fixes
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_stroke.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_stroke.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 634b82674b5..1167e011c86 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -43,6 +43,7 @@ #include "BLI_arithb.h" +#include "BIF_gl.h" #include "BIF_glutil.h" #include "ED_screen.h" @@ -54,6 +55,9 @@ #include <math.h> typedef struct PaintStroke { + void *mode_data; + void *smooth_stroke_cursor; + /* Cached values */ ViewContext vc; bglMats mats; @@ -71,6 +75,42 @@ typedef struct PaintStroke { StrokeDone done; } PaintStroke; +/*** Cursor ***/ +static void paint_draw_smooth_stroke(bContext *C, int x, int y, void *customdata) +{ + Brush *brush = paint_brush(paint_get_active(CTX_data_scene(C))); + PaintStroke *stroke = customdata; + + glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + + if(stroke && brush && (brush->flag & BRUSH_SMOOTH_STROKE)) { + ARegion *ar = CTX_wm_region(C); + sdrawline(x, y, (int)stroke->last_mouse_position[0] - ar->winrct.xmin, + (int)stroke->last_mouse_position[1] - ar->winrct.ymin); + } + + glDisable(GL_BLEND); + glDisable(GL_LINE_SMOOTH); +} + +static void paint_draw_cursor(bContext *C, int x, int y, void *customdata) +{ + Brush *brush = paint_brush(paint_get_active(CTX_data_scene(C))); + + glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col); + glEnable(GL_LINE_SMOOTH); + glEnable(GL_BLEND); + + glTranslatef((float)x, (float)y, 0.0f); + glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size, 40); + glTranslatef((float)-x, (float)-y, 0.0f); + + glDisable(GL_BLEND); + glDisable(GL_LINE_SMOOTH); +} + /* Put the location of the next stroke dot into the stroke RNA and apply it to the mesh */ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse[2]) { @@ -191,6 +231,11 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) 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) + stroke->smooth_stroke_cursor = + WM_paint_cursor_activate(CTX_wm_manager(C), paint_poll, paint_draw_smooth_stroke, stroke); + ED_region_tag_redraw(ar); } @@ -209,6 +254,9 @@ int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event) /* TODO: fix hardcoded event here */ if(event->type == LEFTMOUSE && event->val == 0) { + if(stroke->smooth_stroke_cursor) + WM_paint_cursor_end(CTX_wm_manager(C), stroke->smooth_stroke_cursor); + stroke->done(C, stroke); MEM_freeN(stroke); return OPERATOR_FINISHED; @@ -222,3 +270,31 @@ ViewContext *paint_stroke_view_context(PaintStroke *stroke) return &stroke->vc; } +void *paint_stroke_mode_data(struct PaintStroke *stroke) +{ + return stroke->mode_data; +} + +void paint_stroke_set_mode_data(PaintStroke *stroke, void *mode_data) +{ + stroke->mode_data = mode_data; +} + +int paint_poll(bContext *C) +{ + Paint *p = paint_get_active(CTX_data_scene(C)); + Object *ob = CTX_data_active_object(C); + + return p && ob && paint_brush(p) && + CTX_wm_area(C)->spacetype == SPACE_VIEW3D && + CTX_wm_region(C)->regiontype == RGN_TYPE_WINDOW; +} + +void paint_cursor_start(bContext *C, int (*poll)(bContext *C)) +{ + Paint *p = paint_get_active(CTX_data_scene(C)); + + if(p && !p->paint_cursor) + p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL); +} + |