BorderEffects.cs :  » Persistence-Frameworks » Ubik » StoresAndStockPricing » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » Ubik 
Ubik » StoresAndStockPricing » Controls » BorderEffects.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace StoresAndStockPricing.Controls{
  internal static class BorderEffects
  {
    public static void FillRoundRectangle(Graphics g, Brush brush, int x, int y,
            int width, int height, int radiusX, int radiusY) 
        { 
            FillRoundRectangle(g, brush, (float)x, (float)y, 
                (float)width, (float)height, (float)radiusX, (float)radiusY); 
        } 

        public static void FillRoundRectangle(Graphics g, Brush brush, float x, float y,
            float width, float height, float radiusX, float radiusY)
        {
            if (g != null)
            {
                RectangleF rectangle = new RectangleF(x, y, width, height);
                GraphicsPath path    = GetRoundedRect(rectangle, radiusX, radiusY);

                g.FillPath(brush, path);
            }
        } 

        public static void DrawRoundRectangle(Graphics g, Pen pen, int x, int y,
            int width, int height, int radiusX, int radiusY) 
        { 
            DrawRoundRectangle(g, pen, (float)x, (float)y, (float)width, 
                (float)height, (float)radiusX, (float)radiusY); 
        }

        public static void DrawRoundRectangle(Graphics g, Pen pen, float x, float y, 
            float width, float height, float radiusX, float radiusY) 
        { 
            if (g != null)
            {
                RectangleF rectangle = new RectangleF(x, y, width, height); 
                GraphicsPath path    = GetRoundedRect(rectangle, radiusX, radiusY);
 
                g.DrawPath(pen, path); 
            }
        } 

        private static GraphicsPath GetRoundedRect(RectangleF baseRect, 
            float radiusX, float radiusY) 
        {
            // if corner radius is less than or equal to zero, 
            // return the original rectangle 
            if (radiusX <= 0.0F || radiusY <= 0.0F) 
            { 
                GraphicsPath mPath = new GraphicsPath(); 
                mPath.AddRectangle(baseRect); 
                mPath.CloseFigure(); 

                return mPath;
            }

            // if the corner radius is greater than or equal to 
            // half the width, or height (whichever is shorter) 
            // then return a capsule instead of a lozenge 
            if (radiusX >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0) 
                return GetCapsule(baseRect); 

            if (radiusY >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0) 
                return GetCapsule(baseRect); 

            // create the arc for the rectangle sides and declare 
            // a graphics path object for the drawing 
            float diameterX    = radiusX * 2.0F; 
            float diameterY    = radiusY * 2.0F; 
            SizeF sizeF       = new SizeF(diameterX, diameterY);
            RectangleF arc    = new RectangleF(baseRect.Location, sizeF); 
            GraphicsPath path = new GraphicsPath(); 

            // top left arc 
            path.AddArc(arc, 180, 90); 

            // top right arc 
            arc.X = baseRect.Right - diameterX; 
            path.AddArc(arc, 270, 90); 

            // bottom right arc 
            arc.Y = baseRect.Bottom - diameterY; 
            path.AddArc(arc, 0, 90); 

            // bottom left arc
            arc.X = baseRect.Left;     
            path.AddArc(arc, 90, 90);     

            path.CloseFigure(); 

            return path; 
        } 

        private static GraphicsPath GetCapsule(RectangleF baseRect) 
        { 
            GraphicsPath path = new GraphicsPath(); 

            try 
            { 
                if (baseRect.Width > baseRect.Height) 
                { 
                    // return horizontal capsule 
                    float diameter = baseRect.Height; 
                    SizeF sizeF    = new SizeF(diameter, diameter);
                    RectangleF arc = new RectangleF(baseRect.Location, sizeF); 
                    path.AddArc(arc, 90, 180);
 
                    arc.X = baseRect.Right - diameter; 
                    path.AddArc(arc, 270, 180); 
                } 
                else if (baseRect.Width < baseRect.Height) 
                { 
                    // return vertical capsule 
                    float diameter = baseRect.Width;
                    SizeF sizeF    = new SizeF(diameter, diameter);
                    RectangleF arc = new RectangleF(baseRect.Location, sizeF); 
                    path.AddArc(arc, 180, 180); 
                    
                    arc.Y = baseRect.Bottom - diameter; 
                    path.AddArc(arc, 0, 180); 
                } 
                else
                { 
                    // return circle 
                    path.AddEllipse(baseRect); 
                }
            } 
            catch
            {
                path.AddEllipse(baseRect); 
            } 
            finally 
            { 
                path.CloseFigure(); 
            } 

            return path; 
        } 
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.