diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-02-22 22:31:25 +0300 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2009-02-22 22:31:25 +0300 |
commit | 674aae36b6fadf97613cc11758c32503b0f5f2f4 (patch) | |
tree | aa9d55871c01e52cc6f623c1320bc4c955f6feac /source/blender/editors/sculpt_paint | |
parent | 7c8d98acb83f0568b3db9c700f456d829d509cc3 (diff) |
* Added radial control for texture paint (in both view3d and image)
* bugfix: for older files, initialize the brush curve on file load
Diffstat (limited to 'source/blender/editors/sculpt_paint')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 181 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 4 |
4 files changed, 143 insertions, 46 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index ee5aa1ee4a7..cf076f5d464 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -4759,6 +4759,110 @@ void PAINT_OT_image_paint(wmOperatorType *ot) RNA_def_collection_runtime(ot->srna, "stroke", &RNA_OperatorStrokeElement, "Stroke", ""); } +static int get_imapaint_zoom(bContext *C, float *zoomx, float *zoomy) +{ + RegionView3D *rv3d= CTX_wm_region_view3d(C); + + if(!rv3d) { + SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); + ARegion *ar= CTX_wm_region(C); + + ED_space_image_zoom(sima, ar, zoomx, zoomy); + + return 1; + } + + *zoomx = *zoomy = 1; + + return 0; +} + +/************************ cursor drawing *******************************/ + +static void brush_drawcursor(bContext *C, int x, int y, void *customdata) +{ + Brush *brush= image_paint_brush(C); + + if(brush) { + float zoomx, zoomy; + glPushMatrix(); + + glTranslatef((float)x, (float)y, 0.0f); + + if(get_imapaint_zoom(C, &zoomx, &zoomy)) + glScalef(zoomx, zoomy, 1.0f); + + glColor4ub(255, 255, 255, 128); + glEnable( GL_LINE_SMOOTH ); + glEnable(GL_BLEND); + glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size*0.5f, 40); + glDisable(GL_BLEND); + glDisable( GL_LINE_SMOOTH ); + + glPopMatrix(); + } +} + +static void toggle_paint_cursor(bContext *C, int enable) +{ + ToolSettings *settings= CTX_data_scene(C)->toolsettings; + + if(settings->imapaint.paintcursor && !enable) { + WM_paint_cursor_end(CTX_wm_manager(C), settings->imapaint.paintcursor); + settings->imapaint.paintcursor = NULL; + } + else if(enable) + settings->imapaint.paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, brush_drawcursor, NULL); +} + +/* ************ image paint radial control *************/ +static int paint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + float zoom; + ToolSettings *ts = CTX_data_scene(C)->toolsettings; + get_imapaint_zoom(C, &zoom, &zoom); + toggle_paint_cursor(C, !ts->imapaint.paintcursor); + brush_radial_control_invoke(op, ts->imapaint.brush, 0.5 * zoom); + return WM_radial_control_invoke(C, op, event); +} + +static int paint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + ToolSettings *ts = CTX_data_scene(C)->toolsettings; + int ret = WM_radial_control_modal(C, op, event); + if(ret != OPERATOR_RUNNING_MODAL) + toggle_paint_cursor(C, !ts->imapaint.paintcursor); + return ret; +} + +static int paint_radial_control_exec(bContext *C, wmOperator *op) +{ + float zoom; + int ret; + char str[256]; + get_imapaint_zoom(C, &zoom, &zoom); + ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->imapaint.brush, 2.0 / zoom); + WM_radial_control_string(op, str, 256); + + return ret; +} + +void PAINT_OT_image_paint_radial_control(wmOperatorType *ot) +{ + WM_OT_radial_control_partial(ot); + + ot->name= "Image Paint Radial Control"; + ot->idname= "PAINT_OT_image_paint_radial_control"; + + ot->invoke= paint_radial_control_invoke; + ot->modal= paint_radial_control_modal; + ot->exec= paint_radial_control_exec; + ot->poll= image_paint_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /************************ grab clone operator ************************/ typedef struct GrabClone { @@ -4962,50 +5066,6 @@ void PAINT_OT_set_clone_cursor(wmOperatorType *ot) RNA_def_float_vector(ot->srna, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "Cursor location in world space coordinates.", -10000.0f, 10000.0f); } -/************************ cursor drawing *******************************/ - -static void brush_drawcursor(bContext *C, int x, int y, void *customdata) -{ - Brush *brush= image_paint_brush(C); - RegionView3D *rv3d= CTX_wm_region_view3d(C); - - if(brush) { - glPushMatrix(); - - glTranslatef((float)x, (float)y, 0.0f); - - if(!rv3d) { - SpaceImage *sima= (SpaceImage*)CTX_wm_space_data(C); - ARegion *ar= CTX_wm_region(C); - float zoomx, zoomy; - - ED_space_image_zoom(sima, ar, &zoomx, &zoomy); - glScalef(zoomx, zoomy, 1.0f); - } - - glColor4ub(255, 255, 255, 128); - glEnable( GL_LINE_SMOOTH ); - glEnable(GL_BLEND); - glutil_draw_lined_arc(0.0, M_PI*2.0, brush->size*0.5f, 40); - glDisable(GL_BLEND); - glDisable( GL_LINE_SMOOTH ); - - glPopMatrix(); - } -} - -static void toggle_paint_cursor(bContext *C, int enable) -{ - ToolSettings *settings= CTX_data_scene(C)->toolsettings; - - if(settings->imapaint.paintcursor && !enable) { - WM_paint_cursor_end(CTX_wm_manager(C), settings->imapaint.paintcursor); - settings->imapaint.paintcursor = NULL; - } - else if(enable) - settings->imapaint.paintcursor= WM_paint_cursor_activate(CTX_wm_manager(C), image_paint_poll, brush_drawcursor, NULL); -} - /******************** texture paint toggle operator ********************/ static int texture_paint_toggle_poll(bContext *C) @@ -5076,3 +5136,36 @@ void PAINT_OT_texture_paint_toggle(wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } +/* ************ texture paint radial control *************/ +static int texture_paint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + ToolSettings *ts = CTX_data_scene(C)->toolsettings; + toggle_paint_cursor(C, !ts->imapaint.paintcursor); + brush_radial_control_invoke(op, ts->imapaint.brush, 0.5); + return WM_radial_control_invoke(C, op, event); +} + +static int texture_paint_radial_control_exec(bContext *C, wmOperator *op) +{ + int ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->imapaint.brush, 2); + char str[256]; + WM_radial_control_string(op, str, 256); + + return ret; +} + +void PAINT_OT_texture_paint_radial_control(wmOperatorType *ot) +{ + WM_OT_radial_control_partial(ot); + + ot->name= "Texture Paint Radial Control"; + ot->idname= "PAINT_OT_texture_paint_radial_control"; + + ot->invoke= texture_paint_radial_control_invoke; + ot->modal= paint_radial_control_modal; + ot->exec= texture_paint_radial_control_exec; + ot->poll= texture_paint_toggle_poll; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index a5ac3264eee..7e1ecd9629a 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -47,10 +47,12 @@ void PAINT_OT_vertex_paint(struct wmOperatorType *ot); /* paint_image.c */ void PAINT_OT_image_paint(struct wmOperatorType *ot); +void PAINT_OT_image_paint_radial_control(struct wmOperatorType *ot); void PAINT_OT_grab_clone(struct wmOperatorType *ot); void PAINT_OT_sample_color(struct wmOperatorType *ot); void PAINT_OT_set_clone_cursor(struct wmOperatorType *ot); void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot); +void PAINT_OT_texture_paint_radial_control(struct wmOperatorType *ot); /* paint_utils.c */ int imapaint_pick_face(struct ViewContext *vc, struct Mesh *me, int *mval, unsigned int *index); diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c index 0918e8c9b94..6b3a36de826 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.c +++ b/source/blender/editors/sculpt_paint/paint_ops.c @@ -12,7 +12,9 @@ void ED_operatortypes_paint(void) { /* image */ WM_operatortype_append(PAINT_OT_texture_paint_toggle); + WM_operatortype_append(PAINT_OT_texture_paint_radial_control); WM_operatortype_append(PAINT_OT_image_paint); + WM_operatortype_append(PAINT_OT_image_paint_radial_control); WM_operatortype_append(PAINT_OT_sample_color); WM_operatortype_append(PAINT_OT_grab_clone); WM_operatortype_append(PAINT_OT_set_clone_cursor); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 8987479bbfc..40aaee758b9 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -1261,7 +1261,7 @@ static void SCULPT_OT_brush_curve_preset(wmOperatorType *ot) static int sculpt_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event) { toggle_paint_cursor(C); - brush_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->sculpt->brush); + brush_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->sculpt->brush, 1); return WM_radial_control_invoke(C, op, event); } @@ -1275,7 +1275,7 @@ static int sculpt_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve static int sculpt_radial_control_exec(bContext *C, wmOperator *op) { - int ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->sculpt->brush); + int ret = brush_radial_control_exec(op, CTX_data_scene(C)->toolsettings->sculpt->brush, 1); char str[256]; WM_radial_control_string(op, str, 256); |