Skip to content

Commit

Permalink
0.3.7.812
Browse files Browse the repository at this point in the history
  • Loading branch information
gleblebedev committed Jul 11, 2024
1 parent 67d1e21 commit e81dba3
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"unofficial.Urho3DNet.Editor": {
"version": "0.3.7.810",
"version": "0.3.7.812",
"commands": [
"rbfx"
]
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Urho3DNetVersion>0.3.7.810</Urho3DNetVersion>
<Urho3DNetVersion>0.3.7.812</Urho3DNetVersion>
</PropertyGroup>
</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 26 additions & 17 deletions Tools/IconUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ static async Task<int> Main(string[] args)
name: "--output",
description: "Output directory.");

var foregroundRoundScaleOption = new Option<float?>(
name: "--foreground-round-scale",
description: "The icon foreground image scale when rendered for round icon.");

var rootCommand = new RootCommand("Generate icons from a single image");
rootCommand.AddOption(foregroundOption);
rootCommand.AddOption(backgroundOption);
rootCommand.AddOption(backgroundColorOption);
rootCommand.AddOption(outputOption);
rootCommand.AddOption(foregroundRoundScaleOption);

rootCommand.SetHandler((fore, back, backCol, output) =>
{
//GenerateCode(output);
GenerateIcons(fore, back, backCol, output);
},
foregroundOption, backgroundOption, backgroundColorOption, outputOption);
rootCommand.SetHandler(GenerateIcons,
foregroundOption, backgroundOption, backgroundColorOption, outputOption, foregroundRoundScaleOption);

return await rootCommand.InvokeAsync(args);
}

private static void GenerateIcons(FileInfo? fore, FileInfo? back, string? backCol, DirectoryInfo? output)
private static void GenerateIcons(FileInfo? fore, FileInfo? back, string? backCol, DirectoryInfo? output, float? foregroundRoundScale)
{
Color backgroundColor = Color.Transparent;
if (!string.IsNullOrWhiteSpace(backCol))
Expand All @@ -52,7 +53,7 @@ private static void GenerateIcons(FileInfo? fore, FileInfo? back, string? backCo

MakeWindowsIcon(outPath, background, backgroundColor, foreground);
MakeUWPIcons(outPath, background, backgroundColor, foreground);
MakeAndroidIcons(outPath, background, backgroundColor, foreground);
MakeAndroidIcons(outPath, background, backgroundColor, foreground, foregroundRoundScale ?? 0.7071f);
MakeIOSIcons(outPath, background, backgroundColor, foreground);
}

Expand Down Expand Up @@ -103,7 +104,7 @@ private static void MakeUWPIcons(string outPath, Image? background, Color backgr
RenderForeground(bmp, foreground);
});
}
private static void MakeAndroidIcons(string outPath, Image? background, Color backgroundColor, Image? foreground)
private static void MakeAndroidIcons(string outPath, Image? background, Color backgroundColor, Image? foreground, float foregroundRoundScale)
{
// hdpi

Expand All @@ -119,7 +120,7 @@ private static void MakeAndroidIcons(string outPath, Image? background, Color ba
MakePng(Path.Combine(outPath, "RbfxTemplate.Android\\Resources\\mipmap-hdpi\\ic_launcher_round.png"), 72, 72, (Bitmap bmp) =>
{
RenderBackground(bmp, background, backgroundColor);
RenderForeground(bmp, foreground);
RenderForeground(bmp, foreground, foregroundRoundScale);
});

// mdpi
Expand All @@ -136,7 +137,7 @@ private static void MakeAndroidIcons(string outPath, Image? background, Color ba
MakePng(Path.Combine(outPath, "RbfxTemplate.Android\\Resources\\mipmap-mdpi\\ic_launcher_round.png"), 48, 48, (Bitmap bmp) =>
{
RenderBackground(bmp, background, backgroundColor);
RenderForeground(bmp, foreground);
RenderForeground(bmp, foreground, foregroundRoundScale);
});

// xhdpi
Expand All @@ -153,7 +154,7 @@ private static void MakeAndroidIcons(string outPath, Image? background, Color ba
MakePng(Path.Combine(outPath, "RbfxTemplate.Android\\Resources\\mipmap-xhdpi\\ic_launcher_round.png"), 96, 96, (Bitmap bmp) =>
{
RenderBackground(bmp, background, backgroundColor);
RenderForeground(bmp, foreground);
RenderForeground(bmp, foreground, foregroundRoundScale);
});

// xxhdpi
Expand All @@ -170,7 +171,7 @@ private static void MakeAndroidIcons(string outPath, Image? background, Color ba
MakePng(Path.Combine(outPath, "RbfxTemplate.Android\\Resources\\mipmap-xxhdpi\\ic_launcher_round.png"), 144, 144, (Bitmap bmp) =>
{
RenderBackground(bmp, background, backgroundColor);
RenderForeground(bmp, foreground);
RenderForeground(bmp, foreground, foregroundRoundScale);
});

// xxxhdpi
Expand All @@ -187,7 +188,7 @@ private static void MakeAndroidIcons(string outPath, Image? background, Color ba
MakePng(Path.Combine(outPath, "RbfxTemplate.Android\\Resources\\mipmap-xxxhdpi\\ic_launcher_round.png"), 192, 192, (Bitmap bmp) =>
{
RenderBackground(bmp, background, backgroundColor);
RenderForeground(bmp, foreground);
RenderForeground(bmp, foreground, foregroundRoundScale);
});
}
private static void MakeIOSIcons(string outPath, Image? background, Color backgroundColor, Image? foreground)
Expand Down Expand Up @@ -325,7 +326,7 @@ private static RectangleF FitRectangle(RectangleF srcRect, RectangleF dstRect)
}
}

private static void RenderForeground(Bitmap bmp, Image? foreground)
private static void RenderForeground(Bitmap bmp, Image? foreground, float scale = 1.0f)
{
if (foreground != null)
{
Expand All @@ -334,15 +335,23 @@ private static void RenderForeground(Bitmap bmp, Image? foreground)
RectangleF srcRect = new RectangleF(0, 0, foreground.Width, foreground.Height);
RectangleF dstRect = new RectangleF(0, 0, bmp.Width, bmp.Height);

var dstAspect = dstRect.Width / dstRect.Height;

dstRect = FitRectangle(srcRect, dstRect);

dstRect = ScaleRectangle(dstRect, scale);

gr.DrawImage(foreground, dstRect, srcRect, GraphicsUnit.Pixel);
}
}
}

private static RectangleF ScaleRectangle(RectangleF dstRect, float scale)
{
var newWidth = dstRect.Width * scale;
var newHeight = dstRect.Height * scale;

return new RectangleF(dstRect.X+(dstRect.Width- newWidth)*0.5f, dstRect.Y + (dstRect.Height - newHeight) * 0.5f, newWidth, newHeight);
}

private static void MakePng(string path, int width, int height, Action<Bitmap> recipe)
{
using (var bmp = new Bitmap(width, height))
Expand Down

0 comments on commit e81dba3

Please sign in to comment.