summaryrefslogtreecommitdiff
path: root/glcddrivers
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2011-05-29 17:09:06 +0200
committermrwastl <mrwastl@users.sourceforge.net>2011-05-29 17:09:06 +0200
commitb56b578398b7d9e9b47d8d880ae9778566a99c34 (patch)
treebf972d19e8efdb8ff5659472a19bbcc5b6ff304f /glcddrivers
parent4c345e10f3587a9ed1bdcd1fb10e68c27f876961 (diff)
downloadgraphlcd-base-b56b578398b7d9e9b47d8d880ae9778566a99c34.tar.gz
graphlcd-base-b56b578398b7d9e9b47d8d880ae9778566a99c34.tar.bz2
add fgcol/bgcol class members to base class cDriver, add distinction between default fg/bg colours from driver and fg/bg colours from class; adapt serdisp-driver to these changes
Diffstat (limited to 'glcddrivers')
-rw-r--r--glcddrivers/driver.c2
-rw-r--r--glcddrivers/driver.h14
-rw-r--r--glcddrivers/serdisp.c30
-rw-r--r--glcddrivers/serdisp.h5
4 files changed, 26 insertions, 25 deletions
diff --git a/glcddrivers/driver.c b/glcddrivers/driver.c
index 2a823d7..8ba192a 100644
--- a/glcddrivers/driver.c
+++ b/glcddrivers/driver.c
@@ -28,6 +28,8 @@ cDriver::cDriver()
: width(0),
height(0)
{
+ fgcol = GetDefaultForegroundColor();
+ bgcol = GetDefaultBackgroundColor();
}
//void cDriver::SetScreen(const unsigned char * data, int wid, int hgt, int lineSize)
diff --git a/glcddrivers/driver.h b/glcddrivers/driver.h
index c235459..5b75c20 100644
--- a/glcddrivers/driver.h
+++ b/glcddrivers/driver.h
@@ -42,10 +42,14 @@ public:
class cDriver
{
protected:
- int width;
- int height;
+ int width;
+ int height;
+ uint32_t bgcol;
+ uint32_t fgcol;
virtual bool GetDriverFeature (const std::string & Feature, int & value) { return false; }
+ virtual GLCD::cColor GetDefaultBackgroundColor(void) { return GLCD::cColor(GLCD::cColor::Black); }
+ GLCD::cColor GetDefaultForegroundColor(void) { return GLCD::cColor(GetBackgroundColor()).Invert(); }
public:
cDriver();
virtual ~cDriver() {}
@@ -65,13 +69,11 @@ public:
virtual void SetBrightness(unsigned int percent) {}
- virtual GLCD::cColor GetBackgroundColor(void) { return GLCD::cColor(GLCD::cColor::White); }
virtual bool SetFeature (const std::string & Feature, int value) { return false; }
- GLCD::cColor GetForegroundColor(void) {
- return GLCD::cColor(GetBackgroundColor()).Invert();
- }
+ GLCD::cColor GetBackgroundColor(bool driverdefault=false) { return (driverdefault) ? GetDefaultBackgroundColor() : (GLCD::cColor)bgcol; }
+ GLCD::cColor GetForegroundColor(bool driverdefault=false) { return (driverdefault) ? GetDefaultForegroundColor() : (GLCD::cColor)fgcol; }
// not to be overridden, override GetDriverFeature() instead
// the following feature names (case insensitive!) are guaranteed to give results:
diff --git a/glcddrivers/serdisp.c b/glcddrivers/serdisp.c
index 9c667dc..c419f08 100644
--- a/glcddrivers/serdisp.c
+++ b/glcddrivers/serdisp.c
@@ -86,8 +86,8 @@ int cDriverSerDisp::Init(void)
/* pre-init some flags, function pointers, ... */
supports_options = 0;
- fg_colour = GLCD::cColor::Black; /* set foreground colour to black */
- bg_colour = GLCD::cColor::ERRCOL;
+ fgcol = GLCD::cColor::Black; /* set foreground colour to black */
+ bgcol = GLCD::cColor::ERRCOL;
// get serdisp version
fp_serdisp_getversioncode = (long int (*)()) dlsym(sdhnd, "serdisp_getversioncode");
@@ -232,12 +232,12 @@ int cDriverSerDisp::Init(void)
} else if (config->options[i].name == "Wiring") {
wiringstring = config->options[i].value;
} else if (config->options[i].name == "FGColour") {
- fg_colour = (uint32_t)strtoul(config->options[i].value.c_str(), (char **)NULL, 0);
- fg_colour |= 0xFF000000; /* force alpha to 0xFF */
+ fgcol = (uint32_t)strtoul(config->options[i].value.c_str(), (char **)NULL, 0);
+ fgcol |= 0xFF000000; /* force alpha to 0xFF */
fg_forced = 1;
} else if (config->options[i].name == "BGColour") {
- bg_colour = (uint32_t)strtoul(config->options[i].value.c_str(), (char **)NULL, 0);
- bg_colour |= 0xFF000000; /* force alpha to 0xFF */
+ bgcol = (uint32_t)strtoul(config->options[i].value.c_str(), (char **)NULL, 0);
+ bgcol |= 0xFF000000; /* force alpha to 0xFF */
bg_forced = 1;
}
}
@@ -297,9 +297,9 @@ int cDriverSerDisp::Init(void)
// self-emitting displays (like OLEDs): default background colour => black
if ( supports_options && fp_serdisp_isoption(dd, "SELFEMITTING") && (fp_serdisp_getoption(dd, "SELFEMITTING", 0)) ) {
if (!bg_forced)
- bg_colour = GLCD::cColor::Black; /* set background colour to black */
+ bgcol = GLCD::cColor::Black; /* set background colour to black */
if (!fg_forced)
- fg_colour = GLCD::cColor::White; /* set foreground colour to white */
+ fgcol = GLCD::cColor::White; /* set foreground colour to white */
}
width = config->width;
@@ -428,13 +428,13 @@ int cDriverSerDisp::CheckSetup()
void cDriverSerDisp::Clear(void)
{
- if (bg_colour == GLCD::cColor::ERRCOL) // bg_colour not set
+ if (bgcol == GLCD::cColor::ERRCOL) // bgcol not set
fp_serdisp_clearbuffer(dd);
- else { /* if bg_colour is set, draw background 'by hand' */
+ else { /* if bgcol is set, draw background 'by hand' */
int x,y;
for (y = 0; y < fp_serdisp_getheight(dd); y++)
for (x = 0; x < fp_serdisp_getwidth(dd); x++)
- fp_serdisp_setcolour(dd, x, y, (long)bg_colour);
+ fp_serdisp_setcolour(dd, x, y, (long)bgcol);
}
}
@@ -449,9 +449,9 @@ void cDriverSerDisp::Set8Pixels(int x, int y, unsigned char data) {
for (i = 0; i < 8; i++) {
pixel = data & (1 << i);
if (pixel) {
- SetPixel(start + i, y, (long)fg_colour);
- } else if (!pixel && bg_colour != GLCD::cColor::ERRCOL) { /* if bg_colour is set: use it if pixel is not set */
- SetPixel(start + i, y, (long)bg_colour);
+ SetPixel(start + i, y, (long)fgcol);
+ } else if (!pixel && bgcol != GLCD::cColor::ERRCOL) { /* if bgcol is set: use it if pixel is not set */
+ SetPixel(start + i, y, (long)bgcol);
}
}
}
@@ -510,7 +510,7 @@ void cDriverSerDisp::SetBrightness(unsigned int percent)
fp_serdisp_setoption(dd, "BRIGHTNESS", (long)percent);
}
-GLCD::cColor cDriverSerDisp::GetBackgroundColor(void) {
+GLCD::cColor cDriverSerDisp::GetDefaultBackgroundColor(void) {
if ( supports_options && fp_serdisp_isoption(dd, "SELFEMITTING") && (fp_serdisp_getoption(dd, "SELFEMITTING", 0)) ) {
return GLCD::cColor::Black;
}
diff --git a/glcddrivers/serdisp.h b/glcddrivers/serdisp.h
index 2300357..659b789 100644
--- a/glcddrivers/serdisp.h
+++ b/glcddrivers/serdisp.h
@@ -65,8 +65,6 @@ private:
long serdisp_version;
int supports_options;
- uint32_t fg_colour;
- uint32_t bg_colour;
void* sdhnd; // serdisplib handle
void* dd; // display descriptor
@@ -102,6 +100,7 @@ private:
protected:
virtual bool GetDriverFeature (const std::string & Feature, int & value);
+ virtual GLCD::cColor GetDefaultBackgroundColor(void);
public:
@@ -120,8 +119,6 @@ public:
virtual void Refresh(bool refreshAll = false);
virtual void SetBrightness(unsigned int percent);
- virtual GLCD::cColor GetBackgroundColor(void);
-
virtual bool SetFeature (const std::string & Feature, int value);
virtual cGLCDEvent * GetEvent(void);