acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

Button.h (1807B)

      1 /***************************************************************************************
      2 // The following button class has been ported over from the Adafruit_GFX library so
      3 // should be compatible.
      4 // A slightly different implementation in this TFT_eSPI library allows the button
      5 // legends to be in any font, allow longer labels and to adjust text positioning
      6 // within button
      7 ***************************************************************************************/
      8 
      9 class TFT_eSPI_Button
     10 {
     11  public:
     12   TFT_eSPI_Button(void);
     13   // "Classic" initButton() uses centre & size
     14   void     initButton(TFT_eSPI *gfx, int16_t x, int16_t y,
     15   uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
     16   uint16_t textcolor, char *label, uint8_t textsize);
     17 
     18   // New/alt initButton() uses upper-left corner & size
     19   void     initButtonUL(TFT_eSPI *gfx, int16_t x1, int16_t y1,
     20   uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
     21   uint16_t textcolor, char *label, uint8_t textsize);
     22   
     23   // Adjust text datum and x, y deltas
     24   void     setLabelDatum(int16_t x_delta, int16_t y_delta, uint8_t datum = MC_DATUM);
     25   
     26   void     drawButton(bool inverted = false, String long_name = "");
     27   bool     contains(int16_t x, int16_t y);
     28 
     29   void     press(bool p);
     30   bool     isPressed();
     31   bool     justPressed();
     32   bool     justReleased();
     33 
     34  private:
     35   TFT_eSPI *_gfx;
     36   int16_t  _x1, _y1; // Coordinates of top-left corner of button
     37   int16_t  _xd, _yd; // Button text datum offsets (wrt centre of button)
     38   uint16_t _w, _h;   // Width and height of button
     39   uint8_t  _textsize, _textdatum; // Text size multiplier and text datum for button
     40   uint16_t _outlinecolor, _fillcolor, _textcolor;
     41   char     _label[10]; // Button text is 9 chars maximum unless long_name used
     42 
     43   bool  currstate, laststate; // Button states
     44 };