From 22c4fd7bb3ef1d7c6bfc67baf79aed53d22d8636 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期五, 14 十一月 2025 18:00:06 +0800
Subject: [PATCH] 1.竖排slot格子指示;
---
SourceCode/Bond/Servo/EqsGraphWnd.cpp | 348 ++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 219 insertions(+), 129 deletions(-)
diff --git a/SourceCode/Bond/Servo/EqsGraphWnd.cpp b/SourceCode/Bond/Servo/EqsGraphWnd.cpp
index 46aa8a4..cca80eb 100644
--- a/SourceCode/Bond/Servo/EqsGraphWnd.cpp
+++ b/SourceCode/Bond/Servo/EqsGraphWnd.cpp
@@ -1,4 +1,4 @@
-#include "stdafx.h"
+锘�#include "stdafx.h"
#include "EqsGraphWnd.h"
#include "ColorTransfer.h"
#include "MapPosWnd.h"
@@ -35,13 +35,7 @@
m_hWnd = NULL;
m_crFrame = GetSysColor(COLOR_WINDOWFRAME);
m_crBkgnd = RGB(255, 255, 255);
- m_listener.onConnectPin = nullptr;
- m_listener.onCheckConnectPin = nullptr;
- m_listener.onDisconnectPin = nullptr;
- m_listener.onDeleteEqItem = nullptr;
- m_listener.onEqItemPosChanged = nullptr;
- m_listener.onDblckEqItem = nullptr;
- m_listener.onRclickEqItem = nullptr;
+ m_listener = {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
m_crItemBackground[0] = RGB(218, 218, 218);
m_crItemBackground[1] = RGB(193, 208, 227);
m_crItemFrame[0] = RGB(128, 128, 128);
@@ -70,6 +64,8 @@
m_nMagneticLinHoz = 0;
m_nMagneticLinVer = 0;
m_hFontTitle = nullptr;
+ m_nIndicatorSize = 10;
+ m_nIndicatorMargin = 3;
}
@@ -92,7 +88,7 @@
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
- // 注册窗口类
+ // 娉ㄥ唽绐楀彛绫�
return (::RegisterClass(&wc) != 0);
}
@@ -163,6 +159,20 @@
m_crItemIdText[0] = CColorTransfer::ApproximateColor(m_crItemNameText[0], -0.3f);
m_crItemIdText[1] = CColorTransfer::ApproximateColor(m_crItemNameText[1], -0.3f);
+}
+
+void CEqsGraphWnd::SetIndicatorSize(int nSize)
+{
+ if (nSize > 0) {
+ m_nIndicatorSize = nSize;
+ }
+}
+
+void CEqsGraphWnd::SetIndicatorMargin(int nMargin)
+{
+ if (nMargin >= 0) {
+ m_nIndicatorMargin = nMargin;
+ }
}
void CEqsGraphWnd::EnableScroll(BOOL bEnable)
@@ -241,7 +251,7 @@
}
/*
- * 计算磁力线位置
+ * 璁$畻纾佸姏绾夸綅缃�
*/
void CEqsGraphWnd::CalculateMagneticLine(EQITEM* pItem, LPRECT lprcItemRect, int &hoz, int &ver)
{
@@ -249,7 +259,7 @@
ver = 0;
#define MAGNETIC_DIS 10
- // 检测是否接近或对齐
+ // 妫�娴嬫槸鍚︽帴杩戞垨瀵归綈
for (int i = 0; i < m_arItem.GetSize(); i++) {
EQITEM *pTemp = (EQITEM*)m_arItem.GetAt(i);
if (pTemp != pItem) {
@@ -293,10 +303,10 @@
}
/*
- * 取得In Pin的区域
+ * 鍙栧緱In Pin鐨勫尯鍩�
* pItem -- EQITEM
- * lpRect -- 得到的Rect
- * 返回是否成功
+ * lpRect -- 寰楀埌鐨凴ect
+ * 杩斿洖鏄惁鎴愬姛
*/
BOOL CEqsGraphWnd::GetItemRect(EQITEM* pItem, LPRECT lpRect)
{
@@ -327,11 +337,11 @@
}
/*
- * 取得In Pin的区域
+ * 鍙栧緱In Pin鐨勫尯鍩�
* pItem -- EQITEM
- * nPinIndex -- in pin索引
- * lpRect -- 得到的Rect
- * 返回是否成功
+ * nPinIndex -- in pin绱㈠紩
+ * lpRect -- 寰楀埌鐨凴ect
+ * 杩斿洖鏄惁鎴愬姛
*/
BOOL CEqsGraphWnd::GetInPinRect(EQITEM* pItem, int nPinIndex, LPRECT lpRect)
{
@@ -351,11 +361,11 @@
}
/*
- * 取得Out Pin的区域
+ * 鍙栧緱Out Pin鐨勫尯鍩�
* pItem -- EQITEM
- * nPinIndex -- in pin索引
- * lpRect -- 得到的Rect
- * 返回是否成功
+ * nPinIndex -- in pin绱㈠紩
+ * lpRect -- 寰楀埌鐨凴ect
+ * 杩斿洖鏄惁鎴愬姛
*/
BOOL CEqsGraphWnd::GetOutPinRect(EQITEM* pItem, int nPinIndex, LPRECT lpRect)
{
@@ -374,11 +384,11 @@
}
/*
- * 取得Pin的Point
+ * 鍙栧緱Pin鐨凱oint
* pItem -- EQITEM
- * nPinIndex -- in pin索引
- * lpRect -- 得到的Rect
- * 返回是否成功
+ * nPinIndex -- in pin绱㈠紩
+ * lpRect -- 寰楀埌鐨凴ect
+ * 杩斿洖鏄惁鎴愬姛
*/
BOOL CEqsGraphWnd::GetPinPoint(PIN *pPin, LPPOINT lpPoint)
{
@@ -459,7 +469,7 @@
}
/*
- * 清空PIN连接线缓存点,以便重新计算和绘制
+ * 娓呯┖PIN杩炴帴绾跨紦瀛樼偣锛屼互渚块噸鏂拌绠楀拰缁樺埗
*/
void CEqsGraphWnd::ClearConnectedLinePoint(EQITEM*& pItem)
{
@@ -492,6 +502,7 @@
m_listener.onEqItemPosChanged = listener.onEqItemPosChanged;
m_listener.onDblckEqItem = listener.onDblckEqItem;
m_listener.onRclickEqItem = listener.onRclickEqItem;
+ m_listener.onSelectEqItem = listener.onSelectEqItem;
}
BOOL CEqsGraphWnd::SetCurSel(int nSel)
@@ -560,7 +571,7 @@
*/
EQITEM* CEqsGraphWnd::AddItem(int id, CString strText, DWORD_PTR dwData, int nType/* = ITEM_NORMAL*/)
{
- // 需要计算一个新位置,不然全部重叠在一起
+ // 闇�瑕佽绠椾竴涓柊浣嶇疆锛屼笉鐒跺叏閮ㄩ噸鍙犲湪涓�璧�
int x, y;
x = (m_arItem.GetCount() % 4) * 218;
y = (m_arItem.GetCount() / 4) * 168;
@@ -633,6 +644,27 @@
void CEqsGraphWnd::SetItemType(EQITEM* pItem, int nType)
{
pItem->nShowType = nType;
+ if (pItem->nShowType == ITEM_SMALL) {
+ pItem->rect.right = pItem->rect.left + ITEM_CX_SMALL;
+ pItem->rect.bottom = pItem->rect.top + ITEM_CY_SMALL;
+ }
+ else if (pItem->nShowType == ITEM_LARGE) {
+ pItem->rect.right = pItem->rect.left + ITEM_CX_LARGE;
+ pItem->rect.bottom = pItem->rect.top + ITEM_CY_LARGE;
+ }
+ else {
+ pItem->rect.right = pItem->rect.left + ITEM_CX_NORMAL;
+ pItem->rect.bottom = pItem->rect.top + ITEM_CY_NORMAL;
+ }
+
+ ::InvalidateRect(m_hWnd, &pItem->rect, TRUE);
+}
+
+void CEqsGraphWnd::SetItemPos(EQITEM* pItem, int x, int y)
+{
+ ASSERT(pItem);
+ pItem->rect.left = x;
+ pItem->rect.top = y;
if (pItem->nShowType == ITEM_SMALL) {
pItem->rect.right = pItem->rect.left + ITEM_CX_SMALL;
pItem->rect.bottom = pItem->rect.top + ITEM_CY_SMALL;
@@ -739,7 +771,7 @@
return 0;
}
-// 删除Item, 如果pin有连接,注意先断开
+// 鍒犻櫎Item, 濡傛灉pin鏈夎繛鎺ワ紝娉ㄦ剰鍏堟柇寮�
int CEqsGraphWnd::DeleteItem(EQITEM* pItem)
{
for (int i = 0; i < m_arItem.GetSize(); i++) {
@@ -779,7 +811,7 @@
}
/*
- * 设置子项的选中状态
+ * 璁剧疆瀛愰」鐨勯�変腑鐘舵��
*/
void CEqsGraphWnd::SetItemSelectState(int nIndex, BOOL bSelect)
{
@@ -812,14 +844,14 @@
}
/*
- * 检测坐标点所在的项
- * 返回项类型, 如HT_ITEM, HT_PIN, HT_LINE
- * pItem - 所在的EQITEM
- * pPin --所在的pin, 如果在连线上,表示所属pin, out pin;
+ * 妫�娴嬪潗鏍囩偣鎵�鍦ㄧ殑椤�
+ * 杩斿洖椤圭被鍨�, 濡侶T_ITEM, HT_PIN, HT_LINE
+ * pItem - 鎵�鍦ㄧ殑EQITEM
+ * pPin --鎵�鍦ㄧ殑pin, 濡傛灉鍦ㄨ繛绾夸笂锛岃〃绀烘墍灞瀙in, out pin锛�
*/
int CEqsGraphWnd::HighTest(POINT pt, OUT EQITEM*& pItem, OUT PIN *& pPin)
{
- // 检测是否在某个子项
+ // 妫�娴嬫槸鍚﹀湪鏌愪釜瀛愰」
int nRet = HT_NOWHERE;
pItem = NULL;
pPin = NULL;
@@ -828,7 +860,7 @@
EQITEM *pTempItem = (EQITEM*)m_arItem.GetAt(i);
GetItemRect(pTempItem, &rcItem);
if (::PtInRect(&rcItem, pt)) {
- // 在Item
+ // 鍦↖tem
pItem = pTempItem;
nRet = HT_ITEM;
break;
@@ -838,7 +870,7 @@
CPtrArray * pPins = (CPtrArray *)pTempItem->pInPins;
for (int j = 0; j < pPins->GetSize(); j++) {
if (GetInPinRect(pTempItem, j, &rcPin) && ::PtInRect(&rcPin, pt)) {
- // 在in pin上
+ // 鍦╥n pin涓�
pPin = (PIN *)pPins->GetAt(j);
pItem = pTempItem;
nRet = HT_PIN;
@@ -850,15 +882,15 @@
pPins = (CPtrArray *)pTempItem->pOutPins;
for (int j = 0; j < pPins->GetSize(); j++) {
if (GetOutPinRect(pTempItem, j, &rcPin) && ::PtInRect(&rcPin, pt)) {
- // 在out pin
+ // 鍦╫ut pin
pPin = (PIN *)pPins->GetAt(j);
pItem = pTempItem;
nRet = HT_PIN;
break;
}
else {
- // 是否在pin连接线上,即判断点是否在线上
- // 点到直线的距离公式(先通过p1,p2用两点式求出直线的表达式,再套距离公式);abs()为取绝对值函数,sqrt()为开根号函数
+ // 鏄惁鍦╬in杩炴帴绾夸笂,鍗冲垽鏂偣鏄惁鍦ㄧ嚎涓�
+ // 鐐瑰埌鐩寸嚎鐨勮窛绂诲叕寮忥紙鍏堥�氳繃p1,p2鐢ㄤ袱鐐瑰紡姹傚嚭鐩寸嚎鐨勮〃杈惧紡锛屽啀濂楄窛绂诲叕寮忥級锛沘bs()涓哄彇缁濆鍊煎嚱鏁帮紝sqrt()涓哄紑鏍瑰彿鍑芥暟
PIN *pTempPin = (PIN *)pPins->GetAt(j);
if (pTempPin->pConnectedPin != NULL && pTempPin->nLinePtCount > 1) {
for (int i = 0; i < pTempPin->nLinePtCount - 1; i++) {
@@ -891,7 +923,7 @@
}
/*
- * 绘制虚线框,代表正在拖动的item
+ * 缁樺埗铏氱嚎妗嗭紝浠h〃姝e湪鎷栧姩鐨刬tem
*/
void CEqsGraphWnd::DrawDropItemRectangle(LPRECT lpRect1, LPRECT lpRect2)
{
@@ -919,7 +951,7 @@
}
/*
- * 绘制磁吸线
+ * 缁樺埗纾佸惛绾�
*/
void CEqsGraphWnd::DrawMagneticLine(LPRECT lprcClient, int nHozLine1, int nHozLine2, int nVerLine1, int nVerLine2)
{
@@ -953,16 +985,16 @@
}
/*
- * 缓制Pin连接线
- * pBrush -- 画刷
- * pPen - 画笔
- * lpPt1, lpPt2 -- Pin脚的位置
- * lpRect1, lpRect2 -- 两个Item的Rect
+ * 缂撳埗Pin杩炴帴绾�
+ * pBrush -- 鐢诲埛
+ * pPen - 鐢荤瑪
+ * lpPt1, lpPt2 -- Pin鑴氱殑浣嶇疆
+ * lpRect1, lpRect2 -- 涓や釜Item鐨凴ect
*/
void CEqsGraphWnd::DrawPinConnectedLine(Gdiplus::Graphics *pGraphics, Gdiplus::Brush *pBrush, Gdiplus::Pen *pPen, LPPOINT lpPt1, LPPOINT lpPt2,
LPRECT lpRect1, LPRECT lpRect2, PIN *pOwnerPin)
{
- // 如果没有缓存线条的POINT,则先计算并缓存
+ // 濡傛灉娌℃湁缂撳瓨绾挎潯鐨凱OINT锛屽垯鍏堣绠楀苟缂撳瓨
ASSERT(pOwnerPin);
int nPinCount = ((CPtrArray*)pOwnerPin->pItem->pOutPins)->GetSize();
@@ -971,10 +1003,10 @@
int nMargin = 12;
int x1, x2, y1;
- if (pOwnerPin->nLinePtCount == 0) { // 第一个点的最小折线长
+ if (pOwnerPin->nLinePtCount == 0) { // 绗竴涓偣鐨勬渶灏忔姌绾块暱
::OffsetRect(lpRect1, +m_nOffsetX, +m_nOffsetY);
::OffsetRect(lpRect2, +m_nOffsetX, +m_nOffsetY);
- lpPt1->x += m_nOffsetX; // 消除偏移
+ lpPt1->x += m_nOffsetX; // 娑堥櫎鍋忕Щ
lpPt1->y += m_nOffsetY;
lpPt2->x += m_nOffsetX;
lpPt2->y += m_nOffsetY;
@@ -1083,7 +1115,7 @@
}
/*
- * WindowProc,窗口过程
+ * WindowProc锛岀獥鍙h繃绋�
*/
LRESULT CALLBACK CEqsGraphWnd::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
@@ -1094,7 +1126,7 @@
}
- // 处理窗口消息
+ // 澶勭悊绐楀彛娑堟伅
ASSERT(hWnd);
switch (uMsg)
{
@@ -1158,7 +1190,7 @@
/*
* WM_NCCREATE
- * 窗口创建
+ * 绐楀彛鍒涘缓
*/
LRESULT CEqsGraphWnd::OnNcCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
@@ -1171,7 +1203,7 @@
/*
* WM_DESTROY
- * 窗口销毁
+ * 绐楀彛閿�姣�
*/
LRESULT CEqsGraphWnd::OnDestroy(WPARAM wParam, LPARAM lParam)
{
@@ -1234,7 +1266,7 @@
/*
* WM_MOUSEMOVE
- * 鼠标滚动
+ * 榧犳爣婊氬姩
*/
LRESULT CEqsGraphWnd::OnMouseMove(WPARAM wParam, LPARAM lParam)
{
@@ -1243,7 +1275,7 @@
/*
* WM_LBUTTONDOWN
- * 鼠标左键按下
+ * 榧犳爣宸﹂敭鎸変笅
*/
LRESULT CEqsGraphWnd::OnLButtonDown(WPARAM wParam, LPARAM lParam)
{
@@ -1260,11 +1292,12 @@
int nLastVerLine = 0;
- // 检测点击坐标是否在某一子项上,如是,则高亮显示
+ // 妫�娴嬬偣鍑诲潗鏍囨槸鍚﹀湪鏌愪竴瀛愰」涓婏紝濡傛槸锛屽垯楂樹寒鏄剧ず
EQITEM* pLastItem = m_pCurItem;
PIN *pLastPin = m_pCurPin;
PIN *pLastSelLineOutPin = m_pSelLineOutPin;
BOOL bChanged = FALSE;
+ BOOL bSelectChanged = FALSE;
EQITEM* pHitItem = NULL;
PIN *pHitPin = NULL;
PIN *pPin2 = NULL;
@@ -1288,8 +1321,11 @@
}
if (nRet == HT_ITEM) {
- m_pCurItem = pHitItem;
- m_pCurItem->bHighlight = TRUE;
+ if (m_pCurItem != pHitItem) {
+ m_pCurItem = pHitItem;
+ m_pCurItem->bHighlight = TRUE;
+ bSelectChanged = TRUE;
+ }
}
else if (nRet == HT_PIN) {
m_pCurPin = pHitPin;
@@ -1303,14 +1339,14 @@
bChanged = pLastItem != m_pCurItem || pLastPin != m_pCurPin || pLastSelLineOutPin != m_pSelLineOutPin;
- // 刷新
+ // 鍒锋柊
SetFocus(m_hWnd);
if (bChanged) {
::InvalidateRect(m_hWnd, &rcClient, TRUE);
}
- // 捕捉鼠标消息,检测是否拖动
+ // 鎹曟崏榧犳爣娑堟伅锛屾娴嬫槸鍚︽嫋鍔�
if (nRet == HT_ITEM && m_pCurItem != NULL) {
GetItemRect(m_pCurItem, &rcItem);
@@ -1373,12 +1409,14 @@
ReleaseCapture();
ExitLoop:
+ m_nMagneticLinHoz = 0;
+ m_nMagneticLinVer = 0;
AfxUnlockTempMaps(FALSE);
}
}
- // 捕捉鼠标消息,检测是否连接引脚
+ // 鎹曟崏榧犳爣娑堟伅锛屾娴嬫槸鍚﹁繛鎺ュ紩鑴�
else if (nRet == HT_PIN && m_pCurPin != NULL) {
if (::GetCapture() == NULL) {
BOOL bLast = FALSE;
@@ -1405,12 +1443,12 @@
ptNew = msg.pt;
::ScreenToClient(m_hWnd, &ptNew);
- // 擦除上一次
+ // 鎿﹂櫎涓婁竴娆�
if (bLast) {
DrawPinWillConnectLine(lineColor, &ptPin, &ptLast);
}
- // 检测是否可以连接
+ // 妫�娴嬫槸鍚﹀彲浠ヨ繛鎺�
bCanConnect = false;
nRet = HighTest(ptNew, pHitItem, pHitPin);
if (nRet == HT_PIN) {
@@ -1436,12 +1474,12 @@
ptNew = msg.pt;
::ScreenToClient(m_hWnd, &ptNew);
- // 擦除上一次
+ // 鎿﹂櫎涓婁竴娆�
if (bLast) {
DrawPinWillConnectLine(lineColor, &ptPin, &ptLast);
}
- // 检测是否可以连接
+ // 妫�娴嬫槸鍚﹀彲浠ヨ繛鎺�
bCanConnect = false;
nRet = HighTest(ptNew, pHitItem, pHitPin);
if (nRet == HT_PIN) {
@@ -1476,7 +1514,7 @@
}
- // 检测鼠标消息,检测是否移动画布
+ // 妫�娴嬮紶鏍囨秷鎭紝妫�娴嬫槸鍚︾Щ鍔ㄧ敾甯�
else if (nRet == HT_NOWHERE) {
if (::GetCapture() == NULL) {
int nLastOffsetX = m_nOffsetX;
@@ -1535,12 +1573,19 @@
}
+ if (bSelectChanged) {
+ if (m_listener.onSelectEqItem != nullptr) {
+ m_listener.onSelectEqItem(m_pCurItem);
+ }
+ }
+
+
return ::DefWindowProc(m_hWnd, WM_LBUTTONDOWN, wParam, lParam);
}
/*
* WM_LBUTTONDBLCLK
- * 鼠标左键双击
+ * 榧犳爣宸﹂敭鍙屽嚮
*/
LRESULT CEqsGraphWnd::OnLButtonDblclk(WPARAM wParam, LPARAM lParam)
{
@@ -1552,7 +1597,7 @@
GetClientRect(m_hWnd, &rcClient);
rcLast = { 0, 0, 0, 0 };
- // 检测点击坐标是否在某一子项上,如是,则高亮显示
+ // 妫�娴嬬偣鍑诲潗鏍囨槸鍚﹀湪鏌愪竴瀛愰」涓婏紝濡傛槸锛屽垯楂樹寒鏄剧ず
EQITEM* pLastItem = m_pCurItem;
BOOL bChanged = FALSE;
EQITEM* pHitItem = NULL;
@@ -1572,7 +1617,7 @@
/*
* WM_MOUSEWHEEL
- * 鼠标滚动
+ * 榧犳爣婊氬姩
*/
LRESULT CEqsGraphWnd::OnMouseWheel(WPARAM wParam, LPARAM lParam)
{
@@ -1599,7 +1644,7 @@
/*
* WM_MOUSEHWHEEL
-* 鼠标滚动
+* 榧犳爣婊氬姩
*/
LRESULT CEqsGraphWnd::OnMouseHWheel(WPARAM wParam, LPARAM lParam)
{
@@ -1626,7 +1671,7 @@
/*
* WM_RBUTTONDOWN
- * 鼠标左键按下
+ * 榧犳爣宸﹂敭鎸変笅
*/
LRESULT CEqsGraphWnd::OnRButtonDown(WPARAM wParam, LPARAM lParam)
{
@@ -1638,7 +1683,7 @@
GetClientRect(m_hWnd, &rcClient);
rcLast = { 0, 0, 0, 0 };
- // 检测点击坐标是否在某一子项上,如是,则高亮显示
+ // 妫�娴嬬偣鍑诲潗鏍囨槸鍚﹀湪鏌愪竴瀛愰」涓婏紝濡傛槸锛屽垯楂樹寒鏄剧ず
EQITEM* pLastItem = m_pCurItem;
PIN *pLastPin = m_pCurPin;
PIN *pLastSelLineOutPin = m_pSelLineOutPin;
@@ -1681,14 +1726,14 @@
bChanged = pLastItem != m_pCurItem || pLastPin != m_pCurPin || pLastSelLineOutPin != m_pSelLineOutPin;
- // 刷新
+ // 鍒锋柊
SetFocus(m_hWnd);
if (bChanged) {
::InvalidateRect(m_hWnd, &rcClient, TRUE);
}
- // 捕捉鼠标消息,检测是否拖动
+ // 鎹曟崏榧犳爣娑堟伅锛屾娴嬫槸鍚︽嫋鍔�
if (nRet == HT_ITEM && m_pCurItem != NULL) {
CopyRect(&rcItem, &m_pCurItem->rect);
@@ -1741,13 +1786,13 @@
/*
* WM_KEYDOWN
- * 键盘消息,按下按键
+ * 閿洏娑堟伅锛屾寜涓嬫寜閿�
*/
LRESULT CEqsGraphWnd::OnKeyDown(WPARAM wParam, LPARAM lParam)
{
BOOL bChanged = FALSE;
if (wParam == VK_DELETE) {
- // 如果当前选择为线,则断开连接
+ // 濡傛灉褰撳墠閫夋嫨涓虹嚎锛屽垯鏂紑杩炴帴
if (m_pSelLineOutPin != NULL) {
if (m_listener.onDisconnectPin != nullptr) {
if (m_listener.onDisconnectPin(m_pSelLineOutPin)) {
@@ -1837,7 +1882,6 @@
CString strText;
HBRUSH hBrushBK;
-
// BeginPaint
PAINTSTRUCT ps;
hDC = BeginPaint(m_hWnd, &ps);
@@ -1848,14 +1892,12 @@
rcClient.bottom - rcClient.top);
::SelectObject(hMemDC, hBitmap);
-
- // 背景颜色
+ // 鑳屾櫙棰滆壊
hBrushBK = CreateSolidBrush(m_crBkgnd);
::FillRect(hMemDC, &rcClient, hBrushBK);
DeleteObject(hBrushBK);
-
- // 标题
+ // 鏍囬瀛椾綋
if (m_hFontTitle == nullptr) {
LOGFONT lf;
HFONT hFontDefault = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
@@ -1865,8 +1907,9 @@
m_hFontTitle = CreateFontIndirect(&lf);
}
+ // 缁樺埗鏍囬鏂囨湰
{
- char szTitle[256];
+ char szTitle[256] = { 0 };
GetWindowText(m_hWnd, szTitle, 256);
RECT rcTitle;
rcTitle.left = rcClient.left + 5;
@@ -1877,19 +1920,23 @@
::DrawText(hMemDC, szTitle, (int)strlen(szTitle), &rcTitle, DT_LEFT | DT_TOP);
}
-
- // 绘制子项
+ // 缁樺埗瀛愰」
HBRUSH hbrItemBackground[2];
HBRUSH hbrItemFrame[2];
HBRUSH hbrPinBackground[3];
+ HBRUSH hbrIndicator;
+ HBRUSH hbrIndicatorGray;
+
hbrItemBackground[0] = CreateSolidBrush(m_crItemBackground[0]);
hbrItemBackground[1] = CreateSolidBrush(m_crItemBackground[1]);
hbrItemFrame[0] = CreateSolidBrush(m_crItemFrame[0]);
hbrItemFrame[1] = CreateSolidBrush(m_crItemFrame[1]);
+ hbrIndicator = CreateSolidBrush(RGB(34, 177, 76)); // 缁胯壊
+ hbrIndicatorGray = CreateSolidBrush(RGB(192, 192, 192)); // 鐏拌壊
+
for (int i = 0; i < 3; i++) {
hbrPinBackground[i] = CreateSolidBrush(m_crPinBkgnd[i]);
}
-
// gdi+
Gdiplus::Graphics graphics(hMemDC);
@@ -1900,21 +1947,22 @@
graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
}
-
SetBkMode(hMemDC, TRANSPARENT);
{
RECT rcItem;
int nPinState;
int nItemCount = (int)m_arItem.GetCount();
+
+ // 鍏堢敾 item銆佹枃鏈�乸in 鍜屾寚绀虹伅
for (int i = 0; i < nItemCount; i++) {
EQITEM* pItem = (EQITEM*)m_arItem.GetAt(i);
if (pItem->nFlashFlag == 1) {
continue;
}
+
GetItemRect(pItem, &rcItem);
-
- // 子项背景和边框
+ // 瀛愰」鑳屾櫙鍜岃竟妗�
if (m_nItemRound == 0) {
::FillRect(hMemDC, &rcItem, pItem->bHighlight ? hbrItemBackground[1] : hbrItemBackground[0]);
::FrameRect(hMemDC, &rcItem, pItem->bHighlight ? hbrItemFrame[1] : hbrItemFrame[0]);
@@ -1926,12 +1974,37 @@
::DeleteObject(hRgn);
}
-
- // name和id
+ // name
HFONT hFontOld = (HFONT)::SelectObject(hMemDC, m_hFontName);
::SetTextColor(hMemDC, pItem->bHighlight ? m_crItemNameText[1] : m_crItemNameText[0]);
- ::DrawText(hMemDC, pItem->text, (int)strlen(pItem->text), &rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
+ ::DrawText(hMemDC, pItem->text, (int)strlen(pItem->text), &rcItem,
+ DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
+ // indicators vertical column layout
+ const int indicatorSize = m_nIndicatorSize;
+ const int indicatorMargin = m_nIndicatorMargin;
+ const int indicatorX = rcItem.left + 5;
+
+ for (int k = 0; k < EQITEM_INDICATOR_COUNT; ++k) {
+ BYTE indicatorState = pItem->nIndicatorState[k];
+ if (indicatorState == INDICATOR_STATE_HIDDEN) {
+ continue;
+ }
+
+ RECT rcIndicator;
+ rcIndicator.left = indicatorX;
+ rcIndicator.top = rcItem.top + 5 + k * (indicatorSize + indicatorMargin);
+ rcIndicator.right = rcIndicator.left + indicatorSize;
+ rcIndicator.bottom = rcIndicator.top + indicatorSize;
+
+ RECT rcInner = rcIndicator;
+ ::InflateRect(&rcInner, -1, -1);
+ ::FillRect(hMemDC, &rcInner, indicatorState == INDICATOR_STATE_HIGHLIGHT
+ ? hbrIndicator : hbrIndicatorGray);
+ ::FrameRect(hMemDC, &rcIndicator, hbrItemFrame[0]);
+ }
+
+ // ID 鏂囨湰锛堥潪灏忓彿 item锛�
if (pItem->nShowType != ITEM_SMALL) {
RECT rcId = rcItem;
rcId.left += 5;
@@ -1940,29 +2013,28 @@
strId.Format(_T("ID:%d"), pItem->id);
::SelectObject(hMemDC, m_hFontId);
::SetTextColor(hMemDC, pItem->bHighlight ? m_crItemIdText[1] : m_crItemIdText[0]);
- ::DrawText(hMemDC, strId, (int)strId.GetLength(), &rcId, DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS);
+ ::DrawText(hMemDC, strId, (int)strId.GetLength(), &rcId,
+ DT_LEFT | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS);
}
-
- // 动画效果不绘pin
+ // 鍔ㄧ敾鏁堟灉鏃朵笉缁樺埗 pin
if (m_pAnimationItem == pItem) {
+ ::SelectObject(hMemDC, hFontOld);
continue;
}
-
- // 绘制pin
+ // 缁樺埗 pin
RECT rcPin, rcPin2, rcPinText;
- CPtrArray *pPins;
+ CPtrArray* pPins;
rcPinText.left = rcItem.left + 8;
rcPinText.right = rcItem.right - 8;
-
// in pins
- PIN *pPin = NULL;
- pPins = (CPtrArray *)pItem->pInPins;
+ PIN* pPin = NULL;
+ pPins = (CPtrArray*)pItem->pInPins;
for (int j = 0; j < pPins->GetSize(); j++) {
if (GetInPinRect(pItem, j, &rcPin)) {
- pPin = (PIN *)pPins->GetAt(j);
+ pPin = (PIN*)pPins->GetAt(j);
::FrameRect(hMemDC, &rcPin, pItem->bHighlight ? hbrItemFrame[1] : hbrItemFrame[0]);
rcPin2.left = rcPin.left + 1;
@@ -1970,22 +2042,25 @@
rcPin2.top = rcPin.top + 1;
rcPin2.bottom = rcPin.bottom - 1;
nPinState = GetPinState(pPin);
- ::FillRect(hMemDC, &rcPin2, nPinState == 0 ? (pItem->bHighlight ? hbrItemBackground[1] : hbrItemBackground[0]) : hbrPinBackground[nPinState]);
+ ::FillRect(hMemDC, &rcPin2,
+ nPinState == 0
+ ? (pItem->bHighlight ? hbrItemBackground[1] : hbrItemBackground[0])
+ : hbrPinBackground[nPinState]);
if (pItem->nShowType != ITEM_SMALL) {
rcPinText.top = rcPin.top - 12;
rcPinText.bottom = rcPin.bottom + 12;
::SetTextColor(hMemDC, pItem->bHighlight ? m_crItemIdText[1] : m_crItemIdText[0]);
- ::DrawText(hMemDC, pPin->text, (int)strlen(pPin->text), &rcPinText, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
+ ::DrawText(hMemDC, pPin->text, (int)strlen(pPin->text), &rcPinText,
+ DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
}
}
}
-
// out pins
- pPins = (CPtrArray *)pItem->pOutPins;
+ pPins = (CPtrArray*)pItem->pOutPins;
for (int j = 0; j < pPins->GetSize(); j++) {
- pPin = (PIN *)pPins->GetAt(j);
+ pPin = (PIN*)pPins->GetAt(j);
if (GetOutPinRect(pItem, j, &rcPin)) {
::FrameRect(hMemDC, &rcPin, pItem->bHighlight ? hbrItemFrame[1] : hbrItemFrame[0]);
@@ -1994,50 +2069,53 @@
rcPin2.top = rcPin.top + 1;
rcPin2.bottom = rcPin.bottom - 1;
nPinState = GetPinState(pPin);
- ::FillRect(hMemDC, &rcPin2, nPinState == 0 ? (pItem->bHighlight ? hbrItemBackground[1] : hbrItemBackground[0]) : hbrPinBackground[nPinState]);
+ ::FillRect(hMemDC, &rcPin2,
+ nPinState == 0
+ ? (pItem->bHighlight ? hbrItemBackground[1] : hbrItemBackground[0])
+ : hbrPinBackground[nPinState]);
if (pItem->nShowType != ITEM_SMALL) {
rcPinText.top = rcPin.top - 12;
rcPinText.bottom = rcPin.bottom + 12;
::SetTextColor(hMemDC, pItem->bHighlight ? m_crItemIdText[1] : m_crItemIdText[0]);
- ::DrawText(hMemDC, pPin->text, (int)strlen(pPin->text), &rcPinText, DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
+ ::DrawText(hMemDC, pPin->text, (int)strlen(pPin->text), &rcPinText,
+ DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
}
}
}
- ::DeleteObject(hbrItemFrame);
::SelectObject(hMemDC, hFontOld);
}
-
- // 绘制连接线,保存线条在最后绘制
+ // 鍐嶇粯鍒惰繛鎺ョ嚎
for (int i = 0; i < nItemCount; i++) {
- EQITEM *pItem = (EQITEM*)m_arItem.GetAt(i);
+ EQITEM* pItem = (EQITEM*)m_arItem.GetAt(i);
if (pItem->nFlashFlag == 1) {
continue;
}
- PIN *pPin = NULL;
- CPtrArray *pPins;
-
- // out pins边线
+ PIN* pPin = NULL;
+ CPtrArray* pPins;
RECT rcItem1, rcItem2;
- pPins = (CPtrArray *)pItem->pOutPins;
+
+ // out pins 杈圭嚎
+ pPins = (CPtrArray*)pItem->pOutPins;
for (int j = 0; j < pPins->GetSize(); j++) {
- pPin = (PIN *)pPins->GetAt(j);
+ pPin = (PIN*)pPins->GetAt(j);
if (pPin->pConnectedPin != NULL) {
POINT pt1, pt2;
if (GetPinPoint(pPin, &pt1) && GetPinPoint(pPin->pConnectedPin, &pt2)) {
GetItemRect(pItem, &rcItem1);
GetItemRect(pPin->pConnectedPin->pItem, &rcItem2);
- DrawPinConnectedLine(&graphics, &brush1, pPin == m_pSelLineOutPin ? &pen2 : &pen1,
+ DrawPinConnectedLine(&graphics, &brush1,
+ pPin == m_pSelLineOutPin ? &pen2 : &pen1,
&pt1, &pt2, &rcItem1, &rcItem2, pPin);
}
}
}
}
-
+ // 鍒犻櫎 brush
for (int i = 0; i < 3; i++) {
::DeleteObject(hbrPinBackground[i]);
}
@@ -2045,10 +2123,9 @@
::DeleteObject(hbrItemBackground[1]);
::DeleteObject(hbrItemFrame[0]);
::DeleteObject(hbrItemFrame[1]);
+ ::DeleteObject(hbrIndicator);
+ ::DeleteObject(hbrIndicatorGray);
}
-
-
-
// EndPaint
::BitBlt(hDC, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
@@ -2057,9 +2134,9 @@
::DeleteObject(hBitmap);
::DeleteDC(hMemDC);
-
return 1;
}
+
/*
* WM_SIZE
@@ -2307,8 +2384,8 @@
/*
- * 设置背景颜色
- * color -- 背景色
+ * 璁剧疆鑳屾櫙棰滆壊
+ * color -- 鑳屾櫙鑹�
*/
void CEqsGraphWnd::SetBkgndColor(COLORREF color)
{
@@ -2316,8 +2393,8 @@
}
/*
- * 边框颜色
- * color -- 边框色
+ * 杈规棰滆壊
+ * color -- 杈规鑹�
*/
void CEqsGraphWnd::SetFrameColor(COLORREF color)
{
@@ -2361,6 +2438,19 @@
SetTimer(m_hWnd, TIMER_ANIMATION_RECT, uElpase, NULL);
}
+void CEqsGraphWnd::ShowItemIndicator(DWORD_PTR dwItemData, int state, int nIndex)
+{
+ if (nIndex < 0 || nIndex >= EQITEM_INDICATOR_COUNT) {
+ return;
+ }
+
+ EQITEM* pItem = GetItem(dwItemData);
+ if (pItem != nullptr) {
+ pItem->nIndicatorState[nIndex] = (BYTE)state;
+ ::InvalidateRect(m_hWnd, nullptr, TRUE);
+ }
+}
+
double CEqsGraphWnd::PointToSegDist(double x, double y, double x1, double y1, double x2, double y2)
{
double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
--
Gitblit v1.9.3