mirror of
https://github.com/opentx/opentx.git
synced 2025-07-24 00:35:18 +03:00
[Horus] MODELSEL screen continued
This commit is contained in:
parent
0db2013d24
commit
683f6e22e2
10 changed files with 76 additions and 41 deletions
|
@ -175,7 +175,7 @@ int getTextWidth(const pm_char * s, int len, LcdFlags flags)
|
||||||
if (flags & ZCHAR)
|
if (flags & ZCHAR)
|
||||||
c = idx2char(*s);
|
c = idx2char(*s);
|
||||||
else
|
else
|
||||||
c = pgm_read_byte(s);
|
c = *s;
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
break;
|
break;
|
||||||
result += getCharWidth(c, specs);
|
result += getCharWidth(c, specs);
|
||||||
|
|
|
@ -205,10 +205,10 @@ void editName(coord_t x, coord_t y, char * name, uint8_t size, evt_t event, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
lcdDrawTextWithLen(x, y, name, size, flags);
|
lcdDrawTextWithLen(x, y, name, size, flags);
|
||||||
coord_t w = (editNameCursorPos == 0 ? 0 : getTextWidth(name, editNameCursorPos, flags));
|
coord_t left = (editNameCursorPos == 0 ? 0 : getTextWidth(name, editNameCursorPos, flags));
|
||||||
char s[] = { (flags & ZCHAR) ? idx2char(name[editNameCursorPos]) : name[editNameCursorPos], '\0' };
|
char s[] = { (flags & ZCHAR) ? idx2char(name[editNameCursorPos]) : name[editNameCursorPos], '\0' };
|
||||||
lcdDrawSolidFilledRect(x+w-1, y-INVERT_VERT_MARGIN, getTextWidth(s, 1, flags)+1, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
|
lcdDrawSolidFilledRect(x+left-1, y-INVERT_VERT_MARGIN, getTextWidth(s, 1)+1, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
|
||||||
lcdDrawText(x+w, y, s, TEXT_INVERTED_COLOR);
|
lcdDrawText(x+left, y, s, TEXT_INVERTED_COLOR);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
editNameCursorPos = 0;
|
editNameCursorPos = 0;
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include "../../opentx.h"
|
#include "../../opentx.h"
|
||||||
|
|
||||||
#define CATEGORIES_WIDTH 140
|
#define CATEGORIES_WIDTH 140
|
||||||
|
|
||||||
#define MODELCELL_WIDTH 153
|
#define MODELCELL_WIDTH 153
|
||||||
#define MODELCELL_HEIGHT 61
|
#define MODELCELL_HEIGHT 61
|
||||||
|
|
||||||
|
@ -54,10 +53,10 @@ char selectedCategory[LEN_MODEL_FILENAME+1];
|
||||||
void drawCategory(coord_t y, const char * name, bool selected)
|
void drawCategory(coord_t y, const char * name, bool selected)
|
||||||
{
|
{
|
||||||
if (selected) {
|
if (selected) {
|
||||||
lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH, INVERT_LINE_HEIGHT, HEADER_BGCOLOR);
|
lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH, INVERT_LINE_HEIGHT+2, HEADER_BGCOLOR);
|
||||||
lcdDrawBitmapPattern(CATEGORIES_WIDTH-12, y, LBM_LIBRARY_CURSOR, MENU_TITLE_COLOR);
|
lcdDrawBitmapPattern(CATEGORIES_WIDTH-12, y, LBM_LIBRARY_CURSOR, MENU_TITLE_COLOR);
|
||||||
if (selectMode == MODE_SELECT_CATEGORY) {
|
if (selectMode == MODE_SELECT_CATEGORY) {
|
||||||
drawShadow(0, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH, INVERT_LINE_HEIGHT);
|
drawShadow(0, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH, INVERT_LINE_HEIGHT+2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lcdDrawText(MENUS_MARGIN_LEFT, y, name, MENU_TITLE_COLOR);
|
lcdDrawText(MENUS_MARGIN_LEFT, y, name, MENU_TITLE_COLOR);
|
||||||
|
@ -81,7 +80,7 @@ void drawModel(coord_t x, coord_t y, const char * name, bool selected)
|
||||||
lcdDrawBitmap(x+5, y+24, modelBitmap, 0, 0, getBitmapScale(modelBitmap, 64, 32));
|
lcdDrawBitmap(x+5, y+24, modelBitmap, 0, 0, getBitmapScale(modelBitmap, 64, 32));
|
||||||
}
|
}
|
||||||
lcdDrawSolidHorizontalLine(x+5, y+19, 143, LINE_COLOR);
|
lcdDrawSolidHorizontalLine(x+5, y+19, 143, LINE_COLOR);
|
||||||
if (selectMode == MODE_SELECT_MODEL && selected) {
|
if (selected) {
|
||||||
lcdDrawSolidRect(x, y, MODELCELL_WIDTH, MODELCELL_HEIGHT, TITLE_BGCOLOR);
|
lcdDrawSolidRect(x, y, MODELCELL_WIDTH, MODELCELL_HEIGHT, TITLE_BGCOLOR);
|
||||||
drawShadow(x, y, MODELCELL_WIDTH, MODELCELL_HEIGHT);
|
drawShadow(x, y, MODELCELL_WIDTH, MODELCELL_HEIGHT);
|
||||||
}
|
}
|
||||||
|
@ -89,8 +88,14 @@ void drawModel(coord_t x, coord_t y, const char * name, bool selected)
|
||||||
|
|
||||||
void onCategorySelectMenu(const char * result)
|
void onCategorySelectMenu(const char * result)
|
||||||
{
|
{
|
||||||
if (result == STR_CREATE_CATEGORY) {
|
if (result == STR_CREATE_MODEL) {
|
||||||
storageAppendCategory("Category");
|
storageCheck(true);
|
||||||
|
createModel(currentCategory);
|
||||||
|
selectMode = MODE_SELECT_MODEL;
|
||||||
|
m_posVert = 255;
|
||||||
|
}
|
||||||
|
else if (result == STR_CREATE_CATEGORY) {
|
||||||
|
storageInsertCategory("Category", -1);
|
||||||
}
|
}
|
||||||
else if (result == STR_RENAME_CATEGORY) {
|
else if (result == STR_RENAME_CATEGORY) {
|
||||||
selectMode = MODE_RENAME_CATEGORY;
|
selectMode = MODE_RENAME_CATEGORY;
|
||||||
|
@ -105,6 +110,7 @@ void onModelSelectMenu(const char * result)
|
||||||
if (result == STR_SELECT_MODEL) {
|
if (result == STR_SELECT_MODEL) {
|
||||||
memcpy(g_eeGeneral.currModelFilename, selectedFilename, LEN_MODEL_FILENAME);
|
memcpy(g_eeGeneral.currModelFilename, selectedFilename, LEN_MODEL_FILENAME);
|
||||||
storageDirty(EE_GENERAL);
|
storageDirty(EE_GENERAL);
|
||||||
|
storageCheck(true);
|
||||||
loadModel(g_eeGeneral.currModelFilename);
|
loadModel(g_eeGeneral.currModelFilename);
|
||||||
chainMenu(menuMainView);
|
chainMenu(menuMainView);
|
||||||
}
|
}
|
||||||
|
@ -177,6 +183,7 @@ bool menuModelSelect(evt_t event)
|
||||||
case EVT_KEY_LONG(KEY_ENTER):
|
case EVT_KEY_LONG(KEY_ENTER):
|
||||||
if (selectMode == MODE_SELECT_CATEGORY) {
|
if (selectMode == MODE_SELECT_CATEGORY) {
|
||||||
killEvents(event);
|
killEvents(event);
|
||||||
|
MENU_ADD_ITEM(STR_CREATE_MODEL);
|
||||||
MENU_ADD_ITEM(STR_CREATE_CATEGORY);
|
MENU_ADD_ITEM(STR_CREATE_CATEGORY);
|
||||||
MENU_ADD_ITEM(STR_RENAME_CATEGORY);
|
MENU_ADD_ITEM(STR_RENAME_CATEGORY);
|
||||||
if (currentCategory > 0)
|
if (currentCategory > 0)
|
||||||
|
@ -244,8 +251,6 @@ bool menuModelSelect(evt_t event)
|
||||||
drawCategory(y, line, currentCategory==index);
|
drawCategory(y, line, currentCategory==index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
y += FH;
|
y += FH;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
@ -261,15 +266,16 @@ bool menuModelSelect(evt_t event)
|
||||||
if (!error) {
|
if (!error) {
|
||||||
bool result = storageSeekCategory(&storage, currentCategory);
|
bool result = storageSeekCategory(&storage, currentCategory);
|
||||||
coord_t y = MENU_HEADER_HEIGHT+7;
|
coord_t y = MENU_HEADER_HEIGHT+7;
|
||||||
int index = 0;
|
int count = 0;
|
||||||
while (result) {
|
while (result) {
|
||||||
char line[LEN_MODEL_FILENAME+1];
|
char line[LEN_MODEL_FILENAME+1];
|
||||||
result = storageReadNextModel(&storage, line, LEN_MODEL_FILENAME);
|
result = storageReadNextModel(&storage, line, LEN_MODEL_FILENAME);
|
||||||
if (!result)
|
if (!result) {
|
||||||
break;
|
break;
|
||||||
if (index >= s_pgOfs*2 && index < (s_pgOfs+3)*2) {
|
}
|
||||||
bool selected = (m_posVert*2+m_posHorz==index);
|
if (count >= s_pgOfs*2 && count < (s_pgOfs+3)*2) {
|
||||||
if (index & 1) {
|
bool selected = (selectMode==MODE_SELECT_MODEL && m_posVert*2+m_posHorz==count);
|
||||||
|
if (count & 1) {
|
||||||
drawModel(CATEGORIES_WIDTH+MENUS_MARGIN_LEFT+162, y, line, selected);
|
drawModel(CATEGORIES_WIDTH+MENUS_MARGIN_LEFT+162, y, line, selected);
|
||||||
y += 66;
|
y += 66;
|
||||||
}
|
}
|
||||||
|
@ -280,14 +286,14 @@ bool menuModelSelect(evt_t event)
|
||||||
memcpy(selectedFilename, line, sizeof(selectedFilename));
|
memcpy(selectedFilename, line, sizeof(selectedFilename));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index++;
|
count++;
|
||||||
}
|
}
|
||||||
if (selectMode == MODE_SELECT_MODEL) {
|
if (selectMode == MODE_SELECT_MODEL) {
|
||||||
if (navigate(event, index, 3, 2)) {
|
if (navigate(event, count, 3, 2)) {
|
||||||
putEvent(EVT_REFRESH);
|
putEvent(EVT_REFRESH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
drawVerticalScrollbar(DEFAULT_SCROLLBAR_X, MENU_HEADER_HEIGHT+7, MENU_FOOTER_TOP-MENU_HEADER_HEIGHT-15, s_pgOfs, (index+1)/2, 3);
|
drawVerticalScrollbar(DEFAULT_SCROLLBAR_X, MENU_HEADER_HEIGHT+7, MENU_FOOTER_TOP-MENU_HEADER_HEIGHT-15, s_pgOfs, (count+1)/2, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -231,6 +231,11 @@ bool navigate(evt_t event, int count, int rows, int columns)
|
||||||
int maxlastcol = count-maxrow*columns-1;
|
int maxlastcol = count-maxrow*columns-1;
|
||||||
int maxcol = (m_posVert != maxrow ? columns-1 : maxlastcol);
|
int maxcol = (m_posVert != maxrow ? columns-1 : maxlastcol);
|
||||||
|
|
||||||
|
if (m_posVert > maxrow) {
|
||||||
|
m_posVert = maxrow;
|
||||||
|
m_posHorz = maxlastcol;
|
||||||
|
}
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case EVT_KEY_FIRST(KEY_RIGHT):
|
case EVT_KEY_FIRST(KEY_RIGHT):
|
||||||
case EVT_KEY_REPT(KEY_RIGHT):
|
case EVT_KEY_REPT(KEY_RIGHT):
|
||||||
|
|
|
@ -180,7 +180,12 @@ void guiMain(evt_t evt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
popupDisplayed = false;
|
if (popupDisplayed) {
|
||||||
|
if (evt == 0) {
|
||||||
|
evt = EVT_REFRESH;
|
||||||
|
}
|
||||||
|
popupDisplayed = false;
|
||||||
|
}
|
||||||
refreshNeeded = g_menuStack[g_menuStackPtr](evt);
|
refreshNeeded = g_menuStack[g_menuStackPtr](evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -461,7 +461,9 @@ void modelDefault(uint8_t id)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(EEPROM)
|
#if !defined(EEPROM)
|
||||||
strcpy(g_model.header.name, "\015\361\374\373\364\033\034");
|
strcpy(g_model.header.name, "\015\361\374\373\364");
|
||||||
|
g_model.header.name[5] = '\033' + id/10;
|
||||||
|
g_model.header.name[6] = '\033' + id%10;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,20 +106,20 @@ char * getFileIndex(char * filename, unsigned int & value)
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool findNextFileIndex(char * filename, const char * directory)
|
int findNextFileIndex(char * filename, const char * directory)
|
||||||
{
|
{
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
char * pos = getFileIndex(filename, index);
|
char * indexPos = getFileIndex(filename, index);
|
||||||
char extension[LEN_FILE_EXTENSION+1];
|
char extension[LEN_FILE_EXTENSION+1];
|
||||||
strncpy(extension, getFileExtension(filename), sizeof(extension));
|
strncpy(extension, getFileExtension(filename), sizeof(extension));
|
||||||
do {
|
do {
|
||||||
pos = strAppendNumber(pos, ++index);
|
char * pos = strAppendNumber(indexPos, ++index);
|
||||||
strAppend(pos, extension);
|
strAppend(pos, extension);
|
||||||
if (!isFileAvailable(filename, directory)) {
|
if (!isFileAvailable(filename, directory)) {
|
||||||
return true;
|
return index;
|
||||||
}
|
}
|
||||||
} while (index < 99);
|
} while (index < 99);
|
||||||
return false;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sdListFiles(const char *path, const char *extension, const uint8_t maxlen, const char *selection, uint8_t flags=0)
|
bool sdListFiles(const char *path, const char *extension, const uint8_t maxlen, const char *selection, uint8_t flags=0)
|
||||||
|
|
|
@ -101,7 +101,7 @@ inline const pm_char * SDCARD_ERROR(FRESULT result)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool isFileAvailable(const char * filename);
|
bool isFileAvailable(const char * filename);
|
||||||
bool findNextFileIndex(char * filename, const char * directory);
|
int findNextFileIndex(char * filename, const char * directory);
|
||||||
|
|
||||||
const char * sdCopyFile(const char * src, const char * dest);
|
const char * sdCopyFile(const char * src, const char * dest);
|
||||||
const char * sdCopyFile(const char * filename, const char * srcDir, const char * destDir);
|
const char * sdCopyFile(const char * filename, const char * srcDir, const char * destDir);
|
||||||
|
|
|
@ -171,18 +171,13 @@ const char * writeGeneralSettings()
|
||||||
|
|
||||||
void storageCheck(bool immediately)
|
void storageCheck(bool immediately)
|
||||||
{
|
{
|
||||||
// if (immediately) {
|
|
||||||
// eepromWriteWait();
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (storageDirtyMsk & EE_GENERAL) {
|
if (storageDirtyMsk & EE_GENERAL) {
|
||||||
TRACE("eeprom write general");
|
TRACE("eeprom write general");
|
||||||
storageDirtyMsk -= EE_GENERAL;
|
storageDirtyMsk -= EE_GENERAL;
|
||||||
writeGeneralSettings();
|
const char * error = writeGeneralSettings();
|
||||||
// if (immediately)
|
if (error) {
|
||||||
// eepromWriteWait();
|
TRACE("writeGeneralSettings error=%s", error);
|
||||||
// else
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storageDirtyMsk & EE_MODEL) {
|
if (storageDirtyMsk & EE_MODEL) {
|
||||||
|
@ -192,8 +187,6 @@ void storageCheck(bool immediately)
|
||||||
if (error) {
|
if (error) {
|
||||||
TRACE("writeModel error=%s", error);
|
TRACE("writeModel error=%s", error);
|
||||||
}
|
}
|
||||||
// if (immediately)
|
|
||||||
// eepromWriteWait();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,9 +423,9 @@ const char * storageModifyLine(unsigned int operation, int category, int positio
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * storageAppendCategory(const char * name)
|
const char * storageInsertCategory(const char * name, int position)
|
||||||
{
|
{
|
||||||
return storageModifyLine(STORAGE_INSERT_CATEGORY, -1, -1, name);
|
return storageModifyLine(STORAGE_INSERT_CATEGORY, position, -1, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char * storageRenameCategory(int category, const char * name)
|
const char * storageRenameCategory(int category, const char * name)
|
||||||
|
@ -459,3 +452,26 @@ const char * storageRenameModel(const char * name, int category, int position)
|
||||||
{
|
{
|
||||||
return storageModifyLine(STORAGE_RENAME_MODEL, category, position, name);
|
return storageModifyLine(STORAGE_RENAME_MODEL, category, position, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * createModel(int category)
|
||||||
|
{
|
||||||
|
preModelLoad();
|
||||||
|
|
||||||
|
char filename[LEN_MODEL_FILENAME+1];
|
||||||
|
memset(filename, 0, sizeof(filename));
|
||||||
|
strcpy(filename, "Model.bin");
|
||||||
|
|
||||||
|
int index = findNextFileIndex(filename, MODELS_PATH);
|
||||||
|
if (index > 0) {
|
||||||
|
modelDefault(index);
|
||||||
|
TRACE("filename=%s", filename);
|
||||||
|
memcpy(g_eeGeneral.currModelFilename, filename, sizeof(g_eeGeneral.currModelFilename));
|
||||||
|
storageDirty(EE_GENERAL);
|
||||||
|
storageDirty(EE_MODEL);
|
||||||
|
storageCheck(true);
|
||||||
|
storageInsertModel(filename, category, -1);
|
||||||
|
}
|
||||||
|
postModelLoad(true);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
|
@ -39,5 +39,6 @@
|
||||||
|
|
||||||
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size);
|
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size);
|
||||||
const char * loadModel(const char * filename);
|
const char * loadModel(const char * filename);
|
||||||
|
const char * createModel(int category);
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue