|
| 1 | +/******************** |
| 2 | +Sept. 2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com |
| 3 | +creative commons license 3.0: Attribution-ShareAlike CC BY-SA |
| 4 | +This software is furnished "as is", without technical support, and with no |
| 5 | +warranty, express or implied, as to its usefulness for any purpose. |
| 6 | +
|
| 7 | +Thread Safe: No |
| 8 | +Extendable: Yes |
| 9 | +
|
| 10 | +Use graphics screens (adafruit library based) as menu output |
| 11 | +***/ |
| 12 | +#ifndef RSITE_ARDUINOP_MENU_GFX |
| 13 | + #define RSITE_ARDUINOP_MENU_GFX |
| 14 | + #include <Adafruit_GFX.h> |
| 15 | + #include "menu.h" |
| 16 | + |
| 17 | + #define RGB565(r,g,b) ((((r>>3)<<11) | ((g>>2)<<5) | (b>>3))) |
| 18 | + |
| 19 | + // Color definitions RGB565 |
| 20 | + #define BLACK 0x0000 |
| 21 | + #define BLUE 0x001F |
| 22 | + #define RED 0xF800 |
| 23 | + #define GREEN 0x07E0 |
| 24 | + #define GRAY RGB565(128,128,128) |
| 25 | + #define SILVER RGB565(200,200,200) |
| 26 | + #define CYAN 0x07FF |
| 27 | + #define MAGENTA 0xF81F |
| 28 | + #define YELLOW 0xFFE0 |
| 29 | + #define WHITE 0xFFFF |
| 30 | + |
| 31 | + class menuGFX:public menuOut { |
| 32 | + public: |
| 33 | + int lastTop; |
| 34 | + int lastSel; |
| 35 | + uint16_t bgColor; |
| 36 | + uint16_t enabledColor; |
| 37 | + uint16_t disabledColor; |
| 38 | + uint16_t hiliteColor; |
| 39 | + Adafruit_GFX& gfx; |
| 40 | + menuGFX( |
| 41 | + Adafruit_GFX& gfx, |
| 42 | + uint16_t hiliteColor=BLUE, |
| 43 | + uint16_t bgColor=BLACK, |
| 44 | + uint16_t enabledColor=WHITE, |
| 45 | + uint16_t disabledColor=SILVER, |
| 46 | + int resX=5, |
| 47 | + int resY=8 |
| 48 | + ) |
| 49 | + :gfx(gfx), |
| 50 | + bgColor(bgColor), |
| 51 | + enabledColor(enabledColor), |
| 52 | + disabledColor(disabledColor), |
| 53 | + hiliteColor(hiliteColor), |
| 54 | + menuOut(gfx.width()/resX,gfx.height()/resY,resX,resY) {} |
| 55 | + virtual void clear() {gfx.fillScreen(bgColor);gfx.setCursor(0,0);} |
| 56 | + virtual void setCursor(int x,int y) {gfx.setCursor(x*resX,y*resY);} |
| 57 | + virtual void print(char ch) {gfx.print(ch);} |
| 58 | + virtual void print(const char *text) {gfx.print(text);} |
| 59 | + virtual void println(const char *text) {gfx.println(text);}; |
| 60 | + virtual void print(int i) {gfx.print(i);}; |
| 61 | + virtual void println(int i) {gfx.println(i);}; |
| 62 | + virtual void print(prompt &o,bool selected,int idx,int posY,int width) { |
| 63 | + gfx.fillRect(0,posY*resY,width*resX,resY,selected?hiliteColor:bgColor); |
| 64 | + gfx.setTextColor(o.enabled?enabledColor:disabledColor); |
| 65 | + gfx.setCursor(0,posY*resY); |
| 66 | + //gfx.setTextColor(o.enabled?enabledColor:disabledColor,selected?hiliteColor:bgColor); |
| 67 | + gfx.print(o.text); |
| 68 | + } |
| 69 | + virtual void printMenu(menu& m,bool drawExit) { |
| 70 | + if (drawn!=&m) clear(); |
| 71 | + if (m.sel-top>=maxY) top=m.sel-maxY+1;//selected option outside device (bottom) |
| 72 | + else if (m.sel<top) top=m.sel;//selected option outside device (top) |
| 73 | + int i=0;for(;i<m.sz;i++) { |
| 74 | + if ((i>=top)&&((i-top)<maxY)) { |
| 75 | + if(i-top>=maxY) break; |
| 76 | + if ((top!=lastTop)||(i==m.sel)||(i==lastSel)||(drawn!=&m)) |
| 77 | + print(*m.data[i],i==m.sel,i+1,i-top,m.width); |
| 78 | + } |
| 79 | + } |
| 80 | + if (drawExit&&i-top<maxY&&((top!=lastTop)||(i==m.sel)||(i==lastSel)||(drawn!=&m))) |
| 81 | + print(menu::exitOption,m.sel==m.sz,0,i-top,m.width); |
| 82 | + lastTop=top; |
| 83 | + lastSel=m.sel; |
| 84 | + drawn=&m; |
| 85 | + } |
| 86 | + }; |
| 87 | +#endif RSITE_ARDUINOP_MENU_LCD |
| 88 | + |
0 commit comments