Click here to Skip to main content
15,885,435 members
Articles / Programming Languages / Visual Basic

AGE, Another Graphic Engine in .NET

Rate me:
Please Sign up or sign in to vote.
4.96/5 (36 votes)
10 May 2007CPOL8 min read 135.9K   5.9K   170  
A library that allows some GDI+ manipulation at runtime in an easy way
/////////////////////////////////////////////////////////////////////////////////
// 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions