Skip to content

Commit 131b872

Browse files
committed
Fixed excessive redraw on GFX menu
Field range validation etc...
1 parent fc2f913 commit 131b872

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

menu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This software is furnished "as is", without technical support, and with no
55
warranty, express or implied, as to its usefulness for any purpose.
66
77
Thread Safe: No
8-
Extendable: Yes
8+
Extensible: Yes
99
1010
Arduino generic menu system
1111
*/
@@ -30,14 +30,14 @@ int menu::menuKeys(menuOut &p,Stream& c,bool canExit) {
3030
if (sel>0) {
3131
sel--;
3232
if (sel+1>=p.maxY) p.top=sel-p.maxY;
33-
p.drawn=0;
33+
//p.drawn=0;
3434
//printMenu(p,canExit);
3535
}
3636
} else if (ch=='+') {
3737
if (sel<(sz-(canExit?0:1))) {
3838
sel++;
3939
if ((sz-sel+(canExit?1:0))>=p.maxY) p.top=sel-(canExit?1:0);
40-
p.drawn=0;
40+
//p.drawn=0;
4141
//printMenu(p,canExit);
4242
}
4343
} else if (ch==27) {
@@ -64,7 +64,7 @@ void menu::activate(menuOut& p,Stream& c,bool canExit) {
6464
activeNode=this;
6565
sel=0;
6666
p.top=0;
67-
p.drawn=0;//redraw menu
67+
//p.drawn=0;//redraw menu
6868
this->canExit=canExit;
6969
}
7070
int op=-1;

menu.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This software is furnished "as is", without technical support, and with no
55
warranty, express or implied, as to its usefulness for any purpose.
66
77
Thread Safe: No
8-
Extendable: Yes
8+
Extensible: Yes
99
1010
Arduino generic menu system
1111
@@ -15,8 +15,8 @@ Arduino generic menu system
1515
menuPrint: menuOut implementation for generic print (as Serial)
1616
menuLCD: menuOut implementation for standard LiquidCrystal LCD
1717
18-
the menu system will read provided stream for input, it works for Serial
19-
for encoders, joysticks, keyboards or touch a stream must be made out of them
18+
the menu system will read provided stream for input, it works for Serial,
19+
encoders, joysticks, keyboards (or touch?) a stream must be made out of them
2020
*/
2121
#ifndef RSITE_ARDUINOP_MENU_SYSTEM
2222
#define RSITE_ARDUINOP_MENU_SYSTEM
@@ -142,6 +142,9 @@ for encoders, joysticks, keyboards or touch a stream must be made out of them
142142
//device resolution
143143
int resX;
144144
int resY;
145+
//preventing uneeded redraws
146+
int lastTop;
147+
int lastSel;
145148
menuOut(int x=0x7F,int y=0x7F,int resX=1,int resY=1)
146149
:maxX(x),maxY(y),top(0),resX(resX),resY(resY),drawn(0) {}
147150
virtual void clear()=0;

menuGFX.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This software is furnished "as is", without technical support, and with no
55
warranty, express or implied, as to its usefulness for any purpose.
66
77
Thread Safe: No
8-
Extendable: Yes
8+
Extensible: Yes
99
1010
Use graphics screens (adafruit library based) as menu output
1111
***/
@@ -30,8 +30,6 @@ Use graphics screens (adafruit library based) as menu output
3030

3131
class menuGFX:public menuOut {
3232
public:
33-
int lastTop;
34-
int lastSel;
3533
uint16_t bgColor;
3634
uint16_t enabledColor;
3735
uint16_t disabledColor;
@@ -69,14 +67,18 @@ Use graphics screens (adafruit library based) as menu output
6967
println();
7068
}
7169
virtual void printMenu(menu& m,bool drawExit) {
72-
if (drawn!=&m) clear();
70+
if (drawn!=&m) clear();//clear all screen when changing menu
7371
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
7472
else if (m.sel<top) top=m.sel;//selected option outside device (top)
7573
int i=0;for(;i<m.sz;i++) {
7674
if ((i>=top)&&((i-top)<maxY)) {
7775
if(i-top>=maxY) break;
78-
if ((top!=lastTop)||(i==m.sel)||(i==lastSel)||(drawn!=&m))
76+
if ((drawn!=&m)||(top!=lastTop)||(m.sel!=lastSel&&((i==m.sel)||(i==lastSel)))) {
77+
Serial<<hex((long)drawn)<<" <-> "<<hex((long)&m)
78+
<<(drawn!=&m)<<(top!=lastTop)<<(m.sel!=lastSel&&((i==m.sel)||(i==lastSel)))
79+
<<" drawing option:"<<m.data[i]->text<<endl;
7980
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
81+
}
8082
}
8183
}
8284
if (drawExit&&i-top<maxY&&((top!=lastTop)||(i==m.sel)||(i==lastSel)||(drawn!=&m)))

menuLCD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This software is furnished "as is", without technical support, and with no
55
warranty, express or implied, as to its usefulness for any purpose.
66
77
Thread Safe: No
8-
Extendable: Yes
8+
Extensible: Yes
99
1010
Use standard arduino LCD (LiquidCrystal library) as menu output
1111
***/

menuLCDs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This software is furnished "as is", without technical support, and with no
55
warranty, express or implied, as to its usefulness for any purpose.
66
77
Thread Safe: No
8-
Extendable: Yes
8+
Extensible: Yes
99
1010
implement menu output for Francisco Malpartida arduino LCD's
1111

menuPrint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This software is furnished "as is", without technical support, and with no
55
warranty, express or implied, as to its usefulness for any purpose.
66
77
Thread Safe: No
8-
Extendable: Yes
8+
Extensible: Yes
99
1010
menu output to Print device (ex: Serial)
1111
***/

0 commit comments

Comments
 (0)