Skip to content

Commit bcab583

Browse files
committed
DXControl: made all private vars to protected
1 parent 09dc8ef commit bcab583

File tree

2 files changed

+37
-32
lines changed

2 files changed

+37
-32
lines changed

Source/DXControl/DXControl.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,30 @@ namespace D2Phap;
1515
/// </summary>
1616
public class DXControl : Control
1717
{
18-
// Private properties
19-
#region Private properties
18+
// Internal properties
19+
#region Internal properties
2020

21-
private bool _isControlLoaded = false;
22-
private float _dpi = 96.0f;
23-
private readonly VerticalBlankTicker _ticker = new();
21+
protected bool _isControlLoaded = false;
22+
protected float _dpi = 96.0f;
23+
protected readonly VerticalBlankTicker _ticker = new();
2424

2525
// Protected properties
26-
private readonly IComObject<ID2D1Factory> _d2DFactory = D2D1Functions.D2D1CreateFactory(D2D1_FACTORY_TYPE.D2D1_FACTORY_TYPE_SINGLE_THREADED);
27-
private readonly IComObject<IDWriteFactory> _dWriteFactory = DWriteFunctions.DWriteCreateFactory(DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_SHARED);
28-
private ID2D1HwndRenderTarget? _renderTarget;
29-
private ID2D1DeviceContext? _device;
30-
private D2DGraphics? _graphicsD2d;
31-
private GdipGraphics? _graphicsGdi;
32-
33-
34-
private bool _useHardwardAcceleration = true;
35-
private bool _firstPaintBackground = true;
36-
private bool _enableAnimation = true;
37-
private int _currentFps = 0;
38-
private int _lastFps = 0;
39-
private DateTime _lastFpsUpdate = DateTime.UtcNow;
40-
41-
#endregion // Private properties
26+
protected readonly IComObject<ID2D1Factory> _d2DFactory = D2D1Functions.D2D1CreateFactory(D2D1_FACTORY_TYPE.D2D1_FACTORY_TYPE_SINGLE_THREADED);
27+
protected readonly IComObject<IDWriteFactory> _dWriteFactory = DWriteFunctions.DWriteCreateFactory(DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_SHARED);
28+
protected ID2D1HwndRenderTarget? _renderTarget;
29+
protected ID2D1DeviceContext? _device;
30+
protected D2DGraphics? _graphicsD2d;
31+
protected GdipGraphics? _graphicsGdi;
32+
33+
34+
protected bool _useHardwardAcceleration = true;
35+
protected bool _firstPaintBackground = true;
36+
protected bool _enableAnimation = true;
37+
protected int _currentFps = 0;
38+
protected int _lastFps = 0;
39+
protected DateTime _lastFpsUpdate = DateTime.UtcNow;
40+
41+
#endregion // Internal properties
4242

4343

4444
// Public properties

Source/Demo/DXCanvas.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Demo;
1313
public class DXCanvas : DXControl
1414
{
1515
private IComObject<ID2D1Bitmap>? _bitmapD2d = null;
16-
private Rectangle rectText = new(100, 100, 0, 200);
16+
private Rectangle rectText = new(40, 40, 300, 200);
1717

1818
public WicBitmapSource? Image
1919
{
@@ -100,19 +100,11 @@ protected override void OnRender(IGraphics g)
100100
g.DrawRectangle(ClientSize.Width / 1.5f, ClientSize.Height / 1.5f, 300, 100,
101101
20f, Color.LightCyan, Color.FromArgb(180, Color.Cyan), 3f);
102102

103-
104-
// draw and fill rectangle
105-
g.DrawRectangle(rectText, 0, Color.Green, Color.FromArgb(100, Color.Yellow));
106-
107-
// draw text
108-
g.DrawText($"Dương Diệu Pháp 😛💋", Font.Name, 9, rectText,
109-
Color.Lavender, DeviceDpi, StringAlignment.Center, isBold: true, isItalic: true);
110-
111-
112103
// draw and fill ellipse
113104
g.DrawEllipse(200, 200, 300, 200, Color.FromArgb(120, Color.Magenta), Color.Purple, 5);
114105

115106

107+
// draw geometry D2D only
116108
if (UseHardwareAcceleration && g is D2DGraphics dg)
117109
{
118110
using var geo = dg.GetCombinedRectanglesGeometry(new RectangleF(200, 300, 300, 300),
@@ -125,6 +117,19 @@ protected override void OnRender(IGraphics g)
125117
}
126118

127119

120+
// draw and fill rectangle
121+
g.DrawRectangle(rectText, 0, Color.Green, Color.FromArgb(100, Color.Yellow));
122+
123+
124+
// draw text
125+
var text = "Dương\r\nDiệu\r\nPháp\r\n😵🪺🐷😶‍🌫️🤯🫶🏿";
126+
var textSize = g.MeasureText(text, Font.Name, 12, textDpi: DeviceDpi, isBold: true, isItalic: true);
127+
g.DrawText($"{text}\r\n{textSize}", Font.Name, 12, rectText,
128+
Color.Red, DeviceDpi, StringAlignment.Near, isBold: true, isItalic: true);
129+
g.DrawRectangle(new RectangleF(rectText.Location, textSize), 0, Color.Red);
130+
131+
132+
// draw FPD info
128133
var engine = UseHardwareAcceleration ? "GPU" : "GDI+";
129134
g.DrawText($"FPS: {FPS} - {engine}", Font.Name, 18, 0, 0, Color.Purple, DeviceDpi);
130135

@@ -134,6 +139,6 @@ protected override void OnRender(IGraphics g)
134139
protected override void OnFrame(FrameEventArgs e)
135140
{
136141
base.OnFrame(e);
137-
rectText.Width++;
142+
//rectText.Width++;
138143
}
139144
}

0 commit comments

Comments
 (0)