dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms ProgressBar.cs,


From: Gopal.V <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms ProgressBar.cs,NONE,1.1 ControlPaint.cs,1.1,1.2
Date: Fri, 13 Jun 2003 16:58:29 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv13554/System.Windows.Forms

Modified Files:
        ControlPaint.cs 
Added Files:
        ProgressBar.cs 
Log Message:
ProgressBar control


--- NEW FILE ---
/*
 * ProgressBar.cs - Implementation of "System.Windows.Forms.ProgressBar" 
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 * 
 * Contributed by Gopal.V <address@hidden> 
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace System.Windows.Forms
{
        public sealed class ProgressBar: Control
        {
                
                private int min=0,max=100,value=0;
                private int step=10;
                private int range=max-min;

                public ProgressBar() : base("ProgressBar")
                        {
                        }

                /* NOTE: not really sure how the stuff is drawn , but
                *  this sure looks like it :-)
                */
                private void Draw(Graphics graphics)
                        {
                                if(!Visible || !IsHandleCreated) return;

                                Size clientSize = ClientSize;
                                int x = 0;
                                int y = 0;
                                int width = clientSize.Width;
                                int height = clientSize.Height;
                                int steps=range/step;
                                int blockWidth, blockHeight, xSpacing, ySpacing;
                                
                                using(Brush brush=CreateBackgroundBrush())
                                {
                                        
graphics.FillRectangle(brush,x,y,width,height);
                                }

                                ControlPaint.DrawBorder3D(graphics, 
                                                                                
          x,y,width,height);

                                width-=4;
                                height-=4;
                                x+=2;
                                y+=2;

                                xSpacing=2;
                                ySpacing=2;
                                width=width-((steps-1)*xSpacing);
                                blockWidth=width/steps;
                                blockHeight=height-ySpacing-1;
                                                
                                x+=2*xSpacing;

                                for(int i=0;i<steps;i++)
                                {
                                        if((i*step) < value)
                                        {
                                                
ControlPaint.DrawBlock(graphics, x, y+ySpacing, 
                                                                                
        blockWidth,
                                                                                
        blockHeight,
                                                                                
        SystemColors.Highlight);
                                        }
                                        x+=blockWidth+xSpacing;
                                }
                        }


                private void Redraw()
                        {
                                if(!Visible || !IsHandleCreated)
                                {
                                        return;
                                }

                                using(Graphics graphics = CreateGraphics())
                                {
                                        Draw(graphics);
                                }
                        }

                protected override void OnPaint(PaintEventArgs args)
                        {
                                Redraw();
                                base.OnPaint(args);
                        }

                public void Increment(int value)
                        {
                                Value=this.value+value;
                                Redraw();
                        }

                public void PerformStep()
                        {
                                if(value>=max)
                                {
                                        value=min;
                                }
                                else
                                {
                                        value=(value + (step - (value % step)));
                                }
                                Redraw();
                        }

                protected override Size DefaultSize 
                        {
                                get
                                {
                                        return new Size(160,20);
                                }
                        }       

                public int Maximum 
                        {
                                get
                                {
                                        return max;
                                }

                                set
                                {
                                        if(value < min)
                                        {
                                                throw new 
ArgumentOutOfRangeException("Maximum");
                                        }
                                        max=value;
                                        range=max-min;
                                        Redraw();
                                }
                        }

                public int Minimum 
                        {
                                get
                                {
                                        return min;
                                }
        
                                set
                                {
                                        if(value > max)
                                        {
                                                throw new 
ArgumentOutOfRangeException("Minimum");
                                        }
                                        min=value;
                                        range=max-min;
                                        Redraw();
                                }

                        }

                public int Step 
                        {
                                get
                                {
                                        return step;
                                }

                                set
                                {
                                        if(step <=0)
                                        {
                                                throw new 
ArgumentOutOfRangeException("Step");
                                        }
                                        step=value;
                                        Redraw();
                                }

                        }

                public int Value 
                        {
                                get
                                {
                                        return value;
                                }

                                set
                                {
                                        if(value > max || value < min)
                                        {
                                                throw new 
ArgumentOutOfRangeException("Value");
                                        }
                                        this.value=value;
                                        Redraw();
                                }

                        }

        }
}//namespace

Index: ControlPaint.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/ControlPaint.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ControlPaint.cs     12 Jun 2003 02:55:49 -0000      1.1
--- ControlPaint.cs     13 Jun 2003 20:58:27 -0000      1.2
***************
*** 229,233 ****
                                                         Border3DSide.Right | 
Border3DSide.Bottom);
                        }
-       [TODO]
        public static void DrawBorder3D(Graphics graphics, int x, int y,
                                                                        int 
width, int height,
--- 229,232 ----
***************
*** 235,239 ****
                                                                        
Border3DSide sides)
                        {
!                               // TODO
                        }
  
--- 234,324 ----
                                                                        
Border3DSide sides)
                        {
!                               DrawBorder3D(graphics, x, y, width, height, 
!                                                               
SystemColors.InactiveBorder,
!                                                               
SystemColors.Control,
!                                                               style,sides);
! 
!                       }
!                       
!       public static void DrawBorder3D(Graphics graphics, int x, int y,
!                                                                       int 
width, int height,
!                                                                       Color 
foreColor,
!                                                                       Color 
backColor,
!                                                                       
Border3DStyle style,
!                                                                       
Border3DSide sides)
!                       {
!                               Color light, lightlight, dark, darkdark;
!                               Pen pen;
! 
!                               // Draw the border around the edges of the 
button.
!                               if(style == Border3DStyle.Etched)
!                               {
!                                       lightlight = DarkDark(backColor);
!                                       darkdark = LightLight(backColor);
!                                       light = Dark(backColor);
!                                       dark = Light(backColor);
!                               }
!                               else
!                               {
!                                       lightlight = LightLight(backColor);
!                                       darkdark = DarkDark(backColor);
!                                       light = Light(backColor);
!                                       dark = Dark(backColor);
!                               }
! 
!                               if(width >= 2 && height >= 2)
!                               {
!                                       pen = new Pen(foreColor, 1.0f);
!                                       pen.EndCap = LineCap.Square;
!                                       graphics.DrawRectangle(pen, x, y, 
width, height);
!                                       pen.Dispose();
!                                       ++x;
!                                       ++y;
!                                       width -= 2;
!                                       height -= 2;
!                               }
!                               if(width >= 4 && height >= 4)
!                               {
!                                       pen = new Pen(lightlight, 1.0f);
!                                       pen.EndCap = LineCap.Square;
!                                       if((sides & Border3DSide.Left )!=0)
!                                       {
!                                               graphics.DrawLine(pen, x, y + 
height - 2, x, y);
!                                               pen.Color = light;
!                                               graphics.DrawLine(pen, x + 1, y 
+ height - 3,
!                                                                         x + 
1, y + 1);
!                                       }
!                                       if((sides & Border3DSide.Right )!=0)
!                                       {
!                                               pen.Color = darkdark;
!                                               graphics.DrawLine(pen, x + 
width - 1, y,
!                                                                         x + 
width - 1, y + height - 1);
!                                               pen.Color = dark;
!                                               graphics.DrawLine(pen, x + 
width - 2, y + 1,
!                                                                         x + 
width - 2, y + height - 2);
!                                       }
!                                       if((sides & Border3DSide.Top)!=0)
!                                       {
!                                               pen.Color = lightlight;
!                                               graphics.DrawLine(pen, x + 1, 
y, x + width - 2, y);
!                                               pen.Color = light;
!                                               graphics.DrawLine(pen, x + 2, y 
+ 1,
!                                                                         x + 
width - 3, y + 1);
!                                       }
!                                       if((sides & Border3DSide.Bottom)!=0)
!                                       {
!                                               pen.Color = darkdark;
!                                               graphics.DrawLine(pen, x + 
width - 2, y + height - 1,
!                                                                         x, y 
+ height - 1);
!                                               pen.Color = dark;
!                                               graphics.DrawLine(pen, x + 
width - 3, y + height - 2,
!                                                                         x + 
1, y + height - 2);
!                                       }
!                                       pen.Dispose();
!                                       x += 2;
!                                       y += 2;
!                                       width -= 4;
!                                       height -= 4;
!                               }
                        }
  
***************
*** 354,357 ****
--- 439,460 ----
                        {
                                // TODO
+                       }
+ 
+       public static void DrawBlock(Graphics graphics, int x, int y,
+                                                                       int 
width, int height,
+                                                                       Color 
color)
+                       {
+                               Brush brush;
+                               Pen pen;
+                               brush=new SolidBrush(color);
+                               /*pen=new Pen(Light(color),1.0f);               
                
+                               graphics.DrawRectangle(pen, x, y, width, 
height);
+                               pen.Dispose();
+                               x+=1;
+                               y+=1;
+                               width-=2;
+                               height-=2;*/
+                               graphics.FillRectangle(brush, x, y, width, 
height);
+                               brush.Dispose();
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]