[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms ControlPaint.cs
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms ControlPaint.cs,1.3,1.4 |
Date: |
Sat, 21 Jun 2003 05:43:52 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms
In directory subversions:/tmp/cvs-serv390/System.Windows.Forms
Modified Files:
ControlPaint.cs
Log Message:
Implement the "ControlPaint.DrawBorder" method; compute
"darker" and "lighter" versions of colors.
Index: ControlPaint.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/System.Windows.Forms/ControlPaint.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ControlPaint.cs 20 Jun 2003 22:12:09 -0000 1.3
--- ControlPaint.cs 21 Jun 2003 09:43:50 -0000 1.4
***************
*** 40,43 ****
--- 40,101 ----
}
+ // Convert HSB values into an RGB value. Algorithm based on:
+ // http://www.cs.rit.edu/~ncs/color/t_convert.html
+ private static Color FromHSB(float hue, float saturation, float
brightness)
+ {
+ float f, p, q, t, r, g, b;
+ int temp;
+ if(saturation == 0.0f)
+ {
+ temp = (int)(brightness * 255.0f);
+ return Color.FromArgb(temp, temp, temp);
+ }
+ else
+ {
+ hue /= 60.0f;
+ temp = (int)hue;
+ f = hue - (float)temp;
+ p = brightness * (1.0f - saturation);
+ q = brightness * (1.0f - saturation *
f);
+ t = brightness * (1.0f - saturation *
(1.0f - f));
+ switch(temp)
+ {
+ case 0:
+ r = brightness;
+ g = t;
+ b = p;
+ break;
+ case 1:
+ r = q;
+ g = brightness;
+ b = p;
+ break;
+ case 2:
+ r = p;
+ g = brightness;
+ b = t;
+ break;
+ case 3:
+ r = p;
+ g = q;
+ b = brightness;
+ break;
+ case 4:
+ r = t;
+ g = p;
+ b = brightness;
+ break;
+ default:
+ r = brightness;
+ g = p;
+ b = q;
+ break;
+ }
+ return Color.FromArgb
+ ((int)(r / 255.0f), (int)(g /
255.0f),
+ (int)(b / 255.0f));
+ }
+ }
+
// Get the "dark" version of a color.
public static Color Dark(Color baseColor)
***************
*** 49,68 ****
return Dark(baseColor, 1.0f);
}
- [TODO]
public static Color Dark(Color baseColor, float percOfDarkDark)
{
if(baseColor.ToKnownColor() ==
KnownColor.Control)
{
! if(percOfDarkDark <= 0.5f)
{
return SystemColors.ControlDark;
}
! else
{
return
SystemColors.ControlDarkDark;
}
}
! // TODO
! return baseColor;
}
--- 107,144 ----
return Dark(baseColor, 1.0f);
}
public static Color Dark(Color baseColor, float percOfDarkDark)
{
if(baseColor.ToKnownColor() ==
KnownColor.Control)
{
! if(percOfDarkDark <= 0.0f)
{
return SystemColors.ControlDark;
}
! else if(percOfDarkDark >= 1.0f)
{
return
SystemColors.ControlDarkDark;
}
+ else
+ {
+ Color dark =
SystemColors.ControlDark;
+ Color darkdark =
SystemColors.ControlDarkDark;
+ int redDiff = darkdark.R -
dark.R;
+ int greenDiff = darkdark.G -
dark.G;
+ int blueDiff = darkdark.B -
dark.B;
+ return Color.FromArgb
+ (dark.R + (int)(redDiff
* percOfDarkDark),
+ dark.G +
(int)(greenDiff * percOfDarkDark),
+ dark.B +
(int)(blueDiff * percOfDarkDark));
+ }
}
! float hue = baseColor.GetHue();
! float saturation = baseColor.GetSaturation();
! float brightness = baseColor.GetBrightness();
! brightness -= percOfDarkDark * 0.666f;
! if(brightness < 0.0f)
! {
! brightness = 0.0f;
! }
! return FromHSB(hue, saturation, brightness);
}
***************
*** 76,95 ****
return Light(baseColor, 1.0f);
}
- [TODO]
public static Color Light(Color baseColor, float percOfLightLight)
{
if(baseColor.ToKnownColor() ==
KnownColor.Control)
{
! if(percOfLightLight <= 0.5f)
{
return
SystemColors.ControlLight;
}
! else
{
return
SystemColors.ControlLightLight;
}
}
! // TODO
! return baseColor;
}
--- 152,189 ----
return Light(baseColor, 1.0f);
}
public static Color Light(Color baseColor, float percOfLightLight)
{
if(baseColor.ToKnownColor() ==
KnownColor.Control)
{
! if(percOfLightLight <= 0.0f)
{
return
SystemColors.ControlLight;
}
! else if(percOfLightLight >= 1.0f)
{
return
SystemColors.ControlLightLight;
}
+ else
+ {
+ Color light =
SystemColors.ControlLight;
+ Color lightlight =
SystemColors.ControlLightLight;
+ int redDiff = lightlight.R -
light.R;
+ int greenDiff = lightlight.G -
light.G;
+ int blueDiff = lightlight.B -
light.B;
+ return Color.FromArgb
+ (light.R +
(int)(redDiff * percOfLightLight),
+ light.G +
(int)(greenDiff * percOfLightLight),
+ light.B +
(int)(blueDiff * percOfLightLight));
+ }
}
! float hue = baseColor.GetHue();
! float saturation = baseColor.GetSaturation();
! float brightness = baseColor.GetBrightness();
! brightness += percOfLightLight * 0.666f;
! if(brightness > 1.0f)
! {
! brightness = 1.0f;
! }
! return FromHSB(hue, saturation, brightness);
}
***************
*** 133,137 ****
case ButtonBorderStyle.Inset:
{
! pen = new Pen(Dark(color),
1.0f);
pen.EndCap = LineCap.Square;
graphics.DrawLine(pen, bounds.X,
--- 227,231 ----
case ButtonBorderStyle.Inset:
{
! pen = new Pen(DarkDark(color),
1.0f);
pen.EndCap = LineCap.Square;
graphics.DrawLine(pen, bounds.X,
***************
*** 141,145 ****
bounds.X + bounds.Width - 1,
bounds.Y);
! pen.Color = Light(color);
graphics.DrawLine(pen, bounds.X
+ 1,
bounds.Y + bounds.Height - 1,
--- 235,239 ----
bounds.X + bounds.Width - 1,
bounds.Y);
! pen.Color = LightLight(color);
graphics.DrawLine(pen, bounds.X
+ 1,
bounds.Y + bounds.Height - 1,
***************
*** 150,153 ****
--- 244,266 ----
bounds.X + bounds.Width - 1,
bounds.Y + 1);
+ pen.Color = Light(color);
+ graphics.DrawLine(pen, bounds.X
+ 1,
+
bounds.Y + bounds.Height - 2,
+
bounds.X + 1, bounds.Y + 1);
+ graphics.DrawLine(pen, bounds.X
+ 2, bounds.Y + 1,
+
bounds.X + bounds.Width - 2,
+
bounds.Y + 1);
+ if(color.ToKnownColor() ==
KnownColor.Control)
+ {
+ pen.Color =
SystemColors.ControlLight;
+ graphics.DrawLine(pen,
bounds.X + 1,
+
bounds.Y + bounds.Height - 2,
+
bounds.X + bounds.Width - 2,
+
bounds.Y + bounds.Height - 2);
+ graphics.DrawLine(pen,
bounds.X + bounds.Width - 2,
+
bounds.Y + bounds.Height - 3,
+
bounds.X + bounds.Width - 2,
+
bounds.Y + 1);
+ }
pen.Dispose();
}
***************
*** 156,169 ****
case ButtonBorderStyle.Outset:
{
! pen = new Pen(Light(color),
1.0f);
pen.EndCap = LineCap.Square;
graphics.DrawLine(pen, bounds.X,
!
bounds.Y + bounds.Height - 1,
bounds.X, bounds.Y);
graphics.DrawLine(pen, bounds.X
+ 1, bounds.Y,
!
bounds.X + bounds.Width - 1,
bounds.Y);
! pen.Color = Dark(color);
! graphics.DrawLine(pen, bounds.X
+ 1,
bounds.Y + bounds.Height - 1,
bounds.X + bounds.Width - 1,
--- 269,282 ----
case ButtonBorderStyle.Outset:
{
! pen = new
Pen(LightLight(color), 1.0f);
pen.EndCap = LineCap.Square;
graphics.DrawLine(pen, bounds.X,
!
bounds.Y + bounds.Height - 2,
bounds.X, bounds.Y);
graphics.DrawLine(pen, bounds.X
+ 1, bounds.Y,
!
bounds.X + bounds.Width - 2,
bounds.Y);
! pen.Color = DarkDark(color);
! graphics.DrawLine(pen, bounds.X,
bounds.Y + bounds.Height - 1,
bounds.X + bounds.Width - 1,
***************
*** 172,175 ****
--- 285,304 ----
bounds.Y + bounds.Height - 2,
bounds.X + bounds.Width - 1,
+
bounds.Y);
+ pen.Color = Light(color);
+ graphics.DrawLine(pen, bounds.X
+ 1,
+
bounds.Y + bounds.Height - 3,
+
bounds.X + 1, bounds.Y + 1);
+ graphics.DrawLine(pen, bounds.X
+ 1, bounds.Y + 1,
+
bounds.X + bounds.Width - 3,
+
bounds.Y + 1);
+ pen.Color = Dark(color);
+ graphics.DrawLine(pen, bounds.X
+ 1,
+
bounds.Y + bounds.Height - 2,
+
bounds.X + bounds.Width - 2,
+
bounds.Y + bounds.Height - 2);
+ graphics.DrawLine(pen, bounds.X
+ bounds.Width - 2,
+
bounds.Y + bounds.Height - 3,
+
bounds.X + bounds.Width - 2,
bounds.Y + 1);
pen.Dispose();
***************
*** 235,250 ****
{
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;
--- 364,378 ----
{
DrawBorder3D(graphics, x, y, width, height,
!
SystemColors.InactiveBorder,
! SystemColors.Control,
! style, sides);
}
! internal 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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/System.Windows.Forms ControlPaint.cs,1.3,1.4,
Rhys Weatherley <address@hidden> <=