Graphics Reference
In-Depth Information
three images, a mesh, and a quiver of arrows in this sample, we'll declare each
of those as an instance variable for the class. If you were to write a program that
needed to display only a single image, you'd delete all but one of these.
Listing 4.5: The C# portion of the
Window1
class definition.
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
45
46
47
48
49
50
51
52
53
using
...
namespace
Testbed2D
{
public
partial
class
Window1 : Window
{
GraphPaper gp =
null
;
Polygon myTriangle =
null
;
GImage myImage1 =
null
;
GImage myImage2 =
null
;
Mesh myMesh =
null
;
Quiver myQuiver =
null
;
// Are we ready for interactions like slider-changes to
// alter the parts of our display (like polygons or images
// or arrows)?
// Probably not until those things have been constructed!
bool
ready =
false
;
public
Window1()
{
InitializeComponent();
InitializeCommands();
// Now add some graphical items in the main Canvas,
// whose name is "GraphPaper"
gp =
this
.FindName(
"Paper"
)
as
GraphPaper;
// A triangle whose top point will be dragged
// by the slider.
myTriangle =
new
Polygon();
myTriangle.Points.Add(
new
Point(0, 10));
myTriangle.Points.Add(
new
Point(10, 0));
myTriangle.Points.Add(
new
Point(-10, 0));
myTriangle.Stroke = Brushes.Black;
myTriangle.StrokeThickness = 1.0;
// 1 mm thick line
myTriangle.Fill = Brushes.LightSeaGreen;
gp.Children.Add(myTriangle);
// A draggable Dot, which is the basepoint of an arrow.
Dot dd =
new
Dot(
new
Point(-40, 60));
dd.MakeDraggable(gp);
gp.Children.Add(dd);
Arrow ee =
new
Arrow(dd,
new
Point(10, 10),
Arrow.endtype.END);
gp.Children.Add(ee);
[lots more shape-creating code omitted]
ready =
true
;
// Now we're ready to have sliders and
// buttons influence the display.
}
[interaction-handling code omitted]
The constructor for
Window1
first initializes the component—a step that's
required for any top-level WPF window, causing all the subparts to be laid out;