UV/Image Editor: Overlay Popover

The overlay options in the image/uv editor is hidden in side panels and menus. Sometimes this panel is even hidden, while still useful.
The goal of this task is to introduce an overlay pop-over just like the overlay-popover of the 3d viewport.

Popover has
* UV Stretching (only available in the UV mode, when active object mode is a mesh and in OB_EDIT mode)
* Display As (only available in the UV mode, when active object mode is a mesh and in OB_EDIT mode)
* Show Modified (only available in the UV mode, when active object mode is a mesh and in OB_EDIT mode)
* Show UV Edges (including opacity slider; available UV, View, Paint, when active object mode is a mesh and in OB_EDIT mode)
* Udim tiles when no image is available.

Like the 3d viewport, there will be a editor toggle to enable/disable the overlays

For compatibility reasons the RNA properties are added to both the `SpaceImage.uv_editor` amd `SpaceImage.overlay`. On DNA level they are still stored in the SpaceImage. only new properties are added to the SpaceImageOverlay struct. During the next major release we could remove these options from `SpaceImage.uv_editor`. This should be noted in the Python section of release notes.

Reviewed By: Julian Eisel, Pablo Vazquez

Differential Revision: https://developer.blender.org/D8890
This commit is contained in:
Jeroen Bakker 2020-10-07 16:29:15 +02:00 committed by Jeroen Bakker
parent fc767502dc
commit afab33e0b9
Notes: blender-bot 2023-02-14 00:20:15 +01:00
Referenced by issue #80767, UV Image Editor: Overlay Popover
10 changed files with 224 additions and 86 deletions

View File

@ -742,6 +742,7 @@ class IMAGE_HT_header(Header):
layout = self.layout
sima = context.space_data
overlay = sima.overlay
ima = sima.image
iuser = sima.image_user
tool_settings = context.tool_settings
@ -787,6 +788,13 @@ class IMAGE_HT_header(Header):
layout.separator_spacer()
# Overlay toggle & popover
row = layout.row(align=True)
row.prop(overlay, "show_overlays", icon='OVERLAY', text="")
sub = row.row(align=True)
sub.active = overlay.show_overlays
sub.popover(panel="IMAGE_PT_overlay", text="")
if show_uvedit:
uvedit = sima.uv_editor
@ -994,68 +1002,6 @@ class IMAGE_PT_view_display(Panel):
col.prop(uvedit, "show_pixel_coords", text="Pixel Coordinates")
class IMAGE_PT_view_display_uv_edit_overlays(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
bl_label = "Overlays"
bl_parent_id = 'IMAGE_PT_view_display'
bl_category = "View"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and (sima.show_uvedit))
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
sima = context.space_data
uvedit = sima.uv_editor
col = layout.column()
col.prop(uvedit, "edge_display_type", text="Display As")
col.prop(uvedit, "show_faces", text="Faces")
col = layout.column()
if context.preferences.experimental.use_image_editor_legacy_drawing:
col.prop(uvedit, "show_smooth_edges", text="Smooth")
col.prop(uvedit, "show_modified_edges", text="Modified")
col.prop(uvedit, "uv_opacity")
class IMAGE_PT_view_display_uv_edit_overlays_stretch(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
bl_label = "Stretching"
bl_parent_id = 'IMAGE_PT_view_display_uv_edit_overlays'
bl_category = "View"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and (sima.show_uvedit))
def draw_header(self, context):
sima = context.space_data
uvedit = sima.uv_editor
self.layout.prop(uvedit, "show_stretch", text="")
def draw(self, context):
layout = self.layout
layout.use_property_split = True
sima = context.space_data
uvedit = sima.uv_editor
layout.active = uvedit.show_stretch
layout.prop(uvedit, "display_stretch_type", text="Type")
class IMAGE_UL_render_slots(UIList):
def draw_item(self, _context, layout, _data, item, _icon, _active_data, _active_propname, _index):
slot = item
@ -1512,6 +1458,119 @@ class IMAGE_PT_udim_grid(Panel):
col.prop(uvedit, "tile_grid_shape", text="Grid Shape")
class IMAGE_PT_overlay(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'HEADER'
bl_label = "Overlays"
bl_ui_units_x = 13
def draw(self, context):
pass
class IMAGE_PT_overlay_uv_edit(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'HEADER'
bl_label = "UV Editing"
bl_parent_id = 'IMAGE_PT_overlay'
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and (sima.show_uvedit))
def draw(self, context):
layout = self.layout
sima = context.space_data
uvedit = sima.uv_editor
overlay = sima.overlay
layout.active = overlay.show_overlays
# UV Stretching
row = layout.row()
row.prop(uvedit, "show_stretch")
subrow = row.row(align=True)
subrow.active = uvedit.show_stretch
subrow.prop(uvedit, "display_stretch_type", text="")
class IMAGE_PT_overlay_uv_edit_geometry(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'HEADER'
bl_label = "Geometry"
bl_parent_id = 'IMAGE_PT_overlay'
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and (sima.show_uvedit))
def draw(self, context):
layout = self.layout
sima = context.space_data
uvedit = sima.uv_editor
overlay = sima.overlay
layout.active = overlay.show_overlays
# Edges
col = layout.column()
col.prop(uvedit, "uv_opacity")
col.prop(uvedit, "edge_display_type", text="")
if context.preferences.experimental.use_image_editor_legacy_drawing:
col.prop(uvedit, "show_smooth_edges", text="Smooth")
col.prop(uvedit, "show_modified_edges", text="Modified Edges")
# Faces
row = col.row()
row.active = not uvedit.show_stretch
row.prop(uvedit, "show_faces", text="Faces")
class IMAGE_PT_overlay_texture_paint(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'HEADER'
bl_label = "Geometry"
bl_parent_id = 'IMAGE_PT_overlay'
@classmethod
def poll(cls, context):
sima = context.space_data
return (sima and (sima.show_paint))
def draw(self, context):
layout = self.layout
sima = context.space_data
uvedit = sima.uv_editor
overlay = sima.overlay
layout.active = overlay.show_overlays
layout.prop(uvedit, "show_texpaint")
class IMAGE_PT_overlay_image(Panel):
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'HEADER'
bl_label = "Image"
bl_parent_id = 'IMAGE_PT_overlay'
def draw(self, context):
layout = self.layout
sima = context.space_data
uvedit = sima.uv_editor
overlay = sima.overlay
layout.active = overlay.show_overlays
layout.prop(uvedit, "show_metadata")
# Grease Pencil properties
class IMAGE_PT_annotation(AnnotationDataPanel, Panel):
bl_space_type = 'IMAGE_EDITOR'
@ -1560,8 +1619,6 @@ classes = (
IMAGE_UL_udim_tiles,
IMAGE_PT_udim_tiles,
IMAGE_PT_view_display,
IMAGE_PT_view_display_uv_edit_overlays,
IMAGE_PT_view_display_uv_edit_overlays_stretch,
IMAGE_PT_paint_select,
IMAGE_PT_paint_settings,
IMAGE_PT_paint_color,
@ -1587,6 +1644,11 @@ classes = (
IMAGE_PT_uv_cursor,
IMAGE_PT_annotation,
IMAGE_PT_udim_grid,
IMAGE_PT_overlay,
IMAGE_PT_overlay_uv_edit,
IMAGE_PT_overlay_uv_edit_geometry,
IMAGE_PT_overlay_texture_paint,
IMAGE_PT_overlay_image,
)

View File

@ -806,5 +806,19 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
}
}
}
/* UV/Image show overlay option. */
if (!DNA_struct_find(fd->filesdna, "SpaceImageOverlay")) {
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) {
if (space->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)space;
sima->overlay.flag = SI_OVERLAY_SHOW_OVERLAYS;
}
}
}
}
}
}
}

View File

@ -78,6 +78,7 @@ void OVERLAY_edit_uv_init(OVERLAY_Data *vedata)
SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
const Scene *scene = draw_ctx->scene;
const ToolSettings *ts = scene->toolsettings;
const bool show_overlays = !pd->hide_overlays;
Image *image = sima->image;
/* By design no image is an image type. This so editor shows UV's by default. */
@ -99,21 +100,20 @@ void OVERLAY_edit_uv_init(OVERLAY_Data *vedata)
((sima->flag & SI_DRAW_STRETCH) != 0);
const bool do_tex_paint_shadows = (sima->flag & SI_NO_DRAW_TEXPAINT) == 0;
pd->edit_uv.do_faces = do_faces && !do_uvstretching_overlay;
pd->edit_uv.do_face_dots = do_faces && do_face_dots;
pd->edit_uv.do_uv_overlay = do_uv_overlay;
pd->edit_uv.do_uv_shadow_overlay = is_image_type &&
pd->edit_uv.do_faces = show_overlays && do_faces && !do_uvstretching_overlay;
pd->edit_uv.do_face_dots = show_overlays && do_faces && do_face_dots;
pd->edit_uv.do_uv_overlay = show_overlays && do_uv_overlay;
pd->edit_uv.do_uv_shadow_overlay = show_overlays && is_image_type &&
((is_paint_mode && do_tex_paint_shadows &&
((draw_ctx->object_mode &
(OB_MODE_TEXTURE_PAINT | OB_MODE_EDIT)) != 0)) ||
(is_view_mode && do_tex_paint_shadows &&
((draw_ctx->object_mode & (OB_MODE_TEXTURE_PAINT)) != 0)) ||
(do_uv_overlay && (show_modified_uvs)));
pd->edit_uv.do_uv_stretching_overlay = do_uvstretching_overlay;
pd->edit_uv.do_uv_stretching_overlay = show_overlays && do_uvstretching_overlay;
pd->edit_uv.uv_opacity = sima->uv_opacity;
pd->edit_uv.do_tiled_image_overlay = is_image_type && is_tiled_image;
pd->edit_uv.do_tiled_image_overlay = show_overlays && is_image_type && is_tiled_image;
pd->edit_uv.do_tiled_image_border_overlay = is_image_type && is_tiled_image;
pd->edit_uv.dash_length = 4.0f * UI_DPI_FAC;
pd->edit_uv.line_style = edit_uv_line_style_from_space_image(sima);
pd->edit_uv.do_smooth_wire = ((U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE) > 0);
@ -223,7 +223,7 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata)
}
}
if (pd->edit_uv.do_tiled_image_overlay) {
if (pd->edit_uv.do_tiled_image_border_overlay) {
const DRWContextState *draw_ctx = DRW_context_state_get();
SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
Image *image = sima->image;
@ -252,14 +252,22 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata)
obmat[3][0] = (float)tile_x;
DRW_shgroup_call_obmat(grp, geom, obmat);
}
/* Only mark active border when overlays are enabled. */
if (pd->edit_uv.do_tiled_image_overlay) {
/* Active tile border */
ImageTile *active_tile = BLI_findlink(&image->tiles, image->active_tile_index);
obmat[3][0] = (float)((active_tile->tile_number - 1001) % 10);
obmat[3][1] = (float)((active_tile->tile_number - 1001) / 10);
grp = DRW_shgroup_create(sh, psl->edit_uv_tiled_image_borders_ps);
DRW_shgroup_uniform_vec4_copy(grp, "color", selected_color);
DRW_shgroup_call_obmat(grp, geom, obmat);
}
}
/* Active tile border */
ImageTile *active_tile = BLI_findlink(&image->tiles, image->active_tile_index);
obmat[3][0] = (float)((active_tile->tile_number - 1001) % 10);
obmat[3][1] = (float)((active_tile->tile_number - 1001) / 10);
grp = DRW_shgroup_create(sh, psl->edit_uv_tiled_image_borders_ps);
DRW_shgroup_uniform_vec4_copy(grp, "color", selected_color);
DRW_shgroup_call_obmat(grp, geom, obmat);
if (pd->edit_uv.do_tiled_image_overlay) {
const DRWContextState *draw_ctx = DRW_context_state_get();
SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
Image *image = sima->image;
struct DRWTextStore *dt = DRW_text_cache_ensure();
uchar color[4];
@ -377,7 +385,7 @@ void OVERLAY_edit_uv_draw(OVERLAY_Data *vedata)
OVERLAY_StorageList *stl = vedata->stl;
OVERLAY_PrivateData *pd = stl->pd;
if (pd->edit_uv.do_tiled_image_overlay) {
if (pd->edit_uv.do_tiled_image_border_overlay) {
DRW_draw_pass(psl->edit_uv_tiled_image_borders_ps);
}

View File

@ -66,6 +66,7 @@ static void OVERLAY_engine_init(void *vedata)
pd->is_image_editor = sima != NULL;
if (pd->is_image_editor) {
pd->hide_overlays = (sima->overlay.flag & SI_OVERLAY_SHOW_OVERLAYS) == 0;
pd->clipping_state = 0;
OVERLAY_grid_init(data);
OVERLAY_edit_uv_init(data);

View File

@ -356,6 +356,7 @@ typedef struct OVERLAY_PrivateData {
bool do_uv_shadow_overlay;
bool do_uv_stretching_overlay;
bool do_tiled_image_overlay;
bool do_tiled_image_border_overlay;
bool do_faces;
bool do_face_dots;

View File

@ -208,11 +208,14 @@ static bool is_cursor_visible_2d(const DRWContextState *draw_ctx)
if (space_data == NULL) {
return false;
}
if (space_data->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)draw_ctx->space_data;
return sima->mode == SI_MODE_UV;
if (space_data->spacetype != SPACE_IMAGE) {
return false;
}
return false;
SpaceImage *sima = (SpaceImage *)space_data;
if (sima->mode != SI_MODE_UV) {
return false;
}
return (sima->overlay.flag & SI_OVERLAY_SHOW_OVERLAYS) != 0;
}
void DRW_draw_cursor_2d(void)

View File

@ -128,6 +128,7 @@ static SpaceLink *image_create(const ScrArea *UNUSED(area), const Scene *UNUSED(
simage->lock = true;
simage->flag = SI_SHOW_GPENCIL | SI_USE_ALPHA | SI_COORDFLOATS;
simage->uv_opacity = 1.0f;
simage->overlay.flag = SI_OVERLAY_SHOW_OVERLAYS;
BKE_imageuser_default(&simage->iuser);
simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS;

View File

@ -1037,6 +1037,12 @@ enum {
* \{ */
/* Image/UV Editor */
typedef struct SpaceImageOverlay {
int flag;
char _pad[4];
} SpaceImageOverlay;
typedef struct SpaceImage {
SpaceLink *next, *prev;
/** Storage of regions for inactive spaces. */
@ -1096,6 +1102,7 @@ typedef struct SpaceImage {
int tile_grid_shape[2];
MaskSpaceInfo mask_info;
SpaceImageOverlay overlay;
} SpaceImage;
/* SpaceImage.dt_uv */
@ -1158,7 +1165,7 @@ typedef enum eSpaceImage_Flag {
SI_PREVSPACE = (1 << 15),
SI_FULLWINDOW = (1 << 16),
SI_FLAG_UNUSED_17 = (1 << 17), /* cleared */
SI_FLAG_UNUSED_17 = (1 << 17),
SI_FLAG_UNUSED_18 = (1 << 18), /* cleared */
/**
@ -1181,6 +1188,10 @@ typedef enum eSpaceImage_Flag {
SI_SHOW_B = (1 << 29),
} eSpaceImage_Flag;
typedef enum eSpaceImageOverlay_Flag {
SI_OVERLAY_SHOW_OVERLAYS = (1 << 0),
} eSpaceImageOverlay_Flag;
/** \} */
/* -------------------------------------------------------------------- */

View File

@ -585,6 +585,7 @@ extern StructRNA RNA_SpaceDopeSheetEditor;
extern StructRNA RNA_SpaceFileBrowser;
extern StructRNA RNA_SpaceGraphEditor;
extern StructRNA RNA_SpaceImageEditor;
extern StructRNA RNA_SpaceImageOverlay;
extern StructRNA RNA_SpaceInfo;
extern StructRNA RNA_SpaceNLA;
extern StructRNA RNA_SpaceNodeEditor;

View File

@ -1397,6 +1397,16 @@ static char *rna_View3DOverlay_path(PointerRNA *UNUSED(ptr))
/* Space Image Editor */
static PointerRNA rna_SpaceImage_overlay_get(PointerRNA *ptr)
{
return rna_pointer_inherit_refine(ptr, &RNA_SpaceImageOverlay, ptr->data);
}
static char *rna_SpaceImageOverlay_path(PointerRNA *UNUSED(ptr))
{
return BLI_strdup("overlay");
}
static char *rna_SpaceUVEditor_path(PointerRNA *UNUSED(ptr))
{
return BLI_strdup("uv_editor");
@ -4512,6 +4522,23 @@ static void rna_def_space_properties(BlenderRNA *brna)
prop, NC_SPACE | ND_SPACE_PROPERTIES, "rna_SpaceProperties_search_filter_update");
}
static void rna_def_space_image_overlay(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "SpaceImageOverlay", NULL);
RNA_def_struct_sdna(srna, "SpaceImage");
RNA_def_struct_nested(brna, srna, "SpaceImageEditor");
RNA_def_struct_path_func(srna, "rna_SpaceImageOverlay_path");
RNA_def_struct_ui_text(
srna, "Overlay Settings", "Settings for display of overlays in the UV/Image editor");
prop = RNA_def_property(srna, "show_overlays", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", SI_OVERLAY_SHOW_OVERLAYS);
RNA_def_property_ui_text(prop, "Show Overlays", "Display overlays like UV Maps and Metadata");
}
static void rna_def_space_image(BlenderRNA *brna)
{
StructRNA *srna;
@ -4675,7 +4702,16 @@ static void rna_def_space_image(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Show Mask Editor", "Show Mask editing related properties");
/* Overlays */
prop = RNA_def_property(srna, "overlay", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_struct_type(prop, "SpaceImageOverlay");
RNA_def_property_pointer_funcs(prop, "rna_SpaceImage_overlay_get", NULL, NULL, NULL);
RNA_def_property_ui_text(
prop, "Overlay Settings", "Settings for display of overlays in the UV/Image editor");
rna_def_space_image_uv(brna);
rna_def_space_image_overlay(brna);
/* mask */
rna_def_space_mask_info(srna, NC_SPACE | ND_SPACE_IMAGE, "rna_SpaceImageEditor_mask_set");