Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/XIVLauncher.Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Config.Net;

using Hexa.NET.SDL3;
using Hexa.NET.SDL3.Image;

using Serilog;

Expand Down Expand Up @@ -41,6 +42,7 @@ sealed class Program
private static string[] mainArgs = [];
private static LauncherApp launcherApp = null!;
private static unsafe SDLWindow* window = null!;
private static unsafe SDLSurface* icon = null!;
private static unsafe SDLGPUDevice* gpuDevice = null!;
public static unsafe SDLGPUDevice* GPUDevice => gpuDevice;
private static ImGuiBindings guiBindings = null!;
Expand Down Expand Up @@ -287,6 +289,8 @@ private static void Main(string[] args)
Environment.Exit(1);
}

icon = GetApplicationIcon();
SDL.SetWindowIcon(window, icon);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
icon = GetApplicationIcon();
SDL.SetWindowIcon(window, icon);
if(!GetApplicationIcon(out icon))
{
Log.Error($"Error: Could not get application icon correctly: {SDL.GetErrorS()}");
}
else
{
SDL.SetWindowIcon(window, icon);
}

SDL.SetWindowPosition(window, (int)SDL.SDL_WINDOWPOS_CENTERED_MASK, (int)SDL.SDL_WINDOWPOS_CENTERED_MASK);
Log.Debug("SDL OK!");

Expand Down Expand Up @@ -336,6 +340,7 @@ private static void Main(string[] args)
guiBindings.Dispose();
SDL.ReleaseWindowFromGPUDevice(gpuDevice, window);
SDL.DestroyGPUDevice(gpuDevice);
SDL.DestroySurface(icon);
SDL.DestroyWindow(window);
SDL.Quit();

Expand Down Expand Up @@ -482,4 +487,30 @@ public static void ClearAll(bool tsbutton = false)
}

public static void ResetUIDCache(bool tsbutton = false) => launcherApp.UniqueIdCache.Reset();

private static unsafe SDLSurface* GetApplicationIcon()
Comment thread
Dormanil marked this conversation as resolved.
Outdated
{
var logoImage = AppUtil.GetEmbeddedResourceBytes("logo.png").AsMemory();
using var handle = logoImage.Pin();
var tempicon = SDLImage.LoadPNGIO(SDL.IOFromMem(handle.Pointer, (nuint) logoImage.Length));
if (tempicon is null)
{
Log.Error($"Error: SDL_LoadPNG_IO failed: {SDL.GetErrorS()}");
return SDL.CreateSurface(0,0,SDLPixelFormat.Abgr8888);
}
Comment on lines +508 to +513

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (tempicon is null)
{
Log.Error($"Error: SDL_LoadPNG_IO failed: {SDL.GetErrorS()}");
return SDL.CreateSurface(0,0,SDLPixelFormat.Abgr8888);
}
if (tempicon is null)
{
icon = null;
return false;
}


var applicationIcon = SDL.ScaleSurface(tempicon, 512, 512, SDLScaleMode.Linear);

// Sizes smaller than 64x64 don't look good on my machine
int[] alternateSizes = [64, 96, 128, 256];
foreach(var size in alternateSizes)
{
var alternateIcon = SDL.ScaleSurface(tempicon, size, size, SDLScaleMode.Linear);
SDL.AddSurfaceAlternateImage(applicationIcon, alternateIcon);
SDL.DestroySurface(alternateIcon);
}

SDL.DestroySurface(tempicon);
return applicationIcon;
Comment thread
Dormanil marked this conversation as resolved.
Outdated
}
}
Loading