Skip to content

Commit 214e81f

Browse files
committed
added Color property for Image class (default: White), so GDI can use it for painting. Perfect solution to paint something like BackgroundImage;
fixed some bugs in ComboBox control and added some more missing features; fixed ScrollBar behavior for handling input keys, now it's just handing over KeyArgs to it's parent as it should be intended;
1 parent ddbf07f commit 214e81f

File tree

19 files changed

+408
-314
lines changed

19 files changed

+408
-314
lines changed

Controls/BitmapText.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ public BitmapText(BitmapFont font)
6464
public void Apply()
6565
{
6666
var tSize = TextureSize;
67-
uTexture = Graphics.ApiGraphics.CreateTexture(tSize.Width, tSize.Height);
67+
Texture = Graphics.ApiGraphics.CreateTexture(tSize.Width, tSize.Height);
6868

6969
if (tSize.Width == 0 || tSize.Height == 0)
7070
return;
7171

7272

7373
// Clear texture with transparent color.
7474
var uBackColor = Color.Transparent;
75-
var clearColor = new Color[uTexture.Width * uTexture.Height];
75+
var clearColor = new Color[Texture.Width * Texture.Height];
7676
for (int i = 0; i < clearColor.Length; i++)
7777
clearColor[i] = uBackColor;
78-
uTexture.SetPixels(clearColor);
78+
Texture.SetPixels(clearColor);
7979

8080
int xOffset = 0;
8181
float cursorY = GetCursorY();
82-
float cursorOffset = uTexture.Height - cursorY;
82+
float cursorOffset = Texture.Height - cursorY;
8383

8484
for (int i = 0; i < Text.Length; i++)
8585
{
@@ -101,7 +101,7 @@ public void Apply()
101101

102102
if (cW > 0 && cH > 0)
103103
{
104-
var charPixels = textC.Texture.uTexture.GetPixels();
104+
var charPixels = textC.Texture.Texture.GetPixels();
105105
var charTexture = Graphics.ApiGraphics.CreateTexture(textC.Texture.Width, textC.Texture.Height);
106106
charTexture.SetPixels(charPixels);
107107
charTexture.Apply();
@@ -126,13 +126,13 @@ public void Apply()
126126
blendedCharPixels[p] = Color.FromArgb(bA, bR, bG, bB);
127127
}
128128

129-
uTexture.SetPixels((int)cX, (int)(cursorOffset - bellowHeight), charTexture.Width, charTexture.Height, blendedCharPixels);
129+
Texture.SetPixels((int)cX, (int)(cursorOffset - bellowHeight), charTexture.Width, charTexture.Height, blendedCharPixels);
130130
}
131131

132132
xOffset += (int)cA;
133133
}
134134

135-
uTexture.Apply();
135+
Texture.Apply();
136136
}
137137
public BitmapChar CharAt(int index)
138138
{

Core/API/IApiGraphics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface IApiGraphics
77

88
void BeginGroup(float x, float y, float width, float height);
99
void Clear(Color color);
10-
void DrawImage(Image image, Color color, float x, float y, float width, float height, float angle);
10+
void DrawImage(Image image, float x, float y, float width, float height, float angle);
1111
void DrawImage(Image image, float x, float y, float width, float height, object material = null);
1212
void DrawLine(Pen pen, float x1, float y1, float x2, float y2, object material = null);
1313
void DrawPolygon(Pen pen, Point[] points, object material = null);

Examples/ControlsExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static class ControlsExtensions
6060
{
6161
public static T Create<T>(this Control parent, int margin = 8, int lineHeight = 24) where T : Control, new()
6262
{
63-
return Create<T>(parent, AnchorStylesExtended.LeftTop, null, false, margin, lineHeight);
63+
return Create<T>(parent, AnchorStylesExtended.LeftTop, string.Empty, false, margin, lineHeight);
6464
}
6565
public static T Create<T>(this Control parent, AnchorStylesExtended anchor, bool placeToRight = false, int margin = 8, int lineHeight = 24) where T : Control, new()
6666
{

System/Drawing/Bitmap.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ public class Bitmap : Image
88
public Bitmap(Image original)
99
{
1010
if (original != null)
11-
uTexture = original.uTexture;
11+
Texture = original.Texture;
1212
}
1313
public Bitmap(int width, int height)
1414
{
15-
uTexture = Graphics.ApiGraphics.CreateTexture(width, height);
15+
Texture = Graphics.ApiGraphics.CreateTexture(width, height);
1616
}
1717

1818
private Bitmap()
@@ -24,30 +24,30 @@ public void ClearColor(Color c, bool apply = true)
2424
var colors = new Color[Width * Height];
2525
for (int i = 0; i < colors.Length; i++)
2626
colors[i] = c;
27-
uTexture.SetPixels(colors);
27+
Texture.SetPixels(colors);
2828
if (apply) this.Apply();
2929
}
3030
public Color GetPixel(int x, int y)
3131
{
32-
return uTexture.GetPixel(x, uTexture.Height - y - 1);
32+
return Texture.GetPixel(x, Texture.Height - y - 1);
3333
}
3434
public Color[] GetPixels(int x, int y, int w, int h)
3535
{
36-
var ucs = uTexture.GetPixels(x, uTexture.Height - y - 1, w, h);
36+
var ucs = Texture.GetPixels(x, Texture.Height - y - 1, w, h);
3737
Color[] cs = new Color[ucs.Length];
3838
for (int i = 0; i < cs.Length; i++)
3939
cs[i] = ucs[i];
4040
return cs;
4141
}
4242
public void SetPixel(int x, int y, Color color)
4343
{
44-
uTexture.SetPixel(x, uTexture.Height - y - 1, color);
44+
Texture.SetPixel(x, Texture.Height - y - 1, color);
4545
}
4646

4747
internal static Bitmap FromTexture(ITexture tex)
4848
{
4949
var bmp = new Bitmap();
50-
bmp.uTexture = tex;
50+
bmp.Texture = tex;
5151

5252
return bmp;
5353
}

System/Drawing/Graphics.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void DrawImage(Image image, int x, int y, int width, int height)
5050
}
5151
public void DrawImage(Image image, float x, float y, float width, float height)
5252
{
53-
ApiGraphics.DrawImage(image, Color.White, x, y, width, height, 0);
53+
ApiGraphics.DrawImage(image, x, y, width, height, 0);
5454
}
5555
public void DrawLine(Pen pen, Point pt1, Point pt2)
5656
{
@@ -161,13 +161,16 @@ public SizeF MeasureString(string text, Font font)
161161

162162
internal static PointF[] GetBezierApproximation(PointF[] controlPoints, int outputSegmentCount)
163163
{
164-
if (outputSegmentCount <= 0) return null;
164+
if (outputSegmentCount <= 0)
165+
return new PointF[] {};
166+
165167
var points = new PointF[outputSegmentCount + 1];
166168
for (int i = 0; i <= outputSegmentCount; i++)
167169
{
168-
float t = (float)i / outputSegmentCount;
170+
float t = (float) i / outputSegmentCount;
169171
points[i] = GetBezierPoint(t, controlPoints, 0, controlPoints.Length);
170172
}
173+
171174
return points;
172175
}
173176
internal void GroupBegin(Control control)
@@ -188,7 +191,8 @@ internal void GroupEnd()
188191
#region Not original methods.
189192
internal void uwfDrawImage(Image image, Color color, float x, float y, float width, float height)
190193
{
191-
ApiGraphics.DrawImage(image, color, x, y, width, height, 0);
194+
image.Color = color;
195+
ApiGraphics.DrawImage(image, x, y, width, height, 0);
192196
}
193197
internal string uwfDrawPasswordField(string s, Font font, Color color, float x, float y, float width, float height, HorizontalAlignment alignment)
194198
{

System/Drawing/Image.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44

55
public abstract class Image
66
{
7-
public int Height { get { return uTexture.Height; } }
7+
internal Image()
8+
{
9+
Color = Color.White;
10+
}
11+
12+
public int Height { get { return Texture.Height; } }
813
public Size Size { get { return new Size(Width, Height); } }
914
public object Tag { get; set; }
10-
public int Width { get { return uTexture.Width; } }
15+
public int Width { get { return Texture.Width; } }
1116

12-
internal ITexture uTexture { get; set; }
17+
internal Color Color { get; set; }
18+
internal ITexture Texture { get; set; }
1319
}
1420
}

System/Drawing/Pen.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public Pen(Color color)
99
Color = color;
1010
Width = 1;
1111
}
12+
1213
public Pen(Color color, float width)
1314
{
1415
Color = color;
@@ -31,14 +32,16 @@ public object Clone()
3132
pen.Width = Width;
3233
return pen;
3334
}
35+
3436
public void Dispose()
3537
{
3638
Dispose(true);
3739
GC.SuppressFinalize(this);
3840
}
3941

40-
void Dispose(bool disposing)
42+
private void Dispose(bool disposing)
4143
{
44+
// Nothing to dispose.
4245
}
4346
}
4447
}

System/Drawing/Rectangle.cs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ public Rectangle(Point location, Size size) : this()
2121
Width = size.Width;
2222
Height = size.Height;
2323
}
24-
25-
public int Bottom { get { return Y + Height; } }
24+
25+
public int Bottom
26+
{
27+
get { return Y + Height; }
28+
}
2629
public int Height { get; set; }
2730
public bool IsEmpty
2831
{
2932
get { return X == 0 && Y == 0 && Width == 0 && Height == 0; }
3033
}
31-
public int Left { get { return X; } }
34+
public int Left
35+
{
36+
get { return X; }
37+
}
3238
public Point Location
3339
{
3440
get { return new Point(X, Y); }
@@ -38,7 +44,10 @@ public Point Location
3844
Y = value.Y;
3945
}
4046
}
41-
public int Right { get { return X + Width; } }
47+
public int Right
48+
{
49+
get { return X + Width; }
50+
}
4251
public Size Size
4352
{
4453
get { return new Size(Width, Height); }
@@ -48,11 +57,14 @@ public Size Size
4857
Height = value.Height;
4958
}
5059
}
51-
public int Top { get { return Y; } }
60+
public int Top
61+
{
62+
get { return Y; }
63+
}
5264
public int Width { get; set; }
5365
public int X { get; set; }
5466
public int Y { get; set; }
55-
67+
5668
public static bool operator !=(Rectangle left, Rectangle right)
5769
{
5870
return !(left == right);
@@ -84,9 +96,9 @@ public static Rectangle Intersect(Rectangle a, Rectangle b)
8496
int y1 = Math.Max(a.Y, b.Y);
8597
int y2 = Math.Min(a.Y + a.Height, b.Y + b.Height);
8698

87-
if (x2 >= x1 && y2 >= y1)
99+
if (x2 >= x1 && y2 >= y1)
88100
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
89-
101+
90102
return Empty;
91103
}
92104
public static Rectangle Union(Rectangle a, Rectangle b)
@@ -98,7 +110,7 @@ public static Rectangle Union(Rectangle a, Rectangle b)
98110

99111
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
100112
}
101-
113+
102114
public bool Contains(int x, int y)
103115
{
104116
return X <= x && x < X + Width && Y <= y && y < Y + Height;
@@ -117,8 +129,8 @@ public bool Equals(Rectangle other)
117129
}
118130
public override bool Equals(object obj)
119131
{
120-
if (obj is Rectangle == false) return false;
121-
var rect = (Rectangle)obj;
132+
if (!(obj is Rectangle)) return false;
133+
var rect = (Rectangle) obj;
122134
return rect.X == X && rect.Y == Y && rect.Width == Width && rect.Height == Height;
123135
}
124136
public override int GetHashCode()
@@ -163,8 +175,8 @@ public void Offset(int x, int y)
163175
public override string ToString()
164176
{
165177
return "{X=" + X.ToString(CultureInfo.CurrentCulture) + ",Y=" + Y.ToString(CultureInfo.CurrentCulture) +
166-
",Width=" + Width.ToString(CultureInfo.CurrentCulture) +
167-
",Height=" + Height.ToString(CultureInfo.CurrentCulture) + "}";
178+
",Width=" + Width.ToString(CultureInfo.CurrentCulture) +
179+
",Height=" + Height.ToString(CultureInfo.CurrentCulture) + "}";
168180
}
169181
}
170-
}
182+
}

System/Windows/Forms/Application.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void ProcessKeys(KeyEventArgs args, KeyEvents keyEventType)
120120
}
121121

122122
// Raise keys on selected controls if possible.
123-
if (Control.lastSelected != null && Control.lastSelected.IsDisposed == false)
123+
if (Control.lastSelected != null && !Control.lastSelected.IsDisposed)
124124
{
125125
var keyControl = Control.lastSelected;
126126

@@ -278,7 +278,7 @@ public void Update()
278278

279279
internal static bool ControlIsVisible(Control control)
280280
{
281-
if (control.Visible == false) return false;
281+
if (!control.Visible) return false;
282282

283283
var co = control.uwfOffset;
284284
var controlLocation = control.Location;
@@ -366,7 +366,7 @@ private static Control FindControlAt(Control currentControl, Point position)
366366
for (int i = currentControl.Controls.Count - 1; i >= 0; i--)
367367
{
368368
var child = currentControl.Controls[i];
369-
if (child.Visible == false || child.Enabled == false) continue;
369+
if (!child.Visible || !child.Enabled) continue;
370370

371371
// Base child bounds.
372372
var childOffset = child.uwfOffset;
@@ -495,7 +495,7 @@ private void RaiseKeyEvent(KeyEventArgs args, KeyEvents keyEventType, Control ke
495495
keyControl.RaiseOnKeyDown(args);
496496

497497
var lastChar = KeyHelper.GetLastInputChar();
498-
if (args.KeyCode == Keys.Space || args.KeyCode == Keys.Back || char.IsControl(lastChar) == false)
498+
if (args.KeyCode == Keys.Space || args.KeyCode == Keys.Back || !char.IsControl(lastChar))
499499
keyControl.RaiseOnKeyPress(new KeyPressEventArgs(lastChar));
500500

501501
break;
@@ -597,7 +597,7 @@ private void UpdateHoveredControl()
597597
else
598598
{
599599
hoveredControl = controlAtMouse;
600-
if (controlAtMouse.mouseEntered == false)
600+
if (!controlAtMouse.mouseEntered)
601601
{
602602
var mclient = controlAtMouse.PointToClient(Control.MousePosition);
603603

0 commit comments

Comments
 (0)