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)
|
||||
c = idx2char(*s);
|
||||
else
|
||||
c = pgm_read_byte(s);
|
||||
c = *s;
|
||||
if (c == '\0')
|
||||
break;
|
||||
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);
|
||||
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' };
|
||||
lcdDrawSolidFilledRect(x+w-1, y-INVERT_VERT_MARGIN, getTextWidth(s, 1, flags)+1, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawText(x+w, y, s, TEXT_INVERTED_COLOR);
|
||||
lcdDrawSolidFilledRect(x+left-1, y-INVERT_VERT_MARGIN, getTextWidth(s, 1)+1, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawText(x+left, y, s, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
else {
|
||||
editNameCursorPos = 0;
|
||||
|
|
|
@ -36,7 +36,6 @@
|
|||
#include "../../opentx.h"
|
||||
|
||||
#define CATEGORIES_WIDTH 140
|
||||
|
||||
#define MODELCELL_WIDTH 153
|
||||
#define MODELCELL_HEIGHT 61
|
||||
|
||||
|
@ -54,10 +53,10 @@ char selectedCategory[LEN_MODEL_FILENAME+1];
|
|||
void drawCategory(coord_t y, const char * name, bool 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);
|
||||
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);
|
||||
|
@ -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));
|
||||
}
|
||||
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);
|
||||
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)
|
||||
{
|
||||
if (result == STR_CREATE_CATEGORY) {
|
||||
storageAppendCategory("Category");
|
||||
if (result == STR_CREATE_MODEL) {
|
||||
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) {
|
||||
selectMode = MODE_RENAME_CATEGORY;
|
||||
|
@ -105,6 +110,7 @@ void onModelSelectMenu(const char * result)
|
|||
if (result == STR_SELECT_MODEL) {
|
||||
memcpy(g_eeGeneral.currModelFilename, selectedFilename, LEN_MODEL_FILENAME);
|
||||
storageDirty(EE_GENERAL);
|
||||
storageCheck(true);
|
||||
loadModel(g_eeGeneral.currModelFilename);
|
||||
chainMenu(menuMainView);
|
||||
}
|
||||
|
@ -177,6 +183,7 @@ bool menuModelSelect(evt_t event)
|
|||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
if (selectMode == MODE_SELECT_CATEGORY) {
|
||||
killEvents(event);
|
||||
MENU_ADD_ITEM(STR_CREATE_MODEL);
|
||||
MENU_ADD_ITEM(STR_CREATE_CATEGORY);
|
||||
MENU_ADD_ITEM(STR_RENAME_CATEGORY);
|
||||
if (currentCategory > 0)
|
||||
|
@ -244,8 +251,6 @@ bool menuModelSelect(evt_t event)
|
|||
drawCategory(y, line, currentCategory==index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
y += FH;
|
||||
index++;
|
||||
}
|
||||
|
@ -261,15 +266,16 @@ bool menuModelSelect(evt_t event)
|
|||
if (!error) {
|
||||
bool result = storageSeekCategory(&storage, currentCategory);
|
||||
coord_t y = MENU_HEADER_HEIGHT+7;
|
||||
int index = 0;
|
||||
int count = 0;
|
||||
while (result) {
|
||||
char line[LEN_MODEL_FILENAME+1];
|
||||
result = storageReadNextModel(&storage, line, LEN_MODEL_FILENAME);
|
||||
if (!result)
|
||||
if (!result) {
|
||||
break;
|
||||
if (index >= s_pgOfs*2 && index < (s_pgOfs+3)*2) {
|
||||
bool selected = (m_posVert*2+m_posHorz==index);
|
||||
if (index & 1) {
|
||||
}
|
||||
if (count >= s_pgOfs*2 && count < (s_pgOfs+3)*2) {
|
||||
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);
|
||||
y += 66;
|
||||
}
|
||||
|
@ -280,14 +286,14 @@ bool menuModelSelect(evt_t event)
|
|||
memcpy(selectedFilename, line, sizeof(selectedFilename));
|
||||
}
|
||||
}
|
||||
index++;
|
||||
count++;
|
||||
}
|
||||
if (selectMode == MODE_SELECT_MODEL) {
|
||||
if (navigate(event, index, 3, 2)) {
|
||||
if (navigate(event, count, 3, 2)) {
|
||||
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;
|
||||
|
|
|
@ -231,6 +231,11 @@ bool navigate(evt_t event, int count, int rows, int columns)
|
|||
int maxlastcol = count-maxrow*columns-1;
|
||||
int maxcol = (m_posVert != maxrow ? columns-1 : maxlastcol);
|
||||
|
||||
if (m_posVert > maxrow) {
|
||||
m_posVert = maxrow;
|
||||
m_posHorz = maxlastcol;
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
case EVT_KEY_FIRST(KEY_RIGHT):
|
||||
case EVT_KEY_REPT(KEY_RIGHT):
|
||||
|
|
|
@ -180,7 +180,12 @@ void guiMain(evt_t evt)
|
|||
}
|
||||
}
|
||||
else {
|
||||
popupDisplayed = false;
|
||||
if (popupDisplayed) {
|
||||
if (evt == 0) {
|
||||
evt = EVT_REFRESH;
|
||||
}
|
||||
popupDisplayed = false;
|
||||
}
|
||||
refreshNeeded = g_menuStack[g_menuStackPtr](evt);
|
||||
}
|
||||
|
||||
|
|
|
@ -461,7 +461,9 @@ void modelDefault(uint8_t id)
|
|||
#endif
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
|
|
|
@ -106,20 +106,20 @@ char * getFileIndex(char * filename, unsigned int & value)
|
|||
return filename;
|
||||
}
|
||||
|
||||
bool findNextFileIndex(char * filename, const char * directory)
|
||||
int findNextFileIndex(char * filename, const char * directory)
|
||||
{
|
||||
unsigned int index;
|
||||
char * pos = getFileIndex(filename, index);
|
||||
char * indexPos = getFileIndex(filename, index);
|
||||
char extension[LEN_FILE_EXTENSION+1];
|
||||
strncpy(extension, getFileExtension(filename), sizeof(extension));
|
||||
do {
|
||||
pos = strAppendNumber(pos, ++index);
|
||||
char * pos = strAppendNumber(indexPos, ++index);
|
||||
strAppend(pos, extension);
|
||||
if (!isFileAvailable(filename, directory)) {
|
||||
return true;
|
||||
return index;
|
||||
}
|
||||
} 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)
|
||||
|
|
|
@ -101,7 +101,7 @@ inline const pm_char * SDCARD_ERROR(FRESULT result)
|
|||
#endif
|
||||
|
||||
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 * filename, const char * srcDir, const char * destDir);
|
||||
|
|
|
@ -171,18 +171,13 @@ const char * writeGeneralSettings()
|
|||
|
||||
void storageCheck(bool immediately)
|
||||
{
|
||||
// if (immediately) {
|
||||
// eepromWriteWait();
|
||||
// }
|
||||
|
||||
if (storageDirtyMsk & EE_GENERAL) {
|
||||
TRACE("eeprom write general");
|
||||
storageDirtyMsk -= EE_GENERAL;
|
||||
writeGeneralSettings();
|
||||
// if (immediately)
|
||||
// eepromWriteWait();
|
||||
// else
|
||||
return;
|
||||
const char * error = writeGeneralSettings();
|
||||
if (error) {
|
||||
TRACE("writeGeneralSettings error=%s", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (storageDirtyMsk & EE_MODEL) {
|
||||
|
@ -192,8 +187,6 @@ void storageCheck(bool immediately)
|
|||
if (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;
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -459,3 +452,26 @@ const char * storageRenameModel(const char * name, int category, int position)
|
|||
{
|
||||
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 * loadModel(const char * filename);
|
||||
const char * createModel(int category);
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue