From e6d0c1858aaa2d53ac32e07c198a4ae1fe2e33c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Mon, 6 Sep 2021 12:16:53 -0300 Subject: [PATCH] Add tag support --- src/app/widget_loader.cpp | 31 +++++++++++++++++++------------ src/gen/ui_class.cpp | 3 +++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/app/widget_loader.cpp b/src/app/widget_loader.cpp index 8e971786d..b1d62c285 100644 --- a/src/app/widget_loader.cpp +++ b/src/app/widget_loader.cpp @@ -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); + } } } } diff --git a/src/gen/ui_class.cpp b/src/gen/ui_class.cpp index 1e8d97425..1f80b64ee 100644 --- a/src/gen/ui_class.cpp +++ b/src/gen/ui_class.cpp @@ -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",