Game Development Reference
In-Depth Information
parameters. These are all float values in the range of 0.0 to 1.0 as well. As you
can see for the red brush, we set the red channel to 1.0f and the green and blue
channels are both set to 0.0f . This means we have maximum red, but no green or
blue in our color.
With our SolidColorBrush objects set up, we now have three brushes we can
draw with, but we still lack something to draw! So, let's fix that by adding some code
to make our rectangle. Add this code to the end of the constructor:
m_Geometry = new
PathGeometry(m_RenderTarget.Factory);
using (GeometrySink sink = m_Geometry.Open())
{
int top = (int) (0.25f * FormObject.Height);
int left = (int) (0.25f * FormObject.Width);
int right = (int) (0.75f *
FormObject.Width);
int bottom = (int) (0.75f *
FormObject.Height);
PointF p0 = new Point(left, top);
PointF p1 = new Point(right, top);
PointF p2 = new Point(right, bottom);
PointF p3 = new Point(left, bottom);
sink.BeginFigure(p0, FigureBegin.Filled);
sink.AddLine(p1);
sink.AddLine(p2);
sink.AddLine(p3);
sink.EndFigure(FigureEnd.Closed);
sink.Close();
}
This code is a bit longer, but it's still fairly simple. The first line creates a new
PathGeometry object and stores it in our m_Geometry member variable. The next
line starts the using block and creates a new GeometrySink object that we will
Search WWH ::




Custom Search