Cleanup: document ownership for uiTooltipField, add function attributes
- Document ownership. - Make some arguments const. - Use function style casts. - Make width/height into a size[2].
This commit is contained in:
parent
c75a304b51
commit
106d2bb312
@ -1774,17 +1774,24 @@ void UI_but_func_tooltip_custom_set(uiBut *but,
|
||||
void *arg,
|
||||
uiFreeArgFunc free_arg);
|
||||
|
||||
/**
|
||||
* \param text: Allocated text (transfer ownership to `data`) or null.
|
||||
* \param suffix: Allocated text (transfer ownership to `data`) or null.
|
||||
*/
|
||||
void UI_tooltip_text_field_add(struct uiTooltipData *data,
|
||||
char *text,
|
||||
char *suffix,
|
||||
const uiTooltipStyle style,
|
||||
const uiTooltipColorID color_id,
|
||||
const bool is_pad = false);
|
||||
const bool is_pad = false) ATTR_NONNULL(1);
|
||||
|
||||
/**
|
||||
* \param image: Image buffer (duplicated, ownership is *not* transferred to `data`).
|
||||
* \param image_size: Display size for the image (pixels )
|
||||
*/
|
||||
void UI_tooltip_image_field_add(struct uiTooltipData *data,
|
||||
struct ImBuf *image,
|
||||
short width,
|
||||
short height);
|
||||
const struct ImBuf *image,
|
||||
const short image_size[2]) ATTR_NONNULL(1, 2, 3);
|
||||
|
||||
/**
|
||||
* Recreate tool-tip (use to update dynamic tips)
|
||||
|
@ -80,8 +80,10 @@ struct uiTooltipFormat {
|
||||
};
|
||||
|
||||
struct uiTooltipField {
|
||||
char *text;
|
||||
char *text_suffix;
|
||||
/** Allocated text (owned by this structure), may be null. */
|
||||
const char *text;
|
||||
/** Allocated text (owned by this structure), may be null. */
|
||||
const char *text_suffix;
|
||||
struct {
|
||||
/** X cursor position at the end of the last line. */
|
||||
uint x_pos;
|
||||
@ -90,8 +92,7 @@ struct uiTooltipField {
|
||||
} geom;
|
||||
uiTooltipFormat format;
|
||||
ImBuf *image;
|
||||
short image_width;
|
||||
short image_height;
|
||||
short image_size[2];
|
||||
};
|
||||
|
||||
struct uiTooltipData {
|
||||
@ -125,21 +126,20 @@ void UI_tooltip_text_field_add(uiTooltipData *data,
|
||||
field->format.style = style;
|
||||
field->format.color_id = color_id;
|
||||
field->format.is_pad = is_pad;
|
||||
field->text = text ? text : nullptr;
|
||||
field->text_suffix = suffix ? suffix : nullptr;
|
||||
field->text = text;
|
||||
field->text_suffix = suffix;
|
||||
}
|
||||
|
||||
void UI_tooltip_image_field_add(uiTooltipData *data,
|
||||
struct ImBuf *image,
|
||||
short width,
|
||||
short height)
|
||||
const struct ImBuf *image,
|
||||
const short image_size[2])
|
||||
{
|
||||
uiTooltipField *field = text_field_add_only(data);
|
||||
field->format = {};
|
||||
field->format.style = UI_TIP_STYLE_IMAGE;
|
||||
field->image = IMB_dupImBuf(image);
|
||||
field->image_width = MIN2(width, UI_TIP_MAXIMAGEWIDTH * UI_SCALE_FAC);
|
||||
field->image_height = MIN2(height, UI_TIP_MAXIMAGEHEIGHT * UI_SCALE_FAC);
|
||||
field->image_size[0] = MIN2(image_size[0], UI_TIP_MAXIMAGEWIDTH * UI_SCALE_FAC);
|
||||
field->image_size[1] = MIN2(image_size[1], UI_TIP_MAXIMAGEHEIGHT * UI_SCALE_FAC);
|
||||
field->text = nullptr;
|
||||
}
|
||||
|
||||
@ -262,8 +262,8 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
|
||||
}
|
||||
else if (field->format.style == UI_TIP_STYLE_IMAGE) {
|
||||
|
||||
bbox.ymax -= field->image_height;
|
||||
bbox.ymin -= field->image_height;
|
||||
bbox.ymax -= field->image_size[0];
|
||||
bbox.ymin -= field->image_size[1];
|
||||
|
||||
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
|
||||
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR);
|
||||
@ -277,8 +277,8 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
|
||||
field->image->byte_buffer.data,
|
||||
1.0f,
|
||||
1.0f,
|
||||
(float)field->image_width / (float)field->image->x,
|
||||
(float)field->image_height / (float)field->image->y,
|
||||
float(field->image_size[0]) / float(field->image->x),
|
||||
float(field->image_size[1]) / float(field->image->y),
|
||||
NULL);
|
||||
|
||||
GPU_blend(GPU_BLEND_ALPHA);
|
||||
@ -313,10 +313,10 @@ static void ui_tooltip_region_free_cb(ARegion *region)
|
||||
for (int i = 0; i < data->fields_len; i++) {
|
||||
const uiTooltipField *field = &data->fields[i];
|
||||
if (field->text) {
|
||||
MEM_freeN(field->text);
|
||||
MEM_freeN((void *)field->text);
|
||||
}
|
||||
if (field->text_suffix) {
|
||||
MEM_freeN(field->text_suffix);
|
||||
MEM_freeN((void *)field->text_suffix);
|
||||
}
|
||||
if (field->image) {
|
||||
IMB_freeImBuf(field->image);
|
||||
@ -1245,8 +1245,8 @@ static ARegion *ui_tooltip_create_with_data(bContext *C,
|
||||
}
|
||||
|
||||
if (field->format.style == UI_TIP_STYLE_IMAGE) {
|
||||
fonth += field->image_height;
|
||||
w = field->image_width;
|
||||
fonth += field->image_size[1];
|
||||
w = field->image_size[0];
|
||||
}
|
||||
|
||||
fontw = max_ii(fontw, w);
|
||||
|
Loading…
Reference in New Issue
Block a user