Beispiel #1
0
        // SiDComponent
        public override Bitmap RenderToBitmap(ResourcePack rp)
        {
            Bitmap tb = new Bitmap(Constants.RoomSize * Constants.TileSize, Constants.RoomSize * Constants.TileSize, PixelFormat.Format24bppRgb);
              Graphics gfx = Graphics.FromImage(tb);

              // rendering a room is pretty simple; just draw each tile, unscaled, in a grid
              Iterate((Int32 x, Int32 y, ref UID uid) =>
              {
            if (uid != null)
            {
              Tile t = rp.LookupByUID(uid) as Tile;
              if (t != null)
              {
            Bitmap tBmp = t.RenderToBitmap(rp);
            gfx.DrawImageUnscaled(tBmp, x * Constants.TileSize, y * Constants.TileSize);
              }
              else
              {
            // missing tile
            gfx.FillRectangle(Brushes.Magenta, x * Constants.TileSize, y * Constants.TileSize, 16.0f, 16.0f);
              }
            }
              });

              gfx.Dispose();
              return tb;
        }
Beispiel #2
0
        public override void Process(String compName, ResourcePack rp)
        {
            Int32 numTilesWide = (TargetBitmap.Width) / (Constants.TileSize);
              Int32 numTilesHigh = (TargetBitmap.Height) / (Constants.TileSize);

              Room r = new Room();
              r.Name = compName;

              Int32 numTilesAdded = 0;
              for (Int32 y = 0; y < numTilesHigh; y++)
              {
            for (Int32 x = 0; x < numTilesWide; x++)
            {
              Tile b = new Tile();

              Int32 tileX = x * (Constants.TileSize);
              Int32 tileY = y * (Constants.TileSize);

              b.SliceFromBitmap(TargetBitmap, tileX, tileY);
              b.Name = compName;

              if (rp.Add(b))
              {
            numTilesAdded++;
              }

              r.SetTile(x, y, b);
            }
              }

              rp.Add(r);
        }
Beispiel #3
0
        public override void Process(String compName, ResourcePack rp)
        {
            Int32 gapX = (Int32)gapInX.Value;
              Int32 gapY = (Int32)gapInY.Value;

              Bitmap edgedBitmap = new Bitmap(TargetBitmap, TargetBitmap.Width + Constants.TileSize, TargetBitmap.Height + Constants.TileSize);
              using (Graphics edgeGfx = Graphics.FromImage(edgedBitmap))
              {
            edgeGfx.Clear(colourSwatch.BackColor);

            edgeGfx.InterpolationMode = InterpolationMode.NearestNeighbor;
            edgeGfx.DrawImage(TargetBitmap, new Rectangle(0, 0, TargetBitmap.Width, TargetBitmap.Height), 0, 0, TargetBitmap.Width, TargetBitmap.Height, GraphicsUnit.Pixel);
              }

              Int32 curX = 0, curY = 0;
              while (curY < TargetBitmap.Height)
              {
            while (curX < TargetBitmap.Width)
            {
              Tile b = new Tile();

              b.SliceFromBitmap(edgedBitmap, curX, curY);
              b.Name = compName;

              rp.Add(b);

              curX += Constants.TileSize + gapX;
            }

            curX = 0;
            curY += Constants.TileSize + gapY;
              }
        }
Beispiel #4
0
        // SiDComponent
        public override Bitmap RenderToBitmap(ResourcePack rp)
        {
            Bitmap tb = new Bitmap(Constants.TileSize, Constants.TileSize, PixelFormat.Format32bppArgb);
              Iterate((Int32 x, Int32 y, ref PixelRGBA pixel, ref byte transFlags) =>
              {
            tb.SetPixel(x, y, Color.FromArgb(transFlags == 1 ? 0 : 255, pixel.R, pixel.G, pixel.B));
              });

              return tb;
        }
Beispiel #5
0
        // SiDComponent
        public override Bitmap RenderToBitmap(ResourcePack rp)
        {
            Bitmap tb = new Bitmap(Constants.TileSize, Constants.TileSize);
              Iterate((Int32 x, Int32 y, ref PixelRGBA pixel) =>
              {
            tb.SetPixel(x, y, Color.FromArgb(pixel.R, pixel.G, pixel.B));
              });

              return tb;
        }
Beispiel #6
0
        public ImageImportForm(Bitmap toSlice, Type configureToSiDType, ResourcePack rp, ControlPanelForm cpf)
        {
            InputBitmap = toSlice;
              SiDType = configureToSiDType;
              HostPack = rp;

              InitializeComponent();

              ControlForm = cpf;
              ControlPanel.SuspendLayout();
              {
            ControlForm.SetTargetBitmap(toSlice);
            ControlForm.TopLevel = false;
            ControlPanel.Controls.Add(ControlForm);
            ControlForm.Show();
              }
              ControlPanel.ResumeLayout();

              Text += String.Format("({0}) - {1}x{2}", configureToSiDType.Name, toSlice.Width, toSlice.Height);
        }
Beispiel #7
0
        public override void Process(String compName, ResourcePack rp)
        {
            const Int32 MidPoint = (Constants.RoomSize * Constants.TileSize) / 2;
              Point assembleAtPoint;

              Bitmap edgedBitmap = new Bitmap(TargetBitmap, TargetBitmap.Width + Constants.TileSize, TargetBitmap.Height + Constants.TileSize);
              edgedBitmap.MakeTransparent();

              using (Graphics edgeGfx = Graphics.FromImage(edgedBitmap))
              {
            edgeGfx.Clear(Color.Transparent);

            edgeGfx.InterpolationMode = InterpolationMode.NearestNeighbor;
            edgeGfx.DrawImage(TargetBitmap, new Rectangle(0, 0, TargetBitmap.Width, TargetBitmap.Height), 0, 0, TargetBitmap.Width, TargetBitmap.Height, GraphicsUnit.Pixel);
              }

              foreach (ExtractedObject eo in ObjectExtents)
              {
            StateObject ob = new StateObject();
            ob.Name = compName;

            if (alignToCenter.Checked)
              assembleAtPoint = new Point(MidPoint - eo.bounds.Width / 2, MidPoint - eo.bounds.Height / 2);
            else
              assembleAtPoint = new Point(0, 0);

            foreach (Rectangle r in eo.slices)
            {
              Sprite b = new Sprite();

              b.SliceFromBitmap(edgedBitmap, r.Left, r.Top, 128);
              b.Name = compName;

              rp.Add(b);
              ob.AddSprite(b, assembleAtPoint.X + (r.Left - eo.bounds.Left), assembleAtPoint.Y + (r.Top - eo.bounds.Top), 1.0f, false);
            }

            rp.Add(ob);
              }
        }
Beispiel #8
0
 public override Bitmap RenderToBitmap(ResourcePack rp)
 {
     throw (new InvalidOperationException("cannot convert Blob type to bitmap"));
 }
Beispiel #9
0
 public virtual void Process(String compName, ResourcePack rp)
 {
     throw new NotImplementedException();
 }
Beispiel #10
0
 void resourcePack_PackCleared(ResourcePack sender)
 {
     TrackedComponents.Clear();
       ilvTiles.Items.Clear();
       ilvRooms.Items.Clear();
       ilvSprites.Items.Clear();
       ilvObjects.Items.Clear();
       blobList.Items.Clear();
 }
Beispiel #11
0
        void resourcePack_ComponentRemoved(ResourcePack sender, SiDComponent comp)
        {
            ImageListViewItem ilvi = TrackedComponents[comp];
              TrackedComponents.Remove(comp);

              if (comp is Tile)
              {
            ilvTiles.Items.Remove(ilvi);
              }
              else if (comp is Room)
              {
            ilvRooms.Items.Remove(ilvi);
              }
              else if (comp is Sprite)
              {
            ilvSprites.Items.Remove(ilvi);
              }
              else if (comp is StateObject)
              {
            ilvObjects.Items.Remove(ilvi);
              }
        }
Beispiel #12
0
        void resourcePack_ComponentAdded(ResourcePack sender, SiDComponent comp)
        {
            String UIDstr = comp.getUID().ToString();

              if (comp is Tile)
              {
            Bitmap rep = ResizeBitmap(comp.RenderToBitmap(resourcePack), 4.0f);

            ilvTiles.Items.Add(UIDstr, comp.Name, rep);

            ImageListViewItem ilvi = ilvTiles.Items[ilvTiles.Items.Count - 1];
            ilvi.Tag = comp;

            TrackedComponents.Add(comp, ilvi);
              }
              else if (comp is Room)
              {
            Bitmap rep = comp.RenderToBitmap(resourcePack);

            ilvRooms.Items.Add(UIDstr, comp.Name, rep);

            ImageListViewItem ilvi = ilvRooms.Items[ilvRooms.Items.Count - 1];
            ilvi.Tag = comp;

            TrackedComponents.Add(comp, ilvi);
              }
              else if (comp is Sprite)
              {
            Bitmap rep = ResizeBitmap(comp.RenderToBitmap(resourcePack), 4.0f);

            ilvSprites.Items.Add(UIDstr, comp.Name, rep);

            ImageListViewItem ilvi = ilvSprites.Items[ilvSprites.Items.Count - 1];
            ilvi.Tag = comp;

            TrackedComponents.Add(comp, ilvi);
              }
              else if (comp is StateObject)
              {
            Bitmap rep = comp.RenderToBitmap(resourcePack);

            ilvObjects.Items.Add(UIDstr, comp.Name, rep);

            ImageListViewItem ilvi = ilvObjects.Items[ilvObjects.Items.Count - 1];
            ilvi.Tag = comp;

            TrackedComponents.Add(comp, ilvi);
              }
              else
              {
            byte [] stream = comp.SaveToByteStream();
            blobList.Items.Add(String.Format("{0} : {1}  ({2} bytes)", comp.ResourceTypeName, comp.Name, stream.Length));
              }
        }
Beispiel #13
0
        private void mmImportResDir_Click(object sender, EventArgs e)
        {
            if (ce != null)
              {
            ce.BringToFront();
            return;
              }

              if (findResourceCache.ShowDialog() == DialogResult.OK)
              {
            // show progress dialog
            ProcessingProgressForm ip = new ProcessingProgressForm();
            ip.Show();
            Application.DoEvents();

            ce = new CacheExplorer();
            ce.hostPack = resourcePack;

            ce.FormClosed += new FormClosedEventHandler((object _send, FormClosedEventArgs _e) => { ce = null; GC.Collect(); });

            ResourcePack dummyPack = new ResourcePack();
            Cursor.Current = Cursors.WaitCursor;

            // formulate directories to search
            String rootResDir = findResourceCache.SelectedPath;
            String tileDir = rootResDir + Path.DirectorySeparatorChar + "tile" + Path.DirectorySeparatorChar;
            String spriteDir = rootResDir + Path.DirectorySeparatorChar + "sprite" + Path.DirectorySeparatorChar;
            String objectDir = rootResDir + Path.DirectorySeparatorChar + "object" + Path.DirectorySeparatorChar;
            String roomDir = rootResDir + Path.DirectorySeparatorChar + "room" + Path.DirectorySeparatorChar;

            // go look up all the files we'll need to import
            Console.WriteLine("Gathering {0}...", tileDir);
            String[] tileFiles = (Directory.Exists(tileDir)) ? Directory.GetFiles(tileDir) : new String[] {};
            Console.WriteLine("Gathering {0}...", spriteDir);
            String[] spriteFiles = (Directory.Exists(spriteDir)) ? Directory.GetFiles(spriteDir) : new String[] {};
            Console.WriteLine("Gathering {0}...", objectDir);
            String[] objectFiles = (Directory.Exists(objectDir)) ? Directory.GetFiles(objectDir) : new String[] {};
            Console.WriteLine("Gathering {0}...", roomDir);
            String[] roomFiles = (Directory.Exists(roomDir)) ? Directory.GetFiles(roomDir) : new String[] { };
            Application.DoEvents();

            // setup progress bar for all files to load
            ip.progressBarLoad.Maximum = (tileFiles.Length + spriteFiles.Length + objectFiles.Length + roomFiles.Length);

            foreach (String tileFile in tileFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(tileFile) != "")
            continue;

              try
              {
            Tile t = new Tile();
            t.LoadFromFile(tileFile);
            dummyPack.Add(t);

            Bitmap rep = ResizeBitmap(t.RenderToBitmap(dummyPack), 4.0f);

            ce.tilesCache.Items.Add(t.getUID().ToString(), t.Name, rep);

            ImageListViewItem ilvi = ce.tilesCache.Items[ce.tilesCache.Items.Count - 1];
            ilvi.Tag = tileFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.tilesCache.Sort();
            }

            foreach (String spriteFile in spriteFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(spriteFile) != "")
            continue;

              try
              {
            Sprite s = new Sprite();
            s.LoadFromFile(spriteFile);

            Bitmap rep = ResizeBitmap(s.RenderToBitmap(dummyPack), 3.0f);
            dummyPack.Add(s);

            ce.spriteCache.Items.Add(s.getUID().ToString(), s.Name, rep);

            ImageListViewItem ilvi = ce.spriteCache.Items[ce.spriteCache.Items.Count - 1];
            ilvi.Tag = spriteFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.spriteCache.Sort();
            }

            foreach (String roomFile in roomFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(roomFile) != "")
            continue;

              try
              {
            Room r = new Room();
            r.LoadFromFile(roomFile);

            Bitmap rep = r.RenderToBitmap(dummyPack);
            dummyPack.Add(r);

            ce.roomCache.Items.Add(r.getUID().ToString(), r.Name, rep);

            ImageListViewItem ilvi = ce.roomCache.Items[ce.roomCache.Items.Count - 1];
            ilvi.Tag = roomFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.roomCache.Sort();
            }

            foreach (String objectFile in objectFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(objectFile) != "")
            continue;

              try
              {
            StateObject ob = new StateObject();
            ob.LoadFromFile(objectFile);

            Bitmap rep = ob.RenderToBitmap(dummyPack);
            dummyPack.Add(ob);

            ce.objectCache.Items.Add(ob.getUID().ToString(), ob.Name, rep);

            ImageListViewItem ilvi = ce.objectCache.Items[ce.objectCache.Items.Count - 1];
            ilvi.Tag = objectFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.objectCache.Sort();
            }

            ip.Close();

            Cursor.Current = Cursors.Default;
            ce.Show();

            GC.Collect();
              }
        }
Beispiel #14
0
 // render the component to a bitmap; we must pass in an RP for any dependant-asset look-up
 public abstract Bitmap RenderToBitmap(ResourcePack rp);
Beispiel #15
0
        // SiDComponent
        public override Bitmap RenderToBitmap(ResourcePack rp)
        {
            Bitmap tb = new Bitmap(Constants.RoomSize * Constants.TileSize, Constants.RoomSize * Constants.TileSize, PixelFormat.Format32bppArgb);
              tb.MakeTransparent();
              Graphics gfx = Graphics.FromImage(tb);

              ImageAttributes ia = new ImageAttributes();
              ColorMatrix cm = new ColorMatrix();

              foreach (SpriteLayer layer in layers)
              {
            Sprite spr = rp.LookupByUID(layer.uid) as Sprite;

            const Int32 MidPoint = (Constants.RoomSize * Constants.TileSize) / 2;
            Int32 sX = MidPoint + (Int32)((sbyte)layer.x);
            Int32 sY = MidPoint - (Int32)((sbyte)layer.y);
            Int32 spriteSpaceX = (sX - (Constants.TileSize / 2));
            Int32 spriteSpaceY = ((Constants.TileSize + sY) - (Constants.TileSize / 2));

            if (spr != null)
            {
              Bitmap sprBmp = spr.RenderToBitmap(rp);
              Rectangle destRect = new Rectangle(spriteSpaceX, spriteSpaceY, sprBmp.Width, sprBmp.Height);

              float transpF = (float)(layer.trans) / 255.0f;
              if (layer.glow == 1)
              {
            // additive blending in GDI+?
            // couldn't find a built-in way to do this. annnooyyyinngg

            Int32 readOffsetX = 0, readOffsetY = 0;
            if (destRect.Y < 0)
            {
              destRect.Height += destRect.Y;
              readOffsetY = -destRect.Y;
              destRect.Y = 0;
            }
            if (destRect.X < 0)
            {
              destRect.Width += destRect.X;
              readOffsetX = -destRect.X;
              destRect.X = 0;
            }

            BitmapData bmpData = tb.LockBits(destRect, ImageLockMode.ReadWrite, tb.PixelFormat);
            unsafe
            {
              for (int y = 0; y < bmpData.Height; y++)
              {
                byte* row = (byte*)bmpData.Scan0 + (y * bmpData.Stride);
                for (int x = 0; x < bmpData.Width; x++)
                {
                  Color topPixel = sprBmp.GetPixel(readOffsetX + x, readOffsetY + y);

                  Int32 xP = x * 4;
                  row[xP + 0] = (byte)Math.Min(255, (Int32)row[xP + 0] + topPixel.B);
                  row[xP + 1] = (byte)Math.Min(255, (Int32)row[xP + 1] + topPixel.G);
                  row[xP + 2] = (byte)Math.Min(255, (Int32)row[xP + 2] + topPixel.R);
                  row[xP + 3] = (byte)Math.Min(255, (Int32)row[xP + 3] + topPixel.A);
                }
              }
            }
            tb.UnlockBits(bmpData);
              }
              else
              {
            // standard alpha composite
            cm.Matrix33 = transpF;
            ia.SetColorMatrix(cm);
            gfx.DrawImage(sprBmp, destRect, 0, 0, 16.0f, 16.0f, GraphicsUnit.Pixel, ia);
              }

            }
            else
            {
              // missing sprite
              gfx.FillRectangle(Brushes.Magenta, spriteSpaceX, spriteSpaceY, 16.0f, 16.0f);
            }
              }

              gfx.Dispose();
              return tb;
        }