Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenkernel/BKE_paint.h2
-rw-r--r--source/blender/blenkernel/intern/paint.c48
-rw-r--r--source/blender/editors/sculpt_paint/paint_cursor.c6
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c5
-rw-r--r--source/blender/editors/sculpt_paint/paint_intern.h2
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c8
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c13
-rw-r--r--source/blender/editors/sculpt_paint/paint_utils.c8
-rw-r--r--source/blender/editors/space_buttons/buttons_texture.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c2
10 files changed, 73 insertions, 23 deletions
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index b32b7145ff4..419fb4cedae 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -32,6 +32,7 @@
* \ingroup bke
*/
+struct bContext;
struct Brush;
struct MDisps;
struct MeshElemMap;
@@ -55,6 +56,7 @@ void free_paint(struct Paint *p);
void copy_paint(struct Paint *src, struct Paint *tar);
struct Paint *paint_get_active(struct Scene *sce);
+struct Paint *paint_get_active_from_context(const struct bContext *C);
struct Brush *paint_brush(struct Paint *paint);
void paint_brush_set(struct Paint *paint, struct Brush *br);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index c7f904755d9..25553448306 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -41,6 +41,7 @@
#include "BLI_utildefines.h"
#include "BKE_brush.h"
+#include "BKE_context.h"
#include "BKE_library.h"
#include "BKE_paint.h"
#include "BKE_subsurf.h"
@@ -83,6 +84,53 @@ Paint *paint_get_active(Scene *sce)
return NULL;
}
+Paint *paint_get_active_from_context(const bContext *C)
+{
+ Scene *sce = CTX_data_scene(C);
+
+ if (sce) {
+ ToolSettings *ts = sce->toolsettings;
+ Object *obact = NULL;
+
+ if (sce->basact && sce->basact->object)
+ obact = sce->basact->object;
+
+ if (CTX_wm_space_image(C) != NULL) {
+ if (obact->mode == OB_MODE_EDIT) {
+ if (ts->use_uv_sculpt)
+ return &ts->uvsculpt->paint;
+ else
+ return &ts->imapaint.paint;
+ }
+ else {
+ return &ts->imapaint.paint;
+ }
+ }
+ else {
+ switch (obact->mode) {
+ case OB_MODE_SCULPT:
+ return &ts->sculpt->paint;
+ case OB_MODE_VERTEX_PAINT:
+ return &ts->vpaint->paint;
+ case OB_MODE_WEIGHT_PAINT:
+ return &ts->wpaint->paint;
+ case OB_MODE_TEXTURE_PAINT:
+ return &ts->imapaint.paint;
+ case OB_MODE_EDIT:
+ if (ts->use_uv_sculpt)
+ return &ts->uvsculpt->paint;
+ else
+ return &ts->imapaint.paint;
+ }
+
+ /* default to image paint */
+ return &ts->imapaint.paint;
+ }
+ }
+
+ return NULL;
+}
+
Brush *paint_brush(Paint *p)
{
return p ? p->brush : NULL;
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index b5d44676cf6..5ca436b07b2 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -333,7 +333,7 @@ static int sculpt_get_brush_geometry(bContext *C, ViewContext *vc,
float location[3])
{
Scene *scene = CTX_data_scene(C);
- Paint *paint = paint_get_active(scene);
+ Paint *paint = paint_get_active_from_context(C);
Brush *brush = paint_brush(paint);
float window[2];
int hit;
@@ -503,7 +503,7 @@ static void paint_cursor_on_hit(Sculpt *sd, Brush *brush, ViewContext *vc,
static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
{
Scene *scene = CTX_data_scene(C);
- Paint *paint = paint_get_active(scene);
+ Paint *paint = paint_get_active_from_context(C);
Brush *brush = paint_brush(paint);
ViewContext vc;
float final_radius;
@@ -605,7 +605,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
void paint_cursor_start(bContext *C, int (*poll)(bContext *C))
{
- Paint *p = paint_get_active(CTX_data_scene(C));
+ Paint *p = paint_get_active_from_context(C);
if (p && !p->paint_cursor)
p->paint_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), poll, paint_draw_cursor, NULL);
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index ed86cb67687..4dee83dbb82 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -5215,7 +5215,7 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
Scene *scene = CTX_data_scene(C);
//Brush *brush= image_paint_brush(C);
- Paint *paint = paint_get_active(scene);
+ Paint *paint = paint_get_active_from_context(C);
Brush *brush = paint_brush(paint);
if (paint && brush && paint->flags & PAINT_SHOW_BRUSH) {
@@ -5420,13 +5420,12 @@ void PAINT_OT_grab_clone(wmOperatorType *ot)
static int sample_color_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
Brush *brush = image_paint_brush(C);
ARegion *ar = CTX_wm_region(C);
int location[2];
RNA_int_get_array(op->ptr, "location", location);
- paint_sample_color(scene, ar, location[0], location[1]);
+ paint_sample_color(C, ar, location[0], location[1]);
WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, brush);
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index de149bf2806..794e7755636 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -137,7 +137,7 @@ float paint_get_tex_pixel(struct Brush *br, float u, float v);
int imapaint_pick_face(struct ViewContext *vc, const int mval[2], unsigned int *index, unsigned int totface);
void imapaint_pick_uv(struct Scene *scene, struct Object *ob, unsigned int faceindex, const int xy[2], float uv[2]);
-void paint_sample_color(struct Scene *scene, struct ARegion *ar, int x, int y);
+void paint_sample_color(const struct bContext *C, struct ARegion *ar, int x, int y);
void BRUSH_OT_curve_preset(struct wmOperatorType *ot);
void PAINT_OT_face_select_linked(struct wmOperatorType *ot);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 23d1c0090a0..7df6a893b5c 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -60,7 +60,7 @@
static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
{
/*int type = RNA_enum_get(op->ptr, "type");*/
- Paint *paint = paint_get_active(CTX_data_scene(C));
+ Paint *paint = paint_get_active_from_context(C);
struct Brush *br = paint_brush(paint);
if (br)
@@ -68,7 +68,7 @@ static int brush_add_exec(bContext *C, wmOperator *UNUSED(op))
else
br = BKE_brush_add("Brush");
- paint_brush_set(paint_get_active(CTX_data_scene(C)), br);
+ paint_brush_set(paint, br);
return OPERATOR_FINISHED;
}
@@ -91,7 +91,7 @@ static void BRUSH_OT_add(wmOperatorType *ot)
static int brush_scale_size_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- Paint *paint = paint_get_active(scene);
+ Paint *paint = paint_get_active_from_context(C);
struct Brush *brush = paint_brush(paint);
// Object *ob= CTX_data_active_object(C);
float scalar = RNA_float_get(op->ptr, "scalar");
@@ -173,7 +173,7 @@ static void PAINT_OT_vertex_color_set(wmOperatorType *ot)
static int brush_reset_exec(bContext *C, wmOperator *UNUSED(op))
{
- Paint *paint = paint_get_active(CTX_data_scene(C));
+ Paint *paint = paint_get_active_from_context(C);
struct Brush *brush = paint_brush(paint);
Object *ob = CTX_data_active_object(C);
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index 987ab932fd6..e36056e0fd9 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -100,10 +100,11 @@ typedef struct 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)));
+ Paint *paint = paint_get_active_from_context(C);
+ Brush *brush = paint_brush(paint);
PaintStroke *stroke = customdata;
- glColor4ubv(paint_get_active(CTX_data_scene(C))->paint_cursor_col);
+ glColor4ubv(paint->paint_cursor_col);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
@@ -141,7 +142,7 @@ static float event_tablet_data(wmEvent *event, int *pen_flip)
static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *event, float mouse_in[2])
{
Scene *scene = CTX_data_scene(C);
- Paint *paint = paint_get_active(scene);
+ Paint *paint = paint_get_active_from_context(C);
Brush *brush = paint_brush(paint);
PaintStroke *stroke = op->customdata;
float mouse[3];
@@ -281,7 +282,7 @@ PaintStroke *paint_stroke_new(bContext *C,
{
PaintStroke *stroke = MEM_callocN(sizeof(PaintStroke), "PaintStroke");
- stroke->brush = paint_brush(paint_get_active(CTX_data_scene(C)));
+ stroke->brush = paint_brush(paint_get_active_from_context(C));
view3d_set_viewcontext(C, &stroke->vc);
view3d_get_transformation(stroke->vc.ar, stroke->vc.rv3d, stroke->vc.obact, &stroke->mats);
@@ -394,7 +395,7 @@ static void paint_stroke_sample_average(const PaintStroke *stroke,
int paint_stroke_modal(bContext *C, wmOperator *op, wmEvent *event)
{
- Paint *p = paint_get_active(CTX_data_scene(C));
+ Paint *p = paint_get_active_from_context(C);
PaintStroke *stroke = op->customdata;
PaintSample sample_average;
float mouse[2];
@@ -518,7 +519,7 @@ void paint_stroke_set_mode_data(PaintStroke *stroke, void *mode_data)
int paint_poll(bContext *C)
{
- Paint *p = paint_get_active(CTX_data_scene(C));
+ Paint *p = paint_get_active_from_context(C);
Object *ob = CTX_data_active_object(C);
return p && ob && paint_brush(p) &&
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 4c374674c9a..082e40f8e4c 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -333,9 +333,9 @@ int imapaint_pick_face(ViewContext *vc, const int mval[2], unsigned int *index,
}
/* used for both 3d view and image window */
-void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf */
+void paint_sample_color(const bContext *C, ARegion *ar, int x, int y) /* frontbuf */
{
- Brush *br = paint_brush(paint_get_active(scene));
+ Brush *br = paint_brush(paint_get_active_from_context(C));
unsigned int col;
char *cp;
@@ -357,7 +357,7 @@ void paint_sample_color(Scene *scene, ARegion *ar, int x, int y) /* frontbuf
static int brush_curve_preset_exec(bContext *C, wmOperator *op)
{
- Brush *br = paint_brush(paint_get_active(CTX_data_scene(C)));
+ Brush *br = paint_brush(paint_get_active_from_context(C));
BKE_brush_curve_preset(br, RNA_enum_get(op->ptr, "shape"));
return OPERATOR_FINISHED;
@@ -365,7 +365,7 @@ static int brush_curve_preset_exec(bContext *C, wmOperator *op)
static int brush_curve_preset_poll(bContext *C)
{
- Brush *br = paint_brush(paint_get_active(CTX_data_scene(C)));
+ Brush *br = paint_brush(paint_get_active_from_context(C));
return br && br->curve;
}
diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c
index 5c5c24f7bc1..cdecda63432 100644
--- a/source/blender/editors/space_buttons/buttons_texture.c
+++ b/source/blender/editors/space_buttons/buttons_texture.c
@@ -175,7 +175,7 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
if (!(pinid || pinid == &scene->id)) {
ob = (scene->basact) ? scene->basact->object : NULL;
wrld = scene->world;
- brush = paint_brush(paint_get_active(scene));
+ brush = paint_brush(paint_get_active_from_context(C));
}
if (ob && ob->type == OB_LAMP && !la)
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 8ba0d75c786..d632314f3ca 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -498,7 +498,7 @@ static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
static void viewops_data_free(bContext *C, wmOperator *op)
{
ARegion *ar;
- Paint *p = paint_get_active(CTX_data_scene(C));
+ Paint *p = paint_get_active_from_context(C);
if (op->customdata) {
ViewOpsData *vod = op->customdata;