diff options
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_image.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 128 |
1 files changed, 87 insertions, 41 deletions
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 6ad2f98c520..e528c64b6e2 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -46,21 +46,23 @@ #include "IMB_imbuf_types.h" #include "DNA_brush_types.h" +#include "DNA_mesh_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" #include "BKE_colorband.h" #include "BKE_context.h" -#include "BKE_depsgraph.h" -#include "BKE_DerivedMesh.h" #include "BKE_brush.h" #include "BKE_main.h" #include "BKE_material.h" +#include "BKE_mesh.h" #include "BKE_node.h" #include "BKE_paint.h" #include "BKE_undo_system.h" +#include "DEG_depsgraph.h" + #include "UI_interface.h" #include "UI_view2d.h" @@ -72,15 +74,17 @@ #include "WM_api.h" #include "WM_types.h" +#include "WM_message.h" +#include "WM_toolsystem.h" #include "RNA_access.h" #include "RNA_define.h" #include "GPU_draw.h" -#include "GPU_buffers.h" +#include "GPU_immediate.h" +#include "GPU_state.h" #include "BIF_gl.h" -#include "BIF_glutil.h" #include "IMB_colormanagement.h" @@ -265,7 +269,7 @@ static Brush *image_paint_brush(bContext *C) return BKE_paint_brush(&settings->imapaint.paint); } -static bool image_paint_poll(bContext *C) +static bool image_paint_poll_ex(bContext *C, bool check_tool) { Object *obact; @@ -274,7 +278,9 @@ static bool image_paint_poll(bContext *C) obact = CTX_data_active_object(C); if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) { - return 1; + if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) { + return 1; + } } else { SpaceImage *sima = CTX_wm_space_image(C); @@ -291,6 +297,16 @@ static bool image_paint_poll(bContext *C) return 0; } +static bool image_paint_poll(bContext *C) +{ + return image_paint_poll_ex(C, true); +} + +static bool image_paint_ignore_tool_poll(bContext *C) +{ + return image_paint_poll_ex(C, false); +} + static bool image_paint_2d_clone_poll(bContext *C) { Brush *brush = image_paint_brush(C); @@ -400,18 +416,34 @@ static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customda PaintOperation *pop = (PaintOperation *)customdata; if (pop) { - glEnable(GL_LINE_SMOOTH); - glEnable(GL_BLEND); - - glLineWidth(4.0); - glColor4ub(0, 0, 0, 255); - sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]); - glLineWidth(2.0); - glColor4ub(255, 255, 255, 255); - sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]); - - glDisable(GL_BLEND); - glDisable(GL_LINE_SMOOTH); + GPU_line_smooth(true); + GPU_blend(true); + + GPUVertFormat *format = immVertexFormat(); + uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_I32, 2, GPU_FETCH_INT_TO_FLOAT); + + immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR); + + GPU_line_width(4.0); + immUniformColor4ub(0, 0, 0, 255); + + immBegin(GPU_PRIM_LINES, 2); + immVertex2i(pos, x, y); + immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]); + immEnd(); + + GPU_line_width(2.0); + immUniformColor4ub(255, 255, 255, 255); + + immBegin(GPU_PRIM_LINES, 2); + immVertex2i(pos, x, y); + immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]); + immEnd(); + + immUnbindProgram(); + + GPU_blend(false); + GPU_line_smooth(false); } } @@ -430,7 +462,8 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo /* initialize from context */ if (CTX_wm_region_view3d(C)) { - Object *ob = OBACT; + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); bool uvs, mat, tex, stencil; if (!BKE_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) { BKE_paint_data_warning(op->reports, uvs, mat, tex, stencil); @@ -452,7 +485,11 @@ 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(CTX_wm_manager(C), image_paint_poll, gradient_draw_line, pop); + pop->cursor = WM_paint_cursor_activate( + CTX_wm_manager(C), + SPACE_TYPE_ANY, RGN_TYPE_ANY, + image_paint_poll, gradient_draw_line, + pop); } settings->imapaint.flag |= IMAGEPAINT_DRAWING; @@ -717,16 +754,20 @@ static void toggle_paint_cursor(bContext *C, int enable) void ED_space_image_paint_update(Main *bmain, wmWindowManager *wm, Scene *scene) { ToolSettings *settings = scene->toolsettings; - wmWindow *win; - ScrArea *sa; ImagePaintSettings *imapaint = &settings->imapaint; bool enabled = false; - for (win = wm->windows.first; win; win = win->next) - for (sa = win->screen->areabase.first; sa; sa = sa->next) - if (sa->spacetype == SPACE_IMAGE) - if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT) + for (wmWindow *win = wm->windows.first; win; win = win->next) { + bScreen *screen = WM_window_get_active_screen(win); + + for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) { + if (sa->spacetype == SPACE_IMAGE) { + if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT) { enabled = true; + } + } + } + } if (enabled) { BKE_paint_init(bmain, scene, ePaintTexture2D, PAINT_CURSOR_TEXTURE_PAINT); @@ -857,7 +898,7 @@ static void sample_color_update_header(SampleColorData *data, bContext *C) !data->sample_palette ? IFACE_("Brush. Use Left Click to sample for palette instead") : IFACE_("Palette. Use Left Click to sample more colors")); - ED_area_headerprint(sa, msg); + ED_workspace_status_text(C, msg); } } @@ -936,8 +977,6 @@ static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event) Brush *brush = BKE_paint_brush(paint); if ((event->type == data->event_type) && (event->val == KM_RELEASE)) { - ScrArea *sa = CTX_wm_area(C); - if (data->show_cursor) { paint->flags |= PAINT_SHOW_BRUSH; } @@ -948,7 +987,7 @@ static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event) } WM_cursor_modal_restore(CTX_wm_window(C)); MEM_freeN(data); - ED_area_headerprint(sa, NULL); + ED_workspace_status_text(C, NULL); return OPERATOR_FINISHED; } @@ -983,11 +1022,6 @@ static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_RUNNING_MODAL; } -static bool sample_color_poll(bContext *C) -{ - return (image_paint_poll(C) || vertex_paint_poll(C)); -} - void PAINT_OT_sample_color(wmOperatorType *ot) { /* identifiers */ @@ -999,7 +1033,7 @@ void PAINT_OT_sample_color(wmOperatorType *ot) ot->exec = sample_color_exec; ot->invoke = sample_color_invoke; ot->modal = sample_color_modal; - ot->poll = sample_color_poll; + ot->poll = image_paint_ignore_tool_poll; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1031,6 +1065,7 @@ static bool texture_paint_toggle_poll(bContext *C) static int texture_paint_toggle_exec(bContext *C, wmOperator *op) { + struct wmMsgBus *mbus = CTX_wm_message_bus(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); @@ -1083,8 +1118,10 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) if (sl->spacetype == SPACE_IMAGE) { SpaceImage *sima = (SpaceImage *)sl; - if (!sima->pin) - ED_space_image_set(bmain, sima, scene, scene->obedit, ima); + if (!sima->pin) { + Object *obedit = CTX_data_edit_object(C); + ED_space_image_set(bmain, sima, scene, obedit, ima); + } } } } @@ -1095,6 +1132,8 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) BKE_paint_init(bmain, scene, ePaintTexture3D, PAINT_CURSOR_TEXTURE_PAINT); + BKE_paint_toolslots_brush_validate(bmain, &imapaint->paint); + if (U.glreslimit != 0) GPU_free_images(bmain); GPU_paint_set_mipmap(bmain, 0); @@ -1102,9 +1141,16 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op) toggle_paint_cursor(C, 1); } - GPU_drawobject_free(ob->derivedFinal); + Mesh *me = BKE_mesh_from_object(ob); + BLI_assert(me != NULL); + DEG_id_tag_update(&me->id, DEG_TAG_COPY_ON_WRITE); + WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene); + WM_msg_publish_rna_prop(mbus, &ob->id, ob, Object, mode); + + WM_toolsystem_update_from_context_view3d(C); + return OPERATOR_FINISHED; } @@ -1128,8 +1174,8 @@ static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op)) { UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; - Brush *br; Object *ob = CTX_data_active_object(C); + Brush *br; if (!(ob && (ob->mode & OB_MODE_VERTEX_PAINT))) { br = image_paint_brush(C); } @@ -1198,7 +1244,7 @@ void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op) BKE_undosys_step_push(wm->undo_stack, C, op->type->name); - DAG_id_tag_update(&ima->id, 0); + DEG_id_tag_update(&ima->id, 0); } |