Skip to content

Commit 9f30bc6

Browse files
committed
滑动条控件垂直方向时改为底部为最小值;界面xml中root元素增加icon属性,用于设置ui对话框的图标
1 parent 976d66d commit 9f30bc6

14 files changed

Lines changed: 53 additions & 25 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,4 @@ __pycache__/
291291
*.sf2
292292
/MusicPlayer2/compile_time.txt
293293
!/MusicPlayer2/language/*.ini
294+
/enc_temp_folder

MusicPlayer2/UIDialog/UIDialog.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "stdafx.h"
55
#include "MusicPlayer2.h"
66
#include "UIDialog.h"
7-
#include <dwmapi.h>
87
#include "WinVersionHelper.h"
98

109
#define UI_DIALOG_TIMER_ID 1365
@@ -29,6 +28,11 @@ CUIDialog::~CUIDialog()
2928
{
3029
}
3130

31+
BOOL CUIDialog::Create(CWnd* pParent)
32+
{
33+
return CDialog::Create(IDD_UI_DIALOG, pParent);
34+
}
35+
3236
void CUIDialog::RePaintUi()
3337
{
3438
Invalidate(FALSE);
@@ -69,8 +73,10 @@ BOOL CUIDialog::OnInitDialog()
6973
CDialog::OnInitDialog();
7074

7175
//深色模式下,为对话框启用深色标题栏
76+
bool dark_mode = false;
7277
if (theApp.m_app_setting_data.dark_mode && CWinVersionHelper::IsWindows10Version1809OrLater())
7378
{
79+
dark_mode = true;
7480
BOOL darkMode = TRUE;
7581
DwmSetWindowAttribute(m_hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &darkMode, sizeof(darkMode));
7682
}
@@ -81,7 +87,8 @@ BOOL CUIDialog::OnInitDialog()
8187

8288
//设置窗口标题和图标
8389
SetWindowText(m_ui.GetUIName().c_str());
84-
SetIcon(theApp.m_icon_mgr.GetHICON(IconMgr::IT_App, IconMgr::IS_Auto, IconMgr::IS_DPI_16), FALSE);
90+
IconMgr::IconStyle icon_style = dark_mode ? IconMgr::IconStyle::IS_OutlinedLight : IconMgr::IconStyle::IS_OutlinedDark;
91+
SetIcon(theApp.m_icon_mgr.GetHICON(m_ui.GetUiIcon(), icon_style, IconMgr::IS_DPI_16), FALSE);
8592

8693
//初始化对话框大小
8794
int width = m_ui.GetCurrentTypeUi()->GetWidth(CRect());

MusicPlayer2/UIDialog/UIDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CUIDialog : public CDialog
1111
public:
1212
CUIDialog(UINT ui_res_id, CWnd* pParent = nullptr); // 标准构造函数
1313
virtual ~CUIDialog();
14+
BOOL Create(CWnd* pParent = nullptr);
1415

1516
// 对话框数据
1617
#ifdef AFX_DESIGN_TIME

MusicPlayer2/UIDialog/UITestDialog.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ CUITestDialog::CUITestDialog(CWnd* pParent)
2020

2121
UiElement::Slider* horizentol_slider = m_ui.GetCurrentTypeUi()->FindElement<UiElement::Slider>("horizontalSlider1");
2222
horizentol_slider->SetPosChangedTrigger([&](UiElement::Slider* sender) {
23-
std::wstring str = L"滑动条当前值:" + std::to_wstring(sender->GetCurPos());
23+
std::wstring str = L"水平滑动条当前值:" + std::to_wstring(sender->GetCurPos());
24+
m_info_text->SetText(str);
25+
});
26+
UiElement::Slider* vertical_slider = m_ui.GetCurrentTypeUi()->FindElement<UiElement::Slider>("verticalSlider1");
27+
vertical_slider->SetPosChangedTrigger([&](UiElement::Slider* sender) {
28+
std::wstring str = L"垂直滑动条当前值:" + std::to_wstring(sender->GetCurPos());
2429
m_info_text->SetText(str);
2530
});
2631

MusicPlayer2/UIElement/AbstractScrollArea.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ bool UiElement::AbstractScrollArea::LButtonDown(CPoint point)
131131
//点击了滚动区域
132132
else
133133
{
134+
if (Element::LButtonDown(point))
135+
return true;
134136
mouse_pressed = true;
135-
rtn = Element::LButtonDown(point);
136137
}
137138
mouse_pressed_offset = scroll_offset;
138139
mouse_pressed_pos = point;

MusicPlayer2/UIElement/Helper/UiElementHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "stdafx.h"
22
#include "UiElementHelper.h"
33

4-
IconMgr::IconType UiElementHelper::NameToIconType(const std::string& icon_name)
4+
IconMgr::IconType UiElementHelper::NameToIconType(const std::string& icon_name, IconMgr::IconType default_icon)
55
{
6-
IconMgr::IconType icon_type{ IconMgr::IT_NO_ICON };
6+
IconMgr::IconType icon_type{ default_icon };
77
if (icon_name == "app") icon_type = IconMgr::IT_App;
88
else if (icon_name == "appMonochrome") icon_type = IconMgr::IT_App_Monochrome;
99
else if (icon_name == "stop") icon_type = IconMgr::IT_Stop;

MusicPlayer2/UIElement/Helper/UiElementHelper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class UiElementHelper
44
{
55
public:
6-
static IconMgr::IconType NameToIconType(const std::string& icon_name);
6+
static IconMgr::IconType NameToIconType(const std::string& icon_name, IconMgr::IconType default_icon = IconMgr::IT_NO_ICON);
77

88
};
99

MusicPlayer2/UIElement/Slider.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ void UiElement::Slider::Draw()
106106
else
107107
{
108108
cur_point.X = rect.CenterPoint().x;
109-
cur_point.Y = rect.top;
109+
cur_point.Y = rect.bottom;
110110
}
111111

112112
if (max_val - min_val > 0)
113113
{
114114
if (orientation == Horizontal)
115115
cur_point.X = rect_back.left + static_cast<double>(rect_back.Width() * (GetCurPos() - min_val) / static_cast<double>(max_val - min_val));
116116
else
117-
cur_point.Y = rect_back.top + static_cast<double>(rect_back.Height() * (GetCurPos() - min_val) / static_cast<double>(max_val - min_val));
117+
cur_point.Y = rect_back.bottom - static_cast<double>(rect_back.Height() * (GetCurPos() - min_val) / static_cast<double>(max_val - min_val));
118118
}
119119

120120
//计算当前位置前后两部分的矩形区域
@@ -127,8 +127,8 @@ void UiElement::Slider::Draw()
127127
}
128128
else
129129
{
130-
rect_back_before_current.bottom = static_cast<int>(cur_point.Y);
131-
rect_back_after_current.top = static_cast<int>(cur_point.Y);
130+
rect_back_after_current.bottom = static_cast<int>(cur_point.Y);
131+
rect_back_before_current.top = static_cast<int>(cur_point.Y);
132132
}
133133
//分别绘制两部分背景
134134
ui->DrawRectangle(rect_back_before_current, back_color_before_curent, GetBackAlpha(true));
@@ -209,7 +209,7 @@ bool UiElement::Slider::MouseMove(CPoint point)
209209
}
210210
else
211211
{
212-
pos = min_val + (max_val - min_val) * (point.y - rect_back.top) / rect_back.Height();
212+
pos = min_val + (max_val - min_val) * (rect_back.bottom - point.y) / rect_back.Height();
213213
}
214214
CCommon::SetNumRange(pos, min_val, max_val);
215215
if (GetCurPos() != pos)

MusicPlayer2/UIElement/SliderProgressBar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool UiElement::SliderProgressBar::MouseMove(CPoint point)
4545
ui->UpdateMouseToolTip(UiElement::TooltipIndex::PROGRESS_BAR, str.c_str());
4646
ui->UpdateMouseToolTipPosition(UiElement::TooltipIndex::PROGRESS_BAR, GetRect());
4747
last_sec = song_pos_time.sec;
48-
TRACE("Progressbar mouse move\n");
48+
//TRACE("Progressbar mouse move\n");
4949
}
5050

5151
return true;

MusicPlayer2/UIElement/StackElement.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,22 @@ void UiElement::StackElement::IndexChanged()
316316
}
317317
//清空不显示的子元素的矩形区域和鼠标提示
318318
auto cur_element{ CurrentElement() };
319-
cur_element->MouseLeave();
320-
for (size_t i{}; i < childLst.size(); i++)
319+
if (cur_element != nullptr)
321320
{
322-
if (cur_element != childLst[i])
321+
cur_element->MouseLeave();
322+
for (size_t i{}; i < childLst.size(); i++)
323323
{
324-
childLst[i]->IterateAllElements([&](UiElement::Element* element) ->bool {
325-
if (element != nullptr)
326-
{
327-
element->ClearRect();
328-
element->HideTooltip();
329-
}
330-
return false;
331-
});
324+
if (cur_element != childLst[i])
325+
{
326+
childLst[i]->IterateAllElements([&](UiElement::Element* element) ->bool {
327+
if (element != nullptr)
328+
{
329+
element->ClearRect();
330+
element->HideTooltip();
331+
}
332+
return false;
333+
});
334+
}
332335
}
333336
}
334337
}

0 commit comments

Comments
 (0)