[idd] helper: add mode save button

This commit is contained in:
Quantum
2025-10-04 03:47:17 -04:00
committed by Geoffrey McRae
parent 124b4742e0
commit bf77128053
5 changed files with 44 additions and 8 deletions

View File

@@ -0,0 +1,10 @@
#include "CButton.h"
#include <commctrl.h>
#include <CDebug.h>
CButton::CButton(LPCWSTR title, DWORD style, HWND parent)
{
m_hwnd = createWindowSimple(WC_BUTTON, title, style, parent);
if (!m_hwnd)
DEBUG_ERROR_HR(GetLastError(), "Failed to create button");
}

View File

@@ -0,0 +1,9 @@
#pragma once
#include "CWidget.h"
class CButton : public CWidget
{
public:
CButton(LPCWSTR title, DWORD style, HWND parent);
};

View File

@@ -2,6 +2,7 @@
#include "CListBox.h"
#include "CGroupBox.h"
#include "CEditWidget.h"
#include "CButton.h"
#include <CDebug.h>
#include <windowsx.h>
#include <strsafe.h>
@@ -56,7 +57,7 @@ void CConfigWindow::updateFont()
for (HWND child : std::initializer_list<HWND>({
*m_version, *m_modeGroup, *m_modeBox, *m_widthLabel, *m_heightLabel, *m_refreshLabel,
*m_modeWidth, *m_modeHeight, *m_modeRefresh,
*m_modeWidth, *m_modeHeight, *m_modeRefresh, *m_modeUpdate,
}))
SendMessage(child, WM_SETFONT, (WPARAM)m_font.Get(), 1);
}
@@ -108,6 +109,8 @@ LRESULT CConfigWindow::onCreate()
m_modeHeight.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | ES_LEFT, m_hwnd));
m_modeRefresh.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | ES_LEFT, m_hwnd));
m_modeUpdate.reset(new CButton(L"Save", WS_CHILD | WS_VISIBLE, m_hwnd));
updateFont();
return 0;
@@ -125,13 +128,14 @@ LRESULT CConfigWindow::onResize(DWORD width, DWORD height)
WidgetPositioner pos(m_scale, width, height);
pos.pinTopLeftRight(*m_version, 12, 12, 12, 20);
pos.pinLeftTopBottom(*m_modeGroup, 12, 40, 200, 12);
pos.pinLeftTopBottom(*m_modeBox, 24, 64, 176, 96);
pos.pinBottomLeft(*m_widthLabel, 24, 72, 50, 20);
pos.pinBottomLeft(*m_heightLabel, 24, 48, 50, 20);
pos.pinBottomLeft(*m_refreshLabel, 24, 24, 50, 20);
pos.pinBottomLeft(*m_modeWidth, 75, 72, 50, 20);
pos.pinBottomLeft(*m_modeHeight, 75, 48, 50, 20);
pos.pinBottomLeft(*m_modeRefresh, 75, 24, 50, 20);
pos.pinLeftTopBottom(*m_modeBox, 24, 64, 176, 120);
pos.pinBottomLeft(*m_widthLabel, 24, 96, 50, 20);
pos.pinBottomLeft(*m_heightLabel, 24, 72, 50, 20);
pos.pinBottomLeft(*m_refreshLabel, 24, 48, 50, 20);
pos.pinBottomLeft(*m_modeWidth, 75, 96, 50, 20);
pos.pinBottomLeft(*m_modeHeight, 75, 72, 50, 20);
pos.pinBottomLeft(*m_modeRefresh, 75, 48, 50, 20);
pos.pinBottomLeft(*m_modeUpdate, 24, 20, 50, 24);
return 0;
}
@@ -144,5 +148,13 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd)
m_modeHeight->setNumericValue(mode.height);
m_modeRefresh->setNumericValue(mode.refresh);
}
else if (hwnd == *m_modeUpdate && code == BN_CLICKED && m_modes)
{
auto &mode = (*m_modes)[m_modeBox->getSelData()];
mode.width = m_modeWidth->getNumericValue();
mode.height = m_modeHeight->getNumericValue();
mode.refresh = m_modeRefresh->getNumericValue();
DEBUG_INFO(L"Updated mode to %s", mode.toString().c_str());
}
return 0;
}

View File

@@ -11,6 +11,7 @@
class CListBox;
class CGroupBox;
class CEditWidget;
class CButton;
class CConfigWindow : public CWindow
{
@@ -28,6 +29,8 @@ class CConfigWindow : public CWindow
std::unique_ptr<CEditWidget> m_modeHeight;
std::unique_ptr<CEditWidget> m_modeRefresh;
std::unique_ptr<CButton> m_modeUpdate;
std::function<void()> m_onDestroy;
double m_scale;
Microsoft::WRL::Wrappers::HandleT<FontTraits> m_font;

View File

@@ -179,6 +179,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="$(SolutionDir)LGCommon\*.cpp" />
<ClCompile Include="CButton.cpp" />
<ClCompile Include="CConfigWindow.cpp" />
<ClCompile Include="CEditWidget.cpp" />
<ClCompile Include="CGroupBox.cpp" />
@@ -194,6 +195,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
</ItemGroup>
<ItemGroup>
<CLInclude Include="$(SolutionDir)LGCommon\*.h" />
<ClInclude Include="CButton.h" />
<ClInclude Include="CConfigWindow.h" />
<ClInclude Include="CEditWidget.h" />
<ClInclude Include="CGroupBox.h" />