示例#1
0
        private void btnAnimStart_Click(object sender, EventArgs e)
        {
            btnAnimStop.Enabled  = true;
            btnAnimStart.Enabled = false;
            btnAnimNext.Enabled  = false;

            int index = cboEntry.SelectedIndex;

            ms = GfxBattleBg.Masters[index];

            for (int i = 0; i < 2; i++)
            {
                try
                {
                    bgAlphas[i] = int.Parse(txtAlpha[i].Text);
                }
                catch
                {
                    txtAlpha[i].SelectAll();
                    return;
                }

                bgLayers[i]  = cboLayer[i].SelectedIndex;
                srcBitmap[i] = GfxBattleBg.GetBg(index, i);
                if (changed)
                {
                    srcPal[i] = (MPalette)GfxBattleBg.Bgs[bgLayers[i]].Palette.Clone();
                }
                srcBd[i] = srcBitmap[i].LockBits(ImageLockMode.ReadWrite);

                bufBitmap[i] = new Bitmap(256, 256, PixelFormat.Format8bppIndexed);
                bufBd[i]     = bufBitmap[i].LockBits(ImageLockMode.ReadWrite);
                buf[i]       = (byte *)bufBd[i].Scan0;

                dstBitmap[i] = new Bitmap(256, 256, PixelFormat.Format8bppIndexed);

                // Apply the alphas
                alphaAttr[i] = new ImageAttributes();

                float a = bgAlphas[i];
                alphaMatrix[i]          = new ColorMatrix();
                alphaMatrix[i].Matrix33 = a / 16.0f;

                alphaAttr[i].SetColorMatrix(alphaMatrix[i], ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            }

            if (changed)
            {
                changed = false;
                t       = 0;
            }

            pAnimation.Visible = true;
            tm.Start();
        }
示例#2
0
        private void cboShowLayer_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (loading2)
            {
                return;
            }

            int bg = cboBg.SelectedIndex;

            if (bg == -1)
            {
                pBg.Image = null;
            }
            else
            {
                pBg.Image = GfxBattleBg.GetBg(bg, cboShowLayer.SelectedIndex);
            }
        }
示例#3
0
        public frmBattleBgEntryEditor()
        {
            InitializeComponent();

            pAnimation.Image   = canvas;
            pAnimation.Visible = false;

            // Draw the layer stuff
            for (int i = 0; i < 2; i++)
            {
                var p = new PictureBox();
                p.SizeMode = PictureBoxSizeMode.Normal;
                p.Width    = p.Height = 128;
                p.Left     = 15;
                p.Top      = 39 + (134 * i);
                p.Visible  = true;
                p.Paint   += (s, e) =>
                {
                    e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    e.Graphics.Clear(this.BackColor);
                    e.Graphics.DrawImage((s as PictureBox).Image, new Rectangle(0, 0, 128, 128),
                                         0, 0, 256, 256, GraphicsUnit.Pixel);
                };

                this.Controls.Add(p);
                pLayer[i] = p;

                var ll = new LinkLabel();
                ll.AutoSize     = true;
                ll.Text         = "Layer " + (i + 1).ToString();
                ll.Left         = 149;
                ll.Top          = 42 + (134 * i);
                ll.Visible      = true;
                ll.Tag          = i;
                ll.LinkClicked += (s, e) =>
                {
                    int index = (int)((LinkLabel)s).Tag;
                    ModuleArbiter.ShowSelect(typeof(frmBattleBgLayerEditor), cboLayer[index].SelectedIndex);
                };

                this.Controls.Add(ll);
                lblLayer[i] = ll;

                var c = new ComboBox();
                c.DropDownStyle = ComboBoxStyle.DropDownList;
                c.Width         = 128;
                c.Height        = 21;
                c.Left          = 200;
                c.Top           = p.Top;
                c.Visible       = true;
                c.Tag           = i;
                for (int j = 0; j < GfxBattleBg.Entries; j++)
                {
                    c.Items.Add(j.ToString("X3"));
                }
                c.SelectedIndexChanged += (s, e) =>
                {
                    if (loading2)
                    {
                        return;
                    }
                    var cb    = s as ComboBox;
                    int index = (int)cb.Tag;
                    pLayer[index].Image = GfxBattleBg.GetLayer(cb.SelectedIndex);
                };

                this.Controls.Add(c);
                cboLayer[i] = c;

                var l = new Label();
                l.AutoSize = true;
                l.Text     = "Alpha";
                l.Left     = ll.Left;
                l.Top      = ll.Top + 28;
                l.Visible  = true;

                this.Controls.Add(l);
                lblAlpha[i] = l;

                var t = new TextBox();
                t.Width   = 64;
                t.Height  = 20;
                t.Left    = c.Left;
                t.Top     = l.Top - 3;
                t.Visible = true;

                this.Controls.Add(t);
                txtAlpha[i] = t;
            }

            // Load the entry list
            loading = true;
            for (int i = 0; i < GfxBattleBg.MasterEntries; i++)
            {
                cboEntry.Items.Add(i.ToString("X2"));
            }
            loading = false;
            cboEntry.SelectedIndex = 0;

            // Setup the animation timer
            tm.Mode       = Multimedia.TimerMode.Periodic;
            tm.Period     = 16;
            tm.Resolution = 1;
            tm.Tick      += (s, ee) =>
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new MethodInvoker(UpdateFrame));
                }
                else
                {
                    UpdateFrame();
                }

                t++;
            };
        }
示例#4
0
        private void pAnimation_Paint(object sender, PaintEventArgs e)
        {
            for (int i = 0; i < 2; i++)
            {
                if (bgLayers[i] == 0)
                {
                    continue;
                }

                var bg = GfxBattleBg.Bgs[bgLayers[i]];

                if ((bg.PalDelay != 0) && (t > 0) && ((t % bg.PalDelay) == 0))
                {
                    GfxBattleBg.RotatePal(srcPal[i], bg);
                }
                dstBitmap[i].CopyPalette(srcPal[i], false);

                byte *src = (byte *)srcBd[i].Scan0;

                double dt = (double)t;
                double DH = -(double)bg.DriftH;
                double DV = -(double)bg.DriftV;
                double AH = (double)bg.AmplH;
                double AV = (double)bg.AmplV;
                double WH = (double)bg.WavenumH;
                double WV = (double)bg.WavenumV;
                double FH = (double)bg.FreqH;
                double FV = (double)bg.FreqV;

                dstBd[i] = dstBitmap[i].LockBits(ImageLockMode.WriteOnly);

                byte *dst = (byte *)dstBd[i].Scan0;

                int height = 256;
                int width  = 256;

                // Horizontal translation
                for (int y = 0; y < height; y++)
                {
                    double dy = (double)y;

                    byte offset_x = (byte)((DH * dt / 256.0d) +
                                           AH * Math.Sin(2.0d * Math.PI * WH * (
                                                             (FH * dt / 65536.0d) + (dy / 256.0d))));

                    int new_y = y;
                    int tmp   = y * width;

                    for (int x = 0; x < width; x++)
                    {
                        int tmpnew = new_y * width + offset_x;
                        buf[i][tmp] = src[tmpnew];

                        offset_x++;
                        tmp++;
                    }
                }

                // Vertical compression
                for (int y = 0; y < height; y++)
                {
                    double dy = (double)y;

                    byte offset_y = (byte)((DV * dt / 256.0d) +
                                           AV * Math.Sin(2.0d * Math.PI * WV * (
                                                             (FV * dt / 65536.0d) + (dy / 256.0d))));

                    int tmp    = y * width;
                    int tmpnew = ((offset_y + y) & 0xFF) * width;

                    for (int x = 0; x < width; x++)
                    {
                        dst[tmp++] = buf[i][tmpnew++];
                    }
                }

                dstBitmap[i].UnlockBits(dstBd[i]);
                Bitmap b = dstBitmap[i].ToRaster();

                e.Graphics.DrawImage(b, new Rectangle(0, 0, 256, 256), 0, 0, 256, 256, GraphicsUnit.Pixel, alphaAttr[i]);
            }
        }