#region gnu_license
/*
Crystal Controls - C# control library containing the following tools:
CrystalControl - base class
CrystalGradientControl - a control that can either have a gradient background or be totally transparent.
CrystalLabel - a homegrown label that can have a gradient or transparent background.
CrystalPanel - a panel that can have a gradient or transparent background.
CrystalTrackBar - a homegrown trackbar that can have a gradient or transparent background.
CrystalToolStripTrackBar - a host for CrystalTrackBar that allows it to work in a ToolStrip.
CrystalImageGridView - a control that hosts thumbnail images in a virtual grid.
CrystalImageGridModel - a data model that holds a collection of CrystalImageItems
to feed to CrystalImageGridView.
CrystalImageItem - a class that describes an Image file.
CrystalThumbnailer - provides thumbnailing methods for images.
CrystalCollector - a base class for a controller that links
CrystalImageGridView to the CrystalImageGridModel.
CrystalFileCollector - a controller that works on disk-based Image files.
CrystalDesignCollector - a controller that works in Visual Studio toolbox designer.
CrystalMemoryCollector - a controller that can be used to add images from memory.
CrystalMemoryZipCollector - a controller that accesses images in zip files by streaming them into memory.
CrystalZipCollector - a controller that accesses images in zip files by unpacking them.
CrystalRarCollector - a controller that accesses images in rar files by unpacking them.
CrystalPictureBox - a picture box control, derived from CrystalGradientControl.
CrystalPictureShow - a control for viewing images and processing slideshows.
CrystalComicShow - a control for viewing comic-book images in the CDisplay format.
Copyright (C) 2006, 2008 Richard Guion
Attilan Software Factory: http://www.attilan.com
Contact: richard@attilan.com
Version 1.0.0
This is a work in progress: USE AT YOUR OWN RISK! Interfaces/Methods may change!
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#endregion
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Attilan.Crystal.Controls
{
public class CrystalDrawing
{
public static void RoundRectPath(GraphicsPath path, Rectangle rect, int arcSize, int borderWidth)
{
path.StartFigure();
int bottom = rect.Y + rect.Height - arcSize - borderWidth;
int right = rect.X + rect.Width - arcSize - borderWidth;
// top left
path.AddArc(new Rectangle(rect.X, rect.Y, arcSize, arcSize), 180, 90);
// top right
path.AddArc(new Rectangle(right, rect.Y, arcSize, arcSize), 270, 90);
// bottom right
path.AddArc(new Rectangle(right, bottom, arcSize, arcSize), 0, 90);
// bottom left
path.AddArc(new Rectangle(rect.X, bottom, arcSize, arcSize), 90, 90);
// close the figure and automatically join the path
path.CloseFigure();
}
public static void DrawRoundRect(Graphics gfx, Rectangle rect, Color borderColor,
int arcSize, int borderWidth)
{
using (GraphicsPath path = new GraphicsPath())
{
RoundRectPath(path, rect, arcSize, borderWidth);
gfx.DrawPath(new Pen(borderColor), path);
}
}
public static void FillRoundRect(Graphics gfx, Rectangle rect, Color rectColor,
int arcSize)
{
using (GraphicsPath path = new GraphicsPath())
{
RoundRectPath(path, rect, arcSize, 1);
gfx.FillPath(new SolidBrush(rectColor), path);
}
}
public static void LinearFillRoundRect(Graphics gfx, Rectangle rect,
Color color1, Color color2,
int arcSize)
{
using (GraphicsPath path = new GraphicsPath())
{
RoundRectPath(path, rect, arcSize, 1);
using (LinearGradientBrush linBrush = new LinearGradientBrush(rect, color1, color2, LinearGradientMode.Vertical))
{
gfx.FillPath(linBrush, path);
}
}
}
}
}