From 30eb2baed93b772e47f15a5fa549f3426fdf468d Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Sun, 28 Aug 2016 11:25:22 +0200 Subject: [PATCH] [Horus] Bitmaps now scaled to fit both dimensions and centered in desired zone --- radio/src/gui/480x272/bitmapbuffer.h | 18 +++++++----------- radio/src/gui/480x272/radio_sdmanager.cpp | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/radio/src/gui/480x272/bitmapbuffer.h b/radio/src/gui/480x272/bitmapbuffer.h index 670fa8c17..190cc7317 100644 --- a/radio/src/gui/480x272/bitmapbuffer.h +++ b/radio/src/gui/480x272/bitmapbuffer.h @@ -256,17 +256,13 @@ class BitmapBuffer: public BitmapBufferBase template void drawScaledBitmap(const T * bitmap, coord_t x, coord_t y, coord_t w, coord_t h) { - coord_t bitmapWidth = bitmap->getWidth(); - - float scale = float(h) / bitmap->getHeight(); - int width = (0.5 + bitmapWidth) * scale; - if (width > w) { - int ww = (0.5 + w) / scale; - drawBitmap(x, y, bitmap, (bitmapWidth - ww)/2, 0, ww, 0, scale); - } - else { - drawBitmap(x+(w-width)/2, y, bitmap, 0, 0, 0, 0, scale); - } + float vscale = float(h) / bitmap->getHeight(); + float hscale = float(w) / bitmap->getWidth(); + float scale = vscale < hscale ? vscale : hscale; + + int xshift = (w - (bitmap->getWidth() * scale)) / 2; + int yshift = (h - (bitmap->getHeight() * scale)) / 2; + drawBitmap(x + xshift, y + yshift, bitmap, 0, 0, 0, 0, scale); } protected: diff --git a/radio/src/gui/480x272/radio_sdmanager.cpp b/radio/src/gui/480x272/radio_sdmanager.cpp index cf76096cf..ae0c0b72f 100644 --- a/radio/src/gui/480x272/radio_sdmanager.cpp +++ b/radio/src/gui/480x272/radio_sdmanager.cpp @@ -376,7 +376,7 @@ bool menuRadioSdManager(event_t _event) startx = (width - LCD_W/2) / 2; width = LCD_W/2; } - lcd->drawBitmap(LCD_W / 2 - 20 + LCD_W/4 - width/2, MENU_BODY_TOP + MENU_BODY_HEIGHT/2 - height/2, currentBitmap, startx, starty, width, height); + lcd->drawScaledBitmap(currentBitmap, LCD_W / 2 - 20 + LCD_W/4 - width/2, MENU_BODY_TOP + MENU_BODY_HEIGHT/2 - height/2, width, height); } }