MCPcopy Create free account
hub / github.com/ddnet/ddnet / DoColorPickerButton

Method DoColorPickerButton

src/game/editor/editor.cpp:2981–3040  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2979}
2980
2981void CEditor::DoColorPickerButton(const void *pId, const CUIRect *pRect, ColorRGBA Color, const std::function<void(ColorRGBA Color)> &SetColor)
2982{
2983 CUIRect ColorRect;
2984 pRect->Draw(ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f * Ui()->ButtonColorMul(pId)), IGraphics::CORNER_ALL, 3.0f);
2985 pRect->Margin(1.0f, &ColorRect);
2986 ColorRect.Draw(Color, IGraphics::CORNER_ALL, 3.0f);
2987
2988 const int ButtonResult = DoButtonLogic(pId, 0, pRect, BUTTONFLAG_ALL, "Click to show the color picker. Shift+right click to copy color to clipboard. Shift+left click to paste color from clipboard.");
2989 if(Input()->ShiftIsPressed())
2990 {
2991 if(ButtonResult == 1)
2992 {
2993 std::string Clipboard = Input()->GetClipboardText();
2994 if(Clipboard[0] == '#' || Clipboard[0] == '$') // ignore leading # (web color format) and $ (console color format)
2995 Clipboard = Clipboard.substr(1);
2996 if(str_isallnum_hex(Clipboard.c_str()))
2997 {
2998 std::optional<ColorRGBA> ParsedColor = color_parse<ColorRGBA>(Clipboard.c_str());
2999 if(ParsedColor)
3000 {
3001 m_ColorPickerPopupContext.m_State = EEditState::ONE_GO;
3002 SetColor(ParsedColor.value());
3003 }
3004 }
3005 }
3006 else if(ButtonResult == 2)
3007 {
3008 char aClipboard[9];
3009 str_format(aClipboard, sizeof(aClipboard), "%08X", Color.PackAlphaLast());
3010 Input()->SetClipboardText(aClipboard);
3011 }
3012 }
3013 else if(ButtonResult > 0)
3014 {
3015 if(m_ColorPickerPopupContext.m_ColorMode == CUi::SColorPickerPopupContext::MODE_UNSET)
3016 m_ColorPickerPopupContext.m_ColorMode = CUi::SColorPickerPopupContext::MODE_RGBA;
3017 m_ColorPickerPopupContext.m_RgbaColor = Color;
3018 m_ColorPickerPopupContext.m_HslaColor = color_cast<ColorHSLA>(Color);
3019 m_ColorPickerPopupContext.m_HsvaColor = color_cast<ColorHSVA>(m_ColorPickerPopupContext.m_HslaColor);
3020 m_ColorPickerPopupContext.m_Alpha = true;
3021 m_pColorPickerPopupActiveId = pId;
3022 Ui()->ShowPopupColorPicker(Ui()->MouseX(), Ui()->MouseY(), &m_ColorPickerPopupContext);
3023 }
3024
3025 if(Ui()->IsPopupOpen(&m_ColorPickerPopupContext))
3026 {
3027 if(m_pColorPickerPopupActiveId == pId)
3028 SetColor(m_ColorPickerPopupContext.m_RgbaColor);
3029 }
3030 else
3031 {
3032 m_pColorPickerPopupActiveId = nullptr;
3033 if(m_ColorPickerPopupContext.m_State == EEditState::EDITING)
3034 {
3035 m_ColorPickerPopupContext.m_State = EEditState::END;
3036 SetColor(m_ColorPickerPopupContext.m_RgbaColor);
3037 m_ColorPickerPopupContext.m_State = EEditState::NONE;
3038 }

Callers 1

PopupEnvPointMethod · 0.80

Calls 15

UiFunction · 0.85
InputFunction · 0.85
str_isallnum_hexFunction · 0.85
str_formatFunction · 0.85
ButtonColorMulMethod · 0.80
MarginMethod · 0.80
ShiftIsPressedMethod · 0.80
GetClipboardTextMethod · 0.80
PackAlphaLastMethod · 0.80
SetClipboardTextMethod · 0.80
ShowPopupColorPickerMethod · 0.80
MouseXMethod · 0.80

Tested by

no test coverage detected