protected void InitVals(string name, Bitmap bmp, string bmpFilePath, EngineResourceFileIdentifier resourceId) { _name = name; if (bmp != null) { _bmp = bmp; } else { if (resourceId != null) { _bmp = new Bitmap(resourceId.Data); } else { _imgFile = bmpFilePath; Bitmap tempBmp = new Bitmap(bmpFilePath); _bmp = new Bitmap(tempBmp, tempBmp.Width, tempBmp.Height); tempBmp.Dispose(); } } CreateGDICompatibleBmp(); if (Tilesheet._tilesheets.ContainsKey(_name)) { Tilesheet._tilesheets[_name].Dispose(); } Tilesheet._tilesheets.Add(_name, this); Tilesheet.RecalcMaxOverlapRatio(); }
public Puzzle(Graphics dc, string imgFile, int columns, int rows, Size size) { tilesheet = new Tilesheet("picture", imgFile); int tileWidth = (int)((float)tilesheet.Bmp.Width / (float)columns); int tileHeight = (int)((float)tilesheet.Bmp.Height / (float)rows); int adjWidth = tileWidth * columns; int adjHeight = tileHeight * rows; tilesheet.TileSize = new Size(tileWidth, tileHeight); originalSize = tilesheet.Bmp.Size; numColumns = columns; numRows = rows; adjustedSize = new Size(adjWidth, adjHeight); GridPointMatrix matrix = new GridPointMatrix(numColumns, numRows, tileWidth, tileHeight); matrix.CoordinateSystem = new SquareIsoCoordinates(); matrixes = new GridPointMatrixes(matrix); surface = new VisibleSurface(dc, size.Width, size.Height, matrixes); surface.Erase(); InitializeSprites(tileWidth, tileHeight); //Gondwana.Scripting.Parser.WriteToFile("bmpProp_file.gond", System.IO.FileMode.Create, tilesheet); //Engine.ScriptEngineState("file.gond", true); delMoveStart = new SpriteMovementEventHandler(Sprites_SpriteMovementStarted); delMoveStop = new SpriteMovementEventHandler(Sprites_SpriteMovementStopped); Sprites.SpriteMovementStarted += delMoveStart; Sprites.SpriteMovementStopped += delMoveStop; }
public Tilesheet(Tilesheet tilesheet, string name, string file) { this.InitialOffsetX = tilesheet.InitialOffsetX; this.InitialOffsetY = tilesheet.InitialOffsetY; this.XPixelsBetweenTiles = tilesheet.XPixelsBetweenTiles; this.YPixelsBetweenTiles = tilesheet.YPixelsBetweenTiles; this.Mask = tilesheet.Mask; this._tileSize = tilesheet._tileSize; this._extraTopSpace = tilesheet._extraTopSpace; this.ValueBag = new Dictionary <string, string>(tilesheet.ValueBag); InitVals(name, null, file, null); }
public void Dispose() { GC.SuppressFinalize(this); Tilesheet._tilesheets.Remove(_name); Tilesheet.RecalcMaxOverlapRatio(); pInvoke.DeleteObject(_hBmp); _dc.Dispose(); _bmp.Dispose(); if (Disposed != null) { Disposed(new TilesheetDisposedEventArgs(this)); } }
public Tilesheet(Tilesheet tilesheet, string name, string file) { this.InitialOffsetX = tilesheet.InitialOffsetX; this.InitialOffsetY = tilesheet.InitialOffsetY; this.XPixelsBetweenTiles = tilesheet.XPixelsBetweenTiles; this.YPixelsBetweenTiles = tilesheet.YPixelsBetweenTiles; this.Mask = tilesheet.Mask; this._tileSize = tilesheet._tileSize; this._extraTopSpace = tilesheet._extraTopSpace; this.ValueBag = new Dictionary<string, string>(tilesheet.ValueBag); InitVals(name, null, file, null); }
private void CopyFilesToAssets() { if (EngineState == null) return; foreach (var tilesheet in new List<Tilesheet>(EngineState.Tilesheets.Values)) { if (tilesheet.ResourceIdentifier != null) continue; if (Path.GetDirectoryName(tilesheet.ImageFilePath) != Path.GetDirectoryName(AssetsDirectory)) { string destFile = AssetsDirectory + Path.GetFileName(tilesheet.ImageFilePath); File.Copy(tilesheet.ImageFilePath, destFile, true); var tmpTilesheet = new Tilesheet(tilesheet, tilesheet.Name, destFile); // this will replace original Tilesheet this.IsDirty = true; } } foreach (var mediaFile in new List<MediaFile>(EngineState.MediaFiles.Values)) { if (mediaFile.ResourceIdentifier != null) continue; if (Path.GetDirectoryName(mediaFile.FileName) != Path.GetDirectoryName(AssetsDirectory)) { string destFile = AssetsDirectory + Path.GetFileName(mediaFile.FileName); File.Copy(mediaFile.FileName, destFile, true); var tmpMediaFile = new MediaFile(mediaFile, mediaFile.Alias, destFile, mediaFile.FileType); // this will replace original MediaFile this.IsDirty = true; } } foreach (var resourceFile in new List<Resource.EngineResourceFile>(EngineState.ResourceFiles)) { if (Path.GetDirectoryName(resourceFile.FilePath) != Path.GetDirectoryName(AssetsDirectory)) { string sourceFile = resourceFile.FilePath; string destFile = AssetsDirectory + Path.GetFileName(sourceFile); string password = resourceFile.Password; bool isEcnrypted = resourceFile.IsEncrypted; resourceFile.Dispose(); File.Copy(sourceFile, destFile, true); var tmpResourceFile = new Resource.EngineResourceFile(destFile, password, isEcnrypted); this.IsDirty = true; } } }
public readonly int YTile; // yTile * bmp.TileHeight = starting point for source bitmap #endregion Fields #region Constructors public Frame(Tilesheet tilesheet, int xTile, int yTile) { Tilesheet = tilesheet; XTile = xTile; YTile = yTile; }
public Frame(Tilesheet tilesheet, int xTile, int yTile) { Tilesheet = tilesheet; XTile = xTile; YTile = yTile; }
public static void LoadBitmaps() { tilesheet = new Tilesheet("original", path + "graphics\\original.bmp"); tilesheet.TileSize = new Size(64, 32); tilesheet.InitialOffsetX = 1; tilesheet.InitialOffsetY = 1; tilesheet.XPixelsBetweenTiles = 1; tilesheet.YPixelsBetweenTiles = 1; tilesheetMask = new Tilesheet("original_mask", path + "graphics\\original_mask.bmp"); tilesheetMask.TileSize = new Size(64, 32); tilesheetMask.InitialOffsetX = 1; tilesheetMask.InitialOffsetY = 1; tilesheetMask.XPixelsBetweenTiles = 1; tilesheetMask.YPixelsBetweenTiles = 1; sprtBmp = new Tilesheet("rooster", path + "graphics\\rooster.bmp"); sprtBmp.TileSize = new Size(50, 50); sprtBmpMask = new Tilesheet("rooster_mask", path + "graphics\\rooster_mask.bmp"); sprtBmpMask.TileSize = new Size(50, 50); tilesheet.Mask = tilesheetMask; sprtBmp.Mask = sprtBmpMask; //tilesheet.ApplyBmpSettingsFile(@"E:\TFS\Hidden Worlds Games\Gondwana\TestHarness\GondwanaWinTest\resources\XMLFile1.xml"); //tilesheetMask.ApplyBmpSettingsFile(@"E:\TFS\Hidden Worlds Games\Gondwana\TestHarness\GondwanaWinTest\resources\XMLFile1.xml"); //sprtBmp.ApplyBmpSettingsFile(@"E:\TFS\Hidden Worlds Games\Gondwana\TestHarness\GondwanaWinTest\resources\XMLFile2.xml"); //sprtBmpMask.ApplyBmpSettingsFile(@"E:\TFS\Hidden Worlds Games\Gondwana\TestHarness\GondwanaWinTest\resources\XMLFile2.xml"); //tilesheet.SaveBmpSettingsFile(path + "tilesheet.xml"); //tilesheetMask.SaveBmpSettingsFile(path + "tilesheetMask.xml"); //tilesheet.SaveBmpSettingsFile(@"E:\Finances\" + tilesheet.Name + ".xml"); FileStream writer = new FileStream(@"E:\TFS\Hidden Worlds Games\Gondwana\TestHarness\GondwanaWinTest\resources\tilesets.xml", FileMode.Create); DataContractSerializer ser = new DataContractSerializer(typeof(Tilesheet)); ser.WriteObject(writer, tilesheet); ser.WriteObject(writer, tilesheetMask); ser.WriteObject(writer, sprtBmp); ser.WriteObject(writer, sprtBmpMask); writer.Close(); }
protected internal TilesheetDisposedEventArgs(Tilesheet tilesheet) { Tilesheet = tilesheet; }
private void CreateResizedGDIBitmap(Tilesheet origTilesheet, ref Bitmap newBmp, ref Graphics newGraphics, ref IntPtr hdc, ref IntPtr hbmp) { // create the new Bitmap object with the new stretched Size newBmp = new Bitmap(RenderSize.Width, RenderSize.Height); // get Graphics object from new Bitmap with new size newGraphics = Graphics.FromImage(newBmp); // get pointer to Graphics object for new Bitmap hdc = ResizedGraphics.GetHdc(); // create and get handle to a GDI bitmap object compatible with the GDI+ Bitmap hbmp = NewBmp.GetHbitmap(); // associate the new bitmap handle with the new Graphics handle pInvoke.SelectObject(hdc, hbmp); // draw (i.e., StretchBlt) to new Graphics object from original Frame Bitmap Win32Support.DrawBitmap(hdc, new Rectangle(0, 0, NewBmp.Width, NewBmp.Height), origTilesheet.hDC, origTilesheet.GetSourceRange(OriginalFrame.XTile, OriginalFrame.YTile), TernaryRasterOperations.SRCCOPY); // release the pointer to the Graphics Hdc ResizedGraphics.ReleaseHdc(hdc); }