/** * * @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; }
/** * Static convenience method - activate all buttons */ void TouchButton::activateAllButtons() { TouchButton * tObjectPointer = sButtonListStart; // walk through list while (tObjectPointer != NULL) { tObjectPointer->activate(); tObjectPointer = tObjectPointer->mNextObject; } }
void DisplayClass::getTouch() { u8 i = 0; TouchButton *pTryButton; pTryButton = pDispButtons; TouchedButtonIndex = END_BUT; // Use large value for non-index indication HeldButtonIndex = END_BUT; // Use large value for non-index indication Point p = pTS->getPoint(); if (p.z > __PRESURE) { p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240); p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320); } else { p.x = 0; p.y = 0; #ifdef SKIP Serial.print("p.x = "); Serial.print(p.x); Serial.print(" p.y = "); Serial.print(p.y); Serial.println(); #endif } while (i < NumDispButtons) // check all the buttons { pTryButton->ProcessXY(p); if (pTryButton->ButtonPressed()) { TouchedButtonIndex = (SYS_BUTTONS)i; #ifdef SKIP Serial.print("TouchedButtonIndex = "); Serial.print(i); Serial.println(); #endif return; // take first button pressed found } if (pTryButton->ButtonHeld()) { HeldButtonIndex = (SYS_BUTTONS)i; #ifdef DEBUG Serial.print(">>** HeldButtonIndex = "); Serial.print(i); Serial.println(); #endif return; // take first button pressed found } if (pTryButton->ButtonReleased()) { ReleaseButtonIndex = (SYS_BUTTONS)i; #ifdef SKIP Serial.print("ReleaseButtonIndex = "); Serial.print(i); Serial.println(); #endif return; // take first button pressed found } pTryButton++; i++; } // } }
/** * Static convenience method - checks all buttons for matching touch position. */ uint8_t TouchButton::checkAllButtons(unsigned int aTouchPositionX, unsigned int aTouchPositionY) { // walk through list of active elements TouchButton * tButtonPointer = sButtonListStart; while (tButtonPointer != NULL) { if ((tButtonPointer->mFlags & FLAG_IS_ACTIVE) && tButtonPointer->checkButton(aTouchPositionX, aTouchPositionY)) { if (tButtonPointer->mFlags & BUTTON_FLAG_TYPE_AUTOREPEAT) { return BUTTON_TOUCHED_AUTOREPEAT; } else { return BUTTON_TOUCHED; } } tButtonPointer = tButtonPointer->mNextObject; } return NOT_TOUCHED; }
/** * * @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; }
void LayoutGamepad(int w, int h) { float controlScale = g_Config.bLargeControls ? 1.6 : 1.15; const int button_spacing = 50 * controlScale; const int arrow_spacing = 40 * controlScale; const int circleX = w - 40 * controlScale; const int circleY = h - 120 * controlScale; const int leftX = 40 * controlScale; int leftY = h - 120 * controlScale; if (g_Config.bShowAnalogStick) { leftY = h - 250 * controlScale; } const int stickX = leftX + arrow_spacing; const int stickY = h - 80 * controlScale; const int halfW = w / 2; buttonO.setPos(circleX, circleY, controlScale); buttonX.setPos(circleX - button_spacing, circleY + button_spacing, controlScale); buttonTri.setPos(circleX - button_spacing, circleY - button_spacing, controlScale); buttonSq.setPos(circleX - button_spacing * 2, circleY, controlScale); crossPad.setPos(leftX + arrow_spacing, leftY, 40, controlScale); buttonSelect.setPos(halfW - button_spacing * 2, h - 20 * controlScale, controlScale); buttonStart.setPos(halfW , h - 20 * controlScale, controlScale); buttonTurbo.setPos(halfW + button_spacing * 2 , h - 20 * controlScale, controlScale); buttonLShoulder.setPos(button_spacing + 10 * controlScale, 30 * controlScale, controlScale); buttonRShoulder.setPos(w - button_spacing - 10 * controlScale, 30 * controlScale, controlScale); #if defined(__SYMBIAN32__) || defined(IOS) buttonPause.setPos(halfW, 15 * controlScale, controlScale); #endif leftStick.setPos(stickX, stickY, controlScale); }
/** * Static convenience method - checks all buttons for matching touch position. */ int TouchButton::checkAllButtons(const int aTouchPositionX, const int aTouchPositionY, const bool doCallback) { TouchButton * tObjectPointer = sListStart; // walk through list of active elements while (tObjectPointer != NULL) { if ((tObjectPointer->mFlags & FLAG_IS_ACTIVE) && tObjectPointer->checkButton(aTouchPositionX, aTouchPositionY, doCallback)) { if (tObjectPointer->mFlags & FLAG_IS_AUTOREPEAT_BUTTON) { sAutorepeatButtonTouched = true; return BUTTON_TOUCHED_AUTOREPEAT; } sButtonTouched = true; return BUTTON_TOUCHED; } tObjectPointer = tObjectPointer->mNextObject; } sAutorepeatButtonTouched = false; sButtonTouched = false; return NOT_TOUCHED; }
void UpdateGamepad(InputState &input_state) { LayoutGamepad(dp_xres, dp_yres); buttonO.update(input_state); buttonX.update(input_state); buttonTri.update(input_state); buttonSq.update(input_state); crossPad.update(input_state); buttonSelect.update(input_state); buttonStart.update(input_state); buttonLShoulder.update(input_state); buttonRShoulder.update(input_state); buttonTurbo.update(input_state); #if defined(__SYMBIAN32__) || defined(IOS) buttonPause.update(input_state); #endif if (g_Config.bShowAnalogStick) leftStick.update(input_state); }
void DrawGamepad(DrawBuffer &db) { uint32_t color = 0xa0c0b080; uint32_t colorOverlay = 0xa0FFFFFF; buttonO.draw(db, color, colorOverlay); buttonX.draw(db, color, colorOverlay); buttonTri.draw(db, color, colorOverlay); buttonSq.draw(db, color, colorOverlay); crossPad.draw(db, color, colorOverlay); buttonSelect.draw(db, color, colorOverlay); buttonStart.draw(db, color, colorOverlay); buttonLShoulder.draw(db, color, colorOverlay); buttonRShoulder.draw(db, color, colorOverlay); buttonTurbo.draw(db, color, colorOverlay); #if defined(__SYMBIAN32__) || defined(IOS) buttonPause.draw(db, color, colorOverlay); #endif if (g_Config.bShowAnalogStick) leftStick.draw(db, color); }
void DrawGamepad(DrawBuffer &db, float opacity) { uint32_t color = colorAlpha(0xc0b080, opacity); uint32_t colorOverlay = colorAlpha(0xFFFFFF, opacity); buttonO.draw(db, color, colorOverlay); buttonX.draw(db, color, colorOverlay); buttonTri.draw(db, color, colorOverlay); buttonSq.draw(db, color, colorOverlay); crossPad.draw(db, color, colorOverlay); buttonSelect.draw(db, color, colorOverlay); buttonStart.draw(db, color, colorOverlay); buttonLShoulder.draw(db, color, colorOverlay); buttonRShoulder.draw(db, color, colorOverlay); if (g_Config.iFpsLimit) buttonVPS.draw(db, color, colorOverlay); else buttonTurbo.draw(db, color, colorOverlay); #if defined(__SYMBIAN32__) || defined(IOS) || defined(MEEGO_EDITION_HARMATTAN) buttonPause.draw(db, color, colorOverlay); #endif if (g_Config.bShowAnalogStick) leftStick.draw(db, color); }
void DrawGamepad(DrawBuffer &db) { uint32_t color = 0xa0c0b080; uint32_t colorOverlay = 0xa0FFFFFF; buttonO.draw(db, color, colorOverlay); buttonX.draw(db, color, colorOverlay); buttonTri.draw(db, color, colorOverlay); buttonSq.draw(db, color, colorOverlay); buttonLeft.draw(db, color, colorOverlay); buttonUp.draw(db, color, colorOverlay); buttonDown.draw(db, color, colorOverlay); buttonRight.draw(db, color, colorOverlay); buttonSelect.draw(db, color, colorOverlay); buttonStart.draw(db, color, colorOverlay); buttonLShoulder.draw(db, color, colorOverlay); buttonRShoulder.draw(db, color, colorOverlay); if (g_Config.bShowAnalogStick) leftStick.draw(db, color); }
void UpdateGamepad(InputState &input_state) { buttonO.update(input_state); buttonX.update(input_state); buttonTri.update(input_state); buttonSq.update(input_state); buttonLeft.update(input_state); buttonUp.update(input_state); buttonDown.update(input_state); buttonRight.update(input_state); buttonSelect.update(input_state); buttonStart.update(input_state); buttonLShoulder.update(input_state); buttonRShoulder.update(input_state); if (g_Config.bShowAnalogStick) leftStick.update(input_state); }
void LayoutGamepad(int w, int h) { const int button_spacing = 50; const int arrow_spacing = 40; const int circleX = w - 40; const int circleY = h - 120; const int leftX = 40; int leftY = h - 120; if (g_Config.bShowAnalogStick) { leftY = h - 220; } const int stickX = leftX + arrow_spacing; const int stickY = h - 80; const int halfW = w / 2; buttonO.setPos(circleX, circleY); buttonX.setPos(circleX - button_spacing, circleY + button_spacing); buttonTri.setPos(circleX - button_spacing, circleY - button_spacing); buttonSq.setPos(circleX - button_spacing * 2, circleY); buttonLeft.setPos(leftX, leftY); buttonUp.setPos(leftX + arrow_spacing, leftY - arrow_spacing); buttonDown.setPos(leftX + arrow_spacing, leftY + arrow_spacing); buttonRight.setPos(leftX + arrow_spacing * 2, leftY); buttonSelect.setPos(halfW - button_spacing, h - 20); buttonStart.setPos(halfW + button_spacing, h - 20); buttonLShoulder.setPos(button_spacing + 10, 15); buttonRShoulder.setPos(w - button_spacing - 10, 15); leftStick.setPos(stickX, stickY); }