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/Themes DefaultTh


From: Richard Baumann <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms/Themes DefaultThemePainter.cs, 1.5, 1.6 IThemePainter.cs, 1.2, 1.3
Date: Tue, 15 Jul 2003 14:38:55 -0400

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

Modified Files:
        DefaultThemePainter.cs IThemePainter.cs 
Log Message:
Fix several ScrollBar drawing problems, and implement DrawGrid.


Index: DefaultThemePainter.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Themes/DefaultThemePainter.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** DefaultThemePainter.cs      12 Jul 2003 07:37:40 -0000      1.5
--- DefaultThemePainter.cs      15 Jul 2003 18:38:53 -0000      1.6
***************
*** 34,37 ****
--- 34,45 ----
  internal class DefaultThemePainter : IThemePainter
  {
+ 
+       // Cached values
+       protected bool gridDark = true;
+       protected Size gridSpacing = Size.Empty;
+       protected Brush gridBrush = null;
+ 
+ 
+ 
        // Draw a simple button border.
        public virtual void DrawBorder
***************
*** 1080,1088 ****
  
        // Draw a grid of dots.
!       [TODO]
!       public virtual void DrawGrid(Graphics graphics, Rectangle area,
!                                                                Size 
pixelsBetweenDots, Color backColor)
                        {
!                               // TODO
                        }
  
--- 1088,1133 ----
  
        // Draw a grid of dots.
!       public virtual void DrawGrid
!                               (Graphics graphics, Rectangle area,
!                                Size pixelsBetweenDots, Color backColor)
                        {
!                               // this is called from ControlPaint static 
methods
!                               // which are supposed to be thread safe, so lock
!                               // this while changing state
!                               lock(this)
!                               {
!                                       bool dark = (backColor.GetBrightness() 
>= 0.5f);
!                                       if (gridBrush == null ||
!                                           gridDark != dark ||
!                                           gridSpacing != pixelsBetweenDots)
!                                       {
!                                               if (gridBrush != null)
!                                               {
!                                                       gridBrush.Dispose();
!                                                       gridBrush = null;
!                                               }
! 
!                                               gridDark = dark;
!                                               Color color;
!                                               if (gridDark)
!                                               {
!                                                       color = Color.Black;
!                                               }
!                                               else
!                                               {
!                                                       color = Color.White;
!                                               }
! 
!                                               gridSpacing = pixelsBetweenDots;
!                                               int spaceX = gridSpacing.Width;
!                                               int spaceY = gridSpacing.Height;
!                                               using (Bitmap bmp = new 
Bitmap(spaceX+1,spaceY+1))
!                                               {
!                                                       bmp.SetPixel(0, 0, 
color);
!                                                       gridBrush = new 
TextureBrush(bmp);
!                                               }
!                                       }
!                               }
!                               graphics.FillRectangle(gridBrush, area);
                        }
  
***************
*** 1170,1193 ****
                                 Brush backgroundBrush,
                                 bool vertical, bool enabled,
!                                Rectangle bar,
                                 Rectangle decrement, bool decDown,
                                 Rectangle increment, bool incDown)
                        {
-                               int x = bounds.X;
-                               int y = bounds.Y;
-                               int width = bounds.Width;
-                               int height = bounds.Height;
- 
                                // fill in the background
!                               graphics.FillRectangle(backgroundBrush,
!                                                      x, y, width, height);
  
!                               // add the border
!                               DrawBorder3D(graphics,
!                                            x, y, width, height,
!                                            foreColor, backColor,
!                                            Border3DStyle.SunkenInner,
!                                            Border3DSide.Left | 
Border3DSide.Top |
!                                            Border3DSide.Right | 
Border3DSide.Bottom);
  
                                // setup the arrow directions for the scroll 
buttons
--- 1215,1246 ----
                                 Brush backgroundBrush,
                                 bool vertical, bool enabled,
!                                Rectangle bar, Rectangle track,
                                 Rectangle decrement, bool decDown,
                                 Rectangle increment, bool incDown)
                        {
                                // fill in the background
!                               graphics.FillRectangle(backgroundBrush, bounds);
  
!                               Color color;
!                               if (backColor.GetBrightness() > 0.5f)
!                               {
!                                       color = Color.White;
!                               }
!                               else
!                               {
!                                       color = Color.Black;
!                               }
!                               using (Brush brush = new 
HatchBrush(HatchStyle.Percent50,
!                                                                   backColor, 
color))
!                               {
!                                       graphics.FillRectangle(brush, track);
!                               }
! 
!                               // workaround some strange visual bugs with the
!                               // hatch... comment these out to see... take a
!                               // screen shot and zoom in on decrement and bar
!                               graphics.FillRectangle(backgroundBrush, bar);
!                               graphics.FillRectangle(backgroundBrush, 
decrement);
!                               graphics.FillRectangle(backgroundBrush, 
increment);
  
                                // setup the arrow directions for the scroll 
buttons
***************
*** 1250,1254 ****
  
        // Draw a scroll button control.
-       [TODO]
        public virtual void DrawScrollButton
                                (Graphics graphics, int x, int y, int width, 
int height,
--- 1303,1306 ----
***************
*** 1266,1325 ****
                                width -= 4; // skip border
                                height -= 4; // skip border
!                               if ((state & ButtonState.Pushed) != 0)
                                {
!                                       x += 1;
!                                       y += 1;
                                }
! 
!                               Point center=new Point(x+width/2,y+height/2);
!                               Size [] offsets;
!                               Point [] vertices=new Point[4];
!                               int arrowWidth, arrowHeight;
!                               arrowWidth=width/2;
!                               arrowHeight=height/2;
!                               if(width>=20 && height>=20)
!                               {
!                                       // arrowHeight and arrowWidth form the 
bounding
!                                       // rectangle rather than the arrow 
parameters
!                                       arrowWidth-=3;
!                                       arrowHeight-=3;
!                               }
!                               if(width>=10 && height>=10)
!                               {
!                                       // arrowHeight and arrowWidth form the 
bounding
!                                       // rectangle rather than the arrow 
parameters
!                                       arrowWidth-=1;
!                                       arrowHeight-=1;
!                               }
!                               // 8 offsets pre-calculated in clockwise 
direction
!                               // from the center
!                               //   7-------------0-------------1
!                               //   |             |             |
!                               //   |             |             |
!                               //   6-------------+-------------2
!                               //   |             |             |
!                               //   |             |             |
!                               //   5-------------4-------------3
!                               //
!                               offsets=new Size[]{
!                                                               new 
Size(0,-arrowHeight),
!                                                               new 
Size(arrowWidth,-arrowHeight),
!                                                               new 
Size(arrowWidth,0),
!                                                               new 
Size(arrowWidth, arrowHeight),
!                                                               new 
Size(0,arrowHeight),
!                                                               new 
Size(-arrowWidth,arrowHeight),
!                                                               new 
Size(-arrowWidth,0),
!                                                               new 
Size(-arrowWidth,-arrowHeight),
!                                                               };
                                switch (button)
                                {
                                        case ScrollButton.Up:
                                        {
!                                               // due to a quirk of fate, this 
is faster
!                                               // than 2 center.X and Y 
get/add/set :)
!                                               vertices[0]=center+offsets[0];
!                                               vertices[1]=center+offsets[3];
!                                               vertices[2]=center+offsets[5];
!                                               vertices[3]=center+offsets[0];
                                        }
                                        break;
--- 1318,1360 ----
                                width -= 4; // skip border
                                height -= 4; // skip border
!                               if ((state & ButtonState.Pushed) == 0)
!                               {
!                                       // the center calculation is off by one
!                                       // so if we don't need "click shift"
!                                       // then minus one from our x and y
!                                       // offsets instead of adding one
!                                       //
!                                       // TODO: "click shift" should probably
!                                       // be set via a protected field or
!                                       // property so themes which don't have
!                                       // it can more easily use this as a base
!                                       x -= 1;
!                                       y -= 1;
!                               }
! 
!                               // setup the glyph shape
!                               int glyphWidth = 3;
!                               int glyphHeight = 3;
!                               if (button == ScrollButton.Up || button == 
ScrollButton.Down)
                                {
!                                       glyphWidth *= 2;
                                }
!                               else
!                               {
!                                       glyphHeight *= 2;
!                               }
!                               Point[] glyph = new Point[3];
!                               int offsetX = x+((width-glyphWidth)/2);
!                               int offsetY = y+((height-glyphHeight)/2);
                                switch (button)
                                {
                                        case ScrollButton.Up:
                                        {
!                                               glyph[0] = new Point(offsetX+3,
!                                                                    offsetY);
!                                               glyph[1] = new Point(offsetX+6,
!                                                                    offsetY+3);
!                                               glyph[2] = new Point(offsetX,
!                                                                    offsetY+3);
                                        }
                                        break;
***************
*** 1327,1334 ****
                                        case ScrollButton.Down:
                                        {
!                                               vertices[0]=center+offsets[1];
!                                               vertices[1]=center+offsets[4];
!                                               vertices[2]=center+offsets[7];
!                                               vertices[3]=center+offsets[1];
                                        }
                                        break;
--- 1362,1371 ----
                                        case ScrollButton.Down:
                                        {
!                                               glyph[0] = new Point(offsetX,
!                                                                    offsetY);
!                                               glyph[1] = new Point(offsetX+6,
!                                                                    offsetY);
!                                               glyph[2] = new Point(offsetX+3,
!                                                                    offsetY+3);
                                        }
                                        break;
***************
*** 1336,1343 ****
                                        case ScrollButton.Left:
                                        {
!                                               vertices[0]=center+offsets[3];
!                                               vertices[1]=center+offsets[6];
!                                               vertices[2]=center+offsets[1];
!                                               vertices[3]=center+offsets[3];
                                        }
                                        break;
--- 1373,1382 ----
                                        case ScrollButton.Left:
                                        {
!                                               glyph[0] = new Point(offsetX,
!                                                                    offsetY+3);
!                                               glyph[1] = new Point(offsetX+3,
!                                                                    offsetY);
!                                               glyph[2] = new Point(offsetX+3,
!                                                                    offsetY+6);
                                        }
                                        break;
***************
*** 1345,1352 ****
                                        case ScrollButton.Right:
                                        {
!                                               vertices[0]=center+offsets[2];
!                                               vertices[1]=center+offsets[5];
!                                               vertices[2]=center+offsets[7];
!                                               vertices[3]=center+offsets[2];
                                        }
                                        break;
--- 1384,1393 ----
                                        case ScrollButton.Right:
                                        {
!                                               glyph[0] = new Point(offsetX,
!                                                                    offsetY);
!                                               glyph[1] = new Point(offsetX,
!                                                                    offsetY+6);
!                                               glyph[2] = new Point(offsetX+3,
!                                                                    offsetY+3);
                                        }
                                        break;
***************
*** 1367,1371 ****
                                using (Brush brush = new SolidBrush(color))
                                {
!                                       graphics.FillPolygon(brush,vertices);
                                }
                        }
--- 1408,1416 ----
                                using (Brush brush = new SolidBrush(color))
                                {
!                                       graphics.FillPolygon(brush,glyph);
!                               }
!                               using (Pen pen = new Pen(color))
!                               {
!                                       graphics.DrawPolygon(pen,glyph);
                                }
                        }

Index: IThemePainter.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/Themes/IThemePainter.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** IThemePainter.cs    8 Jul 2003 10:45:00 -0000       1.2
--- IThemePainter.cs    15 Jul 2003 18:38:53 -0000      1.3
***************
*** 121,125 ****
                                 Brush backgroundBrush,
                                 bool vertical, bool enabled,
!                                Rectangle bar,
                                 Rectangle decrement, bool decDown,
                                 Rectangle increment, bool incDown);
--- 121,125 ----
                                 Brush backgroundBrush,
                                 bool vertical, bool enabled,
!                                Rectangle bar, Rectangle track,
                                 Rectangle decrement, bool decDown,
                                 Rectangle increment, bool incDown);





reply via email to

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