Skip to content

Commit 4503aa9

Browse files
authored
Simplify logic for #53 (#54)
* 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.
1 parent 7872c69 commit 4503aa9

16 files changed

+205
-174
lines changed

Diablo Edit2/CharacterDialogBase.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ class CCharacterDialogBase : public CDialog
1212
CCharacterDialogBase(UINT nIDTemplate,CWnd* pParent = NULL); // 标准构造函数
1313
virtual ~CCharacterDialogBase();
1414
// 自定义函数
15-
virtual CSize GetSize() const = 0;
1615
virtual void UpdateUI(const CD2S_Struct & character) = 0;
1716
virtual BOOL GatherData(CD2S_Struct & character) = 0;
1817
virtual void ResetAll() = 0;

Diablo Edit2/Diablo Edit2View.cpp

Lines changed: 13 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void CDiabloEdit2View::OnInitialUpdate()
7575
GetParentFrame()->RecalcLayout();
7676
//初始化界面
7777
InitUI();
78+
RefreshUI();
7879
}
7980

8081
// CDiabloEdit2View 诊断
@@ -135,63 +136,27 @@ void CDiabloEdit2View::InitUI(void)
135136

136137
LoadText();
137138

138-
// Calulate minimum size for view
139-
CSize newSize;
140-
CSize result = m_dlgTabPage[0]->GetSize();
141-
newSize.cx = max(result.cx, newSize.cx);
142-
newSize.cy = max(result.cy, newSize.cy);
143-
144-
result = m_dlgTabPage[1]->GetSize();
145-
newSize.cx = max(result.cx, newSize.cx);
146-
newSize.cy = max(result.cy, newSize.cy);
147-
148-
// Adjust size for frame
149-
CRect toolRect(0, 0, 0, 0);
150-
CWnd* pBar;
151-
WINDOWPLACEMENT wndpl;
152-
if (pBar = GetParent()->GetDescendantWindow(AFX_IDW_TOOLBAR))
153-
{
154-
pBar->GetWindowPlacement(&wndpl);
155-
if (wndpl.showCmd && SW_SHOW)
156-
{
157-
toolRect = wndpl.rcNormalPosition;
158-
newSize.cy -= toolRect.Height();
159-
}
160-
}
161-
162-
if (pBar = GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR))
163-
{
164-
pBar->GetWindowPlacement(&wndpl);
165-
if (wndpl.showCmd && SW_SHOW)
166-
{
167-
toolRect = wndpl.rcNormalPosition;
168-
newSize.cy -= toolRect.Height();
169-
}
170-
}
171-
172-
newSize.cx += (GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXBORDER)) * 2 + GetSystemMetrics(SM_CYVSCROLL);
173-
174-
CRect rect;
175-
GetWindowRect(&rect);
176-
GetParent()->ScreenToClient(&rect);
177-
rect.right = rect.left + newSize.cx;
178-
rect.bottom = rect.top + newSize.cy;
179-
m_dlgTabPage[0]->MoveWindow(rect);
180-
m_dlgTabPage[1]->MoveWindow(rect);
181-
SetWindowPos(NULL, -1, -1, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
182-
GetParentFrame()->SetWindowPos(NULL, -1, -1, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
139+
// resize views
140+
ResizeParentToFit();
141+
RefreshUI();
183142
}
184143
}
185144

186145
void CDiabloEdit2View::RefreshUI(void)
187146
{
147+
// In case of resize, the tab control needs to resize
188148
CRect rect;
189149
GetClientRect(&rect);
150+
151+
// get the current scroll bar state and adjust rect
152+
CSize scrollPos = GetScrollPosition();
153+
rect.left -= scrollPos.cx;
154+
rect.top -= scrollPos.cy;
190155
m_tcTab.MoveWindow(rect);
191156
m_tcTab.GetClientRect(&rect);
192-
rect.top += 20;
193-
if(m_dlgTabPage)
194-
for(int i = 0;i < m_nTabPageCount;++i)
157+
m_tcTab.AdjustRect(FALSE, &rect);
158+
if (m_dlgTabPage)
159+
for (int i = 0; i < m_nTabPageCount; ++i)
195160
m_dlgTabPage[i]->MoveWindow(rect);
196161
}
197162

@@ -408,4 +373,3 @@ void CDiabloEdit2View::OnLanguage3()
408373
LoadText();
409374
}
410375
}
411-

Diablo Edit2/DiabloEdit2.rc

4.09 KB
Binary file not shown.

Diablo Edit2/DlgCharBasicInfo.cpp

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -144,53 +144,6 @@ BEGIN_MESSAGE_MAP(CDlgCharBasicInfo, CDialog)
144144
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CDlgCharBasicInfo::OnTcnSelchangeTab1)
145145
END_MESSAGE_MAP()
146146

147-
CSize CDlgCharBasicInfo::GetSize() const
148-
{
149-
CRect rect;
150-
auto pWnd = GetDlgItem(IDC_TAB1); // This control should have an pixel top position of 235
151-
if (pWnd == nullptr || !::IsWindow(pWnd->GetSafeHwnd()))
152-
{
153-
GetClientRect(&rect);
154-
return CSize(rect.Width(), rect.Height());
155-
}
156-
157-
CRect rectTab;
158-
pWnd->GetWindowRect(&rectTab);
159-
ScreenToClient(&rectTab);
160-
161-
m_dlgTabPage[0]->GetWindowRect(&rect);
162-
ScreenToClient(&rect);
163-
CSize result = m_dlgTabPage[0]->GetSize();
164-
result.cx += rectTab.left + rect.left;
165-
result.cy += rectTab.top + rect.top;
166-
CSize newSize = result;
167-
168-
m_dlgTabPage[1]->GetWindowRect(&rect);
169-
ScreenToClient(&rect);
170-
result = m_dlgTabPage[0]->GetSize();
171-
result.cx += rectTab.left + rect.left;
172-
result.cy += rectTab.top + rect.top;
173-
newSize.cx = max(result.cx, newSize.cx);
174-
newSize.cy = max(result.cy, newSize.cy);
175-
176-
pWnd = GetDlgItem(IDC_STATIC_GoldinSta); // This control should be the right most
177-
if (pWnd != nullptr && ::IsWindow(pWnd->GetSafeHwnd()))
178-
{
179-
CRect rect2;
180-
pWnd->GetWindowRect(&rect2);
181-
ScreenToClient(&rect);
182-
newSize.cx = max(newSize.cx, rect2.right + rect.left);
183-
}
184-
185-
GetClientRect(&rect);
186-
rect.right = rect.left + newSize.cx;
187-
rect.bottom = rect.top + newSize.cy;
188-
::SetWindowPos(GetSafeHwnd(), NULL, -1, -1, rect.Width(), rect.Height(), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
189-
m_dlgTabPage[0]->MoveWindow(rect);
190-
m_dlgTabPage[1]->MoveWindow(rect);
191-
return newSize;
192-
}
193-
194147
// 更新显示的人物信息
195148
void CDlgCharBasicInfo::UpdateUI(const CD2S_Struct& character)
196149
{
@@ -376,13 +329,37 @@ void CDlgCharBasicInfo::InitUI(void)
376329
m_dlgTabPage[1]->Create(CDlgQuestInfo::IDD, &m_tcBasicInfo);
377330
m_dlgTabPage[1]->ShowWindow(SW_HIDE);
378331
//在此处添加新的属性窗体
332+
//
333+
// resize views
334+
RefreshUI();
379335

380336
m_nTabCurSel = 0;
381337
m_tcBasicInfo.SetCurSel(m_nTabCurSel);
382338
m_dlgTabPage[m_nTabCurSel]->ShowWindow(SW_SHOW);
383339
}
384340
}
385341

342+
void CDlgCharBasicInfo::RefreshUI(void)
343+
{
344+
// In case of resize, the tab control needs to resize
345+
CRect rect;
346+
GetClientRect(&rect);
347+
348+
CRect rectTab;
349+
m_tcBasicInfo.GetWindowRect(&rectTab);
350+
ScreenToClient(&rectTab);
351+
rect.top = rectTab.top;
352+
353+
m_tcBasicInfo.MoveWindow(rect);
354+
m_tcBasicInfo.GetClientRect(&rect);
355+
m_tcBasicInfo.AdjustRect(FALSE, &rect);
356+
357+
// resize views
358+
if (m_dlgTabPage)
359+
for (int i = 0; i < m_nTabPageCount; ++i)
360+
m_dlgTabPage[i]->MoveWindow(rect);
361+
}
362+
386363
void CDlgCharBasicInfo::LoadText(void)
387364
{
388365
TCITEM tci;
@@ -449,29 +426,8 @@ void CDlgCharBasicInfo::OnEnChangeLevel()
449426

450427
void CDlgCharBasicInfo::OnPaint()
451428
{
429+
RefreshUI();
452430
CCharacterDialogBase::OnPaint();
453-
CRect rect;
454-
GetClientRect(&rect);
455-
456-
auto pWnd = GetDlgItem(IDC_TAB1); // This control should have an pixel left position of 338 and bottom position of 58
457-
if (pWnd != nullptr && ::IsWindow(pWnd->GetSafeHwnd()))
458-
{
459-
CRect rectTab;
460-
pWnd->GetWindowRect(&rectTab);
461-
ScreenToClient(&rectTab);
462-
rect.top = rectTab.top;
463-
}
464-
else
465-
{
466-
rect.top += 235;
467-
}
468-
469-
m_tcBasicInfo.MoveWindow(rect);
470-
m_tcBasicInfo.GetClientRect(&rect);
471-
rect.top += 20;
472-
if (m_dlgTabPage)
473-
for (int i = 0; i < m_nTabPageCount; ++i)
474-
m_dlgTabPage[i]->MoveWindow(rect);
475431
}
476432

477433
void CDlgCharBasicInfo::OnTcnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)

Diablo Edit2/DlgCharBasicInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ class CDlgCharBasicInfo : public CCharacterDialogBase
6666
DWORD m_dwMaxGoldInStash;
6767
// 自定义函数
6868
public:
69-
CSize GetSize() const;
7069
void UpdateUI(const CD2S_Struct & character);
7170
BOOL GatherData(CD2S_Struct & character);
7271
void ResetAll();
7372
void LoadText(void); //加载控件的字符串内容
7473
private:
7574
void InitUI(void);
75+
void RefreshUI(void);
7676
public:
7777
virtual BOOL OnInitDialog();
7878
afx_msg void OnBnClicked_Skills();

0 commit comments

Comments
 (0)