-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathSampleControl.cs
More file actions
44 lines (38 loc) · 1.5 KB
/
Copy pathSampleControl.cs
File metadata and controls
44 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using SharpDX;
using SharpDX.Direct2D1;
using SharpDX.Mathematics.Interop;
using System;
namespace Sample {
class SampleControl : D2dControl.D2dControl {
private float x = 0;
private float y = 0;
private float w = 10;
private float h = 10;
private float dx = 1;
private float dy = 1;
private Random rnd = new Random();
public SampleControl() {
resCache.Add( "RedBrush" , t => new SolidColorBrush( t, new RawColor4( 1.0f, 0.0f, 0.0f, 1.0f ) ) );
resCache.Add( "GreenBrush", t => new SolidColorBrush( t, new RawColor4( 0.0f, 1.0f, 0.0f, 1.0f ) ) );
resCache.Add( "BlueBrush" , t => new SolidColorBrush( t, new RawColor4( 0.0f, 0.0f, 1.0f, 1.0f ) ) );
}
public override void Render( RenderTarget target ) {
target.Clear( new RawColor4( 1.0f, 1.0f, 1.0f, 1.0f ) );
Brush brush = null;
switch( rnd.Next( 3 ) ) {
case 0: brush = resCache["RedBrush" ] as Brush; break;
case 1: brush = resCache["GreenBrush"] as Brush; break;
case 2: brush = resCache["BlueBrush" ] as Brush; break;
}
target.DrawRectangle( new RawRectangleF( x, y, x + w, y + h ), brush );
x = x + dx;
y = y + dy;
if ( x >= ActualWidth - w || x <= 0 ) {
dx = -dx;
}
if ( y >= ActualHeight - h || y <= 0 ) {
dy = -dy;
}
}
}
}