예제 #1
0
        public PreviewPanel(AnimDoc doc)
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            Globals.ActiveStripChanged += new EventHandler(OnActiveStripChanged);
            Globals.ActiveFrameChanged += new EventHandler(OnActiveFrameChanged);
            trkbScale.Value = Globals.PreviewScale - 1;
        }
예제 #2
0
 static void DumpStats(AnimDoc doc)
 {
     Console.WriteLine("Filename: " + doc.FileName.ToLower());
     Console.WriteLine("FrameRate: " + doc.FrameRate);
     Console.WriteLine("Strip Count: " + doc.StripSet.Count);
     foreach (Strip stp in doc.StripSet) {
         Console.WriteLine("Strip Name: " + stp.Name);
         Console.WriteLine("Frame Count: " + stp.Count);
     }
 }
예제 #3
0
        public PreviewForm(AnimDoc doc)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        public ReplaceColorsForm(AnimDoc doc)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_doc = doc;
        }
예제 #5
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();
        }
예제 #6
0
        public StripsForm(AnimDoc doc)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // My constructor code

            Globals.ActiveDocumentChanged += new EventHandler(OnActiveDocumentChanged);
            Globals.ActiveStripChanged += new EventHandler(OnActiveStripChanged);
            m_doc = doc;
            m_stps = m_doc.StripSet;
            RefreshView();
        }
예제 #7
0
        public StripForm(AnimDoc doc)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // My constructor code

            Globals.ActiveDocumentChanged += new EventHandler(OnActiveDocumentChanged);
            Globals.ActiveStripChanged += new EventHandler(OnActiveStripChanged);
            Globals.TileSizeChanged += new EventHandler(OnTileSizeChanged);
            Globals.StripControl = stpc;
            m_doc = doc;
            ckbToggleGrid.Checked = Globals.GridOn;
            ckbToggleSideColor.Checked = Globals.SideColorMappingOn;
            ckbToggleOriginPoint.Checked = Globals.ShowOriginPoint;
            ckbToggleSpecialPoint.Checked = Globals.ShowSpecialPoint;
            RefreshView();
        }
예제 #8
0
        static Strip MakeHighlightStrip(AnimDoc doc, int cxTile,
                Palette palFixed)
        {
            Strip stpHelp = doc.StripSet["help"];
            if (stpHelp == null) {
                return null;
            }

            // This does a deep copy
            Strip stpHighlight = (Strip)stpHelp.Clone();
            stpHighlight.Name = "highlight";

            // Figure out the scaling. It would be better to pass this in as
            // a parameter.

            Frame frT = stpHighlight[0];
            Rectangle rcUnion = new Rectangle();
            foreach (BitmapPlacer plc in frT.BitmapPlacers) {
                Rectangle rc = new Rectangle();
                rc.X = -plc.X;
                rc.Y = -plc.Y;
                rc.Width = plc.XBitmap.Width;
                rc.Height = plc.XBitmap.Height;
                if (rcUnion.IsEmpty) {
                    rcUnion = rc;
                } else {
                    rcUnion = Rectangle.Union(rcUnion, rc);
                }
            }

            // Needs to be 4 tiles high. Keep aspect ratio

            int cy = rcUnion.Height;
            if (cy < cxTile * 4) {
                cy = cxTile * 4;
            }
            double nScale = 1.0;
            if (cy > rcUnion.Height) {
                nScale = (double)cy / (double)rcUnion.Height;
            }

            // Scale

            if (nScale != 1.0) {
                foreach (Frame fr in stpHighlight) {
                    foreach (BitmapPlacer plc in fr.BitmapPlacers) {
                        plc.XBitmap.Bitmap = TBitmapTools.ScaleBitmap(
                            plc.XBitmap.Bitmap, nScale, palFixed);
                        plc.X = (int)Math.Round(plc.X * nScale);
                        plc.Y = (int)Math.Round(plc.Y * nScale);
                    }

                    Point pt = new Point();
                    pt.X = (int)Math.Round(fr.SpecialPoint.X * nScale);
                    pt.Y = (int)Math.Round(fr.SpecialPoint.Y * nScale);
                    fr.SpecialPoint = pt;
                }
            }

            return stpHighlight;
        }
예제 #9
0
 private void OnActiveDocumentChanged(object obSender, EventArgs e)
 {
     m_doc = Globals.ActiveDocument;
     m_stps = m_doc.StripSet;
     RefreshView();
 }
예제 #10
0
 private void OnActiveDocumentChanged(object obSender, EventArgs e)
 {
     m_doc  = Globals.ActiveDocument;
     m_xbms = m_doc != null ? m_doc.XBitmapSet : null;
     RefreshView();
 }
예제 #11
0
        static void ShrinkWrap(AnimDoc doc)
        {
            Color clrTransparent = Color.FromArgb(0xff, 0, 0xff);
            SolidBrush brTransparent = new SolidBrush(clrTransparent);

            foreach (XBitmap xbm in doc.XBitmapSet) {

                Bitmap bm = xbm.Bitmap;

                // OPT: this could be made faster by doing four independent edge scans

                int xL = bm.Width;
                int xR = 0;
                int yT = bm.Height;
                int yB = 0;
                for (int y = 0; y < bm.Height; y++) {
                    for (int x = 0; x < bm.Width; x++) {
                        Color clr = bm.GetPixel(x, y);
                        if (clr != clrTransparent) {
                            xL = Math.Min(xL, x);
                            xR = Math.Max(xR, x);
                            yT = Math.Min(yT, y);
                            yB = Math.Max(yB, y);
                        }
                    }
                }
                int cx = xR - xL + 1;
                int cy = yB - yT + 1;

                Bitmap bmT = new Bitmap(cx, cy, PixelFormat.Format24bppRgb);
                using (Graphics g = Graphics.FromImage(bmT)) {
                    Rectangle rcT = new Rectangle(xL, yT, cx, cy);
                    g.DrawImage(bm, 0, 0, rcT, GraphicsUnit.Pixel);
                }

                xbm.Bitmap = bmT;

                // Don't need this anymore

                bm.Dispose();

                // If the upper-left corner of the bitmap has been adjusted
                // we must adjust the origins of all Frames referencing it.

                if (xL != 0 || yT != 0) {
                    foreach (Strip stp in doc.StripSet) {
                        foreach (Frame fr in stp) {
                            foreach (BitmapPlacer plc in fr.BitmapPlacers) {
                                if (plc.XBitmap == xbm) {
                                    plc.X -= xL;
                                    plc.Y -= yT;
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #12
0
        static void Scale(AnimDoc doc, double nScale, Palette palFixed, bool fScaleIcon)
        {
            if (nScale >= 1.5)
                doc.Hires = true;

            // If not scaling icon, make a clone of it so it doesn't get scaled,
            // then after scaling set this clone back in.

            Strip stpIcon = doc.StripSet["icon"];
            Strip stpIconClone = null;
            if (!fScaleIcon && stpIcon != null) {
                stpIconClone = (Strip)stpIcon.Clone();
            }

            // Scale all the bitmaps

            foreach (XBitmap xbm in doc.XBitmapSet) {
                // Scale

                xbm.Bitmap = TBitmapTools.ScaleBitmap(xbm.Bitmap, nScale, palFixed);

                // Scale the points in the frames that use this bitmap

                foreach (Strip stp in doc.StripSet) {
                    foreach (Frame fr in stp) {
                        foreach (BitmapPlacer plc in fr.BitmapPlacers) {
                            if (plc.XBitmap == xbm) {
                                plc.X = (int)Math.Round(plc.X * nScale);
                                plc.Y = (int)Math.Round(plc.Y * nScale);
                            }
                        }
                    }
                }
            }

            // Scale all special points too

            foreach (Strip stp in doc.StripSet) {
                foreach (Frame fr in stp) {
                    Point pt = new Point();
                    pt.X = (int)Math.Round(fr.SpecialPoint.X * nScale);
                    pt.Y = (int)Math.Round(fr.SpecialPoint.Y * nScale);
                    fr.SpecialPoint = pt;
                }
            }

            // Put the strip icon back in if it shouldn't be scaled

            if (!fScaleIcon && stpIconClone != null) {
                // Patch in the clone and add the images to the XBitmapSet
                // (they are not added auto-magically).

                doc.StripSet[doc.StripSet.IndexOf(stpIcon)] = stpIconClone;
                foreach (Frame fr in stpIconClone) {
                    foreach (BitmapPlacer plc in fr.BitmapPlacers) {
                        doc.XBitmapSet.Add(plc.XBitmap);
                    }
                }
            }
        }
예제 #13
0
 private void OnActiveDocumentChanged(object obSender, EventArgs e)
 {
     m_doc = Globals.ActiveDocument;
     m_xbms = m_doc != null ? m_doc.XBitmapSet : null;
     RefreshView();
 }
예제 #14
0
 private void OnActiveDocumentChanged(object obSender, EventArgs e)
 {
     m_doc = Globals.ActiveDocument;
     if (m_doc.FileName == null)
         Text = gstrAniMax;
     else
         Text = gstrAniMax + " - " + m_doc.FileName;
 }
예제 #15
0
        public MainForm(string strOpenFileName)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            m_dkm = new DockingManager(this, VisualStyle.IDE);
            Globals.ActiveDocumentChanged += new EventHandler(OnActiveDocumentChanged);
            m_doc = Globals.ActiveDocument;
            Globals.MainForm = this;

            // Create all the "Contents" used to display the various animation components

            m_ctlPreviewPanel = new PreviewPanel(m_doc);
            Globals.PreviewControl = m_ctlPreviewPanel.PreviewControl;
            m_ctlPreviewPanel.Dock = DockStyle.Fill;
            Controls.Add(m_ctlPreviewPanel);
            m_dkm.InnerControl = m_ctlPreviewPanel;

            m_frmStrips = new StripsForm(m_doc);
            Globals.StripsForm = m_frmStrips;
            m_tntStrips = m_dkm.Contents.Add(m_frmStrips, m_frmStrips.Text);
            m_tntStrips.DisplaySize = new Size(ClientSize.Width / 4, ClientSize.Height / 2);
            m_wcStrips = m_dkm.AddContentWithState(m_tntStrips, State.DockLeft);

            m_frmBitmaps = new BitmapsForm(m_doc);
            m_tntBitmaps = m_dkm.Contents.Add(m_frmBitmaps, m_frmBitmaps.Text);
            m_tntBitmaps.DisplaySize = new Size(ClientSize.Width / 4, ClientSize.Height / 2);
            m_dkm.AddContentWithState(m_tntBitmaps, State.DockTop);

            // Add the Bitmaps form to the StripForm's Zone

            m_dkm.AddContentToZone(m_tntBitmaps, m_wcStrips.ParentZone, 1);

            m_frmFrames = new StripForm(m_doc);
            Globals.StripForm = m_frmFrames;
            m_tntFrames = m_dkm.Contents.Add(m_frmFrames, m_frmFrames.Text);
            m_frmFrames.Content = m_tntFrames;
            int cx = ClientSize.Width - (ClientSize.Width / 4);
            int cy = ClientSize.Height / 3;
            m_tntFrames.DisplaySize = new Size(cx, cy);
            m_dkm.AddContentWithState(m_tntFrames, State.DockBottom);

            m_frmCombiner = new CombinerForm();
            m_tntCombiner = m_dkm.Contents.Add(m_frmCombiner, m_frmCombiner.Text);
            m_tntCombiner.DisplaySize = new Size(ClientSize.Width / 2, ClientSize.Height / 2);
            //			m_dkm.AddContentWithState(m_tntCombiner, State.Floating);
            //			m_dkm.HideContent(m_tntCombiner);

            // Do a little wiring

            ((StripControl)Globals.StripControl).FrameOffsetChanged +=
                    new FrameOffsetEventHandler(((PreviewControl)Globals.PreviewControl).OnFrameOffsetChanged);
            ((PreviewControl)Globals.PreviewControl).FrameOffsetChanged +=
                new FrameOffsetEventHandler(((StripControl)Globals.StripControl).OnFrameOffsetChanged);

            // We always have a document around

            if (strOpenFileName == null)
                NewDocument();
            else
                OpenDocument(strOpenFileName);
        }
예제 #16
0
        private void mniImport_Click(object sender, System.EventArgs e)
        {
            if (importFileDialog.ShowDialog() != DialogResult.OK)
                return;

            string[] astrFileNames = importFileDialog.FileNames;

            // If a document doesn't already exist create a new one and show its views

            if (m_doc == Globals.NullDocument) {
                m_doc = new AnimDoc(Globals.TileSize, Globals.FrameRate);
                ShowViews();
            }

            Cursor.Current = Cursors.WaitCursor;
            bool fSuccess = m_doc.Import(astrFileNames);
            Cursor.Current = Cursors.Arrow;
            if (!fSuccess)
                return;

            Globals.ActiveDocument = m_doc;
            Globals.ActiveStrip = m_doc.StripSet[0];
        }
예제 #17
0
        public static AnimDoc Load(string strFileName, Stream stmZamx)
        {
            string strFileNameOrig = strFileName;
            string strExt          = Path.GetExtension(strFileName).ToLower();
            bool   fZip            = strExt == ".zip" || strExt == ".zamx";

            string strCurrentDirSav = null;
            string strTempDir       = null;

            // Remember current dir

            strCurrentDirSav = Directory.GetCurrentDirectory();

            if (fZip)
            {
                // Change current dir to temp dir

                strTempDir = Path.Combine(Path.GetTempPath(), "AniMax_temp_extract_dir");
                Directory.CreateDirectory(strTempDir);
                Directory.SetCurrentDirectory(strTempDir);

                // Extract the .zip to the temp dir

                ZipInputStream zipi = new ZipInputStream(stmZamx != null ? stmZamx : File.OpenRead(strFileName));

                ZipEntry zipe;
                while ((zipe = zipi.GetNextEntry()) != null)
                {
                    string strDir = Path.GetDirectoryName(zipe.Name);
                    if (Path.GetExtension(zipe.Name).ToLower() == ".amx")
                    {
                        strFileName = zipe.Name;
                    }

                    if (strDir != null && strDir != "")
                    {
                        if (!Directory.Exists(strDir))
                        {
                            Directory.CreateDirectory(strDir);
                        }
                    }

                    FileStream stm = File.Create(zipe.Name);
                    byte[]     abT = new byte[zipe.Size];

                    // For some reason due to its implementation, ZipInputStream.Read can return
                    // fewer than the requested number of bytes. Loop until we have them all.

                    while (true)
                    {
                        int cbRead = zipi.Read(abT, 0, abT.Length);
                        if (cbRead <= 0)
                        {
                            break;
                        }
                        stm.Write(abT, 0, cbRead);
                    }

                    stm.Close();
                }

                zipi.Close();

                // Convert filename from, say, c:\ht\data\foo.zip or foo.zamx to foo.amx

                strFileName = Path.GetFileNameWithoutExtension(strFileName) + ".amx";
            }

            FileStream    stmAmx = File.Open(strFileName, FileMode.Open, FileAccess.Read);
            SoapFormatter spfmt  = new SoapFormatter();

            spfmt.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple;
            spfmt.Binder         = new RelaxedSerializationBinder();

            if (!fZip)
            {
                // If .amx being loaded is in a directory other than the current one,
                // change to it so deserialization will find the contained bitmaps in
                // their proper place.

                string strPath = Path.GetDirectoryName(strFileName);
                if (strPath != null && strPath != "")
                {
                    Directory.SetCurrentDirectory(strPath);
                }
            }

            AnimDoc doc = null;

            try {
                doc = (AnimDoc)spfmt.Deserialize(stmAmx);
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString());
                Console.WriteLine(ex);
            }
            stmAmx.Close();

            // Restore current dir (NOTE: can't delete temp dir until it isn't current)

            Directory.SetCurrentDirectory(strCurrentDirSav);

            if (fZip)
            {
                // Delete temp extraction dir and its contents

                Directory.Delete(strTempDir, true);
            }

            if (doc == null)
            {
                return(null);
            }

            doc.m_strFileName = strFileNameOrig;
            return(doc);
        }