1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 16:55:20 +03:00

PoC: nicer ModelBmp widget

This commit is contained in:
Raphael Coeffic 2021-04-05 15:01:49 +02:00
parent b54f01e0b7
commit ad15dfd170
2 changed files with 24 additions and 29 deletions

View file

@ -26,13 +26,31 @@ class ModelBitmapWidget: public Widget
ModelBitmapWidget(const WidgetFactory * factory, FormGroup * parent, const rect_t & rect, Widget::PersistentData * persistentData):
Widget(factory, parent, rect, persistentData)
{
loadBitmap();
}
void paint(BitmapBuffer * dc) override
{
if (buffer)
dc->drawBitmap(0, 0, buffer.get());
// big space to draw
if (rect.h >= 96 && rect.w >= 120) {
dc->drawFilledRect(0, 0, rect.w, rect.h, SOLID, MAINVIEW_PANES_COLOR | OPACITY(5));
auto iconMask = theme->getIconMask(ICON_MODEL);
if (iconMask) {
dc->drawMask(6, 4, iconMask, MAINVIEW_GRAPHICS_COLOR);
}
dc->drawSizedText(45, 10, g_model.header.name, LEN_MODEL_NAME, FONT(XS));
dc->drawSolidFilledRect(39, 27, rect.w - 48, 2, MAINVIEW_GRAPHICS_COLOR);
if (buffer) {
dc->drawScaledBitmap(buffer.get(), 0, 38, rect.w, rect.h - 38);
}
}
// smaller space to draw
else if (buffer) {
dc->drawScaledBitmap(buffer.get(), 0, 0, rect.w, rect.h);
}
}
void checkEvents() override
@ -55,37 +73,14 @@ class ModelBitmapWidget: public Widget
void loadBitmap()
{
buffer.reset(new BitmapBuffer(BMP_RGB565, rect.w, rect.h));
buffer->clear(MAINVIEW_PANES_COLOR);
std::string filename = std::string(g_model.header.bitmap);
std::string fullpath = std::string(BITMAPS_PATH PATH_SEPARATOR) + filename;
auto bitmap = std::unique_ptr<BitmapBuffer>(BitmapBuffer::loadBitmap(fullpath.c_str()));
if (!bitmap) {
buffer.reset(BitmapBuffer::loadBitmap(fullpath.c_str()));
if (!buffer) {
TRACE("could not load bitmap '%s'", filename.c_str());
return;
}
// big space to draw
if (rect.h >= 96 && rect.w >= 120) {
auto iconMask = theme->getIconMask(ICON_MODEL);
if (iconMask) {
buffer->drawMask(6, 4, iconMask, MAINVIEW_GRAPHICS_COLOR);
}
buffer->drawSizedText(45, 10, g_model.header.name, LEN_MODEL_NAME, FONT(XS));
buffer->drawSolidFilledRect(39, 27, rect.w - 48, 2, MAINVIEW_GRAPHICS_COLOR);
if (bitmap) {
buffer->drawScaledBitmap(bitmap.get(), 0, 38, rect.w, rect.h - 38);
}
}
// smaller space to draw
else if (bitmap) {
buffer->drawScaledBitmap(bitmap.get(), 0, 0, rect.w, rect.h);
}
}
};

@ -1 +1 @@
Subproject commit db3a6342b85cd17bf0b6a0aa2021b68ffef470d9
Subproject commit a106ff4ff7b0437fbd9b43c24546df93049f3e57