Based on a previous suggestion from someone in this forum, I am trying to figure how to define a virtual method inside a class.
I tried multiple ways of defining it but each one generates some kind of error. Below you will find the latest attempt and the error message.
The Error message
Arduino: 1.8.12 (Windows 10), TD: 1.53, Board: "Arduino Uno"
C:\Users\Mike\Desktop\MRE\MRE.ino: In constructor 'CreateButton::CreateButton(String, int, int, int, String, int, int)':
MRE:75:36: error: qualified-id in declaration before '(' token
virtual void CreateButton::Action(void)
^
Multiple libraries were found for "Adafruit_HX8357.h"
Used: C:\Users\Mike\Documents\Arduino\libraries\Adafruit_HX8357_Library
Not used: C:\Users\Mike\Documents\Arduino\libraries\Adafruit_HX8357_Library-1.1.8
exit status 1
qualified-id in declaration before '(' tokenThis report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
#include <Adafruit_HX8357.h>
#define TFT_RST -1 // dont use a reset pin, tie to arduino RST if you like
#define TFT_DC 9
#define TFT_CS 10
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
// Colors
#define BACKGROUNDCLR 0xB5B6
#define HIGHLIGHTCLR 0x0500
#define TEXTCLR 0x0000
#define BORDERCLR 0x0000
#define BUTTONCLR 0x7D75
#define REDCLR 0xA800
#define GREENCLR 0x0360
/**********************************************************************************/
void setup()
{
Serial.begin(115200);
}
/**********************************************************************************/
void loop()
{
}
/**********************************************************************************/
class CreateButton
{
private:
String _key;
int _txtSize;
int _x;
int _y;
String _txt;
int _bgClr;
int _txtClr;
public:
CreateButton(String key, int txtSize, int x, int y, String txt, int bgClr, int txtClr);
virtual void CreateButton::Action(void);
};
/**********************************************************************************/
CreateButton::CreateButton(String key, int txtSize, int x, int y, String txt, int bgClr, int txtClr)
{
_key = key;
_txtSize = txtSize;
_x = x;
_y = y;
_txt = txt;
_bgClr = bgClr;
_txtClr = txtClr;
float charWidth[6] = {6, 6, 12, 18, 24, 28};
float charHeight[6] = {7, 7, 14, 22, 30, 36};
float rectWidth, rectHeight;
rectWidth = (txt.length() + 1) * charWidth[txtSize];
rectHeight = charHeight[txtSize] + 20;
tft.drawRect(x, y, rectWidth, rectHeight, TEXTCLR);
tft.fillRect(x + 1, y + 1, rectWidth - 2, rectHeight - 2, bgClr);
int txtStartX = x + (charWidth[txtSize] / 2) + 1; // Center the text;
int txtStartY = y + 10; // text in the middle
tft.setCursor(txtStartX, txtStartY);
tft.setTextColor(txtClr);
tft.setTextSize(txtSize);
tft.print(txt);
virtual void CreateButton::Action(void)
{
}
}