mirror of https://github.com/AxioDL/metaforce.git
Set window icon
This commit is contained in:
parent
b871cc965a
commit
011f65c48f
|
@ -166,11 +166,16 @@ mod ffi {
|
||||||
TriggerRight,
|
TriggerRight,
|
||||||
MAX,
|
MAX,
|
||||||
}
|
}
|
||||||
|
pub struct Icon {
|
||||||
|
pub data: Vec<u8>,
|
||||||
|
pub width: u32,
|
||||||
|
pub height: u32,
|
||||||
|
}
|
||||||
|
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
type WindowContext;
|
type WindowContext;
|
||||||
type App;
|
type App;
|
||||||
fn app_run(mut delegate: UniquePtr<AppDelegate>);
|
fn app_run(mut delegate: UniquePtr<AppDelegate>, icon: Icon);
|
||||||
fn get_args() -> Vec<String>;
|
fn get_args() -> Vec<String>;
|
||||||
fn get_window_size() -> WindowSize;
|
fn get_window_size() -> WindowSize;
|
||||||
fn set_window_title(title: &CxxString);
|
fn set_window_title(title: &CxxString);
|
||||||
|
@ -232,14 +237,19 @@ pub struct WindowContext {
|
||||||
|
|
||||||
static mut APP: Option<App> = None;
|
static mut APP: Option<App> = None;
|
||||||
|
|
||||||
fn app_run(mut delegate: cxx::UniquePtr<ffi::AppDelegate>) {
|
fn app_run(mut delegate: cxx::UniquePtr<ffi::AppDelegate>, icon: ffi::Icon) {
|
||||||
if delegate.is_null() {
|
if delegate.is_null() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
log::info!("Running app");
|
log::info!("Running app");
|
||||||
let event_loop = winit::event_loop::EventLoop::new();
|
let event_loop = winit::event_loop::EventLoop::new();
|
||||||
let window = winit::window::WindowBuilder::new().build(&event_loop).unwrap();
|
let window_icon = winit::window::Icon::from_rgba(icon.data, icon.width, icon.height).expect("Failed to load icon");
|
||||||
|
let window = winit::window::WindowBuilder::new()
|
||||||
|
.with_inner_size(winit::dpi::LogicalSize::new(1280, 720))
|
||||||
|
.with_window_icon(Some(window_icon))
|
||||||
|
.build(&event_loop)
|
||||||
|
.unwrap();
|
||||||
let sdl = sdl2::init().unwrap();
|
let sdl = sdl2::init().unwrap();
|
||||||
let sdl_events = sdl.event_pump().unwrap();
|
let sdl_events = sdl.event_pump().unwrap();
|
||||||
let controller = sdl.game_controller().unwrap();
|
let controller = sdl.game_controller().unwrap();
|
||||||
|
|
|
@ -566,6 +566,8 @@ static bool IsClientLoggingEnabled(int argc, char** argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !WINDOWS_STORE
|
#if !WINDOWS_STORE
|
||||||
|
extern "C" void cxxbridge1$rust_vec$u8$set_len(rust::Vec<u8>* ptr, std::size_t len) noexcept;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
//TODO: This seems to fix a lot of weird issues with rounding
|
//TODO: This seems to fix a lot of weird issues with rounding
|
||||||
// but breaks animations, need to research why this is the case
|
// but breaks animations, need to research why this is the case
|
||||||
|
@ -609,7 +611,17 @@ int main(int argc, char** argv) {
|
||||||
hecl::SetCpuCountOverride(argc, argv);
|
hecl::SetCpuCountOverride(argc, argv);
|
||||||
|
|
||||||
auto app = std::make_unique<metaforce::Application>(fileMgr, cvarMgr, cvarCmns);
|
auto app = std::make_unique<metaforce::Application>(fileMgr, cvarMgr, cvarCmns);
|
||||||
aurora::app_run(std::move(app));
|
auto data = aurora::Icon{};
|
||||||
|
{
|
||||||
|
auto icon = metaforce::GetIcon();
|
||||||
|
data.data.reserve(icon.size);
|
||||||
|
std::memcpy(data.data.data(), icon.data.get(), icon.size);
|
||||||
|
// terrible hack: https://github.com/dtolnay/cxx/issues/990
|
||||||
|
cxxbridge1$rust_vec$u8$set_len(&data.data, icon.size);
|
||||||
|
data.width = icon.width;
|
||||||
|
data.height = icon.height;
|
||||||
|
}
|
||||||
|
aurora::app_run(std::move(app), data);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -45,13 +45,22 @@ void ImGuiEngine_Initialize(float scale) {
|
||||||
ImGui::GetStyle().ScaleAllSizes(scale);
|
ImGui::GetStyle().ScaleAllSizes(scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiEngine_AddTextures(ImGuiState& state, const DeviceHolder& gpu) {
|
Icon GetIcon() {
|
||||||
int iconWidth = 0;
|
int iconWidth = 0;
|
||||||
int iconHeight = 0;
|
int iconHeight = 0;
|
||||||
auto* iconData = stbi_load_from_memory(static_cast<const stbi_uc*>(METAFORCE_ICON), int(METAFORCE_ICON_SZ),
|
auto* data = stbi_load_from_memory(static_cast<const stbi_uc*>(METAFORCE_ICON), int(METAFORCE_ICON_SZ), &iconWidth,
|
||||||
&iconWidth, &iconHeight, nullptr, 4);
|
&iconHeight, nullptr, 4);
|
||||||
ImGuiEngine::metaforceIcon = ImGuiEngine_AddTexture(state, gpu, iconWidth, iconHeight,
|
return Icon{
|
||||||
{iconData, static_cast<size_t>(iconWidth * iconHeight * 4)});
|
std::unique_ptr<uint8_t[]>{data},
|
||||||
stbi_image_free(iconData);
|
static_cast<size_t>(iconWidth) * static_cast<size_t>(iconHeight) * 4,
|
||||||
|
static_cast<uint32_t>(iconWidth),
|
||||||
|
static_cast<uint32_t>(iconHeight),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImGuiEngine_AddTextures(ImGuiState& state, const DeviceHolder& gpu) {
|
||||||
|
auto icon = GetIcon();
|
||||||
|
ImGuiEngine::metaforceIcon =
|
||||||
|
ImGuiEngine_AddTexture(state, gpu, icon.width, icon.height, {icon.data.get(), icon.size});
|
||||||
}
|
}
|
||||||
} // namespace metaforce
|
} // namespace metaforce
|
||||||
|
|
|
@ -21,6 +21,14 @@ struct ImGuiState;
|
||||||
struct DeviceHolder;
|
struct DeviceHolder;
|
||||||
void ImGuiEngine_AddTextures(ImGuiState& state, const DeviceHolder& gpu);
|
void ImGuiEngine_AddTextures(ImGuiState& state, const DeviceHolder& gpu);
|
||||||
|
|
||||||
|
struct Icon {
|
||||||
|
std::unique_ptr<uint8_t[]> data;
|
||||||
|
size_t size;
|
||||||
|
uint32_t width;
|
||||||
|
uint32_t height;
|
||||||
|
};
|
||||||
|
Icon GetIcon();
|
||||||
|
|
||||||
enum class KeyCode {
|
enum class KeyCode {
|
||||||
/// The '1' key over the letters.
|
/// The '1' key over the letters.
|
||||||
Key1,
|
Key1,
|
||||||
|
|
Loading…
Reference in New Issue