public void Insert(int ifr, Frame fr) { ((IList)this).Insert(ifr, fr); }
// Deep copy public object Clone() { Frame fr = new Frame(); fr.m_cHold = m_cHold; fr.m_ptSpecial = new Point(m_ptSpecial.X, m_ptSpecial.Y); fr.m_plcl = (BitmapPlacerList)m_plcl.Clone(); return fr; }
public int IndexOf(Frame fr) { return ((IList)this).IndexOf(fr); }
public int Add(Frame fr) { return ((IList)this).Add(fr); }
private void StripControl_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { tmrScroll.Stop(); Focus(); // Drop from Bitmaps window XBitmap[] axbm = e.Data.GetData(typeof(XBitmap[])) as XBitmap[]; if (axbm != null) { if (m_stp == null) ((StripsForm)Globals.StripsForm).NewStrip(); int ifrFirst = m_ifrInsertionPoint; int ifrInsert = ifrFirst; UndoManager.BeginGroup(); foreach (XBitmap xbm in axbm) { Frame frT = new Frame(); frT.BitmapPlacers.Add(new BitmapPlacer()); frT.BitmapPlacers[0].XBitmap = xbm; frT.BitmapPlacers[0].X = xbm.Width / 2; frT.BitmapPlacers[0].Y = xbm.Height / 2; InsertFrame(m_stp, ifrInsert++, frT, true); } UndoManager.EndGroup(); m_stp.ActiveFrame = ifrFirst; } // Drop from Strip window // UNDONE: wrap the Frame in a data structure that includes Strip and ifr // and clean this up Frame fr = e.Data.GetData(typeof(Frame)) as Frame; if (fr != null) { if (m_ifrInsertionPoint != -1) { if ((ModifierKeys & Keys.Control) == 0) { // Don't try to move the frame immediately before or after itself if (m_ifrInsertionPoint == m_stp.ActiveFrame || m_ifrInsertionPoint == m_stp.ActiveFrame + 1) { m_ifrInsertionPoint = -1; Invalidate(); return; } } UndoManager.BeginGroup(); // Insert at new place int ifrOld = m_stp.ActiveFrame; fr = (Frame)m_stp[ifrOld].Clone(); InsertFrame(m_stp, m_ifrInsertionPoint, fr, true); m_stp.ActiveFrame = m_ifrInsertionPoint; // If the control key is held the frame is duplicated, not moved if ((ModifierKeys & Keys.Control) == 0) { // Remove from old place if (m_ifrInsertionPoint <= ifrOld) ifrOld++; DeleteFrame(m_stp, ifrOld, true); } UndoManager.EndGroup(); } } m_ifrInsertionPoint = -1; Invalidate(); }
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(); }
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; }