T Tomtom2 New Member Licensed User Longtime User Feb 21, 2020 #1 Hallo, I try to understand in wich way the Library for Adafruit_SSD1306.h was create. There are some statemates that I do not understand. I hope some can explain this. in rAdafruit_SSD1306.h there will be the definitions. Why i need both definitions of "B4RAdafruitGFX" Code: private: ... Adafruit_SSD1306* ssd; B4RAdafruitGFX gfx; public: B4RAdafruitGFX* GFX; in rAdafruit_SSD1306.cpp is the function definition of init(): The "gfx" Object have no gfx method, what the meanning of. And why I have to assign the ssd Object to gfx. In the Arduino code the constructor of "Adafruit_SSD1306" get a gfx Object Code: void B4RAdafruitSSD1306::init() { gfx.gfx = ssd; GFX = &gfx; ssd->setTextColor(WHITE); }
Hallo, I try to understand in wich way the Library for Adafruit_SSD1306.h was create. There are some statemates that I do not understand. I hope some can explain this. in rAdafruit_SSD1306.h there will be the definitions. Why i need both definitions of "B4RAdafruitGFX" Code: private: ... Adafruit_SSD1306* ssd; B4RAdafruitGFX gfx; public: B4RAdafruitGFX* GFX; in rAdafruit_SSD1306.cpp is the function definition of init(): The "gfx" Object have no gfx method, what the meanning of. And why I have to assign the ssd Object to gfx. In the Arduino code the constructor of "Adafruit_SSD1306" get a gfx Object Code: void B4RAdafruitSSD1306::init() { gfx.gfx = ssd; GFX = &gfx; ssd->setTextColor(WHITE); }
Erel B4X founder Staff member Licensed User Longtime User Feb 23, 2020 #2 Tomtom2 said: Why i need both definitions of "B4RAdafruitGFX" Click to expand... A pointer points to an object. The object allocated memory must be kept somewhere or bad things will happen. In this case the object (B4RAdafruitGFX instance) memory is inside SSD1306 object. B4R works with pointer to objects so there is another pointer field. Tomtom2 said: in rAdafruit_SSD1306.cpp is the function definition of init(): The "gfx" Object have no gfx method, what the meanning of. And why I have to assign the ssd Object to gfx. In the Arduino code the constructor of "Adafruit_SSD1306" get a gfx Object Click to expand... The answer starts in the wrapped library code: Code: class Adafruit_SSD1306 : public Adafruit_GFX As you can see SSD is also a GFX object. rAdafruitGFX does have a gfx field: Code: class B4RAdafruitGFX { public: //~hide Adafruit_GFX* gfx; All the drawing methods use this field.
Tomtom2 said: Why i need both definitions of "B4RAdafruitGFX" Click to expand... A pointer points to an object. The object allocated memory must be kept somewhere or bad things will happen. In this case the object (B4RAdafruitGFX instance) memory is inside SSD1306 object. B4R works with pointer to objects so there is another pointer field. Tomtom2 said: in rAdafruit_SSD1306.cpp is the function definition of init(): The "gfx" Object have no gfx method, what the meanning of. And why I have to assign the ssd Object to gfx. In the Arduino code the constructor of "Adafruit_SSD1306" get a gfx Object Click to expand... The answer starts in the wrapped library code: Code: class Adafruit_SSD1306 : public Adafruit_GFX As you can see SSD is also a GFX object. rAdafruitGFX does have a gfx field: Code: class B4RAdafruitGFX { public: //~hide Adafruit_GFX* gfx; All the drawing methods use this field.