main sync #3

Merged
Patrick Busch merged 318 commits from blender/blender:main into main 2023-03-17 15:52:21 +01:00
2 changed files with 35 additions and 18 deletions
Showing only changes of commit 4f56b02a0c - Show all commits

View File

@ -2716,14 +2716,28 @@ static void count_multi_input_socket_links(bNodeTree &ntree, SpaceNode &snode)
} }
} }
static float frame_node_label_height(const NodeFrame &frame_data)
{
return frame_data.label_size * U.dpi_fac;
}
#define NODE_FRAME_MARGIN (1.5f * U.widget_unit)
/* XXX Does a bounding box update by iterating over all children. /* XXX Does a bounding box update by iterating over all children.
* Not ideal to do this in every draw call, but doing as transform callback doesn't work, * Not ideal to do this in every draw call, but doing as transform callback doesn't work,
* since the child node totr rects are not updated properly at that point. */ * since the child node totr rects are not updated properly at that point. */
static void frame_node_prepare_for_draw(bNode &node, Span<bNode *> nodes) static void frame_node_prepare_for_draw(bNode &node, Span<bNode *> nodes)
{ {
const float margin = 1.5f * U.widget_unit;
NodeFrame *data = (NodeFrame *)node.storage; NodeFrame *data = (NodeFrame *)node.storage;
const float margin = NODE_FRAME_MARGIN;
const float has_label = node.label[0] != '\0';
const float label_height = frame_node_label_height(*data);
/* Add an additional 25 % to account for the descenders. This works well in most cases. */
const float margin_top = 0.5f * margin + (has_label ? 1.25f * label_height : 0.5f * margin);
/* Initialize rect from current frame size. */ /* Initialize rect from current frame size. */
rctf rect; rctf rect;
node_to_updated_rect(node, rect); node_to_updated_rect(node, rect);
@ -2743,7 +2757,7 @@ static void frame_node_prepare_for_draw(bNode &node, Span<bNode *> nodes)
noderect.xmin -= margin; noderect.xmin -= margin;
noderect.xmax += margin; noderect.xmax += margin;
noderect.ymin -= margin; noderect.ymin -= margin;
noderect.ymax += margin; noderect.ymax += margin_top;
/* First child initializes frame. */ /* First child initializes frame. */
if (bbinit) { if (bbinit) {
@ -2841,8 +2855,7 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx,
BLF_enable(fontid, BLF_ASPECT); BLF_enable(fontid, BLF_ASPECT);
BLF_aspect(fontid, aspect, aspect, 1.0f); BLF_aspect(fontid, aspect, aspect, 1.0f);
/* Clamp. Otherwise it can suck up a LOT of memory. */ BLF_size(fontid, font_size * U.dpi_fac);
BLF_size(fontid, MIN2(24.0f, font_size) * U.dpi_fac);
/* Title color. */ /* Title color. */
int color_id = node_get_colorid(tree_draw_ctx, node); int color_id = node_get_colorid(tree_draw_ctx, node);
@ -2850,21 +2863,18 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx,
UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color); UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color);
BLF_color3ubv(fontid, color); BLF_color3ubv(fontid, color);
const float margin = float(NODE_DY / 4); const float margin = NODE_FRAME_MARGIN;
const float width = BLF_width(fontid, label, sizeof(label)); const float width = BLF_width(fontid, label, sizeof(label));
const float ascender = BLF_ascender(fontid); const int label_height = frame_node_label_height(*data);
const int label_height = ((margin / aspect) + (ascender * aspect));
/* 'x' doesn't need aspect correction */
const rctf &rct = node.runtime->totr; const rctf &rct = node.runtime->totr;
/* XXX a bit hacky, should use separate align values for x and y. */ const float label_x = BLI_rctf_cent_x(&rct) - (0.5f * width);
float x = BLI_rctf_cent_x(&rct) - (0.5f * width); const float label_y = rct.ymax - label_height - (0.5f * margin);
float y = rct.ymax - label_height;
/* label */ /* Label. */
const bool has_label = node.label[0] != '\0'; const bool has_label = node.label[0] != '\0';
if (has_label) { if (has_label) {
BLF_position(fontid, x, y, 0); BLF_position(fontid, label_x, label_y, 0);
BLF_draw(fontid, label, sizeof(label)); BLF_draw(fontid, label, sizeof(label));
} }
@ -2875,11 +2885,10 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx,
const float line_spacing = (line_height_max * aspect); const float line_spacing = (line_height_max * aspect);
const float line_width = (BLI_rctf_size_x(&rct) - 2 * margin) / aspect; const float line_width = (BLI_rctf_size_x(&rct) - 2 * margin) / aspect;
/* 'x' doesn't need aspect correction. */ const float x = rct.xmin + margin;
x = rct.xmin + margin; float y = rct.ymax - label_height - (has_label ? line_spacing + margin : 0);
y = rct.ymax - label_height - (has_label ? line_spacing : 0);
int y_min = y + ((margin * 2) - (y - rct.ymin)); const int y_min = rct.ymin + margin;
BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP); BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
BLF_clipping(fontid, rct.xmin, rct.ymin + margin, rct.xmax, rct.ymax); BLF_clipping(fontid, rct.xmin, rct.ymin + margin, rct.xmax, rct.ymax);

View File

@ -11,6 +11,8 @@
#include "BLI_math.h" #include "BLI_math.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BLF_api.h"
#include "BLT_translation.h" #include "BLT_translation.h"
#include "DNA_curves_types.h" #include "DNA_curves_types.h"
@ -4164,6 +4166,12 @@ static bNodeSocket *rna_NodeOutputFile_slots_new(
return sock; return sock;
} }
static void rna_FrameNode_label_size_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
BLF_cache_clear();
rna_Node_update(bmain, scene, ptr);
}
static void rna_ShaderNodeTexIES_mode_set(PointerRNA *ptr, int value) static void rna_ShaderNodeTexIES_mode_set(PointerRNA *ptr, int value)
{ {
bNode *node = (bNode *)ptr->data; bNode *node = (bNode *)ptr->data;
@ -4816,7 +4824,7 @@ static void def_frame(StructRNA *srna)
RNA_def_property_int_sdna(prop, NULL, "label_size"); RNA_def_property_int_sdna(prop, NULL, "label_size");
RNA_def_property_range(prop, 8, 64); RNA_def_property_range(prop, 8, 64);
RNA_def_property_ui_text(prop, "Label Font Size", "Font size to use for displaying the label"); RNA_def_property_ui_text(prop, "Label Font Size", "Font size to use for displaying the label");
RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, NULL); RNA_def_property_update(prop, NC_NODE | ND_DISPLAY, "rna_FrameNode_label_size_update");
} }
static void def_clamp(StructRNA *srna) static void def_clamp(StructRNA *srna)