Esempio n. 1
0
        /// <summary>
        /// On draw backbuffer
        /// </summary>
        protected override void OnDrawOnBackbuffer(ref System.Drawing.Graphics gfx)
        {
            // If the color matrix is empty, create it
            if (_cm == null)
            {
                _cm = new ColorMatrix(new float[][] {
                    new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, 0.5f, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                });
            }

            // Create new image attributes
            ImageAttributes ia = new ImageAttributes();

            ia.SetColorMatrix(_cm);

            // Get tile size
            Size tileSize = _background.TileSize;

            tileSize.Width  += 1;
            tileSize.Height += 1;

            // Iterate through instances
            foreach (GMareInstance inst in App.Room.Blocks)
            {
                // Get the object associated with this instance
                GMareObject obj = App.Room.Objects.Find(delegate(GMareObject o) { return(o.Resource.Id == inst.ObjectId); });

                // If no object was found, continue
                if (obj == null)
                {
                    continue;
                }

                // Get drawing point
                Point point = GMareBrush.TileIdToSourcePosition(inst.TileId, Image.Width, tileSize);
                point.X += 1;
                point.Y += 1;

                Bitmap image = obj.Image.ToBitmap();

                // Draw glyph
                gfx.DrawImage(image, new Rectangle(point.X, point.Y, obj.Image.Width, obj.Image.Height), 0, 0, obj.Image.Width, obj.Image.Height, GraphicsUnit.Pixel, ia);
                image.Dispose();
            }

            // Dispose.
            ia.Dispose();
        }
Esempio n. 2
0
 /// <summary>
 /// Object list click
 /// </summary>
 private void lstObjects_Click(object sender, EventArgs e)
 {
     // Set the selected object and close the dialog
     _selectedObject = lstObjects.SelectedItem == null ? null : (GMareObject)lstObjects.SelectedItem;
     DialogResult    = DialogResult.OK;
 }
Esempio n. 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);
            }
        }