Set window icon to OpenLoco logo

This commit is contained in:
Ted John 2019-02-24 17:09:06 +00:00
parent 2ff2792bdc
commit 2405c9a3ce
6 changed files with 173 additions and 0 deletions

69
resources/OpenLoco.rc Normal file
View File

@ -0,0 +1,69 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United Kingdom) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON ICON "logo\\icon.ico"
#endif // English (United Kingdom) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

BIN
resources/logo/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -0,0 +1,57 @@
#r "System.Drawing.dll"
using System.Drawing;
using System.Drawing.Imaging;
if (Args.Count == 0)
{
Console.WriteLine("Usage: makeico <directory>");
return;
}
var inputDirectory = Args[0];
var outputPath = Path.Combine(inputDirectory, "icon.ico");
var imageSizes = new int[] { 256, 128, 96, 64, 48, 40, 32, 24, 16, 8, 4 };
var foundImages = imageSizes
.Select(size => (size, Path.Combine(inputDirectory, "icon_x" + size + ".png")))
.Where(x => File.Exists(x.Item2))
.ToArray();
using (FileStream fs = new FileStream(outputPath, FileMode.Create))
{
var bw = new BinaryWriter(fs);
bw.Write((short)0);
bw.Write((short)1);
bw.Write((short)foundImages.Length);
var dataStartOffset = 6 + (foundImages.Length * 16);
using (var dataStream = new MemoryStream())
{
foreach (var (size, path) in foundImages)
{
bw.Write((byte)(size == 256 ? 0 : size));
bw.Write((byte)(size == 256 ? 0 : size));
bw.Write((byte)0);
bw.Write((byte)0);
bw.Write((short)0);
bw.Write((short)32);
int dataOffset = (int)dataStream.Position;
int dataLength;
Console.WriteLine("Importing {0}", Path.GetFileName(path));
using (var image = Image.FromFile(path))
{
image.Save(dataStream, ImageFormat.Png);
}
dataLength = (int)dataStream.Position - dataOffset;
dataOffset += dataStartOffset;
bw.Write(dataLength);
bw.Write(dataOffset);
}
bw.Write(dataStream.ToArray());
}
}

16
resources/resource.h Normal file
View File

@ -0,0 +1,16 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by OpenLoco.rc
//
#define IDI_ICON 101
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -24,9 +24,16 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\resources\resource.h" />
<ClInclude Include="**\*.h" />
<ClInclude Include="**\*.hpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\resources\OpenLoco.rc" />
</ItemGroup>
<ItemGroup>
<Image Include="..\..\resources\logo\icon.ico" />
</ItemGroup>
<ItemGroup>
<Natvis Include="NatvisFile.natvis" />
</ItemGroup>

View File

@ -9,6 +9,8 @@
#include <vector>
#ifdef _WIN32
#include "..\..\resources\resource.h"
#ifndef NOMINMAX
#define NOMINMAX
#endif
@ -101,6 +103,7 @@ namespace openloco::ui
static SDL_Palette* palette;
static std::vector<SDL_Cursor*> _cursors;
static void set_window_icon();
static void update(int32_t width, int32_t height);
static void resize(int32_t width, int32_t height);
static int32_t convert_sdl_keycode_to_windows(int32_t keyCode);
@ -195,6 +198,8 @@ namespace openloco::ui
_hwnd = wmInfo.info.win.window;
#endif
set_window_icon();
// Create a palette for the window
palette = SDL_AllocPalette(256);
set_palette_callback = update_palette;
@ -203,6 +208,25 @@ namespace openloco::ui
#endif
}
static void set_window_icon()
{
#ifdef _WIN32
auto win32module = GetModuleHandleA("openloco.dll");
if (win32module != nullptr)
{
auto icon = LoadIconA(win32module, MAKEINTRESOURCEA(IDI_ICON));
if (icon != nullptr)
{
auto hwnd = (HWND)*_hwnd;
if (hwnd != nullptr)
{
SendMessageA(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon);
}
}
}
#endif
}
// 0x0045235D
void initialise()
{