BitmapBuffer::load renamed to BitmapBuffer::loadBitmap

This commit is contained in:
Bertrand Songis
2019-10-21 21:06:43 +02:00
parent 5ef575132f
commit 1d8c5d38e4
16 changed files with 1513 additions and 470 deletions
+2 -3
View File
@@ -30,7 +30,7 @@ set(GUI_SRC
draw_functions.cpp
# menus.cpp
menu_model.cpp
# model_select.cpp
model_select.cpp
model_setup.cpp
model_flightmodes.cpp
model_inputs.cpp
@@ -83,6 +83,7 @@ endif()
set(SRC
${SRC}
stubs.cpp
storage/modelslist.cpp
)
# includes libopenui
@@ -104,5 +105,3 @@ add_gui_src(curveedit.cpp)
if(HARDWARE_TOUCH)
add_gui_src(keyboard_curve.cpp)
endif()
# gui/${GUI_DIR}/modelslist.cpp
+2 -2
View File
@@ -203,7 +203,7 @@ void drawSleepBitmap()
lcd->clearClippingRect();
lcd->clear();
const BitmapBuffer * bitmap = BitmapBuffer::load(static_cast<ThemeBase *>(theme)->getFilePath("sleep.bmp"));
const BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(static_cast<ThemeBase *>(theme)->getFilePath("sleep.bmp"));
if (bitmap) {
lcd->drawBitmap((LCD_W-bitmap->getWidth())/2, (LCD_H-bitmap->getHeight())/2, bitmap);
delete bitmap;
@@ -219,7 +219,7 @@ void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char
return;
static uint32_t lastDuration = 0xffffffff;
static const BitmapBuffer * shutdown = BitmapBuffer::load(static_cast<ThemeBase *>(theme)->getFilePath("shutdown.bmp"));
static const BitmapBuffer * shutdown = BitmapBuffer::loadBitmap(static_cast<ThemeBase *>(theme)->getFilePath("shutdown.bmp"));
if (shutdown) {
if (duration < lastDuration) {
+161 -398
View File
@@ -18,8 +18,10 @@
* GNU General Public License for more details.
*/
#include <algorithm>
#include "model_select.h"
#include "opentx.h"
#include "modelslist.h"
#include "storage/modelslist.h"
#define CATEGORIES_WIDTH 120
#define MODELS_LEFT 123
@@ -37,12 +39,14 @@ enum ModelDeleteMode {
};
uint8_t selectMode, deleteMode;
//ModelsList modelslist;
ModelsCategory * currentCategory;
int currentCategoryIndex;
ModelCell * currentModel;
void drawCategory(coord_t y, const char * name, bool selected)
/*
void drawCategory(BitmapBuffer * dc, coord_t y, const char * name, bool selected)
{
if (selected) {
lcdDrawSolidFilledRect(1, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH-10, INVERT_LINE_HEIGHT+2, FOCUS_BGCOLOR);
@@ -64,247 +68,38 @@ void drawModel(coord_t x, coord_t y, ModelCell * model, bool current, bool selec
drawShadow(x, y, MODELCELL_WIDTH+2, MODELCELL_HEIGHT+2);
if (selectMode == MODE_MOVE_MODEL) {
lcd->drawMask(x+MODELCELL_WIDTH+2-modelselModelMoveBackground->getWidth(), y, modelselModelMoveBackground, TITLE_BGCOLOR);
lcd->drawMask(x+MODELCELL_WIDTH+2-modelselModelMoveBackground->getWidth()+12, y+5, modelselModelMoveIcon, DEFAULT_BGCOLOR);
lcd->drawMask(x+MODELCELL_WIDTH+2-modelselModelMoveBackground->getWidth()+12, y+5, modelselModelMoveIcon, TEXT_BGCOLOR);
}
}
}
*/
uint16_t categoriesVerticalOffset = 0;
uint16_t categoriesVerticalPosition = 0;
#define MODEL_INDEX() (menuVerticalPosition*2+menuHorizontalPosition)
#if 0
void setCurrentModel(unsigned int index)
{
std::list<ModelCell *>::iterator it = currentCategory->begin();
auto it = currentCategory->begin();
std::advance(it, index);
currentModel = *it;
menuVerticalPosition = index / 2;
menuHorizontalPosition = index & 1;
menuVerticalOffset = limit<int>(menuVerticalPosition-2, menuVerticalOffset, min<int>(menuVerticalPosition, max<int>(0, (currentCategory->size()-7)/2)));
}
#endif
void setCurrentCategory(unsigned int index)
{
currentCategoryIndex = index;
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
std::list<ModelsCategory *>::const_iterator it = cats.begin();
auto it = modelslist.getCategories().begin();
std::advance(it, index);
currentCategory = *it;
categoriesVerticalPosition = index;
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-4, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, cats.size()-5)));
if (currentCategory->size() > 0)
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-4, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, modelslist.getCategories().size()-5)));
/*if (currentCategory->size() > 0)
setCurrentModel(0);
else
currentModel = NULL;
}
#if defined(LUA)
#define MAX_WIZARD_NAME_LEN (sizeof(WIZARD_PATH)+20)
#define WIZARD_SPACING 40
#define WIZARD_LEFT_SPACING 30
#define WIZARD_ICON_X 80
#define WIZARD_ICON_Y 110
#define WIZARD_TEXT_Y 195
uint8_t getWizardCount()
{
uint8_t wizCnt=0;
DIR dir;
static FILINFO fno;
FRESULT res = f_opendir(&dir, WIZARD_PATH);
if (res == FR_OK) {
for (;;) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) {
break;
}
if (fno.fattrib & AM_DIR) {
wizCnt++;
}
}
}
f_closedir(&dir);
return wizCnt;
}
bool menuModelWizard(event_t event)
{
static uint8_t wizardSelected = 0;
static uint8_t wizardCnt = getWizardCount();
bool executeMe = false;
uint8_t first = 0;
DIR dir;
static FILINFO fno;
char wizpath[MAX_WIZARD_NAME_LEN];
if (wizardCnt == 0) {
chainMenu(menuModelSelect);
return false;
}
switch(event) {
case 0:
// no need to refresh the screen
return false;
case EVT_KEY_FIRST(KEY_EXIT):
chainMenu(menuModelSelect);
return false;
case EVT_KEY_BREAK(KEY_ENTER):
executeMe = true;
break;
case EVT_ROTARY_RIGHT:
if (wizardSelected < wizardCnt-1) {
wizardSelected++;
}
if (wizardSelected > 3) {
first = wizardSelected - 3;
}
break;
case EVT_ROTARY_LEFT:
if (wizardSelected != 0) {
wizardSelected--;
}
if(wizardSelected < first)
{
first = wizardSelected;
}
break;
}
strcpy(wizpath, WIZARD_PATH);
strcpy(&wizpath[sizeof(WIZARD_PATH)-1], "/");
lcdDrawSolidFilledRect(0, 0, LCD_W, LCD_H, DEFAULT_BGCOLOR);
lcd->drawBitmap(0, 0, modelselWizardBackground);
FRESULT res = f_opendir(&dir, WIZARD_PATH);
if (res == FR_OK) {
for (uint8_t wizidx=0;;wizidx++) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) {
break;
}
if (fno.fattrib & AM_DIR) {
if((wizidx >= first) && (wizidx < (first+4))) {
uint16_t x = WIZARD_LEFT_SPACING + (wizidx - first) * (WIZARD_SPACING + WIZARD_ICON_X);
strcpy(&wizpath[sizeof(WIZARD_PATH)], fno.fname);
strcpy(&wizpath[sizeof(WIZARD_PATH) + strlen(fno.fname)], "/icon.png");
lcdDrawText(x + 10, WIZARD_TEXT_Y, fno.fname);
BitmapBuffer * background = BitmapBuffer::load(wizpath);
lcd->drawBitmap(x, WIZARD_ICON_Y, background);
if(wizidx == wizardSelected ) {
if (wizardSelected < 5) {
lcdDrawRect(x, WIZARD_ICON_Y, 85, 130, 2, SOLID, MAINVIEW_GRAPHICS_COLOR_INDEX);
lcdDrawRect(x+5, WIZARD_TEXT_Y, 75, 4, 2, SOLID, MAINVIEW_GRAPHICS_COLOR_INDEX);
}
if (executeMe) {
strcpy(&wizpath[sizeof(WIZARD_PATH)+strlen(fno.fname)], "/wizard.lua");
if (isFileAvailable(wizpath)) {
wizpath[sizeof(WIZARD_PATH) + strlen(fno.fname)] = 0;
f_chdir(wizpath);
luaExec(WIZARD_NAME);
}
}
}
delete background;
}
}
}
f_closedir(&dir);
}
return true;
}
#endif
void onDeleteModelConfirm(const char * result)
{
if (result == STR_OK) {
if (deleteMode == MODE_DELETE_CATEGORY) {
modelslist.removeCategory(currentCategory);
modelslist.save();
setCurrentCategory(currentCategoryIndex > 0 ? currentCategoryIndex-1 : currentCategoryIndex);
}
else if (deleteMode == MODE_DELETE_MODEL){
int modelIndex = MODEL_INDEX();
modelslist.removeModel(currentCategory, currentModel);
s_copyMode = 0;
putEvent(EVT_REFRESH);
if (modelIndex > 0) {
modelIndex--;
}
setCurrentModel(modelIndex);
}
}
}
void onModelSelectMenu(const char * result)
{
if (result == STR_SELECT_MODEL) {
// we store the latest changes if any
storageFlushCurrentModel();
storageCheck(true);
memcpy(g_eeGeneral.currModelFilename, currentModel->modelFilename, LEN_MODEL_FILENAME);
modelslist.setCurrentModel(currentModel);
loadModel(g_eeGeneral.currModelFilename, true);
storageDirty(EE_GENERAL);
storageCheck(true);
chainMenu(menuMainView);
}
else if (result == STR_DELETE_MODEL) {
POPUP_CONFIRMATION(STR_DELETEMODEL, onDeleteModelConfirm);
SET_WARNING_INFO(currentModel->modelName, LEN_MODEL_NAME, 0);
deleteMode = MODE_DELETE_MODEL;
}
else if (result == STR_CREATE_MODEL) {
storageCheck(true);
modelslist.addModel(currentCategory, createModel());
selectMode = MODE_SELECT_MODEL;
setCurrentModel(currentCategory->size() - 1);
modelslist.setCurrentModel(currentModel);
modelslist.onNewModelCreated(currentModel, &g_model);
#if defined(LUA)
chainMenu(menuModelWizard);
#endif
}
else if (result == STR_DUPLICATE_MODEL) {
char duplicatedFilename[LEN_MODEL_FILENAME+1];
memcpy(duplicatedFilename, currentModel->modelFilename, sizeof(duplicatedFilename));
if (findNextFileIndex(duplicatedFilename, LEN_MODEL_FILENAME, MODELS_PATH)) {
sdCopyFile(currentModel->modelFilename, MODELS_PATH, duplicatedFilename, MODELS_PATH);
ModelCell* dup_model = modelslist.addModel(currentCategory, duplicatedFilename);
dup_model->fetchRfData();
setCurrentModel(currentCategory->size() - 1);
}
else {
POPUP_WARNING("Invalid File");
}
}
else if (result == STR_MOVE_MODEL) {
selectMode = MODE_MOVE_MODEL;
}
else if (result == STR_CREATE_CATEGORY) {
currentCategory = modelslist.createCategory();
setCurrentCategory(modelslist.getCategories().size() - 1);
}
else if (result == STR_RENAME_CATEGORY) {
selectMode = MODE_RENAME_CATEGORY;
s_editMode = EDIT_MODIFY_STRING;
editNameCursorPos = 0;
}
else if (result == STR_DELETE_CATEGORY) {
if (currentCategory->size() > 0){
POPUP_WARNING(STR_DELETE_ERROR);
SET_WARNING_INFO(STR_CAT_NOT_EMPTY, sizeof(TR_CAT_NOT_EMPTY), 0);
}
else {
POPUP_CONFIRMATION(STR_DELETEMODEL, onDeleteModelConfirm);
SET_WARNING_INFO(currentCategory->name, LEN_MODEL_FILENAME, 0);
deleteMode = MODE_DELETE_CATEGORY;
}
}
currentModel = NULL;*/
}
void initModelsList()
@@ -314,13 +109,13 @@ void initModelsList()
categoriesVerticalOffset = 0;
bool found = false;
int index = 0;
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
if (*it == modelslist.getCurrentCategory()) {
for (auto & category : modelslist.getCategories()) {
if (category == modelslist.getCurrentCategory()) {
setCurrentCategory(index);
found = true;
break;
}
index++;
}
if (!found) {
setCurrentCategory(0);
@@ -329,191 +124,159 @@ void initModelsList()
menuVerticalOffset = 0;
found = false;
index = 0;
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
if (*it == modelslist.getCurrentModel()) {
setCurrentModel(index);
for (auto & cell : *currentCategory) {
if (cell == modelslist.getCurrentModel()) {
// setCurrentModel(index);
found = true;
break;
}
}
if (!found) {
setCurrentModel(0);
// setCurrentModel(0);
}
}
bool menuModelSelect(event_t event)
{
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
switch(event) {
case 0:
// no need to refresh the screen
return false;
class ModelselectButton: public Button {
public:
ModelselectButton(FormGroup * parent, const rect_t & rect, ModelCell * modelCell, Window * footer);
case EVT_ENTRY:
selectMode = MODE_SELECT_MODEL;
void paint(BitmapBuffer * dc) override
{
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
dc->drawBitmap(10, 2, modelCell->getBuffer());
if (modelCell == modelslist.getCurrentModel()) {
dc->drawBitmapPattern(112, 71, LBM_ACTIVE_MODEL, TITLE_BGCOLOR);
}
}
const char * modelFilename() {
return modelCell->modelFilename;
}
protected:
ModelCell * modelCell;
};
class ModelselectFooter: public Window {
public:
ModelselectFooter(Window * parent, const rect_t & rect):
Window(parent, rect)
{
}
void paint(BitmapBuffer * dc) override
{
dc->drawSolidFilledRect(0, 5, rect.w, 2, CURVE_AXIS_COLOR);
dc->drawBitmap(7, 12, modelselSdFreeBitmap);
uint32_t size = sdGetSize() / 100;
dc->drawNumber(24, 11, size, PREC1|SMLSIZE, 0, NULL, "GB");
dc->drawBitmap(77, 12, modelselModelQtyBitmap);
dc->drawNumber(99, 11, modelslist.getModelsCount(), SMLSIZE);
ModelselectButton * selectedModel = dynamic_cast<ModelselectButton *>(focusWindow);
if (selectedModel) {
dc->drawBitmap(7, 37, modelselModelNameBitmap);
dc->drawText(24, 32, selectedModel->modelFilename(), SMLSIZE | DEFAULT_COLOR);
}
}
};
class ModelselectPage: public PageTab {
public:
ModelselectPage() :
PageTab(STR_MODEL_SELECT, ICON_MODEL_CURVES /*ICON_MODEL_SELECT*/)
{
}
static void updateModels(FormGroup * window, Window * footer, int selected = -1)
{
window->clear();
int index = 0;
for (auto it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
Button * button = new ModelselectButton(window, {10, 10 + index * 104, LCD_W - 20, 94}, *it, footer);
if (selected == index) {
button->setFocus();
}
}
window->adjustInnerHeight();
}
void build(FormWindow * window) override
{
initModelsList();
break;
case EVT_KEY_BREAK(KEY_ENTER):
if (selectMode == MODE_MOVE_MODEL)
selectMode = MODE_SELECT_MODEL;
break;
case EVT_KEY_FIRST(KEY_EXIT):
switch (selectMode) {
case MODE_MOVE_MODEL:
selectMode = MODE_SELECT_MODEL;
break;
case MODE_SELECT_MODEL:
chainMenu(menuMainView);
return false;
}
break;
case EVT_KEY_FIRST(KEY_PGUP):
#if defined(PCBX10)
case EVT_KEY_LONG(KEY_PGDN):
#endif
if (selectMode == MODE_SELECT_MODEL) {
if (categoriesVerticalPosition == 0)
categoriesVerticalPosition = cats.size() - 1;
else
categoriesVerticalPosition -= 1;
setCurrentCategory(categoriesVerticalPosition);
}
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition > 0) {
ModelsCategory * previous_category = currentCategory;
ModelCell * model = currentModel;
categoriesVerticalPosition -= 1;
setCurrentCategory(categoriesVerticalPosition);
modelslist.moveModel(model, previous_category, currentCategory);
setCurrentModel(currentCategory->size()-1);
}
killEvents(event);
break;
#if defined(PCBX12S)
case EVT_KEY_FIRST(KEY_PGDN):
#elif defined(PCBX10)
case EVT_KEY_BREAK(KEY_PGDN):
#endif
if (selectMode == MODE_SELECT_MODEL) {
categoriesVerticalPosition += 1;
if (categoriesVerticalPosition >= cats.size())
categoriesVerticalPosition = 0;
setCurrentCategory(categoriesVerticalPosition);
}
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition < cats.size()-1) {
ModelsCategory * previous_category = currentCategory;
ModelCell * model = currentModel;
categoriesVerticalPosition += 1;
setCurrentCategory(categoriesVerticalPosition);
modelslist.moveModel(model, previous_category, currentCategory);
setCurrentModel(currentCategory->size()-1);
}
break;
case EVT_KEY_LONG(KEY_ENTER):
if (selectMode == MODE_SELECT_MODEL) {
killEvents(event);
if (currentModel && currentModel != modelslist.getCurrentModel()) {
POPUP_MENU_ADD_ITEM(STR_SELECT_MODEL);
}
POPUP_MENU_ADD_ITEM(STR_CREATE_MODEL);
if (currentModel) {
POPUP_MENU_ADD_ITEM(STR_DUPLICATE_MODEL);
POPUP_MENU_ADD_ITEM(STR_MOVE_MODEL);
}
// POPUP_MENU_ADD_SD_ITEM(STR_BACKUP_MODEL);
if (currentModel && currentModel != modelslist.getCurrentModel()) {
POPUP_MENU_ADD_ITEM(STR_DELETE_MODEL);
}
// POPUP_MENU_ADD_ITEM(STR_RESTORE_MODEL);
POPUP_MENU_ADD_ITEM(STR_CREATE_CATEGORY);
POPUP_MENU_ADD_ITEM(STR_RENAME_CATEGORY);
if (cats.size() > 1) {
POPUP_MENU_ADD_ITEM(STR_DELETE_CATEGORY);
}
POPUP_MENU_START(onModelSelectMenu);
}
break;
}
lcdDrawSolidFilledRect(0, 0, LCD_W, LCD_H, DEFAULT_BGCOLOR);
lcd->drawBitmap(0, 0, modelselIconBitmap);
// Categories
int index = 0;
coord_t y = 97;
drawVerticalScrollbar(CATEGORIES_WIDTH-1, y-1, 5*(FH+7)-5, categoriesVerticalOffset, cats.size(), 5);
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
if (index >= categoriesVerticalOffset && index < categoriesVerticalOffset+5) {
if (index != categoriesVerticalOffset) {
lcdDrawSolidHorizontalLine(1, y-4, CATEGORIES_WIDTH-10, LINE_COLOR);
}
if (selectMode == MODE_RENAME_CATEGORY && currentCategory == *it) {
lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN+1, CATEGORIES_WIDTH-2, INVERT_LINE_HEIGHT, DEFAULT_BGCOLOR);
editName(MENUS_MARGIN_LEFT, y, currentCategory->name, LEN_MODEL_FILENAME, event, 1, 0);
if (s_editMode == 0 || event == EVT_KEY_BREAK(KEY_EXIT)) {
modelslist.save();
selectMode = MODE_SELECT_MODEL;
putEvent(EVT_REFRESH);
}
}
else {
drawCategory(y, (*it)->name, currentCategory==*it);
}
y += FH+7;
FormWindow * body = new FormWindow(window, {0, 0, LCD_W, window->height() - 55});
Window * footer = new ModelselectFooter(window, {0, window->height() - 55, LCD_W, 55});
updateModels(body, footer);
}
}
};
// Models
index = 0;
y = 5;
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
if (index >= menuVerticalOffset*2 && index < (menuVerticalOffset+4)*2) {
bool selected = ((selectMode==MODE_SELECT_MODEL || selectMode==MODE_MOVE_MODEL) && index==menuVerticalPosition*2+menuHorizontalPosition);
bool current = !strncmp((*it)->modelFilename, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
if (index & 1) {
drawModel(MODELS_LEFT + MODELS_COLUMN_WIDTH, y, *it, current, selected);
y += 66;
}
else {
drawModel(MODELS_LEFT, y, *it, current, selected);
}
if (selected) {
lcd->drawBitmap(5, LCD_H-FH, modelselModelNameBitmap);
lcdDrawText(22, LCD_H-FH-1, (*it)->modelFilename, SMLSIZE|DEFAULT_COLOR);
}
}
}
// Navigation
if (currentModel) {
if (selectMode == MODE_SELECT_MODEL) {
if (navigate(event, index, 4, 2) != 0) {
setCurrentModel(MODEL_INDEX());
putEvent(EVT_REFRESH);
}
}
else if (selectMode == MODE_MOVE_MODEL) {
int8_t direction = navigate(event, index, 4, 2, false);
if (direction) {
modelslist.moveModel(currentCategory, currentModel, direction);
setCurrentModel(MODEL_INDEX());
putEvent(EVT_REFRESH);
}
}
}
drawVerticalScrollbar(DEFAULT_SCROLLBAR_X + 4, 7, LCD_H - 15, menuVerticalOffset, (index + 1) / 2, 4);
// Footer
lcd->drawBitmap(5, LCD_H-FH-20, modelselSdFreeBitmap);
uint32_t size = sdGetSize() / 100;
lcdDrawNumber(22, LCD_H-FH-21, size, PREC1|SMLSIZE, 0, NULL, "GB");
lcd->drawBitmap(70, LCD_H-FH-20, modelselModelQtyBitmap);
lcdDrawNumber(92, LCD_H-FH-21, modelslist.getModelsCount(),SMLSIZE);
return true;
ModelselectMenu::ModelselectMenu():
TabsGroup(ICON_MODEL_CURVES)
{
addTab(new ModelselectPage());
}
ModelselectButton::ModelselectButton(FormGroup * parent, const rect_t & rect, ModelCell * modelCell, Window * footer):
Button(parent, rect,
[=]() -> uint8_t {
if (hasFocus()) {
Menu * menu = new Menu();
if (modelCell && modelCell != modelslist.getCurrentModel()) {
menu->addLine(STR_SELECT_MODEL, [=]() {
// we store the latest changes if any
storageFlushCurrentModel();
storageCheck(true);
memcpy(g_eeGeneral.currModelFilename, modelCell->modelFilename, LEN_MODEL_FILENAME);
loadModel(g_eeGeneral.currModelFilename, false);
storageDirty(EE_GENERAL);
storageCheck(true);
// chainMenu(menuMainView);
postModelLoad(true);
modelslist.setCurrentModel(modelCell);
// TODO ModelselectPage::updateModels(parent, footer, modelslist.getModelIndex(modelCell));
});
}
menu->addLine(STR_CREATE_MODEL, [=]() {
storageCheck(true);
modelslist.setCurrentModel(modelslist.addModel(currentCategory, createModel()));
#if defined(LUA)
// chainMenu(menuModelWizard);
#endif
ModelselectPage::updateModels(parent, footer, currentCategory->size() - 1);
});
if (modelCell) {
menu->addLine(STR_DUPLICATE_MODEL, [=]() {
char duplicatedFilename[LEN_MODEL_FILENAME + 1];
memcpy(duplicatedFilename, modelCell->modelFilename, sizeof(duplicatedFilename));
if (findNextFileIndex(duplicatedFilename, LEN_MODEL_FILENAME, MODELS_PATH)) {
sdCopyFile(modelCell->modelFilename, MODELS_PATH, duplicatedFilename, MODELS_PATH);
modelslist.addModel(currentCategory, duplicatedFilename);
ModelselectPage::updateModels(parent, footer, currentCategory->size() - 1);
}
else {
POPUP_WARNING("Invalid File");
}
});
}
// menu->addLine(STR_MOVE_MODEL);
if (modelCell && modelCell != modelslist.getCurrentModel()) {
menu->addLine(STR_DELETE_MODEL, [=]() {
// POPUP_CONFIRMATION(STR_DELETEMODEL);
// SET_WARNING_INFO(modelCell->modelName, LEN_MODEL_NAME, 0);
unsigned int index = 0; // TODOmodelslist.getModelIndex(modelCell);
if (index > 0)
--index;
modelslist.removeModel(currentCategory, modelCell);
ModelselectPage::updateModels(parent, footer, index);
});
}
}
else {
setFocus();
footer->invalidate();
}
return 1;
}, BUTTON_CHECKED_ON_FOCUS),
modelCell(modelCell)
{
}
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _MODEL_SELECT_H_
#define _MODEL_SELECT_H_
#include "tabsgroup.h"
class ModelselectMenu: public TabsGroup {
public:
ModelselectMenu();
};
#endif // _MODEL_SELECT_H_
+519
View File
@@ -0,0 +1,519 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "opentx.h"
#include "modelslist.h"
#define CATEGORIES_WIDTH 120
#define MODELS_LEFT 123
#define MODELS_COLUMN_WIDTH 174
enum ModelSelectMode {
MODE_SELECT_MODEL,
MODE_RENAME_CATEGORY,
MODE_MOVE_MODEL,
};
enum ModelDeleteMode {
MODE_DELETE_MODEL,
MODE_DELETE_CATEGORY,
};
uint8_t selectMode, deleteMode;
ModelsCategory * currentCategory;
int currentCategoryIndex;
ModelCell * currentModel;
void drawCategory(coord_t y, const char * name, bool selected)
{
if (selected) {
lcdDrawSolidFilledRect(1, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH-10, INVERT_LINE_HEIGHT+2, FOCUS_BGCOLOR);
lcdDrawText(6, y, name, DEFAULT_COLOR | INVERS);
}
else {
lcdDrawText(6, y, name, DEFAULT_COLOR);
}
}
void drawModel(coord_t x, coord_t y, ModelCell * model, bool current, bool selected)
{
lcd->drawBitmap(x+1, y+1, model->getBuffer());
if (current) {
lcd->drawBitmapPattern(x+66, y+43, LBM_ACTIVE_MODEL, TITLE_BGCOLOR);
}
if (selected) {
lcdDrawSolidRect(x, y, MODELCELL_WIDTH+2, MODELCELL_HEIGHT+2, 1, TITLE_BGCOLOR);
drawShadow(x, y, MODELCELL_WIDTH+2, MODELCELL_HEIGHT+2);
if (selectMode == MODE_MOVE_MODEL) {
lcd->drawMask(x+MODELCELL_WIDTH+2-modelselModelMoveBackground->getWidth(), y, modelselModelMoveBackground, TITLE_BGCOLOR);
lcd->drawMask(x+MODELCELL_WIDTH+2-modelselModelMoveBackground->getWidth()+12, y+5, modelselModelMoveIcon, DEFAULT_BGCOLOR);
}
}
}
uint16_t categoriesVerticalOffset = 0;
uint16_t categoriesVerticalPosition = 0;
#define MODEL_INDEX() (menuVerticalPosition*2+menuHorizontalPosition)
void setCurrentModel(unsigned int index)
{
std::list<ModelCell *>::iterator it = currentCategory->begin();
std::advance(it, index);
currentModel = *it;
menuVerticalPosition = index / 2;
menuHorizontalPosition = index & 1;
menuVerticalOffset = limit<int>(menuVerticalPosition-2, menuVerticalOffset, min<int>(menuVerticalPosition, max<int>(0, (currentCategory->size()-7)/2)));
}
void setCurrentCategory(unsigned int index)
{
currentCategoryIndex = index;
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
std::list<ModelsCategory *>::const_iterator it = cats.begin();
std::advance(it, index);
currentCategory = *it;
categoriesVerticalPosition = index;
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-4, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, cats.size()-5)));
if (currentCategory->size() > 0)
setCurrentModel(0);
else
currentModel = NULL;
}
#if defined(LUA)
#define MAX_WIZARD_NAME_LEN (sizeof(WIZARD_PATH)+20)
#define WIZARD_SPACING 40
#define WIZARD_LEFT_SPACING 30
#define WIZARD_ICON_X 80
#define WIZARD_ICON_Y 110
#define WIZARD_TEXT_Y 195
uint8_t getWizardCount()
{
uint8_t wizCnt=0;
DIR dir;
static FILINFO fno;
FRESULT res = f_opendir(&dir, WIZARD_PATH);
if (res == FR_OK) {
for (;;) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) {
break;
}
if (fno.fattrib & AM_DIR) {
wizCnt++;
}
}
}
f_closedir(&dir);
return wizCnt;
}
bool menuModelWizard(event_t event)
{
static uint8_t wizardSelected = 0;
static uint8_t wizardCnt = getWizardCount();
bool executeMe = false;
uint8_t first = 0;
DIR dir;
static FILINFO fno;
char wizpath[MAX_WIZARD_NAME_LEN];
if (wizardCnt == 0) {
chainMenu(menuModelSelect);
return false;
}
switch(event) {
case 0:
// no need to refresh the screen
return false;
case EVT_KEY_FIRST(KEY_EXIT):
chainMenu(menuModelSelect);
return false;
case EVT_KEY_BREAK(KEY_ENTER):
executeMe = true;
break;
case EVT_ROTARY_RIGHT:
if (wizardSelected < wizardCnt-1) {
wizardSelected++;
}
if (wizardSelected > 3) {
first = wizardSelected - 3;
}
break;
case EVT_ROTARY_LEFT:
if (wizardSelected != 0) {
wizardSelected--;
}
if(wizardSelected < first)
{
first = wizardSelected;
}
break;
}
strcpy(wizpath, WIZARD_PATH);
strcpy(&wizpath[sizeof(WIZARD_PATH)-1], "/");
lcdDrawSolidFilledRect(0, 0, LCD_W, LCD_H, DEFAULT_BGCOLOR);
lcd->drawBitmap(0, 0, modelselWizardBackground);
FRESULT res = f_opendir(&dir, WIZARD_PATH);
if (res == FR_OK) {
for (uint8_t wizidx=0;;wizidx++) {
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0) {
break;
}
if (fno.fattrib & AM_DIR) {
if((wizidx >= first) && (wizidx < (first+4))) {
uint16_t x = WIZARD_LEFT_SPACING + (wizidx - first) * (WIZARD_SPACING + WIZARD_ICON_X);
strcpy(&wizpath[sizeof(WIZARD_PATH)], fno.fname);
strcpy(&wizpath[sizeof(WIZARD_PATH) + strlen(fno.fname)], "/icon.png");
lcdDrawText(x + 10, WIZARD_TEXT_Y, fno.fname);
BitmapBuffer * background = BitmapBuffer::load(wizpath);
lcd->drawBitmap(x, WIZARD_ICON_Y, background);
if(wizidx == wizardSelected ) {
if (wizardSelected < 5) {
lcdDrawRect(x, WIZARD_ICON_Y, 85, 130, 2, SOLID, MAINVIEW_GRAPHICS_COLOR_INDEX);
lcdDrawRect(x+5, WIZARD_TEXT_Y, 75, 4, 2, SOLID, MAINVIEW_GRAPHICS_COLOR_INDEX);
}
if (executeMe) {
strcpy(&wizpath[sizeof(WIZARD_PATH)+strlen(fno.fname)], "/wizard.lua");
if (isFileAvailable(wizpath)) {
wizpath[sizeof(WIZARD_PATH) + strlen(fno.fname)] = 0;
f_chdir(wizpath);
luaExec(WIZARD_NAME);
}
}
}
delete background;
}
}
}
f_closedir(&dir);
}
return true;
}
#endif
void onDeleteModelConfirm(const char * result)
{
if (result == STR_OK) {
if (deleteMode == MODE_DELETE_CATEGORY) {
modelslist.removeCategory(currentCategory);
modelslist.save();
setCurrentCategory(currentCategoryIndex > 0 ? currentCategoryIndex-1 : currentCategoryIndex);
}
else if (deleteMode == MODE_DELETE_MODEL){
int modelIndex = MODEL_INDEX();
modelslist.removeModel(currentCategory, currentModel);
s_copyMode = 0;
putEvent(EVT_REFRESH);
if (modelIndex > 0) {
modelIndex--;
}
setCurrentModel(modelIndex);
}
}
}
void onModelSelectMenu(const char * result)
{
if (result == STR_SELECT_MODEL) {
// we store the latest changes if any
storageFlushCurrentModel();
storageCheck(true);
memcpy(g_eeGeneral.currModelFilename, currentModel->modelFilename, LEN_MODEL_FILENAME);
modelslist.setCurrentModel(currentModel);
loadModel(g_eeGeneral.currModelFilename, true);
storageDirty(EE_GENERAL);
storageCheck(true);
chainMenu(menuMainView);
}
else if (result == STR_DELETE_MODEL) {
POPUP_CONFIRMATION(STR_DELETEMODEL, onDeleteModelConfirm);
SET_WARNING_INFO(currentModel->modelName, LEN_MODEL_NAME, 0);
deleteMode = MODE_DELETE_MODEL;
}
else if (result == STR_CREATE_MODEL) {
storageCheck(true);
modelslist.addModel(currentCategory, createModel());
selectMode = MODE_SELECT_MODEL;
setCurrentModel(currentCategory->size() - 1);
modelslist.setCurrentModel(currentModel);
modelslist.onNewModelCreated(currentModel, &g_model);
#if defined(LUA)
chainMenu(menuModelWizard);
#endif
}
else if (result == STR_DUPLICATE_MODEL) {
char duplicatedFilename[LEN_MODEL_FILENAME+1];
memcpy(duplicatedFilename, currentModel->modelFilename, sizeof(duplicatedFilename));
if (findNextFileIndex(duplicatedFilename, LEN_MODEL_FILENAME, MODELS_PATH)) {
sdCopyFile(currentModel->modelFilename, MODELS_PATH, duplicatedFilename, MODELS_PATH);
ModelCell* dup_model = modelslist.addModel(currentCategory, duplicatedFilename);
dup_model->fetchRfData();
setCurrentModel(currentCategory->size() - 1);
}
else {
POPUP_WARNING("Invalid File");
}
}
else if (result == STR_MOVE_MODEL) {
selectMode = MODE_MOVE_MODEL;
}
else if (result == STR_CREATE_CATEGORY) {
currentCategory = modelslist.createCategory();
setCurrentCategory(modelslist.getCategories().size() - 1);
}
else if (result == STR_RENAME_CATEGORY) {
selectMode = MODE_RENAME_CATEGORY;
s_editMode = EDIT_MODIFY_STRING;
editNameCursorPos = 0;
}
else if (result == STR_DELETE_CATEGORY) {
if (currentCategory->size() > 0){
POPUP_WARNING(STR_DELETE_ERROR);
SET_WARNING_INFO(STR_CAT_NOT_EMPTY, sizeof(TR_CAT_NOT_EMPTY), 0);
}
else {
POPUP_CONFIRMATION(STR_DELETEMODEL, onDeleteModelConfirm);
SET_WARNING_INFO(currentCategory->name, LEN_MODEL_FILENAME, 0);
deleteMode = MODE_DELETE_CATEGORY;
}
}
}
void initModelsList()
{
modelslist.load();
categoriesVerticalOffset = 0;
bool found = false;
int index = 0;
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
if (*it == modelslist.getCurrentCategory()) {
setCurrentCategory(index);
found = true;
break;
}
}
if (!found) {
setCurrentCategory(0);
}
menuVerticalOffset = 0;
found = false;
index = 0;
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
if (*it == modelslist.getCurrentModel()) {
setCurrentModel(index);
found = true;
break;
}
}
if (!found) {
setCurrentModel(0);
}
}
bool menuModelSelect(event_t event)
{
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
switch(event) {
case 0:
// no need to refresh the screen
return false;
case EVT_ENTRY:
selectMode = MODE_SELECT_MODEL;
initModelsList();
break;
case EVT_KEY_BREAK(KEY_ENTER):
if (selectMode == MODE_MOVE_MODEL)
selectMode = MODE_SELECT_MODEL;
break;
case EVT_KEY_FIRST(KEY_EXIT):
switch (selectMode) {
case MODE_MOVE_MODEL:
selectMode = MODE_SELECT_MODEL;
break;
case MODE_SELECT_MODEL:
chainMenu(menuMainView);
return false;
}
break;
case EVT_KEY_FIRST(KEY_PGUP):
#if defined(PCBX10)
case EVT_KEY_LONG(KEY_PGDN):
#endif
if (selectMode == MODE_SELECT_MODEL) {
if (categoriesVerticalPosition == 0)
categoriesVerticalPosition = cats.size() - 1;
else
categoriesVerticalPosition -= 1;
setCurrentCategory(categoriesVerticalPosition);
}
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition > 0) {
ModelsCategory * previous_category = currentCategory;
ModelCell * model = currentModel;
categoriesVerticalPosition -= 1;
setCurrentCategory(categoriesVerticalPosition);
modelslist.moveModel(model, previous_category, currentCategory);
setCurrentModel(currentCategory->size()-1);
}
killEvents(event);
break;
#if defined(PCBX12S)
case EVT_KEY_FIRST(KEY_PGDN):
#elif defined(PCBX10)
case EVT_KEY_BREAK(KEY_PGDN):
#endif
if (selectMode == MODE_SELECT_MODEL) {
categoriesVerticalPosition += 1;
if (categoriesVerticalPosition >= cats.size())
categoriesVerticalPosition = 0;
setCurrentCategory(categoriesVerticalPosition);
}
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition < cats.size()-1) {
ModelsCategory * previous_category = currentCategory;
ModelCell * model = currentModel;
categoriesVerticalPosition += 1;
setCurrentCategory(categoriesVerticalPosition);
modelslist.moveModel(model, previous_category, currentCategory);
setCurrentModel(currentCategory->size()-1);
}
break;
case EVT_KEY_LONG(KEY_ENTER):
if (selectMode == MODE_SELECT_MODEL) {
killEvents(event);
if (currentModel && currentModel != modelslist.getCurrentModel()) {
POPUP_MENU_ADD_ITEM(STR_SELECT_MODEL);
}
POPUP_MENU_ADD_ITEM(STR_CREATE_MODEL);
if (currentModel) {
POPUP_MENU_ADD_ITEM(STR_DUPLICATE_MODEL);
POPUP_MENU_ADD_ITEM(STR_MOVE_MODEL);
}
// POPUP_MENU_ADD_SD_ITEM(STR_BACKUP_MODEL);
if (currentModel && currentModel != modelslist.getCurrentModel()) {
POPUP_MENU_ADD_ITEM(STR_DELETE_MODEL);
}
// POPUP_MENU_ADD_ITEM(STR_RESTORE_MODEL);
POPUP_MENU_ADD_ITEM(STR_CREATE_CATEGORY);
POPUP_MENU_ADD_ITEM(STR_RENAME_CATEGORY);
if (cats.size() > 1) {
POPUP_MENU_ADD_ITEM(STR_DELETE_CATEGORY);
}
POPUP_MENU_START(onModelSelectMenu);
}
break;
}
lcdDrawSolidFilledRect(0, 0, LCD_W, LCD_H, DEFAULT_BGCOLOR);
lcd->drawBitmap(0, 0, modelselIconBitmap);
// Categories
int index = 0;
coord_t y = 97;
drawVerticalScrollbar(CATEGORIES_WIDTH-1, y-1, 5*(FH+7)-5, categoriesVerticalOffset, cats.size(), 5);
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
if (index >= categoriesVerticalOffset && index < categoriesVerticalOffset+5) {
if (index != categoriesVerticalOffset) {
lcdDrawSolidHorizontalLine(1, y-4, CATEGORIES_WIDTH-10, LINE_COLOR);
}
if (selectMode == MODE_RENAME_CATEGORY && currentCategory == *it) {
lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN+1, CATEGORIES_WIDTH-2, INVERT_LINE_HEIGHT, DEFAULT_BGCOLOR);
editName(MENUS_MARGIN_LEFT, y, currentCategory->name, LEN_MODEL_FILENAME, event, 1, 0);
if (s_editMode == 0 || event == EVT_KEY_BREAK(KEY_EXIT)) {
modelslist.save();
selectMode = MODE_SELECT_MODEL;
putEvent(EVT_REFRESH);
}
}
else {
drawCategory(y, (*it)->name, currentCategory==*it);
}
y += FH+7;
}
}
// Models
index = 0;
y = 5;
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
if (index >= menuVerticalOffset*2 && index < (menuVerticalOffset+4)*2) {
bool selected = ((selectMode==MODE_SELECT_MODEL || selectMode==MODE_MOVE_MODEL) && index==menuVerticalPosition*2+menuHorizontalPosition);
bool current = !strncmp((*it)->modelFilename, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
if (index & 1) {
drawModel(MODELS_LEFT + MODELS_COLUMN_WIDTH, y, *it, current, selected);
y += 66;
}
else {
drawModel(MODELS_LEFT, y, *it, current, selected);
}
if (selected) {
lcd->drawBitmap(5, LCD_H-FH, modelselModelNameBitmap);
lcdDrawText(22, LCD_H-FH-1, (*it)->modelFilename, SMLSIZE|DEFAULT_COLOR);
}
}
}
// Navigation
if (currentModel) {
if (selectMode == MODE_SELECT_MODEL) {
if (navigate(event, index, 4, 2) != 0) {
setCurrentModel(MODEL_INDEX());
putEvent(EVT_REFRESH);
}
}
else if (selectMode == MODE_MOVE_MODEL) {
int8_t direction = navigate(event, index, 4, 2, false);
if (direction) {
modelslist.moveModel(currentCategory, currentModel, direction);
setCurrentModel(MODEL_INDEX());
putEvent(EVT_REFRESH);
}
}
}
drawVerticalScrollbar(DEFAULT_SCROLLBAR_X + 4, 7, LCD_H - 15, menuVerticalOffset, (index + 1) / 2, 4);
// Footer
lcd->drawBitmap(5, LCD_H-FH-20, modelselSdFreeBitmap);
uint32_t size = sdGetSize() / 100;
lcdDrawNumber(22, LCD_H-FH-21, size, PREC1|SMLSIZE, 0, NULL, "GB");
lcd->drawBitmap(70, LCD_H-FH-20, modelselModelQtyBitmap);
lcdDrawNumber(92, LCD_H-FH-21, modelslist.getModelsCount(),SMLSIZE);
return true;
}
+1 -1
View File
@@ -61,7 +61,7 @@ class FilePreview : public Window
delete bitmap;
const char *ext = getFileExtension(filename);
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
bitmap = BitmapBuffer::load(filename);
bitmap = BitmapBuffer::loadBitmap(filename);
} else {
bitmap = nullptr;
}
+1 -1
View File
@@ -36,7 +36,7 @@ void drawSplash()
bool sd_mounted = sdMounted();
if (!sd_mounted)
sdInit();
splashImg = BitmapBuffer::load(BITMAPS_PATH "/" SPLASH_FILE);
splashImg = BitmapBuffer::loadBitmap(BITMAPS_PATH "/" SPLASH_FILE);
loadImgFromSD = false;
if (!sd_mounted)
sdDone();
+4 -4
View File
@@ -61,11 +61,11 @@ void ThemeBase::init() const
void ThemeBase::load() const
{
if (!asterisk)
asterisk = BitmapBuffer::load(getFilePath("asterisk.bmp"));
asterisk = BitmapBuffer::loadBitmap(getFilePath("asterisk.bmp"));
if (!question)
question = BitmapBuffer::load(getFilePath("question.bmp"));
question = BitmapBuffer::loadBitmap(getFilePath("question.bmp"));
if (!busy)
busy = BitmapBuffer::load(getFilePath("busy.bmp"));
busy = BitmapBuffer::loadBitmap(getFilePath("busy.bmp"));
}
ZoneOptionValue * ThemeBase::getOptionValue(unsigned int index) const
@@ -88,7 +88,7 @@ void ThemeBase::drawThumb(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t flag
#define THUMB_WIDTH 51
#define THUMB_HEIGHT 31
if (!thumb) {
thumb = BitmapBuffer::load(getFilePath("thumb.bmp"));
thumb = BitmapBuffer::loadBitmap(getFilePath("thumb.bmp"));
}
lcd->drawBitmap(x, y, thumb);
if (flags == LINE_COLOR) {
+7 -7
View File
@@ -206,22 +206,22 @@ class FlyskyTheme: public ThemeBase
{
// Calibration screen
delete calibStick;
calibStick = BitmapBuffer::load(getFilePath("stick_pointer.png"));
calibStick = BitmapBuffer::loadBitmap(getFilePath("stick_pointer.png"));
delete calibStickBackground;
calibStickBackground = BitmapBuffer::load(getFilePath("stick_background.png"));
calibStickBackground = BitmapBuffer::loadBitmap(getFilePath("stick_background.png"));
delete calibTrackpBackground;
calibTrackpBackground = BitmapBuffer::load(getFilePath("trackp_background.png"));
calibTrackpBackground = BitmapBuffer::loadBitmap(getFilePath("trackp_background.png"));
delete calibRadioPict;
calibRadioPict = BitmapBuffer::load(getFilePath("NV14.bmp"));
calibRadioPict = BitmapBuffer::loadBitmap(getFilePath("NV14.bmp"));
// Model Selection screen
delete modelselIconBitmap;
modelselIconBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_iconback.png", TITLE_BGCOLOR, DEFAULT_BGCOLOR);
if (modelselIconBitmap) {
BitmapBuffer * bitmap = BitmapBuffer::load(getFilePath("modelsel/icon_default.png"));
BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(getFilePath("modelsel/icon_default.png"));
modelselIconBitmap->drawBitmap(20, 8, bitmap);
delete bitmap;
}
@@ -242,7 +242,7 @@ class FlyskyTheme: public ThemeBase
modelselModelMoveIcon = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveico.png"));
delete modelselWizardBackground;
modelselWizardBackground = BitmapBuffer::load(getFilePath("wizard/background.png"));
modelselWizardBackground = BitmapBuffer::loadBitmap(getFilePath("wizard/background.png"));
// Channels monitor screen
delete chanMonLockedBitmap;
@@ -297,7 +297,7 @@ class FlyskyTheme: public ThemeBase
loadColors();
ThemeBase::load();
if (!backgroundBitmap) {
backgroundBitmap = BitmapBuffer::load(getFilePath("background.png"));
backgroundBitmap = BitmapBuffer::loadBitmap(getFilePath("background.png"));
}
update();
}
+7 -7
View File
@@ -177,13 +177,13 @@ class FrskyTheme: public ThemeBase
{
// Calibration screen
delete calibStick;
calibStick = BitmapBuffer::load(getFilePath("stick_pointer.png"));
calibStick = BitmapBuffer::loadBitmap(getFilePath("stick_pointer.png"));
delete calibStickBackground;
calibStickBackground = BitmapBuffer::load(getFilePath("stick_background.png"));
calibStickBackground = BitmapBuffer::loadBitmap(getFilePath("stick_background.png"));
delete calibTrackpBackground;
calibTrackpBackground = BitmapBuffer::load(getFilePath("trackp_background.png"));
calibTrackpBackground = BitmapBuffer::loadBitmap(getFilePath("trackp_background.png"));
delete calibRadioPict;
#if defined(PCBX10)
@@ -194,14 +194,14 @@ class FrskyTheme: public ThemeBase
calibRadioPict = BitmapBuffer::load(getFilePath("X10.bmp"));
}
#else
calibRadioPict = BitmapBuffer::load(getFilePath("horus.bmp"));
calibRadioPict = BitmapBuffer::loadBitmap(getFilePath("horus.bmp"));
#endif
// Model Selection screen
delete modelselIconBitmap;
modelselIconBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_iconback.png", TITLE_BGCOLOR, DEFAULT_BGCOLOR);
if (modelselIconBitmap) {
BitmapBuffer * bitmap = BitmapBuffer::load(getFilePath("modelsel/icon_default.png"));
BitmapBuffer * bitmap = BitmapBuffer::loadBitmap(getFilePath("modelsel/icon_default.png"));
modelselIconBitmap->drawBitmap(20, 8, bitmap);
delete bitmap;
}
@@ -222,7 +222,7 @@ class FrskyTheme: public ThemeBase
modelselModelMoveIcon = BitmapBuffer::loadMask(getFilePath("modelsel/mask_moveico.png"));
delete modelselWizardBackground;
modelselWizardBackground = BitmapBuffer::load(getFilePath("wizard/background.png"));
modelselWizardBackground = BitmapBuffer::loadBitmap(getFilePath("wizard/background.png"));
// Channels monitor screen
delete chanMonLockedBitmap;
@@ -277,7 +277,7 @@ class FrskyTheme: public ThemeBase
loadColors();
ThemeBase::load();
if (!backgroundBitmap) {
backgroundBitmap = BitmapBuffer::load(getFilePath("background.png"));
backgroundBitmap = BitmapBuffer::loadBitmap(getFilePath("background.png"));
}
update();
}
+54 -42
View File
@@ -23,7 +23,7 @@
#include "menu_radio.h"
#include "menu_screen.h"
// #include "menu_screens.h"
// #include "model_select.h"
#include "model_select.h"
// #include "view_channels.h"
// #include "view_statistics.h"
#include "opentx.h"
@@ -150,12 +150,18 @@ ViewMain::ViewMain(bool icons):
return 0;
});
// new FabButton(this, LCD_W - 50, 100, ICON_THEME,
// [=]() -> uint8_t {
// new ScreensMenu();
// return 0;
// });
new FabButton(this, LCD_W - 50, 100, ICON_THEME,
[=]() -> uint8_t {
new ScreenMenu();
return 0;
});
}
new IconButton(this, {0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH}, ICON_BACK,
[=]() -> uint8_t {
openMenu();
return 0;
}, BUTTON_NOFOCUS);
#endif
}
@@ -184,46 +190,52 @@ void ViewMain::onEvent(event_t event)
case EVT_KEY_LONG(KEY_ENTER):
killEvents(event);
Menu * menu = new Menu();
menu->addLine(STR_MODEL_SELECT, [=]() {
// new ModelselectMenu();
});
if (modelHasNotes()) {
menu->addLine(STR_VIEW_NOTES, [=]() {
// TODO
});
}
menu->addLine(STR_MONITOR_SCREENS, [=]() {
// new ChannelsMonitorMenu();
});
menu->addLine(STR_RESET_SUBMENU, [=]() {
Menu * menu = new Menu();
menu->addLine(STR_RESET_FLIGHT, [=]() {
flightReset();
});
menu->addLine(STR_RESET_TIMER1, [=]() {
timerReset(0);
});
menu->addLine(STR_RESET_TIMER2, [=]() {
timerReset(1);
});
menu->addLine(STR_RESET_TIMER3, [=]() {
timerReset(2);
});
menu->addLine(STR_RESET_TELEMETRY, [=]() {
telemetryReset();
});
});
menu->addLine(STR_STATISTICS, [=]() {
// new StatisticsMenu();
});
menu->addLine(STR_ABOUT_US, [=]() {
// TODO
});
openMenu();
break;
}
}
#endif
void ViewMain::openMenu()
{
Menu * menu = new Menu();
menu->addLine(STR_MODEL_SELECT, [=]() {
new ModelselectMenu();
});
if (modelHasNotes()) {
menu->addLine(STR_VIEW_NOTES, [=]() {
// TODO
});
}
menu->addLine(STR_MONITOR_SCREENS, [=]() {
// new ChannelsMonitorMenu();
});
menu->addLine(STR_RESET_SUBMENU, [=]() {
Menu * menu = new Menu();
menu->addLine(STR_RESET_FLIGHT, [=]() {
flightReset();
});
menu->addLine(STR_RESET_TIMER1, [=]() {
timerReset(0);
});
menu->addLine(STR_RESET_TIMER2, [=]() {
timerReset(1);
});
menu->addLine(STR_RESET_TIMER3, [=]() {
timerReset(2);
});
menu->addLine(STR_RESET_TELEMETRY, [=]() {
telemetryReset();
});
});
menu->addLine(STR_STATISTICS, [=]() {
// new StatisticsMenu();
});
menu->addLine(STR_ABOUT_US, [=]() {
// TODO
});
}
void ViewMain::checkEvents()
{
Window::checkEvents();
+1
View File
@@ -44,6 +44,7 @@ class ViewMain: public FormWindow {
#endif
void paint(BitmapBuffer * dc) override;
void checkEvents() override;
void openMenu();
};
#endif // _VIEW_MAIN_H_