forked from bartvdbraak/blender
Fix #23336: radial control crashing or not showing correct colors in modes
other than sculpt. The sculpt changes made the radial control code sculpt mode specific, it should be usable for various purposes, so made it generic again now.
This commit is contained in:
parent
07cfb4f4f5
commit
4c094d700e
@ -1144,10 +1144,16 @@ static int vpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *ev
|
||||
{
|
||||
Paint *p = paint_get_active(CTX_data_scene(C));
|
||||
Brush *brush = paint_brush(p);
|
||||
float col[4];
|
||||
|
||||
WM_paint_cursor_end(CTX_wm_manager(C), p->paint_cursor);
|
||||
p->paint_cursor = NULL;
|
||||
brush_radial_control_invoke(op, brush, 1);
|
||||
|
||||
copy_v3_v3(col, brush->add_col);
|
||||
col[3]= 0.5f;
|
||||
RNA_float_set_array(op->ptr, "color", col);
|
||||
|
||||
return WM_radial_control_invoke(C, op, event);
|
||||
}
|
||||
|
||||
@ -1173,10 +1179,16 @@ static int wpaint_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *ev
|
||||
{
|
||||
Paint *p = paint_get_active(CTX_data_scene(C));
|
||||
Brush *brush = paint_brush(p);
|
||||
float col[4];
|
||||
|
||||
WM_paint_cursor_end(CTX_wm_manager(C), p->paint_cursor);
|
||||
p->paint_cursor = NULL;
|
||||
brush_radial_control_invoke(op, brush, 1);
|
||||
|
||||
copy_v3_v3(col, brush->add_col);
|
||||
col[3]= 0.5f;
|
||||
RNA_float_set_array(op->ptr, "color", col);
|
||||
|
||||
return WM_radial_control_invoke(C, op, event);
|
||||
}
|
||||
|
||||
|
@ -2726,10 +2726,24 @@ static int sculpt_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *ev
|
||||
{
|
||||
Paint *p = paint_get_active(CTX_data_scene(C));
|
||||
Brush *brush = paint_brush(p);
|
||||
float col[4], tex_col[4];
|
||||
|
||||
WM_paint_cursor_end(CTX_wm_manager(C), p->paint_cursor);
|
||||
p->paint_cursor = NULL;
|
||||
brush_radial_control_invoke(op, brush, 1);
|
||||
|
||||
if((brush->flag & BRUSH_DIR_IN) && ELEM4(brush->sculpt_tool, SCULPT_TOOL_DRAW, SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY, SCULPT_TOOL_PINCH))
|
||||
copy_v3_v3(col, brush->sub_col);
|
||||
else
|
||||
copy_v3_v3(col, brush->add_col);
|
||||
col[3]= 0.5f;
|
||||
|
||||
copy_v3_v3(tex_col, U.sculpt_paint_overlay_col);
|
||||
tex_col[3]= (brush->texture_overlay_alpha / 100.0f);
|
||||
|
||||
RNA_float_set_array(op->ptr, "color", col);
|
||||
RNA_float_set_array(op->ptr, "texture_color", tex_col);
|
||||
|
||||
return WM_radial_control_invoke(C, op, event);
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_brush_types.h"
|
||||
#include "DNA_userdef_types.h"
|
||||
#include "DNA_windowmanager_types.h"
|
||||
|
||||
@ -64,7 +63,6 @@
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_screen.h" /* BKE_ST_MAXNAME */
|
||||
#include "BKE_utildefines.h"
|
||||
#include "BKE_brush.h" // JW
|
||||
#include "BKE_idcode.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
@ -74,7 +72,6 @@
|
||||
|
||||
#include "ED_screen.h"
|
||||
#include "ED_util.h"
|
||||
#include "ED_view3d.h" // JW
|
||||
|
||||
#include "RNA_access.h"
|
||||
#include "RNA_define.h"
|
||||
@ -92,8 +89,6 @@
|
||||
#include "wm_subwindow.h"
|
||||
#include "wm_window.h"
|
||||
|
||||
|
||||
|
||||
static ListBase global_ops= {NULL, NULL};
|
||||
|
||||
/* ************ operator API, exported ********** */
|
||||
@ -2585,33 +2580,22 @@ const int WM_RADIAL_CONTROL_DISPLAY_SIZE = 200;
|
||||
typedef struct wmRadialControl {
|
||||
int mode;
|
||||
float initial_value, value, max_value;
|
||||
float col[4], tex_col[4];
|
||||
int initial_mouse[2];
|
||||
void *cursor;
|
||||
GLuint tex;
|
||||
} wmRadialControl;
|
||||
|
||||
extern Paint *paint_get_active(Scene *sce);
|
||||
extern struct Brush *paint_brush(struct Paint *paint);
|
||||
|
||||
static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
|
||||
{
|
||||
wmRadialControl *rc = (wmRadialControl*)customdata;
|
||||
ARegion *ar = CTX_wm_region(C);
|
||||
float r1=0.0f, r2=0.0f, r3=0.0f, angle=0.0f;
|
||||
|
||||
Paint *paint = paint_get_active(CTX_data_scene(C));
|
||||
struct Brush *brush = paint_brush(paint);
|
||||
|
||||
ViewContext vc;
|
||||
|
||||
// int hit = 0;
|
||||
|
||||
int flip;
|
||||
int sign;
|
||||
|
||||
float* col;
|
||||
|
||||
const float str = rc->mode == WM_RADIALCONTROL_STRENGTH ? (rc->value + 0.5) : (brush->texture_overlay_alpha / 100.0f);
|
||||
|
||||
if(rc->mode == WM_RADIALCONTROL_STRENGTH)
|
||||
rc->tex_col[3]= (rc->value + 0.5);
|
||||
|
||||
if(rc->mode == WM_RADIALCONTROL_SIZE) {
|
||||
r1= rc->value;
|
||||
@ -2629,18 +2613,6 @@ static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
|
||||
x = rc->initial_mouse[0] - ar->winrct.xmin;
|
||||
y = rc->initial_mouse[1] - ar->winrct.ymin;
|
||||
|
||||
view3d_set_viewcontext(C, &vc);
|
||||
|
||||
// XXX: no way currently to know state of pen flip or invert key modifier without starting a stroke
|
||||
flip = 1;
|
||||
|
||||
sign = flip * ((brush->flag & BRUSH_DIR_IN)? -1 : 1);
|
||||
|
||||
if (sign < 0 && ELEM4(brush->sculpt_tool, SCULPT_TOOL_DRAW, SCULPT_TOOL_INFLATE, SCULPT_TOOL_CLAY, SCULPT_TOOL_PINCH))
|
||||
col = brush->sub_col;
|
||||
else
|
||||
col = brush->add_col;
|
||||
|
||||
glTranslatef((float)x, (float)y, 0.0f);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
@ -2657,7 +2629,7 @@ static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBegin(GL_QUADS);
|
||||
glColor4f(U.sculpt_paint_overlay_col[0],U.sculpt_paint_overlay_col[1],U.sculpt_paint_overlay_col[2], str);
|
||||
glColor4f(rc->tex_col[0], rc->tex_col[1], rc->tex_col[2], rc->tex_col[3]);
|
||||
glTexCoord2f(0,0);
|
||||
glVertex2f(-r3, -r3);
|
||||
glTexCoord2f(1,0);
|
||||
@ -2671,7 +2643,7 @@ static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
|
||||
}
|
||||
|
||||
if(rc->mode == WM_RADIALCONTROL_ANGLE) {
|
||||
glColor4f(col[0], col[1], col[2], 0.5f);
|
||||
glColor4f(rc->col[0], rc->col[1], rc->col[2], rc->col[3]);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glRotatef(-angle, 0, 0, 1);
|
||||
fdrawline(0, 0, WM_RADIAL_CONTROL_DISPLAY_SIZE, 0);
|
||||
@ -2680,7 +2652,7 @@ static void wm_radial_control_paint(bContext *C, int x, int y, void *customdata)
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
}
|
||||
|
||||
glColor4f(col[0], col[1], col[2], 0.5f);
|
||||
glColor4f(rc->col[0], rc->col[1], rc->col[2], rc->col[3]);
|
||||
glutil_draw_lined_arc(0.0, M_PI*2.0, r1, 40);
|
||||
glutil_draw_lined_arc(0.0, M_PI*2.0, r2, 40);
|
||||
glDisable(GL_BLEND);
|
||||
@ -2806,6 +2778,9 @@ int WM_radial_control_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
MEM_freeN(im);
|
||||
}
|
||||
|
||||
RNA_float_get_array(op->ptr, "color", rc->col);
|
||||
RNA_float_get_array(op->ptr, "texture_color", rc->tex_col);
|
||||
|
||||
RNA_int_set_array(op->ptr, "initial_mouse", mouse);
|
||||
RNA_float_set(op->ptr, "new_value", initial_value);
|
||||
|
||||
@ -2850,6 +2825,8 @@ void WM_OT_radial_control_partial(wmOperatorType *ot)
|
||||
{WM_RADIALCONTROL_STRENGTH, "STRENGTH", 0, "Strength", ""},
|
||||
{WM_RADIALCONTROL_ANGLE, "ANGLE", 0, "Angle", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
static float color[4] = {1.0f, 1.0f, 1.0f, 0.5f};
|
||||
static float tex_color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
|
||||
/* Should be set in custom invoke() */
|
||||
RNA_def_float(ot->srna, "initial_value", 0, 0, FLT_MAX, "Initial Value", "", 0, FLT_MAX);
|
||||
@ -2861,7 +2838,10 @@ void WM_OT_radial_control_partial(wmOperatorType *ot)
|
||||
RNA_def_enum(ot->srna, "mode", radial_mode_items, 0, "Mode", "");
|
||||
|
||||
/* Internal */
|
||||
RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "initial_mouse", "", INT_MIN, INT_MAX);
|
||||
RNA_def_int_vector(ot->srna, "initial_mouse", 2, NULL, INT_MIN, INT_MAX, "Initial Mouse", "", INT_MIN, INT_MAX);
|
||||
|
||||
RNA_def_float_color(ot->srna, "color", 4, color, 0.0f, FLT_MAX, "Color", "Radial control color", 0.0f, 1.0f);
|
||||
RNA_def_float_color(ot->srna, "texture_color", 4, tex_color, 0.0f, FLT_MAX, "Texture Color", "Radial control texture color", 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
/* ************************** timer for testing ***************** */
|
||||
|
Loading…
Reference in New Issue
Block a user