当前位置:   article > 正文

嵌入式开发之上位机工业风界面实现_上位机软件界面

上位机软件界面

      在做测控类的嵌入式系统开发时,一个精美的上位机控制软件UI是可以为系统增色不少,一般会采用组态软件来开发,我们来看看下面的界面

b7246a38df504c85a213f38c4f2c9936.png

是不是非常直观有工业质感,还可以根据实时数据进行动态的显示和动画效果,那这些炫酷的界面是怎么实现的呢,我们来探讨一下相关技术。

     首先我们看到的漂亮精美的画面是一幅一幅的png图片或者gif动图,如果我们能找到方法将这些图片根据状态或采集数据和状态的需要,实时的展示渲染出来是不是就可以了呢。

     渲染技术其实从图像系统出来就一直在进化,游戏是这方面的优秀应用场景,可以用gdi gdiplus opengl vuklan webgpu等技术实现多平台,甚至跨平台的UI

下面是一组工业风的开关,可以用双缓冲的gdi plus方式结合鼠标的操作事件进行切换显示就可以实现形象的工业控制开关

07594d108aad4d15a31da14bd958503e.pngadca1a297f724d17bd8bc10f08719141.pngd42f96cd375d4b62be2a2f735afa64b5.png8d35f2fc4cf945aba3517c403f7dbd89.png0d138901e16f4ae7be7dabf99ed8aba9.png56ef2962b046489abaac42d342cd6e55.png

下面就是一个switcherctl的类实现,可以嵌入到你的代码中实现工业开关控制

  1. // SwitcherCtrl.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "VDC300Controler.h"
  5. #include "SwitcherCtrl.h"
  6. #include "DrawFunction.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /
  13. // CSwitcherCtrl
  14. CSwitcherCtrl::CSwitcherCtrl()
  15. {
  16. }
  17. CSwitcherCtrl::~CSwitcherCtrl()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CSwitcherCtrl, CWnd)
  21. //{{AFX_MSG_MAP(CSwitcherCtrl)
  22. ON_WM_PAINT()
  23. ON_WM_LBUTTONDOWN()
  24. //}}AFX_MSG_MAP
  25. END_MESSAGE_MAP()
  26. /
  27. // CSwitcherCtrl message handlers
  28. BOOL CSwitcherCtrl::Create(DWORD dwStyle, const RECT& rect,
  29. CWnd* pParentWnd, UINT nID)
  30. {
  31. BOOL result ;
  32. static CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW) ;
  33. result = CWnd::CreateEx(NULL,
  34. className, NULL, dwStyle,
  35. rect.left, rect.top, rect.right-rect.left+45, rect.bottom-rect.top+30,
  36. pParentWnd->GetSafeHwnd(), (HMENU)nID) ;
  37. if (result != 0)
  38. {
  39. /*
  40. hFuncInst = LoadLibrary("User32.DLL");
  41. BOOL bRet=FALSE;
  42. if(hFuncInst)
  43. UpdateLayeredWindow=(MYFUNC)GetProcAddress(hFuncInst, "UpdateLayeredWindow");
  44. else
  45. {
  46. AfxMessageBox("User32.dll ERROR!");
  47. exit(0);
  48. }
  49. */
  50. //初始化gdiplus的环境
  51. // Initialize GDI+.
  52. m_Blend.BlendOp=0; //theonlyBlendOpdefinedinWindows2000
  53. m_Blend.BlendFlags=0; //nothingelseisspecial...
  54. m_Blend.AlphaFormat=1; //...
  55. m_Blend.SourceConstantAlpha=255;//AC_SRC_ALPHA
  56. //CDC *pDC;
  57. //pDC = GetDC();
  58. //DrawLed(pDC,m_nLedColor,m_nLedMode,m_nLedShape,"LED");
  59. }
  60. return result;
  61. }
  62. void CSwitcherCtrl::DrawSwitcher(int Transparent)
  63. {
  64. HDC hdcTemp=GetDC()->m_hDC;
  65. if(Transparent<0||Transparent>100) Transparent=100;
  66. m_Blend.SourceConstantAlpha=int(Transparent*2.55);//1~255
  67. RECT rct;
  68. GetClientRect(&rct);
  69. Graphics graph(hdcTemp);//m_hdcMemory);
  70. ImageFromIDResource(IDR_PNGSWITCHER,"PNG",m_pImageSwitcher);
  71. if(m_pImageSwitcher)
  72. {
  73. m_SwitchWidth =m_pImageSwitcher->GetWidth();
  74. m_SwitchHeight =m_pImageSwitcher->GetHeight();
  75. }
  76. else
  77. return ;
  78. m_bSwitcherOn?graph.DrawImage(m_pImageSwitcher,0, 0, 0, 5,m_SwitchWidth/2,m_SwitchHeight-10,UnitPixel):
  79. graph.DrawImage(m_pImageSwitcher,0, 0, m_SwitchWidth/2, 5,m_SwitchWidth/2,m_SwitchHeight-10,UnitPixel);
  80. CString strcaption;
  81. strcaption.Format("%s-%s",m_strCaption,m_bSwitcherOn?"ON":"OFF");
  82. int nLen = strlen(strcaption) + 1;
  83. int nwLen = MultiByteToWideChar(CP_ACP, 0, strcaption, nLen, NULL, 0);
  84. unsigned short lpszTitle[256];
  85. MultiByteToWideChar(CP_ACP, 0, strcaption, nLen, lpszTitle, nwLen);
  86. FontFamily fontsmallFamily(L"宋体");//选择一种字体
  87. Gdiplus::Font fontSmall(&fontsmallFamily,12,FontStyleRegular);
  88. int titlestarty=rct.bottom-20;
  89. int titlestartx=rct.left;
  90. if(m_bSwitcherOn)
  91. {
  92. graph.DrawString(lpszTitle,-1,&fontSmall,PointF(titlestartx,titlestarty),&SolidBrush(Color::Black));
  93. graph.DrawString(lpszTitle,-1,&fontSmall,PointF(titlestartx-2,titlestarty-2),&SolidBrush(Color::Red));
  94. }
  95. else
  96. {
  97. graph.DrawString(lpszTitle,-1,&fontSmall,PointF(titlestartx,titlestarty),&SolidBrush(Color::Black));
  98. graph.DrawString(lpszTitle,-1,&fontSmall,PointF(titlestartx-2,titlestarty-2),&SolidBrush(Color::White));
  99. }
  100. delete(m_pImageSwitcher);
  101. m_pImageSwitcher=NULL;
  102. ::ReleaseDC(m_hWnd,hdcTemp);
  103. hdcTemp=NULL;
  104. }
  105. /*
  106. BOOL CSwitcherCtrl::ImageFromIDResource(UINT nID, LPCTSTR sTR,Image * &pImg)
  107. {
  108. HINSTANCE hInst = AfxGetResourceHandle();
  109. HRSRC hRsrc = ::FindResource (hInst,MAKEINTRESOURCE(nID),sTR); // type
  110. if (!hRsrc)
  111. return FALSE;
  112. // load resource into memory
  113. DWORD len = SizeofResource(hInst, hRsrc);
  114. BYTE* lpRsrc = (BYTE*)LoadResource(hInst, hRsrc);
  115. if (!lpRsrc)
  116. return FALSE;
  117. // Allocate global memory on which to create stream
  118. HGLOBAL m_hMem = GlobalAlloc(GMEM_FIXED, len);
  119. BYTE* pmem = (BYTE*)GlobalLock(m_hMem);
  120. memcpy(pmem,lpRsrc,len);
  121. IStream* pstm;
  122. CreateStreamOnHGlobal(m_hMem,FALSE,&pstm);
  123. // load from stream
  124. pImg=Gdiplus::Image::FromStream(pstm);
  125. // free/release stuff
  126. GlobalUnlock(m_hMem);
  127. pstm->Release();
  128. FreeResource(lpRsrc);
  129. return TRUE;
  130. }
  131. */
  132. void CSwitcherCtrl::OnPaint()
  133. {
  134. CPaintDC dc(this); // device context for painting
  135. CRect rect;
  136. GetClientRect(&rect);
  137. // dc.FillSolidRect(rect,RGB(129,129,129));
  138. PaintBK(&dc);
  139. DrawSwitcher();
  140. // Do not call CWnd::OnPaint() for painting messages
  141. }
  142. void CSwitcherCtrl::SetSwitcher(LPCSTR strswitchname, BOOL bOn,int id,HWND hwnd)
  143. {
  144. m_ParentWnd=hwnd;
  145. m_strCaption=strswitchname;
  146. m_bSwitcherOn=bOn;
  147. //m_SwichterCallBck=CallBck;
  148. m_ID=id;
  149. }
  150. void CSwitcherCtrl::OnLButtonDown(UINT nFlags, CPoint point)
  151. {
  152. m_bSwitcherOn=1-m_bSwitcherOn;
  153. ::SendMessage(m_ParentWnd,WM_DIGOUT_SWITCH,WPARAM(m_ID),LPARAM(m_bSwitcherOn));
  154. //if(m_SwichterCallBck!=NULL)
  155. // m_SwichterCallBck(m_ID,m_bSwitcherOn);
  156. //SendMessage(
  157. Invalidate(FALSE);
  158. CWnd::OnLButtonDown(nFlags, point);
  159. }
  160. void CSwitcherCtrl::SetBkGnd(CDC *pDC)
  161. {
  162. CRect rect, rectS;
  163. CBitmap bmp, *pOldBitmap;
  164. GetClientRect(rect);
  165. GetWindowRect(rectS);
  166. GetParent()->ScreenToClient(rectS);
  167. m_dcBk.DeleteDC();
  168. m_dcBk.CreateCompatibleDC(pDC);
  169. bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
  170. if(bmp.GetSafeHandle()!=NULL)
  171. {
  172. pOldBitmap = m_dcBk.SelectObject(&bmp);
  173. m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, rectS.left, rectS.top, SRCCOPY);
  174. bmp.DeleteObject();
  175. }
  176. }
  177. void CSwitcherCtrl::PaintBK(CDC *pDC)
  178. {
  179. CRect rect;
  180. GetClientRect(rect);
  181. pDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_dcBk, 0, 0, SRCCOPY);
  182. }

 速度表盘

 b1a2833eddd448c6864aa55ba72c02cf.png68250cf416e04238b75b5d7fed670c01.png0b8c1fdffd7148d7b3c4b30df83213d6.png819d546c3edf41c9931f26599e99bc11.png63e27b0b34654cc99b7d923e57a85a3f.png

 

 同上,速度表盘或者压力表盘也可以照此方式实现,将图片作为背景图,然后自绘表指针,根据实时数据计算算出表针的旋转角度,即可实现一组精美的表盘控件。

  1. // DashBoard.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "VDC300Controler.h"
  5. #include "DashBoard.h"
  6. #include "Drawfunction.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /
  13. // CDashBoard
  14. CDashBoard::CDashBoard()
  15. {
  16. m_DashBoardName=_T("Km/h");
  17. m_speedvalue=128;
  18. m_dMinValue = 0.00f; //表量程初始值
  19. m_dMaxValue = 140.00f; //表量程终值
  20. m_nTicks = 7; //大格个数
  21. m_nSubTicks = 5; //大格中小格个数
  22. }
  23. CDashBoard::~CDashBoard()
  24. {
  25. if(m_pDashBoard!=NULL)
  26. {
  27. delete(m_pDashBoard);
  28. m_pDashBoard=NULL;
  29. }
  30. }
  31. BEGIN_MESSAGE_MAP(CDashBoard, CWnd)
  32. //{{AFX_MSG_MAP(CDashBoard)
  33. ON_WM_PAINT()
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /
  37. // CDashBoard message handlers
  38. BOOL CDashBoard::Create(DWORD dwStyle, const RECT& rect,
  39. CWnd* pParentWnd, UINT nID)
  40. {
  41. BOOL result ;
  42. static CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW) ;
  43. result = CWnd::CreateEx(NULL,
  44. className, NULL, dwStyle,
  45. rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
  46. pParentWnd->GetSafeHwnd(), (HMENU)nID) ;
  47. /*
  48. BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
  49. LPCTSTR lpszWindowName, DWORD dwStyle,
  50. int x, int y, int nWidth, int nHeight,
  51. HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL);
  52. */
  53. if (result != 0)
  54. {
  55. ImageFromIDResource(IDR_DASHBOARD,"PNG",m_pDashBoard);
  56. ImageFromIDResource(IDR_PNGNUM,"PNG",m_pImageNum);
  57. }
  58. return result;
  59. }
  60. void CDashBoard::DrawDashBoard()
  61. {
  62. CRect rect;
  63. HDC hdcTemp=GetDC()->m_hDC;
  64. GetClientRect(&rect);
  65. Bitmap *m_pBackBmp = ::new Bitmap((HBITMAP)::GetCurrentObject(m_dcBk.m_hDC, OBJ_BITMAP),NULL);
  66. Graphics CacheGraphics(m_pBackBmp );
  67. int nLen = strlen(m_DashBoardName) + 1;
  68. int nwLen = MultiByteToWideChar(CP_ACP, 0, m_DashBoardName, nLen, NULL, 0);
  69. unsigned short lpszTitle[256];
  70. MultiByteToWideChar(CP_ACP, 0, m_DashBoardName, nLen, lpszTitle, nwLen);
  71. FontFamily fontsmallFamily(L"宋体");//选择一种字体
  72. Gdiplus::Font fontSmall(&fontsmallFamily,12,FontStyleRegular);
  73. LOGFONTA lf;
  74. fontSmall.GetLogFontA(&CacheGraphics,&lf);
  75. int fontsmallWidth=abs(lf.lfHeight);
  76. int xblank=(rect.Width()-300)/2;
  77. int yblank=(rect.Height()-300)/2;
  78. CacheGraphics.DrawImage(m_pDashBoard, Rect(xblank,
  79. yblank,
  80. 300,//rect.right-xblank,
  81. 300));//rect.bottom-yblank));
  82. int midx=rect.Width()/2;
  83. int midy=rect.Height()/2;
  84. DrawScale(&CacheGraphics,CRect(xblank,
  85. yblank,
  86. 256,//rect.right-xblank,
  87. 256),midx,midy);
  88. int titlestarty=rect.bottom-yblank-60;//rect.bottom-20;
  89. int titlestartx=midx-18; //if(titlestartx<0) titlestartx=0;
  90. CacheGraphics.DrawString(lpszTitle,-1,&fontSmall,PointF(titlestartx,titlestarty),&SolidBrush(Color::Black));
  91. CacheGraphics.DrawString(lpszTitle,-1,&fontSmall,PointF(titlestartx-1,titlestarty-1),&SolidBrush(Color::White));
  92. int ThirdNum=(((int)m_speedvalue)%10);
  93. int SecondNum=(((int)m_speedvalue-ThirdNum)%100)/10;
  94. int FirstNum=(((int)m_speedvalue-SecondNum*10-ThirdNum)%1000)/100;
  95. int FourthNum=(int(m_speedvalue-FirstNum*100-SecondNum*10-ThirdNum)*10);
  96. SolidBrush brush1( Gdiplus::Color( 250, 0,0,0 ) ); //半透明红色
  97. int char_xdis=12;
  98. int char_width=10;
  99. int char_height=16;
  100. int numstartx=midx-2*(char_xdis)-6;
  101. int recwidth=5*(char_xdis);
  102. int recheight=char_height+2;
  103. int numstarty=midy+3*char_height;//(rect.right-rect.left-fontsmallWidth*(nLen-1)/2)/2; if(titlestartx<0) titlestartx=0;
  104. CacheGraphics.FillRectangle(&brush1,Gdiplus::Rect(numstartx-2,numstarty-2,recwidth,recheight));
  105. CacheGraphics.DrawImage(m_pImageNum,Rect(numstartx,numstarty,char_width,char_height), 14*FirstNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  106. CacheGraphics.DrawImage(m_pImageNum,Rect(numstartx+char_xdis,numstarty,char_width,char_height), 14*SecondNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  107. CacheGraphics.DrawImage(m_pImageNum,Rect(numstartx+char_xdis*2,numstarty,char_width,char_height), 14*ThirdNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  108. CacheGraphics.DrawImage(m_pImageNum,Rect(numstartx+char_xdis*3,numstarty,char_width,char_height), 140, 0,14,10,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  109. CacheGraphics.DrawImage(m_pImageNum,Rect(numstartx+char_xdis*4,numstarty,char_width,char_height), 14*FourthNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  110. /*
  111. CacheGraphics.DrawImage(m_pImageNum,numstartx, numstarty, 14*FirstNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  112. CacheGraphics.DrawImage(m_pImageNum,numstartx+20, numstarty, 14*SecondNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  113. CacheGraphics.DrawImage(m_pImageNum,numstartx+20*2, numstarty, 14*ThirdNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  114. CacheGraphics.DrawImage(m_pImageNum,numstartx+20*3,numstarty+15, 140, 10,14,10,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  115. CacheGraphics.DrawImage(m_pImageNum,numstartx+20*4, numstarty, 14*FourthNum, 0,14,23,UnitPixel); //该函数从m_pImageClock中剪切指定rect中的像素draw到指定位置
  116. */
  117. DrawPitch(&CacheGraphics,CRect(xblank,
  118. yblank,
  119. 256,//rect.right-xblank,
  120. 256),
  121. midx,midy);
  122. // 对CacheImage进行描画 // ......
  123. // 获得窗口的Graphics对象
  124. Graphics Graphic(hdcTemp);
  125. // 将描画好的CacheImage画到窗口上
  126. Graphic.DrawImage(m_pBackBmp, rect.left,rect.top );
  127. // CacheImage.DeleteObject();
  128. ::delete(m_pBackBmp);
  129. m_pBackBmp=NULL;
  130. // delete(m_pDashBoard);
  131. // m_pButtonPng=NULL;
  132. ::ReleaseDC(m_hWnd,hdcTemp);
  133. hdcTemp=NULL;
  134. }
  135. void CDashBoard::SetBkGnd(CDC *pDC)
  136. {
  137. CRect rect, rectS;
  138. CBitmap bmp, *pOldBitmap;
  139. GetClientRect(rect);
  140. GetWindowRect(rectS);
  141. GetParent()->ScreenToClient(rectS);
  142. m_dcBk.DeleteDC();
  143. //Gdiplus::Bitmap pBitmap(rcBounds.Width(), rcBounds.Height());
  144. m_dcBk.CreateCompatibleDC(pDC);
  145. bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
  146. pOldBitmap = m_dcBk.SelectObject(&bmp);
  147. m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, rectS.left, rectS.top, SRCCOPY);
  148. bmp.DeleteObject();
  149. Invalidate(FALSE);
  150. }
  151. void CDashBoard::SetSpeedValue(float fspeed)
  152. {
  153. if(fspeed>m_dMaxValue) m_speedvalue=m_dMaxValue;
  154. else m_speedvalue=fspeed;
  155. Invalidate(FALSE);
  156. }
  157. void CDashBoard::OnPaint()
  158. {
  159. CPaintDC dc(this); // device context for painting
  160. DrawDashBoard();
  161. }
  162. void CDashBoard::DrawScale(Graphics *pGraph, CRect rect,int midx,int midy)
  163. {
  164. //画刻度
  165. int nTicks = m_nTicks;
  166. int nSubTicks = m_nSubTicks;
  167. char strFigure[MAXNAMELENGTH + 1];
  168. const int nSidePos = 40;
  169. int nRadius = 0;
  170. if (rect.Width() <= rect.Height())
  171. {
  172. nRadius = rect.Width();
  173. }
  174. else
  175. {
  176. nRadius = rect.Height();
  177. }
  178. memset(strFigure, 0, sizeof(strFigure));
  179. double dRadius = fabs(nRadius / 2 - nRadius / 16);
  180. double dWidth = fabs(nRadius / 14);
  181. double dMaxAngle = double(300.00f / nTicks); //每个大格的角度
  182. double dMinAngle = dMaxAngle / nSubTicks; //每个小格的角度
  183. int center_x=midx;
  184. int center_y=midy;
  185. SolidBrush brush( Gdiplus::Color( 60, 0,0,255 ) ); //半透明红色
  186. pGraph->SetSmoothingMode(SmoothingModeAntiAlias);//平滑处理 抗锯齿
  187. for (int i=0; i<nTicks+1; i++) //刻度坐标
  188. {
  189. Point ptBigScale[4];//ptStartTick, ptStartTick1 ,ptEndTick,ptEndTick1;
  190. double dDrawAngle = (i * dMaxAngle + 30) * PI / 180; //
  191. dDrawAngle-=0.04;
  192. ptBigScale[0].X = int(center_x - dRadius * sin(dDrawAngle));
  193. ptBigScale[0].Y = int(center_y + dRadius * cos(dDrawAngle));
  194. ptBigScale[1].X = int(center_x - dRadius * sin(dDrawAngle) + dWidth * sin(dDrawAngle));
  195. ptBigScale[1].Y = int(center_y + dRadius * cos(dDrawAngle) - dWidth * cos(dDrawAngle));
  196. dDrawAngle += 0.08;//(i * dMaxAngle + 30) * PI / 180; //
  197. ptBigScale[3].X = int(center_x - dRadius * sin(dDrawAngle));
  198. ptBigScale[3].Y = int(center_y + dRadius * cos(dDrawAngle));
  199. ptBigScale[2].X = int(center_x - dRadius * sin(dDrawAngle) + dWidth * sin(dDrawAngle));
  200. ptBigScale[2].Y = int(center_y + dRadius * cos(dDrawAngle) - dWidth * cos(dDrawAngle));
  201. //pGraph->Polygons()
  202. pGraph->FillPolygon(&brush, ptBigScale, 4, FillModeAlternate);
  203. //pGraph->MoveTo(ptStartTick);
  204. //pGraph->LineTo(ptEndTick);
  205. sprintf(strFigure, "%.0f", (m_dMaxValue - m_dMinValue) * i / nTicks);
  206. unsigned short wcharFigure[100];
  207. unsigned short *pshort=&wcharFigure[0];
  208. FontFamily fontsmallFamily(L"黑体");//选择一种字体
  209. Gdiplus::Font fontSmall(&fontsmallFamily,12,FontStyleRegular);
  210. // LOGFONTA lf;
  211. //fontSmall.GetLogFontA(&CacheGraphics,&lf);
  212. Color fontColor(Color::Black);
  213. CharToWChar(strFigure, &pshort);
  214. //pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[0].X-20,ptBigScale[3].Y-5),&SolidBrush(Color::Black));
  215. if (dMaxAngle * (nTicks - i) - 30 < 20)
  216. {
  217. pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[2].X-30,ptBigScale[2].Y-5),&SolidBrush(fontColor));
  218. }
  219. else if (dMaxAngle * (nTicks - i) - 30 < 40)
  220. {
  221. pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[2].X-30,ptBigScale[1].Y),&SolidBrush(Color::Gray));
  222. }
  223. else if (dMaxAngle * (nTicks - i) - 30 < 60)
  224. {
  225. pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-26,ptBigScale[1].Y),&SolidBrush(fontColor));
  226. // pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[0].X-20,ptBigScale[3].Y-5),&SolidBrush(Color::Black));
  227. // pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-nSidePos+1,ptBigScale[1].Y+1),&SolidBrush(Color::Black));
  228. // pGraph->DrawString(lpszTitle,-1,&fontSmall,ptBigScale[1],&SolidBrush(Color::White));
  229. // pGraph->DrawString(ptEndTick.x - nSidePos + 1, ptEndTick.y + 1, strFigure);
  230. // pGraph->SetTextColor(RGB(0, 0, 255));
  231. // pGraph->TextOut(ptEndTick.x - nSidePos, ptEndTick.y, strFigure);
  232. }
  233. else if (dMaxAngle * (nTicks - i) - 30 <= 90)
  234. {
  235. pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-25,ptBigScale[2].Y-3),&SolidBrush(fontColor));
  236. // pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-nSidePos+1,ptBigScale[1].Y+1),&SolidBrush(Color::DarkGray));
  237. // pGraph->SetTextColor(RGB(255, 255, 255));
  238. // pGraph->TextOut(ptEndTick.x - nSidePos / 2 + 1, ptEndTick.y + 3 + 1, strFigure);
  239. // pGraph->SetTextColor(RGB(0, 0, 255));
  240. // pGraph->TextOut(ptEndTick.x - nSidePos / 2, ptEndTick.y + 3, strFigure);
  241. }
  242. else if (dMaxAngle * (nTicks - i) - 30 < 140)
  243. {
  244. pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[0].X-5,ptBigScale[1].Y),&SolidBrush(fontColor));
  245. // pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-nSidePos+1,ptBigScale[1].Y+1),&SolidBrush(Color::Black));
  246. // pGraph->SetTextColor(RGB(255, 255, 255));
  247. // pGraph->TextOut(ptEndTick.x - nSidePos / 3 + 1, ptEndTick.y + 1, strFigure);
  248. // pGraph->SetTextColor(RGB(0, 0, 255));
  249. // pGraph->TextOut(ptEndTick.x - nSidePos / 3, ptEndTick.y, strFigure);
  250. }
  251. else if (dMaxAngle * (nTicks - i) - 30 < 160)
  252. {
  253. pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X,ptBigScale[1].Y-3),&SolidBrush(fontColor));
  254. // pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-nSidePos+1,ptBigScale[1].Y+1),&SolidBrush(Color::Black));
  255. // pGraph->SetTextColor(RGB(255, 255, 255));
  256. // pGraph->TextOut(ptEndTick.x - nSidePos / 3 + 1, ptEndTick.y + 1, strFigure);
  257. // pGraph->SetTextColor(RGB(0, 0, 255));
  258. // pGraph->TextOut(ptEndTick.x - nSidePos / 3, ptEndTick.y, strFigure);
  259. }
  260. else
  261. {
  262. pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-1,ptBigScale[2].Y-5),&SolidBrush(fontColor));
  263. // pGraph->DrawString(wcharFigure,-1,&fontSmall,PointF(ptBigScale[1].X-nSidePos+1,ptBigScale[1].Y+5),&SolidBrush(Color::Black));
  264. // pGraph->SetTextColor(RGB(255, 255, 255));
  265. // pGraph->TextOut(ptEndTick.x - nSidePos / 10 + 1, ptEndTick.y + 1, strFigure);
  266. // pGraph->SetTextColor(RGB(0, 0, 255));
  267. // pGraph->TextOut(ptEndTick.x - nSidePos / 10, ptEndTick.y, strFigure);
  268. }
  269. }
  270. dWidth = fabs(nRadius / 20);
  271. Pen myPen(Color(126, 0, 0, 255), 2);
  272. for (i=0; i<nTicks; i++)
  273. {
  274. for (int j=1; j<nSubTicks; j++) //子刻度
  275. {
  276. Point ptSubStartTick, ptSubEndTick;
  277. double dDrawAngle = ((i * dMaxAngle + 30) + (j * dMinAngle)) * PI / 180;
  278. ptSubStartTick.X = int(center_x - dRadius * sin(dDrawAngle));
  279. ptSubStartTick.Y = int(center_y + dRadius * cos(dDrawAngle));
  280. ptSubEndTick.X = int(center_x - dRadius * sin(dDrawAngle) + dWidth * sin(dDrawAngle));
  281. ptSubEndTick.Y = int(center_y + dRadius * cos(dDrawAngle) - dWidth * cos(dDrawAngle));
  282. pGraph->DrawLine(&myPen,ptSubStartTick,ptSubEndTick);
  283. }
  284. }
  285. int nradius=86;
  286. int rang=16;
  287. int startspeed=40;
  288. int endspeed=80;
  289. int nmode=0;
  290. Rect rt(center_x-nradius,center_y-nradius,nradius*2,nradius*2);
  291. DrawRangArc(pGraph, center_x,center_y,rt, nradius,rang,startspeed,endspeed,nmode);
  292. nradius=86;
  293. rang=16;
  294. startspeed=100;
  295. endspeed=140;
  296. nmode=1;
  297. Rect rt1(center_x-nradius,center_y-nradius,nradius*2,nradius*2);
  298. DrawRangArc(pGraph, center_x,center_y,rt1, nradius,rang,startspeed,endspeed,nmode);
  299. nradius=70;
  300. rang=16;
  301. startspeed=60;
  302. endspeed=130;
  303. nmode=2;
  304. Rect rt2(center_x-nradius,center_y-nradius,nradius*2,nradius*2);
  305. DrawRangArc(pGraph, center_x,center_y,rt2, nradius,rang,startspeed,endspeed,nmode);
  306. }
  307. BOOL CDashBoard::CharToWChar(LPCSTR strChar, unsigned short **sWchar)
  308. {
  309. int nLen = strlen(strChar) + 1;
  310. int nwLen = MultiByteToWideChar(CP_ACP, 0, strChar, nLen, NULL, 0);
  311. MultiByteToWideChar(CP_ACP, 0, strChar, nLen, *sWchar, nwLen);
  312. return TRUE;
  313. }
  314. //#define FACTOR 1
  315. #define FACTOR 1
  316. /*
  317. Point _aNeedleSrc[5][5] = {
  318. {
  319. Point(FACTOR * 0, FACTOR * -5),
  320. Point(FACTOR * -5, FACTOR * 25),
  321. Point(FACTOR * 0, FACTOR * 100),
  322. Point(FACTOR * 5, FACTOR * 25)
  323. },{
  324. Point(FACTOR * -4, FACTOR * 0),
  325. Point(FACTOR * -3, FACTOR * 60),
  326. Point(FACTOR * 0, FACTOR * 1000),
  327. Point(FACTOR * 3, FACTOR * 60),
  328. Point(FACTOR * 4, FACTOR * 0)
  329. },{
  330. Point(FACTOR * -3, FACTOR * -13),
  331. Point(FACTOR * -3, FACTOR * 60),
  332. Point(FACTOR * 0, FACTOR * 100),
  333. Point(FACTOR * 3, FACTOR * 60),
  334. Point(FACTOR * 3, FACTOR * -13)
  335. },{
  336. Point(FACTOR * -5, FACTOR * -13),
  337. Point(FACTOR * -4, FACTOR * 20),
  338. Point(FACTOR * 0, FACTOR * 100),
  339. Point(FACTOR * 4, FACTOR * 20),
  340. Point(FACTOR * 5, FACTOR * -13)
  341. },{
  342. Point(FACTOR * -5, FACTOR * -13),
  343. Point(FACTOR * -4, FACTOR * 65),
  344. Point(FACTOR * 0, FACTOR * 100),
  345. Point(FACTOR * 4, FACTOR * 65),
  346. Point(FACTOR * 5, FACTOR * -13)
  347. }
  348. };
  349. */
  350. /*
  351. static void _DrawLine(const SCALE* pObj, int r1, int r2, float Angel) {
  352. float co = cos(Angel / 180.) * FACTOR;
  353. float si = sin(Angel / 180.) * FACTOR;
  354. int x0 = pObj->x0 * FACTOR - r1 * co;
  355. int y0 = pObj->y0 * FACTOR - r1 * si;
  356. int x1 = pObj->x0 * FACTOR - r2 * co;
  357. int y1 = pObj->y0 * FACTOR - r2 * si;
  358. GUI_AA_DrawLine(x0, y0, x1, y1);
  359. }
  360. */
  361. void CDashBoard::DrawPitch(Graphics *pGraph,CRect rect,int OxyX,int OxyY)
  362. {
  363. //Pen pen(ARGB(0xFFFF4500),1);
  364. Pen pen(Color(255, 255, 255, 255));
  365. double Angle_PerKm=(double)(300.00f / (m_dMaxValue - m_dMinValue));
  366. double Angel = (Angle_PerKm*m_speedvalue+30);//* PI / 180;
  367. double dDrawAngle = (Angel ) * PI / 180; //
  368. Matrix matrixH(1,0,0,1,OxyX,OxyY); // 定义一个单位矩阵,坐标原点在表盘中央
  369. matrixH.Rotate(Angel); // 时针旋转的角度度
  370. // matrixH.Translate(-OxyX,-OxyY);
  371. Point pointsH[]={
  372. Point(FACTOR * 0, FACTOR * -15),
  373. Point(FACTOR * -15, FACTOR * 30),
  374. Point(FACTOR * 0, FACTOR * 100),
  375. Point(FACTOR * 15, FACTOR * 30)
  376. };
  377. Point pointsH1[]={
  378. Point(FACTOR * 0, FACTOR * -5),
  379. Point(FACTOR * -5, FACTOR * 25),
  380. Point(FACTOR * 0, FACTOR * 100),
  381. Point(FACTOR * 5, FACTOR * 25)
  382. };
  383. Point pointsH2[]={
  384. Point(FACTOR * -3, FACTOR * -13),
  385. Point(FACTOR * -3, FACTOR * 60),
  386. Point(FACTOR * 0, FACTOR * 100),
  387. Point(FACTOR * 3, FACTOR * 60),
  388. Point(FACTOR * 3, FACTOR * -13)
  389. };
  390. Point pointsH3[]={
  391. Point(FACTOR * -5, FACTOR * -13),
  392. Point(FACTOR * -4, FACTOR * 20),
  393. Point(FACTOR * 0, FACTOR * 100),
  394. Point(FACTOR * 4, FACTOR * 20),
  395. Point(FACTOR * 5, FACTOR * -13)
  396. };
  397. Point pointsH4[]={
  398. Point(FACTOR * -5, FACTOR * -13),
  399. Point(FACTOR * -4, FACTOR * 65),
  400. Point(FACTOR * 0, FACTOR * 100),
  401. Point(FACTOR * 4, FACTOR * 65),
  402. Point(FACTOR * 5, FACTOR * -13)
  403. };
  404. //Point *pPoint=_aNeedleSrc[0];
  405. matrixH.TransformPoints( pointsH, 4); // 用该矩阵转换points
  406. SolidBrush brush( Gdiplus::Color( 126, 255,0,0 ) ); //半透明红色
  407. pGraph->SetSmoothingMode(SmoothingModeAntiAlias);//平滑处理 抗锯齿
  408. // 取得第一种颜色的R,G,B值
  409. COLORREF Color2=RGB(0,45,145);
  410. COLORREF Color1=RGB(255,255,255);
  411. int r1 = GetRValue(Color1);
  412. int g1 = GetGValue(Color1);
  413. int b1 = GetBValue(Color1);
  414. // 取得第二种颜色的R,G,B值
  415. int r2 = GetRValue(Color2);
  416. int g2 = GetGValue(Color2);
  417. int b2 = GetBValue(Color2);
  418. // CRect rect;
  419. // GetClientRect(&rect);
  420. int iRotation=180;
  421. // 刷子
  422. Gdiplus::LinearGradientBrush linGrBrush(Gdiplus::Rect(0, 0, rect.right,rect.bottom), // 绘制区域
  423. Gdiplus::Color(255, r1, g1, b1), // 第一种颜色
  424. Gdiplus::Color(255, r2, g2, b2), // 第二种颜色
  425. (Gdiplus::REAL)(90 - iRotation)); // 渐变色的角度
  426. //SolidBrush brush1( Gdiplus::Color(126,0,0,255) ); //半透明红色
  427. pGraph->FillPolygon(&brush, pointsH, 4,FillModeAlternate);
  428. //pGraph->FillPolygon(&brush, pointsH, 4,FillModeAlternate);
  429. pGraph->DrawPolygon(&pen, pointsH, 4);
  430. int nRadius = 0;
  431. if (rect.Width() <= rect.Height())
  432. {
  433. nRadius = rect.Width();
  434. }
  435. else
  436. {
  437. nRadius = rect.Height();
  438. }
  439. double dRadius = fabs(nRadius / 2 - nRadius / 16);
  440. int endx = int(OxyX - dRadius * sin(dDrawAngle));
  441. int endy = int(OxyY + dRadius * cos(dDrawAngle));
  442. pGraph->DrawLine(&pen,OxyX,OxyY,endx,endy);
  443. // 得到绘制区域
  444. pGraph->FillEllipse(&linGrBrush,OxyX-10,OxyY-10,20,20);
  445. // pGraph->FillCircle(&brush1,OxyX,OxyY,5);
  446. // fla=(260-0)*m_speedvalue;//(范围最大值-范围最小值)*数据百分比+范围最小值
  447. //CacheGraphics.DrawLine(&pen, midx, midy, midx + (int) (100 * cos(fla * radian)),
  448. //midy + (INT) (100 * sin(fla * radian)));
  449. // CacheGraphics.FillEllipse(&brush,midx-20,midy-20,20,20);
  450. /*
  451. Matrix matrixH(1,0,0,1,OxyX,OxyY); // 定义一个单位矩阵,坐标原点在表盘中央
  452. matrixH.Rotate(SystemTime.wHour*30+SystemTime.wMinute/2.0-180); // 时针旋转的角度度
  453. Point pointsH[] = { Point(0, 0),Point(m_HourWidth, 0),Point(0, m_HourHeight)};
  454. matrixH.Translate(-m_HourWidth/2,-m_HourHeight/6);
  455. matrixH.TransformPoints( pointsH, 3); // 用该矩阵转换points
  456. graph.DrawImage (m_pImageHHour,pointsH, 3);
  457. */
  458. }
  459. void CDashBoard::DrawRangArc(Graphics *pGraph, int OxyX,int OxyY,Rect rect,int nRadius,int nRang, float startspeed, float endspeed, int nRangMode)
  460. {
  461. //120---0 140--60 300
  462. int arc_startx=startspeed*(300/(m_dMaxValue - m_dMinValue))+120;
  463. if(arc_startx>360) arc_startx-=360;
  464. int arc_starty=(endspeed-startspeed)*(300/(m_dMaxValue - m_dMinValue));
  465. if(arc_starty>360) arc_starty-=360;
  466. double Angle_PerKm=(double)(300.00f / (m_dMaxValue - m_dMinValue));
  467. double Angel = (Angle_PerKm*startspeed+30);//* PI / 180;
  468. double dDrawAngle = (Angel ) * PI / 180; //
  469. int startx = int(OxyX - (nRadius+nRang/2) * sin(dDrawAngle));
  470. int starty = int(OxyY + (nRadius+nRang/2) * cos(dDrawAngle));
  471. int endx = int(OxyX - (nRadius+nRang/2) * sin(dDrawAngle) + nRang * sin(dDrawAngle));
  472. int endy = int(OxyY + (nRadius+nRang/2) * cos(dDrawAngle) - nRang * cos(dDrawAngle));
  473. double Angel1 = (Angle_PerKm*endspeed+30);
  474. double dDrawAngle1 = (Angel1-0.4) * PI / 180; //
  475. int startx1 = int(OxyX - (nRadius+nRang/2) * sin(dDrawAngle1));
  476. int starty1 = int(OxyY + (nRadius+nRang/2) * cos(dDrawAngle1));
  477. int endx1 = int(OxyX - (nRadius+nRang/2) * sin(dDrawAngle1) + nRang * sin(dDrawAngle1));
  478. int endy1 = int(OxyY + (nRadius+nRang/2) * cos(dDrawAngle1) - nRang * cos(dDrawAngle1));
  479. switch(nRangMode)
  480. {
  481. case 0:
  482. {
  483. int nradius=nRadius;
  484. Pen pen1(Color(255, 0, 255, 0), 1);
  485. pGraph->DrawArc(&pen1,Rect(rect.X+nRang/2,rect.Y+nRang/2,nRadius*2-nRang,nRadius*2-nRang),arc_startx+0.5,arc_starty-0.4);
  486. pGraph->DrawArc(&pen1,Rect(rect.X-nRang/2,rect.Y-nRang/2,nRadius*2+nRang,nRadius*2+nRang),arc_startx+0.5,arc_starty-0.4);
  487. pGraph->DrawLine(&pen1,startx,starty,endx,endy);
  488. pGraph->DrawLine(&pen1,startx1,starty1,endx1,endy1);
  489. Pen pen(Color(100, 0, 255, 0), nRang);
  490. pGraph->DrawArc(&pen,rect,arc_startx,arc_starty);
  491. }
  492. break;
  493. case 1:
  494. {
  495. int nradius=nRadius;
  496. Pen pen1(Color(255, 255, 0, 0), 1);
  497. pGraph->DrawArc(&pen1,Rect(rect.X+nRang/2,rect.Y+nRang/2,nRadius*2-nRang,nRadius*2-nRang),arc_startx+0.5,arc_starty-0.4);
  498. pGraph->DrawArc(&pen1,Rect(rect.X-nRang/2,rect.Y-nRang/2,nRadius*2+nRang,nRadius*2+nRang),arc_startx+0.5,arc_starty-0.4);
  499. pGraph->DrawLine(&pen1,startx,starty,endx,endy);
  500. pGraph->DrawLine(&pen1,startx1,starty1,endx1,endy1);
  501. Pen pen(Color(100, 255, 0, 0), nRang);
  502. pGraph->DrawArc(&pen,rect,arc_startx,arc_starty);
  503. }
  504. break;
  505. case 2:
  506. {
  507. int nradius=nRadius;
  508. Pen pen1(Color(255, 255, 255, 0), 1);
  509. pGraph->DrawArc(&pen1,Rect(rect.X+nRang/2,rect.Y+nRang/2,nRadius*2-nRang,nRadius*2-nRang),arc_startx+0.5,arc_starty-0.4);
  510. pGraph->DrawArc(&pen1,Rect(rect.X-nRang/2,rect.Y-nRang/2,nRadius*2+nRang,nRadius*2+nRang),arc_startx+0.5,arc_starty-0.4);
  511. pGraph->DrawLine(&pen1,startx,starty,endx,endy);
  512. pGraph->DrawLine(&pen1,startx1,starty1,endx1,endy1);
  513. Pen pen(Color(126, 255, 255, 0), nRang);
  514. pGraph->DrawArc(&pen,rect,arc_startx,arc_starty);
  515. }
  516. break;
  517. }
  518. }

 工业风的界面随着计算机软件计算的发展逐渐衍生出了现在风靡业界的数字孪生应用,也从二维的变成3维实时仿真的UI,大大的增强了数字化虚拟世界的表达现实世界的能力

 

 

 

 

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/112182
推荐阅读
相关标签
  

闽ICP备14008679号