Projectitis
Well-known member
Hi all,
Bit of background - I'm a seasoned programmer (20+ years professional) but less c/c++ experience than I would like.
So I'm working on a GUI library that will support Adafruit_GFX, Paul's fast t3 library and Franks' DMA version, and also sumotoy's RA8875 library and others. The aim of the library is to provide very simple-to-use but beautiful GUI controls for your projects - you can spend less time thinking about your GUI and more on your project
Anyhow, the way this works is that you pass an instance of your library into the constructor like so:
Unfortunately, the various GFX libraries do not inherit from a common class that provide a common set of methods that my GUI library will need (e.g. drawRect, drawCircle, drawLine etc).
My method of dealing with that is creating a base class (GFXLibrary) like this:
And then creating a subclass for each supported library, creating basically a pass-thru method for each supported method, like the following:
So my question is - is this the most (or at least "an") efficient way of achieving this in c++?
Bit of background - I'm a seasoned programmer (20+ years professional) but less c/c++ experience than I would like.
So I'm working on a GUI library that will support Adafruit_GFX, Paul's fast t3 library and Franks' DMA version, and also sumotoy's RA8875 library and others. The aim of the library is to provide very simple-to-use but beautiful GUI controls for your projects - you can spend less time thinking about your GUI and more on your project
Anyhow, the way this works is that you pass an instance of your library into the constructor like so:
Code:
#define TFT_DC 9
#define TFT_CS 10
ILI9341_t3 tft;
Projectitis_GUI gui;
void setup() {
tft = new ILI9341_t3(TFT_CS, TFT_DC);
gui = new Projectitis_GUI( tft );
Unfortunately, the various GFX libraries do not inherit from a common class that provide a common set of methods that my GUI library will need (e.g. drawRect, drawCircle, drawLine etc).
My method of dealing with that is creating a base class (GFXLibrary) like this:
Code:
class GFXLibrary{
public:
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
}
And then creating a subclass for each supported library, creating basically a pass-thru method for each supported method, like the following:
Code:
//GFXLibrary_ILI9431_t3.h
class GFXLibrary_ILI9431_t3 : public GFXLibrary{
public:
GFXLibrary_ILI9431_t3( ILI9341_t3 agfx);
ILI9431_t3 *gfx;
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
}
//GFXLibrary_ILI9431_t3.cpp
GFXLibrary_ILI9431_t3::GFXLibrary_ILI9431_t3( ILI9431_t3 agfx ){
gfx = &agfx;
}
void GFXLibrary_ILI9431_t3::drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color){
gfx->drawRect( x,y, w,h, color );
}
void GFXLibrary_ILI9431_t3::drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color){
gfx->drawCircle( x0,y0, r, color );
}
void GFXLibrary_ILI9431_t3::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color){
gfx->drawCircle( x0,y0, x1,y1, color );
}
So my question is - is this the most (or at least "an") efficient way of achieving this in c++?