| 6674 | } |
| 6675 | |
| 6676 | void CEditor::UpdateColorPipette() |
| 6677 | { |
| 6678 | if(!m_ColorPipetteActive) |
| 6679 | return; |
| 6680 | |
| 6681 | static char s_PipetteScreenButton; |
| 6682 | if(Ui()->HotItem() == &s_PipetteScreenButton) |
| 6683 | { |
| 6684 | // Read color one pixel to the top and left as we would otherwise not read the correct |
| 6685 | // color due to the cursor sprite being rendered over the current mouse position. |
| 6686 | const int PixelX = std::clamp<int>(round_to_int((Ui()->MouseX() - 1.0f) / Ui()->Screen()->w * Graphics()->ScreenWidth()), 0, Graphics()->ScreenWidth() - 1); |
| 6687 | const int PixelY = std::clamp<int>(round_to_int((Ui()->MouseY() - 1.0f) / Ui()->Screen()->h * Graphics()->ScreenHeight()), 0, Graphics()->ScreenHeight() - 1); |
| 6688 | Graphics()->ReadPixel(ivec2(PixelX, PixelY), &m_PipetteColor); |
| 6689 | } |
| 6690 | |
| 6691 | // Simulate button overlaying the entire screen to intercept all clicks for color pipette. |
| 6692 | const int ButtonResult = DoButtonLogic(&s_PipetteScreenButton, 0, Ui()->Screen(), BUTTONFLAG_ALL, "Left click to pick a color from the screen. Right click to cancel pipette mode."); |
| 6693 | // Don't handle clicks if we are panning, so the pipette stays active while panning. |
| 6694 | // Checking m_pContainerPanned alone is not enough, as this variable is reset when |
| 6695 | // panning ends before this function is called. |
| 6696 | if(m_pContainerPanned == nullptr && m_pContainerPannedLast == nullptr) |
| 6697 | { |
| 6698 | if(ButtonResult == 1) |
| 6699 | { |
| 6700 | char aClipboard[9]; |
| 6701 | str_format(aClipboard, sizeof(aClipboard), "%08X", m_PipetteColor.PackAlphaLast()); |
| 6702 | Input()->SetClipboardText(aClipboard); |
| 6703 | |
| 6704 | // Check if any of the saved colors is equal to the picked color and |
| 6705 | // bring it to the front of the list instead of adding a duplicate. |
| 6706 | int ShiftEnd = (int)std::size(m_aSavedColors) - 1; |
| 6707 | for(int i = 0; i < (int)std::size(m_aSavedColors); ++i) |
| 6708 | { |
| 6709 | if(m_aSavedColors[i].Pack() == m_PipetteColor.Pack()) |
| 6710 | { |
| 6711 | ShiftEnd = i; |
| 6712 | break; |
| 6713 | } |
| 6714 | } |
| 6715 | for(int i = ShiftEnd; i > 0; --i) |
| 6716 | { |
| 6717 | m_aSavedColors[i] = m_aSavedColors[i - 1]; |
| 6718 | } |
| 6719 | m_aSavedColors[0] = m_PipetteColor; |
| 6720 | } |
| 6721 | if(ButtonResult > 0) |
| 6722 | { |
| 6723 | m_ColorPipetteActive = false; |
| 6724 | } |
| 6725 | } |
| 6726 | } |
| 6727 | |
| 6728 | void CEditor::RenderMousePointer() |
| 6729 | { |
nothing calls this directly
no test coverage detected