|
/////////////////////////////////////////////////////////////////////////////////
// MyNeoReport Designer
// --------------------
// Project Copyright (C) : Fabio Zanetta, email: support@neodatatype.net
// Portions Copyright (C) : Microsoft Corporation. All Rights Reserved.
// License : docs/license.txt
// ------------------------------------------------------------------------------
// File created by : Fabio Zanetta, email: support@neodatatype.net
// ------------------------------------------------------------------------------
// Please, if you modify some parts of this file mark them as described in
// docs/modify_guidelines.txt
/////////////////////////////////////////////////////////////////////////////////
using System;
using System.Drawing;
namespace NeoDataType.Graphic.Christmas
{
class StarPainter : Painter
{
Point[] _points;
protected override void OnItemBoundsChanged()
{
base.OnItemBoundsChanged();
Star star = (Star)Item;
int nPoints = star.SidesCount * 2;
_points = new Point[nPoints];
Rectangle bounds = Item.Bounds;
Point center = new Point(bounds.X + (bounds.Width / 2),
bounds.Y + (bounds.Height / 2));
Point radius1 = new Point(bounds.Width / 2,
bounds.Height / 2);
Point radius2 = new Point(bounds.Width / 4,
bounds.Height / 4);
for (int i = 0; i < nPoints; i++)
{
Point radius;
double d;
if ((i & 1) != 0)
radius = radius2;
else
radius = radius1;
d = 0;
_points[i] = GetPointOnCircle(center, radius, Convert.ToInt32((i + d) * (360 / nPoints)));
}
}
private Point GetPointOnCircle(Point center, Point radius, int angle)
{
const double pi = Math.PI;
double r = pi / 180.0;
Point pt = new Point(Convert.ToInt32(center.X - (Math.Sin(-angle * r) * radius.X)),
Convert.ToInt32(center.Y - (Math.Sin((90 + angle) * r) * radius.Y)));
return pt;
}
protected override void Paint(Graphics g)
{
Star star = (Star)Item;
Pen pen = new Pen(star.ForeColor, (int)((Item.Width + Item.Height) * 0.02));
SolidBrush brush = new SolidBrush(star.FillColor);
g.FillPolygon(brush, _points);
g.DrawPolygon(pen, _points);
pen.Dispose();
brush.Dispose();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.