Nodes: Limit the size of the previews #111040

Open
Colin Marmond wants to merge 2 commits from Kdaf/blender:GSOC-limit-preview-size into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
7 changed files with 30 additions and 10 deletions

View File

@ -80,6 +80,7 @@ const UserDef U_default = {
.scrollback = 256,
.node_margin = 80,
.node_preview_res = 120,
.node_max_preview_size = 150,
.transopts = USER_TR_TOOLTIPS,
.menuthreshold1 = 5,
.menuthreshold2 = 2,

View File

@ -502,6 +502,7 @@ class USERPREF_PT_edit_misc(EditingPanel, CenterAlignMixIn, Panel):
col.prop(edit, "sculpt_paint_overlay_color", text="Sculpt Overlay Color")
col.prop(edit, "node_margin", text="Node Auto-Offset Margin")
col.prop(edit, "node_preview_resolution", text="Node Preview Resolution")
col.prop(edit, "node_max_preview_size", text="Node Maximum Preview Size")
# -----------------------------------------------------------------------------

View File

@ -29,7 +29,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 15
#define BLENDER_FILE_SUBVERSION 16
/* 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

View File

@ -852,6 +852,10 @@ void blo_do_versions_userdef(UserDef *userdef)
userdef->node_preview_res = 120;
}
if (!USER_VERSION_ATLEAST(400, 16)) {
userdef->node_max_preview_size = 150;
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -2141,28 +2141,30 @@ static void node_draw_extra_info_panel(const Scene *scene,
extra_info_rect.ymin = rct.ymax;
extra_info_rect.ymax = rct.ymax + extra_info_rows.size() * (20.0f * UI_SCALE_FAC);
if (preview) {
const float node_max_width = fmin(width, U.node_max_preview_size * UI_SCALE_FAC);
const float preview_padding = 3.0f * UI_SCALE_FAC;
if (preview->x > preview->y) {
const float preview_padding = 3.0f * UI_SCALE_FAC;
preview_height = (width - 2.0 * preview_padding) * float(preview->y) / float(preview->x) +
preview_height = (node_max_width - 2.0 * preview_padding) * float(preview->y) /
float(preview->x) +
2.0 * preview_padding;
preview_rect.ymin = extra_info_rect.ymin + preview_padding;
preview_rect.ymax = extra_info_rect.ymin + preview_height - preview_padding;
preview_rect.xmin = extra_info_rect.xmin + preview_padding;
preview_rect.xmax = extra_info_rect.xmax - preview_padding;
extra_info_rect.ymax += preview_height;
}
else {
const float preview_padding = 3.0f * UI_SCALE_FAC;
preview_height = width;
const float preview_width = (width - 2.0 * preview_padding) * float(preview->x) /
preview_height = node_max_width;
const float preview_width = (node_max_width - 2.0 * preview_padding) * float(preview->x) /
float(preview->y) +
2.0 * preview_padding;
preview_rect.ymin = extra_info_rect.ymin + preview_padding;
preview_rect.ymax = extra_info_rect.ymin + preview_height - preview_padding;
preview_rect.xmin = extra_info_rect.xmin + preview_padding + (width - preview_width) / 2;
preview_rect.xmax = extra_info_rect.xmax - preview_padding - (width - preview_width) / 2;
extra_info_rect.ymax += preview_height;
preview_rect.xmin = extra_info_rect.xmin + preview_padding +
(node_max_width - preview_width) / 2;
preview_rect.xmax = extra_info_rect.xmax - preview_padding -
(node_max_width - preview_width) / 2;
}
extra_info_rect.ymax += preview_height;
}
if (node.flag & NODE_MUTED) {

View File

@ -823,6 +823,9 @@ typedef struct UserDef {
/** Node insert offset (aka auto-offset) margin, but might be useful for later stuff as well. */
char node_margin;
char node_preview_res;
/** Maximum size of the preview above the node. */
char node_max_preview_size;
char _pad2[7];
/** #eUserpref_Translation_Flags. */
short transopts;
short menuthreshold1, menuthreshold2;

View File

@ -5567,6 +5567,15 @@ static void rna_def_userdef_edit(BlenderRNA *brna)
"performance convenience)");
RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "node_max_preview_size", PROP_INT, PROP_PIXEL);
RNA_def_property_int_sdna(prop, nullptr, "node_max_preview_size");
RNA_def_property_range(prop, 50, 250);
RNA_def_property_ui_text(
prop,
"Node Max Preview Size",
"The maximum size a node preview can take(independently from the max width of the node)");
RNA_def_property_update(prop, 0, "rna_userdef_update");
/* cursor */
prop = RNA_def_property(srna, "use_cursor_lock_adjust", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, nullptr, "uiflag", USER_LOCK_CURSOR_ADJUST);