Compare commits

...

11 Commits

Author SHA1 Message Date
pineappleEA
74cf531d9d Change yuzu_icon.h output dir and write to log when SetWindowIcon fails.
Add warnings when the BMP fails to load.
CMake now writes the resource to the build dir, so the source dir is not modified
2021-01-16 21:33:11 -06:00
pineappleEA
7f6c87cffb Convert windowIcon to window_icon 2021-01-17 00:02:43 +02:00
pineappleEA
074a663063 fix formatting on all files 2021-01-16 14:25:53 -06:00
pineappleEA
64107d72ee Make yuzu_icon_stream const
Co-authored-by: Rodrigo Locatti <reinuseslisp@airmail.cc>
2021-01-16 13:01:04 -06:00
pineappleEA
c6fd95cddd Make window icon const and fix naming convention
Co-authored-by: Rodrigo Locatti <reinuseslisp@airmail.cc>
2021-01-16 13:00:14 -06:00
pineappleEA
2ff675fa88 Call the SetWindowIcon function on the Vulkan window 2021-01-16 03:03:50 +02:00
pineappleEA
13056dea11 Call the SetWindowIcon function on the OpenGL window 2021-01-16 03:02:50 +02:00
pineappleEA
c70a284ffd Declare the SetWindowIcon function 2021-01-16 02:56:33 +02:00
pineappleEA
9cf8fe8c4b Implement the SetWindowIcon function
This function reads the bitmap resource from memory and sets it as the window icon
2021-01-16 02:47:04 +02:00
pineappleEA
d880a25368 Upload yuzu logo in bitmap format
This is needed since SDL2 parses only bitmaps, without additional libraries that is
2021-01-16 02:38:33 +02:00
pineappleEA
55d8d30c72 Implement the resource extractor
The extractor takes an asset (or multiple assets), in this case yuzu.bmp, and extracts their hex code to the header file yuzu_icon.h in order to be compiled and be embedded into the binary
2021-01-16 02:31:38 +02:00
6 changed files with 37 additions and 0 deletions

BIN
dist/yuzu.bmp vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

View File

@@ -1,5 +1,15 @@
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMakeModules)
function(create_resource file output filename)
# Read hex data from file
file(READ ${file} filedata HEX)
# Convert hex data for C compatibility
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
# Write data to output file
set(RESOURCES_DIR "${PROJECT_BINARY_DIR}/dist" PARENT_SCOPE)
file(WRITE "${PROJECT_BINARY_DIR}/dist/${output}" "const unsigned char ${filename}[] = {${filedata}};\nconst unsigned ${filename}_size = sizeof(${filename});\n")
endfunction()
add_executable(yuzu-cmd
config.cpp
config.h
@@ -24,6 +34,9 @@ if (MSVC)
endif()
target_link_libraries(yuzu-cmd PRIVATE ${PLATFORM_LIBRARIES} SDL2 Threads::Threads)
create_resource("../../dist/yuzu.bmp" "yuzu_cmd/yuzu_icon.h" "yuzu_icon")
target_include_directories(yuzu-cmd PRIVATE ${RESOURCES_DIR})
target_include_directories(yuzu-cmd PRIVATE ../../externals/Vulkan-Headers/include)
if(UNIX AND NOT APPLE)

View File

@@ -12,6 +12,7 @@
#include "input_common/mouse/mouse_input.h"
#include "input_common/sdl/sdl.h"
#include "yuzu_cmd/emu_window/emu_window_sdl2.h"
#include "yuzu_cmd/yuzu_icon.h"
EmuWindow_SDL2::EmuWindow_SDL2(InputCommon::InputSubsystem* input_subsystem_)
: input_subsystem{input_subsystem_} {
@@ -193,6 +194,22 @@ void EmuWindow_SDL2::WaitEvent() {
}
}
void EmuWindow_SDL2::SetWindowIcon() {
SDL_RWops* const yuzu_icon_stream = SDL_RWFromConstMem((void*)yuzu_icon, yuzu_icon_size);
if (yuzu_icon_stream == nullptr) {
LOG_WARNING(Frontend, "Failed to create yuzu icon stream.");
return;
}
SDL_Surface* const window_icon = SDL_LoadBMP_RW(yuzu_icon_stream, 1);
if (window_icon == nullptr) {
LOG_WARNING(Frontend, "Failed to read BMP from stream.");
return;
}
// The icon is attached to the window pointer
SDL_SetWindowIcon(render_window, window_icon);
SDL_FreeSurface(window_icon);
}
void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned> minimal_size) {
SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second);
}

View File

@@ -32,6 +32,9 @@ public:
/// Wait for the next event on the main thread.
void WaitEvent();
// Sets the window icon from yuzu.bmp
void SetWindowIcon();
protected:
/// Called by WaitEvent when a key is pressed or released.
void OnKeyEvent(int key, u8 state);

View File

@@ -119,6 +119,8 @@ EmuWindow_SDL2_GL::EmuWindow_SDL2_GL(InputCommon::InputSubsystem* input_subsyste
dummy_window = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 0, 0,
SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
SetWindowIcon();
if (fullscreen) {
Fullscreen();
}

View File

@@ -35,6 +35,8 @@ EmuWindow_SDL2_VK::EmuWindow_SDL2_VK(InputCommon::InputSubsystem* input_subsyste
std::exit(EXIT_FAILURE);
}
SetWindowIcon();
switch (wm.subsystem) {
#ifdef SDL_VIDEO_DRIVER_WINDOWS
case SDL_SYSWM_TYPE::SDL_SYSWM_WINDOWS: