fix: 自定义颜色色块与预设色块保持一致,拾色浮窗改为锚点定位并放行面板内点击

- 自定义颜色入口改为与预设色块完全一致的呈现:当前颜色不在预设中时,
  方格直接填充该自定义颜色(并自动选择浅色/深色加号图标以保证可读性),
  外框尺寸与选中样式与预设色块完全相同。
- 拾色浮窗改为以触发控件矩形为锚点定位:优先紧贴其下方展开,空间不足时改到上方,
  修复此前浮窗遮挡「加号」方格的问题。
- 拾色浮窗展开时点击面板内的其它控件(预设色、线宽、样式、透明度等)不再被吞掉,
  改为「先收起浮窗、再放行该次点击」,一次点击即可切换预设色;
  点击面板外或绘图区仍只收起浮窗。
This commit is contained in:
DeepSeek V4.1 Flash committed 2026-09-29 17:23:45 +08:00
1 parent 729494d1ec
commit 0f98dd9a85
4 files changed
+64 -31

No files matched your search

+15 -3
View File
@@ -1183,13 +1183,25 @@ namespace jdi
m_plot.OnLButtonUp(0, 0);
m_activeTarget = Target::NONE;
m_draggingSplitter = false;
m_colorPicker.OnLButtonDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
if (m_colorPicker.IsOpen())
// 点击拾色器外部时收起;若落点落在信号面板内则放行本次点击,
// 便于用户在展开状态下直接改选预设色、线宽等其它样式。
if (m_colorPicker.ContainsPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)))
{
m_colorPicker.OnLButtonDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
SetCapture(hwnd);
}
else
{
m_colorPicker.Close();
if (!m_panel.HitTest(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)))
{
InvalidateRect(hwnd, nullptr, FALSE);
return 0;
}
}
repaint = true;
consume = true;
consume = false;
break;
case WM_LBUTTONUP:
m_colorPicker.OnLButtonUp();
+29 -9
View File
@@ -105,6 +105,19 @@ namespace jdi
return WithAlpha(color, static_cast<unsigned int>(alpha * 255.0 + 0.5));
}
/**
* @brief 判断颜色是否偏暗(用于在色块之上选择可读的图标颜色)。
* @param [IN] color 0xAARRGGBB 颜色值。
* @return 相对亮度低于阈值返回 true。
*/
bool IsDarkColor(std::uint32_t color)
{
const double r = static_cast<double>((color >> 16) & 0xFFu);
const double g = static_cast<double>((color >> 8) & 0xFFu);
const double b = static_cast<double>(color & 0xFFu);
return (0.299 * r + 0.587 * g + 0.114 * b) < 140.0;
}
/**
* @brief 将数值限制到合法区间。
* @param [IN] value 输入值。
@@ -852,14 +865,23 @@ namespace jdi
}
// 自定义颜色入口:与预设色块完全同尺寸、同外框样式的小方格,仅多一个加号图标。
// 当前颜色不在预设中时,方格直接填充该颜色,与预设色块的表现保持一致。
const bool chipHot = (m_hoverStyle == StyleHit::CUSTOM_CHIP);
const bool chipActive = !presetActive && (m_colorPicker != nullptr) && m_colorPicker->IsOpen();
UiFillRoundRect(g, m_customChipRect, kCorner * m_scale, m_theme->cardBg);
UiDrawRoundRect(g, m_customChipRect, kCorner * m_scale, m_theme->borderStrong, 1.0f);
UiDrawPlusIcon(g, m_customChipRect, chipHot ? m_theme->accent : m_theme->text,
1.6f * m_scale);
// 当前颜色不在预设中时,用与预设一致的外框指示“正在使用自定义颜色”。
std::uint32_t chipColor = m_theme->cardBg;
std::uint32_t iconColor = chipHot ? m_theme->accent : m_theme->text;
if (!presetActive)
{
chipColor = ApplyOpacity(style->color, style->opacity);
iconColor = IsDarkColor(chipColor) ? 0xFFFDF6E3u : 0xFF073642u;
}
UiFillRoundRect(g, m_customChipRect, kCorner * m_scale, chipColor);
UiDrawRoundRect(g, m_customChipRect, kCorner * m_scale,
chipHot ? m_theme->accent : m_theme->borderStrong, 1.0f);
UiDrawPlusIcon(g, m_customChipRect, iconColor, 1.6f * m_scale);
// 选中外框与预设色块完全一致(当前正在使用自定义颜色或被悬停时显示)。
if (!presetActive || chipHot)
{
const gd::RectF& chip = m_customChipRect;
@@ -869,7 +891,6 @@ namespace jdi
!presetActive ? m_theme->textStrong : m_theme->borderStrong,
!presetActive ? 1.6f : 1.0f);
}
(void)chipActive;
}
// ---- 第二行:线宽 ----
@@ -1193,8 +1214,7 @@ namespace jdi
}
const gd::RectF bounds = (m_clientBounds.Width > 1.0f) ? m_clientBounds : m_area;
m_colorPicker->Open(bounds, static_cast<int>(m_customChipRect.X),
static_cast<int>(m_customChipRect.Y + m_customChipRect.Height), style.color);
m_colorPicker->Open(bounds, m_customChipRect, style.color);
return true;
}