I'm taking a stab at converting the Adafruit_GFX library from C++ to FP. Digging through my "The C++ Programming Language" by Bjarne Stroustrup I can't find a direct reference to this so I'm having trouble figuring out exactly how to convert. So I thought maybe I'd ask here before I try again with the book.
In C++ we have the public constructor defined in the .h file as WIDTH, HEIGHT protected:
public:
Adafruit_GFX(int16_t w, int16_t h); // Constructor
...
protected:
int16_t WIDTH, ///< This is the 'raw' display width - never changes
HEIGHT; ///< This is the 'raw' display height - never changes
and then in the cpp file:
Adafruit_GFX::Adafruit_GFX(int16_t w, int16_t h) : WIDTH(w), HEIGHT(h) {
_width = WIDTH;
_height = HEIGHT;
...
}
Now the pascal translation.
protected
WIDTH : Int16; ///< This is the 'raw' display width - never changes
HEIGHT : Int16; ///< This is the 'raw' display height - never changes
_width, ///< Display width as modified by current rotation
_height, ///< Display height as modified by current rotation
...
public
constructor Adafruit_GFX(w : Int16; h : Int16);
and further down
constructor TAdafruit_GFX.Adafruit_GFX(w : Int16; h : Int16);
begin
_width := WIDTH;
_height := HEIGHT;
...
end;
I could set up WIDTH and HEIGHT as default initializers
constructor TAdafruit_GFX.Adafruit_GFX(w : Int16 = WIDTH; h : Int16 = HEIGHT);
end;
but then what initializes WIDTH, HEIGHT?
Inside the Adafruit_SPITFT.cpp the constructor is called:
Adafruit_GFX(w, h) where w,h are arguments to the SPITFT constructor.
Following the constructors AdaFruit_ILI9341 is dependant on Adafruit_SPITFT which is dependent on Adafruit_GFX and eventually inside Adafruit_ILI9341.h there is passed down to the Adafruit_GFX constructor.
#define ILI9341_TFTWIDTH 240 ///< ILI9341 max TFT width
#define ILI9341_TFTHEIGHT 320 ///< ILI9341 max TFT height
But that doesn't explain how the protected WIDTH, HEIGHT are initialized.
Or does the : WIDTH(w), HEIGHT(h) assign the passed w,h into the protected variables that are then used to initialize the _width and _height?
Hope that description makes sense.
John