Paint: Fix Image Editor Cursor Disappearing (T90120)

This patch fixes T90120.  The fundamental problem is that 2d and the old 3d paint modes share a single Paint struct, ToolSettings->imapaint.  This patch is a temporary fix until the new 3d paint mode (which has its own Paint struct) is released.

The patch works by listening for `NC_SCENE|ND_MODE` inside `image_listener` in `space_image.c`.   It does not use `ED_space_image_paint_update` since that requires a `bMain.`  Instead it calls `paint_cursor_start` (which is promoted to `ED_paint_cursor_start`).  `image_paint_poll` is also promoted to an `ED_` function.

Reviewed By: Campbell Barton
Differential Revision: https://developer.blender.org/D14946
Ref D14946
This commit is contained in:
Joseph Eagar
2022-06-08 12:37:29 -07:00
parent 285a68b7bb
commit 371fc68678
9 changed files with 26 additions and 15 deletions

View File

@@ -24,6 +24,7 @@ struct Scene;
struct SpaceImage;
struct View2D;
struct bContext;
struct Paint;
struct wmOperator;
struct wmWindowManager;
@@ -187,6 +188,9 @@ ListBase ED_image_filesel_detect_sequences(struct Main *bmain,
struct wmOperator *op,
bool detect_udim);
bool ED_image_tools_paint_poll(struct bContext *C);
void ED_paint_cursor_start(struct Paint *p, bool (*poll)(struct bContext *C));
#ifdef __cplusplus
}
#endif

View File

@@ -17,6 +17,7 @@
#include "WM_api.h"
#include "WM_toolsystem.h"
#include "ED_image.h"
#include "ED_curves_sculpt.h"
#include "ED_object.h"
#include "ED_screen.h"
@@ -271,7 +272,7 @@ static void curves_sculptmode_enter(bContext *C)
ob->mode = OB_MODE_SCULPT_CURVES;
paint_cursor_start(&curves_sculpt->paint, CURVES_SCULPT_mode_poll_view3d);
ED_paint_cursor_start(&curves_sculpt->paint, CURVES_SCULPT_mode_poll_view3d);
/* Update for mode change. */
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);

View File

@@ -1932,7 +1932,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
/* Public API */
void paint_cursor_start(Paint *p, bool (*poll)(bContext *C))
void ED_paint_cursor_start(Paint *p, bool (*poll)(bContext *C))
{
if (p && !p->paint_cursor) {
p->paint_cursor = WM_paint_cursor_activate(

View File

@@ -272,7 +272,7 @@ static bool image_paint_poll_ex(bContext *C, bool check_tool)
SpaceImage *sima = CTX_wm_space_image(C);
if (sima) {
if (sima->image != nullptr &&
if (sima->image != NULL &&
(ID_IS_LINKED(sima->image) || ID_IS_OVERRIDE_LIBRARY(sima->image))) {
return false;
}
@@ -287,7 +287,7 @@ static bool image_paint_poll_ex(bContext *C, bool check_tool)
return false;
}
bool image_paint_poll(bContext *C)
bool ED_image_tools_paint_poll(bContext *C)
{
return image_paint_poll_ex(C, true);
}
@@ -301,7 +301,7 @@ static bool image_paint_2d_clone_poll(bContext *C)
{
Brush *brush = image_paint_brush(C);
if (!CTX_wm_region_view3d(C) && image_paint_poll(C)) {
if (!CTX_wm_region_view3d(C) && ED_image_tools_paint_poll(C)) {
if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) {
if (brush->clone.image) {
return true;
@@ -430,7 +430,7 @@ static void toggle_paint_cursor(Scene *scene, bool enable)
paint_cursor_delete_textures();
}
else if (enable) {
paint_cursor_start(p, image_paint_poll);
ED_paint_cursor_start(p, ED_image_tools_paint_poll);
}
}
@@ -455,7 +455,7 @@ void ED_space_image_paint_update(Main *bmain, wmWindowManager *wm, Scene *scene)
if (enabled) {
BKE_paint_init(bmain, scene, PAINT_MODE_TEXTURE_2D, PAINT_CURSOR_TEXTURE_PAINT);
paint_cursor_start(&imapaint->paint, image_paint_poll);
ED_paint_cursor_start(&imapaint->paint, ED_image_tools_paint_poll);
}
else {
paint_cursor_delete_textures();
@@ -925,7 +925,7 @@ static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op))
static bool brush_colors_flip_poll(bContext *C)
{
if (image_paint_poll(C)) {
if (ED_image_tools_paint_poll(C)) {
Brush *br = image_paint_brush(C);
if (ELEM(br->imagepaint_tool, PAINT_TOOL_DRAW, PAINT_TOOL_FILL)) {
return true;
@@ -991,7 +991,7 @@ static bool texture_paint_poll(bContext *C)
bool image_texture_paint_poll(bContext *C)
{
return (texture_paint_poll(C) || image_paint_poll(C));
return (texture_paint_poll(C) || ED_image_tools_paint_poll(C));
}
bool facemask_paint_poll(bContext *C)

View File

@@ -34,6 +34,8 @@
#include "WM_toolsystem.h"
#include "WM_types.h"
#include "ED_image.h"
#include "paint_intern.h"
namespace blender::ed::sculpt_paint::image::ops::paint {
@@ -316,7 +318,7 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
if ((brush->imagepaint_tool == PAINT_TOOL_FILL) && (brush->flag & BRUSH_USE_GRADIENT)) {
pop->cursor = WM_paint_cursor_activate(
SPACE_TYPE_ANY, RGN_TYPE_ANY, image_paint_poll, gradient_draw_line, pop);
SPACE_TYPE_ANY, RGN_TYPE_ANY, ED_image_tools_paint_poll, gradient_draw_line, pop);
}
settings->imapaint.flag |= IMAGEPAINT_DRAWING;
@@ -520,7 +522,7 @@ void PAINT_OT_image_paint(wmOperatorType *ot)
ot->invoke = paint_invoke;
ot->modal = paint_modal;
ot->exec = paint_exec;
ot->poll = image_paint_poll;
ot->poll = ED_image_tools_paint_poll;
ot->cancel = paint_cancel;
/* flags */

View File

@@ -98,7 +98,6 @@ void *paint_stroke_mode_data(struct PaintStroke *stroke);
float paint_stroke_distance_get(struct PaintStroke *stroke);
void paint_stroke_set_mode_data(struct PaintStroke *stroke, void *mode_data);
bool PAINT_brush_tool_poll(struct bContext *C);
void paint_cursor_start(struct Paint *p, bool (*poll)(struct bContext *C));
/**
* Delete overlay cursor textures to preserve memory and invalidate all overlay flags.
*/

View File

@@ -55,6 +55,7 @@
#include "WM_toolsystem.h"
#include "WM_types.h"
#include "ED_image.h"
#include "ED_armature.h"
#include "ED_mesh.h"
#include "ED_object.h"
@@ -1322,7 +1323,7 @@ static void ed_vwpaintmode_enter_generic(
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->vpaint);
Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
paint_cursor_start(paint, vertex_paint_poll);
ED_paint_cursor_start(paint, vertex_paint_poll);
BKE_paint_init(bmain, scene, paint_mode, PAINT_CURSOR_VERTEX_PAINT);
}
else if (mode_flag == OB_MODE_WEIGHT_PAINT) {
@@ -1330,7 +1331,7 @@ static void ed_vwpaintmode_enter_generic(
BKE_paint_ensure(scene->toolsettings, (Paint **)&scene->toolsettings->wpaint);
Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
paint_cursor_start(paint, weight_paint_poll);
ED_paint_cursor_start(paint, weight_paint_poll);
BKE_paint_init(bmain, scene, paint_mode, PAINT_CURSOR_WEIGHT_PAINT);
/* weight paint specific */

View File

@@ -84,6 +84,7 @@
#include "WM_toolsystem.h"
#include "WM_types.h"
#include "ED_image.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_sculpt.h"
@@ -349,7 +350,7 @@ void ED_object_sculptmode_enter_ex(Main *bmain,
Paint *paint = BKE_paint_get_active_from_paintmode(scene, PAINT_MODE_SCULPT);
BKE_paint_init(bmain, scene, PAINT_MODE_SCULPT, PAINT_CURSOR_SCULPT);
paint_cursor_start(paint, SCULPT_mode_poll_view3d);
ED_paint_cursor_start(paint, SCULPT_mode_poll_view3d);
/* Check dynamic-topology flag; re-enter dynamic-topology mode when changing modes,
* As long as no data was added that is not supported. */

View File

@@ -316,6 +316,9 @@ static void image_listener(const wmSpaceTypeListenerParams *params)
ED_area_tag_redraw(area);
break;
case ND_MODE:
ED_paint_cursor_start(&params->scene->toolsettings->imapaint.paint,
ED_image_tools_paint_poll);
if (wmn->subtype == NS_EDITMODE_MESH) {
ED_area_tag_refresh(area);
}