diff --git a/release/datafiles/userdef/userdef_default.c b/release/datafiles/userdef/userdef_default.c index 4ab4b75e710..0c4ac7f63d2 100644 --- a/release/datafiles/userdef/userdef_default.c +++ b/release/datafiles/userdef/userdef_default.c @@ -242,7 +242,7 @@ const UserDef U_default = { .statusbar_flag = STATUSBAR_SHOW_VERSION | STATUSBAR_SHOW_EXTENSIONS_UPDATES, .file_preview_type = USER_FILE_PREVIEW_AUTO, - .sequencer_editor_flag = USER_SEQ_ED_SIMPLE_TWEAKING, + .sequencer_editor_flag = USER_SEQ_ED_SIMPLE_TWEAKING | USER_SEQ_ED_CONNECT_STRIPS_BY_DEFAULT, .runtime = { diff --git a/source/blender/draw/engines/overlay/overlay_grease_pencil.cc b/source/blender/draw/engines/overlay/overlay_grease_pencil.cc index b206452509a..5e93cebe2a4 100644 --- a/source/blender/draw/engines/overlay/overlay_grease_pencil.cc +++ b/source/blender/draw/engines/overlay/overlay_grease_pencil.cc @@ -8,15 +8,20 @@ #include "DRW_render.hh" +#include "draw_manager_text.hh" + #include "ED_grease_pencil.hh" #include "BKE_attribute.hh" +#include "BKE_curves.hh" #include "BKE_grease_pencil.hh" #include "DNA_grease_pencil_types.h" #include "overlay_private.hh" +#include "DEG_depsgraph_query.hh" + static void is_selection_visible(bool &r_show_points, bool &r_show_lines) { using namespace blender; @@ -58,6 +63,82 @@ static void is_selection_visible(bool &r_show_points, bool &r_show_lines) r_show_lines = flag_show_lines; } +static void overlay_grease_pencil_draw_stroke_color_name(Object &object, + const int mat_nr, + const blender::float3 position) +{ + Material *ma = BKE_object_material_get_eval(&object, mat_nr + 1); + const DRWContextState *draw_ctx = DRW_context_state_get(); + ViewLayer *view_layer = draw_ctx->view_layer; + + int theme_id = DRW_object_wire_theme_get(&object, view_layer, nullptr); + uchar color[4]; + UI_GetThemeColor4ubv(theme_id, color); + + const float3 fpt = blender::math::transform_point(object.object_to_world(), position); + + DRWTextStore *dt = DRW_text_cache_ensure(); + DRW_text_cache_add(dt, + fpt, + ma->id.name + 2, + strlen(ma->id.name + 2), + 10, + 0, + DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, + color); +} + +static void OVERLAY_grease_pencil_material_names(Object *ob) +{ + using namespace blender; + + const DRWContextState *draw_ctx = DRW_context_state_get(); + + bool show_points = false; + bool show_lines = false; + is_selection_visible(show_points, show_lines); + + GreasePencil &grease_pencil = *static_cast(ob->data); + + Vector drawings = ed::greasepencil::retrieve_visible_drawings( + *draw_ctx->scene, grease_pencil, false); + if (drawings.is_empty()) { + return; + } + + for (const ed::greasepencil::DrawingInfo &info : drawings) { + const bke::greasepencil::Drawing &drawing = info.drawing; + + const bke::CurvesGeometry strokes = drawing.strokes(); + const OffsetIndices points_by_curve = strokes.points_by_curve(); + const bke::AttrDomain domain = show_points ? bke::AttrDomain::Point : bke::AttrDomain::Curve; + const VArray selections = *strokes.attributes().lookup_or_default( + ".selection", domain, true); + const VArray materials = *strokes.attributes().lookup_or_default( + "material_index", bke::AttrDomain::Curve, 0); + const Span positions = strokes.positions(); + + auto show_stroke_name = [&](const int stroke_i) { + if (show_points) { + for (const int point_i : points_by_curve[stroke_i]) { + if (selections[point_i]) { + return true; + } + } + return false; + } + return selections[stroke_i]; + }; + + for (const int stroke_i : strokes.curves_range()) { + const int point_i = points_by_curve[stroke_i].first(); + if (show_stroke_name(stroke_i)) { + overlay_grease_pencil_draw_stroke_color_name(*ob, materials[stroke_i], positions[point_i]); + } + } + } +} + void OVERLAY_edit_grease_pencil_cache_init(OVERLAY_Data *vedata) { using namespace blender; @@ -137,7 +218,7 @@ void OVERLAY_grease_pencil_cache_init(OVERLAY_Data *vedata) const GreasePencil &grease_pencil = *static_cast(ob->data); if (ts->gp_sculpt.lock_axis != GP_LOCKAXIS_CURSOR && grease_pencil.has_active_layer()) { - const blender::bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer(); + const bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer(); mat = layer.to_world_space(*ob); } const View3DCursor *cursor = &scene->cursor; @@ -170,7 +251,7 @@ void OVERLAY_grease_pencil_cache_init(OVERLAY_Data *vedata) mat.location() = cursor->location; } else if (grease_pencil.has_active_layer()) { - const blender::bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer(); + const bke::greasepencil::Layer &layer = *grease_pencil.get_active_layer(); mat.location() = layer.to_world_space(*ob).location(); } /* Local transform of the grid from the overlay settings. */ @@ -222,6 +303,14 @@ void OVERLAY_edit_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *ob) DRW_shgroup_call_no_cull(points_grp, geom_points, ob); } } + + View3D *v3d = draw_ctx->v3d; + /* Don't show object extras in set's. */ + if ((ob->base_flag & (BASE_FROM_SET | BASE_FROM_DUPLI)) == 0) { + if ((v3d->gp_flag & V3D_GP_SHOW_MATERIAL_NAME) && DRW_state_show_text()) { + OVERLAY_grease_pencil_material_names(ob); + } + } } void OVERLAY_sculpt_grease_pencil_cache_populate(OVERLAY_Data *vedata, Object *ob)