Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/intern/wm_splash_screen.c
| Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (!STREQ(build_branch, "master")) { | ||||
| wm_block_splash_add_label(block, branch_buf, x, &y); | wm_block_splash_add_label(block, branch_buf, x, &y); | ||||
| } | } | ||||
| } | } | ||||
| #else | #else | ||||
| UNUSED_VARS(show_build_info); | UNUSED_VARS(show_build_info); | ||||
| #endif /* WITH_BUILDINFO */ | #endif /* WITH_BUILDINFO */ | ||||
| } | } | ||||
| static ImBuf *wm_block_splash_image(int r_unit_size[2]) | static ImBuf *wm_block_splash_image(void) | ||||
| { | { | ||||
| #ifndef WITH_HEADLESS | #ifndef WITH_HEADLESS | ||||
| extern char datatoc_splash_png[]; | |||||
| extern int datatoc_splash_png_size; | |||||
| extern char datatoc_splash_2x_png[]; | extern char datatoc_splash_2x_png[]; | ||||
| extern int datatoc_splash_2x_png_size; | extern int datatoc_splash_2x_png_size; | ||||
| const bool is_2x = U.dpi_fac > 1.0; | |||||
| const int imb_scale = is_2x ? 2 : 1; | |||||
| /* We could allow this to be variable, | |||||
| * for now don't since allowing it might create layout issues. | |||||
| * | |||||
| * Only check width because splashes sometimes change height | |||||
| * and we don't want to break app-templates. */ | |||||
| const int x_expect = 501 * imb_scale; | |||||
| ImBuf *ibuf = NULL; | ImBuf *ibuf = NULL; | ||||
| if (U.app_template[0] != '\0') { | if (U.app_template[0] != '\0') { | ||||
| char splash_filepath[FILE_MAX]; | char splash_filepath[FILE_MAX]; | ||||
| char template_directory[FILE_MAX]; | char template_directory[FILE_MAX]; | ||||
| if (BKE_appdir_app_template_id_search( | if (BKE_appdir_app_template_id_search( | ||||
| U.app_template, template_directory, sizeof(template_directory))) { | U.app_template, template_directory, sizeof(template_directory))) { | ||||
| BLI_join_dirfile(splash_filepath, | BLI_join_dirfile(splash_filepath, sizeof(splash_filepath), template_directory, "splash.png"); | ||||
| sizeof(splash_filepath), | |||||
| template_directory, | |||||
| is_2x ? "splash_2x.png" : "splash.png"); | |||||
| ibuf = IMB_loadiffname(splash_filepath, IB_rect, NULL); | ibuf = IMB_loadiffname(splash_filepath, IB_rect, NULL); | ||||
| /* We could skip this check, see comment about 'x_expect' above. */ | |||||
| if (ibuf && ibuf->x != x_expect) { | |||||
| CLOG_ERROR(WM_LOG_OPERATORS, | |||||
| "Splash expected %d width found %d, ignoring: %s\n", | |||||
| x_expect, | |||||
| ibuf->x, | |||||
| splash_filepath); | |||||
| IMB_freeImBuf(ibuf); | |||||
| ibuf = NULL; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| if (ibuf == NULL) { | if (ibuf == NULL) { | ||||
| const uchar *splash_data; | const uchar *splash_data = (const uchar *)datatoc_splash_2x_png; | ||||
| size_t splash_data_size; | size_t splash_data_size = datatoc_splash_2x_png_size; | ||||
| if (is_2x) { | |||||
| splash_data = (const uchar *)datatoc_splash_2x_png; | |||||
| splash_data_size = datatoc_splash_2x_png_size; | |||||
| } | |||||
| else { | |||||
| splash_data = (const uchar *)datatoc_splash_png; | |||||
| splash_data_size = datatoc_splash_png_size; | |||||
| } | |||||
| ibuf = IMB_ibImageFromMemory(splash_data, splash_data_size, IB_rect, NULL, "<splash screen>"); | ibuf = IMB_ibImageFromMemory(splash_data, splash_data_size, IB_rect, NULL, "<splash screen>"); | ||||
| BLI_assert(ibuf->x == x_expect); | |||||
| } | |||||
| if (is_2x) { | |||||
| r_unit_size[0] = ibuf->x / 2; | |||||
| r_unit_size[1] = ibuf->y / 2; | |||||
| } | |||||
| else { | |||||
| r_unit_size[0] = ibuf->x; | |||||
| r_unit_size[1] = ibuf->y; | |||||
| } | } | ||||
| return ibuf; | return ibuf; | ||||
| #else | #else | ||||
| UNUSED_VARS(r_unit_size); | UNUSED_VARS(r_unit_size); | ||||
| return NULL; | return NULL; | ||||
| #endif | #endif | ||||
| } | } | ||||
| static uiBlock *wm_block_create_splash(bContext *C, ARegion *region, void *UNUSED(arg)) | static uiBlock *wm_block_create_splash(bContext *C, ARegion *region, void *UNUSED(arg)) | ||||
| { | { | ||||
| uiBlock *block; | uiBlock *block; | ||||
| uiBut *but; | uiBut *but; | ||||
| const uiStyle *style = UI_style_get_dpi(); | const uiStyle *style = UI_style_get_dpi(); | ||||
| block = UI_block_begin(C, region, "splash", UI_EMBOSS); | block = UI_block_begin(C, region, "splash", UI_EMBOSS); | ||||
| /* note on UI_BLOCK_NO_WIN_CLIP, the window size is not always synchronized | /* note on UI_BLOCK_NO_WIN_CLIP, the window size is not always synchronized | ||||
| * with the OS when the splash shows, window clipping in this case gives | * with the OS when the splash shows, window clipping in this case gives | ||||
| * ugly results and clipping the splash isn't useful anyway, just disable it [#32938] */ | * ugly results and clipping the splash isn't useful anyway, just disable it [#32938] */ | ||||
| UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_KEEP_OPEN | UI_BLOCK_NO_WIN_CLIP); | UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_KEEP_OPEN | UI_BLOCK_NO_WIN_CLIP); | ||||
| UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); | ||||
| /* Size before dpi scaling (halved for hi-dpi image). */ | /* Would be nice to support caching this, so it only has to be re-read (and likely resized) on | ||||
| int ibuf_unit_size[2]; | * first draw or if the image changed. */ | ||||
| ImBuf *ibuf = wm_block_splash_image(ibuf_unit_size); | ImBuf *ibuf = wm_block_splash_image(); | ||||
| but = uiDefButImage(block, | |||||
| ibuf, | float splash_width = 500.0f * U.dpi_fac; | ||||
| 0, | float splash_height = (splash_width * ibuf->y) / ibuf->x; | ||||
| 0.5f * U.widget_unit, | |||||
| U.dpi_fac * ibuf_unit_size[0], | but = uiDefButImage(block, ibuf, 0, 0.5f * U.widget_unit, splash_width, splash_height, NULL); | ||||
| U.dpi_fac * ibuf_unit_size[1], | |||||
| NULL); | |||||
| UI_but_func_set(but, wm_block_splash_close, block, NULL); | UI_but_func_set(but, wm_block_splash_close, block, NULL); | ||||
| UI_block_func_set(block, wm_block_splash_refreshmenu, block, NULL); | UI_block_func_set(block, wm_block_splash_refreshmenu, block, NULL); | ||||
| int x = U.dpi_fac * (ibuf_unit_size[0] + 1); | wm_block_splash_add_labels(block, splash_width, splash_height - 13 * U.dpi_fac); | ||||
| int y = U.dpi_fac * (ibuf_unit_size[1] - 13); | |||||
| wm_block_splash_add_labels(block, x, y); | |||||
| const int layout_margin_x = U.dpi_fac * 26; | const int layout_margin_x = U.dpi_fac * 26; | ||||
| uiLayout *layout = UI_block_layout(block, | uiLayout *layout = UI_block_layout(block, | ||||
| UI_LAYOUT_VERTICAL, | UI_LAYOUT_VERTICAL, | ||||
| UI_LAYOUT_PANEL, | UI_LAYOUT_PANEL, | ||||
| layout_margin_x, | layout_margin_x, | ||||
| 0, | 0, | ||||
| (U.dpi_fac * ibuf_unit_size[0]) - (layout_margin_x * 2), | splash_width - (layout_margin_x * 2), | ||||
| U.dpi_fac * 110, | U.dpi_fac * 110, | ||||
| 0, | 0, | ||||
| style); | style); | ||||
| MenuType *mt = WM_menutype_find("WM_MT_splash", true); | MenuType *mt = WM_menutype_find("WM_MT_splash", true); | ||||
| if (mt) { | if (mt) { | ||||
| UI_menutype_draw(C, mt, layout); | UI_menutype_draw(C, mt, layout); | ||||
| } | } | ||||
| Show All 22 Lines | |||||