Game Development Reference
In-Depth Information
if (_placement == Placement::Place_Center)
{
int w, h;
MeasureString(&w, &h);
origin.x = w / 2.0f;
origin.y = h / 2.0f;
}
_font->DrawString(
sb.get(),
_text.data(),
_pos,
(focused && _canFocus) ? _focusCol : _color,
0.0F,
origin);
}
To draw the TextBlock we first need to make sure that there is text to render; oth-
erwise, we shouldn't bother. If there is, then we need to determine the origin point of
the text, which will allow us to implement our Placement functionality. In the case
of Place_TopLeft , we just stick with an origin of (0, 0) . The difference comes
when we handle Placement::Place_Center , which requires us to find the middle
of the TextBlock by measuring the string with our SpriteFont . Finally we draw
the string using the DrawString() method provided by our SpriteFont . At this
point we also check if the control is focused, so that we can apply the alternate focus
color if it is.
Let's finish up by digging deeper into the implementation of the PointInBounds()
method:
bool TextBlock::PointInBounds(float x, float y)
{
int width, height;
MeasureString(&width, &height);
float hw = (float)width / 2.0f;
float hh = (float)height / 2.0f;
Search WWH ::




Custom Search