Skip to content

Commit 82b02bd

Browse files
committed
added color space to gfx screens (better suport on monochrom)
enabledColorHi and disabledColorHi to be used on hilited options
1 parent e7bb2ab commit 82b02bd

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

menuGFX.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/********************
22
Sept. 2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
33
creative commons license 3.0: Attribution-ShareAlike CC BY-SA
4-
This software is furnished "as is", without technical support, and with no
4+
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
@@ -26,7 +26,7 @@ www.r-site.net
2626
#define SILVER RGB565(200,200,200)
2727
#define CYAN 0x07FF
2828
#define MAGENTA 0xF81F
29-
#define YELLOW 0xFFE0
29+
#define YELLOW 0xFFE0
3030
#define WHITE 0xFFFF
3131

3232
class menuGFX:public menuOut {
@@ -35,23 +35,27 @@ www.r-site.net
3535
uint16_t bgColor;
3636
uint16_t enabledColor;
3737
uint16_t disabledColor;
38+
uint16_t enabledColorHi;
39+
uint16_t disabledColorHi;
3840
Adafruit_GFX& gfx;
3941
menuGFX(
4042
Adafruit_GFX& gfx,
4143
uint16_t hiliteColor=BLUE,
4244
uint16_t bgColor=BLACK,
43-
uint16_t enabledColor=WHITE,
45+
uint16_t enabledColor=WHITE,
4446
uint16_t disabledColor=SILVER,
4547
int resX=6,
4648
int resY=9
4749
)
4850
:gfx(gfx),
4951
bgColor(bgColor),
5052
enabledColor(enabledColor),
51-
disabledColor(disabledColor),
53+
disabledColor(disabledColor),
5254
hiliteColor(hiliteColor),
55+
enabledColorHi(enabledColor),
56+
disabledColorHi(disabledColor),
5357
menuOut(gfx.width()/resX,gfx.height()/resY,resX,resY) {}
54-
58+
5559
virtual void clearLine(int ln) {
5660
gfx.fillRect(0,ln*resY,resX*maxX,resY,bgColor);
5761
setCursor(0,ln);
@@ -64,7 +68,7 @@ www.r-site.net
6468
virtual size_t write(uint8_t ch) {return gfx.write(ch);}
6569
virtual void printPrompt(prompt &o,bool selected,int idx,int posX,int posY,int width) {
6670
gfx.fillRect(0,posY*resY,maxX*resX,resY,selected?hiliteColor:bgColor);
67-
gfx.setTextColor(o.enabled?enabledColor:disabledColor);
71+
gfx.setTextColor(selected?(o.enabled?enabledColorHi:disabledColorHi):(o.enabled?enabledColor:disabledColor));
6872
setCursor(0,posY);
6973
o.printTo(*this);
7074
}
@@ -86,4 +90,3 @@ www.r-site.net
8690
}
8791
};
8892
#endif RSITE_ARDUINOP_MENU_LCD
89-

menuU8G.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/********************
22
Sept. 2014 Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
33
creative commons license 3.0: Attribution-ShareAlike CC BY-SA
4-
This software is furnished "as is", without technical support, and with no
4+
This software is furnished "as is", without technical support, and with no
55
warranty, express or implied, as to its usefulness for any purpose.
6-
6+
77
Thread Safe: No
88
Extensible: Yes
99
1010
Use graphics screens as menu output, based on U8GLIB graphic display
1111
www.r-site.net
12-
12+
1313
printPrompt(), Added posX to take into account ox via menu.ox and setPosition(ox,oy), need to update other files to support that.
14-
14+
1515
***/
1616
#ifndef RSITE_ARDUINOP_MENU_U8G
1717
#define RSITE_ARDUINOP_MENU_U8G
18-
//#include <U8glib.h>
19-
#include <U8g_teensy.h>
18+
#include <U8glib.h>
19+
//#include <U8g_teensy.h>
2020
#include "menu.h"
2121

2222
class menuU8G:public menuOut {
@@ -25,7 +25,9 @@ www.r-site.net
2525
unsigned char bgColor;
2626
unsigned char enabledColor;
2727
unsigned char disabledColor;
28-
28+
unsigned char enabledColorHi;
29+
unsigned char disabledColorHi;
30+
2931
U8GLIB& gfx;
3032
menuU8G(
3133
U8GLIB& gfx,
@@ -41,6 +43,8 @@ www.r-site.net
4143
enabledColor(enabledColor),
4244
disabledColor(disabledColor),
4345
hiliteColor(hiliteColor),
46+
enabledColorHi(bgColor),
47+
disabledColorHi(bgColor),
4448
menuOut(gfx.getWidth()/resX,gfx.getHeight()/resY,resX,resY)
4549
{
4650
// Small typefaces used to draw the menu, do not forget to report resX and resY
@@ -52,13 +56,13 @@ www.r-site.net
5256
gfx.setFont(u8g_font_04b_03); // Good result
5357
gfx.setFontPosBottom(); // U8Glib font positioning
5458
}
55-
59+
5660
virtual void clearLine(int ln) {
5761
// No need to clear, the U8Glib display loop clear screen on each refresh
5862
//setCursor(0,ln);
5963
}
6064
virtual void clear() {
61-
// No need to clear, the U8Glib display loop clear screen on each refresh
65+
// No need to clear, the U8Glib display loop clear screen on each refresh
6266
}
6367
virtual void setCursor(int x,int y) {
6468
unsigned char xPxTextOffset = 4; // offset in pixels on text on x againt hightlight bar
@@ -69,22 +73,22 @@ www.r-site.net
6973
return 1;
7074
}
7175
virtual void printPrompt(prompt &o,bool selected,int idx,int posX,int posY,int width) {
72-
gfx.setColorIndex(selected?disabledColor:bgColor);
76+
gfx.setColorIndex(selected?hiliteColor:bgColor);
7377
gfx.drawBox(posX*resX,posY*resY,maxX*resX,resY);
74-
gfx.setColorIndex(selected?hiliteColor:disabledColor);
78+
gfx.setColorIndex(selected?(o.enabled?enabledColorHi:disabledColorHi):(o.enabled?enabledColor:disabledColor));
7579
setCursor(posX,posY+1); //+1 compensate the height of the font and the way how U8Glib works
7680
o.printTo(*this);
7781
}
7882
virtual void printMenu(menu& m,bool drawExit) {
7983
//if (drawn!=&m) clear();//clear all screen when changing menu - not ok for U8Glib
80-
84+
8185
if (m.sel-top >= maxY)
8286
top = m.sel - maxY + resY + 1; //selected option outside device (bottom)
8387
else if (m.sel < top)
8488
top = m.sel + resY; //selected option outside device (top)
85-
89+
8690
int i = top;
87-
91+
8892
for (; i < m.sz; i++)
8993
{
9094
if (i-top >= maxY)
@@ -100,4 +104,3 @@ www.r-site.net
100104
}
101105
};
102106
#endif RSITE_ARDUINOP_MENU_LCD
103-

0 commit comments

Comments
 (0)