Blender V5.3
interface_template_project_splash.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <fmt/format.h>
10
11#include "BLI_fileops.hh"
12
14#include "BKE_context.hh"
15
16#include "BLT_translation.hh"
17
18#include "IMB_imbuf.hh"
19
20#include "RNA_access.hh"
21#include "RNA_prototypes.hh"
22
23#include "UI_interface_c.hh"
25#include "UI_resources.hh"
26
27#include "WM_api.hh"
28
29namespace blender::ui {
30
32{
33 Main *bmain = CTX_data_main(C);
35 bmain, [](bke::BlenderProject *project) {
36 return RNA_pointer_create_discrete(nullptr, RNA_BlenderProject, project);
37 });
38 if (project_ptr.data == nullptr) {
39 return;
40 }
41
42 const bool has_path = BKE_blender_project_read_callback(
43 bmain, [](const bke::BlenderProject *project) {
44 return project && !project->get_splash_image_path().is_empty();
45 });
46 if (!has_path) {
47 layout->op("PROJECT_OT_splash_image_create", IFACE_("Create from Image..."), ICON_FILEBROWSER);
48 return;
49 }
50
51 /* Read-only path, as a custom property to hide the automatic open button
52 * and replace it with our own operator. */
53 Layout &row = layout->row(true);
54 Layout &path_row = row.row(true);
55 path_row.enabled_set(false);
56 Block *block = layout->block();
57 block_layout_set_current(block, &path_row);
58 uiDefButR(block,
60 "",
61 0,
62 0,
63 UI_UNIT_X * 10,
65 &project_ptr,
66 "splash_image_path",
67 0,
68 0,
69 0,
70 std::nullopt);
71 row.op("PROJECT_OT_splash_image_create", "", ICON_FILEBROWSER);
72 row.op("PROJECT_OT_splash_image_clear", "", ICON_X);
73
74 layout->separator();
75
76 const std::string filepath = WM_project_splash_image_filepath(bmain);
77
78 BLI_stat_t stat;
79 if (!filepath.empty() && BLI_stat(filepath.c_str(), &stat) == 0) {
80 /* Reload the image when the file changes. */
81 const std::string key = fmt::format(
82 "{}:{}:{}", filepath, int64_t(stat.st_mtime), int64_t(stat.st_size));
83 const bool loaded = layout->image(key, [&]() -> ImBuf * {
84 ImBuf *ibuf = WM_project_splash_image_load(filepath, 1000, true);
85 if (ibuf) {
87 }
88 return ibuf;
89 });
90 if (loaded) {
91 return;
92 }
93 }
94
95 layout->label(IFACE_("Failed to load splash image"), ICON_ERROR);
96}
97
98} // namespace blender::ui
File and directory operations.
#define IFACE_(msgid)
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
Button * uiDefButR(Block *block, ButtonType type, std::optional< StringRef > str, int x, int y, short width, short height, PointerRNA *ptr, StringRefNull propname, int index, float min, float max, std::optional< StringRef > tip)
void template_project_splash(Layout *layout, bContext *C)
void block_layout_set_current(Block *block, Layout *layout)
__int64 int64_t
Definition BKE_text.h:90
std::string WM_project_splash_image_filepath(const Main *bmain)
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
ImBuf * WM_project_splash_image_load(const StringRefNull filepath, const int width, const bool add_logo)
Main * CTX_data_main(const bContext *C)
struct stat BLI_stat_t
auto BKE_blender_project_write_callback(const Main *bmain, Fn lambda)
void IMB_premultiply_alpha(ImBuf *ibuf)
Definition filter.cc:382
void enabled_set(bool enabled)
void label(StringRef name, int icon)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
Layout & row(bool align)
bool image(StringRef key, FunctionRef< ImBuf *()> create_fn)