Пример #1
0
        /// <summary>
        /// Check item index to see if it is a block instance
        /// </summary>
        /// <param name="index">Item index to check</param>
        /// <returns>If a block instance or not</returns>
        private bool IsBlock(int index)
        {
            // Get instance
            GMareInstance instance = Items[index] as GMareInstance;

            // Return results
            return(_listboxMode != ListboxType.Instances || instance.TileId == -1 ? false : true);
        }
Пример #2
0
        /// <summary>
        /// On get text
        /// </summary>
        public override string OnGetText(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("");
                }

                // Convert tileset boolean
                string convert = background.UseAsTileSet ? "Yes" : "No";

                // Create a string with background data
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Name: " + background.Name + " (Id: " + background.Id + ")");
                sb.AppendLine("Tileset: " + convert);
                sb.AppendLine("Width: " + background.Width);
                sb.AppendLine("Height: " + background.Height);
                return(sb.ToString());

            case ListboxType.Instances:
                // Get instance
                GMareInstance instance = Items[e.Index] as GMareInstance;

                // If the instance is empty, return default text
                if (instance == null)
                {
                    return(Items[e.Index].ToString());
                }

                return(Items[e.Index].ToString() + " (X: " + instance.X + ", Y: " + instance.Y + ")");

            default: return(Items[e.Index].ToString());
            }
        }
Пример #3
0
        /// <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);
            }
        }