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,
|
void *arg,
|
||||||
uiFreeArgFunc free_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,
|
void UI_tooltip_text_field_add(struct uiTooltipData *data,
|
||||||
char *text,
|
char *text,
|
||||||
char *suffix,
|
char *suffix,
|
||||||
const uiTooltipStyle style,
|
const uiTooltipStyle style,
|
||||||
const uiTooltipColorID color_id,
|
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,
|
void UI_tooltip_image_field_add(struct uiTooltipData *data,
|
||||||
struct ImBuf *image,
|
const struct ImBuf *image,
|
||||||
short width,
|
const short image_size[2]) ATTR_NONNULL(1, 2, 3);
|
||||||
short height);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recreate tool-tip (use to update dynamic tips)
|
* Recreate tool-tip (use to update dynamic tips)
|
||||||
|
@ -80,8 +80,10 @@ struct uiTooltipFormat {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct uiTooltipField {
|
struct uiTooltipField {
|
||||||
char *text;
|
/** Allocated text (owned by this structure), may be null. */
|
||||||
char *text_suffix;
|
const char *text;
|
||||||
|
/** Allocated text (owned by this structure), may be null. */
|
||||||
|
const char *text_suffix;
|
||||||
struct {
|
struct {
|
||||||
/** X cursor position at the end of the last line. */
|
/** X cursor position at the end of the last line. */
|
||||||
uint x_pos;
|
uint x_pos;
|
||||||
@ -90,8 +92,7 @@ struct uiTooltipField {
|
|||||||
} geom;
|
} geom;
|
||||||
uiTooltipFormat format;
|
uiTooltipFormat format;
|
||||||
ImBuf *image;
|
ImBuf *image;
|
||||||
short image_width;
|
short image_size[2];
|
||||||
short image_height;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct uiTooltipData {
|
struct uiTooltipData {
|
||||||
@ -125,21 +126,20 @@ void UI_tooltip_text_field_add(uiTooltipData *data,
|
|||||||
field->format.style = style;
|
field->format.style = style;
|
||||||
field->format.color_id = color_id;
|
field->format.color_id = color_id;
|
||||||
field->format.is_pad = is_pad;
|
field->format.is_pad = is_pad;
|
||||||
field->text = text ? text : nullptr;
|
field->text = text;
|
||||||
field->text_suffix = suffix ? suffix : nullptr;
|
field->text_suffix = suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UI_tooltip_image_field_add(uiTooltipData *data,
|
void UI_tooltip_image_field_add(uiTooltipData *data,
|
||||||
struct ImBuf *image,
|
const struct ImBuf *image,
|
||||||
short width,
|
const short image_size[2])
|
||||||
short height)
|
|
||||||
{
|
{
|
||||||
uiTooltipField *field = text_field_add_only(data);
|
uiTooltipField *field = text_field_add_only(data);
|
||||||
field->format = {};
|
field->format = {};
|
||||||
field->format.style = UI_TIP_STYLE_IMAGE;
|
field->format.style = UI_TIP_STYLE_IMAGE;
|
||||||
field->image = IMB_dupImBuf(image);
|
field->image = IMB_dupImBuf(image);
|
||||||
field->image_width = MIN2(width, UI_TIP_MAXIMAGEWIDTH * UI_SCALE_FAC);
|
field->image_size[0] = MIN2(image_size[0], UI_TIP_MAXIMAGEWIDTH * UI_SCALE_FAC);
|
||||||
field->image_height = MIN2(height, UI_TIP_MAXIMAGEHEIGHT * UI_SCALE_FAC);
|
field->image_size[1] = MIN2(image_size[1], UI_TIP_MAXIMAGEHEIGHT * UI_SCALE_FAC);
|
||||||
field->text = nullptr;
|
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) {
|
else if (field->format.style == UI_TIP_STYLE_IMAGE) {
|
||||||
|
|
||||||
bbox.ymax -= field->image_height;
|
bbox.ymax -= field->image_size[0];
|
||||||
bbox.ymin -= field->image_height;
|
bbox.ymin -= field->image_size[1];
|
||||||
|
|
||||||
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
|
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
|
||||||
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR);
|
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,
|
field->image->byte_buffer.data,
|
||||||
1.0f,
|
1.0f,
|
||||||
1.0f,
|
1.0f,
|
||||||
(float)field->image_width / (float)field->image->x,
|
float(field->image_size[0]) / float(field->image->x),
|
||||||
(float)field->image_height / (float)field->image->y,
|
float(field->image_size[1]) / float(field->image->y),
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
GPU_blend(GPU_BLEND_ALPHA);
|
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++) {
|
for (int i = 0; i < data->fields_len; i++) {
|
||||||
const uiTooltipField *field = &data->fields[i];
|
const uiTooltipField *field = &data->fields[i];
|
||||||
if (field->text) {
|
if (field->text) {
|
||||||
MEM_freeN(field->text);
|
MEM_freeN((void *)field->text);
|
||||||
}
|
}
|
||||||
if (field->text_suffix) {
|
if (field->text_suffix) {
|
||||||
MEM_freeN(field->text_suffix);
|
MEM_freeN((void *)field->text_suffix);
|
||||||
}
|
}
|
||||||
if (field->image) {
|
if (field->image) {
|
||||||
IMB_freeImBuf(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) {
|
if (field->format.style == UI_TIP_STYLE_IMAGE) {
|
||||||
fonth += field->image_height;
|
fonth += field->image_size[1];
|
||||||
w = field->image_width;
|
w = field->image_size[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
fontw = max_ii(fontw, w);
|
fontw = max_ii(fontw, w);
|
||||||
|
Loading…
Reference in New Issue
Block a user