#region Copyright & License Information /* * Copyright 2007-2015 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. For more information, * see COPYING. */ #endregion using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using System.Windows.Forms; using System.Xml; using OpenRA.Graphics; namespace OpenRA.TilesetBuilder { public partial class FormBuilder : Form { string srcfile; int size; public TerrainTypeInfo[] TerrainType; public ImmutablePalette TerrainPalette; public bool PaletteFromImage = true; public string PaletteFile = ""; public string ImageFile = ""; public int TileSize = 24; private static int ColorDiff(Color color, Color curr) { return Math.Abs(color.R - curr.R) + Math.Abs(color.G - curr.G) + Math.Abs(color.B - curr.B); } public void CreateNewTileset() { this.Show(); using (var formNew = new FormNew { }) if (DialogResult.OK == formNew.ShowDialog()) { PaletteFromImage = formNew.PaletteFromImage; PaletteFile = formNew.PaletteFile; ImageFile = formNew.ImageFile; TileSize = formNew.TileSize; srcfile = ImageFile; this.size = TileSize; surface1.TileSize = TileSize; Bitmap rbitmap; using (var fbitmap = new Bitmap(ImageFile)) rbitmap = fbitmap.Clone(new Rectangle(0, 0, fbitmap.Width, fbitmap.Height), fbitmap.PixelFormat); int[] shadowIndex = { }; if (!PaletteFromImage) { TerrainPalette = new ImmutablePalette(PaletteFile, shadowIndex); rbitmap.Palette = TerrainPalette.AsSystemPalette(); } surface1.Image = (Bitmap)rbitmap; surface1.TilesPerRow = surface1.Image.Size.Width / surface1.TileSize; surface1.Image.SetResolution(96, 96); // people keep being noobs about DPI, and GDI+ cares. surface1.TerrainTypes = new int[surface1.Image.Width / size, surface1.Image.Height / size]; /* all passable by default */ surface1.Templates = new List