public override void Render(Graphics ctx, float dt) { var state = ctx.Save(); var baseOp = Fill.A / 255.0f; var anim = ActiveAnimation; var clipping = false; var opacity = (int)(Opacity * 255.0f * baseOp); Rectangle clipBounds = Rectangle.Empty; if (anim != null) { if (anim is Reveal) { clipBounds = AnimatableProperties.Bounds; clipping = true; } else if (anim is Fade) { opacity = (int)(AnimatableProperties.Opacity * 255.0f * baseOp); } } opacity = Math.Max(0, Math.Min(opacity, 255)); var sb = new SolidBrush(Color.FromArgb(opacity, Fill)); var clip = new Region(Bounds); if (clipping) { clip.Intersect(GetClipPath(ctx, clipBounds)); } if (Clipper != null) { if (!clipping) { clip.Intersect(Clipper.GetClipPath(ctx, Clipper.Bounds)); } else { clip.Intersect(Clipper.Bounds); } if (Clipper.AnimationPlaying) { clip.Intersect(Clipper.GetClipPath(ctx, Clipper.AnimatableProperties.Bounds)); } } ctx.Clip = clip; ctx.FillRoundedRectangle(sb, Bounds, BorderRadius, EdgeFilter); ctx.ResetClip(); ctx.Restore(state); }
public override void Render(Graphics ctx, float dt) { var state = ctx.Save(); var anim = ActiveAnimation; var opacity = Opacity; var clipping = false; Rectangle clipBounds = Rectangle.Empty; if (anim != null) { if (anim is Reveal) { clipBounds = AnimatableProperties.Bounds; clipping = true; } else if (anim is Fade) { opacity = AnimatableProperties.Opacity; } } opacity = Math.Max(0.0f, Math.Min(opacity, 1.0f)); ColorMatrix colormatrix = new ColorMatrix(); colormatrix.Matrix33 = opacity; ImageAttributes attr = new ImageAttributes(); attr.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); var clip = new Region(Bounds); if (clipping) { clip.Intersect(clipBounds); } if (Clipper != null) { if (!clipping) { clip.Intersect(Clipper.GetClipPath(ctx, Clipper.Bounds)); } else { clip.Intersect(Clipper.Bounds); } if (Clipper.AnimationPlaying) { clip.Intersect(Clipper.GetClipPath(ctx, Clipper.AnimatableProperties.Bounds)); } } ctx.Clip = clip; if (Image != null) { ctx.DrawImage(Image, new Rectangle(Bounds.X, Bounds.Y, Bounds.Width, Bounds.Height), Source.X, Source.Y, Source.Width, Source.Height, GraphicsUnit.Pixel, attr); } else { ctx.FillRectangle(Brushes.Magenta, Bounds); } ctx.ResetClip(); ctx.Restore(state); }
public override void Render(Graphics ctx, float dt) { preferredSize = ctx.MeasureString(Text, Font).ToSize(); preferredSize.Width += 10; var state = ctx.Save(); var sf = new StringFormat(); var baseOp = Fill.A / 255.0f; var anim = ActiveAnimation; var clipping = false; var opacity = (int)(Opacity * 255.0f * baseOp); Rectangle clipBounds = Rectangle.Empty; if (anim != null) { if (anim is Reveal) { clipBounds = AnimatableProperties.Bounds; clipping = true; } else if (anim is Fade) { opacity = (int)(AnimatableProperties.Opacity * 255.0f * baseOp); } } opacity = Math.Max(0, Math.Min(opacity, 255)); var sb = new SolidBrush(Color.FromArgb(opacity, Fill)); switch (HorizontalAlign) { case Alignment.Near: sf.Alignment = StringAlignment.Near; break; case Alignment.Center: sf.Alignment = StringAlignment.Center; break; case Alignment.Far: sf.Alignment = StringAlignment.Far; break; } switch (VerticalAlign) { case Alignment.Near: sf.LineAlignment = StringAlignment.Near; break; case Alignment.Center: sf.LineAlignment = StringAlignment.Center; break; case Alignment.Far: sf.LineAlignment = StringAlignment.Far; break; } var sz = GetPreferredSize(); var clip = new Region(new Rectangle(Bounds.Location, sz)); if (clipping) { clip.Intersect(clipBounds); } if (Clipper != null) { if (!clipping) { clip.Intersect(Clipper.GetClipPath(ctx, Clipper.Bounds)); } else { clip.Intersect(Clipper.Bounds); } if (Clipper.AnimationPlaying) { clip.Intersect(Clipper.GetClipPath(ctx, Clipper.AnimatableProperties.Bounds)); } } ctx.Clip = clip; //List<Line> lines = GetLines(ctx); //var boxHeight = lines.Select(l => l.Height).Aggregate((a, b) => a + b); //var boxWidth = 0.0; //foreach (var line in lines) boxWidth = Math.Max(boxWidth, line.Width); //float y = Bounds.Height / 2.0f; //switch (VerticalAlign) { // case Alignment.Near: y += 0; break; // case Alignment.Center: y += (Bounds.Height / 2 - boxHeight / 2); break; // case Alignment.Far: y += (Bounds.Height - boxHeight); break; //} ctx.DrawString(Text, Font, sb, new RectangleF(Bounds.X, Bounds.Y, sz.Width, sz.Height), sf); //foreach (var line in lines) { // float x = Bounds.Width / 2.0f; // //switch (HorizontalAlign) { // // case Alignment.Near: x = 0; break; // // case Alignment.Center: x = (Bounds.Width / 2 - line.Width / 2); break; // // case Alignment.Far: x = (Bounds.Width - line.Width); break; // //} // ctx.DrawString(line.Text, Font, sb, x + Bounds.X, y + Bounds.Y); // y += line.Height; //} ctx.ResetClip(); ctx.Restore(state); }