public void NewStrip()
        {
            Strip stp = new Strip("untitled " + (m_stps.Count + 1).ToString());

            // UNDONE: undo
            m_stps.Add(stp);
            Globals.ActiveStrip = stp;
            m_doc.Dirty         = true;
            RefreshView();
        }
Exemple #2
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);
        }