Exemplo n.º 1
0
        private void RefreshView()
        {
            lstv.Items.Clear();
            if (m_stps == null)
            {
                return;
            }

            // Prep LargeImageList

            if (lstv.LargeImageList != null)
            {
                lstv.LargeImageList.Dispose();
            }
            lstv.LargeImageList            = new ImageList();
            lstv.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            lstv.LargeImageList.ImageSize  = new Size(64, 64);

            // Prep SmallImageList

            if (lstv.SmallImageList != null)
            {
                lstv.SmallImageList.Dispose();
            }
            lstv.SmallImageList            = new ImageList();
            lstv.SmallImageList.ColorDepth = ColorDepth.Depth32Bit;
            lstv.SmallImageList.ImageSize  = new Size(16, 16);

            int i = 0;

            foreach (Strip stp in m_stps)
            {
                ListViewItem lvi = lstv.Items.Add(stp.Name);
                lvi.Tag = stp;

                if (stp == Globals.ActiveStrip)
                {
                    lvi.Selected = true;
                }

                lvi.SubItems.Add(stp.Count.ToString());

                // UNDONE: cook up better thumbnails
                // UNDONE: have a 'blank' thumbnail for empty Strips

                if (stp.Count > 0)
                {
                    if (stp[0].BitmapPlacers.Count > 0)
                    {
                        XBitmap xbm     = stp[0].BitmapPlacers[0].XBitmap;
                        Bitmap  bmThumb = xbm.MakeThumbnail(64, 64, false);
                        lstv.LargeImageList.Images.Add(bmThumb);
                        bmThumb = xbm.MakeThumbnail(16, 16, false);
                        lstv.SmallImageList.Images.Add(bmThumb);
                        lvi.ImageIndex = i++;
                    }
                }
            }
        }
Exemplo n.º 2
0
        // ISerializable interface implementation

        private XBitmapSet(SerializationInfo seri, StreamingContext stmc)
        {
            for (int i = 0; i < seri.MemberCount; i++)
            {
                XBitmap xbm = (XBitmap)seri.GetValue(i.ToString(), typeof(XBitmap));
                Add(xbm);
            }
        }
Exemplo n.º 3
0
 private void lstv_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
 {
     XBitmap[] axbm = new XBitmap[lstv.SelectedItems.Count];
     for (int i = 0; i < lstv.SelectedItems.Count; i++)
     {
         axbm[i] = (XBitmap)lstv.SelectedItems[i].Tag;
     }
     DoDragDrop(axbm, DragDropEffects.All);
 }
Exemplo n.º 4
0
        private void mniDelete_Click(object sender, System.EventArgs e)
        {
            XBitmap xbm = (XBitmap)lstv.SelectedItems[0].Tag;
            int     i   = m_xbms.IndexOf(xbm);

            // UNDONE: undo
            m_xbms.RemoveAt(i);
            lstv.Items.Remove(lstv.SelectedItems[0]);
            m_doc.Dirty = true;
        }
Exemplo n.º 5
0
        public Bitmap MakeThumbnail(int cxThumb, int cyThumb, bool fFilter)
        {
            Rectangle rcSrc = XBitmap.CalcRealBounds(m_bm);

            if (rcSrc.Width <= 0 || rcSrc.Height <= 0)
            {
                return(m_bm);
            }

            int      cxy   = Math.Max(rcSrc.Width, rcSrc.Height);
            Bitmap   bmDst = new Bitmap(cxy, cxy);
            Graphics gDst  = Graphics.FromImage(bmDst);

            gDst.Clear(Color.White);
            gDst.Dispose();
            int xDst = (bmDst.Width - rcSrc.Width) / 2;
            int yDst = (bmDst.Height - rcSrc.Height) / 2;

            BitmapData bmdDst = bmDst.LockBits(
                new Rectangle(0, 0, bmDst.Width, bmDst.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            SuperBlt(rcSrc.X, rcSrc.Y, bmdDst, xDst, yDst,
                     rcSrc.Width, rcSrc.Height, false);

            bmDst.UnlockBits(bmdDst);

            Bitmap            bmLarge = new Bitmap(cxThumb, cyThumb);
            Graphics          g       = Graphics.FromImage(bmLarge);
            InterpolationMode imOld   = g.InterpolationMode;

            g.InterpolationMode = fFilter ? InterpolationMode.Bicubic : InterpolationMode.NearestNeighbor;
            PixelOffsetMode pomOld = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.Half;

            g.DrawImage(bmDst, 0, 0, cxThumb, cyThumb);

            g.PixelOffsetMode   = pomOld;
            g.InterpolationMode = imOld;

            g.Dispose();
            bmDst.Dispose();

            return(bmLarge);
        }
Exemplo n.º 6
0
        private void lstv_AfterLabelEdit(object sender, System.Windows.Forms.LabelEditEventArgs e)
        {
            // Restore the context menu so the command keys, etc will work again

            lstv.ContextMenu = mnuListView;

            XBitmap xbm = (XBitmap)lstv.Items[e.Item].Tag;

            // No change or an invalid change

            if (e.Label == null || e.Label == "")
            {
                e.CancelEdit = true;
                return;
            }

            xbm.FileName = e.Label;
            m_doc.Dirty  = true;
        }
Exemplo n.º 7
0
 private BitmapPlacer(SerializationInfo seri, StreamingContext stmc)
     : this()
 {
     m_pt = (Point)seri.GetValue("Point", typeof(Point));
     m_xbm = (XBitmap)seri.GetValue("XBitmap", typeof(XBitmap));
 }
Exemplo n.º 8
0
 private BitmapPlacer(SerializationInfo seri, StreamingContext stmc) : this()
 {
     m_pt  = (Point)seri.GetValue("Point", typeof(Point));
     m_xbm = (XBitmap)seri.GetValue("XBitmap", typeof(XBitmap));
 }
Exemplo n.º 9
0
        public void DrawUnscaled(Bitmap bmDst, int cx, int cy, DrawArgs drwa, Point ptOffset)
        {
            Graphics gDst = Graphics.FromImage(bmDst);

            int xCenter = cx / 2;
            int yCenter = cy / 2;

            // Draw background (if enabled)

            if (drwa.fDrawBackground)
            {
                gDst.Clear(drwa.clrBackground);
            }

#if false
            // Draw background bitmap, if any

            if (m_bmBackground != null)
            {
                gT.DrawImage(m_bmBackground, xCenter - (m_bmBackground.Width / 2) + m_ptBackgroundOffset.X,
                             yCenter - (m_bmBackground.Height / 2) + m_ptBackgroundOffset.Y,
                             m_bmBackground.Width, m_bmBackground.Height);
            }
#endif
            // Draw grid (if enabled)
            // UNDONE: use alpha to draw grid (e.g., brighten or darken)

            if (drwa.fShowGrid)
            {
                int cxGrid = drwa.cxGrid;
                int cyGrid = drwa.cyGrid;
//						Brush br = new SolidBrush(Color.FromKnownColor(KnownColor.LightGray));
                Brush br = new SolidBrush(Color.FromArgb(256 / 3, 255, 255, 255));
                for (int x = (xCenter + ptOffset.X) % cxGrid; x < cx; x += cxGrid)
                {
                    gDst.FillRectangle(br, x, 0, 1, cy);
                }

                for (int y = (yCenter + ptOffset.Y) % cyGrid; y < cy; y += cyGrid)
                {
                    gDst.FillRectangle(br, 0, y, cx, 1);
                }
            }

            BitmapData bmdDst = bmDst.LockBits(
                new Rectangle(0, 0, bmDst.Width, bmDst.Height),
                ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            // Draw bitmaps from bottom up

            for (int i = BitmapPlacers.Count - 1; i >= 0; i--)
            {
                BitmapPlacer plc = BitmapPlacers[i];
                XBitmap      xbm = plc.XBitmap;
                xbm.SuperBlt(0, 0, bmdDst,
                             xCenter - plc.X + ptOffset.X,
                             yCenter - plc.Y + ptOffset.Y,
                             xbm.Bitmap.Width, xbm.Bitmap.Height,
                             drwa.fMapSideColors);
            }

            bmDst.UnlockBits(bmdDst);

            // Draw origin point (if enabled)

            if (drwa.fShowOrigin)
            {
                // This is really weird but if we don't do our own clipping then SetPixel will
                // raise an exception!

                int x = xCenter + ptOffset.X;
                int y = yCenter + ptOffset.Y;
                if (x >= 0 && y >= 0 && x < bmDst.Width && y < bmDst.Height)
                {
                    bmDst.SetPixel(x, y, Color.FromKnownColor(KnownColor.Orange));
                }
            }

            // Draw special point (if enabled)

            if (drwa.fShowSpecialPoint)
            {
                // This is really weird but if we don't do our own clipping then SetPixel will
                // raise an exception!

                int x = xCenter + ptOffset.X + m_ptSpecial.X;
                int y = yCenter + ptOffset.Y + m_ptSpecial.Y;
                if (x >= 0 && y >= 0 && x < bmDst.Width && y < bmDst.Height)
                {
                    bmDst.SetPixel(x, y, Color.FromArgb(0, 255, 0));
                }
            }

            gDst.Dispose();
        }
Exemplo n.º 10
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g      = e.Graphics;
            int      nScale = Globals.PreviewScale;
            Bitmap   bmDst  = new Bitmap(Width, Height);
            Graphics gDst   = Graphics.FromImage(bmDst);

            // Draw background (if enabled)

//			if (drwa.fDrawBackground)
            gDst.Clear(BackColor);

            // Draw grid (if enabled)

            if (true)
            {
                Brush br = new SolidBrush(Color.FromArgb(256 / 3, 255, 255, 255));
                for (int x = 0; x < bmDst.Width; x += Globals.GridWidth)
                {
                    gDst.FillRectangle(br, x, 0, 1, bmDst.Height);
                }

                for (int y = 0; y < bmDst.Height; y += Globals.GridHeight)
                {
                    gDst.FillRectangle(br, 0, y, bmDst.Width, 1);
                }
            }

            BitmapData bmdDst = bmDst.LockBits(new Rectangle(0, 0, bmDst.Width, bmDst.Height),
                                               ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            for (int ty = 0; ty < Height / Globals.GridHeight; ty++)
            {
                for (int tx = 0; tx < Width / Globals.GridWidth; tx++)
                {
                    if (m_mpfWall[tx, ty])
                    {
                        int ifrm = 0;
                        if (ty > 0)
                        {
                            ifrm |= m_mpfWall[tx, ty - 1] ? 1 : 0;
                        }
                        if (tx < kctxMap - 1)
                        {
                            ifrm |= m_mpfWall[tx + 1, ty] ? 2 : 0;
                        }
                        if (ty < kctyMap - 1)
                        {
                            ifrm |= m_mpfWall[tx, ty + 1] ? 4 : 0;
                        }
                        if (tx > 0)
                        {
                            ifrm |= m_mpfWall[tx - 1, ty] ? 8 : 0;
                        }

                        XBitmap xbm = Globals.ActiveStrip[ifrm].BitmapPlacers[0].XBitmap;
                        xbm.SuperBlt(0, 0, bmdDst,
                                     tx * Globals.GridWidth, ty * Globals.GridHeight,
                                     xbm.Bitmap.Width, xbm.Bitmap.Height,
                                     Globals.SideColorMappingOn);
                    }
                }
            }

            bmDst.UnlockBits(bmdDst);

            // Force a nice simple fast old-school stretchblt

            InterpolationMode imOld = g.InterpolationMode;

            g.InterpolationMode = InterpolationMode.NearestNeighbor;

            // NOTE: _without_ this the first row and column are only scaled by half!

            PixelOffsetMode pomOld = g.PixelOffsetMode;

            g.PixelOffsetMode = PixelOffsetMode.Half;

            // StretchBlt the temporary composite to the passed-in Graphic

            g.DrawImage(bmDst, 0, 0, bmDst.Width * nScale, bmDst.Height * nScale);

            g.PixelOffsetMode   = pomOld;
            g.InterpolationMode = imOld;

//			e.Graphics.DrawImage(bmDst, 0, 0, Width, Height);
            bmDst.Dispose();
            gDst.Dispose();
        }
Exemplo n.º 11
0
        public bool Import(string[] astrFileNames)
        {
            // Is this a SideWinder framedata.txt file?

            if (astrFileNames.Length == 1 && Path.GetFileName(astrFileNames[0]).ToLower() == "framedata.txt")
            {
                // Yep, open it up and parse it

                StreamReader stmr  = new StreamReader(astrFileNames[0]);
                int          iLine = 0;
                string       str;

                do
                {
                    iLine++;
                    str = stmr.ReadLine();
                } while (str == "");                    // skip blank lines

                if (str == null)
                {
                    MessageBox.Show(null, "Reached the end of the file before it was expected", "Error");
                    return(false);
                }

                string strName, strValue;
                if (!ParseNameValueString(str, out strName, out strValue))
                {
                    MessageBox.Show(null, String.Format("Syntax error on line %d: %s", iLine, str), "Error");
                    return(false);
                }

                if (strName != "cfrm")
                {
                    MessageBox.Show(null, "Expected a 'cfrm =' statement but didn't find it", "Error");
                    return(false);
                }

                // Find a unique name for this strip

                int iStrip = 0;
                while (StripSet["strip" + iStrip] != null)
                {
                    iStrip++;
                }
                Strip stp = new Strip("strip" + iStrip);
                StripSet.Add(stp);

                int cfr = int.Parse(strValue);
                for (int ifr = 0; ifr < cfr; ifr++)
                {
                    // 1. Read the bitmap from it and add it to the Document's XBitmapSet

                    XBitmap xbm;
                    string  strBitmap = "frame" + ifr + ".bmp";
                    try {
                        xbm = new XBitmap(strBitmap, true);
                    } catch {
                        MessageBox.Show(null, String.Format("Can't load \"{0}\"", strBitmap), "Error");
                        return(false);
                    }
                    XBitmapSet.Add(xbm);

                    // 2. Create a Frame to go with the Bitmap and add it to the appropriate
                    // Strip. If no strip exists, create one.

                    Frame fr = new Frame();
                    fr.BitmapPlacers.Add(new BitmapPlacer());
                    fr.BitmapPlacers[0].XBitmap = xbm;
                    stp[ifr] = fr;

                    bool fDone = false;
                    while (!fDone)
                    {
                        do
                        {
                            iLine++;
                            str = stmr.ReadLine();
                        } while (str == "");                            // skip blank lines

                        if (!ParseNameValueString(str, out strName, out strValue))
                        {
                            MessageBox.Show(null, String.Format("Syntax error on line %d: %s", iLine, str), "Error");
                            return(false);
                        }
                        switch (strName)
                        {
                        case "flags":
                            Debug.Assert(strValue.Trim() == "0");
                            break;

                        case "xCenter":
                            fr.BitmapPlacers[0].X = int.Parse(strValue);
                            break;

                        case "yCenter":
                            fr.BitmapPlacers[0].Y = int.Parse(strValue);
                            break;

                        case "xGrab":
                            fr.SpecialPoint = new Point(int.Parse(strValue) - fr.BitmapPlacers[0].X, fr.SpecialPoint.Y);
                            break;

                        case "yGrab":
                            fr.SpecialPoint = new Point(fr.SpecialPoint.X, int.Parse(strValue) - fr.BitmapPlacers[0].Y);
                            break;

                        case "xWidth":
                            Debug.Assert(int.Parse(strValue.Trim()) == xbm.Width);
                            break;

                        case "yHeight":
                            Debug.Assert(int.Parse(strValue.Trim()) == xbm.Height);
                            fDone = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                // XBitmap encapsulates special filename rules

                astrFileNames = XBitmap.FilterFileNames(astrFileNames);

                // By sorting the filenames we introduce a useful bit of
                // determinism.

                Array.Sort(astrFileNames);

                // Enumerate all the filenames and for each one:

                foreach (string strFile in astrFileNames)
                {
                    // 0. Verify the filename fits the pattern we're expecting

                    string[] astr = strFile.Substring(strFile.LastIndexOf('\\') + 1).Split('_', '.');
                    if (astr.Length != 5)
                    {
                        MessageBox.Show(null, String.Format("File {0} does not match the requisite naming pattern. Skipping and continuing.",
                                                            strFile), "Error");
                        continue;
                    }
                    string strAnimDoc = astr[0];
                    string strStripA  = astr[1];
                    string strStripB  = astr[2];
                    int    ifr        = Convert.ToInt32(astr[3]);

                    // 1. Read the bitmap from it and add it to the Document's XBitmapSet

                    XBitmap xbm;
                    try {
                        xbm = new XBitmap(strFile);
                    } catch {
                        MessageBox.Show(null, String.Format("Can't load \"{0}\"", strFile), "Error");
                        return(false);
                    }
                    XBitmapSet.Add(xbm);

                    // 2. Create a Frame to go with the Bitmap and add it to the appropriate
                    // Strip. If no strip exists, create one.

                    Frame fr = new Frame();
                    fr.BitmapPlacers.Add(new BitmapPlacer());
                    fr.BitmapPlacers[0].XBitmap = xbm;
                    fr.BitmapPlacers[0].X       = xbm.Width / 2;
                    fr.BitmapPlacers[0].Y       = xbm.Height / 2;

                    string strStripName = strStripA + " " + strStripB;
                    Strip  stp          = StripSet[strStripName];
                    if (stp == null)
                    {
                        stp = new Strip(strStripName);
                        StripSet.Add(stp);
                    }
                    stp[ifr] = fr;
                }
            }

            Dirty = true;
            return(true);
        }
Exemplo n.º 12
0
 public int IndexOf(XBitmap xbm)
 {
     return(((IList)this).IndexOf(xbm));
 }
Exemplo n.º 13
0
 public int Add(XBitmap xbm)
 {
     return(((IList)this).Add(xbm));
 }
Exemplo n.º 14
0
 private void lstv_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
 {
     XBitmap[] axbm = new XBitmap[lstv.SelectedItems.Count];
     for (int i = 0; i < lstv.SelectedItems.Count; i++)
         axbm[i] = (XBitmap)lstv.SelectedItems[i].Tag;
     DoDragDrop(axbm, DragDropEffects.All);
 }
Exemplo n.º 15
0
        public bool Import(string[] astrFileNames)
        {
            // Is this a SideWinder framedata.txt file?

            if (astrFileNames.Length == 1 && Path.GetFileName(astrFileNames[0]).ToLower() == "framedata.txt") {

                // Yep, open it up and parse it

                StreamReader stmr = new StreamReader(astrFileNames[0]);
                int iLine = 0;
                string str;

                do {
                    iLine++;
                    str = stmr.ReadLine();
                } while (str == "");	// skip blank lines

                if (str == null) {
                    MessageBox.Show(null, "Reached the end of the file before it was expected", "Error");
                    return false;
                }

                string strName, strValue;
                if (!ParseNameValueString(str, out strName, out strValue)) {
                    MessageBox.Show(null, String.Format("Syntax error on line %d: %s", iLine, str), "Error");
                    return false;
                }

                if (strName != "cfrm") {
                    MessageBox.Show(null, "Expected a 'cfrm =' statement but didn't find it", "Error");
                    return false;
                }

                // Find a unique name for this strip

                int iStrip = 0;
                while (StripSet["strip" + iStrip] != null)
                    iStrip++;
                Strip stp = new Strip("strip" + iStrip);
                StripSet.Add(stp);

                int cfr = int.Parse(strValue);
                for (int ifr = 0; ifr < cfr; ifr++) {

                    // 1. Read the bitmap from it and add it to the Document's XBitmapSet

                    XBitmap xbm;
                    string strBitmap = "frame" + ifr + ".bmp";
                    try {
                        xbm = new XBitmap(strBitmap, true);
                    } catch {
                        MessageBox.Show(null, String.Format("Can't load \"{0}\"", strBitmap), "Error");
                        return false;
                    }
                    XBitmapSet.Add(xbm);

                    // 2. Create a Frame to go with the Bitmap and add it to the appropriate
                    // Strip. If no strip exists, create one.

                    Frame fr = new Frame();
                    fr.BitmapPlacers.Add(new BitmapPlacer());
                    fr.BitmapPlacers[0].XBitmap = xbm;
                    stp[ifr] = fr;

                    bool fDone = false;
                    while (!fDone) {
                        do {
                            iLine++;
                            str = stmr.ReadLine();
                        } while (str == "");	// skip blank lines

                        if (!ParseNameValueString(str, out strName, out strValue)) {
                            MessageBox.Show(null, String.Format("Syntax error on line %d: %s", iLine, str), "Error");
                            return false;
                        }
                        switch (strName) {
                        case "flags":
                            Debug.Assert(strValue.Trim() == "0");
                            break;

                        case "xCenter":
                            fr.BitmapPlacers[0].X = int.Parse(strValue);
                            break;

                        case "yCenter":
                            fr.BitmapPlacers[0].Y = int.Parse(strValue);
                            break;

                        case "xGrab":
                            fr.SpecialPoint = new Point(int.Parse(strValue) - fr.BitmapPlacers[0].X, fr.SpecialPoint.Y);
                            break;

                        case "yGrab":
                            fr.SpecialPoint = new Point(fr.SpecialPoint.X, int.Parse(strValue) - fr.BitmapPlacers[0].Y);
                            break;

                        case "xWidth":
                            Debug.Assert(int.Parse(strValue.Trim()) == xbm.Width);
                            break;

                        case "yHeight":
                            Debug.Assert(int.Parse(strValue.Trim()) == xbm.Height);
                            fDone = true;
                            break;
                        }
                    }
                }

            } else {
                // XBitmap encapsulates special filename rules

                astrFileNames = XBitmap.FilterFileNames(astrFileNames);

                // By sorting the filenames we introduce a useful bit of
                // determinism.

                Array.Sort(astrFileNames);

                // Enumerate all the filenames and for each one:

                foreach (string strFile in astrFileNames) {

                    // 0. Verify the filename fits the pattern we're expecting

                    string[] astr = strFile.Substring(strFile.LastIndexOf('\\') + 1).Split('_', '.');
                    if (astr.Length != 5) {
                        MessageBox.Show(null, String.Format("File {0} does not match the requisite naming pattern. Skipping and continuing.",
                            strFile), "Error");
                        continue;
                    }
                    string strAnimDoc = astr[0];
                    string strStripA = astr[1];
                    string strStripB = astr[2];
                    int ifr = Convert.ToInt32(astr[3]);

                    // 1. Read the bitmap from it and add it to the Document's XBitmapSet

                    XBitmap xbm;
                    try {
                        xbm = new XBitmap(strFile);
                    } catch {
                        MessageBox.Show(null, String.Format("Can't load \"{0}\"", strFile), "Error");
                        return false;
                    }
                    XBitmapSet.Add(xbm);

                    // 2. Create a Frame to go with the Bitmap and add it to the appropriate
                    // Strip. If no strip exists, create one.

                    Frame fr = new Frame();
                    fr.BitmapPlacers.Add(new BitmapPlacer());
                    fr.BitmapPlacers[0].XBitmap = xbm;
                    fr.BitmapPlacers[0].X = xbm.Width / 2;
                    fr.BitmapPlacers[0].Y = xbm.Height / 2;

                    string strStripName = strStripA + " " + strStripB;
                    Strip stp = StripSet[strStripName];
                    if (stp == null) {
                        stp = new Strip(strStripName);
                        StripSet.Add(stp);
                    }
                    stp[ifr] = fr;
                }
            }

            Dirty = true;
            return true;
        }