本文整理汇总了C++中CFont::Width方法的典型用法代码示例。如果您正苦于以下问题:C++ CFont::Width方法的具体用法?C++ CFont::Width怎么用?C++ CFont::Width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFont
的用法示例。
在下文中一共展示了CFont::Width方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Draw
/**
** Draw text with variable.
**
** @param unit unit with variable to show.
** @param defaultfont default font if no specific font in extra data.
*/
void CContentTypeText::Draw(const CUnit *unit, CFont *defaultfont) const
{
char *text; // Optional text to display.
CFont *font; // Font to use.
int x; // X coordinate to display.
int y; // Y coordinate to display.
x = this->PosX;
y = this->PosY;
font = this->Font ? this->Font : defaultfont;
Assert(font);
Assert(unit || this->Index == -1);
Assert(this->Index == -1 || (0 <= this->Index && this->Index < UnitTypeVar.NumberVariable));
if (this->Text) {
text = EvalString(this->Text);
if (this->Centered) {
VideoDrawTextCentered(x, y, font, text);
} else {
VideoDrawText(x, y, font, text);
}
x += font->Width(text);
delete[] text;
}
if (this->ShowName) {
VideoDrawTextCentered(x, y, font, unit->Type->Name);
return;
}
if (this->Index != -1) {
if (!this->Stat) {
EnumVariable component = this->Component;
switch (component) {
case VariableValue:
case VariableMax:
case VariableIncrease:
case VariableDiff:
case VariablePercent:
VideoDrawNumber(x, y, font, GetComponent(unit, this->Index, component, 0).i);
break;
case VariableName:
VideoDrawText(x, y, font, GetComponent(unit, this->Index, component, 0).s);
break;
default:
Assert(0);
}
} else {
int value = unit->Type->Variable[this->Index].Value;
int diff = unit->Stats->Variables[this->Index].Value - value;
if (!diff) {
VideoDrawNumber(x, y, font, value);
} else {
char buf[64];
sprintf(buf, diff > 0 ? "%d~<+%d~>" : "%d~<-%d~>", value, diff);
VideoDrawText(x, y, font, buf);
}
}
}
}