LAPTOP-T815PCOQ\25526
2024-11-21 d84ddeea533a8e5f122cc4a2fed06e93c2aacf3d
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
ÎļþÃû´Ó SourceCode/Bond/BondEq/AxisSettingsDlg.cpp ÐÞ¸Ä
@@ -34,25 +34,27 @@
   CDialogEx::DoDataExchange(pDX);
}
CFont* CAxisSettingsDlg::GetOrCreateFont(int nFontSize)
{
   auto it = m_mapFonts.find(nFontSize);
   if (it != m_mapFonts.end()) {
      return it->second;
   }
   CFont* font = new CFont();
   LOGFONT logFont = { 0 };
   _tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
   logFont.lfHeight = -nFontSize;
   logFont.lfQuality = CLEARTYPE_QUALITY;
   font->CreateFontIndirect(&logFont);
   m_mapFonts[nFontSize] = font;
   return font;
}
void CAxisSettingsDlg::SetDefaultFont()
{
   CFont* defaultFont = nullptr;
   // å¦‚果字体管理容器中有默认大小(如 12)的字体,直接使用
   auto it = m_mapFonts.find(12);
   if (it != m_mapFonts.end()) {
      defaultFont = it->second;
   }
   else {
      // åˆ›å»ºé»˜è®¤å­—体
      defaultFont = new CFont();
      LOGFONT logFont = { 0 };
      _tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
      logFont.lfHeight = -12;
      logFont.lfQuality = CLEARTYPE_QUALITY;
      defaultFont->CreateFontIndirect(&logFont);
      m_mapFonts[12] = defaultFont; // å­˜å‚¨åˆ°å­—体管理容器
   }
   CFont* defaultFont = GetOrCreateFont(12);
   // éåŽ†æ‰€æœ‰æŽ§ä»¶ï¼Œåº”ç”¨é»˜è®¤å­—ä½“
   CWnd* pWnd = GetWindow(GW_CHILD);
@@ -62,34 +64,31 @@
   }
}
void CAxisSettingsDlg::AdjustControls(int nWidth, int nHeight)
void CAxisSettingsDlg::AdjustControls(float dScaleX, float dScaleY)
{
   CWnd* pWnd = GetWindow(GW_CHILD);
   while (pWnd) {
      UINT nCtrlID = pWnd->GetDlgCtrlID();
      int nCtrlID = pWnd->GetDlgCtrlID();
      if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end())
      {
         CRect originalRect = m_mapCtrlLayouts[nCtrlID];
         CRect newRect(
            static_cast<int>(originalRect.left * dScaleX),
            static_cast<int>(originalRect.top * dScaleY),
            static_cast<int>(originalRect.right * dScaleX),
            static_cast<int>(originalRect.bottom * dScaleY));
      CRect ctrlRect;
      pWnd->GetWindowRect(&ctrlRect);
      ScreenToClient(&ctrlRect);
         TCHAR szClassName[256];
         GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
      // è®¡ç®—控件的新位置和大小,按比例调整
      int newX = (int)(ctrlRect.left * (nWidth / (float)m_nInitialWidth));
      int newY = (int)(ctrlRect.top * (nHeight / (float)m_nInitialHeight));
      int newWidth = (int)(ctrlRect.Width() * (nWidth / (float)m_nInitialWidth));
      int newHeight = (int)(ctrlRect.Height() * (nHeight / (float)m_nInitialHeight));
         if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
            CComboBox* pComboBox = (CComboBox*)pWnd;
            pComboBox->SetItemHeight(-1, newRect.Height());  // -1 è¡¨ç¤ºæ‰€æœ‰é¡¹çš„高度
         }
      TCHAR szClassName[256];
      GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
      if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
         CComboBox* pComboBox = (CComboBox*)pWnd;
         pComboBox->SetItemHeight(-1, nHeight);  // -1 è¡¨ç¤ºæ‰€æœ‰é¡¹çš„高度
         pWnd->MoveWindow(&newRect);
         AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
      }
      pWnd->MoveWindow(newX, newY, newWidth, newHeight);
      AdjustControlFont(pWnd, newWidth, newHeight);
      // èŽ·å–ä¸‹ä¸€ä¸ªæŽ§ä»¶
      pWnd = pWnd->GetNextWindow();
   }
}
@@ -100,23 +99,10 @@
   int fontSize = nHeight / 2;
   if (fontSize < 8) fontSize = 8;
   // æ£€æŸ¥å­—体是否已经存在
   auto it = m_mapFonts.find(fontSize);
   if (it == m_mapFonts.end()) {
      // åŠ¨æ€åˆ›å»ºæ–°å­—ä½“
      CFont* newFont = new CFont();
      LOGFONT logFont = { 0 };
      _tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
      logFont.lfHeight = -fontSize;
      logFont.lfQuality = CLEARTYPE_QUALITY; // å¯ç”¨ ClearType æŠ—锯齿
      newFont->CreateFontIndirect(&logFont);
   // èŽ·å–æˆ–åˆ›å»ºå­—ä½“
   CFont* pFont = GetOrCreateFont(fontSize);
      // å­˜å‚¨åˆ°å­—体管理容器中
      m_mapFonts[fontSize] = newFont;
      it = m_mapFonts.find(fontSize);
   }
   pWnd->SetFont(it->second);
   pWnd->SetFont(pFont);
   pWnd->Invalidate(); // åˆ·æ–°æŽ§ä»¶æ˜¾ç¤º
}
@@ -152,16 +138,31 @@
   CDialogEx::OnInitDialog();
   // TODO:  åœ¨æ­¤æ·»åŠ é¢å¤–çš„åˆå§‹åŒ–
   //ModifyStyle(0, WS_THICKFRAME | WS_SIZEBOX);
   // è®¾ç½®é»˜è®¤å­—体
   SetDefaultFont();
   CRect screenRect, dlgRect, clientRect;
   GetClientRect(&clientRect);
   m_nInitialWidth = clientRect.Width();
   m_nInitialHeight = clientRect.Height();
   // åˆå§‹åŒ–默认字体
   CFont* pDefaultFont = GetOrCreateFont(12);
   // éåŽ†æ‰€æœ‰å­æŽ§ä»¶ï¼Œè®°å½•åˆå§‹ä½ç½®å¹¶è®¾ç½®é»˜è®¤å­—ä½“
   CWnd* pWnd = GetWindow(GW_CHILD);
   while (pWnd) {
      int nCtrlID = pWnd->GetDlgCtrlID();
      if (nCtrlID != -1) {
         // è®°å½•控件初始布局
         CRect ctrlRect;
         pWnd->GetWindowRect(&ctrlRect);
         ScreenToClient(&ctrlRect);
         m_mapCtrlLayouts[nCtrlID] = ctrlRect;
         // è®¾ç½®é»˜è®¤å­—体
         pWnd->SetFont(pDefaultFont);
      }
      pWnd = pWnd->GetNextWindow();
   }
   GetWindowRect(&dlgRect);
   int dlgWidth = dlgRect.Width() * 2;
   int dlgHeight = dlgRect.Height() * 2;