diff --git a/Ink Canvas/Controls/FixedAspectRatioPanel.cs b/Ink Canvas/Controls/FixedAspectRatioPanel.cs new file mode 100644 index 00000000..02ac0d97 --- /dev/null +++ b/Ink Canvas/Controls/FixedAspectRatioPanel.cs @@ -0,0 +1,77 @@ +using System.Windows; +using System.Windows.Controls; + +namespace Ink_Canvas.Controls +{ + /// + /// 在父容器可用空间内计算最大的固定宽高比矩形, + /// 子元素按真实布局尺寸排列(无任何缩放变换),多余空间居中留白。 + /// + public class FixedAspectRatioPanel : Panel + { + public double AspectRatio + { + get => (double)GetValue(AspectRatioProperty); + set => SetValue(AspectRatioProperty, value); + } + + public static readonly DependencyProperty AspectRatioProperty = + DependencyProperty.Register( + nameof(AspectRatio), + typeof(double), + typeof(FixedAspectRatioPanel), + new PropertyMetadata(16.0 / 9.0, (d, _) => ((FixedAspectRatioPanel)d).InvalidateMeasure())); + + protected override Size MeasureOverride(Size availableSize) + { + double ratio = AspectRatio; + double contentWidth, contentHeight; + + double widthByHeight = availableSize.Height * ratio; + if (widthByHeight <= availableSize.Width) + { + contentWidth = widthByHeight; + contentHeight = availableSize.Height; + } + else + { + contentWidth = availableSize.Width; + contentHeight = availableSize.Width / ratio; + } + + if (double.IsInfinity(contentWidth)) contentWidth = 0; + if (double.IsInfinity(contentHeight)) contentHeight = 0; + + foreach (UIElement child in InternalChildren) + child.Measure(new Size(contentWidth, contentHeight)); + + return new Size(contentWidth, contentHeight); + } + + protected override Size ArrangeOverride(Size finalSize) + { + double ratio = AspectRatio; + double contentWidth, contentHeight; + + double widthByHeight = finalSize.Height * ratio; + if (widthByHeight <= finalSize.Width) + { + contentWidth = widthByHeight; + contentHeight = finalSize.Height; + } + else + { + contentWidth = finalSize.Width; + contentHeight = finalSize.Width / ratio; + } + + double left = (finalSize.Width - contentWidth) / 2; + double top = (finalSize.Height - contentHeight) / 2; + + foreach (UIElement child in InternalChildren) + child.Arrange(new Rect(left, top, contentWidth, contentHeight)); + + return finalSize; + } + } +} diff --git a/Ink Canvas/Helpers/PPTUIManager.cs b/Ink Canvas/Helpers/PPTUIManager.cs index 74f299b5..6194fda6 100644 --- a/Ink Canvas/Helpers/PPTUIManager.cs +++ b/Ink Canvas/Helpers/PPTUIManager.cs @@ -15,6 +15,14 @@ public class PPTUIManager public int PPTButtonsDisplayOption { get; set; } = 2222; public int PPTSButtonsOption { get; set; } = 221; public int PPTBButtonsOption { get; set; } = 121; + public bool PPTLSButtonShowPageNumber { get; set; } = true; + public bool PPTRSButtonShowPageNumber { get; set; } = true; + public bool PPTLBButtonShowPageNumber { get; set; } = false; + public bool PPTRBButtonShowPageNumber { get; set; } = false; + public bool PPTLSButtonBlackBackground { get; set; } = false; + public bool PPTRSButtonBlackBackground { get; set; } = false; + public bool PPTLBButtonBlackBackground { get; set; } = false; + public bool PPTRBButtonBlackBackground { get; set; } = false; public int PPTLSButtonPosition { get; set; } = 0; public int PPTRSButtonPosition { get; set; } = 0; public int PPTLBButtonPosition { get; set; } = 0; @@ -256,7 +264,7 @@ public void UpdateNavigationPanelsVisibility() _mainWindow.RightBottomPanelForPPTNavigation.Margin = new Thickness(0, 0, 6 + PPTRBButtonPosition, 6); // 根据显示选项设置面板可见性 - var displayOption = PPTButtonsDisplayOption.ToString(); + var displayOption = PPTButtonsDisplayOption.ToString().PadLeft(4, '1'); if (displayOption.Length >= 4) { var options = displayOption.ToCharArray(); @@ -400,24 +408,17 @@ private void UpdateSideButtonStyles() { try { - var sideOption = PPTSButtonsOption.ToString(); - if (sideOption.Length < 3) return; - - var options = sideOption.ToCharArray(); - - // 页码按钮显示 - var pageButtonVisibility = options[0] == '2' ? Visibility.Visible : Visibility.Collapsed; - _mainWindow.LeftSidePanelForPPTNavigation.SetPageButtonVisibility(pageButtonVisibility); - _mainWindow.RightSidePanelForPPTNavigation.SetPageButtonVisibility(pageButtonVisibility); - - // 透明度 + // 左侧按钮 + _mainWindow.LeftSidePanelForPPTNavigation.SetPageButtonVisibility( + PPTLSButtonShowPageNumber ? Visibility.Visible : Visibility.Collapsed); _mainWindow.LeftSidePanelForPPTNavigation.SetBarOpacity(PPTLSButtonOpacity); - _mainWindow.RightSidePanelForPPTNavigation.SetBarOpacity(PPTRSButtonOpacity); + _mainWindow.LeftSidePanelForPPTNavigation.ApplyTheme(PPTLSButtonBlackBackground); - // 颜色主题 - bool isDarkTheme = options[2] == '2'; - _mainWindow.LeftSidePanelForPPTNavigation.ApplyTheme(isDarkTheme); - _mainWindow.RightSidePanelForPPTNavigation.ApplyTheme(isDarkTheme); + // 右侧按钮 + _mainWindow.RightSidePanelForPPTNavigation.SetPageButtonVisibility( + PPTRSButtonShowPageNumber ? Visibility.Visible : Visibility.Collapsed); + _mainWindow.RightSidePanelForPPTNavigation.SetBarOpacity(PPTRSButtonOpacity); + _mainWindow.RightSidePanelForPPTNavigation.ApplyTheme(PPTRSButtonBlackBackground); } catch (Exception ex) { @@ -429,24 +430,17 @@ private void UpdateBottomButtonStyles() { try { - var bottomOption = PPTBButtonsOption.ToString(); - if (bottomOption.Length < 3) return; - - var options = bottomOption.ToCharArray(); - - // 页码按钮显示 - var pageButtonVisibility = options[0] == '2' ? Visibility.Visible : Visibility.Collapsed; - _mainWindow.LeftBottomPanelForPPTNavigation.SetPageButtonVisibility(pageButtonVisibility); - _mainWindow.RightBottomPanelForPPTNavigation.SetPageButtonVisibility(pageButtonVisibility); - - // 透明度 + // 左下按钮 + _mainWindow.LeftBottomPanelForPPTNavigation.SetPageButtonVisibility( + PPTLBButtonShowPageNumber ? Visibility.Visible : Visibility.Collapsed); _mainWindow.LeftBottomPanelForPPTNavigation.SetBarOpacity(PPTLBButtonOpacity); - _mainWindow.RightBottomPanelForPPTNavigation.SetBarOpacity(PPTRBButtonOpacity); + _mainWindow.LeftBottomPanelForPPTNavigation.ApplyTheme(PPTLBButtonBlackBackground); - // 颜色主题 - bool isDarkTheme = options[2] == '2'; - _mainWindow.LeftBottomPanelForPPTNavigation.ApplyTheme(isDarkTheme); - _mainWindow.RightBottomPanelForPPTNavigation.ApplyTheme(isDarkTheme); + // 右下按钮 + _mainWindow.RightBottomPanelForPPTNavigation.SetPageButtonVisibility( + PPTRBButtonShowPageNumber ? Visibility.Visible : Visibility.Collapsed); + _mainWindow.RightBottomPanelForPPTNavigation.SetBarOpacity(PPTRBButtonOpacity); + _mainWindow.RightBottomPanelForPPTNavigation.ApplyTheme(PPTRBButtonBlackBackground); } catch (Exception ex) { diff --git a/Ink Canvas/MainWindow_cs/MW_PPT.cs b/Ink Canvas/MainWindow_cs/MW_PPT.cs index eab761db..bcf9e762 100644 --- a/Ink Canvas/MainWindow_cs/MW_PPT.cs +++ b/Ink Canvas/MainWindow_cs/MW_PPT.cs @@ -314,6 +314,7 @@ public void InitializePPTManagers() // 初始化UI管理器 _pptUIManager = new PPTUIManager(this); + Settings.PowerPointSettings.MigrateLegacyButtonOptions(); _pptUIManager.ShowPPTButton = Settings.PowerPointSettings.ShowPPTButton; _pptUIManager.PPTButtonsDisplayOption = Settings.PowerPointSettings.PPTButtonsDisplayOption; _pptUIManager.PPTSButtonsOption = Settings.PowerPointSettings.PPTSButtonsOption; @@ -324,6 +325,19 @@ public void InitializePPTManagers() _pptUIManager.PPTRBButtonPosition = Settings.PowerPointSettings.PPTRBButtonPosition; _pptUIManager.EnablePPTButtonPageClickable = Settings.PowerPointSettings.EnablePPTButtonPageClickable; _pptUIManager.EnablePPTButtonLongPressPageTurn = Settings.PowerPointSettings.EnablePPTButtonLongPressPageTurn; + _pptUIManager.PPTLSButtonOpacity = Settings.PowerPointSettings.PPTLSButtonOpacity; + _pptUIManager.PPTRSButtonOpacity = Settings.PowerPointSettings.PPTRSButtonOpacity; + _pptUIManager.PPTLBButtonOpacity = Settings.PowerPointSettings.PPTLBButtonOpacity; + _pptUIManager.PPTRBButtonOpacity = Settings.PowerPointSettings.PPTRBButtonOpacity; + _pptUIManager.PPTLSButtonShowPageNumber = Settings.PowerPointSettings.PPTLSButtonShowPageNumber; + _pptUIManager.PPTRSButtonShowPageNumber = Settings.PowerPointSettings.PPTRSButtonShowPageNumber; + _pptUIManager.PPTLBButtonShowPageNumber = Settings.PowerPointSettings.PPTLBButtonShowPageNumber; + _pptUIManager.PPTRBButtonShowPageNumber = Settings.PowerPointSettings.PPTRBButtonShowPageNumber; + _pptUIManager.PPTLSButtonBlackBackground = Settings.PowerPointSettings.PPTLSButtonBlackBackground; + _pptUIManager.PPTRSButtonBlackBackground = Settings.PowerPointSettings.PPTRSButtonBlackBackground; + _pptUIManager.PPTLBButtonBlackBackground = Settings.PowerPointSettings.PPTLBButtonBlackBackground; + _pptUIManager.PPTRBButtonBlackBackground = Settings.PowerPointSettings.PPTRBButtonBlackBackground; + _pptUIManager.PPTNavBarScale = Settings.PowerPointSettings.PPTNavBarScale; LogHelper.WriteLogToFile("PPT管理器初始化完成", LogHelper.LogType.Event); } diff --git a/Ink Canvas/MainWindow_cs/MW_Settings.cs b/Ink Canvas/MainWindow_cs/MW_Settings.cs index 299af31f..6e2f7a8d 100644 --- a/Ink Canvas/MainWindow_cs/MW_Settings.cs +++ b/Ink Canvas/MainWindow_cs/MW_Settings.cs @@ -500,6 +500,7 @@ public void UpdatePPTUIManagerSettings() { if (_pptUIManager != null && IsInPPTPresentationMode) { + Settings.PowerPointSettings.MigrateLegacyButtonOptions(); _pptUIManager.PPTButtonsDisplayOption = Settings.PowerPointSettings.PPTButtonsDisplayOption; _pptUIManager.PPTSButtonsOption = Settings.PowerPointSettings.PPTSButtonsOption; _pptUIManager.PPTBButtonsOption = Settings.PowerPointSettings.PPTBButtonsOption; @@ -513,6 +514,14 @@ public void UpdatePPTUIManagerSettings() _pptUIManager.PPTRSButtonOpacity = Settings.PowerPointSettings.PPTRSButtonOpacity; _pptUIManager.PPTLBButtonOpacity = Settings.PowerPointSettings.PPTLBButtonOpacity; _pptUIManager.PPTRBButtonOpacity = Settings.PowerPointSettings.PPTRBButtonOpacity; + _pptUIManager.PPTLSButtonShowPageNumber = Settings.PowerPointSettings.PPTLSButtonShowPageNumber; + _pptUIManager.PPTRSButtonShowPageNumber = Settings.PowerPointSettings.PPTRSButtonShowPageNumber; + _pptUIManager.PPTLBButtonShowPageNumber = Settings.PowerPointSettings.PPTLBButtonShowPageNumber; + _pptUIManager.PPTRBButtonShowPageNumber = Settings.PowerPointSettings.PPTRBButtonShowPageNumber; + _pptUIManager.PPTLSButtonBlackBackground = Settings.PowerPointSettings.PPTLSButtonBlackBackground; + _pptUIManager.PPTRSButtonBlackBackground = Settings.PowerPointSettings.PPTRSButtonBlackBackground; + _pptUIManager.PPTLBButtonBlackBackground = Settings.PowerPointSettings.PPTLBButtonBlackBackground; + _pptUIManager.PPTRBButtonBlackBackground = Settings.PowerPointSettings.PPTRBButtonBlackBackground; _pptUIManager.PPTNavBarScale = Settings.PowerPointSettings.PPTNavBarScale; _pptUIManager.UpdateNavigationPanelsVisibility(); _pptUIManager.UpdateNavigationButtonStyles(); diff --git a/Ink Canvas/Properties/PPTStrings.Designer.cs b/Ink Canvas/Properties/PPTStrings.Designer.cs index 540daf4d..82334a90 100644 --- a/Ink Canvas/Properties/PPTStrings.Designer.cs +++ b/Ink Canvas/Properties/PPTStrings.Designer.cs @@ -68,6 +68,16 @@ public static string GetString(string key) public static string FlipButtonsScale => ResourceManager.GetString(nameof(FlipButtonsScale), _resourceCulture); + public static string FlipButtonsSettingHint => ResourceManager.GetString(nameof(FlipButtonsSettingHint), _resourceCulture); + + public static string Configure => ResourceManager.GetString(nameof(Configure), _resourceCulture); + + public static string GlobalSettings => ResourceManager.GetString(nameof(GlobalSettings), _resourceCulture); + + public static string Positions => ResourceManager.GetString(nameof(Positions), _resourceCulture); + + public static string EnablePositionButton => ResourceManager.GetString(nameof(EnablePositionButton), _resourceCulture); + public static string GoToFirstPageOnReenter => ResourceManager.GetString(nameof(GoToFirstPageOnReenter), _resourceCulture); public static string GroupTitle => ResourceManager.GetString(nameof(GroupTitle), _resourceCulture); diff --git a/Ink Canvas/Properties/PPTStrings.en-US.resx b/Ink Canvas/Properties/PPTStrings.en-US.resx index 21a283da..802b5c63 100644 --- a/Ink Canvas/Properties/PPTStrings.en-US.resx +++ b/Ink Canvas/Properties/PPTStrings.en-US.resx @@ -84,6 +84,21 @@ Page-turn button size + + Configure the position, appearance, and behavior of page-turn buttons + + + Configure + + + Global settings + + + Display positions + + + Enable {0} button + Go to first slide when starting a slideshow diff --git a/Ink Canvas/Properties/PPTStrings.resx b/Ink Canvas/Properties/PPTStrings.resx index 4e15d78d..2b7ba71f 100644 --- a/Ink Canvas/Properties/PPTStrings.resx +++ b/Ink Canvas/Properties/PPTStrings.resx @@ -84,6 +84,21 @@ 翻页按钮大小 + + 配置翻页按钮的位置、外观与行为 + + + 配置 + + + 全局设置 + + + 显示位置 + + + 启用{0}按钮 + 进入放映时回到首页 diff --git a/Ink Canvas/Properties/PPTStrings.zh-ME.resx b/Ink Canvas/Properties/PPTStrings.zh-ME.resx index 4fdcd701..84756351 100644 --- a/Ink Canvas/Properties/PPTStrings.zh-ME.resx +++ b/Ink Canvas/Properties/PPTStrings.zh-ME.resx @@ -1,4 +1,4 @@ - + @@ -84,6 +84,21 @@ 翻页按钮大小 + + 配置翻页按钮的位置、外观和行为 + + + 配置 + + + 全局设置 + + + 显示位置 + + + 启用{0}按钮 + 进放映时回到首页 diff --git a/Ink Canvas/Resources/Settings.cs b/Ink Canvas/Resources/Settings.cs index 9ef08cf9..8d93e2a3 100644 --- a/Ink Canvas/Resources/Settings.cs +++ b/Ink Canvas/Resources/Settings.cs @@ -683,6 +683,30 @@ public class PowerPointSettings [JsonProperty("pptBButtonsOption")] public int PPTBButtonsOption { get; set; } = 121; + [JsonProperty("pptLSButtonShowPageNumber")] + public bool PPTLSButtonShowPageNumber { get; set; } = true; + + [JsonProperty("pptRSButtonShowPageNumber")] + public bool PPTRSButtonShowPageNumber { get; set; } = true; + + [JsonProperty("pptLBButtonShowPageNumber")] + public bool PPTLBButtonShowPageNumber { get; set; } = false; + + [JsonProperty("pptRBButtonShowPageNumber")] + public bool PPTRBButtonShowPageNumber { get; set; } = false; + + [JsonProperty("pptLSButtonBlackBackground")] + public bool PPTLSButtonBlackBackground { get; set; } = false; + + [JsonProperty("pptRSButtonBlackBackground")] + public bool PPTRSButtonBlackBackground { get; set; } = false; + + [JsonProperty("pptLBButtonBlackBackground")] + public bool PPTLBButtonBlackBackground { get; set; } = false; + + [JsonProperty("pptRBButtonBlackBackground")] + public bool PPTRBButtonBlackBackground { get; set; } = false; + [JsonProperty("enablePPTButtonPageClickable")] public bool EnablePPTButtonPageClickable { get; set; } = true; @@ -707,6 +731,86 @@ public class PowerPointSettings [JsonProperty("pptNavBarScale")] public double PPTNavBarScale { get; set; } = 1.0; + private bool _hasMigratedButtonOptions = false; + + public string GetPPTButtonsDisplayOptionString() + { + return PPTButtonsDisplayOption.ToString().PadLeft(4, '1'); + } + + public void MigrateLegacyButtonOptions() + { + if (_hasMigratedButtonOptions) return; + _hasMigratedButtonOptions = true; + + bool changed = false; + + var dispOpt = PPTButtonsDisplayOption.ToString(); + if (dispOpt.Length < 4) + { + PPTButtonsDisplayOption = int.Parse(dispOpt.PadLeft(4, '1')); + changed = true; + dispOpt = PPTButtonsDisplayOption.ToString(); + } + + if (dispOpt.Length >= 4) + { + bool hasAnyEnabled = dispOpt[0] == '2' || dispOpt[1] == '2' || dispOpt[2] == '2' || dispOpt[3] == '2'; + if (!hasAnyEnabled) + { + PPTButtonsDisplayOption = 2222; + changed = true; + } + } + + var sideOpt = PPTSButtonsOption.ToString(); + if (sideOpt.Length >= 3) + { + bool sideShowPage = sideOpt[0] == '2'; + bool sideBlackBg = sideOpt[2] == '2'; + if (PPTLSButtonShowPageNumber == true && PPTRSButtonShowPageNumber == true) + { + PPTLSButtonShowPageNumber = sideShowPage; + PPTRSButtonShowPageNumber = sideShowPage; + changed = true; + } + if (PPTLSButtonBlackBackground == false && PPTRSButtonBlackBackground == false) + { + PPTLSButtonBlackBackground = sideBlackBg; + PPTRSButtonBlackBackground = sideBlackBg; + changed = true; + } + } + + var bottomOpt = PPTBButtonsOption.ToString(); + if (bottomOpt.Length >= 3) + { + bool bottomShowPage = bottomOpt[0] == '2'; + bool bottomBlackBg = bottomOpt[2] == '2'; + if (PPTLBButtonShowPageNumber == false && PPTRBButtonShowPageNumber == false) + { + PPTLBButtonShowPageNumber = bottomShowPage; + PPTRBButtonShowPageNumber = bottomShowPage; + changed = true; + } + if (PPTLBButtonBlackBackground == false && PPTRBButtonBlackBackground == false) + { + PPTLBButtonBlackBackground = bottomBlackBg; + PPTRBButtonBlackBackground = bottomBlackBg; + changed = true; + } + } + + if (changed) + { + try + { + Windows.SettingsViews.Helpers.SettingsManager.SaveSettingsToFile(); + } + catch { } + } + } + // -- new -- [JsonProperty("powerPointSupport")] diff --git a/Ink Canvas/Windows/SettingsViews/Helpers/SettingsActionHub.cs b/Ink Canvas/Windows/SettingsViews/Helpers/SettingsActionHub.cs index 19f3c973..31e70987 100644 --- a/Ink Canvas/Windows/SettingsViews/Helpers/SettingsActionHub.cs +++ b/Ink Canvas/Windows/SettingsViews/Helpers/SettingsActionHub.cs @@ -635,6 +635,46 @@ public static void OnPPTBButtonsOptionChanged() mw?.UpdatePPTBtnPreview(); } + public static void OnPPTButtonShowPageNumberChanged(string buttonKey, bool value) + { + var mw = GetMainWindow(); + if (mw?.PPTUIManager != null) + { + switch (buttonKey) + { + case "LS": mw.PPTUIManager.PPTLSButtonShowPageNumber = value; break; + case "RS": mw.PPTUIManager.PPTRSButtonShowPageNumber = value; break; + case "LB": mw.PPTUIManager.PPTLBButtonShowPageNumber = value; break; + case "RB": mw.PPTUIManager.PPTRBButtonShowPageNumber = value; break; + } + if (mw.IsInPPTPresentationMode) + { + mw.PPTUIManager.UpdateNavigationButtonStyles(); + } + } + mw?.UpdatePPTBtnPreview(); + } + + public static void OnPPTButtonBlackBackgroundChanged(string buttonKey, bool value) + { + var mw = GetMainWindow(); + if (mw?.PPTUIManager != null) + { + switch (buttonKey) + { + case "LS": mw.PPTUIManager.PPTLSButtonBlackBackground = value; break; + case "RS": mw.PPTUIManager.PPTRSButtonBlackBackground = value; break; + case "LB": mw.PPTUIManager.PPTLBButtonBlackBackground = value; break; + case "RB": mw.PPTUIManager.PPTRBButtonBlackBackground = value; break; + } + if (mw.IsInPPTPresentationMode) + { + mw.PPTUIManager.UpdateNavigationButtonStyles(); + } + } + mw?.UpdatePPTBtnPreview(); + } + public static void OnPPTBButtonsOptionWithOpacityChanged() { var mw = GetMainWindow(); diff --git a/Ink Canvas/Windows/SettingsViews/Pages/BoardMenuPage.xaml b/Ink Canvas/Windows/SettingsViews/Pages/BoardMenuPage.xaml index 2f077cad..1333b6b3 100644 --- a/Ink Canvas/Windows/SettingsViews/Pages/BoardMenuPage.xaml +++ b/Ink Canvas/Windows/SettingsViews/Pages/BoardMenuPage.xaml @@ -168,6 +168,6 @@ - - - - - + @@ -368,7 +369,7 @@ - - - - - + @@ -548,6 +548,6 @@