private Color getColor(Tank tank, SelectBy by) { switch (by) { case SelectBy.Class: return(tank.Class.Pick(ClassLight, ClassMedium, ClassHeavy, ClassDestroyer, ClassArtillery, ClassNone)); case SelectBy.Country: return(tank.Country.Pick(CountryUSSR, CountryGermany, CountryUSA, CountryFrance, CountryChina, CountryUK, CountryJapan, CountryCzech, CountrySweden, CountryPoland, CountryItaly, CountryNone)); case SelectBy.Category: return(tank.Category.Pick(CategNormal, CategPremium, CategSpecial, CategCollector)); case SelectBy.Tier: if (tank.Tier == 0) { return(TierNone); } return(tank.Tier <= 5 ? Ut.BlendColors(Tier1, Tier5, (tank.Tier - 1) / 4.0) : Ut.BlendColors(Tier5, Tier10, (tank.Tier - 5) / 5.0)); case SelectBy.Single: return(Single); default: throw new Exception(); } }
/// <summary>A convenience method to save a GDI image directly to a .tga file.</summary> public static unsafe void Save(BitmapBase image, string filename) { using (image.UseRead()) using (var file = File.Open(filename, FileMode.Create, FileAccess.Write, FileShare.Read)) { var header = new byte[18]; header[2] = 2; header[12] = (byte)(image.Width); header[13] = (byte)(image.Width >> 8); header[14] = (byte)(image.Height); header[15] = (byte)(image.Height >> 8); header[16] = 32; header[17] = 32; file.Write(header); byte[] dummy = new byte[image.Width * 4]; for (int y = 0; y < image.Height; y++) { Ut.MemCpy(dummy, image.Data + y * image.Stride, image.Width * 4); file.Write(dummy); } } }
/// <summary>Applies a "colorize" effect to this image.</summary> /// <param name="hue">The hue of the color to apply, 0..359</param> /// <param name="saturation">The saturation of the color to apply, 0..1</param> /// <param name="lightness">A lightness adjustment, -1..1</param> /// <param name="alpha">Overall strength of the effect, 0..1. A value of 0 keeps only the original image.</param> public void Colorize(int hue, double saturation, double lightness, double alpha) { using (UseWrite()) { // http://stackoverflow.com/a/9177602/33080 var color = Ut.BlendColors(Color.FromRgb(128, 128, 128), ColorHSV.FromHSV(hue, 100, 100).ToColorWpf(), saturation); for (int y = 0; y < Height; y++) { byte *ptr = Data + y * Stride; byte *end = ptr + Width * 4; while (ptr < end) { double pixel = Math.Max(*ptr, Math.Max(*(ptr + 1), *(ptr + 2))) / 255.0; double position = lightness >= 0 ? (2 * (1 - lightness) * (pixel - 1) + 1) : 2 * (1 + lightness) * (pixel) - 1; * ptr = (byte)(*ptr * (1 - alpha) + (position < 0 ? color.B * (position + 1) : (color.B * (1 - position) + 255 * position)) * alpha); ptr++; *ptr = (byte)(*ptr * (1 - alpha) + (position < 0 ? color.G * (position + 1) : (color.G * (1 - position) + 255 * position)) * alpha); ptr++; *ptr = (byte)(*ptr * (1 - alpha) + (position < 0 ? color.R * (position + 1) : (color.R * (1 - position) + 255 * position)) * alpha); ptr += 2; } } } }
static int Main(string[] args) { // Configure Classify. This goes before the post-build check because it depends on it Classify.DefaultOptions = new ClassifyOptions() .AddTypeOptions(typeof(W.Color), new colorTypeOptions()) .AddTypeOptions(typeof(D.Color), new colorTypeOptions()) .AddTypeOptions(typeof(Filename), new filenameTypeOptions()) .AddTypeOptions(typeof(ObservableCollection <LayerBase>), new listLayerBaseOptions()) .AddTypeOptions(typeof(ObservableCollection <EffectBase>), new listEffectBaseOptions()); if (args.Length == 2 && args[0] == "--post-build-check") { return(RT.Util.Ut.RunPostBuildChecks(args[1], Assembly.GetExecutingAssembly())); } System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); #if DEBUG CompositePath.Tests(); #endif Thread.CurrentThread.Name = "Main"; #if !DEBUG AppDomain.CurrentDomain.UnhandledException += (_, ea) => { bool copy = DlgMessage.ShowError(App.Translation.Error.ExceptionGlobal, App.Translation.Error.ErrorToClipboard_Copy, App.Translation.Error.ErrorToClipboard_OK) == 0; if (copy) { if (Ut.ClipboardSet(Ut.ExceptionToDebugString(ea.ExceptionObject))) { DlgMessage.ShowInfo(App.Translation.Error.ErrorToClipboard_Copied); } } }; #else var dummy = App.Translation.Error.ExceptionGlobal; // to keep Lingo happy that the string is used var dummy2 = new StringBuilder(); // to keep the "using" clause used #endif // Find all the layer and effect types in the assembly (required before settings are loaded) App.LayerTypes = findTypes <LayerBase>("layer"); App.EffectTypes = findTypes <EffectBase>("effect"); // Load all settings SettingsUtil.LoadSettings(out App.Settings); UpdateSettingsIfNecessary(); // Guess the language if the OS language has changed (or this is the first run) var osLingo = Ut.GetOsLanguage(); if (App.Settings.OsLingo != osLingo) { App.Settings.OsLingo = App.Settings.Lingo = osLingo; } // Load translation App.Translation = Lingo.LoadTranslationOrDefault <Translation>("TankIconMaker", ref App.Settings.Lingo); // Run the UI var app = new App(); app.InitializeComponent(); app.Run(); // Save settings upon exit, even though they should be saved on every change anyway App.Settings.SaveQuiet(); return(0); }
private void ctValue_TextChanged(object sender, TextChangedEventArgs e) { ctExpandsTo.Text = Ut.ExpandIconPath(ctValue.Text, _context, _style, _exampleTank, saveType: this._saveType); }
public static BitmapGdi ToBitmapGdi(this D.Image src) { return(Ut.NewBitmapGdi(src.Width, src.Height, dc => { dc.DrawImageUnscaled(src, 0, 0); })); }
/// <summary>Expands a Tank Icon Maker-style path, which may have expandable tokens like "VersionName".</summary> public static string ExpandIconPath(string path, WotContext context, Style style, string country, string class_, string tankId, string tankFullName, string tankShortName, int tankTier, bool fragment = false, SaveType saveType = SaveType.Icons) { if (string.IsNullOrEmpty(path)) { switch (saveType) { case SaveType.Icons: path = "{IconsPath}\\{TankId}{Ext}"; break; case SaveType.BattleAtlas: path = "{AtlasPath}\\" + AtlasBuilder.battleAtlas + ".png"; break; case SaveType.VehicleMarkerAtlas: path = "{AtlasPath}\\" + AtlasBuilder.vehicleMarkerAtlas + ".png"; break; case SaveType.CustomAtlas: path = "{AtlasPath}\\" + AtlasBuilder.customAtlas + ".png"; break; } } path = path.Replace("{IconsPath}", Ut.ExpandPath(context, context.VersionConfig.PathDestination) + @"\"); path = path.Replace("{AtlasPath}", Ut.ExpandPath(context, context.VersionConfig.PathDestinationAtlas) + @"\"); path = path.Replace("{TimPath}", PathUtil.AppPath + @"\"); path = path.Replace("{GamePath}", context.Installation.Path + @"\"); path = path.Replace("{GameVersion}", context.Installation.GameVersionName); if (class_ != null) { path = path.Replace("{TankClass}", class_); } if (country != null) { path = path.Replace("{TankCountry}", country); } if (tankId != null) { path = path.Replace("{TankId}", tankId); } if (tankFullName != null) { path = path.Replace("{TankFullName}", tankFullName); } if (tankShortName != null) { path = path.Replace("{TankShortName}", tankShortName); } path = path.Replace("{TankTier}", tankTier.ToString()); path = path.Replace("{StyleName}", style.Name); path = path.Replace("{StyleAuthor}", style.Author); path = path.Replace("{Ext}", context.VersionConfig.TankIconExtension); path = Environment.ExpandEnvironmentVariables(path); path = path.Replace(@"\\", @"\").Replace(@"\\", @"\").Replace(@"\\", @"\"); if (path.EndsWith(@"\") && !path.EndsWith(@":\")) { path = path.Substring(0, path.Length - 1); } return(fragment ? path : Path.GetFullPath(Path.Combine(context.Installation.Path, path))); }
/// <summary> /// Works correctly even if context is null; will simply skip trying to make the path relative to game directories. /// </summary> public static string MakeRelativePath(WotContext context, string path) { try { if (PathUtil.IsSubpathOfOrSame(path, PathUtil.AppPath)) { return(PathUtil.ToggleRelative(PathUtil.AppPath, path)); } } catch { } try { if (PathUtil.IsSubpathOfOrSame(path, Path.Combine(context.Installation.Path, Ut.ExpandPath(context, context.VersionConfig.PathMods)))) { return(PathUtil.ToggleRelative(Path.Combine(context.Installation.Path, Ut.ExpandPath(context, context.VersionConfig.PathMods)), path)); } } catch { } try { if (PathUtil.IsSubpathOfOrSame(path, context.Installation.Path)) { return(PathUtil.ToggleRelative(context.Installation.Path, path)); } } catch { } return(path); }