前提:加载完成后全部采样都已驻留内存,程序此后与源文件再无联系。 据此修正了一批会让人误以为"仍在读写文件"的命名: - SampleFileAt → SampleSignalAt(取的是内存信号在给定时刻的采样值)。 - DataSet::AddPreparedFile → AddDataFile。 - PlotView::InvalidatePolylineCache → InvalidateDerivedCaches (它同时清空折线、边沿统计、中心平均值曲线、静态场景缓存与悬停引用)。 - PlotView::CursorColor(int which) → CursorColor()(两条光标同色,参数从未使用)。 - UiEllipsize(g,…) → UiEllipsize(…):纯测量不绘制,删掉被忽略的绘图上下文参数; 同时删除与 UiMeasureTextWidth 完全重复的 UiTextWidth,调用点统一到 UiMeasureTextWidth。 清理残留参数((void)xxx;): - TabConfig 的可见性/网格族(SetVisible / ToggleVisible / SetFileVisible / SetAllVisible / SoloSignal / SetMode / SyncLanes / FileHasVisible / FileAllVisible)去掉从未使用的 const DataSet& 参数(仅 SyncToDataSet 真正需要数据层,保留)。 - PlotView::OnLButtonUp(int y)、OnMouseWheel(int delta, bool shift);PainterSignalHalo 去掉未用的 ref。 - BuildDataFile 中未使用的局部 rowCount。 删除无人调用的死函数: DataSet::Clear / AddFromTable;SignalColorCount;WideToUtf8 / StartsWith; PlotView::ViewMinTime / ViewMaxTime / EdgePanelRect / EdgePanelCloseRect / EdgeCenterPanelRect / ScaleLaneRange / BeginLaneValueEdit / LaneContentHeight; SignalPanel::NeedsScrollBar / IsFilterEditing / FilterText / ContentHeight; PopupMenu::EditingItemId;TabBar::IsDragging;TextEdit::PlaceCaret。 删除只写不读的死字段:CsvTable::sourceRowCount(与 rowCount 等义)与 skippedRowCount。 以 VERY_BIG_DATA.CSV 回归验证:加载与勾选、筛选框(含"无匹配的筛选信号")、 样式区线宽文案省略、选区放大(横向与纵向)、双光标读数与 Δt、右键菜单(Y 轴数值与 实验性功能子菜单)、合并/拆分网格、标签与信号重命名省略号,行为均与改动前一致; make clean && make all 无任何警告。
2547 lines
75 KiB
C++
2547 lines
75 KiB
C++
#include "SignalPanel.hpp"
|
||
|
||
#include <algorithm>
|
||
#include <cmath>
|
||
#include <cstdlib>
|
||
|
||
#include "Utf8Util.hpp"
|
||
|
||
namespace jdi
|
||
{
|
||
|
||
namespace
|
||
{
|
||
const float kHeaderHeight = 38.0f; /**< 标题区高度(逻辑像素)。 */
|
||
const float kFileRowHeight = 30.0f; /**< 文件分组行高。 */
|
||
const float kSignalRowHeight = 27.0f; /**< 信号行高。 */
|
||
const float kPadding = 12.0f; /**< 通用内边距。 */
|
||
const float kCheckSize = 15.0f; /**< 复选框尺寸。 */
|
||
const float kSwatchSize = 12.0f; /**< 信号行颜色小方块尺寸。 */
|
||
const float kBadgeWidth = 30.0f; /**< 网格徽标宽度。 */
|
||
const float kBadgeHeight = 17.0f; /**< 网格徽标高度。 */
|
||
const float kCorner = 4.0f; /**< 通用圆角半径。 */
|
||
const float kDisclosureWidth = 16.0f; /**< 折叠三角占位宽度。 */
|
||
const float kIndent = 14.0f; /**< 信号行相对文件行的缩进。 */
|
||
const float kScrollBarThickness = 8.0f; /**< 滚动条宽度。 */
|
||
const float kCloseButtonSize = 18.0f; /**< 文件行关闭按钮尺寸。 */
|
||
const float kGroupSeparatorGap = 7.0f; /**< 分组标签与分隔线/名称的间距。 */
|
||
const float kGroupSeparatorWidth = 1.0f; /**< 分组标签右侧分隔线宽度。 */
|
||
const float kFilterHeight = 26.0f; /**< 「筛选信号」输入框高度。 */
|
||
const float kFilterPadV = 5.0f; /**< 筛选框上下留白。 */
|
||
const float kFilterTextPad = 4.0f; /**< 筛选框内文字/输入框相对外框的内缩(四边一致)。 */
|
||
|
||
/**
|
||
* @brief 大小写无关的通配符匹配(`*` 匹配任意长度的任意字符序列)。
|
||
* @param [IN] text 待匹配文本。
|
||
* @param [IN] pattern 模式(可含多个 `*`)。
|
||
* @return 匹配返回 true。
|
||
*/
|
||
bool WildcardMatchNoCase(const std::wstring& text, const std::wstring& pattern)
|
||
{
|
||
const auto fold = [](wchar_t character) -> wchar_t
|
||
{
|
||
// 仅对基本拉丁字母做大小写折叠(中文等其它字符原样比较)。
|
||
if (character >= L'A' && character <= L'Z')
|
||
{
|
||
return static_cast<wchar_t>(character - L'A' + L'a');
|
||
}
|
||
return character;
|
||
};
|
||
|
||
// 经典双指针回溯:`star` 记录最近一个 `*` 的位置,`resume` 记录当时尝试的文本位置。
|
||
std::size_t t = 0;
|
||
std::size_t p = 0;
|
||
std::size_t star = std::wstring::npos;
|
||
std::size_t resume = 0;
|
||
|
||
while (t < text.size())
|
||
{
|
||
if (p < pattern.size() && pattern[p] == L'*')
|
||
{
|
||
star = p;
|
||
resume = t;
|
||
++p;
|
||
}
|
||
else if (p < pattern.size() && fold(pattern[p]) == fold(text[t]))
|
||
{
|
||
++p;
|
||
++t;
|
||
}
|
||
else if (star != std::wstring::npos)
|
||
{
|
||
p = star + 1;
|
||
++resume;
|
||
t = resume;
|
||
}
|
||
else
|
||
{
|
||
return false;
|
||
}
|
||
}
|
||
|
||
// 文本已耗尽:模式剩余部分必须全是 `*`。
|
||
while (p < pattern.size() && pattern[p] == L'*')
|
||
{
|
||
++p;
|
||
}
|
||
return p == pattern.size();
|
||
}
|
||
|
||
// 样式编辑区:固定四行网格(颜色 / 样式 / 透明度 / 线宽),行高、间距与内容列宽度统一,
|
||
// 保证面板宽度变化时四行控件始终对齐,且不会被无限制拉伸。
|
||
const float kStylePadH = 12.0f; /**< 样式区左右内边距。 */
|
||
const float kStylePadV = 12.0f; /**< 样式区上下内边距。 */
|
||
const float kStyleRowHeight = 26.0f; /**< 样式区单行高度。 */
|
||
const float kStyleRowGap = 10.0f; /**< 样式区行间距。 */
|
||
const float kStyleLabelWidth = 44.0f; /**< 样式行标签列宽度。 */
|
||
const float kStyleLabelGap = 8.0f; /**< 标签列与内容列间距。 */
|
||
const float kStyleRowCount = 4.0f; /**< 样式区固定行数。 */
|
||
const float kStyleContentMax = 260.0f; /**< 内容列最大宽度(再拉宽面板也不再延伸)。 */
|
||
const float kSwatchEdge = 18.0f; /**< 颜色色块边长上限(含自定义颜色入口)。 */
|
||
const float kSwatchMin = 11.0f; /**< 颜色色块边长下限。 */
|
||
const float kSwatchGap = 4.0f; /**< 颜色色块最小间距。 */
|
||
const float kSwatchMaxGap = 10.0f; /**< 颜色色块最大间距(用于铺满内容列)。 */
|
||
const float kSliderValueWidth = 52.0f; /**< 滑块行数值文本宽度(透明度与线宽一致)。 */
|
||
const float kSliderValueGap = 8.0f; /**< 滑块轨道与数值文本间距。 */
|
||
const float kTrackHeight = 6.0f; /**< 滑块轨道高度。 */
|
||
|
||
const float kWidthMin = 0.5f; /**< 允许的最小线宽(px)。 */
|
||
const float kWidthMax = 10.0f; /**< 允许的最大线宽(px)。 */
|
||
|
||
/** @brief 可选绘制样式顺序(不含阶梯方式)。 */
|
||
const DrawMode kModeOptions[] = {DrawMode::LINE, DrawMode::SCATTER, DrawMode::LINE_SCATTER};
|
||
const int kModeOptionCount = static_cast<int>(sizeof(kModeOptions) / sizeof(kModeOptions[0]));
|
||
|
||
/**
|
||
* @brief 计算滑块的便捷命中矩形(比轨道略大,便于拖拽)。
|
||
* @param [IN] track 轨道矩形。
|
||
* @param [IN] scale 缩放比例。
|
||
* @return 命中矩形。
|
||
*/
|
||
gd::RectF SliderHitRect(const gd::RectF& track, float scale)
|
||
{
|
||
return gd::RectF(track.X - 6.0f * scale, track.Y - 9.0f * scale, track.Width + 12.0f * scale,
|
||
track.Height + 18.0f * scale);
|
||
}
|
||
|
||
/**
|
||
* @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 输入值。
|
||
* @param [IN] low 下限。
|
||
* @param [IN] high 上限。
|
||
* @return 限制后的数值。
|
||
*/
|
||
float ClampFloat(float value, float low, float high)
|
||
{
|
||
return (value < low) ? low : ((value > high) ? high : value);
|
||
}
|
||
}
|
||
|
||
SignalPanel::SignalPanel()
|
||
{
|
||
m_colorRects.fill(gd::RectF());
|
||
m_modeRects.fill(gd::RectF());
|
||
}
|
||
|
||
void SignalPanel::Setup(HWND host, const UiFonts* fonts, const Theme* theme, PopupMenu* menu,
|
||
ColorPickerPopup* colorPicker)
|
||
{
|
||
m_host = host;
|
||
m_fonts = fonts;
|
||
m_theme = theme;
|
||
m_menu = menu;
|
||
m_colorPicker = colorPicker;
|
||
}
|
||
|
||
void SignalPanel::SetContext(DataSet* dataSet, TabConfig* tab)
|
||
{
|
||
m_dataSet = dataSet;
|
||
m_dataSetWritable = dataSet;
|
||
m_tab = tab;
|
||
m_rowsDirty = true;
|
||
m_scrollOffset = 0.0f;
|
||
m_draggingOpacity = false;
|
||
m_draggingWidth = false;
|
||
m_edit.End();
|
||
m_editRow = -1;
|
||
m_editField = StyleEditField::NONE;
|
||
m_pendingLaneMenu = false;
|
||
m_pendingColorPicker = false;
|
||
}
|
||
|
||
void SignalPanel::SetScale(float scale)
|
||
{
|
||
m_scale = (scale > 0.1f) ? scale : 1.0f;
|
||
}
|
||
|
||
bool SignalPanel::HitTest(int x, int y) const
|
||
{
|
||
return UiPointInRect(m_area, static_cast<float>(x), static_cast<float>(y));
|
||
}
|
||
|
||
int SignalPanel::TotalSignalCount() const
|
||
{
|
||
if (m_dataSet == nullptr)
|
||
{
|
||
return 0;
|
||
}
|
||
return static_cast<int>(m_dataSet->SignalCount());
|
||
}
|
||
|
||
float SignalPanel::DesiredStyleHeight() const
|
||
{
|
||
return kStylePadV * 2.0f + kStyleRowCount * kStyleRowHeight +
|
||
(kStyleRowCount - 1.0f) * kStyleRowGap;
|
||
}
|
||
|
||
bool SignalPanel::TakeLayoutDirty()
|
||
{
|
||
const bool dirty = m_layoutDirty;
|
||
m_layoutDirty = false;
|
||
return dirty;
|
||
}
|
||
|
||
bool SignalPanel::IsOnFilterBox(int x, int y) const
|
||
{
|
||
return UiPointInRect(m_filterRect, static_cast<float>(x), static_cast<float>(y));
|
||
}
|
||
|
||
void SignalPanel::ClearFilter()
|
||
{
|
||
if (m_filterText.empty() && !m_filterEditing)
|
||
{
|
||
return;
|
||
}
|
||
m_filterText.clear();
|
||
if (m_filterEditing)
|
||
{
|
||
// 编辑态下一并重置输入模型,避免残留旧文本(Begin 会整段选中/清空)。
|
||
m_filterEdit.Begin(std::wstring(), false, EditFilter::ANY, 0u);
|
||
}
|
||
// 清空后回到完整列表:重建行集合、回到顶部。
|
||
m_rowsDirty = true;
|
||
m_scrollOffset = 0.0f;
|
||
m_layoutDirty = true;
|
||
}
|
||
|
||
HCURSOR SignalPanel::QueryCursor(int x, int y) const
|
||
{
|
||
// 清空按钮 ✕ 是独立可点击控件,用手型光标给出除高亮之外的额外交互提示。
|
||
const gd::RectF clearRect = FilterClearRect();
|
||
if (clearRect.Width > 0.0f &&
|
||
UiPointInRect(clearRect, static_cast<float>(x), static_cast<float>(y)))
|
||
{
|
||
return LoadCursorW(nullptr, IDC_HAND);
|
||
}
|
||
return nullptr;
|
||
}
|
||
|
||
void SignalPanel::BeginFilterEdit()
|
||
{
|
||
if (m_filterEditing)
|
||
{
|
||
return;
|
||
}
|
||
m_filterEditing = true;
|
||
// 单击进入编辑:光标落在末尾,不做全选(用户可以继续追加筛选词)。
|
||
m_filterEdit.Begin(m_filterText, false, EditFilter::ANY, 0u);
|
||
}
|
||
|
||
bool SignalPanel::EndFilterEdit()
|
||
{
|
||
if (!m_filterEditing)
|
||
{
|
||
return false;
|
||
}
|
||
// **必须**在 `End()` 之前取出文本:`TextEdit::End()` 会清空内部缓冲区。
|
||
const std::wstring finalText = Trim(m_filterEdit.Text());
|
||
m_filterEditing = false;
|
||
m_filterEdit.End();
|
||
// 文本在编辑过程中已实时生效,这里只需把最终值再同步一次并收起插入符。
|
||
m_filterText = finalText;
|
||
return true;
|
||
}
|
||
|
||
void SignalPanel::ApplyFilterText(const std::wstring& text)
|
||
{
|
||
if (m_filterText == text)
|
||
{
|
||
return;
|
||
}
|
||
m_filterText = text;
|
||
// 筛选结果变化 → 重建行集合、回到列表顶部并重新计算滚动条。
|
||
m_rowsDirty = true;
|
||
m_scrollOffset = 0.0f;
|
||
m_layoutDirty = true;
|
||
}
|
||
|
||
bool SignalPanel::FilterMatchesSignal(const SignalData& signal) const
|
||
{
|
||
if (m_filterText.empty())
|
||
{
|
||
return true;
|
||
}
|
||
// 以 `*` 为通配符、忽略大小写,匹配"信号名中是否出现过符合该模式的片段"。
|
||
// 两侧补 `*` 使模式等价于子串匹配,因此下面这些写法都能按直觉工作:
|
||
// `编码器` → 名称包含"编码器"
|
||
// `编码器*相` → 名称中出现以"编码器"开头、"相"结尾的片段
|
||
// `*x10` / `ABS*` → 尾部/首部片段匹配(无需用户自己补另一侧的 `*`)
|
||
std::wstring pattern = L"*";
|
||
pattern += m_filterText;
|
||
pattern += L'*';
|
||
return WildcardMatchNoCase(signal.Title(), pattern);
|
||
}
|
||
|
||
void SignalPanel::BuildRows()
|
||
{ m_rows.clear();
|
||
m_rowsDirty = false;
|
||
|
||
if (m_dataSet == nullptr || m_tab == nullptr)
|
||
{
|
||
m_contentHeight = 0.0f;
|
||
return;
|
||
}
|
||
|
||
const float fileHeight = kFileRowHeight * m_scale;
|
||
const float signalHeight = kSignalRowHeight * m_scale;
|
||
const bool filtering = !m_filterText.empty();
|
||
|
||
const std::vector<DataFile>& files = m_dataSet->Files();
|
||
for (std::size_t fileIndex = 0; fileIndex < files.size(); ++fileIndex)
|
||
{
|
||
// 筛选时先挑出本组内匹配的信号;整组都没有匹配则**不显示该组**。
|
||
std::vector<int> matched;
|
||
if (filtering)
|
||
{
|
||
const std::size_t signalCount = files[fileIndex].signals.size();
|
||
for (std::size_t signalIndex = 0; signalIndex < signalCount; ++signalIndex)
|
||
{
|
||
if (FilterMatchesSignal(files[fileIndex].signals[signalIndex]))
|
||
{
|
||
matched.push_back(static_cast<int>(signalIndex));
|
||
}
|
||
}
|
||
if (matched.empty())
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
|
||
ListRow fileRow;
|
||
fileRow.kind = RowKind::FILE;
|
||
fileRow.fileIndex = static_cast<int>(fileIndex);
|
||
fileRow.height = fileHeight;
|
||
m_rows.push_back(fileRow);
|
||
|
||
// 筛选结果**默认展开**(忽略折叠状态),便于直接看到匹配项。
|
||
if (!filtering && m_tab->IsCollapsed(static_cast<int>(fileIndex)))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (filtering)
|
||
{
|
||
for (const int signalIndex : matched)
|
||
{
|
||
ListRow signalRow;
|
||
signalRow.kind = RowKind::SIGNAL;
|
||
signalRow.fileIndex = static_cast<int>(fileIndex);
|
||
signalRow.signalIndex = signalIndex;
|
||
signalRow.height = signalHeight;
|
||
m_rows.push_back(signalRow);
|
||
}
|
||
continue;
|
||
}
|
||
|
||
const std::size_t signalCount = files[fileIndex].signals.size();
|
||
for (std::size_t signalIndex = 0; signalIndex < signalCount; ++signalIndex)
|
||
{
|
||
ListRow signalRow;
|
||
signalRow.kind = RowKind::SIGNAL;
|
||
signalRow.fileIndex = static_cast<int>(fileIndex);
|
||
signalRow.signalIndex = static_cast<int>(signalIndex);
|
||
signalRow.height = signalHeight;
|
||
m_rows.push_back(signalRow);
|
||
}
|
||
}
|
||
|
||
m_contentHeight = 0.0f;
|
||
for (const ListRow& row : m_rows)
|
||
{
|
||
m_contentHeight += row.height;
|
||
}
|
||
}
|
||
|
||
void SignalPanel::EnsureRows()
|
||
{
|
||
if (m_rowsDirty)
|
||
{
|
||
BuildRows();
|
||
RefreshScrollBar();
|
||
}
|
||
}
|
||
|
||
void SignalPanel::RefreshScrollBar()
|
||
{
|
||
if (m_listFullWidth <= 0.0f)
|
||
{
|
||
m_scrollBarVisible = false;
|
||
return;
|
||
}
|
||
|
||
m_scrollBarVisible = (m_contentHeight > m_listRect.Height + 0.5f);
|
||
if (m_scrollBarVisible)
|
||
{
|
||
const float thickness = kScrollBarThickness * m_scale;
|
||
m_listRect.Width = std::max(0.0f, m_listFullWidth - thickness - 2.0f * m_scale);
|
||
m_scrollBarRect = gd::RectF(m_area.X + m_area.Width - thickness - 3.0f * m_scale, m_listRect.Y,
|
||
thickness, m_listRect.Height);
|
||
}
|
||
else
|
||
{
|
||
m_listRect.Width = m_listFullWidth;
|
||
m_scrollBarRect = gd::RectF();
|
||
}
|
||
|
||
ClampScroll();
|
||
}
|
||
|
||
void SignalPanel::ClampScroll()
|
||
{
|
||
const float maxOffset = std::max(0.0f, m_contentHeight - m_listRect.Height);
|
||
m_scrollOffset = std::max(0.0f, std::min(m_scrollOffset, maxOffset));
|
||
}
|
||
|
||
gd::RectF SignalPanel::RowRect(int row) const
|
||
{
|
||
if (row < 0 || row >= static_cast<int>(m_rows.size()))
|
||
{
|
||
return gd::RectF();
|
||
}
|
||
|
||
float top = m_listRect.Y - m_scrollOffset;
|
||
for (int index = 0; index < row; ++index)
|
||
{
|
||
top += m_rows[static_cast<std::size_t>(index)].height;
|
||
}
|
||
return gd::RectF(m_listRect.X, top, m_listRect.Width, m_rows[static_cast<std::size_t>(row)].height);
|
||
}
|
||
|
||
gd::RectF SignalPanel::FileCloseRect(int row) const
|
||
{
|
||
const gd::RectF rect = RowRect(row);
|
||
const float size = kCloseButtonSize * m_scale;
|
||
return gd::RectF(rect.X + rect.Width - kPadding * m_scale - size,
|
||
rect.Y + (rect.Height - size) * 0.5f, size, size);
|
||
}
|
||
|
||
gd::RectF SignalPanel::SignalBadgeRect(int row) const
|
||
{
|
||
const gd::RectF rect = RowRect(row);
|
||
const float width = kBadgeWidth * m_scale;
|
||
const float height = kBadgeHeight * m_scale;
|
||
return gd::RectF(rect.X + rect.Width - kPadding * m_scale - width,
|
||
rect.Y + (rect.Height - height) * 0.5f, width, height);
|
||
}
|
||
|
||
int SignalPanel::HitRow(int x, int y, RowPart& part)
|
||
{
|
||
part = RowPart::NONE;
|
||
EnsureRows();
|
||
|
||
if (m_listRect.Height <= 0.0f)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
const float fx = static_cast<float>(x);
|
||
const float fy = static_cast<float>(y);
|
||
if (fy < m_listRect.Y || fy > m_listRect.Y + m_listRect.Height)
|
||
{
|
||
return -1;
|
||
}
|
||
if (fx < m_listRect.X || fx > m_listRect.X + m_listRect.Width)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
const float local = fy - m_listRect.Y + m_scrollOffset;
|
||
if (local < 0.0f)
|
||
{
|
||
return -1;
|
||
}
|
||
|
||
float accumulated = 0.0f;
|
||
for (std::size_t index = 0; index < m_rows.size(); ++index)
|
||
{
|
||
const ListRow& row = m_rows[index];
|
||
if (local >= accumulated && local < accumulated + row.height)
|
||
{
|
||
const int rowIndex = static_cast<int>(index);
|
||
const gd::RectF rect = RowRect(rowIndex);
|
||
const bool isFile = (row.kind == RowKind::FILE);
|
||
const float baseX = rect.X + kPadding * m_scale + (isFile ? 0.0f : kIndent * m_scale);
|
||
|
||
const gd::RectF disclosureRect(baseX, rect.Y, kDisclosureWidth * m_scale, rect.Height);
|
||
const gd::RectF checkRect(baseX + kDisclosureWidth * m_scale,
|
||
rect.Y + (rect.Height - kCheckSize * m_scale) * 0.5f,
|
||
kCheckSize * m_scale, kCheckSize * m_scale);
|
||
|
||
if (isFile)
|
||
{
|
||
if (UiPointInRect(disclosureRect, fx, fy))
|
||
{
|
||
part = RowPart::DISCLOSURE;
|
||
}
|
||
else if (UiPointInRect(checkRect, fx, fy))
|
||
{
|
||
part = RowPart::CHECK;
|
||
}
|
||
else if (UiPointInRect(FileCloseRect(rowIndex), fx, fy))
|
||
{
|
||
part = RowPart::CLOSE;
|
||
}
|
||
else
|
||
{
|
||
part = RowPart::BODY;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
const SignalRef ref{row.fileIndex, row.signalIndex};
|
||
const bool badgeVisible = (m_tab != nullptr) && m_tab->IsVisible(ref);
|
||
|
||
if (UiPointInRect(checkRect, fx, fy))
|
||
{
|
||
part = RowPart::CHECK;
|
||
}
|
||
else if (badgeVisible && UiPointInRect(SignalBadgeRect(rowIndex), fx, fy))
|
||
{
|
||
part = RowPart::LANE_BADGE;
|
||
}
|
||
else
|
||
{
|
||
part = RowPart::BODY;
|
||
}
|
||
}
|
||
return rowIndex;
|
||
}
|
||
accumulated += row.height;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
void SignalPanel::ScrollToSignal(const SignalRef& ref)
|
||
{
|
||
EnsureRows();
|
||
if (!ref.IsValid())
|
||
{
|
||
return;
|
||
}
|
||
|
||
float top = 0.0f;
|
||
for (std::size_t index = 0; index < m_rows.size(); ++index)
|
||
{
|
||
const ListRow& row = m_rows[index];
|
||
if (row.kind == RowKind::SIGNAL && row.fileIndex == ref.fileIndex &&
|
||
row.signalIndex == ref.signalIndex)
|
||
{
|
||
if (top < m_scrollOffset)
|
||
{
|
||
m_scrollOffset = top;
|
||
}
|
||
else if (top + row.height > m_scrollOffset + m_listRect.Height)
|
||
{
|
||
m_scrollOffset = top + row.height - m_listRect.Height;
|
||
}
|
||
ClampScroll();
|
||
return;
|
||
}
|
||
top += row.height;
|
||
}
|
||
}
|
||
|
||
void SignalPanel::LayoutStyleControls()
|
||
{
|
||
const float padH = kStylePadH * m_scale;
|
||
const float labelWidth = kStyleLabelWidth * m_scale;
|
||
const float labelGap = kStyleLabelGap * m_scale;
|
||
const float rowHeight = kStyleRowHeight * m_scale;
|
||
const float rowStep = (kStyleRowHeight + kStyleRowGap) * m_scale;
|
||
const float firstTop = m_styleRect.Y + kStylePadV * m_scale;
|
||
|
||
// 内容列宽度带上下限:面板变窄时收缩,面板变宽时不再延伸,四行始终共用同一宽度。
|
||
const float available = std::max(40.0f, m_styleRect.Width - padH * 2.0f - labelWidth - labelGap);
|
||
const float contentWidth = std::min(available, kStyleContentMax * m_scale);
|
||
|
||
// 标签列 + 内容列整体靠左对齐(始终从左侧内边距开始),不随面板变宽而居中偏移。
|
||
const float groupWidth = labelWidth + labelGap + contentWidth;
|
||
const float groupLeft = m_styleRect.X + padH;
|
||
const float contentLeft = groupLeft + labelWidth + labelGap;
|
||
|
||
for (int index = 0; index < static_cast<int>(kStyleRowCount); ++index)
|
||
{
|
||
m_styleRowRects[static_cast<std::size_t>(index)] =
|
||
gd::RectF(groupLeft, firstTop + static_cast<float>(index) * rowStep, groupWidth, rowHeight);
|
||
}
|
||
|
||
const gd::RectF& colorRow = m_styleRowRects[0];
|
||
const gd::RectF& modeRow = m_styleRowRects[1];
|
||
const gd::RectF& opacityRow = m_styleRowRects[2];
|
||
const gd::RectF& widthRow = m_styleRowRects[3];
|
||
|
||
// ---- 颜色行:预设色块 + 同尺寸自定义颜色入口(合计恰好铺满内容列宽度)----
|
||
int paletteCount = 0;
|
||
SignalPalette(paletteCount);
|
||
|
||
const float swatchGap = kSwatchGap * m_scale;
|
||
const float swatchMaxGap = kSwatchMaxGap * m_scale;
|
||
const float swatchMin = kSwatchMin * m_scale;
|
||
int count = std::min(paletteCount, static_cast<int>(m_colorRects.size()));
|
||
float swatchSize = kSwatchEdge * m_scale;
|
||
float gap = swatchGap;
|
||
while (count >= 1)
|
||
{
|
||
const float slots = static_cast<float>(count + 1);
|
||
const float fit = (contentWidth - swatchGap * (slots - 1.0f)) / slots;
|
||
if (count == 1 || fit >= swatchMin)
|
||
{
|
||
swatchSize = std::max(swatchMin, std::min(kSwatchEdge * m_scale, fit));
|
||
// 用实际色块尺寸反算间距,让颜色行与透明度、线宽、样式各行同宽。
|
||
gap = (contentWidth - swatchSize * slots) / static_cast<float>(count);
|
||
gap = std::max(swatchGap, std::min(gap, swatchMaxGap));
|
||
break;
|
||
}
|
||
--count;
|
||
}
|
||
m_colorCount = std::max(1, count);
|
||
|
||
// 颜色行与其余三行共用同一左边界(不再居中),保证四行纵向对齐。
|
||
const float colorRowLeft = contentLeft;
|
||
|
||
const float swatchTop = colorRow.Y + (rowHeight - swatchSize) * 0.5f;
|
||
for (int index = 0; index < m_colorCount; ++index)
|
||
{
|
||
m_colorRects[static_cast<std::size_t>(index)] =
|
||
gd::RectF(colorRowLeft + static_cast<float>(index) * (swatchSize + gap), swatchTop,
|
||
swatchSize, swatchSize);
|
||
}
|
||
m_customChipRect =
|
||
gd::RectF(colorRowLeft + static_cast<float>(m_colorCount) * (swatchSize + gap), swatchTop,
|
||
swatchSize, swatchSize);
|
||
|
||
// ---- 样式行:三个等宽按钮铺满内容列 ----
|
||
const float modeGap = 6.0f * m_scale;
|
||
const float modeWidth =
|
||
std::max(20.0f, (contentWidth - modeGap * static_cast<float>(kModeOptionCount - 1)) /
|
||
static_cast<float>(kModeOptionCount));
|
||
for (int index = 0; index < kModeOptionCount; ++index)
|
||
{
|
||
m_modeRects[static_cast<std::size_t>(index)] =
|
||
gd::RectF(contentLeft + static_cast<float>(index) * (modeWidth + modeGap), modeRow.Y,
|
||
modeWidth, rowHeight);
|
||
}
|
||
|
||
// ---- 透明度行与线宽行:几何完全一致,保证纵向宽度对齐 ----
|
||
const float valueWidth = std::min(kSliderValueWidth * m_scale, contentWidth * 0.4f);
|
||
const float trackWidth = std::max(24.0f, contentWidth - valueWidth - kSliderValueGap * m_scale);
|
||
const float trackHeight = kTrackHeight * m_scale;
|
||
|
||
m_opacityTrackRect = gd::RectF(contentLeft, opacityRow.Y + (rowHeight - trackHeight) * 0.5f,
|
||
trackWidth, trackHeight);
|
||
m_opacityValueRect = gd::RectF(contentLeft + trackWidth + kSliderValueGap * m_scale, opacityRow.Y,
|
||
valueWidth, rowHeight);
|
||
|
||
m_widthTrackRect =
|
||
gd::RectF(contentLeft, widthRow.Y + (rowHeight - trackHeight) * 0.5f, trackWidth, trackHeight);
|
||
m_widthValueRect = gd::RectF(contentLeft + trackWidth + kSliderValueGap * m_scale, widthRow.Y,
|
||
valueWidth, rowHeight);
|
||
}
|
||
|
||
void SignalPanel::Layout(const gd::RectF& area)
|
||
{
|
||
m_area = area;
|
||
|
||
m_headerRect = gd::RectF(area.X, area.Y, area.Width, kHeaderHeight * m_scale);
|
||
|
||
// 标题下方的「筛选信号」输入框(列表内容过滤)。
|
||
const float filterHeight = kFilterHeight * m_scale;
|
||
m_filterRect = gd::RectF(area.X + kPadding * m_scale,
|
||
m_headerRect.Y + m_headerRect.Height + kFilterPadV * m_scale,
|
||
std::max(20.0f, area.Width - kPadding * 2.0f * m_scale), filterHeight);
|
||
|
||
const float styleHeight = DesiredStyleHeight() * m_scale;
|
||
m_styleRect = gd::RectF(area.X, area.Y + area.Height - styleHeight, area.Width, styleHeight);
|
||
const float listTop = m_filterRect.Y + m_filterRect.Height + kFilterPadV * m_scale;
|
||
m_listRect = gd::RectF(area.X, listTop, area.Width,
|
||
std::max(0.0f, m_styleRect.Y - listTop));
|
||
|
||
// 标题区右侧的“全部显示/隐藏”按钮。
|
||
const float toggleWidth = 68.0f * m_scale;
|
||
const float toggleHeight = 22.0f * m_scale;
|
||
m_toggleAllRect = gd::RectF(area.X + area.Width - kPadding * m_scale - toggleWidth,
|
||
m_headerRect.Y + (m_headerRect.Height - toggleHeight) * 0.5f,
|
||
toggleWidth, toggleHeight);
|
||
|
||
// 依据内容决定是否显示滚动条,并据此收缩列表可用宽度。
|
||
m_listFullWidth = m_listRect.Width;
|
||
EnsureRows();
|
||
RefreshScrollBar();
|
||
|
||
LayoutStyleControls();
|
||
}
|
||
|
||
void SignalPanel::Paint(gd::Graphics& g)
|
||
{
|
||
if (m_theme == nullptr || m_fonts == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
EnsureRows();
|
||
UiFillRect(g, m_area, m_theme->panelBg);
|
||
|
||
// 标题区。
|
||
{
|
||
std::wstring title = L"信号";
|
||
if (m_dataSet != nullptr && m_tab != nullptr)
|
||
{
|
||
title += L" · " + std::to_wstring(m_tab->VisibleCount()) + L"/" +
|
||
std::to_wstring(TotalSignalCount()) + L" 已选";
|
||
}
|
||
|
||
gd::RectF titleRect(m_headerRect.X + kPadding * m_scale, m_headerRect.Y,
|
||
std::max(20.0f, m_headerRect.Width - kPadding * 2.0f * m_scale -
|
||
m_toggleAllRect.Width - 8.0f * m_scale),
|
||
m_headerRect.Height);
|
||
UiText(g, UiEllipsize(title, m_fonts->uiBold, titleRect.Width), m_fonts->uiBold, titleRect,
|
||
m_theme->textStrong, TextAlign::LEFT);
|
||
|
||
const bool allVisible = AreAllSignalsVisible();
|
||
const std::wstring toggleLabel = allVisible ? L"全部隐藏" : L"全部显示";
|
||
const bool toggleHover = (m_hoverStyle == StyleHit::TOGGLE_ALL);
|
||
if (toggleHover)
|
||
{
|
||
UiFillRoundRect(g, m_toggleAllRect, kCorner * m_scale, m_theme->hover);
|
||
}
|
||
UiDrawRoundRect(g, m_toggleAllRect, kCorner * m_scale, m_theme->border, 1.0f);
|
||
const bool enabled = (m_dataSet != nullptr && !m_dataSet->Empty());
|
||
UiText(g, toggleLabel, m_fonts->uiSmall, m_toggleAllRect,
|
||
enabled ? m_theme->text : m_theme->textMuted, TextAlign::CENTER);
|
||
}
|
||
|
||
// 「筛选信号」输入框:未输入内容时显示占位提示,单击进入编辑,输入实时过滤下方列表。
|
||
{
|
||
UiFillRoundRect(g, m_filterRect, kCorner * m_scale, m_theme->cardBg);
|
||
UiDrawRoundRect(g, m_filterRect, kCorner * m_scale,
|
||
m_filterEditing ? m_theme->accent : m_theme->border,
|
||
m_filterEditing ? 1.6f : 1.0f);
|
||
|
||
const float pad = kFilterTextPad * m_scale;
|
||
const gd::RectF clearRect = FilterClearRect();
|
||
// 有输入内容时在右侧留出 ✕ 的位置,文本不会压到按钮上。
|
||
const float textRight = (clearRect.Width > 0.0f) ? clearRect.X : (m_filterRect.X + m_filterRect.Width);
|
||
const float textWidth = std::max(8.0f, textRight - pad - (m_filterRect.X + pad));
|
||
const gd::RectF textRect(m_filterRect.X + pad, m_filterRect.Y, textWidth,
|
||
m_filterRect.Height);
|
||
|
||
if (m_filterEditing)
|
||
{
|
||
gd::RectF fieldRect = FilterFieldRect();
|
||
fieldRect.Width = std::max(8.0f, textWidth + pad);
|
||
UiDrawEditField(g, fieldRect, m_filterEdit, m_fonts->uiSmall, m_scale);
|
||
}
|
||
else if (m_filterText.empty())
|
||
{
|
||
UiText(g, L"筛选信号", m_fonts->uiSmall, textRect, m_theme->textMuted, TextAlign::LEFT);
|
||
}
|
||
else
|
||
{
|
||
UiText(g, UiEllipsize(m_filterText, m_fonts->uiSmall, textWidth), m_fonts->uiSmall,
|
||
textRect, m_theme->text, TextAlign::LEFT);
|
||
}
|
||
|
||
// 清空按钮 ✕:仅在筛选框有内容时出现,悬停高亮(鼠标光标保持箭头)。
|
||
if (clearRect.Width > 0.0f)
|
||
{
|
||
const bool clearHot = (m_hoverStyle == StyleHit::FILTER_CLEAR);
|
||
if (clearHot)
|
||
{
|
||
UiFillRoundRect(g, clearRect, 3.0f * m_scale, WithAlpha(m_theme->danger, 0x33));
|
||
}
|
||
const std::uint32_t crossColor = clearHot ? m_theme->danger : m_theme->textMuted;
|
||
const float crossPad = clearRect.Width * 0.28f;
|
||
UiDrawLine(g, clearRect.X + crossPad, clearRect.Y + crossPad,
|
||
clearRect.X + clearRect.Width - crossPad,
|
||
clearRect.Y + clearRect.Height - crossPad, crossColor, 1.5f * m_scale);
|
||
UiDrawLine(g, clearRect.X + clearRect.Width - crossPad, clearRect.Y + crossPad,
|
||
clearRect.X + crossPad, clearRect.Y + clearRect.Height - crossPad, crossColor,
|
||
1.5f * m_scale);
|
||
}
|
||
}
|
||
|
||
// 列表区。
|
||
{
|
||
const int saveState = g.Save();
|
||
g.SetClip(gd::RectF(m_listRect.X, m_listRect.Y, m_listRect.Width, m_listRect.Height));
|
||
|
||
if (m_dataSet == nullptr || m_dataSet->Empty())
|
||
{
|
||
UiText(g, L"尚未加载数据,请打开 CSV 文件", m_fonts->uiSmall, m_listRect, m_theme->textMuted,
|
||
TextAlign::CENTER);
|
||
}
|
||
else if (m_rows.empty() && !m_filterText.empty())
|
||
{
|
||
// 筛选结果为空:明确提示"无匹配",而不是让人误以为数据丢失。
|
||
UiText(g, L"无匹配的筛选信号", m_fonts->uiSmall, m_listRect, m_theme->textMuted,
|
||
TextAlign::CENTER);
|
||
}
|
||
else
|
||
{
|
||
const int rowCount = static_cast<int>(m_rows.size());
|
||
for (int row = 0; row < rowCount; ++row)
|
||
{
|
||
const gd::RectF rect = RowRect(row);
|
||
if (rect.Y + rect.Height < m_listRect.Y || rect.Y > m_listRect.Y + m_listRect.Height)
|
||
{
|
||
continue;
|
||
}
|
||
if (m_rows[static_cast<std::size_t>(row)].kind == RowKind::FILE)
|
||
{
|
||
PaintFileRow(g, row);
|
||
}
|
||
else
|
||
{
|
||
PaintSignalRow(g, row);
|
||
}
|
||
}
|
||
}
|
||
|
||
g.Restore(saveState);
|
||
}
|
||
|
||
PaintScrollBar(g);
|
||
PaintStyleSection(g);
|
||
|
||
// 分隔线。
|
||
UiDrawLine(g, m_area.X + m_area.Width - 1.0f, m_area.Y, m_area.X + m_area.Width - 1.0f,
|
||
m_area.Y + m_area.Height, m_theme->border, 1.0f);
|
||
UiDrawLine(g, m_headerRect.X, m_headerRect.Y + m_headerRect.Height - 1.0f,
|
||
m_headerRect.X + m_headerRect.Width, m_headerRect.Y + m_headerRect.Height - 1.0f,
|
||
m_theme->border, 1.0f);
|
||
if (m_styleRect.Height > 0.0f)
|
||
{
|
||
UiDrawLine(g, m_styleRect.X, m_styleRect.Y, m_styleRect.X + m_styleRect.Width, m_styleRect.Y,
|
||
m_theme->border, 1.0f);
|
||
}
|
||
}
|
||
|
||
void SignalPanel::PaintFileRow(gd::Graphics& g, int row)
|
||
{
|
||
if (m_dataSet == nullptr || m_tab == nullptr || row < 0 || row >= static_cast<int>(m_rows.size()))
|
||
{
|
||
return;
|
||
}
|
||
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
const DataFile* file = m_dataSet->FileAt(item.fileIndex);
|
||
if (file == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
const gd::RectF rect = RowRect(row);
|
||
const bool hovered = (m_hoverRow == row);
|
||
if (hovered)
|
||
{
|
||
UiFillRect(g, rect, m_theme->hover);
|
||
}
|
||
UiFillRect(g, gd::RectF(rect.X, rect.Y, 2.0f * m_scale, rect.Height),
|
||
WithAlpha(m_theme->borderStrong, 0x90));
|
||
|
||
const float baseX = rect.X + kPadding * m_scale;
|
||
const float centerY = rect.Y + rect.Height * 0.5f;
|
||
const bool collapsed = m_tab->IsCollapsed(item.fileIndex);
|
||
|
||
// 折叠三角。
|
||
{
|
||
const float cx = baseX + kDisclosureWidth * m_scale * 0.5f;
|
||
const std::uint32_t color =
|
||
(hovered && m_hoverPart == RowPart::DISCLOSURE) ? m_theme->accent : m_theme->text;
|
||
UiDrawTriangleIcon(g, gd::RectF(cx - 6.0f * m_scale, centerY - 6.0f * m_scale, 12.0f * m_scale,
|
||
12.0f * m_scale),
|
||
color, collapsed ? IconDirection::RIGHT : IconDirection::DOWN);
|
||
}
|
||
|
||
// 分组复选框(三态:全选 / 部分 / 未选)。
|
||
const gd::RectF checkRect(baseX + kDisclosureWidth * m_scale, centerY - kCheckSize * m_scale * 0.5f,
|
||
kCheckSize * m_scale, kCheckSize * m_scale);
|
||
const bool allVisible = m_tab->FileAllVisible(item.fileIndex);
|
||
const bool anyVisible = m_tab->FileHasVisible(item.fileIndex);
|
||
UiDrawCheckBox(g, checkRect, allVisible ? 1 : (anyVisible ? 2 : 0), 3.0f * m_scale);
|
||
|
||
const gd::RectF closeRect = FileCloseRect(row);
|
||
|
||
// 分组标题:左侧为“组X”标签,右侧以绘制的竖线分隔分组名(不使用字符),再显示可重命名的名称。
|
||
const std::wstring groupLabel = L"组" + std::to_wstring(item.fileIndex + 1);
|
||
const std::wstring stats = std::to_wstring(file->signals.size()) + L" 项";
|
||
const float groupWidth = FileGroupLabelWidth(row);
|
||
const float statsWidth = UiMeasureTextWidth(m_fonts->uiSmall, stats);
|
||
const float statsRight = closeRect.X - 6.0f * m_scale;
|
||
const float nameLeft = checkRect.X + checkRect.Width + 8.0f * m_scale;
|
||
const float nameAreaLeft =
|
||
nameLeft + groupWidth + kGroupSeparatorGap * 2.0f * m_scale + kGroupSeparatorWidth * m_scale;
|
||
const float nameWidth =
|
||
std::max(20.0f, statsRight - statsWidth - 6.0f * m_scale - nameAreaLeft);
|
||
|
||
// 序号以强调色突出,便于在多组之间快速定位。
|
||
UiText(g, groupLabel, m_fonts->uiBold, gd::RectF(nameLeft, rect.Y, groupWidth, rect.Height),
|
||
m_theme->accent, TextAlign::LEFT);
|
||
|
||
// 竖线分隔符:以绘制方式实现,与文字基线无关,排版更稳。
|
||
UiFillRect(g, gd::RectF(nameLeft + groupWidth + kGroupSeparatorGap * m_scale,
|
||
rect.Y + 7.0f * m_scale, kGroupSeparatorWidth * m_scale,
|
||
rect.Height - 14.0f * m_scale),
|
||
WithAlpha(m_theme->borderStrong, 0xB0));
|
||
|
||
if (m_editField == StyleEditField::FILE_NAME && m_editRow == row)
|
||
{
|
||
UiDrawEditField(g, RowNameRect(row), m_edit, m_fonts->uiSmall, m_scale);
|
||
}
|
||
else
|
||
{
|
||
UiText(g, UiEllipsize(file->Title(), m_fonts->uiBold, nameWidth), m_fonts->uiBold,
|
||
gd::RectF(nameAreaLeft, rect.Y, nameWidth, rect.Height), m_theme->textStrong,
|
||
TextAlign::LEFT);
|
||
}
|
||
|
||
UiText(g, stats, m_fonts->uiSmall, gd::RectF(statsRight - statsWidth, rect.Y, statsWidth, rect.Height),
|
||
m_theme->textMuted, TextAlign::RIGHT);
|
||
|
||
// 关闭按钮(从工作区移除该文件)。
|
||
const bool closeHot = hovered && (m_hoverPart == RowPart::CLOSE);
|
||
if (closeHot)
|
||
{
|
||
UiFillRoundRect(g, closeRect, 3.0f * m_scale, m_theme->pressed);
|
||
}
|
||
UiDrawCrossIcon(g, closeRect, closeHot ? m_theme->danger : m_theme->textMuted, 1.5f * m_scale);
|
||
}
|
||
|
||
void SignalPanel::PaintSignalRow(gd::Graphics& g, int row)
|
||
{
|
||
if (m_dataSet == nullptr || m_tab == nullptr || row < 0 || row >= static_cast<int>(m_rows.size()))
|
||
{
|
||
return;
|
||
}
|
||
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
const SignalRef ref{item.fileIndex, item.signalIndex};
|
||
const SignalData* signal = m_dataSet->Resolve(ref);
|
||
const SignalStyle* style = StyleOf(ref);
|
||
if (signal == nullptr || style == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
const gd::RectF rect = RowRect(row);
|
||
const bool selected = (SelectedRef() == ref);
|
||
const bool hovered = (m_hoverRow == row);
|
||
|
||
if (selected)
|
||
{
|
||
UiFillRect(g, rect, m_theme->selection);
|
||
UiFillRect(g, gd::RectF(rect.X, rect.Y, 2.0f * m_scale, rect.Height), m_theme->accent);
|
||
}
|
||
else if (hovered)
|
||
{
|
||
UiFillRect(g, rect, m_theme->hover);
|
||
}
|
||
|
||
const float baseX = rect.X + kPadding * m_scale + kIndent * m_scale;
|
||
const float centerY = rect.Y + rect.Height * 0.5f;
|
||
|
||
// 复选框。
|
||
const gd::RectF checkRect(baseX + kDisclosureWidth * m_scale, centerY - kCheckSize * m_scale * 0.5f,
|
||
kCheckSize * m_scale, kCheckSize * m_scale);
|
||
// 可见性属于当前标签页,与全局共享的显示外观分开读取。
|
||
const bool visible = m_tab->IsVisible(ref);
|
||
UiDrawCheckBox(g, checkRect, visible ? 1 : 0, 3.0f * m_scale);
|
||
|
||
// 颜色块:叠加不透明度,透明度过低时自动补描边(与样式区色块规则一致)。
|
||
const gd::RectF swatchRect(checkRect.X + checkRect.Width + 6.0f * m_scale,
|
||
centerY - kSwatchSize * m_scale * 0.5f, kSwatchSize * m_scale,
|
||
kSwatchSize * m_scale);
|
||
UiDrawSwatch(g, swatchRect, style->color, visible ? style->opacity : 0.3f, 2.5f * m_scale,
|
||
m_scale);
|
||
|
||
// 网格徽标(可点击,用于调整所属网格)。
|
||
const int laneIndex = m_tab->LaneOfSignal(ref);
|
||
const bool badgeVisible = (laneIndex >= 0) && visible;
|
||
const gd::RectF badgeRect = SignalBadgeRect(row);
|
||
|
||
float nameRightLimit = rect.X + rect.Width - kPadding * m_scale;
|
||
if (badgeVisible)
|
||
{
|
||
nameRightLimit = badgeRect.X - 6.0f * m_scale;
|
||
}
|
||
|
||
// 名称:完全保留文件内的列名(含 "[n]" 序号与括号描述),双击可重命名。
|
||
const float nameLeft = swatchRect.X + swatchRect.Width + 6.0f * m_scale;
|
||
if (m_editField == StyleEditField::SIGNAL_NAME && m_editRow == row)
|
||
{
|
||
UiDrawEditField(g, RowNameRect(row), m_edit, m_fonts->ui, m_scale);
|
||
}
|
||
else
|
||
{
|
||
const float nameWidth = std::max(16.0f, nameRightLimit - nameLeft);
|
||
const std::uint32_t nameColor = visible ? m_theme->text : m_theme->textMuted;
|
||
UiText(g, UiEllipsize(signal->Title(), m_fonts->ui, nameWidth), m_fonts->ui,
|
||
gd::RectF(nameLeft, rect.Y, nameWidth, rect.Height), nameColor, TextAlign::LEFT);
|
||
}
|
||
|
||
if (badgeVisible)
|
||
{
|
||
const bool badgeHot = hovered && (m_hoverPart == RowPart::LANE_BADGE);
|
||
UiFillRoundRect(g, badgeRect, kBadgeHeight * m_scale * 0.5f,
|
||
badgeHot ? m_theme->accentSoft : m_theme->cardBg);
|
||
UiDrawRoundRect(g, badgeRect, kBadgeHeight * m_scale * 0.5f,
|
||
badgeHot ? m_theme->accent : m_theme->border, 1.0f);
|
||
UiText(g, L"G" + std::to_wstring(laneIndex + 1), m_fonts->monoSmall, badgeRect,
|
||
badgeHot ? m_theme->textStrong : m_theme->text, TextAlign::CENTER);
|
||
}
|
||
}
|
||
|
||
gd::RectF SignalPanel::ScrollThumbRect() const
|
||
{
|
||
if (!m_scrollBarVisible || m_contentHeight <= m_listRect.Height || m_listRect.Height <= 0.0f)
|
||
{
|
||
return gd::RectF();
|
||
}
|
||
|
||
const float ratio = std::min(1.0f, m_listRect.Height / m_contentHeight);
|
||
const float thumbHeight = std::max(24.0f * m_scale, m_scrollBarRect.Height * ratio);
|
||
const float maxScroll = m_contentHeight - m_listRect.Height;
|
||
const float progress = (maxScroll > 0.0f) ? (m_scrollOffset / maxScroll) : 0.0f;
|
||
const float thumbY = m_scrollBarRect.Y + progress * (m_scrollBarRect.Height - thumbHeight);
|
||
|
||
return gd::RectF(m_scrollBarRect.X, thumbY, m_scrollBarRect.Width, thumbHeight);
|
||
}
|
||
|
||
void SignalPanel::PaintScrollBar(gd::Graphics& g)
|
||
{
|
||
if (!m_scrollBarVisible || m_contentHeight <= m_listRect.Height)
|
||
{
|
||
return;
|
||
}
|
||
|
||
UiFillRoundRect(g, m_scrollBarRect, kScrollBarThickness * m_scale * 0.5f, m_theme->gridWeak);
|
||
UiFillRoundRect(g, ScrollThumbRect(), kScrollBarThickness * m_scale * 0.5f, m_theme->borderStrong);
|
||
}
|
||
|
||
void SignalPanel::PaintStyleSection(gd::Graphics& g)
|
||
{
|
||
if (m_styleRect.Height <= 0.0f)
|
||
{
|
||
return;
|
||
}
|
||
|
||
UiFillRect(g, m_styleRect, m_theme->panelBg);
|
||
|
||
const SignalStyle* style = (m_tab == nullptr) ? nullptr : StyleOf(SelectedRef());
|
||
if (style == nullptr || SelectedRef().IsValid() == false)
|
||
{
|
||
UiText(g, L"请选择信号以编辑样式", m_fonts->uiSmall, m_styleRect, m_theme->textMuted,
|
||
TextAlign::CENTER);
|
||
return;
|
||
}
|
||
|
||
const float labelWidth = kStyleLabelWidth * m_scale;
|
||
|
||
// 行标签统一以整行为基准垂直居中,确保与同行控件纵向对齐。
|
||
auto paintRowLabel = [&](int rowIndex, const wchar_t* text)
|
||
{
|
||
const gd::RectF& row = m_styleRowRects[static_cast<std::size_t>(rowIndex)];
|
||
UiText(g, text, m_fonts->uiSmall, gd::RectF(row.X, row.Y, labelWidth, row.Height),
|
||
m_theme->textMuted, TextAlign::LEFT);
|
||
};
|
||
|
||
// ---- 第一行:颜色(预设色块 + 自定义颜色入口)----
|
||
{
|
||
paintRowLabel(0, L"颜色");
|
||
|
||
int paletteCount = 0;
|
||
const std::uint32_t* palette = SignalPalette(paletteCount);
|
||
|
||
// 判定“当前是否在用自定义色”:必须同时满足
|
||
// 1) 显示颜色等于记忆的自定义色;
|
||
// 2) 该颜色不是任何一个可见的预设色。
|
||
// 否则一旦自定义色与某个预设色相同时,点击那个预设色块会把高亮错误地
|
||
// 挪到自定义色块上(用户报告的“点预设色直接跳到自定义色块”)。
|
||
bool presetMatches = false;
|
||
for (int index = 0; index < m_colorCount; ++index)
|
||
{
|
||
if (style->color == palette[index % paletteCount])
|
||
{
|
||
presetMatches = true;
|
||
break;
|
||
}
|
||
}
|
||
const bool customActive = (style->color == style->customColor) && !presetMatches;
|
||
for (int index = 0; index < m_colorCount; ++index)
|
||
{
|
||
const gd::RectF& rect = m_colorRects[static_cast<std::size_t>(index)];
|
||
const std::uint32_t color = palette[index % paletteCount];
|
||
const bool hovered = (m_hoverStyle == StyleHit::COLOR && m_hoverStyleIndex == index);
|
||
const bool active = !customActive && (style->color == color);
|
||
|
||
// 预设色块同样叠加不透明度;透明度过低时自动补描边以保证可辨识(与自定义色块一致)。
|
||
UiDrawSwatch(g, rect, color, style->opacity, kCorner * m_scale, m_scale);
|
||
if (active || hovered)
|
||
{
|
||
const gd::RectF ring(rect.X - 2.0f * m_scale, rect.Y - 2.0f * m_scale,
|
||
rect.Width + 4.0f * m_scale, rect.Height + 4.0f * m_scale);
|
||
UiDrawRoundRect(g, ring, 5.0f * m_scale,
|
||
active ? m_theme->textStrong : m_theme->borderStrong,
|
||
active ? 1.6f : 1.0f);
|
||
}
|
||
}
|
||
|
||
// 自定义颜色入口:与预设色块完全同尺寸、同外框规则的小方格,仅多一个加号图标。
|
||
// 方格始终显示记忆的自定义颜色,因此从任意预设色再次点击它都能立即回到上次的自定义色。
|
||
const bool chipHot = (m_hoverStyle == StyleHit::CUSTOM_CHIP);
|
||
const std::uint32_t chipColor =
|
||
UiDrawSwatch(g, m_customChipRect, style->customColor, style->opacity, kCorner * m_scale, m_scale);
|
||
const std::uint32_t iconColor = IsDarkColor(chipColor) ? 0xFFFDF6E3u : 0xFF073642u;
|
||
UiDrawPlusIcon(g, m_customChipRect, iconColor, 1.6f * m_scale);
|
||
|
||
// 当前正在使用自定义颜色、或鼠标悬停时,显示与预设色块一致的外框。
|
||
if (customActive || chipHot)
|
||
{
|
||
const gd::RectF& chip = m_customChipRect;
|
||
const gd::RectF ring(chip.X - 2.0f * m_scale, chip.Y - 2.0f * m_scale,
|
||
chip.Width + 4.0f * m_scale, chip.Height + 4.0f * m_scale);
|
||
UiDrawRoundRect(g, ring, 5.0f * m_scale,
|
||
customActive ? m_theme->textStrong : m_theme->borderStrong,
|
||
customActive ? 1.6f : 1.0f);
|
||
}
|
||
}
|
||
|
||
// ---- 第二行:样式(线段 / 散点 / 点线)----
|
||
{
|
||
paintRowLabel(1, L"样式");
|
||
|
||
for (int index = 0; index < kModeOptionCount; ++index)
|
||
{
|
||
const gd::RectF& rect = m_modeRects[static_cast<std::size_t>(index)];
|
||
const bool active = (style->mode == kModeOptions[index]);
|
||
const bool hovered = (m_hoverStyle == StyleHit::MODE && m_hoverStyleIndex == index);
|
||
|
||
UiFillRoundRect(g, rect, kCorner * m_scale,
|
||
active ? m_theme->accentSoft : (hovered ? m_theme->hover : m_theme->cardBg));
|
||
UiDrawRoundRect(g, rect, kCorner * m_scale, active ? m_theme->accent : m_theme->border, 1.0f);
|
||
UiText(g, DrawModeName(kModeOptions[index]), m_fonts->uiSmall, rect,
|
||
active ? m_theme->textStrong : m_theme->text, TextAlign::CENTER);
|
||
}
|
||
}
|
||
|
||
// ---- 第三行:透明度(数值可点击输入)----
|
||
{
|
||
paintRowLabel(2, L"透明度");
|
||
|
||
const bool active = m_draggingOpacity || (m_hoverStyle == StyleHit::OPACITY_SLIDER);
|
||
UiDrawSlider(g, m_opacityTrackRect, static_cast<double>(style->opacity), m_theme->accent, active,
|
||
m_scale);
|
||
|
||
if (m_editField == StyleEditField::OPACITY)
|
||
{
|
||
UiDrawEditField(g, m_opacityValueRect, m_edit, m_fonts->monoSmall, m_scale);
|
||
}
|
||
else
|
||
{
|
||
const int percent = static_cast<int>(style->opacity * 100.0f + 0.5f);
|
||
UiText(g, std::to_wstring(percent) + L"%", m_fonts->monoSmall, m_opacityValueRect,
|
||
m_theme->textStrong, TextAlign::RIGHT);
|
||
}
|
||
}
|
||
|
||
// ---- 第四行:线宽(与透明度行几何一致,数值可点击输入)----
|
||
{
|
||
paintRowLabel(3, L"线宽");
|
||
|
||
const double ratio =
|
||
(static_cast<double>(style->lineWidth) - kWidthMin) / (kWidthMax - kWidthMin);
|
||
const bool active = m_draggingWidth || (m_hoverStyle == StyleHit::WIDTH_SLIDER);
|
||
UiDrawSlider(g, m_widthTrackRect, ratio, m_theme->accent, active, m_scale);
|
||
|
||
if (m_editField == StyleEditField::WIDTH)
|
||
{
|
||
UiDrawEditField(g, m_widthValueRect, m_edit, m_fonts->monoSmall, m_scale);
|
||
}
|
||
else
|
||
{
|
||
const std::wstring numberText = FormatNumber(style->lineWidth, 1);
|
||
const std::wstring fullText = numberText + L" px";
|
||
// 空间不足时省略单位,保证数值本身完整可读。
|
||
const std::wstring shown =
|
||
(UiMeasureTextWidth(m_fonts->monoSmall, fullText) >
|
||
m_widthValueRect.Width - 6.0f * m_scale)
|
||
? numberText
|
||
: fullText;
|
||
UiText(g, shown, m_fonts->monoSmall, m_widthValueRect, m_theme->textStrong, TextAlign::RIGHT);
|
||
}
|
||
}
|
||
}
|
||
|
||
bool SignalPanel::AreAllSignalsVisible() const
|
||
{
|
||
if (m_dataSet == nullptr || m_tab == nullptr || m_dataSet->Empty())
|
||
{
|
||
return false;
|
||
}
|
||
return m_tab->VisibleCount() == TotalSignalCount();
|
||
}
|
||
|
||
bool SignalPanel::ApplyWidthFromX(float x)
|
||
{
|
||
if (m_tab == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
SignalStyle* style = StyleOf(SelectedRef());
|
||
if (style == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const double ratio = UiSliderRatioFromX(m_widthTrackRect, x);
|
||
float value = static_cast<float>(kWidthMin + ratio * (kWidthMax - kWidthMin));
|
||
value = std::round(value * 10.0f) / 10.0f;
|
||
value = ClampFloat(value, kWidthMin, kWidthMax);
|
||
if (std::fabs(value - style->lineWidth) < 0.001f)
|
||
{
|
||
return false;
|
||
}
|
||
style->lineWidth = value;
|
||
return true;
|
||
}
|
||
|
||
gd::RectF SignalPanel::RowNameRect(int row) const
|
||
{
|
||
if (m_dataSet == nullptr || m_tab == nullptr || row < 0 || row >= static_cast<int>(m_rows.size()))
|
||
{
|
||
return gd::RectF();
|
||
}
|
||
|
||
const gd::RectF rect = RowRect(row);
|
||
const bool isFile = (m_rows[static_cast<std::size_t>(row)].kind == RowKind::FILE);
|
||
const float baseX = rect.X + kPadding * m_scale + (isFile ? 0.0f : kIndent * m_scale);
|
||
const float checkRight = baseX + kDisclosureWidth * m_scale + kCheckSize * m_scale;
|
||
|
||
float left = 0.0f;
|
||
float right = 0.0f;
|
||
if (isFile)
|
||
{
|
||
// 分组名需要跳过左侧的“组X”标签与分隔线。
|
||
left = checkRight + 8.0f * m_scale + FileGroupLabelWidth(row) + kGroupSeparatorGap * 2.0f * m_scale +
|
||
kGroupSeparatorWidth * m_scale;
|
||
right = FileCloseRect(row).X - 6.0f * m_scale;
|
||
}
|
||
else
|
||
{
|
||
left = checkRight + 6.0f * m_scale + kSwatchSize * m_scale + 6.0f * m_scale;
|
||
right = SignalBadgeRect(row).X - 6.0f * m_scale;
|
||
}
|
||
|
||
if (right <= left)
|
||
{
|
||
return gd::RectF();
|
||
}
|
||
return gd::RectF(left, rect.Y + 3.0f * m_scale, right - left, rect.Height - 6.0f * m_scale);
|
||
}
|
||
|
||
float SignalPanel::FileGroupLabelWidth(int row) const
|
||
{
|
||
if (m_fonts == nullptr || m_fonts->uiBold == nullptr || row < 0 ||
|
||
row >= static_cast<int>(m_rows.size()))
|
||
{
|
||
return 0.0f;
|
||
}
|
||
const std::wstring label = L"组" + std::to_wstring(m_rows[static_cast<std::size_t>(row)].fileIndex + 1);
|
||
return UiMeasureTextWidth(m_fonts->uiBold, label);
|
||
}
|
||
|
||
bool SignalPanel::BeginEdit(StyleEditField field, int row)
|
||
{
|
||
if (m_tab == nullptr || field == StyleEditField::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
if (m_editField == field && m_editRow == row)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
std::wstring initial;
|
||
switch (field)
|
||
{
|
||
case StyleEditField::WIDTH:
|
||
{
|
||
const SignalStyle* style = StyleOf(SelectedRef());
|
||
if (style == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
initial = FormatNumber(style->lineWidth, 1);
|
||
break;
|
||
}
|
||
case StyleEditField::OPACITY:
|
||
{
|
||
const SignalStyle* style = StyleOf(SelectedRef());
|
||
if (style == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
initial = std::to_wstring(static_cast<int>(style->opacity * 100.0f + 0.5f));
|
||
break;
|
||
}
|
||
case StyleEditField::SIGNAL_NAME:
|
||
{
|
||
if (row < 0 || row >= static_cast<int>(m_rows.size()))
|
||
{
|
||
return false;
|
||
}
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
const SignalData* signal = m_dataSet->Resolve(SignalRef{item.fileIndex, item.signalIndex});
|
||
if (signal == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
initial = signal->Title();
|
||
break;
|
||
}
|
||
case StyleEditField::FILE_NAME:
|
||
{
|
||
if (row < 0 || row >= static_cast<int>(m_rows.size()))
|
||
{
|
||
return false;
|
||
}
|
||
const DataFile* file = m_dataSet->FileAt(m_rows[static_cast<std::size_t>(row)].fileIndex);
|
||
if (file == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
initial = file->Title();
|
||
break;
|
||
}
|
||
default:
|
||
return false;
|
||
}
|
||
|
||
m_editField = field;
|
||
m_editRow = row;
|
||
|
||
// 名称类字段可输入任意字符,数值类字段限制为数字与小数点。
|
||
const bool nameField =
|
||
(field == StyleEditField::SIGNAL_NAME) || (field == StyleEditField::FILE_NAME);
|
||
// 不限长度:名称与数值都由各自的提交逻辑处理超长内容。
|
||
m_edit.Begin(std::move(initial), true, nameField ? EditFilter::ANY : EditFilter::NUMBER, 0u);
|
||
return true;
|
||
}
|
||
|
||
bool SignalPanel::EndEdit(bool commit)
|
||
{
|
||
if (m_editField == StyleEditField::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const StyleEditField field = m_editField;
|
||
const int row = m_editRow;
|
||
const std::wstring text = m_edit.Text();
|
||
|
||
m_editField = StyleEditField::NONE;
|
||
m_editRow = -1;
|
||
m_edit.End();
|
||
|
||
if (!commit || m_tab == nullptr || m_dataSet == nullptr)
|
||
{
|
||
return true;
|
||
}
|
||
|
||
const std::wstring trimmed = Trim(text);
|
||
switch (field)
|
||
{
|
||
case StyleEditField::WIDTH:
|
||
{
|
||
if (trimmed.empty())
|
||
{
|
||
break;
|
||
}
|
||
wchar_t* stop = nullptr;
|
||
const double parsed = std::wcstod(trimmed.c_str(), &stop);
|
||
if (stop == trimmed.c_str() || parsed != parsed)
|
||
{
|
||
break;
|
||
}
|
||
if (SignalStyle* style = StyleOf(SelectedRef()))
|
||
{
|
||
const float value = ClampFloat(static_cast<float>(parsed), kWidthMin, kWidthMax);
|
||
style->lineWidth = std::round(value * 10.0f) / 10.0f;
|
||
}
|
||
break;
|
||
}
|
||
case StyleEditField::OPACITY:
|
||
{
|
||
if (trimmed.empty())
|
||
{
|
||
break;
|
||
}
|
||
wchar_t* stop = nullptr;
|
||
const double parsed = std::wcstod(trimmed.c_str(), &stop);
|
||
if (stop == trimmed.c_str() || parsed != parsed)
|
||
{
|
||
break;
|
||
}
|
||
if (SignalStyle* style = StyleOf(SelectedRef()))
|
||
{
|
||
style->opacity = ClampFloat(static_cast<float>(parsed) / 100.0f, 0.0f, 1.0f);
|
||
}
|
||
break;
|
||
}
|
||
case StyleEditField::SIGNAL_NAME:
|
||
{
|
||
if (row < 0 || row >= static_cast<int>(m_rows.size()) || m_dataSetWritable == nullptr)
|
||
{
|
||
break;
|
||
}
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
m_dataSetWritable->SetSignalDisplayName(item.fileIndex, item.signalIndex, trimmed);
|
||
break;
|
||
}
|
||
case StyleEditField::FILE_NAME:
|
||
{
|
||
if (row < 0 || row >= static_cast<int>(m_rows.size()) || m_dataSetWritable == nullptr)
|
||
{
|
||
break;
|
||
}
|
||
m_dataSetWritable->SetFileDisplayName(m_rows[static_cast<std::size_t>(row)].fileIndex, trimmed);
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
gd::RectF SignalPanel::FilterFieldRect() const
|
||
{
|
||
// 输入框内容区:左右与上下使用**同一内缩**,避免编辑态出现"左右空隙明显更大"的观感;
|
||
// 占位提示与显示文本也用同一内缩,因此进入/退出编辑时文字不会跳动。
|
||
const float inset = kFilterTextPad * m_scale;
|
||
return gd::RectF(m_filterRect.X + inset, m_filterRect.Y + inset,
|
||
std::max(8.0f, m_filterRect.Width - inset * 2.0f),
|
||
std::max(8.0f, m_filterRect.Height - inset * 2.0f));
|
||
}
|
||
|
||
gd::RectF SignalPanel::FilterClearRect() const
|
||
{
|
||
if (m_filterText.empty())
|
||
{
|
||
return gd::RectF();
|
||
}
|
||
const float size = std::max(12.0f, m_filterRect.Height - kFilterTextPad * 2.0f * m_scale);
|
||
const float right = m_filterRect.X + m_filterRect.Width - kFilterTextPad * m_scale;
|
||
return gd::RectF(right - size, m_filterRect.Y + (m_filterRect.Height - size) * 0.5f, size, size);
|
||
}
|
||
|
||
gd::RectF SignalPanel::EditFieldRect() const
|
||
{
|
||
switch (m_editField)
|
||
{
|
||
case StyleEditField::WIDTH:
|
||
return m_widthValueRect;
|
||
case StyleEditField::OPACITY:
|
||
return m_opacityValueRect;
|
||
case StyleEditField::SIGNAL_NAME:
|
||
case StyleEditField::FILE_NAME:
|
||
return RowNameRect(m_editRow);
|
||
case StyleEditField::NONE:
|
||
default:
|
||
return gd::RectF();
|
||
}
|
||
}
|
||
|
||
bool SignalPanel::OnEditChar(wchar_t character)
|
||
{
|
||
// 「筛选信号」输入框:字符实时进入筛选(无需回车即可看到结果变化)。
|
||
if (m_filterEditing)
|
||
{
|
||
switch (character)
|
||
{
|
||
case 0x03: // Ctrl+C
|
||
m_filterEdit.CopyToClipboard(m_host);
|
||
return false;
|
||
case 0x18: // Ctrl+X
|
||
m_filterEdit.CutToClipboard(m_host);
|
||
ApplyFilterText(m_filterEdit.Text());
|
||
return true;
|
||
case 0x16: // Ctrl+V
|
||
m_filterEdit.PasteFromClipboard(m_host);
|
||
ApplyFilterText(m_filterEdit.Text());
|
||
return true;
|
||
case 0x01: // Ctrl+A
|
||
m_filterEdit.SelectAll();
|
||
return true;
|
||
default:
|
||
break;
|
||
}
|
||
if (character == L'\r' || character == L'\n')
|
||
{
|
||
return EndFilterEdit();
|
||
}
|
||
// 退格/删除已由 WM_KEYDOWN 的 OnEditKey 处理,运里忽略控制字符避免重复删除。
|
||
if (character < 0x20 || character == 0x7F)
|
||
{
|
||
return false;
|
||
}
|
||
if (!m_filterEdit.Insert(character))
|
||
{
|
||
return false;
|
||
}
|
||
ApplyFilterText(m_filterEdit.Text());
|
||
return true;
|
||
}
|
||
|
||
if (m_editField == StyleEditField::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// 剪贴板与全选快捷键经 WM_CHAR 送达(Ctrl+C/X/V/A 分别对应 3/24/22/1)。
|
||
switch (character)
|
||
{
|
||
case 0x03: // Ctrl+C
|
||
m_edit.CopyToClipboard(m_host);
|
||
return false;
|
||
case 0x18: // Ctrl+X
|
||
return m_edit.CutToClipboard(m_host);
|
||
case 0x16: // Ctrl+V
|
||
return m_edit.PasteFromClipboard(m_host);
|
||
case 0x01: // Ctrl+A
|
||
m_edit.SelectAll();
|
||
return true;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
if (character == L'\r' || character == L'\n')
|
||
{
|
||
return EndEdit(true);
|
||
}
|
||
// 退格/删除已由 WM_KEYDOWN 的 OnEditKey 处理:这里必须忽略控制字符,
|
||
// 否则同一次按键会被处理两次(一次删除两个字符)。
|
||
if (character < 0x20 || character == 0x7F)
|
||
{
|
||
return false;
|
||
}
|
||
// 百分比字段允许直接输入 % 但会被忽略,其余控制字符一律丢弃。
|
||
if (m_editField == StyleEditField::OPACITY && character == L'%')
|
||
{
|
||
return false;
|
||
}
|
||
return m_edit.Insert(character);
|
||
}
|
||
|
||
bool SignalPanel::OnEditKey(WPARAM key)
|
||
{
|
||
// 「筛选信号」输入框的键盘处理(回车结束编辑,Esc 清空并结束)。
|
||
if (m_filterEditing)
|
||
{
|
||
const bool shift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
|
||
const bool control = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
|
||
switch (key)
|
||
{
|
||
case VK_RETURN:
|
||
return EndFilterEdit();
|
||
case VK_ESCAPE:
|
||
{
|
||
const bool changed = m_filterEdit.Text() != m_filterText;
|
||
EndFilterEdit();
|
||
return changed;
|
||
}
|
||
case VK_BACK:
|
||
{
|
||
if (!m_filterEdit.Backspace())
|
||
{
|
||
return false;
|
||
}
|
||
ApplyFilterText(m_filterEdit.Text());
|
||
return true;
|
||
}
|
||
case VK_DELETE:
|
||
{
|
||
if (!m_filterEdit.DeleteForward())
|
||
{
|
||
return false;
|
||
}
|
||
ApplyFilterText(m_filterEdit.Text());
|
||
return true;
|
||
}
|
||
case VK_LEFT:
|
||
return m_filterEdit.MoveCaret(-1, shift);
|
||
case VK_RIGHT:
|
||
return m_filterEdit.MoveCaret(1, shift);
|
||
case VK_HOME:
|
||
return m_filterEdit.MoveHome(shift);
|
||
case VK_END:
|
||
return m_filterEdit.MoveEnd(shift);
|
||
case 'A':
|
||
if (control)
|
||
{
|
||
m_filterEdit.SelectAll();
|
||
return true;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
if (m_editField == StyleEditField::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const bool shift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
|
||
const bool control = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
|
||
|
||
switch (key)
|
||
{
|
||
case VK_RETURN:
|
||
return EndEdit(true);
|
||
case VK_ESCAPE:
|
||
return EndEdit(false);
|
||
case VK_BACK:
|
||
return m_edit.Backspace();
|
||
case VK_DELETE:
|
||
return m_edit.DeleteForward();
|
||
case VK_LEFT:
|
||
return m_edit.MoveCaret(-1, shift);
|
||
case VK_RIGHT:
|
||
return m_edit.MoveCaret(1, shift);
|
||
case VK_HOME:
|
||
return m_edit.MoveHome(shift);
|
||
case VK_END:
|
||
return m_edit.MoveEnd(shift);
|
||
case 'A':
|
||
if (control)
|
||
{
|
||
m_edit.SelectAll();
|
||
return true;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool SignalPanel::CollapseEditSelectionToEnd()
|
||
{
|
||
if (m_filterEditing)
|
||
{
|
||
return m_filterEdit.DeselectToEnd();
|
||
}
|
||
if (m_editField == StyleEditField::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
return m_edit.DeselectToEnd();
|
||
}
|
||
|
||
bool SignalPanel::OnEditMouseDown(int x, int y)
|
||
{
|
||
if (m_filterEditing)
|
||
{
|
||
// 编辑态下 ✕ 位于输入框内容区之内,必须优先于插入符定位处理,
|
||
// 否则点击会被当成"把光标移到此处"而清空不了内容。
|
||
const gd::RectF clearRect = FilterClearRect();
|
||
if (clearRect.Width > 0.0f &&
|
||
UiPointInRect(clearRect, static_cast<float>(x), static_cast<float>(y)))
|
||
{
|
||
ClearFilter();
|
||
return true;
|
||
}
|
||
return UiEditFieldMouseDown(m_fonts->uiSmall, FilterFieldRect(), m_filterEdit, m_scale, x, y);
|
||
}
|
||
if (m_editField == StyleEditField::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
return UiEditFieldMouseDown(m_fonts->ui, EditFieldRect(), m_edit, m_scale, x, y);
|
||
}
|
||
|
||
bool SignalPanel::OnEditMouseMove(int x)
|
||
{
|
||
if (m_filterEditing)
|
||
{
|
||
return UiEditFieldMouseMove(m_fonts->uiSmall, FilterFieldRect(), m_filterEdit, m_scale, x);
|
||
}
|
||
if (m_editField == StyleEditField::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
return UiEditFieldMouseMove(m_fonts->ui, EditFieldRect(), m_edit, m_scale, x);
|
||
}
|
||
|
||
bool SignalPanel::OnEditMouseUp()
|
||
{
|
||
if (m_filterEditing)
|
||
{
|
||
if (!m_filterEdit.Dragging())
|
||
{
|
||
return false;
|
||
}
|
||
m_filterEdit.EndDrag();
|
||
return true;
|
||
}
|
||
if (!m_edit.Dragging())
|
||
{
|
||
return false;
|
||
}
|
||
m_edit.EndDrag();
|
||
return true;
|
||
}
|
||
|
||
const SignalStyle* SignalPanel::StyleOf(const SignalRef& ref) const
|
||
{
|
||
return (m_dataSet != nullptr) ? m_dataSet->Style(ref) : nullptr;
|
||
}
|
||
|
||
SignalStyle* SignalPanel::StyleOf(const SignalRef& ref)
|
||
{
|
||
return (m_dataSetWritable != nullptr) ? m_dataSetWritable->Style(ref) : nullptr;
|
||
}
|
||
|
||
const SignalRef& SignalPanel::SelectedRef() const
|
||
{
|
||
static const SignalRef fallback;
|
||
return (m_dataSet != nullptr) ? m_dataSet->Selected() : fallback;
|
||
}
|
||
|
||
void SignalPanel::SelectSignal(const SignalRef& ref)
|
||
{
|
||
if (m_dataSetWritable != nullptr)
|
||
{
|
||
m_dataSetWritable->SetSelected(ref);
|
||
}
|
||
}
|
||
|
||
bool SignalPanel::ApplyColor(std::uint32_t color)
|
||
{
|
||
if (m_tab == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
SignalStyle* style = StyleOf(SelectedRef());
|
||
if (style == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// 同时记住最后一次自定义取值,便于切换到预设色后一键回到该颜色。
|
||
const bool changed = (style->color != color) || (style->customColor != color);
|
||
style->color = color;
|
||
style->customColor = color;
|
||
return changed;
|
||
}
|
||
|
||
bool SignalPanel::ApplyOpacityFromX(float x)
|
||
{
|
||
if (m_tab == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
SignalStyle* style = StyleOf(SelectedRef());
|
||
if (style == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const float value = static_cast<float>(UiSliderRatioFromX(m_opacityTrackRect, x));
|
||
if (std::fabs(value - style->opacity) < 0.005f)
|
||
{
|
||
return false;
|
||
}
|
||
style->opacity = value;
|
||
return true;
|
||
}
|
||
|
||
bool SignalPanel::OpenColorPickerPopup(const SignalStyle& style)
|
||
{
|
||
if (m_colorPicker == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const gd::RectF bounds = (m_clientBounds.Width > 1.0f) ? m_clientBounds : m_area;
|
||
// 以记忆的自定义颜色作为初始取值,实现“再次打开即恢复上次取色”。
|
||
m_colorPicker->Open(bounds, m_customChipRect, style.customColor);
|
||
return true;
|
||
}
|
||
|
||
bool SignalPanel::CloseTransientUi()
|
||
{
|
||
bool changed = false;
|
||
if (m_editField != StyleEditField::NONE)
|
||
{
|
||
changed = EndEdit(true) || changed;
|
||
}
|
||
// 点击面板之外也要结束「筛选信号」的编辑状态。
|
||
if (m_filterEditing)
|
||
{
|
||
changed = EndFilterEdit() || changed;
|
||
}
|
||
if (m_colorPicker != nullptr && m_colorPicker->IsOpen())
|
||
{
|
||
m_colorPicker->Close();
|
||
changed = true;
|
||
}
|
||
return changed;
|
||
}
|
||
|
||
bool SignalPanel::OnMouseMove(int x, int y)
|
||
{
|
||
// 拖拽优先级最高。
|
||
if (m_draggingOpacity)
|
||
{
|
||
return ApplyOpacityFromX(static_cast<float>(x));
|
||
}
|
||
if (m_draggingWidth)
|
||
{
|
||
return ApplyWidthFromX(static_cast<float>(x));
|
||
}
|
||
if (m_draggingScrollBar)
|
||
{
|
||
const gd::RectF thumb = ScrollThumbRect();
|
||
const float travel = static_cast<float>(y - m_scrollGrabOffset) - m_scrollBarRect.Y;
|
||
const float usable = m_scrollBarRect.Height - thumb.Height;
|
||
if (usable > 0.0f)
|
||
{
|
||
const float progress = std::max(0.0f, std::min(1.0f, travel / usable));
|
||
m_scrollOffset = progress * (m_contentHeight - m_listRect.Height);
|
||
ClampScroll();
|
||
}
|
||
return true;
|
||
}
|
||
|
||
RowPart part = RowPart::NONE;
|
||
const int hoverRow = HitRow(x, y, part);
|
||
|
||
StyleHit hoverStyle = StyleHit::NONE;
|
||
int hoverStyleIndex = -1;
|
||
|
||
const float fx = static_cast<float>(x);
|
||
const float fy = static_cast<float>(y);
|
||
|
||
if (UiPointInRect(m_toggleAllRect, fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::TOGGLE_ALL;
|
||
}
|
||
else if (UiPointInRect(FilterClearRect(), fx, fy))
|
||
{
|
||
// 筛选框右侧的清空 ✕(仅在筛选框有内容时存在)。
|
||
hoverStyle = StyleHit::FILTER_CLEAR;
|
||
}
|
||
else if (m_tab != nullptr && StyleOf(SelectedRef()) != nullptr)
|
||
{
|
||
for (int index = 0; index < m_colorCount; ++index)
|
||
{
|
||
if (UiPointInRect(m_colorRects[static_cast<std::size_t>(index)], fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::COLOR;
|
||
hoverStyleIndex = index;
|
||
break;
|
||
}
|
||
}
|
||
if (hoverStyle == StyleHit::NONE && UiPointInRect(m_customChipRect, fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::CUSTOM_CHIP;
|
||
}
|
||
if (hoverStyle == StyleHit::NONE)
|
||
{
|
||
for (int index = 0; index < kModeOptionCount; ++index)
|
||
{
|
||
if (UiPointInRect(m_modeRects[static_cast<std::size_t>(index)], fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::MODE;
|
||
hoverStyleIndex = index;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (hoverStyle == StyleHit::NONE &&
|
||
UiPointInRect(SliderHitRect(m_opacityTrackRect, m_scale), fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::OPACITY_SLIDER;
|
||
}
|
||
if (hoverStyle == StyleHit::NONE &&
|
||
UiPointInRect(SliderHitRect(m_widthTrackRect, m_scale), fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::WIDTH_SLIDER;
|
||
}
|
||
if (hoverStyle == StyleHit::NONE && UiPointInRect(m_opacityValueRect, fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::OPACITY_VALUE;
|
||
}
|
||
if (hoverStyle == StyleHit::NONE && UiPointInRect(m_widthValueRect, fx, fy))
|
||
{
|
||
hoverStyle = StyleHit::WIDTH_VALUE;
|
||
}
|
||
}
|
||
|
||
if (hoverRow == m_hoverRow && hoverStyle == m_hoverStyle && hoverStyleIndex == m_hoverStyleIndex &&
|
||
part == m_hoverPart)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
m_hoverRow = hoverRow;
|
||
m_hoverPart = part;
|
||
m_hoverStyle = hoverStyle;
|
||
m_hoverStyleIndex = hoverStyleIndex;
|
||
return true;
|
||
}
|
||
|
||
bool SignalPanel::OnLButtonDown(int x, int y)
|
||
{
|
||
if (m_dataSet == nullptr || m_tab == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const float fx = static_cast<float>(x);
|
||
const float fy = static_cast<float>(y);
|
||
|
||
// 「筛选信号」输入框:单击进入编辑;点击其它位置则先结束筛选编辑(文本已实时生效)。
|
||
if (IsOnFilterBox(x, y))
|
||
{
|
||
// 右侧 ✕:清空筛选内容(不退出编辑态,便于继续输入)。
|
||
if (UiPointInRect(FilterClearRect(), fx, fy))
|
||
{
|
||
ClearFilter();
|
||
return true;
|
||
}
|
||
BeginFilterEdit();
|
||
return true;
|
||
}
|
||
if (m_filterEditing)
|
||
{
|
||
// 文本已实时生效,这里只需收起编辑态,随后继续处理本次点击。
|
||
EndFilterEdit();
|
||
}
|
||
|
||
// 滚动条拖拽优先于其它命中测试。
|
||
if (m_scrollBarVisible && UiPointInRect(m_scrollBarRect, fx, fy))
|
||
{
|
||
const gd::RectF thumb = ScrollThumbRect();
|
||
m_draggingScrollBar = true;
|
||
if (UiPointInRect(thumb, fx, fy))
|
||
{
|
||
m_scrollGrabOffset = y - static_cast<int>(thumb.Y);
|
||
}
|
||
else
|
||
{
|
||
m_scrollGrabOffset = static_cast<int>(thumb.Height * 0.5f);
|
||
const float travel = fy - m_scrollBarRect.Y - static_cast<float>(m_scrollGrabOffset);
|
||
const float usable = m_scrollBarRect.Height - thumb.Height;
|
||
if (usable > 0.0f)
|
||
{
|
||
const float progress = std::max(0.0f, std::min(1.0f, travel / usable));
|
||
m_scrollOffset = progress * (m_contentHeight - m_listRect.Height);
|
||
ClampScroll();
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
m_pendingLaneMenu = false;
|
||
m_pendingColorPicker = false;
|
||
|
||
// 点击当前输入框以外的位置时提交输入。
|
||
if (m_editField != StyleEditField::NONE &&
|
||
!UiPointInRect(EditFieldRect(), fx, fy))
|
||
{
|
||
EndEdit(true);
|
||
}
|
||
|
||
// 全部显示/隐藏。
|
||
if (UiPointInRect(m_toggleAllRect, fx, fy))
|
||
{
|
||
m_tab->SetAllVisible(!AreAllSignalsVisible());
|
||
m_rowsDirty = true;
|
||
return true;
|
||
}
|
||
|
||
// 样式编辑区。
|
||
if (SignalStyle* style = StyleOf(SelectedRef()))
|
||
{
|
||
int paletteCount = 0;
|
||
const std::uint32_t* palette = SignalPalette(paletteCount);
|
||
for (int index = 0; index < m_colorCount; ++index)
|
||
{
|
||
if (UiPointInRect(m_colorRects[static_cast<std::size_t>(index)], fx, fy))
|
||
{
|
||
style->color = palette[index % paletteCount];
|
||
return true;
|
||
}
|
||
}
|
||
if (UiPointInRect(m_customChipRect, fx, fy))
|
||
{
|
||
// 先恢复到记忆的自定义颜色(即便随后收起浮窗也会生效),再在抬起时展开浮窗。
|
||
style->color = style->customColor;
|
||
m_pendingColorPicker = true;
|
||
return true;
|
||
}
|
||
for (int index = 0; index < kModeOptionCount; ++index)
|
||
{
|
||
if (UiPointInRect(m_modeRects[static_cast<std::size_t>(index)], fx, fy))
|
||
{
|
||
style->mode = kModeOptions[index];
|
||
return true;
|
||
}
|
||
}
|
||
if (UiPointInRect(SliderHitRect(m_opacityTrackRect, m_scale), fx, fy))
|
||
{
|
||
m_draggingOpacity = true;
|
||
ApplyOpacityFromX(fx);
|
||
return true;
|
||
}
|
||
if (UiPointInRect(SliderHitRect(m_widthTrackRect, m_scale), fx, fy))
|
||
{
|
||
m_draggingWidth = true;
|
||
ApplyWidthFromX(fx);
|
||
return true;
|
||
}
|
||
// 数值框的命中优先于滑块:两者几何重叠时要能进入输入状态。
|
||
if (UiPointInRect(m_widthValueRect, fx, fy))
|
||
{
|
||
return BeginEdit(StyleEditField::WIDTH);
|
||
}
|
||
if (UiPointInRect(m_opacityValueRect, fx, fy))
|
||
{
|
||
return BeginEdit(StyleEditField::OPACITY);
|
||
}
|
||
}
|
||
|
||
// 列表行。
|
||
RowPart part = RowPart::NONE;
|
||
const int row = HitRow(x, y, part);
|
||
if (row < 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
|
||
if (item.kind == RowKind::FILE)
|
||
{
|
||
if (part == RowPart::CHECK)
|
||
{
|
||
const bool allVisible = m_tab->FileAllVisible(item.fileIndex);
|
||
m_tab->SetFileVisible(item.fileIndex, !allVisible);
|
||
m_rowsDirty = true;
|
||
return true;
|
||
}
|
||
if (part == RowPart::CLOSE)
|
||
{
|
||
// 关闭文件属于数据层操作,交由宿主窗口处理。
|
||
if (m_host != nullptr)
|
||
{
|
||
PostMessageW(m_host, WM_APP + 1, static_cast<WPARAM>(item.fileIndex), 0);
|
||
}
|
||
return true;
|
||
}
|
||
m_tab->ToggleCollapsed(item.fileIndex);
|
||
m_rowsDirty = true;
|
||
return true;
|
||
}
|
||
|
||
const SignalRef ref{item.fileIndex, item.signalIndex};
|
||
SelectSignal(ref);
|
||
|
||
if (part == RowPart::CHECK)
|
||
{
|
||
// 勾选/取消勾选会立即触发网格重新划分(取消后空网格随之消失)。
|
||
m_tab->ToggleVisible(ref);
|
||
m_rowsDirty = true;
|
||
}
|
||
else if (part == RowPart::LANE_BADGE)
|
||
{
|
||
// 在左键抬起时弹出,保证菜单不会随着按键松开而消失。
|
||
m_pendingLaneMenu = true;
|
||
m_pendingLaneRef = ref;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool SignalPanel::OnLButtonUp(int x, int y)
|
||
{
|
||
bool changed = false;
|
||
|
||
if (m_draggingOpacity)
|
||
{
|
||
m_draggingOpacity = false;
|
||
changed = true;
|
||
}
|
||
if (m_draggingWidth)
|
||
{
|
||
m_draggingWidth = false;
|
||
changed = true;
|
||
}
|
||
if (m_draggingScrollBar)
|
||
{
|
||
m_draggingScrollBar = false;
|
||
changed = true;
|
||
}
|
||
|
||
if (m_pendingColorPicker)
|
||
{
|
||
m_pendingColorPicker = false;
|
||
const float fx = static_cast<float>(x);
|
||
const float fy = static_cast<float>(y);
|
||
if (UiPointInRect(m_customChipRect, fx, fy) && m_tab != nullptr)
|
||
{
|
||
if (const SignalStyle* style = StyleOf(SelectedRef()))
|
||
{
|
||
changed = OpenColorPickerPopup(*style) || changed;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (m_pendingLaneMenu)
|
||
{
|
||
m_pendingLaneMenu = false;
|
||
RowPart part = RowPart::NONE;
|
||
const int row = HitRow(x, y, part);
|
||
if (row >= 0 && part == RowPart::LANE_BADGE)
|
||
{
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
const SignalRef ref{item.fileIndex, item.signalIndex};
|
||
if (ref == m_pendingLaneRef)
|
||
{
|
||
const gd::RectF badge = SignalBadgeRect(row);
|
||
OpenLaneMenu(ref, static_cast<int>(badge.X),
|
||
static_cast<int>(badge.Y + badge.Height));
|
||
changed = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
return changed;
|
||
}
|
||
|
||
bool SignalPanel::OnDoubleClick(int x, int y)
|
||
{
|
||
if (m_dataSet == nullptr || m_tab == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const float fx = static_cast<float>(x);
|
||
const float fy = static_cast<float>(y);
|
||
|
||
// 样式区数值框:双击进入(或保持)输入状态。
|
||
if (UiPointInRect(m_widthValueRect, fx, fy))
|
||
{
|
||
return BeginEdit(StyleEditField::WIDTH);
|
||
}
|
||
if (UiPointInRect(m_opacityValueRect, fx, fy))
|
||
{
|
||
return BeginEdit(StyleEditField::OPACITY);
|
||
}
|
||
|
||
RowPart part = RowPart::NONE;
|
||
const int row = HitRow(x, y, part);
|
||
if (row < 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
|
||
// 分组行:双击折叠三角用于折叠,双击名称区域进入重命名。
|
||
if (item.kind == RowKind::FILE)
|
||
{
|
||
if (part == RowPart::DISCLOSURE)
|
||
{
|
||
m_tab->ToggleCollapsed(item.fileIndex);
|
||
m_rowsDirty = true;
|
||
return true;
|
||
}
|
||
if (part != RowPart::BODY)
|
||
{
|
||
return false;
|
||
}
|
||
// 重命名分组会改变列表行高度以外的展示内容,重建行缓存以保证文字刷新。
|
||
m_rowsDirty = true;
|
||
return BeginEdit(StyleEditField::FILE_NAME, row);
|
||
}
|
||
|
||
// 复选框与网格徽标各自由单击处理,双击不再切换可见性。
|
||
if (part == RowPart::CHECK || part == RowPart::LANE_BADGE)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const SignalRef ref{item.fileIndex, item.signalIndex};
|
||
SelectSignal(ref);
|
||
m_rowsDirty = true;
|
||
return BeginEdit(StyleEditField::SIGNAL_NAME, row);
|
||
}
|
||
|
||
bool SignalPanel::OnRButtonDown(int x, int y)
|
||
{
|
||
if (m_dataSet == nullptr || m_tab == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
RowPart part = RowPart::NONE;
|
||
const int row = HitRow(x, y, part);
|
||
if (row < 0)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const ListRow& item = m_rows[static_cast<std::size_t>(row)];
|
||
if (item.kind == RowKind::FILE)
|
||
{
|
||
OpenFileMenu(item.fileIndex, x, y);
|
||
return true;
|
||
}
|
||
|
||
const SignalRef ref{item.fileIndex, item.signalIndex};
|
||
SelectSignal(ref);
|
||
OpenSignalMenu(ref, x, y);
|
||
return true;
|
||
}
|
||
|
||
bool SignalPanel::OnMouseWheel(int delta)
|
||
{
|
||
if (m_dataSet == nullptr)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
const float previous = m_scrollOffset;
|
||
m_scrollOffset -= static_cast<float>(delta) / 120.0f * 54.0f * m_scale;
|
||
ClampScroll();
|
||
return std::fabs(previous - m_scrollOffset) > 0.01f;
|
||
}
|
||
|
||
bool SignalPanel::OnMouseLeave()
|
||
{
|
||
if (m_hoverRow < 0 && m_hoverStyle == StyleHit::NONE)
|
||
{
|
||
return false;
|
||
}
|
||
m_hoverRow = -1;
|
||
m_hoverPart = RowPart::NONE;
|
||
m_hoverStyle = StyleHit::NONE;
|
||
m_hoverStyleIndex = -1;
|
||
return true;
|
||
}
|
||
|
||
void SignalPanel::OpenSignalMenu(const SignalRef& ref, int x, int y)
|
||
{
|
||
if (m_menu == nullptr || m_tab == nullptr || m_dataSet == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
const SignalStyle* style = StyleOf(ref);
|
||
const SignalData* signal = m_dataSet->Resolve(ref);
|
||
if (style == nullptr || signal == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_menuTargetSignal = ref;
|
||
m_menuTargetFile = -1;
|
||
|
||
std::vector<MenuItem> items;
|
||
|
||
MenuItem header;
|
||
header.kind = MenuItemKind::HEADER;
|
||
header.label = signal->Title();
|
||
items.push_back(header);
|
||
|
||
MenuItem toggle;
|
||
toggle.label = m_tab->IsVisible(ref) ? L"隐藏该信号" : L"显示该信号";
|
||
toggle.id = CMD_SIGNAL_TOGGLE;
|
||
items.push_back(toggle);
|
||
|
||
MenuItem solo;
|
||
solo.label = L"仅显示该信号";
|
||
solo.id = CMD_SIGNAL_SOLO;
|
||
items.push_back(solo);
|
||
|
||
MenuItem showAll;
|
||
showAll.label = L"显示全部信号";
|
||
showAll.id = CMD_SIGNAL_SHOW_ALL;
|
||
items.push_back(showAll);
|
||
|
||
MenuItem hideAll;
|
||
hideAll.label = L"隐藏全部信号";
|
||
hideAll.id = CMD_SIGNAL_HIDE_ALL;
|
||
items.push_back(hideAll);
|
||
|
||
MenuItem separator;
|
||
separator.kind = MenuItemKind::SEPARATOR;
|
||
items.push_back(separator);
|
||
|
||
int paletteCount = 0;
|
||
const std::uint32_t* palette = SignalPalette(paletteCount);
|
||
MenuItem colors;
|
||
colors.kind = MenuItemKind::SWATCHES;
|
||
colors.id = CMD_COLOR_BASE;
|
||
colors.swatchCount = std::min(paletteCount, 16);
|
||
colors.checkedSwatch = -1;
|
||
for (int index = 0; index < colors.swatchCount; ++index)
|
||
{
|
||
colors.swatches[index] = palette[index];
|
||
if (style->color == palette[index])
|
||
{
|
||
colors.checkedSwatch = index;
|
||
}
|
||
}
|
||
items.push_back(colors);
|
||
|
||
MenuItem modeHeader;
|
||
modeHeader.kind = MenuItemKind::HEADER;
|
||
modeHeader.label = L"样式";
|
||
items.push_back(modeHeader);
|
||
|
||
for (int index = 0; index < kModeOptionCount; ++index)
|
||
{
|
||
MenuItem mode;
|
||
mode.label = DrawModeName(kModeOptions[index]);
|
||
mode.id = CMD_MODE_BASE + index;
|
||
mode.checked = (style->mode == kModeOptions[index]);
|
||
items.push_back(mode);
|
||
}
|
||
|
||
const gd::RectF bounds = (m_clientBounds.Width > 1.0f) ? m_clientBounds : m_area;
|
||
m_menu->Open(MenuScope::SIGNAL_PANEL, bounds, x, y, items);
|
||
}
|
||
|
||
void SignalPanel::OpenFileMenu(int fileIndex, int x, int y)
|
||
{
|
||
if (m_menu == nullptr || m_tab == nullptr || m_dataSet == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
const DataFile* file = m_dataSet->FileAt(fileIndex);
|
||
if (file == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_menuTargetFile = fileIndex;
|
||
m_menuTargetSignal = SignalRef();
|
||
|
||
std::vector<MenuItem> items;
|
||
|
||
MenuItem header;
|
||
header.kind = MenuItemKind::HEADER;
|
||
header.label = file->Title();
|
||
items.push_back(header);
|
||
|
||
MenuItem showAll;
|
||
showAll.label = L"选中该文件全部信号";
|
||
showAll.id = CMD_FILE_SHOW_ALL;
|
||
items.push_back(showAll);
|
||
|
||
MenuItem hideAll;
|
||
hideAll.label = L"取消该文件全部信号";
|
||
hideAll.id = CMD_FILE_HIDE_ALL;
|
||
items.push_back(hideAll);
|
||
|
||
MenuItem separator;
|
||
separator.kind = MenuItemKind::SEPARATOR;
|
||
items.push_back(separator);
|
||
|
||
MenuItem remove;
|
||
remove.label = L"关闭该文件(从工作区移除)";
|
||
remove.id = CMD_FILE_REMOVE;
|
||
items.push_back(remove);
|
||
|
||
const gd::RectF bounds = (m_clientBounds.Width > 1.0f) ? m_clientBounds : m_area;
|
||
m_menu->Open(MenuScope::SIGNAL_PANEL, bounds, x, y, items);
|
||
}
|
||
|
||
void SignalPanel::OpenLaneMenu(const SignalRef& ref, int x, int y)
|
||
{
|
||
if (m_menu == nullptr || m_tab == nullptr || m_dataSet == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
const SignalData* signal = m_dataSet->Resolve(ref);
|
||
if (signal == nullptr)
|
||
{
|
||
return;
|
||
}
|
||
|
||
m_menuTargetSignal = ref;
|
||
m_menuTargetFile = -1;
|
||
|
||
std::vector<MenuItem> items;
|
||
|
||
MenuItem header;
|
||
header.kind = MenuItemKind::HEADER;
|
||
header.label = L"所属网格";
|
||
items.push_back(header);
|
||
|
||
const std::vector<Lane>& lanes = m_tab->Lanes();
|
||
const int currentLane = m_tab->LaneOfSignal(ref);
|
||
for (std::size_t index = 0; index < lanes.size(); ++index)
|
||
{
|
||
MenuItem lane;
|
||
lane.label = L"网格 " + std::to_wstring(index + 1) + L"(" +
|
||
std::to_wstring(lanes[index].signals.size()) + L" 条信号)";
|
||
lane.id = CMD_LANE_BASE + static_cast<int>(index);
|
||
lane.checked = (currentLane == static_cast<int>(index));
|
||
items.push_back(lane);
|
||
}
|
||
|
||
MenuItem separator;
|
||
separator.kind = MenuItemKind::SEPARATOR;
|
||
items.push_back(separator);
|
||
|
||
MenuItem create;
|
||
create.label = L"新建网格";
|
||
create.id = CMD_LANE_NEW;
|
||
items.push_back(create);
|
||
|
||
const gd::RectF bounds = (m_clientBounds.Width > 1.0f) ? m_clientBounds : m_area;
|
||
m_menu->Open(MenuScope::SIGNAL_PANEL, bounds, x, y, items);
|
||
}
|
||
|
||
bool SignalPanel::OnMenuCommand(const MenuResult& result)
|
||
{
|
||
if (m_tab == nullptr || m_dataSet == nullptr || !result.valid)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
bool needRelayout = false;
|
||
|
||
switch (result.id)
|
||
{
|
||
case CMD_SIGNAL_TOGGLE:
|
||
if (m_menuTargetSignal.IsValid())
|
||
{
|
||
m_tab->ToggleVisible(m_menuTargetSignal);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
}
|
||
break;
|
||
case CMD_SIGNAL_SOLO:
|
||
if (m_menuTargetSignal.IsValid())
|
||
{
|
||
m_tab->SoloSignal(m_menuTargetSignal);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
}
|
||
break;
|
||
case CMD_SIGNAL_SHOW_ALL:
|
||
m_tab->SetAllVisible(true);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
break;
|
||
case CMD_SIGNAL_HIDE_ALL:
|
||
m_tab->SetAllVisible(false);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
break;
|
||
case CMD_FILE_SHOW_ALL:
|
||
if (m_menuTargetFile >= 0)
|
||
{
|
||
m_tab->SetFileVisible(m_menuTargetFile, true);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
}
|
||
break;
|
||
case CMD_FILE_HIDE_ALL:
|
||
if (m_menuTargetFile >= 0)
|
||
{
|
||
m_tab->SetFileVisible(m_menuTargetFile, false);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
}
|
||
break;
|
||
case CMD_FILE_REMOVE:
|
||
if (m_menuTargetFile >= 0 && m_host != nullptr)
|
||
{
|
||
PostMessageW(m_host, WM_APP + 1, static_cast<WPARAM>(m_menuTargetFile), 0);
|
||
}
|
||
break;
|
||
case CMD_LANE_NEW:
|
||
if (m_menuTargetSignal.IsValid())
|
||
{
|
||
m_tab->MoveSignalToLane(*m_dataSet, m_menuTargetSignal, -1);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
}
|
||
break;
|
||
default:
|
||
if (result.id >= CMD_LANE_BASE && result.id < CMD_LANE_NEW)
|
||
{
|
||
if (m_menuTargetSignal.IsValid())
|
||
{
|
||
m_tab->MoveSignalToLane(*m_dataSet, m_menuTargetSignal, result.id - CMD_LANE_BASE);
|
||
m_rowsDirty = true;
|
||
needRelayout = true;
|
||
}
|
||
}
|
||
else if (result.id == CMD_COLOR_BASE && result.swatchIndex >= 0)
|
||
{
|
||
if (SignalStyle* style = StyleOf(m_menuTargetSignal))
|
||
{
|
||
int paletteCount = 0;
|
||
const std::uint32_t* palette = SignalPalette(paletteCount);
|
||
style->color = palette[result.swatchIndex % std::max(1, paletteCount)];
|
||
}
|
||
}
|
||
else if (result.id >= CMD_MODE_BASE && result.id < CMD_MODE_BASE + kModeOptionCount)
|
||
{
|
||
if (SignalStyle* style = StyleOf(m_menuTargetSignal))
|
||
{
|
||
style->mode = kModeOptions[result.id - CMD_MODE_BASE];
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
|
||
return needRelayout;
|
||
}
|
||
|
||
} // namespace jdi
|