本文整理汇总了C++中ImageResource::GetResource方法的典型用法代码示例。如果您正苦于以下问题:C++ ImageResource::GetResource方法的具体用法?C++ ImageResource::GetResource怎么用?C++ ImageResource::GetResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImageResource
的用法示例。
在下文中一共展示了ImageResource::GetResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadResources
void ResourceManager::LoadResources(xml_node<>* resList, ZipArchive* pZip)
{
xml_node<>* child;
if (!resList)
return;
child = resList->first_node("resource");
while (child != NULL)
{
xml_attribute<>* attr = child->first_attribute("type");
if (!attr)
break;
std::string type = attr->value();
if (type == "font")
{
FontResource* res = new FontResource(child, pZip);
if (res == NULL || res->GetResource() == NULL)
{
xml_attribute<>* attr_name = child->first_attribute("name");
if (!attr_name) {
std::string res_name = attr_name->value();
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
} else
LOGERR("Resource type (%s) failed to load\n", type.c_str());
delete res;
}
else
{
mResources.push_back((Resource*) res);
}
}
else if (type == "image")
{
ImageResource* res = new ImageResource(child, pZip);
if (res == NULL || res->GetResource() == NULL)
{
xml_attribute<>* attr_name = child->first_attribute("name");
if (!attr_name) {
std::string res_name = attr_name->value();
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
} else
LOGERR("Resource type (%s) failed to load\n", type.c_str());
delete res;
}
else
{
mResources.push_back((Resource*) res);
}
}
else if (type == "animation")
{
AnimationResource* res = new AnimationResource(child, pZip);
if (res == NULL || res->GetResource() == NULL)
{
xml_attribute<>* attr_name = child->first_attribute("name");
if (!attr_name) {
std::string res_name = attr_name->value();
LOGERR("Resource (%s)-(%s) failed to load\n", type.c_str(), res_name.c_str());
} else
LOGERR("Resource type (%s) failed to load\n", type.c_str());
delete res;
}
else
{
mResources.push_back((Resource*) res);
}
}
else
{
LOGERR("Resource type (%s) not supported.\n", type.c_str());
}
child = child->next_sibling("resource");
}
}
示例2: DrawKey
void GUIKeyboard::DrawKey(Key& key, int keyX, int keyY, int keyW, int keyH)
{
unsigned char keychar = key.key;
if (!keychar)
return;
// key background
COLOR& c = (keychar >= 32 && keychar < 127) ? mKeyColorAlphanumeric : mKeyColorOther;
gr_color(c.red, c.green, c.blue, c.alpha);
keyX += mKeyMarginX;
keyY += mKeyMarginY;
keyW -= mKeyMarginX * 2;
keyH -= mKeyMarginY * 2;
gr_fill(keyX, keyY, keyW, keyH);
// key label
FontResource* labelFont = mFont;
string labelText;
ImageResource* labelImage = NULL;
if (keychar > 32 && keychar < 127) {
labelText = (char) keychar;
gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, mFontColor.alpha);
}
else {
// search for a special key label
for (std::vector<KeyLabel>::iterator it = mKeyLabels.begin(); it != mKeyLabels.end(); ++it) {
if (it->layout_from > 0 && it->layout_from != currentLayout)
continue; // this label is for another layout
if (it->key == key.key && it->layout_to == key.layout)
{
// found a label
labelText = it->text;
labelImage = it->image;
break;
}
}
labelFont = mSmallFont;
gr_color(mFontColorSmall.red, mFontColorSmall.green, mFontColorSmall.blue, mFontColorSmall.alpha);
}
if (labelImage)
{
int w = labelImage->GetWidth();
int h = labelImage->GetHeight();
int x = keyX + (keyW - w) / 2;
int y = keyY + (keyH - h) / 2;
gr_blit(labelImage->GetResource(), 0, 0, w, h, x, y);
}
else if (!labelText.empty())
{
void* fontResource = labelFont->GetResource();
int textW = gr_measureEx(labelText.c_str(), fontResource);
int textH = labelFont->GetHeight();
int textX = keyX + (keyW - textW) / 2;
int textY = keyY + (keyH - textH) / 2;
gr_textEx(textX, textY, labelText.c_str(), fontResource);
}
// longpress key label (only if font is defined)
keychar = key.longpresskey;
if (keychar > 32 && keychar < 127 && mLongpressFont->GetResource()) {
void* fontResource = mLongpressFont->GetResource();
gr_color(mLongpressFontColor.red, mLongpressFontColor.green, mLongpressFontColor.blue, mLongpressFontColor.alpha);
string text(1, keychar);
int textH = mLongpressFont->GetHeight();
int textW = gr_measureEx(text.c_str(), fontResource);
int textX = keyX + keyW - longpressOffsetX - textW;
int textY = keyY + longpressOffsetY;
gr_textEx(textX, textY, text.c_str(), fontResource);
}
}