Beispiel #1
0
        // ISerializable interface implementation

        private StripSet(SerializationInfo seri, StreamingContext stmc)
        {
            for (int i = 0; i < seri.MemberCount; i++)
            {
                Strip stp = (Strip)seri.GetValue(i.ToString(), typeof(Strip));
                Add(stp);
            }
        }
        public StripProperties(Strip stp)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            prgStrip.SelectedObject = stp;
        }
        public StripProperties(Strip stp)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            prgStrip.SelectedObject = stp;
        }
 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();
 }
        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();
        }
        public void ShowStripProperties(Strip stp)
        {
            Form frm = new StripProperties(stp);
            if (frm.ShowDialog(this) == DialogResult.Cancel)
                return;

            // UNDONE: animation interval must be updated if Strip.DefHoldCount changes
            //			if (stp == stpc.Strip)
            //				tmrAnim.Interval = 80 + (80 * stpc.Strip.DefHoldCount);
        }
Beispiel #7
0
 private void InsertFrame(Strip stp, int ifr, Frame fr, bool fUndoable)
 {
     if (fUndoable)
     {
         UndoManager.AddUndo(new UndoDelegate(UndoInsert), new Object [] { stp, ifr, stp.ActiveFrame });
     }
     stp.Insert(ifr, fr);
     Globals.ActiveDocument.Dirty = true;
     Invalidate();
     RecalcScrollbar();
 }
Beispiel #8
0
        public void ShowStripProperties(Strip stp)
        {
            Form frm = new StripProperties(stp);

            if (frm.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            // UNDONE: animation interval must be updated if Strip.DefHoldCount changes
//			if (stp == stpc.Strip)
//				tmrAnim.Interval = 80 + (80 * stpc.Strip.DefHoldCount);
        }
Beispiel #9
0
        public object Clone()
        {
            Strip stpNew = new Strip(m_strName);

            for (int i = 0; i < this.Count; i++)
            {
                stpNew.Add((Frame)this[i].Clone());
            }
            stpNew.m_ifrActive = m_ifrActive;
            stpNew.m_cfrActive = m_cfrActive;
            stpNew.m_cHold     = m_cHold;
            return(stpNew);
        }
Beispiel #10
0
 private void DeleteFrame(Strip stp, int ifr, bool fUndoable)
 {
     if (fUndoable)
     {
         UndoManager.AddUndo(new UndoDelegate(UndoDelete), new object[] { stp, ifr, stp[ifr], stp.ActiveFrame });
     }
     stp.RemoveAt(ifr);
     Globals.ActiveDocument.Dirty = true;
     if (stp.ActiveFrame >= stp.Count)
     {
         stp.ActiveFrame = stp.Count - 1;
     }
     RecalcScrollbar();
 }
Beispiel #11
0
        private void OnActiveStripChanged(object obSender, EventArgs e)
        {
            if (m_stpActive == Globals.ActiveStrip)
            {
                return;
            }

            m_stpActive = Globals.ActiveStrip;
            foreach (ListViewItem lvi in lstv.Items)
            {
                if (lvi.Tag == Globals.ActiveStrip)
                {
                    lvi.Selected = true;
                    break;
                }
            }
        }
Beispiel #12
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;

            Strip stp = (Strip)lstv.Items[e.Item].Tag;

            // No change or an invalid change

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

            stp.Name    = e.Label;
            m_doc.Dirty = true;
        }
        private void SelectStrip(int i, Strip stp, int ifr)
        {
            // Deselect any selected strip's FrameControl

            for (int j = 0; j < m_astp.Length; j++)
            {
                if (m_afrc[j] != null)
                {
                    m_afrc[j].BorderColor = Color.Black;
                }
            }

            m_iSelected = i;
            m_afrc[m_iSelected].BorderColor = Color.Red;

            m_astp[m_iSelected]       = stp;
            m_aifr[m_iSelected]       = stp == null ? 0 : stp.ActiveFrame;
            m_afrc[m_iSelected].Frame = stp == null ? null : stp.Count == 0 ? null : stp[stp.ActiveFrame];
            m_albl[m_iSelected].Text  = stp == null ? "<empty>" : stp.Name;
            Invalidate();
        }
Beispiel #14
0
        private void tmrAnim_Tick(object sender, System.EventArgs e)
        {
            Strip stp = Globals.ActiveStrip;

            if (stp == null)
            {
                return;
            }

            int ifr = stp.ActiveFrame + 1;

            if (ifr >= stp.Count)
            {
                ifr = 0;
                if (!m_fLoop)
                {
                    tmrAnim.Stop();
                }
            }
            tmrAnim.Interval = (stp[ifr].HoldCount * 80) + (80 * (Globals.ActiveStrip.DefHoldCount + 1));
            stp.ActiveFrame  = ifr;
        }
Beispiel #15
0
        private void PreviewControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            m_fDragging = false;

            if (m_fFrameRecentering)
            {
                Cursor = Cursors.Default;
                m_fFrameRecentering = false;
            }

            if (m_fRepositionBitmaps)
            {
                m_fRepositionBitmaps = false;
                Strip stp = Globals.ActiveStrip;

                UndoManager.BeginGroup();
                for (int ifr = 0; ifr < stp.Count; ifr++)
                {
                    if (ifr != stp.ActiveFrame)
                    {
                        if (stp[ifr].BitmapPlacers.Count > 0)
                        {
                            UndoManager.AddUndo(new UndoDelegate(UndoSetBitmapPosition),
                                                new Object[] { stp[ifr].BitmapPlacers[0], m_aptPreDragBitmap[ifr].X, m_aptPreDragBitmap[ifr].Y });
                        }
                    }
                }
                UndoManager.AddUndo(new UndoDelegate(UndoSetBitmapPosition),
                                    new Object[] { m_plcSelected, m_aptPreDragBitmap[stp.ActiveFrame].X, m_aptPreDragBitmap[stp.ActiveFrame].Y });
                UndoManager.EndGroup();
            }

            if (m_fSetSpecialPoint)
            {
                m_fSetSpecialPoint = false;
                UndoManager.AddUndo(new UndoDelegate(UndoSetSpecialPoint),
                                    new Object[] { Globals.ActiveStrip[Globals.ActiveFrame], m_ptPreSetSpecialPoint.X, m_ptPreSetSpecialPoint.Y });
            }
        }
Beispiel #16
0
        private void mniDelete_Click(object sender, System.EventArgs e)
        {
            Strip stp = (Strip)lstv.SelectedItems[0].Tag;
            int   i   = m_stps.IndexOf(stp);

            // UNDONE: undo
            m_stps.RemoveAt(i);
            lstv.Items.Remove(lstv.SelectedItems[0]);
            m_doc.Dirty = true;

            // Select a new Strip to be active

            i = Math.Min(i, m_stps.Count - 1);
            if (i >= 0)
            {
                Globals.ActiveStrip = m_stps[i];
            }
            else
            {
                Globals.ActiveStrip = null;
            }
        }
 public int IndexOf(Strip stp)
 {
     return ((IList)this).IndexOf(stp);
 }
 // For whatever reason the designers of CollectionBase decided to implement
 // IList.Add as 'explicit' which means it is effectively hidden from  users
 // of derived classes. So we must add our own Add method which does have the
 // benefit of being type-safe (possibly why they hid IList.Add in the first place)
 public int Add(Strip stp)
 {
     return ((IList)this).Add(stp);
 }
Beispiel #19
0
 public int IndexOf(Strip stp)
 {
     return(((IList)this).IndexOf(stp));
 }
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (Globals.ActiveStrip == null || Globals.ActiveStrip.Count == 0)
            {
                e.Graphics.FillRectangle(new SolidBrush(BackColor), e.ClipRectangle);
                return;
            }

            Frame.DrawArgs drwa = new Frame.DrawArgs();
            drwa.clrBackground     = BackColor;
            drwa.fDrawBackground   = true;
            drwa.fMapSideColors    = Globals.SideColorMappingOn;
            drwa.fShowGrid         = Globals.GridOn;
            drwa.cxGrid            = Globals.GridWidth;
            drwa.cyGrid            = Globals.GridHeight;
            drwa.fShowOrigin       = Globals.ShowOriginPoint;
            drwa.fShowSpecialPoint = Globals.ShowSpecialPoint;
            drwa.nScale            = Globals.PreviewScale;

            Rectangle rcClient = new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height);

            Graphics g = e.Graphics;

            int xCenter = rcClient.Width / 2;
            int yCenter = rcClient.Height / 2;

            int cxT      = ((rcClient.Width + drwa.nScale - 1) / drwa.nScale) + 2;
            int cyT      = ((rcClient.Height + drwa.nScale - 1) / drwa.nScale) + 2;
            int xCenterT = cxT / 2;
            int yCenterT = cyT / 2;

            // Create a temporary bitmap for compositing the grid, frames, origin indicator, etc into

            using (Bitmap bmT = new Bitmap(cxT, cyT)) {
                Point ptSpecial = new Point(0, 0);

                for (int i = 0; i < m_astp.Length; i++)
                {
                    // Draw the frame and its indicators (grid, center point, special point, etc)

                    Strip stp = m_astp[i];
                    if (stp == null)
                    {
                        continue;
                    }

                    Frame fr       = stp[m_aifr[i]];
                    Point ptOffset = new Point(m_ptOffset.X + ptSpecial.X, m_ptOffset.Y + ptSpecial.Y);
                    fr.DrawUnscaled(bmT, cxT, cyT, drwa, ptOffset);

                    drwa.fDrawBackground = false;
                    drwa.fShowGrid       = false;

                    ptSpecial = fr.SpecialPoint;
                }

                // 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(bmT, rcClient.Left - ((xCenterT * drwa.nScale) - xCenter),
                            rcClient.Top - ((yCenterT * drwa.nScale) - yCenter),
                            cxT * drwa.nScale, cyT * drwa.nScale);

                // Restore the Graphics' state

                g.PixelOffsetMode   = pomOld;
                g.InterpolationMode = imOld;
            }
        }
Beispiel #21
0
        private void lstv_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            string[] astrFiles = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (astrFiles != null)
            {
                if (astrFiles.Length == 1)
                {
                    ((MainForm)Globals.MainForm).CloseAndOpenDocument(astrFiles[0]);
                }
                else
                {
                    MessageBox.Show(this, "Please, only drop one animation file.", "Too many files dropped", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
#if false
            XBitmap[] axbm = e.Data.GetData(typeof(XBitmap[])) as XBitmap[];
            if (axbm == null)
            {
                return;
            }

            // Use the standard file naming convention to break the bitmaps down into
            // animations (e.g., *_fire_*_*), a single track (e.g., track 1), and a set
            // of TSprite keys (e.g., *_*_d_n)

            foreach (XBitmap xbm in axbm)
            {
                string   strFile = xbm.FileName;
                string[] astr    = strFile.Substring(strFile.LastIndexOf('\\') + 1).Split('_', '.');
                if (astr.Length != 5)
                {
                    MessageBox.Show(this, String.Format("Warning: file {0} does not match the requisite naming pattern", strFile),
                                    "AniMax");
                    continue;
                }

                // Find the appropriate animation

                Strip  stp     = null;
                Frame  fr      = null;
                string strName = astr[1] + " " + astr[2];
                foreach (Strip stpT in m_stps)
                {
                    if (stpT.Name == strName)
                    {
                        stp = stpT;
                        fr  = stp[0];
                        break;
                    }
                }

                // If one isn't found, create a new stpmation and empty track

                if (stp == null)
                {
                    stp = new Strip(strName);
                    m_stps.Add(stp);
                    tspr = new TSprite("track 1");
                    stp.Add(tspr);
                }

                Sprite spr = new Sprite(xbm, 0, 0);
                Time   t   = 0;
                if (tspr.End != Time.tUndefined)
                {
                    t = tspr.End + m_doc.FrameRate;
                }
                tspr.SetValue(t, spr);
            }

            m_doc.Dirty = true;
            RefreshView();
#endif
        }
 private void DeleteFrame(Strip stp, int ifr, bool fUndoable)
 {
     if (fUndoable)
         UndoManager.AddUndo(new UndoDelegate(UndoDelete), new object[] { stp, ifr, stp[ifr], stp.ActiveFrame});
     stp.RemoveAt(ifr);
     Globals.ActiveDocument.Dirty = true;
     if (stp.ActiveFrame >= stp.Count)
         stp.ActiveFrame = stp.Count - 1;
     RecalcScrollbar();
 }
Beispiel #23
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);
        }
 private void InsertFrame(Strip stp, int ifr, Frame fr, bool fUndoable)
 {
     if (fUndoable)
         UndoManager.AddUndo(new UndoDelegate(UndoInsert), new Object [] { stp, ifr, stp.ActiveFrame });
     stp.Insert(ifr, fr);
     Globals.ActiveDocument.Dirty = true;
     Invalidate();
     RecalcScrollbar();
 }
Beispiel #25
0
 public object Clone()
 {
     Strip stpNew = new Strip(m_strName);
     for (int i = 0; i < this.Count; i++) {
         stpNew.Add((Frame)this[i].Clone());
     }
     stpNew.m_ifrActive = m_ifrActive;
     stpNew.m_cfrActive = m_cfrActive;
     stpNew.m_cHold = m_cHold;
     return stpNew;
 }
        private void SelectStrip(int i, Strip stp, int ifr)
        {
            // Deselect any selected strip's FrameControl

            for (int j = 0; j < m_astp.Length; j++) {
                if (m_afrc[j] != null)
                    m_afrc[j].BorderColor = Color.Black;
            }

            m_iSelected = i;
            m_afrc[m_iSelected].BorderColor = Color.Red;

            m_astp[m_iSelected] = stp;
            m_aifr[m_iSelected] = stp == null ? 0 : stp.ActiveFrame;
            m_afrc[m_iSelected].Frame = stp == null ? null : stp.Count == 0 ? null : stp[stp.ActiveFrame];
            m_albl[m_iSelected].Text = stp == null ? "<empty>" : stp.Name;
            Invalidate();
        }
Beispiel #27
0
        // For whatever reason the designers of CollectionBase decided to implement
        // IList.Add as 'explicit' which means it is effectively hidden from  users
        // of derived classes. So we must add our own Add method which does have the
        // benefit of being type-safe (possibly why they hid IList.Add in the first place)

        public int Add(Strip stp)
        {
            return(((IList)this).Add(stp));
        }
Beispiel #28
0
        private void PreviewControl_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!m_fDragging)
            {
                return;
            }

            Strip stp = Globals.ActiveStrip;

            if (stp == null)
            {
                return;
            }

            if (m_fFrameRecentering)
            {
                m_ptOffset = m_ptInitialOffset;
                Point ptNew = FxyFromWxy(new Point(e.X, e.Y));
                m_ptOffset.X = m_ptInitialOffset.X + (ptNew.X - m_ptDragStart.X);
                m_ptOffset.Y = m_ptInitialOffset.Y + (ptNew.Y - m_ptDragStart.Y);
                Invalidate();
                Update();

                // Notify anyone who cares that we've changed the Frame offset

                if (FrameOffsetChanged != null)
                {
                    FrameOffsetChanged(this, new FrameOffsetEventArgs(m_ptOffset.X, m_ptOffset.Y));
                }
                return;
            }

            switch (m_mode)
            {
            case PreviewControlMode.SetSpecialPoint:
            {
                Point ptT = FxyFromWxy(new Point(e.X, e.Y));
                Frame fr  = stp[Globals.ActiveFrame];
                fr.SpecialPoint = ptT;
                Globals.ActiveDocument.Dirty = true;
                Globals.OnFrameContentChanged(this, new EventArgs());
            }
            break;

            case PreviewControlMode.RepositionBitmap:
            {
                Point ptT = FxyFromWxy(new Point(e.X, e.Y));
                int   ipl = stp[Globals.ActiveFrame].BitmapPlacers.
                            Index(m_plcSelected);
                int ifr;
                int cfr;
                if (m_fAllFrames)
                {
                    ifr = 0;
                    cfr = stp.Count;
                }
                else
                {
                    ifr = Globals.ActiveFrame;
                    cfr = Globals.ActiveFrameCount;
                }

                for (int ifrT = ifr; ifrT < ifr + cfr; ifrT++)
                {
                    int iplT = ipl;
                    if (iplT >= stp[ifrT].BitmapPlacers.Count)
                    {
                        iplT = 0;
                    }
                    BitmapPlacer plc = stp[ifrT].BitmapPlacers[iplT];
                    plc.X = m_aptPreDragBitmap[ifrT].X + m_ptDragStart.X -
                            ptT.X;
                    plc.Y = m_aptPreDragBitmap[ifrT].Y + m_ptDragStart.Y -
                            ptT.Y;
                }
                m_fRepositionBitmaps         = true;
                Globals.ActiveDocument.Dirty = true;
                Globals.OnFrameContentChanged(this, new EventArgs());
            }
            break;
            }
        }
Beispiel #29
0
        private void PreviewControl_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Strip stp = Globals.ActiveStrip;

            if (stp == null)
            {
                return;
            }

            if (m_fSpaceDown)
            {
                m_fFrameRecentering = true;
                m_fDragging         = true;
                m_ptDragStart       = FxyFromWxy(new Point(e.X, e.Y));
                m_ptInitialOffset   = m_ptOffset;
                Cursor = Globals.GrabCursor;
                return;
            }

            switch (m_mode)
            {
            case PreviewControlMode.SetSpecialPoint:
            {
                m_fDragging        = true;
                m_fSetSpecialPoint = true;
                Point ptT = FxyFromWxy(new Point(e.X, e.Y));
                Frame fr  = stp[Globals.ActiveFrame];
                m_ptPreSetSpecialPoint       = fr.SpecialPoint;
                fr.SpecialPoint              = ptT;
                Globals.ActiveDocument.Dirty = true;
                Globals.OnFrameContentChanged(this, new EventArgs());
            }
            break;

            case PreviewControlMode.RepositionBitmap:
            {
                BitmapPlacer plc = HitTest(e.X, e.Y);
                if (plc == null)
                {
                    break;
                }
                m_plcSelected = plc;

                m_fDragging  = true;
                m_fAllFrames = (ModifierKeys & Keys.Shift) != 0;

                // UNDONE: across frame operations don't really make sense until we have Tracks

                m_aptPreDragBitmap = new Point[stp.Count];
                for (int ifr = 0; ifr < stp.Count; ifr++)
                {
                    Frame fr = stp[ifr];
                    if (fr.BitmapPlacers.Count > 0)
                    {
                        m_aptPreDragBitmap[ifr].X = fr.BitmapPlacers[0].X;
                        m_aptPreDragBitmap[ifr].Y = fr.BitmapPlacers[0].Y;
                    }
                }

                // Special handling for active frame

                m_aptPreDragBitmap[stp.ActiveFrame].X = m_plcSelected.X;
                m_aptPreDragBitmap[stp.ActiveFrame].Y = m_plcSelected.Y;

                m_ptDragStart = FxyFromWxy(new Point(e.X, e.Y));
            }
            break;
            }
        }
        private void lstv_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            string[] astrFiles = e.Data.GetData(DataFormats.FileDrop) as string[];
            if (astrFiles != null) {
                if (astrFiles.Length == 1)
                    ((MainForm)Globals.MainForm).CloseAndOpenDocument(astrFiles[0]);
                else
                    MessageBox.Show(this, "Please, only drop one animation file.", "Too many files dropped", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            #if false
            XBitmap[] axbm = e.Data.GetData(typeof(XBitmap[])) as XBitmap[];
            if (axbm == null)
                return;

            // Use the standard file naming convention to break the bitmaps down into
            // animations (e.g., *_fire_*_*), a single track (e.g., track 1), and a set
            // of TSprite keys (e.g., *_*_d_n)

            foreach (XBitmap xbm in axbm) {
                string strFile = xbm.FileName;
                string[] astr = strFile.Substring(strFile.LastIndexOf('\\') + 1).Split('_', '.');
                if (astr.Length != 5) {
                    MessageBox.Show(this, String.Format("Warning: file {0} does not match the requisite naming pattern", strFile),
                            "AniMax");
                    continue;
                }

                // Find the appropriate animation

                Strip stp = null;
                Frame fr = null;
                string strName = astr[1] + " " + astr[2];
                foreach (Strip stpT in m_stps) {
                    if (stpT.Name == strName) {
                        stp = stpT;
                        fr = stp[0];
                        break;
                    }
                }

                // If one isn't found, create a new stpmation and empty track

                if (stp == null) {
                    stp = new Strip(strName);
                    m_stps.Add(stp);
                    tspr = new TSprite("track 1");
                    stp.Add(tspr);
                }

                Sprite spr = new Sprite(xbm, 0, 0);
                Time t = 0;
                if (tspr.End != Time.tUndefined)
                    t = tspr.End + m_doc.FrameRate;
                tspr.SetValue(t, spr);
            }

            m_doc.Dirty = true;
            RefreshView();
            #endif
        }
        private void OnActiveStripChanged(object obSender, EventArgs e)
        {
            if (m_stpActive == Globals.ActiveStrip)
                return;

            m_stpActive = Globals.ActiveStrip;
            foreach (ListViewItem lvi in lstv.Items) {
                if (lvi.Tag == Globals.ActiveStrip) {
                    lvi.Selected = true;
                    break;
                }
            }
        }
Beispiel #32
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;
        }