Improve editor color picker popup

By replacing the editor specific color picker popup with the generic UI color picker popup.

Improve layout of the editor color picker button. Improve spacing and ensure that the button is square. Slightly enlarge button on mouse hover.
This commit is contained in:
Robert Müller 2023-06-14 19:54:21 +02:00
parent 7ce9fd9949
commit 34c2e5649b
3 changed files with 15 additions and 133 deletions

View file

@ -75,10 +75,6 @@ bool CEditor::IsVanillaImage(const char *pImage)
const void *CEditor::ms_pUiGotContext;
ColorHSVA CEditor::ms_PickerColor;
int CEditor::ms_SVPicker;
int CEditor::ms_HuePicker;
enum
{
BUTTON_CONTEXT = 1,
@ -488,12 +484,6 @@ int CEditor::DoButton_ButtonDec(const void *pID, const char *pText, int Checked,
return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip);
}
int CEditor::DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip)
{
pRect->Draw(*pColor, 0, 0.0f);
return DoButton_Editor_Common(pID, nullptr, 0, pRect, 0, pToolTip);
}
int CEditor::DoButton_DraggableEx(const void *pID, const char *pText, int Checked, const CUIRect *pRect, bool *pClicked, bool *pAbrupted, int Flags, const char *pToolTip, int Corners, float FontSize)
{
pRect->Draw(GetButtonColor(pID, Checked), Corners, 3.0f);
@ -3148,8 +3138,9 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
pToolBox->HSplitTop(3.0f * 13.0f, &Slot, pToolBox);
Slot.VSplitMid(&ColorBox, &ColorSlots);
ColorBox.HMargin(1.0f, &ColorBox);
ColorBox.VMargin(6.0f, &ColorBox);
ColorBox.HSplitTop(8.0f, nullptr, &ColorBox);
ColorBox.VMargin(12.0f, &ColorBox);
ColorBox.HMargin((ColorBox.h - ColorBox.w) / 2.0f, &ColorBox);
for(int c = 0; c < 4; c++)
{
@ -3179,20 +3170,23 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIDs, int *
1.0f);
static int s_ColorPicker;
if(DoButton_ColorPicker(&s_ColorPicker, &ColorBox, &ColorPick))
{
ms_PickerColor = color_cast<ColorHSVA>(ColorPick);
static SPopupMenuId s_PopupColorPickerId;
UI()->DoPopupMenu(&s_PopupColorPickerId, UI()->MouseX(), UI()->MouseY(), 180, 150, this, PopupColorPicker);
}
if(UI()->HotItem() == &s_ColorPicker)
ColorBox.Margin(-2.0f, &ColorBox);
ColorBox.Draw(ColorPick, IGraphics::CORNER_ALL, 3.0f);
if(UI()->HotItem() == &ms_SVPicker || UI()->HotItem() == &ms_HuePicker)
static CUI::SColorPickerPopupContext s_ColorPickerPopupContext;
if(DoButton_Editor_Common(&s_ColorPicker, nullptr, 0, &ColorBox, 0, "Click to show the color picker."))
{
ColorRGBA c = color_cast<ColorRGBA>(ms_PickerColor);
s_ColorPickerPopupContext.m_HsvaColor = color_cast<ColorHSVA>(ColorPick);
s_ColorPickerPopupContext.m_Alpha = true;
UI()->ShowPopupColorPicker(UI()->MouseX(), UI()->MouseY(), &s_ColorPickerPopupContext);
}
else if(UI()->IsPopupOpen(&s_ColorPickerPopupContext))
{
ColorRGBA c = color_cast<ColorRGBA>(s_ColorPickerPopupContext.m_HsvaColor);
NewColor = ((int)(c.r * 255.0f) & 0xff) << 24 | ((int)(c.g * 255.0f) & 0xff) << 16 | ((int)(c.b * 255.0f) & 0xff) << 8 | (pProps[i].m_Value & 0xff);
}
//
if(NewColor != pProps[i].m_Value)
{
*pNewVal = NewColor;
@ -6755,8 +6749,6 @@ void CEditor::Init()
Reset(false);
m_Map.m_Modified = false;
ms_PickerColor = ColorHSVA(1.0f, 0.0f, 0.0f);
ResetMenuBackgroundPositions();
m_vpMenuBackgroundPositionNames.resize(CMenuBackground::NUM_POS);
m_vpMenuBackgroundPositionNames[CMenuBackground::POS_START] = "start";

View file

@ -1138,8 +1138,6 @@ public:
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);
int DoButton_MenuItem(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags = 0, const char *pToolTip = nullptr);
int DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip = nullptr);
int DoButton_DraggableEx(const void *pID, const char *pText, int Checked, const CUIRect *pRect, bool *pClicked, bool *pAbrupted, int Flags, const char *pToolTip = nullptr, int Corners = IGraphics::CORNER_ALL, float FontSize = 10.0f);
bool DoEditBox(CLineInput *pLineInput, const CUIRect *pRect, float FontSize, int Corners = IGraphics::CORNER_ALL, const char *pToolTip = nullptr);
@ -1180,7 +1178,6 @@ public:
static CUI::EPopupMenuFunctionResult PopupSwitch(void *pContext, CUIRect View, bool Active);
static CUI::EPopupMenuFunctionResult PopupTune(void *pContext, CUIRect View, bool Active);
static CUI::EPopupMenuFunctionResult PopupGoto(void *pContext, CUIRect View, bool Active);
static CUI::EPopupMenuFunctionResult PopupColorPicker(void *pContext, CUIRect View, bool Active);
static CUI::EPopupMenuFunctionResult PopupEntities(void *pContext, CUIRect View, bool Active);
static CUI::EPopupMenuFunctionResult PopupProofMode(void *pContext, CUIRect View, bool Active);
@ -1333,10 +1330,6 @@ public:
float MinZoomLevel() const;
float MaxZoomLevel() const;
static ColorHSVA ms_PickerColor;
static int ms_SVPicker;
static int ms_HuePicker;
// DDRace
IGraphics::CTextureHandle GetFrontTexture();

View file

@ -2193,109 +2193,6 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGoto(void *pContext, CUIRect View, b
return CUI::POPUP_KEEP_OPEN;
}
CUI::EPopupMenuFunctionResult CEditor::PopupColorPicker(void *pContext, CUIRect View, bool Active)
{
CEditor *pEditor = static_cast<CEditor *>(pContext);
CUIRect SVPicker, HuePicker;
View.VSplitRight(20.0f, &SVPicker, &HuePicker);
HuePicker.VSplitLeft(4.0f, nullptr, &HuePicker);
pEditor->Graphics()->TextureClear();
pEditor->Graphics()->QuadsBegin();
// base: white - hue
ColorHSVA Hsv = CEditor::ms_PickerColor;
IGraphics::CColorVertex aColors[4];
ColorRGBA Color = color_cast<ColorRGBA>(ColorHSVA(Hsv.x, 0.0f, 1.0f));
aColors[0] = IGraphics::CColorVertex(0, Color.r, Color.g, Color.b, 1.0f);
Color = color_cast<ColorRGBA>(ColorHSVA(Hsv.x, 1.0f, 1.0f));
aColors[1] = IGraphics::CColorVertex(1, Color.r, Color.g, Color.b, 1.0f);
Color = color_cast<ColorRGBA>(ColorHSVA(Hsv.x, 1.0f, 1.0f));
aColors[2] = IGraphics::CColorVertex(2, Color.r, Color.g, Color.b, 1.0f);
Color = color_cast<ColorRGBA>(ColorHSVA(Hsv.x, 0.0f, 1.0f));
aColors[3] = IGraphics::CColorVertex(3, Color.r, Color.g, Color.b, 1.0f);
pEditor->Graphics()->SetColorVertex(aColors, 4);
IGraphics::CQuadItem QuadItem(SVPicker.x, SVPicker.y, SVPicker.w, SVPicker.h);
pEditor->Graphics()->QuadsDrawTL(&QuadItem, 1);
// base: transparent - black
aColors[0] = IGraphics::CColorVertex(0, 0.0f, 0.0f, 0.0f, 0.0f);
aColors[1] = IGraphics::CColorVertex(1, 0.0f, 0.0f, 0.0f, 0.0f);
aColors[2] = IGraphics::CColorVertex(2, 0.0f, 0.0f, 0.0f, 1.0f);
aColors[3] = IGraphics::CColorVertex(3, 0.0f, 0.0f, 0.0f, 1.0f);
pEditor->Graphics()->SetColorVertex(aColors, 4);
pEditor->Graphics()->QuadsDrawTL(&QuadItem, 1);
pEditor->Graphics()->QuadsEnd();
// marker
const vec2 Marker = vec2(Hsv.y, (1.0f - Hsv.z)) * vec2(SVPicker.w, SVPicker.h);
pEditor->Graphics()->QuadsBegin();
pEditor->Graphics()->SetColor(0.5f, 0.5f, 0.5f, 1.0f);
IGraphics::CQuadItem aMarker[2];
aMarker[0] = IGraphics::CQuadItem(SVPicker.x + Marker.x, SVPicker.y + Marker.y - 5.0f * pEditor->UI()->PixelSize(), pEditor->UI()->PixelSize(), 11.0f * pEditor->UI()->PixelSize());
aMarker[1] = IGraphics::CQuadItem(SVPicker.x + Marker.x - 5.0f * pEditor->UI()->PixelSize(), SVPicker.y + Marker.y, 11.0f * pEditor->UI()->PixelSize(), pEditor->UI()->PixelSize());
pEditor->Graphics()->QuadsDrawTL(aMarker, 2);
pEditor->Graphics()->QuadsEnd();
// logic
float X, Y;
if(pEditor->UI()->DoPickerLogic(&CEditor::ms_SVPicker, &SVPicker, &X, &Y))
{
Hsv.y = X / SVPicker.w;
Hsv.z = 1.0f - Y / SVPicker.h;
}
// hue slider
static const float s_aaColorIndices[7][3] = {
{1.0f, 0.0f, 0.0f}, // red
{1.0f, 0.0f, 1.0f}, // magenta
{0.0f, 0.0f, 1.0f}, // blue
{0.0f, 1.0f, 1.0f}, // cyan
{0.0f, 1.0f, 0.0f}, // green
{1.0f, 1.0f, 0.0f}, // yellow
{1.0f, 0.0f, 0.0f}, // red
};
pEditor->Graphics()->QuadsBegin();
const float Offset = HuePicker.h / 6.0f;
for(size_t j = 0; j < std::size(s_aaColorIndices) - 1; ++j)
{
const ColorRGBA ColorTop = ColorRGBA(s_aaColorIndices[j][0], s_aaColorIndices[j][1], s_aaColorIndices[j][2], 1.0f);
const ColorRGBA ColorBottom = ColorRGBA(s_aaColorIndices[j + 1][0], s_aaColorIndices[j + 1][1], s_aaColorIndices[j + 1][2], 1.0f);
aColors[0] = IGraphics::CColorVertex(0, ColorTop.r, ColorTop.g, ColorTop.b, ColorTop.a);
aColors[1] = IGraphics::CColorVertex(1, ColorTop.r, ColorTop.g, ColorTop.b, ColorTop.a);
aColors[2] = IGraphics::CColorVertex(2, ColorBottom.r, ColorBottom.g, ColorBottom.b, ColorBottom.a);
aColors[3] = IGraphics::CColorVertex(3, ColorBottom.r, ColorBottom.g, ColorBottom.b, ColorBottom.a);
pEditor->Graphics()->SetColorVertex(aColors, 4);
QuadItem = IGraphics::CQuadItem(HuePicker.x, HuePicker.y + Offset * j, HuePicker.w, Offset);
pEditor->Graphics()->QuadsDrawTL(&QuadItem, 1);
}
// marker
pEditor->Graphics()->SetColor(0.5f, 0.5f, 0.5f, 1.0f);
IGraphics::CQuadItem QuadItemMarker(HuePicker.x, HuePicker.y + (1.0f - Hsv.x) * HuePicker.h, HuePicker.w, pEditor->UI()->PixelSize());
pEditor->Graphics()->QuadsDrawTL(&QuadItemMarker, 1);
pEditor->Graphics()->QuadsEnd();
if(pEditor->UI()->DoPickerLogic(&CEditor::ms_HuePicker, &HuePicker, &X, &Y))
{
Hsv.x = 1.0f - Y / HuePicker.h;
}
CEditor::ms_PickerColor = Hsv;
return CUI::POPUP_KEEP_OPEN;
}
CUI::EPopupMenuFunctionResult CEditor::PopupEntities(void *pContext, CUIRect View, bool Active)
{
CEditor *pEditor = static_cast<CEditor *>(pContext);