Now the curses driver supports a -B option: backlight color (on) color.
This goes with the "standard" background color option -b to give the appearance of a backlight.
This commit is contained in:
@@ -108,6 +108,8 @@ set_background_color (char * buf) {
|
|||||||
#define TOP_LEFT_X 7
|
#define TOP_LEFT_X 7
|
||||||
#define TOP_LEFT_Y 7
|
#define TOP_LEFT_Y 7
|
||||||
|
|
||||||
|
int current_color_pair, current_border_pair, curses_backlight_state = 0;
|
||||||
|
|
||||||
int
|
int
|
||||||
curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
||||||
{
|
{
|
||||||
@@ -118,7 +120,8 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
|||||||
|
|
||||||
// Colors....
|
// Colors....
|
||||||
chtype back_color = DEFAULT_BACKGROUND_COLOR,
|
chtype back_color = DEFAULT_BACKGROUND_COLOR,
|
||||||
fore_color = DEFAULT_FOREGROUND_COLOR;
|
fore_color = DEFAULT_FOREGROUND_COLOR,
|
||||||
|
backlight_color = DEFAULT_BACKGROUND_COLOR;
|
||||||
|
|
||||||
// Screen position (top left)
|
// Screen position (top left)
|
||||||
int screen_begx = TOP_LEFT_X,
|
int screen_begx = TOP_LEFT_X,
|
||||||
@@ -150,6 +153,14 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
|||||||
strncpy(buf, argv[++i], sizeof(buf));
|
strncpy(buf, argv[++i], sizeof(buf));
|
||||||
back_color = set_background_color(buf);
|
back_color = set_background_color(buf);
|
||||||
break;
|
break;
|
||||||
|
case 'B':
|
||||||
|
if (i + 1 >= argc) {
|
||||||
|
fprintf (stderr, "curses_init: %s requires an argument\n", argv[i]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
strncpy(buf, argv[++i], sizeof(buf));
|
||||||
|
backlight_color = set_background_color(buf);
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
printf ("LCDproc [n]curses driver\n"
|
printf ("LCDproc [n]curses driver\n"
|
||||||
"\t-f\tChange the foreground color\n"
|
"\t-f\tChange the foreground color\n"
|
||||||
@@ -210,9 +221,14 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
|||||||
|
|
||||||
if (has_colors()) {
|
if (has_colors()) {
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(1, fore_color, back_color);
|
init_pair(1, back_color, fore_color);
|
||||||
init_pair(2, back_color, fore_color);
|
init_pair(2, fore_color, back_color);
|
||||||
init_pair(3, COLOR_WHITE, back_color);
|
init_pair(3, COLOR_WHITE, back_color);
|
||||||
|
init_pair(4, fore_color, backlight_color);
|
||||||
|
init_pair(5, COLOR_WHITE, backlight_color);
|
||||||
|
|
||||||
|
current_color_pair = 2;
|
||||||
|
current_border_pair = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
curses_drv_clear ();
|
curses_drv_clear ();
|
||||||
@@ -235,7 +251,7 @@ curses_drv_init (struct lcd_logical_driver *driver, char *args)
|
|||||||
driver->flush = curses_drv_flush;
|
driver->flush = curses_drv_flush;
|
||||||
driver->flush_box = curses_drv_flush_box;
|
driver->flush_box = curses_drv_flush_box;
|
||||||
//driver->contrast = NULL;
|
//driver->contrast = NULL;
|
||||||
//driver->backlight = NULL;
|
driver->backlight = curses_drv_backlight;
|
||||||
//driver->set_char = NULL;
|
//driver->set_char = NULL;
|
||||||
driver->icon = curses_drv_icon;
|
driver->icon = curses_drv_icon;
|
||||||
driver->draw_frame = curses_drv_draw_frame;
|
driver->draw_frame = curses_drv_draw_frame;
|
||||||
@@ -254,15 +270,15 @@ curses_drv_wborder (WINDOW *win) {
|
|||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
if (has_colors()) {
|
if (has_colors()) {
|
||||||
wcolor_set(win, 3, NULL);
|
wcolor_set(win, current_border_pair, NULL);
|
||||||
wattron(win, COLOR_PAIR(3) | A_BOLD);
|
wattron(win, COLOR_PAIR(current_border_pair) | A_BOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
box(win, 0, 0);
|
box(win, 0, 0);
|
||||||
|
|
||||||
if (has_colors()) {
|
if (has_colors()) {
|
||||||
wcolor_set(win, 1, NULL);
|
wcolor_set(win, current_color_pair, NULL);
|
||||||
wattron(win, COLOR_PAIR(1));
|
wattron(win, COLOR_PAIR(current_color_pair));
|
||||||
wattroff(win, A_BOLD);
|
wattroff(win, A_BOLD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,7 +310,7 @@ curses_drv_close ()
|
|||||||
void
|
void
|
||||||
curses_drv_clear ()
|
curses_drv_clear ()
|
||||||
{
|
{
|
||||||
wbkgdset(lcd_win, COLOR_PAIR(1) | ' ');
|
wbkgdset(lcd_win, COLOR_PAIR(current_color_pair) | ' ');
|
||||||
curses_drv_wborder (lcd_win);
|
curses_drv_wborder (lcd_win);
|
||||||
werase (lcd_win);
|
werase (lcd_win);
|
||||||
}
|
}
|
||||||
@@ -302,6 +318,33 @@ curses_drv_clear ()
|
|||||||
#define ValidX(a) { if (x > curses_drv->wid) { x = curses_drv->wid; } else x < 1 ? 1 : x; }
|
#define ValidX(a) { if (x > curses_drv->wid) { x = curses_drv->wid; } else x < 1 ? 1 : x; }
|
||||||
#define ValidY(a) { if (y > curses_drv->hgt) { y = curses_drv->hgt; } else y < 1 ? 1 : y; }
|
#define ValidY(a) { if (y > curses_drv->hgt) { y = curses_drv->hgt; } else y < 1 ? 1 : y; }
|
||||||
|
|
||||||
|
void
|
||||||
|
curses_drv_backlight (int on)
|
||||||
|
{
|
||||||
|
if (curses_backlight_state == on)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// no backlight: pairs 2, 3
|
||||||
|
// backlight: pairs 4, 5
|
||||||
|
|
||||||
|
switch (on) {
|
||||||
|
case 0:
|
||||||
|
curses_backlight_state = 0;
|
||||||
|
current_color_pair = 2;
|
||||||
|
current_border_pair = 3;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
curses_backlight_state = 1;
|
||||||
|
current_color_pair = 4;
|
||||||
|
current_border_pair = 5;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
curses_drv_clear;
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
// Prints a string on the lcd display, at position (x,y). The
|
// Prints a string on the lcd display, at position (x,y). The
|
||||||
// upper-left is (1,1), and the lower right should be (20,4).
|
// upper-left is (1,1), and the lower right should be (20,4).
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
extern lcd_logical_driver *curses_drv;
|
extern lcd_logical_driver *curses_drv;
|
||||||
|
|
||||||
int curses_drv_init (struct lcd_logical_driver *driver, char *args);
|
int curses_drv_init (struct lcd_logical_driver *driver, char *args);
|
||||||
|
void curses_drv_backlight (int on);
|
||||||
void curses_drv_close ();
|
void curses_drv_close ();
|
||||||
void curses_drv_clear ();
|
void curses_drv_clear ();
|
||||||
void curses_drv_flush ();
|
void curses_drv_flush ();
|
||||||
|
|||||||
Reference in New Issue
Block a user