public Item(int x, int y, Page targetPage, GMTextureItem textureItem) { X = x; Y = y; TargetPage = targetPage; targetPage.Items.Add(this); TextureItem = textureItem; }
public void AddNewEntry(Textures textures, GMTextureItem entry) { if (Items.Contains(entry)) return; Dirty = true; Items.Add(entry); if (entry.TexturePageID == -1 && !entry._EmptyBorder && AllowCrop) entry.Crop(); long key = textures.GetHashKeyForEntry(entry); if (HashedItems.TryGetValue(key, out List<GMTextureItem> list)) list.Add(entry); else HashedItems[key] = new List<GMTextureItem>() { entry }; }
public override void Unserialize(GMDataReader reader) { base.Unserialize(reader); Unknown = reader.ReadUInt64(); Options = (OptionsFlags)reader.ReadUInt64(); Scale = reader.ReadUInt32(); WindowColor = reader.ReadUInt32(); ColorDepth = reader.ReadUInt32(); Resolution = reader.ReadUInt32(); Frequency = reader.ReadUInt32(); VertexSync = reader.ReadUInt32(); Priority = reader.ReadUInt32(); SplashBackImage = reader.ReadPointerObject <GMTextureItem>(); SplashFrontImage = reader.ReadPointerObject <GMTextureItem>(); SplashLoadImage = reader.ReadPointerObject <GMTextureItem>(); LoadAlpha = reader.ReadUInt32(); Constants = new GMList <Constant>(); Constants.Unserialize(reader); }
public bool Place(Textures.Group group, GMTextureItem entry, int extraBorder, bool pregms2_2_2, out int x, out int y) { int gap = group.Border; if (entry._HasExtraBorder) { gap += extraBorder; } int width = entry.SourceWidth, height = entry.SourceHeight; bool addX = false, addY = false; if (pregms2_2_2) { // Before 2.2.2 if (width + (gap * 2) < Width) { width = (width + (gap * 2) + 3) & -4; addX = true; } if (height + (gap * 2) < Height) { height = (height + (gap * 2) + 3) & -4; addY = true; } } else { // After 2.2.2 if (width != Width) { width += gap * 2; addX = true; } if (height != Height) { height += gap * 2; addY = true; } } Rect rect = MainRect.FindSpace(width, height); if (rect != null) { MainRect.Place(rect, width, height, out x, out y); if (addX) { x += gap; } if (addY) { y += gap; } return(true); } x = -1; y = -1; return(false); }
protected override byte[] WriteInternal(ProjectFile pf, string assetPath, bool actuallyWrite) { byte[] buff = JsonSerializer.SerializeToUtf8Bytes(this, ProjectFile.JsonOptions); string dir = null; if (actuallyWrite) { dir = Path.GetDirectoryName(assetPath); Directory.CreateDirectory(dir); using (FileStream fs = new FileStream(assetPath, FileMode.Create)) fs.Write(buff, 0, buff.Length); } // Compute hash manually here using (SHA1Managed sha1 = new SHA1Managed()) { Length = buff.Length; // Handle sprite frames for (int i = 0; i < TextureItems.Count; i++) { GMTextureItem item = TextureItems[i]; byte[] imgBuff; Bitmap imgBitmap; if (item.TexturePageID == -1) { imgBitmap = item._Bitmap; } else { imgBitmap = pf.Textures.GetTextureEntryBitmap(item, Width, Height); } imgBuff = imgBitmap.GetReadOnlyByteArray(); if (actuallyWrite) { using (FileStream fs = new FileStream(Path.Combine(dir, Name + "_" + i.ToString() + ".png"), FileMode.Create)) imgBitmap.Save(fs, System.Drawing.Imaging.ImageFormat.Png); } Length += imgBuff.Length; sha1.TransformBlock(imgBuff, 0, imgBuff.Length, null, 0); } if (SpecialInfo != null) { if (SpecialInfo.InternalBuffer != null && SpecialInfo.Buffer != null) { byte[] internalBufferArray = SpecialInfo.InternalBuffer.Memory.ToArray(); if (actuallyWrite) { using (FileStream fs = new FileStream(Path.Combine(dir, SpecialInfo.Buffer), FileMode.Create)) fs.Write(internalBufferArray, 0, internalBufferArray.Length); } Length += internalBufferArray.Length; sha1.TransformBlock(internalBufferArray, 0, internalBufferArray.Length, null, 0); } } // Save raw collision masks if (CollisionMask.RawMasks?.Count > 0) { for (int i = 0; i < CollisionMask.RawMasks.Count; i++) { byte[] mask = CollisionMask.RawMasks[i].Memory.ToArray(); if (actuallyWrite) { using (FileStream fs = new FileStream(Path.Combine(dir, Name + "_mask_" + i.ToString() + ".png"), FileMode.Create)) CollisionMasks.GetImageFromMask(Width, Height, mask).Save(fs, System.Drawing.Imaging.ImageFormat.Png); } Length += mask.Length; sha1.TransformBlock(mask, 0, mask.Length, null, 0); } } sha1.TransformFinalBlock(buff, 0, buff.Length); Hash = sha1.Hash; } return(null); }
public void Unserialize(GMDataReader reader) { Name = reader.ReadStringPointerObject(); TextureItem = reader.ReadPointer <GMTextureItem>(); }
public void RemoveEntry(Textures textures, GMTextureItem entry) { Items.Remove(entry); if (HashedItems.TryGetValue(textures.GetHashKeyForEntry(entry), out List<GMTextureItem> list)) list.Remove(entry); }
public override void Unserialize(GMDataReader reader) { base.Unserialize(reader); reader.VersionInfo.OptionBitflag = (reader.ReadInt32() == int.MinValue); reader.Offset -= 4; if (reader.VersionInfo.OptionBitflag) { Unknown = reader.ReadUInt64(); Options = (OptionsFlags)reader.ReadUInt64(); Scale = reader.ReadInt32(); WindowColor = reader.ReadUInt32(); ColorDepth = reader.ReadUInt32(); Resolution = reader.ReadUInt32(); Frequency = reader.ReadUInt32(); VertexSync = reader.ReadUInt32(); Priority = reader.ReadUInt32(); SplashBackImage = reader.ReadPointerObject <GMTextureItem>(); SplashFrontImage = reader.ReadPointerObject <GMTextureItem>(); SplashLoadImage = reader.ReadPointerObject <GMTextureItem>(); LoadAlpha = reader.ReadUInt32(); } else { Options = 0; ReadOption(reader, OptionsFlags.FullScreen); ReadOption(reader, OptionsFlags.InterpolatePixels); ReadOption(reader, OptionsFlags.UseNewAudio); ReadOption(reader, OptionsFlags.NoBorder); ReadOption(reader, OptionsFlags.ShowCursor); Scale = reader.ReadInt32(); ReadOption(reader, OptionsFlags.Sizeable); ReadOption(reader, OptionsFlags.StayOnTop); WindowColor = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.ChangeResolution); ColorDepth = reader.ReadUInt32(); Resolution = reader.ReadUInt32(); Frequency = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.NoButtons); VertexSync = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.ScreenKey); ReadOption(reader, OptionsFlags.HelpKey); ReadOption(reader, OptionsFlags.QuitKey); ReadOption(reader, OptionsFlags.SaveKey); ReadOption(reader, OptionsFlags.ScreenShotKey); ReadOption(reader, OptionsFlags.CloseSec); Priority = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.Freeze); ReadOption(reader, OptionsFlags.ShowProgress); SplashBackImage = reader.ReadPointerObject <GMTextureItem>(); SplashFrontImage = reader.ReadPointerObject <GMTextureItem>(); SplashLoadImage = reader.ReadPointerObject <GMTextureItem>(); ReadOption(reader, OptionsFlags.LoadTransparent); LoadAlpha = reader.ReadUInt32(); ReadOption(reader, OptionsFlags.ScaleProgress); ReadOption(reader, OptionsFlags.DisplayErrors); ReadOption(reader, OptionsFlags.WriteErrors); ReadOption(reader, OptionsFlags.AbortErrors); ReadOption(reader, OptionsFlags.VariableErrors); ReadOption(reader, OptionsFlags.CreationEventOrder); } Constants = new GMList <Constant>(); Constants.Unserialize(reader); }