Added radial control support to vpaint and wpaint. Added undo pushes as well.

This commit is contained in:
2009-01-25 21:02:52 +00:00
parent 3c088f3434
commit 3d39996f0f
6 changed files with 220 additions and 67 deletions

View File

@@ -1255,7 +1255,11 @@ static int sculpt_radial_control_modal(bContext *C, wmOperator *op, wmEvent *eve
static int sculpt_radial_control_exec(bContext *C, wmOperator *op)
{
return 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);
char str[256];
WM_radial_control_string(op, str, 256);
ED_undo_push(C, str);
return ret;
}
static void SCULPT_OT_radial_control(wmOperatorType *ot)

View File

@@ -107,6 +107,8 @@ void VIEW3D_OT_borderselect(struct wmOperatorType *ot);
void VIEW3D_OT_lasso_select(struct wmOperatorType *ot);
/* vpaint.c */
void VIEW3D_OT_vpaint_radial_control(struct wmOperatorType *ot);
void VIEW3D_OT_wpaint_radial_control(struct wmOperatorType *ot);
void VIEW3D_OT_vpaint_toggle(struct wmOperatorType *ot);
void VIEW3D_OT_vpaint(struct wmOperatorType *ot);
void VIEW3D_OT_wpaint_toggle(struct wmOperatorType *ot);

View File

@@ -80,6 +80,8 @@ void view3d_operatortypes(void)
WM_operatortype_append(VIEW3D_OT_lasso_select);
WM_operatortype_append(VIEW3D_OT_setcameratoview);
WM_operatortype_append(VIEW3D_OT_drawtype);
WM_operatortype_append(VIEW3D_OT_vpaint_radial_control);
WM_operatortype_append(VIEW3D_OT_wpaint_radial_control);
WM_operatortype_append(VIEW3D_OT_vpaint_toggle);
WM_operatortype_append(VIEW3D_OT_wpaint_toggle);
WM_operatortype_append(VIEW3D_OT_vpaint);
@@ -98,10 +100,6 @@ void view3d_keymap(wmWindowManager *wm)
WM_keymap_verify_item(keymap, "VIEW3D_OT_wpaint", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", WM_RADIALCONTROL_ANGLE);
WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0);
@@ -168,6 +166,16 @@ void view3d_keymap(wmWindowManager *wm)
WM_keymap_add_item(keymap, "VIEW3D_OT_vpaint_toggle", VKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "VIEW3D_OT_wpaint_toggle", TABKEY, KM_PRESS, KM_CTRL, 0);
/* radial control */
RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
RNA_enum_set(WM_keymap_add_item(keymap, "SCULPT_OT_radial_control", FKEY, KM_PRESS, KM_CTRL, 0)->ptr, "mode", WM_RADIALCONTROL_ANGLE);
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_vpaint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_wpaint_radial_control", FKEY, KM_PRESS, 0, 0)->ptr, "mode", WM_RADIALCONTROL_SIZE);
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_vpaint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_wpaint_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "mode", WM_RADIALCONTROL_STRENGTH);
/* TODO - this is just while we have no way to load a text datablock */
km = WM_keymap_add_item(keymap, "SCRIPT_OT_run_pyfile", PKEY, KM_PRESS, 0, 0);
RNA_string_set(km->ptr, "filename", "test.py");

View File

@@ -61,6 +61,8 @@
#include "DNA_view3d_types.h"
#include "DNA_userdef_types.h"
#include "RNA_access.h"
#include "BKE_armature.h"
#include "BKE_DerivedMesh.h"
#include "BKE_cloth.h"
@@ -105,6 +107,84 @@
static void BIF_undo_push() {}
static void error() {}
/* polling - retrieve whether cursor should be set or operator should be done */
static int vp_poll(bContext *C)
{
if(G.f & G_VERTEXPAINT) {
ScrArea *sa= CTX_wm_area(C);
if(sa->spacetype==SPACE_VIEW3D) {
ARegion *ar= CTX_wm_region(C);
if(ar->regiontype==RGN_TYPE_WINDOW)
return 1;
}
}
return 0;
}
static int wp_poll(bContext *C)
{
if(G.f & G_WEIGHTPAINT) {
ScrArea *sa= CTX_wm_area(C);
if(sa->spacetype==SPACE_VIEW3D) {
ARegion *ar= CTX_wm_region(C);
if(ar->regiontype==RGN_TYPE_WINDOW)
return 1;
}
}
return 0;
}
/* Cursors */
static void vp_drawcursor(bContext *C, int x, int y, void *customdata)
{
ToolSettings *ts= CTX_data_tool_settings(C);
glTranslatef((float)x, (float)y, 0.0f);
glColor4ub(255, 255, 255, 128);
glEnable( GL_LINE_SMOOTH );
glEnable(GL_BLEND);
glutil_draw_lined_arc(0.0, M_PI*2.0, ts->vpaint->size, 40);
glDisable(GL_BLEND);
glDisable( GL_LINE_SMOOTH );
glTranslatef((float)-x, (float)-y, 0.0f);
}
static void wp_drawcursor(bContext *C, int x, int y, void *customdata)
{
ToolSettings *ts= CTX_data_tool_settings(C);
glTranslatef((float)x, (float)y, 0.0f);
glColor4ub(200, 200, 255, 128);
glEnable( GL_LINE_SMOOTH );
glEnable(GL_BLEND);
glutil_draw_lined_arc(0.0, M_PI*2.0, ts->wpaint->size, 40);
glDisable(GL_BLEND);
glDisable( GL_LINE_SMOOTH );
glTranslatef((float)-x, (float)-y, 0.0f);
}
static void toggle_paint_cursor(bContext *C, int wpaint)
{
ToolSettings *ts = CTX_data_scene(C)->toolsettings;
VPaint *vp = wpaint ? ts->wpaint : ts->vpaint;
if(vp->paintcursor) {
WM_paint_cursor_end(CTX_wm_manager(C), vp->paintcursor);
vp->paintcursor = NULL;
}
else {
vp->paintcursor = wpaint ?
WM_paint_cursor_activate(CTX_wm_manager(C), wp_poll, wp_drawcursor, NULL) :
WM_paint_cursor_activate(CTX_wm_manager(C), vp_poll, vp_drawcursor, NULL);
}
}
static VPaint *new_vpaint(int wpaint)
{
VPaint *vp= MEM_callocN(sizeof(VPaint), "VPaint");
@@ -1055,35 +1135,6 @@ static void do_weight_paint_vertex(VPaint *wp, Object *ob, int index, int alpha,
/* *************** set wpaint operator ****************** */
/* retrieve whether cursor should be set or operator should be done */
static int wp_poll(bContext *C)
{
if(G.f & G_WEIGHTPAINT) {
ScrArea *sa= CTX_wm_area(C);
if(sa->spacetype==SPACE_VIEW3D) {
ARegion *ar= CTX_wm_region(C);
if(ar->regiontype==RGN_TYPE_WINDOW)
return 1;
}
}
return 0;
}
static void wp_drawcursor(bContext *C, int x, int y, void *customdata)
{
ToolSettings *ts= CTX_data_tool_settings(C);
glTranslatef((float)x, (float)y, 0.0f);
glColor4ub(200, 200, 255, 128);
glEnable( GL_LINE_SMOOTH );
glEnable(GL_BLEND);
glutil_draw_lined_arc(0.0, M_PI*2.0, ts->wpaint->size, 40);
glDisable(GL_BLEND);
glDisable( GL_LINE_SMOOTH );
glTranslatef((float)-x, (float)-y, 0.0f);
}
static int set_wpaint(bContext *C, wmOperator *op) /* toggle */
{
@@ -1118,7 +1169,7 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */
if(wp==NULL)
wp= scene->toolsettings->wpaint= new_vpaint(1);
wp->paintcursor = WM_paint_cursor_activate(CTX_wm_manager(C), wp_poll, wp_drawcursor, NULL);
toggle_paint_cursor(C, 1);
mesh_octree_table(ob, NULL, NULL, 's');
@@ -1135,7 +1186,7 @@ static int set_wpaint(bContext *C, wmOperator *op) /* toggle */
}
else {
if(wp)
WM_paint_cursor_end(CTX_wm_manager(C), wp->paintcursor);
toggle_paint_cursor(C, 1);
mesh_octree_table(ob, NULL, NULL, 'e');
}
@@ -1158,6 +1209,108 @@ void VIEW3D_OT_wpaint_toggle(wmOperatorType *ot)
}
/* ************ paint radial controls *************/
void paint_radial_control_invoke(wmOperator *op, VPaint *vp)
{
int mode = RNA_int_get(op->ptr, "mode");
float original_value;
if(mode == WM_RADIALCONTROL_SIZE)
original_value = vp->size;
else if(mode == WM_RADIALCONTROL_STRENGTH)
original_value = vp->a;
RNA_float_set(op->ptr, "initial_value", original_value);
}
static int paint_radial_control_exec(wmOperator *op, VPaint *vp)
{
int mode = RNA_int_get(op->ptr, "mode");
float new_value = RNA_float_get(op->ptr, "new_value");
if(mode == WM_RADIALCONTROL_SIZE)
vp->size = new_value;
else if(mode == WM_RADIALCONTROL_STRENGTH)
vp->a = new_value;
return OPERATOR_FINISHED;
}
static int vpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
toggle_paint_cursor(C, 0);
paint_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->vpaint);
return WM_radial_control_invoke(C, op, event);
}
static int vpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
{
int ret = WM_radial_control_modal(C, op, event);
if(ret != OPERATOR_RUNNING_MODAL)
toggle_paint_cursor(C, 0);
return ret;
}
static int vpaint_radial_control_exec(bContext *C, wmOperator *op)
{
int ret = paint_radial_control_exec(op, CTX_data_scene(C)->toolsettings->vpaint);
char str[256];
WM_radial_control_string(op, str, 256);
ED_undo_push(C, str);
return ret;
}
static int wpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
toggle_paint_cursor(C, 1);
paint_radial_control_invoke(op, CTX_data_scene(C)->toolsettings->wpaint);
return WM_radial_control_invoke(C, op, event);
}
static int wpaint_radial_control_modal(bContext *C, wmOperator *op, wmEvent *event)
{
int ret = WM_radial_control_modal(C, op, event);
if(ret != OPERATOR_RUNNING_MODAL)
toggle_paint_cursor(C, 1);
return ret;
}
static int wpaint_radial_control_exec(bContext *C, wmOperator *op)
{
int ret = paint_radial_control_exec(op, CTX_data_scene(C)->toolsettings->wpaint);
char str[256];
WM_radial_control_string(op, str, 256);
ED_undo_push(C, str);
return ret;
}
void VIEW3D_OT_wpaint_radial_control(wmOperatorType *ot)
{
WM_OT_radial_control_partial(ot);
ot->name= "Weight Paint Radial Control";
ot->idname= "VIEW3D_OT_wpaint_radial_control";
ot->invoke= wpaint_radial_control_invoke;
ot->modal= wpaint_radial_control_modal;
ot->exec= wpaint_radial_control_exec;
ot->poll= wp_poll;
}
void VIEW3D_OT_vpaint_radial_control(wmOperatorType *ot)
{
WM_OT_radial_control_partial(ot);
ot->name= "Vertex Paint Radial Control";
ot->idname= "VIEW3D_OT_vpaint_radial_control";
ot->invoke= vpaint_radial_control_invoke;
ot->modal= vpaint_radial_control_modal;
ot->exec= vpaint_radial_control_exec;
ot->poll= vp_poll;
}
/* ************ weight paint operator ********** */
struct WPaintData {
@@ -1487,35 +1640,6 @@ void VIEW3D_OT_wpaint(wmOperatorType *ot)
/* ************ set / clear vertex paint mode ********** */
/* retrieve whether cursor should be set or operator should be done */
static int vp_poll(bContext *C)
{
if(G.f & G_VERTEXPAINT) {
ScrArea *sa= CTX_wm_area(C);
if(sa->spacetype==SPACE_VIEW3D) {
ARegion *ar= CTX_wm_region(C);
if(ar->regiontype==RGN_TYPE_WINDOW)
return 1;
}
}
return 0;
}
static void vp_drawcursor(bContext *C, int x, int y, void *customdata)
{
ToolSettings *ts= CTX_data_tool_settings(C);
glTranslatef((float)x, (float)y, 0.0f);
glColor4ub(255, 255, 255, 128);
glEnable( GL_LINE_SMOOTH );
glEnable(GL_BLEND);
glutil_draw_lined_arc(0.0, M_PI*2.0, ts->vpaint->size, 40);
glDisable(GL_BLEND);
glDisable( GL_LINE_SMOOTH );
glTranslatef((float)-x, (float)-y, 0.0f);
}
static int set_vpaint(bContext *C, wmOperator *op) /* toggle */
{
@@ -1545,7 +1669,7 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */
G.f &= ~G_VERTEXPAINT;
if(vp) {
WM_paint_cursor_end(CTX_wm_manager(C), vp->paintcursor);
toggle_paint_cursor(C, 0);
vp->paintcursor= NULL;
}
}
@@ -1559,7 +1683,7 @@ static int set_vpaint(bContext *C, wmOperator *op) /* toggle */
if(vp==NULL)
vp= scene->toolsettings->vpaint= new_vpaint(0);
vp->paintcursor = WM_paint_cursor_activate(CTX_wm_manager(C), vp_poll, vp_drawcursor, NULL);
toggle_paint_cursor(C, 0);
}
if (me)

View File

@@ -160,6 +160,7 @@ void WM_gesture_end(struct bContext *C, struct wmGesture *gesture);
int WM_radial_control_invoke(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
int WM_radial_control_modal(struct bContext *C, struct wmOperator *op, struct wmEvent *event);
void WM_OT_radial_control_partial(struct wmOperatorType *ot);
void WM_radial_control_string(struct wmOperator *op, char str[], int maxlen);
/* OpenGL wrappers, mimicking opengl syntax */
void wmSubWindowSet (struct wmWindow *win, int swinid);

View File

@@ -1075,6 +1075,20 @@ int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
return OPERATOR_RUNNING_MODAL;
}
/* Gets a descriptive string of the operation */
void WM_radial_control_string(wmOperator *op, char str[], int maxlen)
{
int mode = RNA_int_get(op->ptr, "mode");
float v = RNA_float_get(op->ptr, "new_value");
if(mode == WM_RADIALCONTROL_SIZE)
sprintf(str, "Size: %d", (int)v);
else if(mode == WM_RADIALCONTROL_STRENGTH)
sprintf(str, "Strength: %d", (int)v);
else if(mode == WM_RADIALCONTROL_ANGLE)
sprintf(str, "Angle: %d", (int)(v * 180.0f/M_PI));
}
/** Important: this doesn't define an actual operator, it
just sets up the common parts of the radial control op. **/
void WM_OT_radial_control_partial(wmOperatorType *ot)