UI: Improved Operator Confirmations #104670
|
@ -265,6 +265,13 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
|
||||||
bbox.ymax -= field->image_size[1];
|
bbox.ymax -= field->image_size[1];
|
||||||
|
|
||||||
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
|
GPU_blend(GPU_BLEND_ALPHA_PREMULT);
|
||||||
|
|
||||||
|
/* Draw checker pattern behind the image in case is has transparency. */
|
||||||
|
imm_draw_box_checker_2d(float(bbox.xmin),
|
||||||
|
float(bbox.ymax),
|
||||||
|
float(bbox.xmin + field->image_size[0]),
|
||||||
|
float(bbox.ymax + field->image_size[1]));
|
||||||
|
|
||||||
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR);
|
IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_3D_IMAGE_COLOR);
|
||||||
immDrawPixelsTexScaledFullSize(&state,
|
immDrawPixelsTexScaledFullSize(&state,
|
||||||
bbox.xmin,
|
bbox.xmin,
|
||||||
|
@ -279,8 +286,27 @@ static void ui_tooltip_region_draw_cb(const bContext * /*C*/, ARegion *region)
|
||||||
float(field->image_size[0]) / float(field->image->x),
|
float(field->image_size[0]) / float(field->image->x),
|
||||||
float(field->image_size[1]) / float(field->image->y),
|
float(field->image_size[1]) / float(field->image->y),
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
GPU_blend(GPU_BLEND_ALPHA);
|
GPU_blend(GPU_BLEND_ALPHA);
|
||||||
|
|
||||||
|
/* Draw border around it. */
|
||||||
|
GPUVertFormat *format = immVertexFormat();
|
||||||
|
uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
|
||||||
|
immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
|
||||||
|
float border_color[4] = {1.0f, 1.0f, 1.0f, 0.15f};
|
||||||
|
float bgcolor[4];
|
||||||
|
UI_GetThemeColor4fv(TH_BACK, bgcolor);
|
||||||
|
if (rgb_to_grayscale(bgcolor) > 0.5f) {
|
||||||
|
border_color[0] = 0.0f;
|
||||||
|
border_color[1] = 0.0f;
|
||||||
|
border_color[2] = 0.0f;
|
||||||
|
}
|
||||||
|
immUniformColor4fv(border_color);
|
||||||
|
imm_draw_box_wire_2d(pos,
|
||||||
|
float(bbox.xmin),
|
||||||
|
float(bbox.ymax),
|
||||||
|
float(bbox.xmin + field->image_size[0]),
|
||||||
|
float(bbox.ymax + field->image_size[1]));
|
||||||
|
immUnbindProgram();
|
||||||
}
|
}
|
||||||
else if (field->format.style == UI_TIP_STYLE_SPACER) {
|
else if (field->format.style == UI_TIP_STYLE_SPACER) {
|
||||||
bbox.ymax -= data->lineh * UI_TIP_SPACER;
|
bbox.ymax -= data->lineh * UI_TIP_SPACER;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "DNA_texture_types.h"
|
#include "DNA_texture_types.h"
|
||||||
|
|
||||||
#include "BLI_alloca.h"
|
#include "BLI_alloca.h"
|
||||||
|
#include "BLI_fileops.h"
|
||||||
#include "BLI_fnmatch.h"
|
#include "BLI_fnmatch.h"
|
||||||
#include "BLI_listbase.h"
|
#include "BLI_listbase.h"
|
||||||
#include "BLI_math_color.h"
|
#include "BLI_math_color.h"
|
||||||
|
@ -68,6 +69,8 @@
|
||||||
#include "BKE_screen.hh"
|
#include "BKE_screen.hh"
|
||||||
#include "BKE_shader_fx.h"
|
#include "BKE_shader_fx.h"
|
||||||
|
|
||||||
|
#include "BLO_readfile.h"
|
||||||
|
|
||||||
#include "DEG_depsgraph.hh"
|
#include "DEG_depsgraph.hh"
|
||||||
#include "DEG_depsgraph_build.hh"
|
#include "DEG_depsgraph_build.hh"
|
||||||
#include "DEG_depsgraph_query.hh"
|
#include "DEG_depsgraph_query.hh"
|
||||||
|
@ -79,6 +82,11 @@
|
||||||
#include "ED_screen.hh"
|
#include "ED_screen.hh"
|
||||||
#include "ED_undo.hh"
|
#include "ED_undo.hh"
|
||||||
|
|
||||||
|
#include "IMB_imbuf.h"
|
||||||
|
#include "IMB_imbuf_types.h"
|
||||||
|
#include "IMB_metadata.h"
|
||||||
|
#include "IMB_thumbs.h"
|
||||||
|
|
||||||
#include "RE_engine.h"
|
#include "RE_engine.h"
|
||||||
|
|
||||||
#include "RNA_access.hh"
|
#include "RNA_access.hh"
|
||||||
|
@ -7185,10 +7193,99 @@ void uiTemplateCacheFile(uiLayout *layout,
|
||||||
/* -------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------- */
|
||||||
/** \name Recent Files Template
|
/** \name Recent Files Template
|
||||||
* \{ */
|
* \{ */
|
||||||
|
static void uiTemplateRecentFiles_tooltip_func(bContext * /*C*/,
|
||||||
|
struct uiTooltipData *tip,
|
||||||
|
void *argN)
|
||||||
|
{
|
||||||
|
char *path = (char *)argN;
|
||||||
|
|
||||||
|
/* File path. */
|
||||||
|
char root[FILE_MAX];
|
||||||
|
BLI_path_split_dir_part(path, root, FILE_MAX);
|
||||||
|
UI_tooltip_text_field_add(tip, BLI_strdup(root), nullptr, UI_TIP_STYLE_HEADER, UI_TIP_LC_NORMAL);
|
||||||
|
UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
|
||||||
|
|
||||||
|
/* Blender version. */
|
||||||
|
char version_st[128] = {0};
|
||||||
|
/* Load the thumbnail from cache if existing, but don't create if not. */
|
||||||
|
ImBuf *thumb = IMB_thumb_read(path, THB_LARGE);
|
||||||
|
if (thumb) {
|
||||||
|
/* Look for version in existing thumbnail if available. */
|
||||||
|
IMB_metadata_get_field(
|
||||||
|
thumb->metadata, "Thumb::Blender::Version", version_st, sizeof(version_st));
|
||||||
|
}
|
||||||
|
|
||||||
|
eFileAttributes attributes = BLI_file_attributes(path);
|
||||||
|
if (!version_st[0] && !(attributes & FILE_ATTR_OFFLINE)) {
|
||||||
|
/* Load Blender version directly from the file. */
|
||||||
|
short version = BLO_version_from_file(path);
|
||||||
|
if (version != 0) {
|
||||||
|
SNPRINTF(version_st, "%d.%01d", version / 100, version % 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version_st[0]) {
|
||||||
|
UI_tooltip_text_field_add(tip,
|
||||||
|
BLI_sprintfN("Blender %s", version_st),
|
||||||
|
nullptr,
|
||||||
|
UI_TIP_STYLE_NORMAL,
|
||||||
|
UI_TIP_LC_NORMAL);
|
||||||
|
UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
BLI_stat_t status;
|
||||||
|
if (BLI_stat(path, &status) != -1) {
|
||||||
|
char date_st[FILELIST_DIRENTRY_DATE_LEN], time_st[FILELIST_DIRENTRY_TIME_LEN];
|
||||||
|
bool is_today, is_yesterday;
|
||||||
|
std::string day_string = ("");
|
||||||
|
BLI_filelist_entry_datetime_to_string(
|
||||||
|
nullptr, int64_t(status.st_mtime), false, time_st, date_st, &is_today, &is_yesterday);
|
||||||
|
if (is_today || is_yesterday) {
|
||||||
|
day_string = (is_today ? N_("Today") : N_("Yesterday")) + std::string(" ");
|
||||||
|
}
|
||||||
|
UI_tooltip_text_field_add(tip,
|
||||||
|
BLI_sprintfN("%s: %s%s%s",
|
||||||
|
N_("Modified"),
|
||||||
|
day_string.c_str(),
|
||||||
|
(is_today || is_yesterday) ? "" : date_st,
|
||||||
|
(is_today || is_yesterday) ? time_st : ""),
|
||||||
|
nullptr,
|
||||||
|
UI_TIP_STYLE_NORMAL,
|
||||||
|
UI_TIP_LC_NORMAL);
|
||||||
|
|
||||||
|
if (status.st_size > 0) {
|
||||||
|
char size[16];
|
||||||
|
BLI_filelist_entry_size_to_string(NULL, status.st_size, false, size);
|
||||||
|
UI_tooltip_text_field_add(tip,
|
||||||
|
BLI_sprintfN("%s: %s", N_("Size"), size),
|
||||||
|
nullptr,
|
||||||
|
UI_TIP_STYLE_NORMAL,
|
||||||
|
UI_TIP_LC_NORMAL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!thumb) {
|
||||||
|
/* try to load from the blend file itself. */
|
||||||
|
BlendThumbnail *data = BLO_thumbnail_from_file(path);
|
||||||
|
thumb = BKE_main_thumbnail_to_imbuf(nullptr, data);
|
||||||
|
if (data) {
|
||||||
|
MEM_freeN(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thumb) {
|
||||||
|
float scale = (72.0f * UI_SCALE_FAC) / float(MAX2(thumb->x, thumb->y));
|
||||||
|
short size[2] = {short(float(thumb->x) * scale), short(float(thumb->y) * scale)};
|
||||||
|
UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
|
||||||
|
UI_tooltip_text_field_add(tip, nullptr, nullptr, UI_TIP_STYLE_SPACER, UI_TIP_LC_NORMAL);
|
||||||
|
UI_tooltip_image_field_add(tip, thumb, size);
|
||||||
|
IMB_freeImBuf(thumb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int uiTemplateRecentFiles(uiLayout *layout, int rows)
|
int uiTemplateRecentFiles(uiLayout *layout, int rows)
|
||||||
{
|
{
|
||||||
int i;
|
int i = 0;
|
||||||
LISTBASE_FOREACH_INDEX (RecentFile *, recent, &G.recent_files, i) {
|
LISTBASE_FOREACH_INDEX (RecentFile *, recent, &G.recent_files, i) {
|
||||||
if (i >= rows) {
|
if (i >= rows) {
|
||||||
break;
|
break;
|
||||||
|
@ -7206,6 +7303,16 @@ int uiTemplateRecentFiles(uiLayout *layout, int rows)
|
||||||
&ptr);
|
&ptr);
|
||||||
RNA_string_set(&ptr, "filepath", recent->filepath);
|
RNA_string_set(&ptr, "filepath", recent->filepath);
|
||||||
RNA_boolean_set(&ptr, "display_file_selector", false);
|
RNA_boolean_set(&ptr, "display_file_selector", false);
|
||||||
|
|
||||||
|
uiBlock *block = uiLayoutGetBlock(layout);
|
||||||
|
uiBut *but = ui_but_last(block);
|
||||||
|
UI_but_func_tooltip_custom_set(
|
||||||
|
but, uiTemplateRecentFiles_tooltip_func, BLI_strdup(recent->filepath), MEM_freeN);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
uiItemS(layout);
|
||||||
|
uiItemO(layout, nullptr, ICON_TRASH, "WM_OT_clear_recent_files");
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
|
|
@ -190,26 +190,7 @@ static void recent_files_menu_draw(const bContext * /*C*/, Menu *menu)
|
||||||
{
|
{
|
||||||
uiLayout *layout = menu->layout;
|
uiLayout *layout = menu->layout;
|
||||||
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
|
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
|
||||||
if (!BLI_listbase_is_empty(&G.recent_files)) {
|
if (uiTemplateRecentFiles(layout, U.recent_files) == 0) {
|
||||||
LISTBASE_FOREACH (RecentFile *, recent, &G.recent_files) {
|
|
||||||
const char *file = BLI_path_basename(recent->filepath);
|
|
||||||
const int icon = BKE_blendfile_extension_check(file) ? ICON_FILE_BLEND : ICON_FILE_BACKUP;
|
|
||||||
PointerRNA ptr;
|
|
||||||
uiItemFullO(layout,
|
|
||||||
"WM_OT_open_mainfile",
|
|
||||||
file,
|
|
||||||
icon,
|
|
||||||
nullptr,
|
|
||||||
WM_OP_INVOKE_DEFAULT,
|
|
||||||
UI_ITEM_NONE,
|
|
||||||
&ptr);
|
|
||||||
RNA_string_set(&ptr, "filepath", recent->filepath);
|
|
||||||
RNA_boolean_set(&ptr, "display_file_selector", false);
|
|
||||||
}
|
|
||||||
uiItemS(layout);
|
|
||||||
uiItemO(layout, nullptr, ICON_TRASH, "WM_OT_clear_recent_files");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
uiItemL(layout, IFACE_("No Recent Files"), ICON_NONE);
|
uiItemL(layout, IFACE_("No Recent Files"), ICON_NONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue