-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mods to customize application icon and title.
- Loading branch information
1 parent
902006b
commit 17ff2cf
Showing
10 changed files
with
110 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#region Copyright & License Information | ||
/* | ||
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS) | ||
* This file is part of OpenRA, which is free software. It is made | ||
* available to you under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, either version 3 of | ||
* the License, or (at your option) any later version. For more | ||
* information, see COPYING. | ||
*/ | ||
#endregion | ||
|
||
using System; | ||
using OpenRA.FileFormats; | ||
|
||
namespace OpenRA.Graphics | ||
{ | ||
public sealed class IconManager | ||
{ | ||
readonly Sprite icon; | ||
readonly SheetBuilder sheetBuilder; | ||
|
||
public IconManager(ModData modData) | ||
{ | ||
var metadata = modData.Manifest.Metadata; | ||
|
||
if (!string.IsNullOrEmpty(metadata.ApplicationTitle)) | ||
Game.Renderer.Window.SetApplicationTitle(metadata.ApplicationTitle); | ||
|
||
if (string.IsNullOrEmpty(metadata.ApplicationIcon)) | ||
return; | ||
|
||
sheetBuilder = new SheetBuilder(SheetType.BGRA); | ||
var fileSystem = modData.DefaultFileSystem; | ||
using (var stream = fileSystem.Open(metadata.ApplicationIcon)) | ||
icon = sheetBuilder.Add(new Png(stream)); | ||
|
||
var size = icon.Bounds.Size; | ||
var srcStride = icon.Sheet.Size.Width; | ||
var srcData = icon.Sheet.GetData(); | ||
var rgbaData = new byte[4 * size.Width * size.Height]; | ||
|
||
for (var j = 0; j < size.Height; j++) | ||
{ | ||
for (var i = 0; i < size.Width; i++) | ||
{ | ||
var src = 4 * (j * srcStride + i); | ||
var dest = 4 * (j * size.Width + i); | ||
Array.Copy(srcData, src, rgbaData, dest, 4); | ||
} | ||
} | ||
|
||
Game.Renderer.Window.SetApplicationIcon(size, rgbaData); | ||
|
||
foreach (var s in sheetBuilder.AllSheets) | ||
s.ReleaseBuffer(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
sheetBuilder.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters