/// <summary> /// Gets a GMare background from imported backgrounds /// </summary> /// <returns>A GMare background</returns> private GMareBackground GetBackground() { // Create new background GMareBackground background = null; // If an item was selected if (lstBackgrounds.SelectedItem != null) { // Get GMare vackground from Game Maker background GMBackground back = lstBackgrounds.SelectedItem as GMBackground; // Set properties background = new GMareBackground(); background.GameMakerId = back.Id; background.Name = back.Name; background.OffsetX = back.HorizontalOffset; background.OffsetY = back.VerticalOffset; background.SeparationX = back.HorizontalSeperation; background.SeparationY = back.VerticalSeperation; background.TileWidth = back.TileWidth; background.TileHeight = back.TileHeight; background.Image = new Graphics.PixelMap(GMUtilities.GetBitmap(back.Image)); // If the background is transparent if (back.Transparent == true) { background.Image.UseKey = true; background.Image.ColorKey = Color.FromArgb(background.Image[0, background.Image.Height - 1]); } } // Return converted background return(background); }
/// <summary> /// On get glyph /// </summary> public override GDI.Bitmap OnGetGlyph(DrawItemEventArgs e) { // Do action based on listbox type switch (_listboxMode) { case ListboxType.Backgrounds: // Get background GMBackground background = Items[e.Index] as GMBackground; // If the background is empty, return null if (background == null) { return(null); } // Image to draw GDI.Bitmap image = null; // Get the background image if (background.Image != null) { image = ScaleBitmap(GMUtilities.GetBitmap(background.Image), _cellSize.Width, _cellSize.Height); } // If the image is still empty, create blank image if (image == null) { image = new GDI.Bitmap(_cellSize.Width, _cellSize.Height); } return(image); case ListboxType.Instances: // Get the instance from the list, also get the parent object of the instance GMareInstance instance = Items[e.Index] as GMareInstance; // If there is no instance or room, return null if (instance == null || App.Room == null) { return(null); } GMareObject gmObject = App.Room.Objects.Find(o => instance.ObjectId == o.Resource.Id); // If the instance or object or object image is empty, return default glyph if (instance == null || gmObject == null || gmObject.Image == null) { return(GMare.Properties.Resources.instance); } // Create a new glyph GDI.Bitmap glyph = new GDI.Bitmap(CellSize.Width * 2 + 2, CellSize.Height); GDI.Bitmap icon = ScaleImage((GDI.Bitmap)gmObject.Image.ToBitmap(), CellSize.Width, CellSize.Height); GDI.Graphics gfx = GDI.Graphics.FromImage(glyph); gfx.DrawImageUnscaled(icon, GDI.Point.Empty); // If there is creation code on the instance, show an icon for it if (instance.CreationCode != string.Empty) { gfx.DrawImageUnscaled(GMare.Properties.Resources.script, new GDI.Point(icon.Width + 2, 0)); } // Return glyph return(glyph); case ListboxType.Objects: // Get the object GMareObject gmObject2 = Items[e.Index] == null ? null : (Items[e.Index] as GMareObject); // If the instance or object or object image is empty, return default glyph if (gmObject2 == null || gmObject2.Image == null) { return(GMare.Properties.Resources.instance); } // Create a new glyph GDI.Bitmap glyph2 = new GDI.Bitmap(CellSize.Width * 2 + 2, CellSize.Height); GDI.Bitmap icon2 = ScaleImage((GDI.Bitmap)gmObject2.Image.ToBitmap(), CellSize.Width, CellSize.Height); GDI.Graphics gfx2 = GDI.Graphics.FromImage(glyph2); gfx2.DrawImageUnscaled(icon2, GDI.Point.Empty); // Return glyph return(glyph2); default: return(Glyph); } }