| 48 | } |
| 49 | |
| 50 | void ButtonWidget::renderImpl() { |
| 51 | if (isPressed() && sustainCallbackOnDownHold()) { |
| 52 | if (m_callback) { |
| 53 | auto unlocker = Input::singleton().unlockClipboard(); |
| 54 | m_callback(this); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | Vec2F position = Vec2F(screenPosition()); |
| 59 | Vec2F textPosition = position + Vec2F(m_textOffset); |
| 60 | if (m_hTextAnchor == HorizontalAnchor::HMidAnchor) |
| 61 | textPosition += Vec2F(size()) / 2; |
| 62 | else if (m_hTextAnchor == HorizontalAnchor::RightAnchor) |
| 63 | textPosition += Vec2F(size()[0], size()[1] / 2); |
| 64 | else if (m_hTextAnchor == HorizontalAnchor::LeftAnchor) |
| 65 | textPosition += Vec2F(0, size()[1] / 2); |
| 66 | // We need to show the down button offset if we're pressing the button or |
| 67 | // don't have checked images and thus need some way to show that the button |
| 68 | // is checked (there's probably some better default behavior in that case) |
| 69 | if (m_pressed || (m_checked && !m_hasCheckedImages)) { |
| 70 | position += Vec2F(m_pressedOffset); |
| 71 | textPosition += Vec2F(m_pressedOffset); |
| 72 | } |
| 73 | |
| 74 | if (m_hasCheckedImages && m_checked) { |
| 75 | if (m_disabled) |
| 76 | drawButtonPart(m_disabledImageChecked, position); |
| 77 | else if ((m_pressed || m_highlighted) && !m_pressedImageChecked.empty()) |
| 78 | drawButtonPart(m_pressedImageChecked, position); |
| 79 | else if ((m_pressed || m_hovered || m_highlighted) && !m_hoverImageChecked.empty()) |
| 80 | drawButtonPart(m_hoverImageChecked, position); |
| 81 | else |
| 82 | drawButtonPart(m_baseImageChecked, position); |
| 83 | } else { |
| 84 | if (m_disabled) |
| 85 | drawButtonPart(m_disabledImage, position); |
| 86 | else if ((m_pressed || m_highlighted) && !m_pressedImage.empty()) |
| 87 | drawButtonPart(m_pressedImage, position); |
| 88 | else if ((m_pressed || m_hovered || m_highlighted) && !m_hoverImage.empty()) |
| 89 | drawButtonPart(m_hoverImage, position); |
| 90 | else if (!m_invisible) |
| 91 | drawButtonPart(m_baseImage, position); |
| 92 | } |
| 93 | |
| 94 | if (!m_overlayImage.empty()) |
| 95 | drawButtonPart(m_overlayImage, position); |
| 96 | |
| 97 | if (!m_text.empty()) { |
| 98 | auto& guiContext = GuiContext::singleton(); |
| 99 | guiContext.setTextStyle(m_textStyle); |
| 100 | if (m_disabled) |
| 101 | guiContext.setFontColor(m_fontColorDisabled.toRgba()); |
| 102 | else if (m_fontColorChecked && m_checked) |
| 103 | guiContext.setFontColor(m_fontColorChecked.value().toRgba()); |
| 104 | else |
| 105 | guiContext.setFontColor(m_fontColor.toRgba()); |
| 106 | guiContext.renderInterfaceText(m_text, {textPosition, m_hTextAnchor, VerticalAnchor::VMidAnchor}); |
| 107 | guiContext.clearTextStyle(); |
nothing calls this directly
no test coverage detected