[Horus] Bitmaps dynamic load

This commit is contained in:
Bertrand Songis
2016-02-21 18:25:52 +01:00
parent 63713578fe
commit 358badfed9
12 changed files with 117 additions and 99 deletions
+2 -7
View File
@@ -58,13 +58,8 @@
#define MENU_ICONS_SPACING 31
#define SUBMENU_LINE_WIDTH 230
#define BITMAP_BUFFER_SIZE(width, height) (4 + (width)*(height)*3)
#define MODEL_BITMAP_WIDTH (3*64)
#define MODEL_BITMAP_HEIGHT (3*32)
#define MODEL_BITMAP_SIZE BITMAP_BUFFER_SIZE(MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)
extern uint8_t modelBitmap[MODEL_BITMAP_SIZE];
bool loadModelBitmap(char * name, uint8_t * bitmap);
#define LOAD_MODEL_BITMAP() loadModelBitmap(g_model.header.bitmap, modelBitmap)
#define BITMAP_BUFFER_SIZE(w, h) (4 + (w)*(h)*3)
#define LOAD_MODEL_BITMAP()
#if defined(FLIGHT_MODES)
void displayFlightModes(coord_t x, coord_t y, FlightModesType value, uint8_t attr);
+1 -1
View File
@@ -324,7 +324,7 @@ void lcdDrawAlphaBitmap(coord_t x, coord_t y, const uint8_t * bmp);
void lcdSetContrast();
#define lcdOff(...)
const char * bmpLoad(uint8_t * dest, const char * filename, uint16_t width, uint16_t height);
uint8_t * bmpLoad(const char * filename);
const char * imgLoad(uint8_t * dest, const char * filename, uint16_t width, uint16_t height);
#if defined(BOOT)
+11 -8
View File
@@ -21,12 +21,13 @@
#include <stdio.h>
#include "../../opentx.h"
#define REFRESH_FILES() do { reusableBuffer.sdmanager.offset = 65535; lastBitmap = -1; } while (0)
#define REFRESH_FILES() do { reusableBuffer.sdmanager.offset = 65535; currentBitmapIndex = -1; } while (0)
#define NODE_TYPE(fname) fname[SD_SCREEN_FILE_LENGTH+1]
#define IS_DIRECTORY(fname) ((bool)(!NODE_TYPE(fname)))
#define IS_FILE(fname) ((bool)(NODE_TYPE(fname)))
int lastBitmap;
int currentBitmapIndex = 0;
uint8_t * currentBitmap = NULL;
bool menuGeneralSdManagerInfo(evt_t event)
{
@@ -362,13 +363,15 @@ bool menuGeneralSdManager(evt_t _event)
char * ext = getFileExtension(reusableBuffer.sdmanager.lines[index], SD_SCREEN_FILE_LENGTH+1);
if (ext && (!strcasecmp(ext, BITMAPS_EXT) || !strcasecmp(ext, PNG_EXT) || !strcasecmp(ext, JPG_EXT))) {
if (lastBitmap != menuVerticalPosition) {
lastBitmap = menuVerticalPosition;
if (bmpLoad(modelBitmap, reusableBuffer.sdmanager.lines[index], MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) {
((uint32_t *)modelBitmap)[0] = 0;
}
if (currentBitmapIndex != menuVerticalPosition) {
currentBitmapIndex = menuVerticalPosition;
free(currentBitmap);
currentBitmap = bmpLoad(reusableBuffer.sdmanager.lines[index]);
}
if (currentBitmap) {
// TODO scale in case of a too large bitmap
lcdDrawBitmap(LCD_W / 2, LCD_H / 2, currentBitmap);
}
lcdDrawBitmap(LCD_W/2, (LCD_H-MODEL_BITMAP_HEIGHT)/2, modelBitmap);
}
return true;
+4 -2
View File
@@ -61,8 +61,10 @@ void drawModel(coord_t x, coord_t y, const char * name, bool selected)
for (int i=0; i<4; i++) {
lcdDrawBitmapPattern(x+104+i*11, y+25, LBM_SCORE0, TITLE_BGCOLOR);
}
if (loadModelBitmap(header.bitmap, modelBitmap)) {
lcdDrawBitmap(x+5, y+24, modelBitmap, 0, 0, getBitmapScale(modelBitmap, 64, 32));
uint8_t * bitmap = bmpLoad(header.bitmap);
if (bitmap) {
lcdDrawBitmap(x+5, y+24, bitmap, 0, 0, getBitmapScale(bitmap, 64, 32));
free(bitmap);
}
else {
lcdDrawBitmapPattern(x+5, y+23, LBM_LIBRARY_SLOT, TEXT_COLOR);
-3
View File
@@ -77,8 +77,6 @@ enum menuModelSetupItems {
ITEM_MODEL_SETUP_MAX
};
#define FIELD_PROTOCOL_MAX 1
#define MODEL_SETUP_2ND_COLUMN 200
#define MODEL_SETUP_BIND_OFS 40
#define MODEL_SETUP_RANGE_OFS 80
@@ -94,7 +92,6 @@ void onModelSetupBitmapMenu(const char *result)
else {
// The user choosed a bmp file in the list
copySelection(g_model.header.bitmap, result, sizeof(g_model.header.bitmap));
loadModelBitmap(g_model.header.bitmap, modelBitmap);
storageDirty(EE_MODEL);
}
}
+1 -1
View File
@@ -173,7 +173,7 @@ const char * displayPopupMenu(evt_t event)
}
if (popupMenuNoItems > display_count) {
drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, POPUP_MENU_MAX_LINES * (FH+1), popupMenuOffset, popupMenuNoItems, POPUP_MENU_MAX_LINES);
drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_DISPLAY_LINES * (FH+1), popupMenuOffset, popupMenuNoItems, MENU_MAX_DISPLAY_LINES);
}
return result;
+38 -11
View File
@@ -24,30 +24,57 @@ class ModelBitmapWidget: public Widget
{
public:
ModelBitmapWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
Widget(factory, zone, persistentData)
Widget(factory, zone, persistentData),
bitmap(NULL)
{
memset(bitmapFilename, 0, sizeof(bitmapFilename));
}
void loadBitmap()
{
char filename[] = BITMAPS_PATH "/xxxxxxxxxx.bmp";
strncpy(filename+sizeof(BITMAPS_PATH), g_model.header.bitmap, sizeof(g_model.header.bitmap));
strcat(filename+sizeof(BITMAPS_PATH), BITMAPS_EXT);
bitmap = bmpLoad(filename);
memcpy(bitmapFilename, g_model.header.bitmap, sizeof(g_model.header.bitmap));
// TODO rescale the bitmap here instead of every refresh!
}
virtual ~ModelBitmapWidget()
{
free(bitmap);
}
virtual void refresh();
protected:
char bitmapFilename[sizeof(g_model.header.bitmap)];
uint8_t * bitmap;
};
void ModelBitmapWidget::refresh()
{
if (zone.h >= MODEL_BITMAP_HEIGHT) {
if (memcmp(bitmapFilename, g_model.header.bitmap, sizeof(g_model.header.bitmap)) != 0) {
loadBitmap();
}
if (zone.h >= 96) {
lcdDrawFilledRect(zone.x, zone.y, zone.w, zone.h, SOLID, MAINVIEW_PANES_COLOR | OPACITY(5));
lcdDrawBitmapPattern(zone.x + 6, zone.y + 4, LBM_MODEL_ICON, MAINVIEW_GRAPHICS_COLOR);
lcdDrawSizedText(zone.x + 45, zone.y + 10, g_model.header.name, LEN_MODEL_NAME, ZCHAR | SMLSIZE);
lcdDrawSolidFilledRect(zone.x + 39, zone.y + 27, zone.w - 48, 2, MAINVIEW_GRAPHICS_COLOR);
float scale = getBitmapScale(modelBitmap, zone.w, zone.h - 25);
int width = getBitmapScaledSize(getBitmapWidth(modelBitmap), scale);
int height = getBitmapScaledSize(getBitmapHeight(modelBitmap), scale);
lcdDrawBitmap(zone.x + (zone.w - width) / 2, zone.y + zone.h - height / 2 - height / 2, modelBitmap, 0, 0, scale);
if (bitmap) {
float scale = getBitmapScale(bitmap, zone.w, zone.h - 25);
int width = getBitmapScaledSize(getBitmapWidth(bitmap), scale);
int height = getBitmapScaledSize(getBitmapHeight(bitmap), scale);
lcdDrawBitmap(zone.x + (zone.w - width) / 2, zone.y + zone.h - height / 2 - height / 2, bitmap, 0, 0, scale);
}
}
else {
float scale = getBitmapScale(modelBitmap, 1000, zone.h);
int width = getBitmapScaledSize(getBitmapWidth(modelBitmap), scale);
int height = getBitmapScaledSize(getBitmapHeight(modelBitmap), scale);
lcdDrawBitmap(zone.x + (zone.w - width) / 2, zone.y + (zone.h - height) / 2, modelBitmap, 0, 0, scale);
else if (bitmap) {
float scale = getBitmapScale(bitmap, 1000, zone.h);
int width = getBitmapScaledSize(getBitmapWidth(bitmap), scale);
int height = getBitmapScaledSize(getBitmapHeight(bitmap), scale);
lcdDrawBitmap(zone.x + (zone.w - width) / 2, zone.y + (zone.h - height) / 2, bitmap, 0, 0, scale);
}
}