[Horus] MODEL SELECT screen continued

This commit is contained in:
Bertrand Songis
2016-06-06 19:36:18 +02:00
parent f6b9a0fcdb
commit 0cf3a278e8
+84 -42
View File
@@ -39,10 +39,10 @@ ModelCell * currentModel;
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+2, HEADER_BGCOLOR); lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH-1, INVERT_LINE_HEIGHT+2, HEADER_BGCOLOR);
lcdDrawBitmapPattern(CATEGORIES_WIDTH-12, y, LBM_LIBRARY_CURSOR, MENU_TITLE_COLOR); lcdDrawBitmapPattern(CATEGORIES_WIDTH-14, y+2, 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+2); drawShadow(0, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH-2, INVERT_LINE_HEIGHT+2);
} }
} }
lcdDrawText(MENUS_MARGIN_LEFT, y, name, MENU_TITLE_COLOR); lcdDrawText(MENUS_MARGIN_LEFT, y, name, MENU_TITLE_COLOR);
@@ -60,7 +60,12 @@ void drawModel(coord_t x, coord_t y, ModelCell * model, bool current, bool selec
} }
} }
#define MODEL_INDEX() (menuVerticalPosition*2+menuHorizontalPosition) uint16_t categoriesVerticalOffset = 0;
uint16_t categoriesVerticalPosition = 0;
uint16_t modelsVerticalOffset = 0;
uint16_t modelsVerticalPosition = 0;
uint16_t modelsHorizontalPosition = 0;
#define MODEL_INDEX() (modelsVerticalPosition*2+modelsHorizontalPosition)
void setCurrentCategory(unsigned int index) void setCurrentCategory(unsigned int index)
{ {
@@ -68,13 +73,18 @@ void setCurrentCategory(unsigned int index)
std::list<ModelsCategory *>::iterator it = modelslist.categories.begin(); std::list<ModelsCategory *>::iterator it = modelslist.categories.begin();
std::advance(it, index); std::advance(it, index);
currentCategory = *it; currentCategory = *it;
categoriesVerticalPosition = index;
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-9, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, modelslist.categories.size()-10)));
} }
void setCurrentModel(unsigned int index) void setCurrentModel(unsigned int index)
{ {
std::list<ModelCell *>::iterator it = currentCategory->begin(); std::list<ModelCell *>::iterator it = currentCategory->begin();
std::advance(it, MODEL_INDEX()); std::advance(it, index);
currentModel = *it; currentModel = *it;
modelsVerticalPosition = index / 2;
modelsHorizontalPosition = index & 1;
modelsVerticalOffset = limit<int>(modelsVerticalPosition-2, modelsVerticalOffset, min<int>(modelsVerticalPosition, max<int>(0, (currentCategory->size()-5)/2)));
} }
void onCategorySelectMenu(const char * result) void onCategorySelectMenu(const char * result)
@@ -83,11 +93,11 @@ void onCategorySelectMenu(const char * result)
storageCheck(true); storageCheck(true);
currentModel = modelslist.addModel(currentCategory, createModel()); currentModel = modelslist.addModel(currentCategory, createModel());
selectMode = MODE_SELECT_MODEL; selectMode = MODE_SELECT_MODEL;
menuVerticalPosition = currentCategory->size() - 1; setCurrentModel(currentCategory->size() - 1);
} }
else if (result == STR_CREATE_CATEGORY) { else if (result == STR_CREATE_CATEGORY) {
currentCategory = modelslist.createCategory(); currentCategory = modelslist.createCategory();
menuVerticalPosition = currentCategoryIndex = modelslist.categories.size() - 1; setCurrentCategory(modelslist.categories.size() - 1);
} }
else if (result == STR_RENAME_CATEGORY) { else if (result == STR_RENAME_CATEGORY) {
selectMode = MODE_RENAME_CATEGORY; selectMode = MODE_RENAME_CATEGORY;
@@ -122,8 +132,8 @@ void onModelSelectMenu(const char * result)
if (findNextFileIndex(duplicatedFilename, MODELS_PATH)) { if (findNextFileIndex(duplicatedFilename, MODELS_PATH)) {
sdCopyFile(currentModel->name, MODELS_PATH, duplicatedFilename, MODELS_PATH); sdCopyFile(currentModel->name, MODELS_PATH, duplicatedFilename, MODELS_PATH);
modelslist.addModel(currentCategory, duplicatedFilename); modelslist.addModel(currentCategory, duplicatedFilename);
menuVerticalPosition = currentCategory->size() - 1; unsigned int index = currentCategory->size() - 1;
setCurrentModel(menuVerticalPosition); setCurrentModel(index);
} }
else { else {
POPUP_WARNING("Invalid File"); POPUP_WARNING("Invalid File");
@@ -131,6 +141,29 @@ void onModelSelectMenu(const char * result)
} }
} }
void initModelsList()
{
modelslist.load();
categoriesVerticalOffset = 0;
int index = 0;
for (std::list<ModelsCategory *>::iterator it = modelslist.categories.begin(); it != modelslist.categories.end(); ++it, ++index) {
if (*it == modelslist.currentCategory) {
setCurrentCategory(index);
break;
}
}
modelsVerticalOffset = 0;
index = 0;
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
if (*it == modelslist.currentModel) {
setCurrentModel(index);
break;
}
}
}
bool menuModelSelect(evt_t event) bool menuModelSelect(evt_t event)
{ {
if (warningResult) { if (warningResult) {
@@ -141,8 +174,6 @@ bool menuModelSelect(evt_t event)
event = EVT_REFRESH; event = EVT_REFRESH;
if (modelIndex > 0) { if (modelIndex > 0) {
modelIndex--; modelIndex--;
menuVerticalPosition = modelIndex / 2;
menuHorizontalPosition = modelIndex & 1;
setCurrentModel(modelIndex); setCurrentModel(modelIndex);
} }
} }
@@ -153,11 +184,8 @@ bool menuModelSelect(evt_t event)
return false; return false;
case EVT_ENTRY: case EVT_ENTRY:
selectMode = MODE_SELECT_CATEGORY; selectMode = MODE_SELECT_MODEL;
modelslist.load(); initModelsList();
menuVerticalPosition = 0;
setCurrentCategory(0);
setCurrentModel(0);
break; break;
case EVT_KEY_FIRST(KEY_EXIT): case EVT_KEY_FIRST(KEY_EXIT):
@@ -167,21 +195,21 @@ bool menuModelSelect(evt_t event)
return false; return false;
case MODE_SELECT_MODEL: case MODE_SELECT_MODEL:
selectMode = MODE_SELECT_CATEGORY; selectMode = MODE_SELECT_CATEGORY;
menuVerticalPosition = currentCategoryIndex;
break; break;
} }
break; break;
case EVT_KEY_BREAK(KEY_ENTER): case EVT_KEY_BREAK(KEY_ENTER):
case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_FIRST(KEY_RIGHT):
switch (selectMode) { if (selectMode == MODE_SELECT_CATEGORY && currentCategory->size() > 0) {
case MODE_SELECT_CATEGORY: selectMode = MODE_SELECT_MODEL;
if (currentCategory->size() > 0) { setCurrentModel(0);
selectMode = MODE_SELECT_MODEL; }
menuVerticalPosition = 0; break;
setCurrentModel(menuVerticalPosition);
} case EVT_KEY_FIRST(KEY_LEFT):
break; if (selectMode == MODE_SELECT_MODEL) {
selectMode = MODE_SELECT_CATEGORY;
} }
break; break;
@@ -201,7 +229,7 @@ bool menuModelSelect(evt_t event)
ModelHeader header; ModelHeader header;
const char * error = readModel(currentModel->name, (uint8_t *)&header, sizeof(header)); const char * error = readModel(currentModel->name, (uint8_t *)&header, sizeof(header));
if (!error) { if (!error) {
if (strncmp(currentModel->name, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME) != 0) { if (currentModel != modelslist.currentModel) {
POPUP_MENU_ADD_ITEM(STR_SELECT_MODEL); POPUP_MENU_ADD_ITEM(STR_SELECT_MODEL);
} }
POPUP_MENU_ADD_ITEM(STR_DUPLICATE_MODEL); POPUP_MENU_ADD_ITEM(STR_DUPLICATE_MODEL);
@@ -221,18 +249,20 @@ bool menuModelSelect(evt_t event)
theme->drawTopbarBackground(ICON_LIBRARY); theme->drawTopbarBackground(ICON_LIBRARY);
// Body // Body
lcdDrawSolidFilledRect(0, MENU_HEADER_HEIGHT, CATEGORIES_WIDTH, LCD_H-MENU_HEADER_HEIGHT-MENU_FOOTER_HEIGHT, TITLE_BGCOLOR); lcdDrawSolidFilledRect(0, MENU_HEADER_HEIGHT, CATEGORIES_WIDTH, LCD_H-MENU_HEADER_HEIGHT-MENU_FOOTER_HEIGHT, TEXT_DISABLE_COLOR);
lcdDrawSolidFilledRect(CATEGORIES_WIDTH, MENU_HEADER_HEIGHT, LCD_W-CATEGORIES_WIDTH, LCD_H-MENU_HEADER_HEIGHT-MENU_FOOTER_HEIGHT, TEXT_BGCOLOR); lcdDrawSolidFilledRect(CATEGORIES_WIDTH, MENU_HEADER_HEIGHT, LCD_W-CATEGORIES_WIDTH, LCD_H-MENU_HEADER_HEIGHT-MENU_FOOTER_HEIGHT, TEXT_BGCOLOR);
// Footer // Footer
lcdDrawSolidFilledRect(0, MENU_FOOTER_TOP, LCD_W, MENU_FOOTER_HEIGHT, HEADER_BGCOLOR); lcdDrawSolidFilledRect(0, MENU_FOOTER_TOP, LCD_W, MENU_FOOTER_HEIGHT, HEADER_BGCOLOR);
// Categories // Categories
coord_t y = MENU_HEADER_HEIGHT+4; int index = 0;
for (std::list<ModelsCategory *>::iterator it = modelslist.categories.begin(); it != modelslist.categories.end(); ++it, y+=FH) { coord_t y = MENU_HEADER_HEIGHT+3;
if (y < MENU_FOOTER_TOP - 5) { drawVerticalScrollbar(CATEGORIES_WIDTH-1, MENU_HEADER_HEIGHT, MENU_FOOTER_TOP-MENU_HEADER_HEIGHT, categoriesVerticalOffset, modelslist.categories.size(), 10);
for (std::list<ModelsCategory *>::iterator it = modelslist.categories.begin(); it != modelslist.categories.end(); ++it, ++index) {
if (index >= categoriesVerticalOffset && index < categoriesVerticalOffset+10) {
if (selectMode == MODE_RENAME_CATEGORY && currentCategory == *it) { if (selectMode == MODE_RENAME_CATEGORY && currentCategory == *it) {
lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH, INVERT_LINE_HEIGHT, TEXT_BGCOLOR); lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN+1, CATEGORIES_WIDTH-2, INVERT_LINE_HEIGHT, TEXT_BGCOLOR);
editName(MENUS_MARGIN_LEFT, y, currentCategory->name, LEN_MODEL_FILENAME, event, 1, 0); editName(MENUS_MARGIN_LEFT, y, currentCategory->name, LEN_MODEL_FILENAME, event, 1, 0);
if (s_editMode == 0 || event == EVT_KEY_BREAK(KEY_EXIT)) { if (s_editMode == 0 || event == EVT_KEY_BREAK(KEY_EXIT)) {
// storageRenameCategory(currentCategory, selectedCategory); // storageRenameCategory(currentCategory, selectedCategory);
@@ -243,22 +273,27 @@ bool menuModelSelect(evt_t event)
else { else {
drawCategory(y, (*it)->name, currentCategory==*it); drawCategory(y, (*it)->name, currentCategory==*it);
} }
y += FH;
} }
} }
if (selectMode == MODE_SELECT_CATEGORY) { if (selectMode == MODE_SELECT_CATEGORY) {
if (navigate(event, modelslist.categories.size(), 9)) { menuVerticalPosition = categoriesVerticalPosition;
menuVerticalOffset = categoriesVerticalOffset;
if (navigate(event, modelslist.categories.size(), 10)) {
categoriesVerticalPosition = menuVerticalPosition;
categoriesVerticalOffset = menuVerticalOffset;
putEvent(EVT_REFRESH); putEvent(EVT_REFRESH);
setCurrentCategory(menuVerticalPosition); setCurrentCategory(categoriesVerticalPosition);
} }
} }
// Models // Models
int index = 0; index = 0;
y = MENU_HEADER_HEIGHT+7; y = MENU_HEADER_HEIGHT+7;
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) { for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
if (index >= menuVerticalOffset*2 && index < (menuVerticalOffset+3)*2) { if (index >= modelsVerticalOffset*2 && index < (modelsVerticalOffset+3)*2) {
bool selected = (selectMode==MODE_SELECT_MODEL && index==menuVerticalPosition*2+menuHorizontalPosition); bool selected = (selectMode==MODE_SELECT_MODEL && index==modelsVerticalPosition*2+modelsHorizontalPosition);
bool current = !strncmp((*it)->name, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME); bool current = !strncmp((*it)->name, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
if (index & 1) { if (index & 1) {
drawModel(CATEGORIES_WIDTH+MENUS_MARGIN_LEFT+162, y, *it, current, selected); drawModel(CATEGORIES_WIDTH+MENUS_MARGIN_LEFT+162, y, *it, current, selected);
@@ -272,19 +307,26 @@ bool menuModelSelect(evt_t event)
if (selectMode == MODE_SELECT_MODEL) { if (selectMode == MODE_SELECT_MODEL) {
if (index == 0) { if (index == 0) {
selectMode = MODE_SELECT_CATEGORY; selectMode = MODE_SELECT_CATEGORY;
menuVerticalPosition = currentCategoryIndex;
putEvent(EVT_REFRESH); putEvent(EVT_REFRESH);
} }
else if (navigate(event, index, 3, 2)) { else {
putEvent(EVT_REFRESH); menuVerticalPosition = modelsVerticalPosition;
setCurrentModel(MODEL_INDEX()); menuHorizontalPosition = modelsHorizontalPosition;
menuVerticalOffset = modelsVerticalOffset;
if (navigate(event, index, 3, 2)) {
modelsVerticalPosition = menuVerticalPosition;
modelsHorizontalPosition = menuHorizontalPosition;
modelsVerticalOffset = menuVerticalOffset;
putEvent(EVT_REFRESH);
setCurrentModel(MODEL_INDEX());
}
} }
if (currentModel) { if (currentModel) {
lcd->drawText(CATEGORIES_WIDTH+MENUS_MARGIN_LEFT, MENU_FOOTER_TOP+2, currentModel->name, TEXT_INVERTED_COLOR); lcd->drawText(CATEGORIES_WIDTH+MENUS_MARGIN_LEFT, MENU_FOOTER_TOP+2, currentModel->name, TEXT_INVERTED_COLOR);
} }
} }
drawVerticalScrollbar(DEFAULT_SCROLLBAR_X, MENU_HEADER_HEIGHT+7, MENU_FOOTER_TOP-MENU_HEADER_HEIGHT-15, menuVerticalOffset, (index+1)/2, 3); drawVerticalScrollbar(DEFAULT_SCROLLBAR_X, MENU_HEADER_HEIGHT+7, MENU_FOOTER_TOP-MENU_HEADER_HEIGHT-15, modelsVerticalOffset, (index+1)/2, 3);
return true; return true;
} }