#region Copyright & License Information /* * Copyright 2007-2012 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 System.Runtime.InteropServices; using OpenRA.FileFormats; namespace OpenRA.TilesetBuilder { public partial class frmBuilder : Form { string srcfile; int size; public TerrainTypeInfo[] TerrainType; public Palette tpal; public bool PaletteFromImage = true; public string PaletteFile = ""; public string ImageFile = ""; public int TileSize = 24; private 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 fNew = new frmNew { }) if (DialogResult.OK == fNew.ShowDialog()) { PaletteFromImage = fNew.PaletteFromImage; PaletteFile = fNew.PaletteFile; ImageFile = fNew.ImageFile; TileSize = fNew.TileSize; srcfile = ImageFile; this.size = TileSize; surface1.TileSize = TileSize; Bitmap fbitmap = new Bitmap(ImageFile); Bitmap rbitmap = fbitmap.Clone(new Rectangle(0, 0, fbitmap.Width, fbitmap.Height), fbitmap.PixelFormat); if (!PaletteFromImage) { tpal = Palette.Load(PaletteFile, false); rbitmap.Palette = tpal.AsSystemPalette(); } surface1.Image = (Bitmap)rbitmap; 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