Exemplo n.º 1
0
        // ISerializable interface implementation

        private AnimDoc(SerializationInfo seri, StreamingContext stmc)
        {
            m_xbms        = (XBitmapSet)seri.GetValue("Bitmaps", typeof(XBitmapSet));
            m_stps        = (StripSet)seri.GetValue("Strips", typeof(StripSet));
            m_msFrameRate = seri.GetInt32("FrameRate");

            try {
                bool fHires = seri.GetBoolean("Hires");
                if (fHires)
                {
                    m_nTileSize = 24;
                }
                else
                {
                    m_nTileSize = 16;
                }
            } catch {
                m_nTileSize = -1;
            }

            if (m_nTileSize == -1)
            {
                m_nTileSize = seri.GetInt32("TileSize");
            }
        }
Exemplo n.º 2
0
        //

        public AnimDoc(int nTileSize, int cmsFrameRate)
        {
            m_nTileSize   = nTileSize;
            m_msFrameRate = cmsFrameRate;
            m_xbms        = new XBitmapSet();
            m_stps        = new StripSet();
            m_fDirty      = true;
        }
Exemplo n.º 3
0
        public BitmapsForm(AnimDoc doc)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // My constructor code

            Globals.ActiveDocumentChanged += new EventHandler(OnActiveDocumentChanged);
            m_doc = doc;
            if (m_doc != null)
            {
                m_xbms = doc.XBitmapSet;
            }
            RefreshView();
        }
Exemplo n.º 4
0
 private void OnActiveDocumentChanged(object obSender, EventArgs e)
 {
     m_doc  = Globals.ActiveDocument;
     m_xbms = m_doc != null ? m_doc.XBitmapSet : null;
     RefreshView();
 }
Exemplo n.º 5
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);
        }