Skip to content

Commit

Permalink
Optimizing Lever display for digital. (#1215)
Browse files Browse the repository at this point in the history
fixing bug for SOCD-N
  • Loading branch information
j-wut authored Nov 25, 2024
1 parent 08bdf59 commit 5e58441
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions src/display/ui/elements/GPLever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,13 @@ void GPLever::draw() {
bool leftState = (this->_leftMask > -1 ? getProcessedGamepad()->pressedButton((uint16_t)this->_leftMask) : getProcessedGamepad()->pressedLeft());
bool downState = (this->_downMask > -1 ? getProcessedGamepad()->pressedButton((uint16_t)this->_downMask) : getProcessedGamepad()->pressedDown());
bool rightState = (this->_rightMask > -1 ? getProcessedGamepad()->pressedButton((uint16_t)this->_rightMask) : getProcessedGamepad()->pressedRight());
if (upState) {
leverY -= leverRadius;
if (leftState) {
leverX -= leverRadius;
} else if (rightState) {
leverX += leverRadius;
}
} else if (downState) {
leverY += leverRadius;
if (leftState) {
leverX -= leverRadius;
} else if (rightState) {
leverX += leverRadius;
}
} else if (leftState) {
leverX -= leverRadius;
} else if (rightState) {
leverX += leverRadius;
if (upState != downState) {
leverY -= upState ? leverRadius : -leverRadius;
}
} else {
if (leftState != rightState) {
leverX -= leftState ? leverRadius : -leverRadius;
}
} else {
// analog
uint16_t analogX = map((this->_inputType == DPAD_MODE_LEFT_ANALOG ? getProcessedGamepad()->state.lx : getProcessedGamepad()->state.rx), 0, 0xFFFF, 0, 100);
uint16_t analogY = map((this->_inputType == DPAD_MODE_LEFT_ANALOG ? getProcessedGamepad()->state.ly : getProcessedGamepad()->state.ry), 0, 0xFFFF, 0, 100);
Expand All @@ -81,7 +68,7 @@ void GPLever::draw() {

// base
getRenderer()->drawEllipse(baseX, baseY, baseRadius, baseRadius, this->strokeColor, 0);

if (this->_showCardinal) {
uint16_t cardinalSize = 3;
uint16_t cardinalN = std::max(0,(baseY - baseRadius)-cardinalSize);
Expand All @@ -99,15 +86,15 @@ void GPLever::draw() {
for (int angle = 45; angle <= 315; angle += 90) {
// Convert angle to radians
double radians = angle * M_PI / 180.0;

// Calculate coordinates of point on ellipse
int xEllipse = baseX + baseRadius * cos(radians);
int yEllipse = baseY + baseRadius * sin(radians);

// Calculate coordinates of endpoint of line
int xEndpoint = xEllipse + ordinalSize * cos(radians);
int yEndpoint = yEllipse + ordinalSize * sin(radians);

// Draw line from point on ellipse to endpoint
getRenderer()->drawLine(xEllipse, yEllipse, xEndpoint, yEndpoint, this->strokeColor, 1);
}
Expand All @@ -122,4 +109,4 @@ void GPLever::setDirectionMasks(int32_t upMask, int32_t downMask, int32_t leftMa
this->_downMask = downMask;
this->_leftMask = leftMask;
this->_rightMask = rightMask;
}
}

0 comments on commit 5e58441

Please sign in to comment.