コード例 #1
0
ファイル: MainWindow.cs プロジェクト: onidenki/TO-Toolbox
        // Animation selector
        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = listBox3.SelectedIndex;

            if (id >= 0 && id < nril.GetAnimationsCount())
            {
                trackBar1.Minimum = 0;

                NRILoader.Animation anim = nril.GetAnimations(id);
                trackBar1.Maximum = anim.frames.Count;

                DisplayAnimation(id, 0);
            }
        }
コード例 #2
0
ファイル: MainWindow.cs プロジェクト: onidenki/TO-Toolbox
        // Open NRI
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "NRI files (*.nri;*.bac)|*.nri;*.bac|All files|*.*";
            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Can use GetFileNameWithoutExtension, but .bac/.nri would be indifferentiable then
                nriName = Path.GetFileName(ofd.FileName);

                if (nril.Load(ofd.FileName))
                {
                    if (nril.status != "")
                    {
                        MessageBox.Show(nril.status);
                    }

                    // Populate file list
                    this.listBox1.Items.Clear();
                    int fileCount = nril.GetFileCount();
                    for (int i = 0; i < fileCount; i++)
                    {
                        this.listBox1.Items.Add("Image" + (i + 1));
                    }

                    // Popuate animation list
                    this.listBox3.Items.Clear();
                    int animCount = nril.GetAnimationsCount();
                    for (int i = 0; i < animCount; i++)
                    {
                        NRILoader.Animation anim = nril.GetAnimations(i);
                        this.listBox3.Items.Add("" + (i + 1) + ". " + anim.name);
                    }
                }
                else
                {
                    MessageBox.Show("Unable to load NRI file");
                }
            }
        }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: onidenki/TO-Toolbox
        // Displays an animation
        private void DisplayAnimation(int id, int frameid)
        {
            if (id >= 0 && id < nril.GetAnimationsCount())
            {
                NRILoader.Animation anim = nril.GetAnimations(id);

                this.label2.Text = anim.name + " (" + anim.frames.Count + " frames)";
                if (frameid >= 0 && frameid < anim.frames.Count)
                {
                    // Render animation
                    NRILoader.Frame frame = anim.frames[frameid];
                    // TODO: Adjusted to fit entire animation
                    int canvaswidth  = 500;
                    int canvasheight = 500;

                    // Setup chroma-key maps
                    ColorMap cmap1 = new ColorMap();
                    cmap1.OldColor = Color.FromArgb(0, 255, 0);
                    cmap1.NewColor = Color.Transparent;
                    ColorMap cmap2 = new ColorMap();
                    cmap2.OldColor = Color.FromArgb(255, 0, 255);
                    cmap2.NewColor = Color.Transparent;
                    ImageAttributes imageAttributes = new ImageAttributes();
                    imageAttributes.SetRemapTable(new ColorMap[] { cmap1, cmap2 }, ColorAdjustType.Bitmap);

                    Bitmap   canvas      = new Bitmap(canvaswidth, canvasheight);
                    Graphics g           = Graphics.FromImage(canvas);
                    int      baseoffsetx = canvaswidth / 2;
                    int      baseoffsety = canvasheight / 2;

                    // Draw guide lines (for debugging)
                    Pen gridPen = new Pen(Color.Black);
                    gridPen.Width = 1;
                    // Grid center is at (baseoffsetx, baseoffsety)
                    g.DrawLine(gridPen, 0, baseoffsety, baseoffsetx * 2, baseoffsety);
                    g.DrawLine(gridPen, baseoffsetx, 0, baseoffsetx, baseoffsety * 2);

                    for (int i = 0; i < frame.planes.Count; i++)
                    {
                        // Draw the requested image
                        NRILoader.FramePlane plane = frame.planes[i];
                        int bitmapid = plane.bitmapid;

                        // Some animations appear to have negative ids specfied (need more investigation)
                        if (bitmapid >= 0 && bitmapid < nril.GetFileCount())
                        {
                            Stream bmpstream = nril.GetFile(bitmapid);
                            Bitmap bmp       = new Bitmap(bmpstream);

                            // Perform image flips
                            switch (plane.reverseflag)
                            {
                            case 1:
                                bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                                break;

                            case 2:
                                bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                                break;

                            case 3:
                                bmp.RotateFlip(RotateFlipType.RotateNoneFlipXY);
                                break;
                            }

                            int x = plane.x + baseoffsetx;
                            int y = plane.y + baseoffsety;
                            g.DrawImage(bmp,
                                        new Rectangle(x, y, bmp.Width, bmp.Height),
                                        0, 0, bmp.Width, bmp.Height
                                        , GraphicsUnit.Pixel, imageAttributes);
                            bmpstream.Close();
                        }
                        else
                        {
                            MessageBox.Show("Unable to load " + bitmapid);
                        }
                    }

                    // Display to picture box
                    this.pictureBox2.Image = canvas;
                }
            }
        }