[Bf-blender-cvs] [a38d07223e7] temp-T96709-painting-target: Toolsystem uses paint canvas.
Jeroen Bakker
noreply at git.blender.org
Mon Mar 28 15:26:20 CEST 2022
Commit: a38d07223e77c2a78329d8eb9bff1ee39641dc88
Author: Jeroen Bakker
Date: Mon Mar 28 15:26:14 2022 +0200
Branches: temp-T96709-painting-target
https://developer.blender.org/rBa38d07223e77c2a78329d8eb9bff1ee39641dc88
Toolsystem uses paint canvas.
===================================================================
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/draw/engines/workbench/workbench_engine.c
M source/blender/editors/include/ED_paint.h
M source/blender/editors/sculpt_paint/paint_canvas.cc
===================================================================
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index ced9ac579c6..a956ecbefdd 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -2231,11 +2231,12 @@ class VIEW3D_PT_tools_paint_canvas(View3DPanel, Panel):
if context.active_object is None:
return False
+ # TODO: connect to ED_paint_tool_use_canvas.
from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
tool_context = ToolSelectPanelHelper.tool_active_from_context(context)
if not tool_context:
return False
-
+
return tool_context.idname in [
"builtin_brush.Paint",
"builtin.color_filter",
diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c
index 3490e9198e4..6e5ee9bfe35 100644
--- a/source/blender/draw/engines/workbench/workbench_engine.c
+++ b/source/blender/draw/engines/workbench/workbench_engine.c
@@ -318,8 +318,13 @@ static eV3DShadingColorType workbench_color_type_get(WORKBENCH_PrivateData *wpd,
}
if (is_sculpt_pbvh) {
- color_type = ED_paint_draw_color_override(
- &wpd->scene->toolsettings->paint_mode, ob, color_type);
+ /* Bad call C is required to access the tool system that is context aware. Cast to non-const
+ * due to current API. */
+ bContext *C = (bContext *)DRW_context_state_get()->evil_C;
+ if (C != NULL) {
+ color_type = ED_paint_draw_color_override(
+ C, &wpd->scene->toolsettings->paint_mode, ob, color_type);
+ }
}
if (r_draw_shadow) {
diff --git a/source/blender/editors/include/ED_paint.h b/source/blender/editors/include/ED_paint.h
index e1a42ee5162..7442ef5a116 100644
--- a/source/blender/editors/include/ED_paint.h
+++ b/source/blender/editors/include/ED_paint.h
@@ -119,14 +119,18 @@ void ED_paint_canvas_material_itemf(struct Object *ob,
int *r_totitem);
struct Image *ED_paint_canvas_image_get(const struct PaintModeSettings *settings,
struct Object *ob);
-int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
+int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
struct Object *ob);
/** Color type of an object can be overridden in sculpt/paint mode. */
-eV3DShadingColorType ED_paint_draw_color_override(const struct PaintModeSettings *settings,
+eV3DShadingColorType ED_paint_draw_color_override(struct bContext *C,
+ const struct PaintModeSettings *settings,
struct Object *ob,
eV3DShadingColorType orig_color_type);
+/** Does the active tool uses a paint canvas for the given object. */
+bool ED_paint_tool_use_canvas(struct bContext *C, struct Object *ob);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/sculpt_paint/paint_canvas.cc b/source/blender/editors/sculpt_paint/paint_canvas.cc
index 8c33052a72e..dad50f77711 100644
--- a/source/blender/editors/sculpt_paint/paint_canvas.cc
+++ b/source/blender/editors/sculpt_paint/paint_canvas.cc
@@ -11,6 +11,7 @@
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_node_types.h"
+#include "DNA_workspace_types.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
@@ -24,6 +25,8 @@
#include "RNA_access.h"
#include "RNA_define.h"
+#include "WM_toolsystem.h"
+
namespace blender::ed::sculpt_paint::canvas {
/**
@@ -415,11 +418,12 @@ void ED_paint_canvas_material_itemf(Object *ob, struct EnumPropertyItem **r_item
}
}
-eV3DShadingColorType ED_paint_draw_color_override(const PaintModeSettings *settings,
+eV3DShadingColorType ED_paint_draw_color_override(bContext *C,
+ const PaintModeSettings *settings,
Object *ob,
eV3DShadingColorType orig_color_type)
{
- if (ob->sculpt == nullptr) {
+ if (!ED_paint_tool_use_canvas(C, ob)) {
return orig_color_type;
}
@@ -504,4 +508,24 @@ int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settin
}
return -1;
}
+
+bool ED_paint_tool_use_canvas(struct bContext *C, struct Object *ob)
+{
+ /* Quick exit, only sculpt tools can use canvas. */
+ if (ob->sculpt == nullptr) {
+ return false;
+ }
+
+ bToolRef *tref = WM_toolsystem_ref_from_context(C);
+ if (tref != nullptr) {
+ if (STREQ(tref->idname, "builtin_brush.Paint")) {
+ return true;
+ }
+ if (STREQ(tref->idname, "builtin.color_filter")) {
+ return true;
+ }
+ }
+
+ return false;
+}
}
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list