mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-12-02 22:28:14 +00:00
[idd] helper: add mode edit controls
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "CConfigWindow.h"
|
||||
#include "CListBox.h"
|
||||
#include "CGroupBox.h"
|
||||
#include "CEditWidget.h"
|
||||
#include <CDebug.h>
|
||||
#include <windowsx.h>
|
||||
#include <strsafe.h>
|
||||
@@ -55,6 +56,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,
|
||||
}))
|
||||
SendMessage(child, WM_SETFONT, (WPARAM)m_font.Get(), 1);
|
||||
}
|
||||
@@ -102,6 +104,10 @@ LRESULT CConfigWindow::onCreate()
|
||||
m_heightLabel.reset(new CStaticWidget(L"Height:", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
|
||||
m_refreshLabel.reset(new CStaticWidget(L"Refresh:", WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, m_hwnd));
|
||||
|
||||
m_modeWidth.reset(new CEditWidget(WS_CHILD | WS_VISIBLE | ES_LEFT, m_hwnd));
|
||||
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));
|
||||
|
||||
updateFont();
|
||||
|
||||
return 0;
|
||||
@@ -123,6 +129,9 @@ LRESULT CConfigWindow::onResize(DWORD width, DWORD height)
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,7 +139,10 @@ LRESULT CConfigWindow::onCommand(WORD id, WORD code, HWND hwnd)
|
||||
{
|
||||
if (hwnd == *m_modeBox && code == LBN_SELCHANGE && m_modes)
|
||||
{
|
||||
DEBUG_INFO(L"Selection changed to: %s", (*m_modes)[m_modeBox->getSelData()].toString().c_str());
|
||||
auto &mode = (*m_modes)[m_modeBox->getSelData()];
|
||||
m_modeWidth->setNumericValue(mode.width);
|
||||
m_modeHeight->setNumericValue(mode.height);
|
||||
m_modeRefresh->setNumericValue(mode.refresh);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
class CListBox;
|
||||
class CGroupBox;
|
||||
class CEditWidget;
|
||||
|
||||
class CConfigWindow : public CWindow
|
||||
{
|
||||
@@ -23,6 +24,10 @@ class CConfigWindow : public CWindow
|
||||
std::unique_ptr<CStaticWidget> m_heightLabel;
|
||||
std::unique_ptr<CStaticWidget> m_refreshLabel;
|
||||
|
||||
std::unique_ptr<CEditWidget> m_modeWidth;
|
||||
std::unique_ptr<CEditWidget> m_modeHeight;
|
||||
std::unique_ptr<CEditWidget> m_modeRefresh;
|
||||
|
||||
std::function<void()> m_onDestroy;
|
||||
double m_scale;
|
||||
Microsoft::WRL::Wrappers::HandleT<FontTraits> m_font;
|
||||
|
||||
36
idd/LGIddHelper/CEditWidget.cpp
Normal file
36
idd/LGIddHelper/CEditWidget.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "CEditWidget.h"
|
||||
#include <commctrl.h>
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <CDebug.h>
|
||||
|
||||
CEditWidget::CEditWidget(DWORD style, HWND parent)
|
||||
{
|
||||
m_hwnd = createWindowSimple(WC_EDIT, nullptr, style, parent, WS_EX_CLIENTEDGE);
|
||||
if (!m_hwnd)
|
||||
DEBUG_ERROR_HR(GetLastError(), "Failed to create edit control");
|
||||
}
|
||||
|
||||
std::wstring CEditWidget::getValue()
|
||||
{
|
||||
std::wstring result;
|
||||
result.resize(Edit_GetTextLength(m_hwnd));
|
||||
Edit_GetText(m_hwnd, result.data(), result.size() + 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
int CEditWidget::getNumericValue()
|
||||
{
|
||||
return std::stoi(getValue());
|
||||
}
|
||||
|
||||
void CEditWidget::setValue(const std::wstring &value)
|
||||
{
|
||||
if (!Edit_SetText(m_hwnd, value.c_str()))
|
||||
DEBUG_ERROR("Failed to update text for edit control");
|
||||
}
|
||||
|
||||
void CEditWidget::setNumericValue(int value)
|
||||
{
|
||||
setValue(std::to_wstring(value));
|
||||
}
|
||||
14
idd/LGIddHelper/CEditWidget.h
Normal file
14
idd/LGIddHelper/CEditWidget.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "CWidget.h"
|
||||
#include <string>
|
||||
|
||||
class CEditWidget : public CWidget
|
||||
{
|
||||
public:
|
||||
CEditWidget(DWORD style, HWND parent);
|
||||
std::wstring getValue();
|
||||
int getNumericValue();
|
||||
|
||||
void setValue(const std::wstring &value);
|
||||
void setNumericValue(int value);
|
||||
};
|
||||
@@ -180,6 +180,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(SolutionDir)LGCommon\*.cpp" />
|
||||
<ClCompile Include="CConfigWindow.cpp" />
|
||||
<ClCompile Include="CEditWidget.cpp" />
|
||||
<ClCompile Include="CGroupBox.cpp" />
|
||||
<ClCompile Include="CListBox.cpp" />
|
||||
<ClCompile Include="CNotifyWindow.cpp" />
|
||||
@@ -194,6 +195,7 @@ copy /Y "$(ProjectDir)VERSION" "$(SolutionDir)$(Platform)\$(Configuration)\LGIdd
|
||||
<ItemGroup>
|
||||
<CLInclude Include="$(SolutionDir)LGCommon\*.h" />
|
||||
<ClInclude Include="CConfigWindow.h" />
|
||||
<ClInclude Include="CEditWidget.h" />
|
||||
<ClInclude Include="CGroupBox.h" />
|
||||
<ClInclude Include="CListBox.h" />
|
||||
<ClInclude Include="CNotifyWindow.h" />
|
||||
|
||||
Reference in New Issue
Block a user