Deleting a canvas or display through an Adafruit_GFX pointer called
only the base destructor, so the canvas buffer leaked (#369). AVR is
left out because a virtual destructor links malloc and free into
display sketches that never use the heap (+602 bytes on an Uno).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* GFXcanvas: Allow subclass to take charge of buffer allocations
In Adafruit_dvhstx, the low level driver takes charge of the framebuffer
allocations. Consequently, any allocation by the GFXcanvas class would be
an unused waste of memory.
Introduce a new constructor parameter `bool allocate_buffer=true`. The
default preserves the old behavior of allocating the buffer in the
constructor and freeing it in the destructor, while passing in `false`
skips buffer allocation & freeing.
In this case, the subclass must allocate the buffer before the first
drawing operation (such as in its constructor or begin method), and
free it in its own destructor or end method.
The subclass can also freely change the buffer pointer at runtime, for
instance in a swap method if the underlying framebuffer is double-buffered.
* experimentally run a different clang-format
This runs version 19.1.7: uvx clang-format -i *.cpp *.h
the changes look similar to what was shown during CI
* undo one edit that ci doesn't like
* Change boolean to bool
This avoids compiler warnings such as:
In file included from /home/ed/git/dryer-arduino/ui/src/graphicstest.ino:18:
.pio/libdeps/nucleo_f446re/Adafruit GFX Library_ID13/Adafruit_GFX.h:48:39: warning: 'boolean' is deprecated [-Wdeprecated-declarations]
48 | virtual void invertDisplay(boolean i);
| ^
In file included from /home/ed/.platformio/packages/framework-arduinoststm32/cores/arduino/wiring.h:34,
from /home/ed/.platformio/packages/framework-arduinoststm32/cores/arduino/Arduino.h:32,
from /tmp/tmpvslwxjr7:1:
/home/ed/.platformio/packages/framework-arduinoststm32/cores/arduino/wiring_constants.h:110:14: note: declared here
* Fix clang format issues unrelated to this PR
Addresses the following from CI:
$ python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
--- ./Adafruit_GFX.h (original)
+++ ./Adafruit_GFX.h (reformatted)
@@ -240,8 +240,8 @@
uint8_t textsize_x; ///< Desired magnification in X-axis of text to print()
uint8_t textsize_y; ///< Desired magnification in Y-axis of text to print()
uint8_t rotation; ///< Display rotation (0 thru 3)
- bool wrap; ///< If set, 'wrap' text at right edge of display
- bool _cp437; ///< If set, use correct CP437 charset (default is off)
+ bool wrap; ///< If set, 'wrap' text at right edge of display
+ bool _cp437; ///< If set, use correct CP437 charset (default is off)
GFXfont *gfxFont; ///< Pointer to special font
};
--- ./Adafruit_GFX.cpp (original)
+++ ./Adafruit_GFX.cpp (reformatted)
@@ -1713,9 +1713,7 @@
@returns True if was pressed before, now is not.
*/
/**************************************************************************/
-bool Adafruit_GFX_Button::justReleased() {
- return (!currstate && laststate);
-}
+bool Adafruit_GFX_Button::justReleased() { return (!currstate && laststate); }
// -------------------------------------------------------------------------
Alsp added and example for GFXcanvas that demonstrates the impact of rotation
on pixel layout and also demonstrates getting a pixel based on raw
physical coordinates.
Adafruit_GFX overrides one of the Print::write() functions.
The rules of overload resolution say that all the overloaded options
need to be visible in the class where the first option is found.
Since Adafruit_GFX only overrides write(uint8_t), the other version,
write(const uint8_t *buffer, size_t size) cannot be called on a
Adafruit_GFX display from sketches.
This change adds the "using" directive, which tells C++ to consider
all of Print's write members to be in scope of Adafruit_GFX, even
though only one is overridden.
With using transactions to draw, we save huge amount of time in pin
changing and SPI setup. This new model, together with the updated
ILI9341 lib give a much better performance.
‘Wrong’ behavior is default, so old code will continue to work. New
code can call cp437() after initializing the display to use correct
symbol numbers for upper ASCII characters.