/**
 *
 * @param aPositionX
 * @param aPositionY
 * @param aWidthX       if aWidthX == 0 render only text no background box
 * @param aHeightY
 * @param aButtonColor  if 0 take sDefaultButtonColor
 * @param aCaption
 * @param aCaptionSize  if aCaptionSize == 0 don't render anything, just check touch area -> transparent button ;-)
 * @param aValue
 * @param aOnTouchHandler
 * @return pointer to allocated button
 */
TouchButton * TouchButton::allocAndInitButton(uint16_t aPositionX, uint16_t aPositionY, uint16_t aWidthX, uint16_t aHeightY,
        uint16_t aButtonColor, const char * aCaption, uint8_t aCaptionSize, uint8_t aFlags, int16_t aValue,
        void (*aOnTouchHandler)(TouchButton *, int16_t)) {

    TouchButton * tButton;
    if (aFlags & BUTTON_FLAG_TYPE_AUTOREPEAT) {
        tButton = TouchButtonAutorepeat::allocAutorepeatButton();
    } else {
        tButton = allocButton(false);
    }

    tButton->mWidthX = aWidthX;
    tButton->mHeightY = aHeightY;
    tButton->mButtonColor = aButtonColor;
    tButton->mCaptionColor = sDefaultCaptionColor;
    tButton->mCaption = aCaption;
    tButton->mCaptionSize = aCaptionSize;
    tButton->mOnTouchHandler = aOnTouchHandler;

    if (aFlags & BUTTON_FLAG_TYPE_AUTO_RED_GREEN) {
        if (aValue != 0) {
            // map to boolean
            aValue = true;
            tButton->mButtonColor = COLOR_GREEN;
        } else {
            tButton->mButtonColor = COLOR_RED;
        }
    }
    tButton->mValue = aValue;

// keep internal flags set by allocButton()
    tButton->mFlags = (aFlags & (~INTERNAL_FLAG_MASK)) | (tButton->mFlags & INTERNAL_FLAG_MASK);
    tButton->setPosition(aPositionX, aPositionY);
    return tButton;
}
/**
 *
 * @param aPositionX
 * @param aPositionY
 * @param aWidthX 		if aWidthX == 0 render only text no background box
 * @param aHeightY
 * @param aButtonColor	if 0 take sDefaultButtonColor
 * @param aCaption
 * @param aCaptionSize	if aCaptionSize == 0 don't render anything, just check touch area -> transparent button ;-)
 * @param aValue
 * @param aOnTouchHandler
 * @return pointer to allocated button
 */
TouchButton * TouchButton::allocAndInitSimpleButton(const uint16_t aPositionX, const uint16_t aPositionY, const uint16_t aWidthX,
        const uint16_t aHeightY, const uint16_t aButtonColor, const char * aCaption, const uint8_t aCaptionSize,
        const uint8_t aFlags, const int16_t aValue, void (*aOnTouchHandler)(TouchButton * const, int16_t)) {
    TouchButton * tButton = allocButton(false);

    tButton->mWidth = aWidthX;
    tButton->mHeight = aHeightY;
    tButton->mButtonColor = aButtonColor;
    if (aButtonColor == 0) {
        tButton->mButtonColor = sDefaultButtonColor;
    }
    tButton->mCaptionColor = sDefaultCaptionColor;
    tButton->mCaption = aCaption;
    tButton->mCaptionSize = aCaptionSize;
    tButton->mOnTouchHandler = aOnTouchHandler;
    tButton->mValue = aValue;
    tButton->setPosition(aPositionX, aPositionY);
    return tButton;
}