protected override void OnPaint(PaintEventArgs e) { var gr = e.Graphics; OnFramePainting(e); try { gr.DrawImage(bgBmp, 0, 0); if (frame != null) { var ea = new TransfromNeededEventArg() { ClientRectangle = new Rectangle(0, 0, this.Width, this.Height) }; ea.ClipRectangle = ea.ClientRectangle; OnTransfromNeeded(ea); gr.SetClip(ea.ClipRectangle); gr.Transform = ea.Matrix; gr.DrawImage(frame, 0, 0); } } catch { } //e.Graphics.DrawLine(Pens.Red, Point.Empty, new Point(Width, Height)); OnFramePainted(e); }
public static void DoScale(TransfromNeededEventArg e, Animation animation) { var rect = e.ClientRectangle; var center = new PointF(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2); e.Matrix.Translate(center.X, center.Y); var kx = 1f - animation.ScaleCoeff.X * e.CurrentTime; var ky = 1f - animation.ScaleCoeff.X * e.CurrentTime; if (Math.Abs(kx) <= 0.001f) kx = 0.001f; if (Math.Abs(ky) <= 0.001f) ky = 0.001f; e.Matrix.Scale(kx, ky); e.Matrix.Translate(-center.X, -center.Y); }
protected override void OnPaint(PaintEventArgs e) { var gr = e.Graphics; OnFramePainting(e); try { gr.DrawImage(bgBmp, -Location.X, -Location.Y); /* if (frame == null) { control.Focus(); if (control.Focused) { frame = new Bitmap(control.Width, control.Height); //control.DrawToBitmap(frame, new Rectangle(padding.Left, padding.Top, control.Width, control.Height)); control.DrawToBitmap(frame, new Rectangle(0, 0, control.Width, control.Height)); } }*/ if (frame != null) { //var ea = new TransfromNeededEventArg(){ ClientRectangle = new Rectangle(0, 0, this.Width, this.Height) }; var ea = new TransfromNeededEventArg(); ea.ClientRectangle = ea.ClipRectangle = new Rectangle(control.Bounds.Left - padding.Left, control.Bounds.Top - padding.Top, control.Bounds.Width + padding.Horizontal, control.Bounds.Height + padding.Vertical); OnTransfromNeeded(ea); gr.SetClip(ea.ClipRectangle); gr.Transform = ea.Matrix; //var p = new Point(); var p = control.Location; //gr.Transform.Translate(p.X, p.Y); gr.DrawImage(frame, p.X - padding.Left, p.Y - padding.Top); } OnFramePainted(e); } catch { } //e.Graphics.DrawLine(Pens.Red, Point.Empty, new Point(Width, Height)); }
protected virtual void OnTransformNeeded(object sender, TransfromNeededEventArg e) { if (TransfromNeeded != null) TransfromNeeded(this, e); else e.UseDefaultMatrix = true; }
private void OnTransfromNeeded(TransfromNeededEventArg ea) { if (TransfromNeeded != null) TransfromNeeded(this, ea); }
protected virtual void OnTransfromNeeded(object sender, TransfromNeededEventArg e) { try { if (CustomClipRect != default(Rectangle)) e.ClipRectangle = ControlRectToMyRect(CustomClipRect); e.CurrentTime = CurrentTime; if (TransfromNeeded != null) TransfromNeeded(this, e); else e.UseDefaultMatrix = true; if (e.UseDefaultMatrix) { TransfromHelper.DoScale(e, animation); TransfromHelper.DoRotate(e, animation); TransfromHelper.DoSlide(e, animation); } } catch { } }
public static void DoSlide(TransfromNeededEventArg e, Animation animation) { var k = e.CurrentTime; e.Matrix.Translate(-e.ClientRectangle.Width * k * animation.SlideCoeff.X, -e.ClientRectangle.Height * k * animation.SlideCoeff.Y); }
public static void DoRotate(TransfromNeededEventArg e, Animation animation) { var rect = e.ClientRectangle; var center = new PointF(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2); e.Matrix.Translate(center.X, center.Y); if (e.CurrentTime > animation.RotateLimit) e.Matrix.Rotate(360 * (e.CurrentTime - animation.RotateLimit) * animation.RotateCoeff); e.Matrix.Translate(-center.X, -center.Y); }