UI: Add shadow to panels
At the moment, only menus and tooltips have a shadow. However, other elements can benefit from having a shadow. This PR adds shadows to panels in overlapped regions. Makes the default shadow size slightly larger, but less opaque so it's not so prominent. While dragging a panel this makes the shadow larger for a "floating" effect. Pull Request: https://projects.blender.org/blender/blender/pulls/139847
This commit is contained in:
committed by
Harley Acheson
parent
2a86a93349
commit
0a22fbc153
@@ -239,8 +239,8 @@ const bTheme U_theme_default = {
|
||||
.blend = 0.5f,
|
||||
},
|
||||
.widget_emboss = RGBA(0x00000026),
|
||||
.menu_shadow_fac = 0.4f,
|
||||
.menu_shadow_width = 2,
|
||||
.menu_shadow_fac = 0.2f,
|
||||
.menu_shadow_width = 6,
|
||||
.editor_border = RGBA(0x161616ff),
|
||||
.editor_outline = RGBA(0xffffff15),
|
||||
.editor_outline_active = RGBA(0xffffff2a),
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
/* Blender file format version. */
|
||||
#define BLENDER_FILE_VERSION BLENDER_VERSION
|
||||
#define BLENDER_FILE_SUBVERSION 18
|
||||
#define BLENDER_FILE_SUBVERSION 19
|
||||
|
||||
/* Minimum Blender version that supports reading file written with the current
|
||||
* version. Older Blender versions will test this and cancel loading the file, showing a warning to
|
||||
|
||||
@@ -326,6 +326,11 @@ static void do_versions_theme(const UserDef *userdef, bTheme *btheme)
|
||||
FROM_DEFAULT_V4_UCHAR(space_preferences.button);
|
||||
}
|
||||
|
||||
if (!USER_VERSION_ATLEAST(500, 19)) {
|
||||
btheme->tui.menu_shadow_fac = U_theme_default.tui.menu_shadow_fac;
|
||||
btheme->tui.menu_shadow_width = U_theme_default.tui.menu_shadow_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always bump subversion in BKE_blender_version.h when adding versioning
|
||||
* code here, and wrap it inside a USER_VERSION_ATLEAST check.
|
||||
|
||||
@@ -1233,6 +1233,21 @@ void ui_draw_layout_panels_backdrop(const ARegion *region,
|
||||
}
|
||||
}
|
||||
|
||||
static void panel_draw_softshadow(const rctf *box_rect,
|
||||
const int roundboxalign,
|
||||
const float radius,
|
||||
const float shadow_width)
|
||||
{
|
||||
const float outline = U.pixelsize;
|
||||
|
||||
rctf shadow_rect = *box_rect;
|
||||
BLI_rctf_pad(&shadow_rect, -outline, -outline);
|
||||
UI_draw_roundbox_corner_set(roundboxalign);
|
||||
|
||||
const float shadow_alpha = UI_GetTheme()->tui.menu_shadow_fac;
|
||||
ui_draw_dropshadow(&shadow_rect, radius, shadow_width, 1.0f, shadow_alpha);
|
||||
}
|
||||
|
||||
static void panel_draw_aligned_backdrop(const ARegion *region,
|
||||
const Panel *panel,
|
||||
const rcti *rect,
|
||||
@@ -1241,6 +1256,7 @@ static void panel_draw_aligned_backdrop(const ARegion *region,
|
||||
const bool is_open = !UI_panel_is_closed(panel);
|
||||
const bool is_subpanel = panel->type->parent != nullptr;
|
||||
const bool has_header = (panel->type->flag & PANEL_TYPE_NO_HEADER) == 0;
|
||||
const bool is_dragging = UI_panel_is_dragging(panel);
|
||||
|
||||
if (is_subpanel && !is_open) {
|
||||
return;
|
||||
@@ -1253,6 +1269,22 @@ static void panel_draw_aligned_backdrop(const ARegion *region,
|
||||
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
|
||||
/* Draw shadow on top-level panels with headers during drag or region overlap. */
|
||||
if (!is_subpanel && has_header && (region->overlap || is_dragging)) {
|
||||
/* Make shadow wider (at least 16px) while the panel is being dragged. */
|
||||
const float shadow_width = is_dragging ?
|
||||
max_ii(int(16.0f * UI_SCALE_FAC), UI_ThemeMenuShadowWidth()) :
|
||||
UI_ThemeMenuShadowWidth();
|
||||
const int roundboxalign = is_open ? UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT : UI_CNR_ALL;
|
||||
|
||||
rctf box_rect;
|
||||
box_rect.xmin = rect->xmin;
|
||||
box_rect.xmax = rect->xmax;
|
||||
box_rect.ymin = is_open ? rect->ymin : header_rect->ymin;
|
||||
box_rect.ymax = header_rect->ymax;
|
||||
panel_draw_softshadow(&box_rect, roundboxalign, radius, shadow_width);
|
||||
}
|
||||
|
||||
/* Panel backdrop. */
|
||||
if (is_open || !has_header) {
|
||||
float panel_backcolor[4];
|
||||
|
||||
@@ -1912,13 +1912,14 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
|
||||
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
|
||||
|
||||
prop = RNA_def_property(srna, "menu_shadow_fac", PROP_FLOAT, PROP_FACTOR);
|
||||
RNA_def_property_ui_text(prop, "Menu Shadow Strength", "Blending factor for menu shadows");
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Panel/Menu Shadow Strength", "Blending factor for panel and menu shadows");
|
||||
RNA_def_property_range(prop, 0.01f, 1.0f);
|
||||
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
|
||||
|
||||
prop = RNA_def_property(srna, "menu_shadow_width", PROP_INT, PROP_PIXEL);
|
||||
RNA_def_property_ui_text(
|
||||
prop, "Menu Shadow Width", "Width of menu shadows, set to zero to disable");
|
||||
prop, "Panel/Menu Shadow Width", "Width of panel and menu shadows, set to zero to disable");
|
||||
RNA_def_property_range(prop, 0.0f, 24.0f);
|
||||
RNA_def_property_update(prop, 0, "rna_userdef_theme_update");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user