mirror of
https://github.com/opentx/opentx.git
synced 2025-07-20 14:55:13 +03:00
[Horus] Bitmaps now scaled to fit both dimensions and centered in desired zone
This commit is contained in:
parent
504592ed18
commit
30eb2baed9
2 changed files with 8 additions and 12 deletions
|
@ -256,17 +256,13 @@ class BitmapBuffer: public BitmapBufferBase<uint16_t>
|
|||
template<class T>
|
||||
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:
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue