Skip to content

Commit

Permalink
Merge pull request #279 from IntelOrca/add-window-icon
Browse files Browse the repository at this point in the history
Set window icon to OpenLoco logo
  • Loading branch information
IntelOrca committed Feb 24, 2019
2 parents 6b96c5c + d4b0bbf commit 33b8799
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
- Feature: [#221, #236] Implement audio through SDL2 mixer, introducing audio on Linux and macOS.
- Feature: [#237] Allow nearest neighbour scaling the game on integer intervals.
- Feature: [#275] Allow disabling the title screen music.
- Feature: [#279] Use OpenLoco logo for window icon. (Logo created by [Zcooger](https://github.com/Zcooger))
- Fix: Tooltips were calling the wrong event.
- Fix: [#219, #257] Prevent text from being drawn off-screen.
- Change: [#107] Show git branch and short sha1 hash in version info line.
Expand Down
69 changes: 69 additions & 0 deletions resources/OpenLoco.rc
@@ -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
Binary file added resources/logo/icon.ico
Binary file not shown.
57 changes: 57 additions & 0 deletions resources/logo/makeico.csx
@@ -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 changes: 16 additions & 0 deletions resources/resource.h
@@ -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
7 changes: 7 additions & 0 deletions src/openloco/openloco.vcxproj
Expand Up @@ -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>
Expand Down
24 changes: 24 additions & 0 deletions src/openloco/ui.cpp
Expand Up @@ -9,6 +9,8 @@
#include <vector>

#ifdef _WIN32
#include "../../resources/resource.h"

#ifndef NOMINMAX
#define NOMINMAX
#endif
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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()
{
Expand Down

0 comments on commit 33b8799

Please sign in to comment.