Add <image> tag support

This commit is contained in:
Martín Capello 2021-09-06 12:16:53 -03:00
parent 3da532453c
commit e6d0c1858a
2 changed files with 22 additions and 12 deletions

View File

@ -487,21 +487,28 @@ Widget* WidgetLoader::convertXmlElementToWidget(const TiXmlElement* elem, Widget
else if (elem_name == "image") {
if (!widget) {
const char* file = elem->Attribute("file");
const char* icon = elem->Attribute("icon");
// Load image
std::string icon(file);
if (file) {
ResourceFinder rf;
rf.includeDataDir(file);
if (!rf.findFirst())
throw base::Exception("File %s not found", file);
ResourceFinder rf;
rf.includeDataDir(file);
if (!rf.findFirst())
throw base::Exception("File %s not found", file);
try {
os::SurfaceRef sur = os::instance()->loadRgbaSurface(rf.filename().c_str());
widget = new ImageView(sur, 0);
try {
os::SurfaceRef sur = os::instance()->loadRgbaSurface(rf.filename().c_str());
widget = new ImageView(sur, 0);
}
catch (...) {
throw base::Exception("Error loading %s file", file);
}
}
catch (...) {
throw base::Exception("Error loading %s file", file);
if (icon) {
SkinPartPtr part = SkinTheme::instance()->getPartById(std::string(icon));
if (part) {
widget = new ImageView(part->bitmapRef(0), 0);
}
}
}
}

View File

@ -116,6 +116,9 @@ static Item convert_to_item(TiXmlElement* elem)
if (name == "hbox")
return item.typeIncl("ui::HBox",
"ui/box.h");
if (name == "image")
return item.typeIncl("ui::ImageView",
"ui/image_view.h");
if (name == "item" &&
parent == "buttonset")
return item.typeIncl("app::ButtonSet::Item",