Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.cc55
-rw-r--r--source/blender/editors/interface/interface_icons.c26
-rw-r--r--source/blender/editors/interface/interface_intern.h3
-rw-r--r--source/blender/editors/interface/interface_widgets.c56
-rw-r--r--source/blender/editors/interface/views/grid_view.cc36
5 files changed, 132 insertions, 44 deletions
diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc
index 2f9e69137ed..b6d212b891e 100644
--- a/source/blender/editors/interface/interface.cc
+++ b/source/blender/editors/interface/interface.cc
@@ -4826,6 +4826,37 @@ uiBut *uiDefBut(uiBlock *block,
return but;
}
+uiBut *uiDefButPadding(uiBlock *block, int x, int y, short width, short height)
+{
+ uiBut *but = ui_def_but(
+ block, UI_BTYPE_LABEL, 0, "", x, y, width, height, nullptr, 0, 0, 0, 0, "");
+ ui_but_update(but);
+ return but;
+}
+
+uiBut *uiDefButPreviewTile(uiBlock *block,
+ int preview_icon_id,
+ const char *label,
+ int x,
+ int y,
+ short width,
+ short height,
+ const uchar mono_color[4])
+{
+ uiBut *but = ui_def_but(
+ block, UI_BTYPE_PREVIEW_TILE, 0, label, x, y, width, height, nullptr, 0, 0, 0, 0, "");
+ ui_def_but_icon(but,
+ preview_icon_id,
+ /* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
+ UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+ if (mono_color) {
+ copy_v4_v4_uchar(but->col, mono_color);
+ }
+
+ ui_but_update(but);
+ return but;
+}
+
uiBut *uiDefButImage(
uiBlock *block, void *imbuf, int x, int y, short width, short height, const uchar color[4])
{
@@ -4993,6 +5024,30 @@ int UI_preview_tile_size_y_no_label(void)
return round_fl_to_int((96.0f / 20.0f) * UI_UNIT_Y + 2.0f * pad);
}
+#define PREVIEW_PAD 4
+
+rcti UI_preview_tile_but_preview_rect_get(const uiBut *but)
+{
+ rcti rect;
+
+ BLI_rcti_rctf_copy_round(&rect, &but->rect);
+
+ if (but->drawstr[0]) {
+ const uiStyle *style = UI_style_get();
+ const uiFontStyle *fstyle = &style->widget;
+ float font_dims[2] = {0.0f, 0.0f};
+
+ UI_fontstyle_set(fstyle);
+ BLF_width_and_height(
+ fstyle->uifont_id, but->drawstr, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
+ /* draw icon in rect above the space reserved for the label */
+ rect.ymin += round_fl_to_int(font_dims[1] + 2 * PREVIEW_PAD);
+ }
+
+ return ui_preview_draw_rect_get(&rect);
+}
+
+#undef PREVIEW_PAD
#undef PREVIEW_TILE_PAD
static void ui_but_update_and_icon_set(uiBut *but, int icon)
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index c19e842aad8..71bd61764c0 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -1503,6 +1503,7 @@ static void icon_draw_rect(float x,
int rh,
uint *rect,
float alpha,
+ const uchar mono_rgba[4],
const float desaturate)
{
int draw_w = w;
@@ -1518,7 +1519,12 @@ static void icon_draw_rect(float x,
return;
}
/* modulate color */
- const float col[4] = {alpha, alpha, alpha, alpha};
+ float col[4] = {alpha, alpha, alpha, alpha};
+ if (mono_rgba) {
+ /* Optionally use a mono color to recolor the image. */
+ rgba_uchar_to_float(col, mono_rgba);
+ mul_v4_fl(col, alpha);
+ }
float scale_x = 1.0f;
float scale_y = 1.0f;
@@ -1813,9 +1819,10 @@ static void icon_draw_size(float x,
if (di->type == ICON_TYPE_IMBUF) {
ImBuf *ibuf = icon->obj;
- GPU_blend(GPU_BLEND_ALPHA_PREMULT);
- icon_draw_rect(x, y, w, h, aspect, ibuf->x, ibuf->y, ibuf->rect, alpha, desaturate);
- GPU_blend(GPU_BLEND_ALPHA);
+ /* TODO preview images are premultiplied apparently (see ICON_TYPE_PREVIEW). */
+ // GPU_blend(GPU_BLEND_ALPHA_PREMULT);
+ icon_draw_rect(x, y, w, h, aspect, ibuf->x, ibuf->y, ibuf->rect, alpha, mono_rgba, desaturate);
+ // GPU_blend(GPU_BLEND_ALPHA);
}
else if (di->type == ICON_TYPE_VECTOR) {
/* vector icons use the uiBlock transformation, they are not drawn
@@ -1854,7 +1861,7 @@ static void icon_draw_size(float x,
}
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
- icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, desaturate);
+ icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, NULL, desaturate);
GPU_blend(GPU_BLEND_ALPHA);
}
else if (di->type == ICON_TYPE_EVENT) {
@@ -1922,7 +1929,7 @@ static void icon_draw_size(float x,
return;
}
- icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, desaturate);
+ icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, NULL, desaturate);
}
else if (di->type == ICON_TYPE_PREVIEW) {
PreviewImage *pi = (icon->id_type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) :
@@ -1938,7 +1945,7 @@ static void icon_draw_size(float x,
/* Preview images use premultiplied alpha. */
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
icon_draw_rect(
- x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, desaturate);
+ x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, NULL, desaturate);
GPU_blend(GPU_BLEND_ALPHA);
}
}
@@ -2433,9 +2440,10 @@ void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
UI_icon_draw_ex(x, y, icon_id, U.inv_dpi_fac, alpha, 0.0f, NULL, false);
}
-void UI_icon_draw_preview(float x, float y, int icon_id, float aspect, float alpha, int size)
+void UI_icon_draw_preview(
+ float x, float y, int icon_id, float aspect, float alpha, int size, const uchar mono_color[4])
{
- icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, false, NULL, false);
+ icon_draw_size(x, y, icon_id, aspect, alpha, ICON_SIZE_PREVIEW, size, 0.0f, mono_color, false);
}
void UI_icon_draw_ex(float x,
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 03b9d03a6e3..ade238a86ef 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -1236,6 +1236,8 @@ void ui_draw_preview_item(const struct uiFontStyle *fstyle,
int iconid,
int but_flag,
eFontStyle_Align text_align);
+rcti ui_preview_draw_rect_get(const rcti *bounds_rect);
+
/**
* Version of #ui_draw_preview_item() that does not draw the menu background and item text based on
* state. It just draws the preview and text directly.
@@ -1245,6 +1247,7 @@ void ui_draw_preview_item_stateless(const struct uiFontStyle *fstyle,
const char *name,
int iconid,
const uchar text_col[4],
+ const uchar mono_col[4],
eFontStyle_Align text_align);
#define UI_TEXT_MARGIN_X 0.4f
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index c939ba461c9..b0400f687aa 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -1316,22 +1316,40 @@ static float widget_alpha_factor(const uiWidgetStateInfo *state)
return 1.0f;
}
-static void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect)
+rcti ui_preview_draw_rect_get(const rcti *bounds_rect)
{
- if (icon == ICON_NONE) {
- return;
+ const int max_width = BLI_rcti_size_x(bounds_rect);
+ const int max_height = BLI_rcti_size_y(bounds_rect);
+
+ rcti rect = {0};
+
+ const int draw_size = MIN2(max_width, max_height) - PREVIEW_PAD * 2;
+ if (draw_size > 0) {
+ rect.xmin = bounds_rect->xmin + max_width / 2 - draw_size / 2;
+ rect.ymin = bounds_rect->ymin + max_height / 2 - draw_size / 2;
+ rect.xmax = rect.xmin + draw_size;
+ rect.ymax = rect.ymin + draw_size;
}
- const int w = BLI_rcti_size_x(rect);
- const int h = BLI_rcti_size_y(rect);
- const int size = MIN2(w, h) - PREVIEW_PAD * 2;
+ return rect;
+}
- if (size > 0) {
- const int x = rect->xmin + w / 2 - size / 2;
- const int y = rect->ymin + h / 2 - size / 2;
+static void widget_draw_preview(BIFIconID icon,
+ float alpha,
+ const rcti *rect,
+ const uchar mono_color[4])
+{
+ if (icon == ICON_NONE) {
+ return;
+ }
- UI_icon_draw_preview(x, y, icon, 1.0f, alpha, size);
+ const rcti draw_rect = ui_preview_draw_rect_get(rect);
+ if (BLI_rcti_is_empty(&draw_rect)) {
+ return;
}
+
+ UI_icon_draw_preview(
+ draw_rect.xmin, draw_rect.ymin, icon, 1.0f, alpha, BLI_rcti_size_x(&draw_rect), mono_color);
}
static int ui_but_draw_menu_icon(const uiBut *but)
@@ -1346,7 +1364,7 @@ static void widget_draw_icon(
{
if (but->flag & UI_BUT_ICON_PREVIEW) {
GPU_blend(GPU_BLEND_ALPHA);
- widget_draw_preview(icon, alpha, rect);
+ widget_draw_preview(icon, alpha, rect, mono_color);
GPU_blend(GPU_BLEND_NONE);
return;
}
@@ -2313,7 +2331,7 @@ static void widget_draw_text_icon(const uiFontStyle *fstyle,
/* draw icon in rect above the space reserved for the label */
rect->ymin += text_size;
GPU_blend(GPU_BLEND_ALPHA);
- widget_draw_preview(icon, alpha, rect);
+ widget_draw_preview(icon, alpha, rect, but->col[3] != 0 ? but->col : NULL);
GPU_blend(GPU_BLEND_NONE);
/* offset rect to draw label in */
@@ -4002,8 +4020,13 @@ static void widget_preview_tile(uiBut *but,
const float UNUSED(zoom))
{
const uiStyle *style = UI_style_get();
- ui_draw_preview_item_stateless(
- &style->widget, rect, but->drawstr, but->icon, wcol->text, UI_STYLE_TEXT_CENTER);
+ ui_draw_preview_item_stateless(&style->widget,
+ rect,
+ but->drawstr,
+ but->icon,
+ wcol->text,
+ but->col[3] ? but->col : NULL,
+ UI_STYLE_TEXT_CENTER);
}
static void widget_menuiconbut(uiWidgetColors *wcol,
@@ -5510,6 +5533,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
const char *name,
int iconid,
const uchar text_col[4],
+ const uchar mono_col[4],
eFontStyle_Align text_align)
{
rcti trect = *rect;
@@ -5526,7 +5550,7 @@ void ui_draw_preview_item_stateless(const uiFontStyle *fstyle,
rect->ymin += round_fl_to_int(font_dims[1] + 2 * padding);
}
GPU_blend(GPU_BLEND_ALPHA);
- widget_draw_preview(iconid, 1.0f, rect);
+ widget_draw_preview(iconid, 1.0f, rect, mono_col);
GPU_blend(GPU_BLEND_NONE);
if (!has_text) {
@@ -5573,7 +5597,7 @@ void ui_draw_preview_item(const uiFontStyle *fstyle,
wt->state(wt, &state, UI_EMBOSS_UNDEFINED);
wt->draw(&wt->wcol, rect, &STATE_INFO_NULL, 0, 1.0f);
- ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, text_align);
+ ui_draw_preview_item_stateless(fstyle, rect, name, iconid, wt->wcol.text, NULL, text_align);
}
/** \} */
diff --git a/source/blender/editors/interface/views/grid_view.cc b/source/blender/editors/interface/views/grid_view.cc
index 52ff1460cbd..edc33fcf944 100644
--- a/source/blender/editors/interface/views/grid_view.cc
+++ b/source/blender/editors/interface/views/grid_view.cc
@@ -8,6 +8,7 @@
#include <stdexcept>
#include "BLI_index_range.hh"
+#include "BLI_math_vector.h"
#include "WM_types.h"
@@ -410,29 +411,26 @@ PreviewGridItem::PreviewGridItem(StringRef identifier, StringRef label, int prev
{
}
-void PreviewGridItem::build_grid_tile(uiLayout &layout) const
+uiBut *PreviewGridItem::add_preview_button(uiLayout &layout,
+ const int preview_icon_id,
+ const uchar mono_color[4]) const
{
const GridViewStyle &style = get_view().get_style();
uiBlock *block = uiLayoutGetBlock(&layout);
- uiBut *but = uiDefBut(block,
- UI_BTYPE_PREVIEW_TILE,
- 0,
- label.c_str(),
- 0,
- 0,
- style.tile_width,
- style.tile_height,
- nullptr,
- 0,
- 0,
- 0,
- 0,
- "");
- ui_def_but_icon(but,
- preview_icon_id,
- /* NOLINTNEXTLINE: bugprone-suspicious-enum-usage */
- UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+ return uiDefButPreviewTile(block,
+ preview_icon_id,
+ label.c_str(),
+ 0,
+ 0,
+ style.tile_width,
+ style.tile_height,
+ mono_color);
+}
+
+void PreviewGridItem::build_grid_tile(uiLayout &layout) const
+{
+ add_preview_button(layout, preview_icon_id);
}
void PreviewGridItem::set_on_activate_fn(ActivateFn fn)