Skip to content

Commit

Permalink
Simplify logic for #53 (#54)
Browse files Browse the repository at this point in the history
* Simplify logic for #53

- Add invisible group boxes to hold RECT of drawing area for Grid or equipped ara.
- Resize controls and fix up borders in RC to match initial size to simplify initial size handling and remove magic numbers

* Make sure all Frame dialogs use the same font to have comparable sizes

- Allow sizing of frame and scrollbars to work
- fix up scaling for icon images.
  • Loading branch information
WalterCouto authored Dec 10, 2022
1 parent 7872c69 commit 4503aa9
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 174 deletions.
1 change: 0 additions & 1 deletion Diablo Edit2/CharacterDialogBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class CCharacterDialogBase : public CDialog
CCharacterDialogBase(UINT nIDTemplate,CWnd* pParent = NULL); // 标准构造函数
virtual ~CCharacterDialogBase();
// 自定义函数
virtual CSize GetSize() const = 0;
virtual void UpdateUI(const CD2S_Struct & character) = 0;
virtual BOOL GatherData(CD2S_Struct & character) = 0;
virtual void ResetAll() = 0;
Expand Down
62 changes: 13 additions & 49 deletions Diablo Edit2/Diablo Edit2View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void CDiabloEdit2View::OnInitialUpdate()
GetParentFrame()->RecalcLayout();
//初始化界面
InitUI();
RefreshUI();
}

// CDiabloEdit2View 诊断
Expand Down Expand Up @@ -135,63 +136,27 @@ void CDiabloEdit2View::InitUI(void)

LoadText();

// Calulate minimum size for view
CSize newSize;
CSize result = m_dlgTabPage[0]->GetSize();
newSize.cx = max(result.cx, newSize.cx);
newSize.cy = max(result.cy, newSize.cy);

result = m_dlgTabPage[1]->GetSize();
newSize.cx = max(result.cx, newSize.cx);
newSize.cy = max(result.cy, newSize.cy);

// Adjust size for frame
CRect toolRect(0, 0, 0, 0);
CWnd* pBar;
WINDOWPLACEMENT wndpl;
if (pBar = GetParent()->GetDescendantWindow(AFX_IDW_TOOLBAR))
{
pBar->GetWindowPlacement(&wndpl);
if (wndpl.showCmd && SW_SHOW)
{
toolRect = wndpl.rcNormalPosition;
newSize.cy -= toolRect.Height();
}
}

if (pBar = GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR))
{
pBar->GetWindowPlacement(&wndpl);
if (wndpl.showCmd && SW_SHOW)
{
toolRect = wndpl.rcNormalPosition;
newSize.cy -= toolRect.Height();
}
}

newSize.cx += (GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXBORDER)) * 2 + GetSystemMetrics(SM_CYVSCROLL);

CRect rect;
GetWindowRect(&rect);
GetParent()->ScreenToClient(&rect);
rect.right = rect.left + newSize.cx;
rect.bottom = rect.top + newSize.cy;
m_dlgTabPage[0]->MoveWindow(rect);
m_dlgTabPage[1]->MoveWindow(rect);
SetWindowPos(NULL, -1, -1, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
GetParentFrame()->SetWindowPos(NULL, -1, -1, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
// resize views
ResizeParentToFit();
RefreshUI();
}
}

void CDiabloEdit2View::RefreshUI(void)
{
// In case of resize, the tab control needs to resize
CRect rect;
GetClientRect(&rect);

// get the current scroll bar state and adjust rect
CSize scrollPos = GetScrollPosition();
rect.left -= scrollPos.cx;
rect.top -= scrollPos.cy;
m_tcTab.MoveWindow(rect);
m_tcTab.GetClientRect(&rect);
rect.top += 20;
if(m_dlgTabPage)
for(int i = 0;i < m_nTabPageCount;++i)
m_tcTab.AdjustRect(FALSE, &rect);
if (m_dlgTabPage)
for (int i = 0; i < m_nTabPageCount; ++i)
m_dlgTabPage[i]->MoveWindow(rect);
}

Expand Down Expand Up @@ -408,4 +373,3 @@ void CDiabloEdit2View::OnLanguage3()
LoadText();
}
}

Binary file modified Diablo Edit2/DiabloEdit2.rc
Binary file not shown.
94 changes: 25 additions & 69 deletions Diablo Edit2/DlgCharBasicInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,53 +144,6 @@ BEGIN_MESSAGE_MAP(CDlgCharBasicInfo, CDialog)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CDlgCharBasicInfo::OnTcnSelchangeTab1)
END_MESSAGE_MAP()

CSize CDlgCharBasicInfo::GetSize() const
{
CRect rect;
auto pWnd = GetDlgItem(IDC_TAB1); // This control should have an pixel top position of 235
if (pWnd == nullptr || !::IsWindow(pWnd->GetSafeHwnd()))
{
GetClientRect(&rect);
return CSize(rect.Width(), rect.Height());
}

CRect rectTab;
pWnd->GetWindowRect(&rectTab);
ScreenToClient(&rectTab);

m_dlgTabPage[0]->GetWindowRect(&rect);
ScreenToClient(&rect);
CSize result = m_dlgTabPage[0]->GetSize();
result.cx += rectTab.left + rect.left;
result.cy += rectTab.top + rect.top;
CSize newSize = result;

m_dlgTabPage[1]->GetWindowRect(&rect);
ScreenToClient(&rect);
result = m_dlgTabPage[0]->GetSize();
result.cx += rectTab.left + rect.left;
result.cy += rectTab.top + rect.top;
newSize.cx = max(result.cx, newSize.cx);
newSize.cy = max(result.cy, newSize.cy);

pWnd = GetDlgItem(IDC_STATIC_GoldinSta); // This control should be the right most
if (pWnd != nullptr && ::IsWindow(pWnd->GetSafeHwnd()))
{
CRect rect2;
pWnd->GetWindowRect(&rect2);
ScreenToClient(&rect);
newSize.cx = max(newSize.cx, rect2.right + rect.left);
}

GetClientRect(&rect);
rect.right = rect.left + newSize.cx;
rect.bottom = rect.top + newSize.cy;
::SetWindowPos(GetSafeHwnd(), NULL, -1, -1, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
m_dlgTabPage[0]->MoveWindow(rect);
m_dlgTabPage[1]->MoveWindow(rect);
return newSize;
}

// 更新显示的人物信息
void CDlgCharBasicInfo::UpdateUI(const CD2S_Struct& character)
{
Expand Down Expand Up @@ -376,13 +329,37 @@ void CDlgCharBasicInfo::InitUI(void)
m_dlgTabPage[1]->Create(CDlgQuestInfo::IDD, &m_tcBasicInfo);
m_dlgTabPage[1]->ShowWindow(SW_HIDE);
//在此处添加新的属性窗体
//
// resize views
RefreshUI();

m_nTabCurSel = 0;
m_tcBasicInfo.SetCurSel(m_nTabCurSel);
m_dlgTabPage[m_nTabCurSel]->ShowWindow(SW_SHOW);
}
}

void CDlgCharBasicInfo::RefreshUI(void)
{
// In case of resize, the tab control needs to resize
CRect rect;
GetClientRect(&rect);

CRect rectTab;
m_tcBasicInfo.GetWindowRect(&rectTab);
ScreenToClient(&rectTab);
rect.top = rectTab.top;

m_tcBasicInfo.MoveWindow(rect);
m_tcBasicInfo.GetClientRect(&rect);
m_tcBasicInfo.AdjustRect(FALSE, &rect);

// resize views
if (m_dlgTabPage)
for (int i = 0; i < m_nTabPageCount; ++i)
m_dlgTabPage[i]->MoveWindow(rect);
}

void CDlgCharBasicInfo::LoadText(void)
{
TCITEM tci;
Expand Down Expand Up @@ -449,29 +426,8 @@ void CDlgCharBasicInfo::OnEnChangeLevel()

void CDlgCharBasicInfo::OnPaint()
{
RefreshUI();
CCharacterDialogBase::OnPaint();
CRect rect;
GetClientRect(&rect);

auto pWnd = GetDlgItem(IDC_TAB1); // This control should have an pixel left position of 338 and bottom position of 58
if (pWnd != nullptr && ::IsWindow(pWnd->GetSafeHwnd()))
{
CRect rectTab;
pWnd->GetWindowRect(&rectTab);
ScreenToClient(&rectTab);
rect.top = rectTab.top;
}
else
{
rect.top += 235;
}

m_tcBasicInfo.MoveWindow(rect);
m_tcBasicInfo.GetClientRect(&rect);
rect.top += 20;
if (m_dlgTabPage)
for (int i = 0; i < m_nTabPageCount; ++i)
m_dlgTabPage[i]->MoveWindow(rect);
}

void CDlgCharBasicInfo::OnTcnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
Expand Down
2 changes: 1 addition & 1 deletion Diablo Edit2/DlgCharBasicInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class CDlgCharBasicInfo : public CCharacterDialogBase
DWORD m_dwMaxGoldInStash;
// 自定义函数
public:
CSize GetSize() const;
void UpdateUI(const CD2S_Struct & character);
BOOL GatherData(CD2S_Struct & character);
void ResetAll();
void LoadText(void); //加载控件的字符串内容
private:
void InitUI(void);
void RefreshUI(void);
public:
virtual BOOL OnInitDialog();
afx_msg void OnBnClicked_Skills();
Expand Down
Loading

0 comments on commit 4503aa9

Please sign in to comment.