My C++ -fu has let me down and I can't work out the best way to implement replacement drawing functions for the SHARP Memory display that can take a color other than 0 or 1 and use it to perform operations like INVERT or MIN MAX on the pixels in the display.
I can and have created a new subclassed display called mySharpMemDisplay that inherits from Adafruit_SharpMem and overrides the Adafruit_SharpMem::drawPixel() to do what I want, and if I directly call drawPixel() in any of the derived functions in mySharpMemDisplay class it is MY function that gets called and all is well.
The problems I am having are involved in calling inherited functions, like fillTriangle() that I haven't overridden . They go thru a series of calls to other functions in Adafruit_GFX::
and end up using GFXCanvas1::drawPixel(). Basically I think the issue is that I can't work out how to override a great-grandparent's putPixel() (Don't even know if it's possible but there are lots of comments in the Adafruit source code saying things like 'overwrite in subclass' that indicate that there is a way...)
I want fillTriangle() (and other functions) to use mySharpMemDisplay::drawPixel().
Will I end up having to implement my own derived (possibly skeleton) versions of fillTriangle(), writeFastHLine() drawFastHLine() writeLine() writePixel() in order to force everything to use mySharpMemDisplay::drawPixel()? Or is there an easier/more correct way to do this?
Thanks for any help. For what it's worth, here's my subclass code. It works, but with the issue as pointed out above.
Code: Select all
class mySharpMemDisplay: public Adafruit_SharpMem {
public:
mySharpMemDisplay(SPIClass* SPI, int CS, int W, int H, int SPEED)
: Adafruit_SharpMem(SPI, CS, W, H, SPEED){}
//drawPixel that understands INVERSE color
void drawPixel(uint16_t x, uint16_t y, uint16_t color){
if(color < INVERSE){ //INVERSE defined as 2
Adafruit_SharpMem::drawPixel(x,y,color); //use the base drawPixel() for colors 0 and 1
}else{ //color must be INVERSE
//Serial.println("mySharpMemDisplay::drawPixel:: inverse detected");
uint16_t c = getPixel(x, y); //find out what's there at that pixel
if(c)
Adafruit_SharpMem::drawPixel(x, y, 0); //invert it
else
Adafruit_SharpMem::drawPixel(x, y, 1); //invert it
}
}