From 8b30a702f2e70073e57ed354519b5df5ea78749c Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期四, 05 六月 2025 08:45:39 +0800
Subject: [PATCH] 1. 添加任务停止按钮
---
SourceCode/Bond/Servo/ServoGraph.cpp | 140 +++++++++++++++++++++++++++++++++++++++-------
1 files changed, 118 insertions(+), 22 deletions(-)
diff --git a/SourceCode/Bond/Servo/ServoGraph.cpp b/SourceCode/Bond/Servo/ServoGraph.cpp
index 718661c..8e037e1 100644
--- a/SourceCode/Bond/Servo/ServoGraph.cpp
+++ b/SourceCode/Bond/Servo/ServoGraph.cpp
@@ -125,6 +125,9 @@
case WM_LBUTTONDOWN:
return pServoGraph->OnLButtonDown(wParam, lParam);
+ case WM_SIZE:
+ return pServoGraph->OnSize(wParam, lParam);
+
case WM_GETDLGCODE:
return DLGC_WANTALLKEYS;
@@ -273,6 +276,14 @@
return ::DefWindowProc(m_hWnd, WM_LBUTTONDOWN, wParam, lParam);
}
+/*
+ * WM_SIZE
+ */
+LRESULT CServoGraph::OnSize(WPARAM wParam, LPARAM lParam)
+{
+ return ::DefWindowProc(m_hWnd, WM_SIZE, wParam, lParam);
+}
+
///////////////////////////////
// WM_PAINT
LRESULT CServoGraph::OnPaint(WPARAM wParam, LPARAM lParam)
@@ -306,29 +317,9 @@
// 画IMAGE
- HDC hDCTemp = ::CreateCompatibleDC(hMemDC);
for (auto& item : m_images) {
- // 载入BMP
- if (item.hBitmap == nullptr) {
- item.hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
- item.szPath, IMAGE_BITMAP, 0, 0,
- LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
- if (item.hBitmap != nullptr) {
- BITMAP bitmap;
- ::GetObject(item.hBitmap, sizeof(BITMAP), &bitmap);
- item.bmWidth = bitmap.bmWidth;
- item.bmHeight = bitmap.bmHeight;
- }
-
- }
-
- if (item.hBitmap != nullptr) {
- ::SelectObject(hDCTemp, item.hBitmap);
- ::BitBlt(hMemDC, item.x, item.y, item.bmWidth, item.bmHeight,
- hDCTemp, 0, 0, SRCCOPY);
- }
+ DrawImage(hMemDC, item);
}
- ::DeleteDC(hDCTemp);
// 画背景指示
@@ -368,7 +359,7 @@
}
// text
- ::DrawText(hMemDC, item.szText, strlen(item.szText),
+ ::DrawText(hMemDC, item.szText, static_cast<int>(strlen(item.szText)),
&rcItem, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
}
@@ -627,3 +618,108 @@
SendMessage(m_hWndTooltip, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&tti);
}
}
+
+void CServoGraph::UpdateImageCoordinates(int id, int newX, int newY)
+{
+ IMAGE* pImage = GetImage(id);
+ if (pImage != nullptr) {
+ pImage->x = newX;
+ pImage->y = newY;
+ }
+}
+
+void CServoGraph::UpdateIndicateBoxCoordinates(int id, int newX, int newY)
+{
+ INDICATEBOX* pIndicateBox = GetIndicateBox(id);
+ if (pIndicateBox != nullptr) {
+ pIndicateBox->x = newX;
+ pIndicateBox->y = newY;
+ }
+}
+
+void CServoGraph::UpdateImageAngle(int id, float angle)
+{
+ IMAGE* pImage = GetImage(id);
+ if (pImage != nullptr) {
+ pImage->angle = angle;
+ }
+}
+
+void CServoGraph::UpdateIndicateBox1Colors(int id, COLORREF newBackgroundColor, COLORREF newFrameColor1, COLORREF newFrameColor2)
+{
+ INDICATEBOX* pIndicateBox = GetIndicateBox(id);
+ if (pIndicateBox != nullptr) {
+ pIndicateBox->box1BackgroundColor = newBackgroundColor;
+ pIndicateBox->box1FrameColor[0] = newFrameColor1;
+ pIndicateBox->box1FrameColor[1] = newFrameColor2;
+ }
+}
+
+void CServoGraph::UpdateIndicateBox2Colors(int id, COLORREF newBackgroundColor, COLORREF newFrameColor)
+{
+ INDICATEBOX* pIndicateBox = GetIndicateBox(id);
+ if (pIndicateBox != nullptr) {
+ pIndicateBox->box2BackgroundColor = newBackgroundColor;
+ pIndicateBox->box2FrameColor = newFrameColor;
+ }
+}
+
+void CServoGraph::DrawImage(HDC hMemDC, IMAGE& item)
+{
+ // 载入BMP
+ if (item.hBitmap == nullptr) {
+ item.hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
+ item.szPath, IMAGE_BITMAP, 0, 0,
+ LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE);
+ if (item.hBitmap != nullptr) {
+ BITMAP bitmap;
+ ::GetObject(item.hBitmap, sizeof(BITMAP), &bitmap);
+ item.bmWidth = bitmap.bmWidth;
+ item.bmHeight = bitmap.bmHeight;
+ }
+ }
+
+ if (item.hBitmap != nullptr) {
+ // 使用 GDI+ 加载位图,并创建GDI+ Graphics 对象
+ Bitmap bitmap(item.hBitmap, nullptr);
+ Graphics graphics(hMemDC);
+
+ // 如果图像需要旋转
+ if (item.angle != 0.0f) {
+ // 角度转换为弧度
+ float angleInRadians = item.angle;
+
+ // 获取图像中心
+ REAL cx = static_cast<REAL>(item.x + item.bmWidth / 2); // 将中心X转换为REAL类型
+ REAL cy = static_cast<REAL>(item.y + item.bmHeight / 2); // 将中心Y转换为REAL类型
+
+ // 创建旋转矩阵
+ Matrix rotateMatrix;
+ rotateMatrix.RotateAt(angleInRadians, PointF(cx, cy));
+
+ // 应用旋转矩阵到图形
+ graphics.SetTransform(&rotateMatrix);
+ }
+
+ graphics.DrawImage(&bitmap, item.x, item.y);
+ graphics.ResetTransform();
+ }
+}
+
+void CServoGraph::SetIndicateBoxData(int id, void* pData)
+{
+ INDICATEBOX* pib = GetIndicateBox(id);
+ if (pib != nullptr) {
+ pib->m_pData = pData;
+ }
+}
+
+void* CServoGraph::GetIndicateBoxData(int id)
+{
+ INDICATEBOX* pib = GetIndicateBox(id);
+ if (pib != nullptr) {
+ return pib->m_pData;
+ }
+
+ return nullptr;
+}
\ No newline at end of file
--
Gitblit v1.9.3