mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 16:55:20 +03:00
[Horus] Model bitmaps can now be either BMP or JPG or BMP
This commit is contained in:
parent
5822cfded1
commit
06bef98a05
9 changed files with 44 additions and 15 deletions
|
@ -480,7 +480,7 @@ void BitmapBuffer::drawBitmapPatternPie(coord_t x0, coord_t y0, const uint8_t *
|
|||
BitmapBuffer * BitmapBuffer::load(const char * filename)
|
||||
{
|
||||
const char * ext = getFileExtension(filename);
|
||||
if (!strcmp(ext, ".bmp"))
|
||||
if (ext && !strcmp(ext, ".bmp"))
|
||||
return load_bmp(filename);
|
||||
else
|
||||
return load_stb(filename);
|
||||
|
|
|
@ -362,7 +362,7 @@ 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 (ext && (!strcasecmp(ext, BMP_EXT) || !strcasecmp(ext, PNG_EXT) || !strcasecmp(ext, JPG_EXT))) {
|
||||
if (currentBitmapIndex != menuVerticalPosition) {
|
||||
currentBitmapIndex = menuVerticalPosition;
|
||||
delete currentBitmap;
|
||||
|
|
|
@ -258,7 +258,7 @@ bool menuModelSetup(evt_t event)
|
|||
lcdDrawTextAtIndex(MODEL_SETUP_2ND_COLUMN, y, STR_VCSWFUNC, 0, attr);
|
||||
if (attr && event==EVT_KEY_BREAK(KEY_ENTER) && READ_ONLY_UNLOCKED()) {
|
||||
s_editMode = 0;
|
||||
if (sdListFiles(BITMAPS_PATH, BITMAPS_EXT, sizeof(g_model.header.bitmap), g_model.header.bitmap, LIST_NONE_SD_FILE)) {
|
||||
if (sdListFiles(BITMAPS_PATH, BITMAPS_EXT, sizeof(g_model.header.bitmap), g_model.header.bitmap, LIST_NONE_SD_FILE | LIST_SD_FILE_EXT)) {
|
||||
POPUP_MENU_START(onModelSetupBitmapMenu);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -42,7 +42,7 @@ class ModelBitmapWidget: public Widget
|
|||
|
||||
if (buffer) {
|
||||
buffer->drawBitmap(0, 0, lcd, zone.x, zone.y, zone.w, zone.h);
|
||||
GET_FILENAME(filename, BITMAPS_PATH, g_model.header.bitmap, BITMAPS_EXT);
|
||||
GET_FILENAME(filename, BITMAPS_PATH, g_model.header.bitmap, "");
|
||||
BitmapBuffer * bitmap = BitmapBuffer::load(filename);
|
||||
if (zone.h >= 96 && zone.w >= 120) {
|
||||
buffer->drawFilledRect(0, 0, zone.w, zone.h, SOLID, MAINVIEW_PANES_COLOR | OPACITY(5));
|
||||
|
|
|
@ -222,7 +222,7 @@ const char * writeScreenshot()
|
|||
|
||||
char * tmp = strAppend(&filename[sizeof(SCREENSHOTS_PATH)-1], "/screen");
|
||||
tmp = strAppendDate(tmp, true);
|
||||
strcpy(tmp, BITMAPS_EXT);
|
||||
strcpy(tmp, BMP_EXT);
|
||||
|
||||
FRESULT result = f_open(&bmpFile, filename, FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (result != FR_OK) {
|
||||
|
|
|
@ -36,7 +36,7 @@ bool loadModelBitmap(char * name, uint8_t * bitmap)
|
|||
if (len > 0) {
|
||||
char lfn[] = BITMAPS_PATH "/xxxxxxxxxx.bmp";
|
||||
strncpy(lfn+sizeof(BITMAPS_PATH), name, len);
|
||||
strcpy(lfn+sizeof(BITMAPS_PATH)+len, BITMAPS_EXT);
|
||||
strcpy(lfn+sizeof(BITMAPS_PATH)+len, BMP_EXT);
|
||||
if (lcdLoadBitmap(bitmap, lfn, MODEL_BITMAP_WIDTH, MODEL_BITMAP_HEIGHT)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -91,6 +91,21 @@ int findNextFileIndex(char * filename, const char * directory)
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool isExtensionMatching(const char * extension, const char * pattern, uint8_t flags)
|
||||
{
|
||||
if (flags & LIST_SD_FILE_EXT) {
|
||||
for (int i=0; pattern[i]!='\0'; i+=LEN_FILE_EXTENSION) {
|
||||
if (strncasecmp(extension, &pattern[i], LEN_FILE_EXTENSION) == 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return strcasecmp(extension, pattern) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen, const char * selection, uint8_t flags)
|
||||
{
|
||||
FILINFO fno;
|
||||
|
@ -116,8 +131,10 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen
|
|||
strcpy(reusableBuffer.modelsel.menu_bss[0], path);
|
||||
strcat(reusableBuffer.modelsel.menu_bss[0], "/");
|
||||
strncat(reusableBuffer.modelsel.menu_bss[0], selection, maxlen);
|
||||
strcat(reusableBuffer.modelsel.menu_bss[0], extension);
|
||||
if (f_stat(reusableBuffer.modelsel.menu_bss[0], &fno) != FR_OK) {
|
||||
if (!(flags & LIST_SD_FILE_EXT)) {
|
||||
strcat(reusableBuffer.modelsel.menu_bss[0], extension);
|
||||
}
|
||||
if (f_stat(reusableBuffer.modelsel.menu_bss[0], &fno) != FR_OK || (fno.fattrib & AM_DIR)) {
|
||||
selection = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +176,7 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen
|
|||
lastpopupMenuOffset++;
|
||||
}
|
||||
else if (popupMenuOffset==0 || popupMenuOffset < lastpopupMenuOffset) {
|
||||
char *line = reusableBuffer.modelsel.menu_bss[0];
|
||||
char * line = reusableBuffer.modelsel.menu_bss[0];
|
||||
memset(line, 0, MENU_LINE_LENGTH);
|
||||
strcpy(line, "---");
|
||||
popupMenuItems[0] = line;
|
||||
|
@ -177,10 +194,14 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen
|
|||
#endif
|
||||
|
||||
uint8_t len = strlen(fn);
|
||||
if (len < 5 || len > maxlen+4 || strcasecmp(fn+len-4, extension) || (fno.fattrib & AM_DIR)) continue;
|
||||
uint8_t maxlen_with_extension = (flags & LIST_SD_FILE_EXT) ? maxlen : maxlen+LEN_FILE_EXTENSION;
|
||||
if (len < LEN_FILE_EXTENSION+1 || len > maxlen_with_extension || !isExtensionMatching(fn+len-LEN_FILE_EXTENSION, extension, flags) || (fno.fattrib & AM_DIR)) continue;
|
||||
|
||||
popupMenuNoItems++;
|
||||
fn[len-4] = '\0';
|
||||
|
||||
if (!(flags & LIST_SD_FILE_EXT)) {
|
||||
fn[len-LEN_FILE_EXTENSION] = '\0';
|
||||
}
|
||||
|
||||
if (popupMenuOffset == 0) {
|
||||
if (selection && strncasecmp(fn, selection, maxlen) < 0) {
|
||||
|
@ -188,7 +209,7 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen
|
|||
}
|
||||
else {
|
||||
for (uint8_t i=0; i<MENU_MAX_DISPLAY_LINES; i++) {
|
||||
char *line = reusableBuffer.modelsel.menu_bss[i];
|
||||
char * line = reusableBuffer.modelsel.menu_bss[i];
|
||||
if (line[0] == '\0' || strcasecmp(fn, line) < 0) {
|
||||
if (i < MENU_MAX_DISPLAY_LINES-1) memmove(reusableBuffer.modelsel.menu_bss[i+1], line, sizeof(reusableBuffer.modelsel.menu_bss[i]) * (MENU_MAX_DISPLAY_LINES-1-i));
|
||||
memset(line, 0, MENU_LINE_LENGTH);
|
||||
|
@ -204,7 +225,7 @@ bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen
|
|||
}
|
||||
else if (lastpopupMenuOffset == 0xffff) {
|
||||
for (int i=MENU_MAX_DISPLAY_LINES-1; i>=0; i--) {
|
||||
char *line = reusableBuffer.modelsel.menu_bss[i];
|
||||
char * line = reusableBuffer.modelsel.menu_bss[i];
|
||||
if (line[0] == '\0' || strcasecmp(fn, line) > 0) {
|
||||
if (i > 0) memmove(reusableBuffer.modelsel.menu_bss[0], reusableBuffer.modelsel.menu_bss[1], sizeof(reusableBuffer.modelsel.menu_bss[i]) * i);
|
||||
memset(line, 0, MENU_LINE_LENGTH);
|
||||
|
|
|
@ -53,7 +53,7 @@ const char RADIO_SETTINGS_PATH[] = RADIO_PATH "/radio.bin";
|
|||
#define MODELS_EXT ".bin"
|
||||
#define LOGS_EXT ".csv"
|
||||
#define SOUNDS_EXT ".wav"
|
||||
#define BITMAPS_EXT ".bmp"
|
||||
#define BMP_EXT ".bmp"
|
||||
#define PNG_EXT ".png"
|
||||
#define JPG_EXT ".jpg"
|
||||
#define SCRIPTS_EXT ".lua"
|
||||
|
@ -62,11 +62,18 @@ const char RADIO_SETTINGS_PATH[] = RADIO_PATH "/radio.bin";
|
|||
#define EEPROM_EXT ".bin"
|
||||
#define SPORT_FIRMWARE_EXT ".frk"
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
#define BITMAPS_EXT BMP_EXT JPG_EXT PNG_EXT
|
||||
#else
|
||||
#define BITMAPS_EXT BMP_EXT
|
||||
#endif
|
||||
|
||||
#define GET_FILENAME(filename, path, var, ext) \
|
||||
char filename[sizeof(path) + sizeof(var) + sizeof(ext)]; \
|
||||
memcpy(filename, path, sizeof(path) - 1); \
|
||||
filename[sizeof(path) - 1] = '/'; \
|
||||
memcpy(&filename[sizeof(path)], var, sizeof(var)); \
|
||||
filename[sizeof(path)+sizeof(var)] = '\0'; \
|
||||
strcat(&filename[sizeof(path)], ext)
|
||||
|
||||
extern FATFS g_FATFS_Obj;
|
||||
|
@ -124,6 +131,7 @@ const char * sdCopyFile(const char * src, const char * dest);
|
|||
const char * sdCopyFile(const char * srcFilename, const char * srcDir, const char * destFilename, const char * destDir);
|
||||
|
||||
#define LIST_NONE_SD_FILE 1
|
||||
#define LIST_SD_FILE_EXT 2
|
||||
bool sdListFiles(const char * path, const char * extension, const uint8_t maxlen, const char * selection, uint8_t flags=0);
|
||||
|
||||
#endif // _SDCARD_H_
|
||||
|
|
|
@ -51,7 +51,7 @@ class ModelCell
|
|||
for (int i=0; i<4; i++) {
|
||||
buffer.drawBitmapPattern(104+i*11, 25, LBM_SCORE0, TITLE_BGCOLOR);
|
||||
}
|
||||
GET_FILENAME(filename, BITMAPS_PATH, header.bitmap, BITMAPS_EXT);
|
||||
GET_FILENAME(filename, BITMAPS_PATH, header.bitmap, "");
|
||||
const BitmapBuffer * bitmap = BitmapBuffer::load(filename);
|
||||
if (bitmap) {
|
||||
buffer.drawScaledBitmap(bitmap, 5, 24, 56, 32);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue