Skip to content
This repository has been archived by the owner on Aug 17, 2024. It is now read-only.

Commit

Permalink
调整翻译窗口按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
Isayama-Kagura committed Aug 12, 2022
1 parent d9cf188 commit f82e0b6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 66 deletions.
6 changes: 3 additions & 3 deletions TsubakiTranslator/BasicLibrary/WindowConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public WindowConfig()
TranslateWindowTransparency = 165;
SourceTextColor = Colors.BurlyWood;
TranslatedTextColor = Colors.WhiteSmoke;
SourceTextVisibility = "Auto";
SourceTextVisibility = true;
}

private double mainWindowWidth;
Expand All @@ -31,7 +31,7 @@ public WindowConfig()
private int translateWindowTransparency;
private Color sourceTextColor;
private Color translatedTextColor;
private string sourceTextVisibility;
private bool sourceTextVisibility;


public double MainWindowWidth
Expand Down Expand Up @@ -93,7 +93,7 @@ public Color TranslatedTextColor
set => SetProperty(ref translatedTextColor, value);
}

public string SourceTextVisibility
public bool SourceTextVisibility
{
get => sourceTextVisibility;
set => SetProperty(ref sourceTextVisibility, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net6.0-windows\publish\noRT</PublishDir>
<PublishDir>bin\Release\net6.0-windows\publish\noRT\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
</PropertyGroup>
</Project>
15 changes: 6 additions & 9 deletions TsubakiTranslator/TranslateWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
<RowDefinition />
</Grid.RowDefinitions>



<DockPanel Grid.Row="0" LastChildFill="False">

<Button DockPanel.Dock="Right" Style="{StaticResource MaterialDesignFlatAccentButton}"
Expand All @@ -37,16 +35,10 @@

<Button x:Name="PinButton"
DockPanel.Dock="Right" Style="{StaticResource MaterialDesignFlatAccentButton}"
ToolTip="不固定" Foreground="White" Cursor="Hand" Visibility="Collapsed"
ToolTip="固定开关" Foreground="White" Cursor="Hand"
Content="{materialDesign:PackIcon Kind=Pin }"
Click="Pin_Button_Click"/>

<Button x:Name="PinOffButton"
DockPanel.Dock="Right" Style="{StaticResource MaterialDesignFlatAccentButton}"
ToolTip="固定最前" Foreground="White" Cursor="Hand"
Content="{materialDesign:PackIcon Kind=PinOff }"
Click="PinOff_Button_Click"/>

<Button DockPanel.Dock="Right" Style="{StaticResource MaterialDesignFlatAccentButton}"
ToolTip="最小化" Foreground="White" Cursor="Hand"
Content="{materialDesign:PackIcon Kind=WindowMinimize }"
Expand All @@ -61,6 +53,11 @@
</Menu>

<StackPanel x:Name="TranslatedResultPanel" Orientation="Horizontal" DockPanel.Dock="Left">
<Button x:Name="SourceTextButton" Style="{StaticResource MaterialDesignFlatAccentButton}"
Foreground="White" Cursor="Hand" Height="25"
Content="{ materialDesign:PackIcon Kind=Book}" ToolTip="源文本开关"
Click="SourceText_Button_Click"/>

<Button Style="{StaticResource MaterialDesignFlatAccentButton}"
Foreground="White" Cursor="Hand" Height="25"
Content="{ materialDesign:PackIcon Kind=FormatFontSizeDecrease}" ToolTip="缩小字体"
Expand Down
85 changes: 51 additions & 34 deletions TsubakiTranslator/TranslateWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Windows.Threading;
using System.Runtime.InteropServices;
using System.Windows.Interop;
using MaterialDesignThemes.Wpf;

namespace TsubakiTranslator
{
Expand Down Expand Up @@ -43,24 +44,23 @@ private void Init()

if (App.WindowConfig.TranslateWindowTopmost)
{
PinButton.Visibility = Visibility.Visible;
PinOffButton.Visibility = Visibility.Collapsed;
timer.Start();
}
else
{
PackIcon packIcon = new PackIcon();
packIcon.Kind = PackIconKind.PinOff;
PinButton.Content = packIcon;
}

this.Background = new SolidColorBrush(Color.FromArgb((byte)App.WindowConfig.TranslateWindowTransparency, 0, 0, 0));

switch (App.WindowConfig.SourceTextVisibility)
if (!App.WindowConfig.SourceTextVisibility)
{
case "Visible":
TranslatedResultDisplay.SourceText.Visibility = Visibility.Visible;
break;
case "Auto":
this.MouseEnter += TranslateWindow_MouseEnter;
this.MouseLeave += TranslateWindow_MouseLeave;
break;
case "Collapsed":
TranslatedResultDisplay.SourceText.Visibility = Visibility.Collapsed;
break;
TranslatedResultDisplay.SourceText.Visibility = Visibility.Collapsed;
PackIcon packIcon = new PackIcon();
packIcon.Kind = PackIconKind.BookOff;
SourceTextButton.Content = packIcon;
}


Expand Down Expand Up @@ -236,35 +236,31 @@ private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

private void Pin_Button_Click(object sender, RoutedEventArgs e)
{
PinButton.Visibility = Visibility.Collapsed;
PinOffButton.Visibility = Visibility.Visible;
this.Topmost = false;
timer.Stop();
}
PackIcon packIcon = new PackIcon();
if (this.Topmost)
{
packIcon.Kind = PackIconKind.PinOff;
PinButton.Content = packIcon;
this.Topmost = false;
timer.Stop();
}
else
{
packIcon.Kind = PackIconKind.Pin;
PinButton.Content = packIcon;
this.Topmost = true;
timer.Start();
}

private void PinOff_Button_Click(object sender, RoutedEventArgs e)
{
PinButton.Visibility = Visibility.Visible;
PinOffButton.Visibility = Visibility.Collapsed;
this.Topmost = true;
timer.Start();

}


private void TranslateWindow_MinimizeButton_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}

private void TranslateWindow_MouseEnter(object sender, MouseEventArgs e)
{
TranslatedResultDisplay.SourceText.Visibility = Visibility.Visible;
}

private void TranslateWindow_MouseLeave(object sender, MouseEventArgs e)
{
TranslatedResultDisplay.SourceText.Visibility = Visibility.Collapsed;
}

private void FormatFontSizeDecrease_Button_Click(object sender, RoutedEventArgs e)
{
foreach (var t in TranslatedResultDisplay.TranslateResultPanel.Children)
Expand All @@ -290,12 +286,33 @@ private void VolumeSource_Button_Click(object sender, RoutedEventArgs e)
}


private void SourceText_Button_Click(object sender, RoutedEventArgs e)
{
PackIcon packIcon = new PackIcon();
if (App.WindowConfig.SourceTextVisibility)
{
App.WindowConfig.SourceTextVisibility = false;
packIcon.Kind = PackIconKind.BookOff;
SourceTextButton.Content = packIcon;
TranslatedResultDisplay.SourceText.Visibility = Visibility.Collapsed;
}
else
{
App.WindowConfig.SourceTextVisibility = true;
packIcon.Kind = PackIconKind.Book;
SourceTextButton.Content = packIcon;
TranslatedResultDisplay.SourceText.Visibility = Visibility.Visible;
}
}

/// <summary>
/// 该函数将指定的窗口设置到Z序的顶部。
/// </summary>
///
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern int BringWindowToTop(IntPtr hWnd);



}
}
2 changes: 1 addition & 1 deletion TsubakiTranslator/TranslatedResultDisplay.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<TextBox x:Name="SourceText"
Style="{StaticResource MaterialDesignComboBoxEditableTextBox}"
Margin="7 0 7 7" TextWrapping="Wrap" FontSize="20" Visibility="Collapsed"
Margin="7 0 7 7" TextWrapping="Wrap" FontSize="20"
Text="{Binding BindingText, Mode=TwoWay}" Foreground="WhiteSmoke"
IsReadOnly="True" FontWeight="Bold"/>

Expand Down
14 changes: 0 additions & 14 deletions TsubakiTranslator/WinStylePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,6 @@
materialDesign:HintAssist.Hint="翻译文本颜色"/>
</DockPanel>


<Separator Style="{StaticResource MaterialDesignSeparator}"/>

<TextBlock Style="{StaticResource MaterialDesignSubtitle1TextBlock}"
Margin="20 10 20 10" Text="源文本显示"/>

<ListBox Style="{StaticResource MaterialDesignChoiceChipOutlineListBox}"
SelectedValue="{Binding SourceTextVisibility, Mode=TwoWay}"
SelectedValuePath="Tag">
<ListBoxItem Content="可见" Tag="Visible" Margin="10,0,0,0" />
<ListBoxItem Content="变动" Tag="Auto" IsSelected="True"/>
<ListBoxItem Content="隐藏" Tag="Collapsed" />
</ListBox>

</StackPanel>


Expand Down

0 comments on commit f82e0b6

Please sign in to comment.