No need to set text color all the time

Since the cursor blinking is handled a bit differently now, there is no need to set text color all the time since we know it should always be white. But just to be certain, lets set it to WHITE first thing in the updatePage function.
Also moved the code from plotMIDI into a custom render function for midi sub menu.
This commit is contained in:
Mikael Degerfält 2019-06-23 21:28:35 +02:00
parent 7a2b70c38d
commit 9561556302
2 changed files with 35 additions and 42 deletions

View file

@ -130,7 +130,6 @@ static void drawAdjustBase(const char* title, bool all) {
display.drawLine(120,36,120,40,WHITE); display.drawLine(120,36,120,40,WHITE);
display.setTextSize(1); display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(25,2); display.setCursor(25,2);
display.println(title); display.println(title);

View file

@ -190,15 +190,14 @@ static const char* numToString(int16_t value, char* dest, bool plusSign = false)
return dest; return dest;
} }
static void plotSubOption(const char* label, int color) { static void plotSubOption(const char* label) {
display.setTextColor(color);
display.setTextSize(2); display.setTextSize(2);
int x_pos = 96-strlen(label)*6; int x_pos = 96-strlen(label)*6;
display.setCursor(x_pos,33); display.setCursor(x_pos,33);
display.println(label); display.println(label);
} }
static bool drawSubMenu(const MenuPage *page, int color) { static bool drawSubMenu(const MenuPage *page) {
int index = cursors[page->cursor]; int index = cursors[page->cursor];
// TODO: Null check subMenuFunc // TODO: Null check subMenuFunc
const MenuEntry* subEntry = page->entries[index]; const MenuEntry* subEntry = page->entries[index];
@ -213,7 +212,7 @@ static bool drawSubMenu(const MenuPage *page, int color) {
// If ECustom flag is set, we assume that the getSubTextFunc // If ECustom flag is set, we assume that the getSubTextFunc
// rendered by it self. // rendered by it self.
if( !(sub->flags & EMenuEntryCustom)) { if( !(sub->flags & EMenuEntryCustom)) {
plotSubOption(buffer, color); plotSubOption(buffer);
if(labelPtr != nullptr) { if(labelPtr != nullptr) {
// TODO: handle this better, we should center text + label // TODO: handle this better, we should center text + label
display.setCursor(105,40); display.setCursor(105,40);
@ -247,7 +246,7 @@ static bool updateSubMenuCursor(const MenuPage *page, uint32_t timeNow)
clearSubValue(); clearSubValue();
} else { } else {
cursorNow = WHITE; cursorNow = WHITE;
return drawSubMenu( page, cursorNow ); return drawSubMenu(page);
} }
} }
return false; return false;
@ -272,7 +271,6 @@ static void drawMenu(const MenuPage *page) {
//Initialize display and draw menu header + line //Initialize display and draw menu header + line
display.clearDisplay(); display.clearDisplay();
display.setTextSize(1); display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0); display.setCursor(0,0);
if(page->flags & EMenuCustomTitle) { if(page->flags & EMenuCustomTitle) {
@ -318,7 +316,6 @@ static void drawPatchView(){
if (FPD){ if (FPD){
drawTrills(); drawTrills();
} }
display.setTextColor(WHITE);
display.setTextSize(6); display.setTextSize(6);
if (FPD < 2){ if (FPD < 2){
int align; int align;
@ -344,7 +341,6 @@ static void drawSubBox(const char* label)
{ {
display.fillRect(63,11,64,52,BLACK); display.fillRect(63,11,64,52,BLACK);
display.drawRect(63,11,64,52,WHITE); display.drawRect(63,11,64,52,WHITE);
display.setTextColor(WHITE);
display.setTextSize(1); display.setTextSize(1);
int len = strlen(label); int len = strlen(label);
@ -357,20 +353,6 @@ void drawMenuCursor(byte itemNo, byte color){
display.drawTriangle(57, ymid,61, ymid+2,61, ymid-2, color); display.drawTriangle(57, ymid,61, ymid+2,61, ymid-2, color);
} }
static void plotMIDI(int color) {
char buff[7];
numToString(MIDIchannel, buff);
plotSubOption(buff, color);
if (slowMidi && color) {
display.setTextColor(WHITE);
} else {
display.setTextColor(BLACK);
}
display.setTextSize(1);
display.setCursor(116,51);
display.print("S");
}
//*********************************************************** //***********************************************************
// TODO: Move these to a settings.cpp maybe? // TODO: Move these to a settings.cpp maybe?
@ -437,13 +419,19 @@ const MenuEntrySub octaveMenu = {
, nullptr , nullptr
}; };
const MenuEntrySub midiMenu = { static void midiSaveFunc(const MenuEntrySub & __unused sub) { writeSetting(MIDI_ADDR, MIDIchannel); }
MenuType::ESub, "MIDI CH", "MIDI CHNL", &MIDIchannel, 1, 16, EMenuEntryCustom | EMenuEntryEnterHandler, static void midiCustomDrawFunc(SubMenuRef __unused, char* __unused, const char** __unused) {
[](SubMenuRef __unused, char* __unused out, const char** __unused unit) { char buff[7];
plotMIDI(WHITE); numToString(MIDIchannel, buff);
}, plotSubOption(buff);
[](const MenuEntrySub & __unused sub) { writeSetting(MIDI_ADDR, MIDIchannel); }, if (slowMidi) {
[]() -> bool { // On enter handler display.setTextSize(1);
display.setCursor(116,51);
display.print("S");
}
}
static bool midiEnterHandlerFunc() {
readSwitches(); readSwitches();
if (pinkyKey){ if (pinkyKey){
slowMidi = !slowMidi; slowMidi = !slowMidi;
@ -455,6 +443,10 @@ const MenuEntrySub midiMenu = {
return true; return true;
} }
} }
const MenuEntrySub midiMenu = {
MenuType::ESub, "MIDI CH", "MIDI CHNL", &MIDIchannel, 1, 16, EMenuEntryCustom | EMenuEntryEnterHandler,
midiCustomDrawFunc, midiSaveFunc, midiEnterHandlerFunc
}; };
const MenuEntryStateCh adjustMenu = { MenuType::EStateChange, "ADJUST", ADJUST_MENU }; const MenuEntryStateCh adjustMenu = { MenuType::EStateChange, "ADJUST", ADJUST_MENU };
@ -832,7 +824,7 @@ static bool selectMenuOption(const MenuPage *page) {
activeSub[page->cursor] = cursorPosition+1; activeSub[page->cursor] = cursorPosition+1;
drawMenuCursor(cursorPosition, WHITE); drawMenuCursor(cursorPosition, WHITE);
drawSubBox( ((const MenuEntrySub*)menuEntry)->subTitle); drawSubBox( ((const MenuEntrySub*)menuEntry)->subTitle);
drawSubMenu(page, WHITE); drawSubMenu(page);
return true; return true;
case MenuType::EStateChange: case MenuType::EStateChange:
@ -901,7 +893,7 @@ static bool updateSubMenu(const MenuPage *page, KeyState &input, uint32_t timeNo
if(redrawSubValue) { if(redrawSubValue) {
clearSubValue(); clearSubValue();
redraw |= drawSubMenu(page, WHITE); redraw |= drawSubMenu(page);
cursorNow = BLACK; cursorNow = BLACK;
cursorBlinkTime = timeNow; cursorBlinkTime = timeNow;
} }
@ -957,6 +949,9 @@ static bool updateMenuPage(const MenuPage *page, KeyState &input, uint32_t timeN
} }
static bool updatePage(const MenuPage *page, KeyState &input, uint32_t timeNow) { static bool updatePage(const MenuPage *page, KeyState &input, uint32_t timeNow) {
display.setTextColor(WHITE);
if(page->flags & EMenuPageCustom) { if(page->flags & EMenuPageCustom) {
auto custom = (const MenuPageCustom*)page; auto custom = (const MenuPageCustom*)page;
return custom->menuUpdateFunc(input, timeNow); return custom->menuUpdateFunc(input, timeNow);
@ -1128,7 +1123,6 @@ static bool patchPageUpdate(KeyState& input, uint32_t timeNow) {
case BTN_MENU+BTN_ENTER: case BTN_MENU+BTN_ENTER:
midiPanic(); midiPanic();
display.clearDisplay(); display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(2); display.setTextSize(2);
display.setCursor(35,15); display.setCursor(35,15);
display.println("DON'T"); display.println("DON'T");