Skip to content

Commit

Permalink
tested menus after Print derivation, PASSED
Browse files Browse the repository at this point in the history
  • Loading branch information
neu-rah committed Dec 12, 2014
1 parent 56882fa commit a074713
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 55 deletions.
1 change: 1 addition & 0 deletions examples/gfx_menu/gfx_menu.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/********************
Arduino generic menu system
GFX menu - unsing adafruit gfx screens
tested on ATmega2560
http://www.r-site.net/?at=//op%5B%40id=%273090%27%5D
Sept. 2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
Expand Down
1 change: 1 addition & 0 deletions menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void menu::activate(menuOut& p,Stream& c,bool canExit) {
if (op>=0&&op<sz) {
sel=op;
if (data[op]->enabled) {
printMenu(p,canExit);//clearing old selection
data[op]->activate(p,c,true);
}
} else if (op==-1) {//then exit
Expand Down
7 changes: 0 additions & 7 deletions menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ www.r-site.net
virtual void clearLine(int ln)=0;
virtual void clear()=0;
virtual void setCursor(int x,int y)=0;
/*virtual void print(char ch)=0;
virtual void print(const char *text)=0;
virtual void println(const char *text="")=0;
virtual void print(unsigned long)=0;
virtual void println(unsigned long)=0;
virtual void print(double)=0;
virtual void println(double)=0;*/
virtual void printPrompt(prompt &o,bool selected,int idx,int posY,int width);
virtual void printMenu(menu&,bool drawExit)=0;
};
Expand Down
17 changes: 4 additions & 13 deletions menuGFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,25 @@ www.r-site.net
setCursor(0,0);
}
virtual void setCursor(int x,int y) {gfx.setCursor(x*resX,y*resY);}
virtual void print(char ch) {gfx.print(ch);}
virtual void print(const char *text) {gfx.print(text);}
virtual void println(const char *text="") {gfx.println(text);};
virtual void print(unsigned long i) {gfx.print(i);};
virtual void println(unsigned long i) {gfx.println(i);};
virtual void print(double i) {gfx.print(i);};
virtual void println(double i) {gfx.println(i);};
virtual void print(prompt &o,bool selected,int idx,int posY,int width) {
virtual size_t write(uint8_t ch) {return gfx.write(ch);}
virtual void printPrompt(prompt &o,bool selected,int idx,int posY,int width) {
gfx.fillRect(0,posY*resY,maxX*resX,resY,selected?hiliteColor:bgColor);
gfx.setTextColor(o.enabled?enabledColor:disabledColor);
setCursor(0,posY);
o.printTo(*this);
//println();
}
virtual void printMenu(menu& m,bool drawExit) {
if (drawn!=&m) clear();//clear all screen when changing menu
if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom)
else if (m.sel<top) top=m.sel;//selected option outside device (top)
int i=top;for(;i<m.sz;i++) {
//if ((i>=top)&&((i-top)<maxY)) {
if(i-top>=maxY) break;
if (needRedraw(m,i)) {
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
printPrompt(*m.data[i],i==m.sel,i+1,i-top,m.width);
}
//}
}
if (drawExit&&i-top<maxY&&needRedraw(m,i))
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
printPrompt(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
lastTop=top;
lastSel=m.sel;
drawn=&m;
Expand Down
15 changes: 4 additions & 11 deletions menuLCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,8 @@ www.r-site.net
}
virtual void clear() {lcd.clear();}
virtual void setCursor(int x,int y) {lcd.setCursor(x*resX,y*resY);}
virtual void print(char ch) {lcd.print(ch);}
virtual void print(const char *text) {lcd.print(text);}
virtual void println(const char *text="") {lcd.print(text);};
virtual void print(unsigned long i) {lcd.print(i);};
virtual void println(unsigned long i) {lcd.println(i);};
virtual void print(double i) {lcd.print(i);};
virtual void println(double i) {lcd.println(i);};
virtual void print(prompt &o,bool selected,int idx,int posY,int width) {
virtual size_t write(uint8_t ch) {return lcd.write(ch);}
virtual void printPrompt(prompt &o,bool selected,int idx,int posY,int width) {
clearLine(posY);
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
o.printTo(*this);
Expand All @@ -46,14 +40,13 @@ www.r-site.net
else if (m.sel<top) top=m.sel;//selected option outside device (top)
int i=0;for(;i<m.sz;i++) {
if ((i>=top)&&((i-top)<maxY)) {
//if(i-top>=maxY) break;
if (needRedraw(m,i)) {
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
printPrompt(*m.data[i],i==m.sel,i+1,i-top,m.width);
}
}
}
if (drawExit&&i-top<maxY&&needRedraw(m,i))
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
printPrompt(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
lastTop=top;
lastSel=m.sel;
drawn=&m;
Expand Down
20 changes: 6 additions & 14 deletions menuLCDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ www.r-site.net
}//clear current line
virtual void clear() {lcd.clear();}
virtual void setCursor(int x,int y) {lcd.setCursor(x*resX,y*resY);}
virtual void print(char ch) {lcd.print(ch);}
virtual void print(const char *text) {lcd.print(text);}
virtual void println(const char *text="") {lcd.print(text);};
virtual void print(unsigned long i) {lcd.print(i);};
virtual void println(unsigned long i) {lcd.println(i);};
virtual void print(double i) {lcd.print(i);};
virtual void println(double i) {lcd.println(i);};
virtual void print(prompt &o,bool selected,int idx,int posY,int width) {
virtual size_t write(uint8_t ch) {return lcd.write(ch);}
virtual void printPrompt(prompt &o,bool selected,int idx,int posY,int width) {
clearLine(posY);
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
o.printTo(*this);
Expand All @@ -48,14 +42,12 @@ www.r-site.net
else if (m.sel<top) top=m.sel;//selected option outside device (top)
if (drawn!=&m||top!=lastTop) clear();
int i=top;for(;i<m.sz;i++) {
//if ((i>=top)&&((i-top)<maxY)) {
if(i-top>=maxY) break;
if (needRedraw(m,i))
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
//}
if(i-top>=maxY) break;
if (needRedraw(m,i))
printPrompt(*m.data[i],i==m.sel,i+1,i-top,m.width);
}
if (drawExit&&i-top<maxY&&needRedraw(m,i))
print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
printPrompt(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
lastTop=top;
lastSel=m.sel;
drawn=&m;
Expand Down
14 changes: 4 additions & 10 deletions menuPrint.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ www.r-site.net
virtual void clearLine(int ln) {}
virtual void clear() {device.println("");device.println("");}
virtual void setCursor(int x,int y) {device.println("");}
virtual void print(char ch) {device.print(ch);}
virtual void print(const char *text) {device.print(text);}
virtual void println(const char *text="") {device.println(text);}
virtual void print(unsigned long i) {device.print(i);};
virtual void println(unsigned long i) {device.println(i);};
virtual void print(double i) {device.print(i);};
virtual void println(double i) {device.println(i);};
virtual void print(prompt &o,bool selected,int idx,int posY,int width) {
virtual size_t write(uint8_t ch) {return device.write(ch);}
virtual void printPrompt(prompt &o,bool selected,int idx,int posY,int width) {
print(idx<10?" ":"");
print((unsigned long)idx);
print(selected?(o.enabled?menu::enabledCursor:menu::disabledCursor):' ');
Expand All @@ -41,8 +35,8 @@ www.r-site.net
clear();
int i=0;
for(;i<m.sz;i++)
print(*m.data[i],i==m.sel,i+1,i-top,m.width);
if (drawExit) print(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
printPrompt(*m.data[i],i==m.sel,i+1,i-top,m.width);
if (drawExit) printPrompt(menu::exitOption,m.sel==m.sz,0,i-top,m.width);
lastTop=top;
lastSel=m.sel;
drawn=&m;
Expand Down

0 comments on commit a074713

Please sign in to comment.