Skip to content

Commit

Permalink
feat: 优化 UI,更符合 Win11 风格
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Oct 5, 2022
1 parent 552bd94 commit 2510715
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 84 deletions.
6 changes: 3 additions & 3 deletions src/Magpie.Core/CursorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static std::optional<LRESULT> HostWndProc(HWND /*hWnd*/, UINT message, WPARAM /*
return 0;
}

if (!MagApp::Get().GetOptions().IsBreakpointMode()) {
if (!MagApp::Get().GetOptions().IsDebugMode()) {
SetWindowPos(MagApp::Get().GetHwndHost(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW);
}
}
Expand Down Expand Up @@ -661,7 +661,7 @@ void CursorManager::_UpdateCursorClip() {

const RECT& srcFrameRect = MagApp::Get().GetFrameSource().GetSrcFrameRect();

if (!MagApp::Get().GetOptions().IsBreakpointMode() && MagApp::Get().GetOptions().Is3DGameMode()) {
if (!MagApp::Get().GetOptions().IsDebugMode() && MagApp::Get().GetOptions().Is3DGameMode()) {
// 开启“在 3D 游戏中限制光标”则每帧都限制一次光标
_curClips = srcFrameRect;
ClipCursor(&srcFrameRect);
Expand Down Expand Up @@ -828,7 +828,7 @@ void CursorManager::_UpdateCursorClip() {
}
}

if (MagApp::Get().GetOptions().IsBreakpointMode()) {
if (MagApp::Get().GetOptions().IsDebugMode()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Magpie.Core/ImGuiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ bool ImGuiImpl::Initialize() {
}

// 断点模式下不注册鼠标钩子,否则调试时鼠标无法使用
if (!MagApp::Get().GetOptions().IsBreakpointMode() && !MagApp::Get().GetOptions().Is3DGameMode()) {
if (!MagApp::Get().GetOptions().IsDebugMode() && !MagApp::Get().GetOptions().Is3DGameMode()) {
_hHookThread = CreateThread(nullptr, 0, ThreadProc, nullptr, 0, &_hookThreadId);
if (!_hHookThread) {
Logger::Get().Win32Error("创建线程失败");
Expand Down
4 changes: 2 additions & 2 deletions src/Magpie.Core/MagApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool MagApp::Run(HWND hwndSrc, MagOptions&& options, winrt::DispatcherQueue cons
return false;
}

if (_options.IsDisableDirectFlip() && !_options.IsBreakpointMode()) {
if (_options.IsDisableDirectFlip() && !_options.IsDebugMode()) {
// 在此处创建的 DDF 窗口不会立刻显示
if (!_DisableDirectFlip()) {
Logger::Get().Error("_DisableDirectFlip 失败");
Expand Down Expand Up @@ -303,7 +303,7 @@ bool MagApp::_CreateHostWnd() {
}

_hwndHost = CreateWindowEx(
(_options.IsBreakpointMode() ? 0 : WS_EX_TOPMOST) | WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW,
(_options.IsDebugMode() ? 0 : WS_EX_TOPMOST) | WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW,
HOST_WINDOW_CLASS_NAME,
NULL, // 标题为空,否则会被添加新配置页面列为候选窗口
WS_POPUP,
Expand Down
2 changes: 1 addition & 1 deletion src/Magpie.Core/MagOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct EffectOption {

struct MagOptions {
DEFINE_FLAG_ACCESSOR(IsDisableWindowResizing, MagFlags::DisableWindowResizing, flags)
DEFINE_FLAG_ACCESSOR(IsBreakpointMode, MagFlags::BreakpointMode, flags)
DEFINE_FLAG_ACCESSOR(IsDebugMode, MagFlags::BreakpointMode, flags)
DEFINE_FLAG_ACCESSOR(IsDisableEffectCache, MagFlags::DisableEffectCache, flags)
DEFINE_FLAG_ACCESSOR(IsSaveEffectSources, MagFlags::SaveEffectSources, flags)
DEFINE_FLAG_ACCESSOR(IsWarningsAreErrors, MagFlags::WarningsAreErrors, flags)
Expand Down
2 changes: 1 addition & 1 deletion src/Magpie.Core/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const EffectDesc& Renderer::GetEffectDesc(uint32_t idx) const noexcept {
bool Renderer::_CheckSrcState() {
HWND hwndSrc = MagApp::Get().GetHwndSrc();

if (!MagApp::Get().GetOptions().IsBreakpointMode()) {
if (!MagApp::Get().GetOptions().IsDebugMode()) {
HWND hwndForeground = GetForegroundWindow();
// 在 3D 游戏模式下打开游戏内覆盖则全屏窗口可以接收焦点
if (!MagApp::Get().GetOptions().Is3DGameMode() || !IsUIVisiable() || hwndForeground != MagApp::Get().GetHwndHost()) {
Expand Down
14 changes: 4 additions & 10 deletions src/Magpie.UI/AboutPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,11 @@
</muxc:Expander.Header>
<muxc:Expander.Content>
<StackPanel Orientation="Vertical">
<local:SettingItem Title="自动下载更新"
Style="{StaticResource ExpanderContentSettingStyle}">
<local:SettingItem.ActionContent>
<ToggleSwitch />
</local:SettingItem.ActionContent>
<local:SettingItem Style="{StaticResource ExpanderContentSettingStyle}">
<CheckBox Content="自动下载更新" />
</local:SettingItem>
<local:SettingItem Title="检查预览版更新"
Style="{StaticResource ExpanderContentSettingStyle}">
<local:SettingItem.ActionContent>
<ToggleSwitch />
</local:SettingItem.ActionContent>
<local:SettingItem Style="{StaticResource ExpanderContentSettingStyle}">
<CheckBox Content="检查预览版更新" />
</local:SettingItem>
</StackPanel>
</muxc:Expander.Content>
Expand Down
6 changes: 3 additions & 3 deletions src/Magpie.UI/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ bool AppSettings::Save() {
writer.Bool(_isAutoRestore);
writer.Key("downCount");
writer.Uint(_downCount);
writer.Key("breakpointMode");
writer.Bool(_isBreakpointMode);
writer.Key("debugMode");
writer.Bool(_isDebugMode);
writer.Key("disableEffectCache");
writer.Bool(_isDisableEffectCache);
writer.Key("saveEffectSources");
Expand Down Expand Up @@ -700,7 +700,7 @@ bool AppSettings::_LoadSettings(std::string text) {
return false;
}

if (!LoadBoolSettingItem(root, "breakpointMode", _isBreakpointMode)) {
if (!LoadBoolSettingItem(root, "debugMode", _isDebugMode)) {
return false;
}
if (!LoadBoolSettingItem(root, "disableEffectCache", _isDisableEffectCache)) {
Expand Down
10 changes: 5 additions & 5 deletions src/Magpie.UI/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ class AppSettings {
_downCountChangedEvent.remove(token);
}

bool IsBreakpointMode() const noexcept {
return _isBreakpointMode;
bool IsDebugMode() const noexcept {
return _isDebugMode;
}

void IsBreakpointMode(bool value) noexcept {
_isBreakpointMode = value;
void IsDebugMode(bool value) noexcept {
_isDebugMode = value;
}

bool IsDisableEffectCache() const noexcept {
Expand Down Expand Up @@ -251,7 +251,7 @@ class AppSettings {
bool _isShowTrayIcon = true;
event<delegate<bool>> _isShowTrayIconChangedEvent;
bool _isAlwaysRunAsElevated = false;
bool _isBreakpointMode = false;
bool _isDebugMode = false;
bool _isDisableEffectCache = false;
bool _isSaveEffectSources = false;
bool _isWarningsAreErrors = false;
Expand Down
8 changes: 3 additions & 5 deletions src/Magpie.UI/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,10 @@
</muxc:Expander.Header>
<muxc:Expander.Content>
<StackPanel Orientation="Vertical">
<local:SettingItem Title="始终以管理员身份运行"
IsEnabled="{x:Bind ViewModel.IsProcessElevated, Mode=OneTime}"
<local:SettingItem IsEnabled="{x:Bind ViewModel.IsProcessElevated, Mode=OneTime}"
Style="{StaticResource ExpanderContentSettingStyle}">
<local:SettingItem.ActionContent>
<ToggleSwitch IsOn="{x:Bind ViewModel.IsAlwaysRunAsElevated, Mode=TwoWay}" />
</local:SettingItem.ActionContent>
<CheckBox Content="始终以管理员身份运行"
IsChecked="{x:Bind ViewModel.IsAlwaysRunAsElevated, Mode=TwoWay}" />
</local:SettingItem>
<muxc:InfoBar Title="以管理员身份重启 Magpie 以更改此设置"
IsClosable="False"
Expand Down
2 changes: 1 addition & 1 deletion src/Magpie.UI/MagService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void MagService::_StartScale(HWND hWnd) {
}

// 应用全局配置
options.IsBreakpointMode(settings.IsBreakpointMode());
options.IsDebugMode(settings.IsDebugMode());
options.IsDisableEffectCache(settings.IsDisableEffectCache());
options.IsSaveEffectSources(settings.IsSaveEffectSources());
options.IsWarningsAreErrors(settings.IsWarningsAreErrors());
Expand Down
9 changes: 3 additions & 6 deletions src/Magpie.UI/ScalingProfilePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,10 @@
</local:SettingItem>
</muxc:Expander.Header>
<muxc:Expander.Content>
<local:SettingItem Title="三重缓冲"
Description="允许额外的延迟以提高性能"
IsEnabled="{x:Bind ViewModel.IsVSync, Mode=OneWay}"
<local:SettingItem IsEnabled="{x:Bind ViewModel.IsVSync, Mode=OneWay}"
Style="{StaticResource ExpanderContentSettingStyle}">
<local:SettingItem.ActionContent>
<ToggleSwitch IsOn="{x:Bind ViewModel.IsTripleBuffering, Mode=TwoWay}" />
</local:SettingItem.ActionContent>
<CheckBox Content="允许额外的延迟以提高性能"
IsChecked="{x:Bind ViewModel.IsTripleBuffering, Mode=TwoWay}" />
</local:SettingItem>
</muxc:Expander.Content>
</muxc:Expander>
Expand Down
29 changes: 26 additions & 3 deletions src/Magpie.UI/SettingItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ using namespace Windows::UI::Xaml::Data;

namespace winrt::Magpie::UI::implementation {

DependencyProperty SettingItem::RawTitleProperty = DependencyProperty::Register(
L"RawTitle",
xaml_typename<IInspectable>(),
xaml_typename<Magpie::UI::SettingItem>(),
PropertyMetadata(nullptr, _OnTitleChanged)
);

DependencyProperty SettingItem::TitleProperty = DependencyProperty::Register(
L"Title",
xaml_typename<hstring>(),
Expand Down Expand Up @@ -43,6 +50,14 @@ SettingItem::SettingItem() {
InitializeComponent();
}

void SettingItem::RawTitle(IInspectable const& value) {
SetValue(RawTitleProperty, value);
}

IInspectable SettingItem::RawTitle() const {
return GetValue(RawTitleProperty);
}

void SettingItem::Title(const hstring& value) {
SetValue(TitleProperty, box_value(value));
}
Expand All @@ -51,30 +66,36 @@ hstring SettingItem::Title() const {
return GetValue(TitleProperty).as<hstring>();
}

void SettingItem::Description(IInspectable value) {
void SettingItem::Description(IInspectable const& value) {
SetValue(DescriptionProperty, value);
}

IInspectable SettingItem::Description() const {
return GetValue(DescriptionProperty);
}

void SettingItem::Icon(IInspectable value) {
void SettingItem::Icon(IInspectable const& value) {
SetValue(IconProperty, value);
}

IInspectable SettingItem::Icon() const {
return GetValue(IconProperty);
}

void SettingItem::ActionContent(IInspectable value) {
void SettingItem::ActionContent(IInspectable const& value) {
SetValue(ActionContentProperty, value);
}

IInspectable SettingItem::ActionContent() const {
return GetValue(ActionContentProperty);
}

void SettingItem::_OnRawTitleChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&) {
SettingItem* that = get_self<SettingItem>(sender.as<default_interface<SettingItem>>());
that->_Update();
that->_propertyChangedEvent(*that, PropertyChangedEventArgs{ L"RawTitle" });
}

void SettingItem::_OnTitleChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&) {
SettingItem* that = get_self<SettingItem>(sender.as<default_interface<SettingItem>>());
that->_Update();
Expand All @@ -100,6 +121,8 @@ void SettingItem::_OnActionContentChanged(DependencyObject const& sender, Depend
}

void SettingItem::_Update() {
RawTitlePresenter().Visibility(RawTitle() == nullptr ? Visibility::Collapsed : Visibility::Visible);
TitleTextBlock().Visibility(Title().empty() ? Visibility::Collapsed : Visibility::Visible);
DescriptionPresenter().Visibility(Description() == nullptr ? Visibility::Collapsed : Visibility::Visible);
IconPresenter().Visibility(Icon() == nullptr ? Visibility::Collapsed : Visibility::Visible);
}
Expand Down
12 changes: 9 additions & 3 deletions src/Magpie.UI/SettingItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ namespace winrt::Magpie::UI::implementation {
struct SettingItem : SettingItemT<SettingItem> {
SettingItem();

void RawTitle(IInspectable const& value);

IInspectable RawTitle() const;

void Title(const hstring& value);

hstring Title() const;

void Description(IInspectable value);
void Description(IInspectable const& value);

IInspectable Description() const;

void Icon(IInspectable value);
void Icon(IInspectable const& value);

IInspectable Icon() const;

void ActionContent(IInspectable value);
void ActionContent(IInspectable const& value);

IInspectable ActionContent() const;

Expand All @@ -31,12 +35,14 @@ struct SettingItem : SettingItemT<SettingItem> {
event_token PropertyChanged(Data::PropertyChangedEventHandler const& value);
void PropertyChanged(event_token const& token);

static DependencyProperty RawTitleProperty;
static DependencyProperty TitleProperty;
static DependencyProperty DescriptionProperty;
static DependencyProperty IconProperty;
static DependencyProperty ActionContentProperty;

private:
static void _OnRawTitleChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&);
static void _OnTitleChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&);
static void _OnDescriptionChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&);
static void _OnIconChanged(DependencyObject const& sender, DependencyPropertyChangedEventArgs const&);
Expand Down
4 changes: 3 additions & 1 deletion src/Magpie.UI/SettingItem.idl
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace Magpie.UI
{
[Windows.UI.Xaml.Markup.ContentProperty("RawTitle")]
[Windows.UI.Xaml.TemplateVisualState("Normal", "CommonStates")]
[Windows.UI.Xaml.TemplateVisualState("Disabled", "CommonStates")]
runtimeclass SettingItem : Windows.UI.Xaml.Controls.UserControl, [default] Windows.UI.Xaml.Data.INotifyPropertyChanged
{
SettingItem();


Object RawTitle;
String Title;
Object Description;
Object Icon;
Expand Down
8 changes: 8 additions & 0 deletions src/Magpie.UI/SettingItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
Foreground="{ThemeResource CardPrimaryForegroundBrush}"
IsTextScaleFactorEnabled="False" />

<ContentPresenter x:Name="RawTitlePresenter"
Content="{x:Bind RawTitle, Mode=OneWay}"
Grid.Column="1"
Margin="0,0,16,0"
HorizontalAlignment="Stretch"
VerticalAlignment="Center" />

<StackPanel Grid.Column="1"
Margin="0,0,16,0"
HorizontalAlignment="Stretch"
Expand Down Expand Up @@ -93,6 +100,7 @@
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Target="RawTitlePresenter.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
<Setter Target="TitleTextBlock.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
<Setter Target="DescriptionPresenter.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
<Setter Target="IconPresenter.Foreground" Value="{ThemeResource TextFillColorDisabledBrush}" />
Expand Down
Loading

0 comments on commit 2510715

Please sign in to comment.