Skip to content

Commit

Permalink
[r5969] В класс CFloatEdit добавлена возможность задать диапазон.
Browse files Browse the repository at this point in the history
  • Loading branch information
v0lt committed Jan 17, 2021
1 parent 41274a4 commit d26f328
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
25 changes: 18 additions & 7 deletions src/apps/mplayerc/controls/FloatEdit.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
* (C) 2006-2018 see Authors.txt
* (C) 2006-2021 see Authors.txt
*
* This file is part of MPC-BE.
*
Expand Down Expand Up @@ -50,9 +50,20 @@ CFloatEdit::operator double()
{
CString s;
GetWindowTextW(s);
float f = 0;
float flt;
if (swscanf_s(s, L"%f", &flt) != 1) {
flt = 0.0f;
}
flt = std::clamp(flt, m_lower, m_upper);

return flt;
}

return (swscanf_s(s, L"%f", &f) == 1 ? f : 0);
void CFloatEdit::SetRange(float fLower, float fUpper)
{
ASSERT(fLower < fUpper);
m_lower = fLower;
m_upper = fUpper;
}

BEGIN_MESSAGE_MAP(CFloatEdit, CEdit)
Expand All @@ -72,9 +83,9 @@ void CFloatEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)

CString s;
GetWindowTextW(s);
float f = 0;
float flt = 0;
wchar_t ch;
if (swscanf_s(s, L"%f%c", &f, &ch, 1) != 1 && s != "-") {
if (swscanf_s(s, L"%f%c", &flt, &ch, 1) != 1 && s != "-") {
SetWindowTextW(str);
SetSel(nStartChar, nEndChar);
};
Expand All @@ -100,9 +111,9 @@ LRESULT CFloatEdit::OnPaste(WPARAM wParam, LPARAM lParam)
if (lr == 1) {
CString s;
GetWindowTextW(s);
float f = 0;
float flt = 0;
wchar_t ch;
if (swscanf_s(s, L"%f%c", &f, &ch, 1) != 1) {
if (swscanf_s(s, L"%f%c", &flt, &ch, 1) != 1) {
SetWindowTextW(str);
SetSel(nStartChar, nEndChar);
};
Expand Down
6 changes: 5 additions & 1 deletion src/apps/mplayerc/controls/FloatEdit.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* (C) 2003-2006 Gabest
* (C) 2006-2018 see Authors.txt
* (C) 2006-2021 see Authors.txt
*
* This file is part of MPC-BE.
*
Expand All @@ -26,10 +26,14 @@

class CFloatEdit : public CEdit
{
float m_lower = -1000000000.0f;
float m_upper = 1000000000.0f;

public:
bool GetFloat(float& f);
double operator = (double d);
operator double();
void SetRange(float fLower, float fUpper);

DECLARE_DYNAMIC(CFloatEdit)
DECLARE_MESSAGE_MAP()
Expand Down

0 comments on commit d26f328

Please sign in to comment.