private void DrawFrameOnPanel(AnimationFrame frame)
        {
            if (CurrentAnimation == null) return;

            // Draw on buffer
            using (Graphics canvas = Graphics.FromImage(AnimationBuffer as Image))
            using (Brush gradient = new LinearGradientBrush(new Point(0, 0), new Point(0, PN_Canvas.Height), Color.FromArgb(30, 0, 50), Color.Black))
            using (Brush overlaybrush = new SolidBrush(frame.Overlay))
            using (Font font = new System.Drawing.Font("Courrier New", 18))
            using (Brush redbrush = new SolidBrush(Color.Red))
            {
                // Clear layer with black background and draw rulers
                canvas.FillRectangle(gradient, new Rectangle(new Point(0, 0), Size));
                DrawRulers(PN_Canvas, canvas);

                // Draw pattern frames
                if (frame.Images != null)
                {
                    foreach (AnimationPatternFrame apf in frame.Images)
                    {
                        Image original = PN_Pattern.Controls[apf.ImageIndex].BackgroundImage;
                        Bitmap img = new Bitmap(original, new Size((Int32)(original.Width * apf.Ratio), (Int32)(original.Height * apf.Ratio)));
                        if (img == null) continue;

                        // Color matrix for color manipulation ~ A little explanation after Matrix comprehension
                        //
                        // Red Ratio [        ] [         ] [           ] [      ]
                        // [       ] Blue Ratio [         ] [           ] [      ]
                        // [       ] [        ] Green Ratio [           ] [      ]
                        // [       ] [        ] [         ] Opacity Ratio [      ]
                        // Red Add   Blue Add   Green Add   Opacity Add   Always 1
                        //
                        // A ratio is a multiplication done on current channel in order
                        // to get a new color. Ex pixel = (50, 0, 0) with a Red Ratio of 2 becomes (100, 0, 0)
                        // An add is a simple addition. Ex pixel = (0, 0, 3) with a Red Add of 100 and a Blue Add of 30
                        // becomes (100, 0, 33)
                        //
                        // Since all numbers are floats, the results are very precise.

                        Single a = apf.Opacity;
                        Single r = apf.RGBratio[0];
                        Single g = apf.RGBratio[1];
                        Single b = apf.RGBratio[2];
                        Single R = apf.RGBadd[0];
                        Single G = apf.RGBadd[1];
                        Single B = apf.RGBadd[2];

                        ColorMatrix matrix = new ColorMatrix
                        (
                            new Single[][]
                            {
                                new Single[] {r, 0, 0, 0, 0},
                                new Single[] {0, g, 0, 0, 0},
                                new Single[] {0, 0, b, 0, 0},
                                new Single[] {0, 0, 0, a, 0},
                                new Single[] {R, G, B, 0, 1}
                            }
                        );

                        ImageAttributes imgAttribs = new ImageAttributes();
                        imgAttribs.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Default);

                        // Draw pattern frame to buffer
                        canvas.DrawImage
                        (
                            img,
                            new Rectangle(new Point(apf.Position.X + AbsoluteCenter.X, apf.Position.Y + AbsoluteCenter.Y),
                            new Size((Int32)((Single)img.Size.Width * apf.Ratio), (Int32)((Single)img.Size.Height * apf.Ratio))),
                            0,
                            0,
                            img.Size.Width * apf.Ratio,
                            img.Size.Height * apf.Ratio,
                            GraphicsUnit.Pixel,
                            imgAttribs
                        );
                    }
                }

                // Draw particules

                // Draw color Overlay
                if (frame.Overlay != null) canvas.FillRectangle(overlaybrush, new Rectangle(new Point(0, 0), PN_Canvas.Size));

                // Draw CurrentFrame corner tag
                canvas.DrawString("Cadre #" + (animationTimeLine1.GetCurrentIndex()+1).ToString() + (Lagging ? " [Lag]" : ""), font, redbrush, new Point(RulerWidth+1, RulerWidth+1));
            }

            // Draw buffer on Panel
            using (Graphics g = PN_Canvas.CreateGraphics())
            {
                g.DrawImage(AnimationBuffer, new Point(0, 0));
            }
        }
        // Called when a frame is drawn
        private void DrawFrame(AnimationFrame frame)
        {
            // If graphical library is used, highly recommanded
            if (!UsingXna)
            {
                DrawFrameOnPanel(frame);
            }
            else
            {
                device.Clear(xColor(GlobalPreferences.Prefs.AnimationStudio.BackgroundColor));

                if (frame.Overlay != null && frame.Overlay.A != 0)
                    screen.SetData<Microsoft.Xna.Framework.Color>(new[] { xColor(frame.Overlay) });
                else
                    screen.SetData<Microsoft.Xna.Framework.Color>(new[] { xColor(0,0,0,0) });

                if (frame.Images != null)
                {
                    batch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
                    if (target != null) batch.Draw(target, new Microsoft.Xna.Framework.Rectangle(AbsoluteCenter.X - target.Width / 2, AbsoluteCenter.Y - target.Height / 2, target.Width, target.Height), xColor(frame.Upperlay));
                    batch.End();

                    batch.Begin(SpriteSortMode.BackToFront, BlendState.Additive);
                    foreach (AnimationPatternFrame f in frame.Images)
                    {
                        if (f.Blending == 1) batch.GraphicsDevice.BlendState = BlendState.Additive;
                        else if (f.Blending == 0) batch.GraphicsDevice.BlendState = BlendState.AlphaBlend;
                        else if (f.Blending == -1) batch.GraphicsDevice.BlendState = BlendState.NonPremultiplied;

                        batch.Draw(textures[f.ImageIndex], new Microsoft.Xna.Framework.Rectangle(f.Position.X + AbsoluteCenter.X, f.Position.Y + AbsoluteCenter.Y, (Int32)(textures[f.ImageIndex].Bounds.Width * f.Ratio), (Int32)(textures[f.ImageIndex].Bounds.Height * f.Ratio)), Microsoft.Xna.Framework.Color.White);
                    }

                    batch.End();
                }

                batch.Begin();
                batch.Draw(screen, new Microsoft.Xna.Framework.Rectangle(0, 0, PN_Canvas.Width, PN_Canvas.Height), White());
                DrawRulers();
                batch.End();

                device.Present();
            }
        }
        private void animationTimeLine1_FrameChanged(object sender, AnimationFrame frame)
        {
            LastFrame = DateTime.Now;

            DrawFrame(frame);
            CurrentFrameIndex = animationTimeLine1.GetCurrentIndex();

            Lagging = (LastFrame != null && animationTimeLine1.GetCurrentIndex() > 1 && DateTime.Now.Subtract(LastFrame).Milliseconds > LagThreshold);
        }
Example #4
0
 public void AlterFrameAt(Int32 index, AnimationFrame frame)
 {
     Frames[index] = frame;
 }
Example #5
0
        public Animation()
        {
            Frames = new AnimationFrame[20].Select(x => x = new AnimationFrame()).ToList();

            Name = "Nouvelle animation";
        }
Example #6
0
        public object Clone()
        {
            AnimationFrame frame = new AnimationFrame();
            frame.BGS = this.BGS;
            frame.Images = this.Images.Select(x => x.Clone() as AnimationPatternFrame).ToList();
            frame.Overlay = this.Overlay;
            frame.Upperlay = this.Upperlay;
            frame.Particules = this.Particules.Select(x => x.Clone() as AnimationParticules).ToArray();
            frame.Pixels = new AnimationPixels[0];

            return frame;
        }