Skip to content

Commit

Permalink
1.1.0 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceTimee committed Mar 21, 2022
1 parent 5ccc2f0 commit 04d2d4e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 51 deletions.
32 changes: 19 additions & 13 deletions Windows/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@
Style="{DynamicResource CommonWindow}"
SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" MinWidth="250" Title="Ona Pix" Loaded="MainWin_Loaded">
<Grid Margin="10,10,10,10">
<Rectangle MouseDown="ActiveSpace_MouseDown" Opacity="0" Fill="#0000" />
<Image MouseDown="ActiveSpace_MouseDown" x:Name="ShowImage" MaxWidth="1080" />
<Rectangle MouseDown="InactiveSpace_MouseDown" Opacity="0" Fill="#0000" />
<Image MouseDown="InactiveSpace_MouseDown" x:Name="ShowImage" MaxWidth="1080" />

<Grid x:Name="InactiveGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>

<Grid>
<Grid x:Name="InactiveTopGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" />
Expand All @@ -29,14 +25,24 @@
<Button x:Name="InactiveViewButton" Style="{StaticResource InactiveButton}" Margin="0,0,0,0" Grid.Column="1" Click="ViewButton_Click" Content="浏览" TabIndex="1" HorizontalAlignment="Right" />
</Grid>

<Button x:Name="InactiveSearchButton" Style="{StaticResource InactiveButton}" Grid.Row="1" Click="SearchButton_Click" Content="搜索" IsDefault="True" IsEnabled="False" TabIndex="2" />
<Button x:Name="InactiveDownloadButton" Style="{StaticResource InactiveButton}" Grid.Row="2" Click="DownloadButton_Click" Content="下载" IsEnabled="False" TabIndex="3" />
<Button x:Name="InactiveLuckyButton" Style="{StaticResource InactiveButton}" Grid.Row="3" Click="LuckyButton_Click" Content="一图" TabIndex="4" />
<Button x:Name="InactiveSettingButton" Style="{StaticResource InactiveButton}" Grid.Row="4" Click="SettingButton_Click" Content="设置" TabIndex="5" />
<Button x:Name="InactiveAboutButton" Style="{StaticResource InactiveButton}" Grid.Row="5" Click="AboutButton_Click" Content="关于" TabIndex="6" />
<Grid x:Name="InactiveRightGrid" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>

<Button x:Name="InactiveSearchButton" Style="{StaticResource InactiveButton}" Grid.Row="0" Click="SearchButton_Click" Content="搜索" IsDefault="True" IsEnabled="False" TabIndex="2" />
<Button x:Name="InactiveDownloadButton" Style="{StaticResource InactiveButton}" Grid.Row="1" Click="DownloadButton_Click" Content="下载" IsEnabled="False" TabIndex="3" />
<Button x:Name="InactiveLuckyButton" Style="{StaticResource InactiveButton}" Grid.Row="2" Click="LuckyButton_Click" Content="一图" TabIndex="4" />
<Button x:Name="InactiveSettingButton" Style="{StaticResource InactiveButton}" Grid.Row="3" Click="SettingButton_Click" Content="设置" TabIndex="5" />
<Button x:Name="InactiveAboutButton" Style="{StaticResource InactiveButton}" Grid.Row="4" Click="AboutButton_Click" Content="关于" TabIndex="6" />
</Grid>
</Grid>

<Grid x:Name="ActiveGrid" Visibility="Hidden">
<Grid x:Name="ActiveGrid" Visibility="Collapsed">
<Grid x:Name="ActiveTopGrid" Margin="0,-65,0,0" MouseDown="ActiveSpace_MouseIn" MouseEnter="ActiveSpace_MouseIn" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
Expand Down
100 changes: 62 additions & 38 deletions Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ namespace Ona_Pix
{
public partial class MainWindow : Window
{
private readonly DispatcherTimer IN_TIMER = new(), OUT_TIMER = new();
private readonly DispatcherTimer ACTIVATE_TIMER = new(), IN_TIMER = new(), OUT_TIMER = new();
private HttpResponseMessage IMAGE_MESSAGE = new();
private bool IS_ACTIVE = false, IS_FIXED = false;

public MainWindow()
{
InitializeComponent();

ACTIVATE_TIMER.Interval = new TimeSpan(1);
ACTIVATE_TIMER.Tick += ACTIVATE_TIMER_Tick;
IN_TIMER.Interval = new TimeSpan(1);
IN_TIMER.Tick += IN_TIMER_Tick;
OUT_TIMER.Interval = new TimeSpan(1);
Expand Down Expand Up @@ -169,25 +172,39 @@ private void AboutButton_Click(object sender, RoutedEventArgs e)
catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); Title = "操作执行失败"; return; }
}

private void ActiveSearchBox_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
private void SearchBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
IS_FIXED = true;
if ((IS_ACTIVE ? ActiveSearchBox : InactiveSearchBox).Text == "")
{
ActiveSearchButton.IsEnabled = false;
ActiveDownloadButton.IsEnabled = false;
InactiveSearchButton.IsEnabled = false;
InactiveDownloadButton.IsEnabled = false;
}
else
{
ActiveSearchButton.IsEnabled = true;
ActiveDownloadButton.IsEnabled = true;
InactiveSearchButton.IsEnabled = true;
InactiveDownloadButton.IsEnabled = true;
}
}
private void ActiveSpace_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)

private void ActiveSpace_MouseIn(object sender, System.Windows.Input.MouseEventArgs e)
{
IN_TIMER.Stop();
OUT_TIMER.Start();
OUT_TIMER.Stop();
IN_TIMER.Start();

ActiveSearchBox.Focus();

IS_FIXED = false;
}
private void ActiveSpace_MouseIn(object sender, System.Windows.Input.MouseEventArgs e)
private void ActiveSearchBox_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
OUT_TIMER.Stop();
IN_TIMER.Start();

ActiveSearchBox.Focus();

IS_FIXED = true;
}
private void ActiveSpace_MouseOut(object sender, System.Windows.Input.MouseEventArgs e)
{
Expand All @@ -197,7 +214,36 @@ private void ActiveSpace_MouseOut(object sender, System.Windows.Input.MouseEvent
OUT_TIMER.Start();
}
}
private void InactiveSpace_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
IN_TIMER.Stop();
OUT_TIMER.Start();

ActiveSearchBox.Focus();

IS_FIXED = false;
}

private void ACTIVATE_TIMER_Tick(object? sender, EventArgs e)
{
if (InactiveRightGrid.Margin.Left < Width)
{
InactiveRightGrid.Margin = new Thickness(InactiveRightGrid.Margin.Left + 0.5, 0, InactiveRightGrid.Margin.Right - 0.5, 0);
InactiveTopGrid.Margin = new Thickness(0, InactiveTopGrid.Margin.Top - 0.1, 0, InactiveTopGrid.Margin.Bottom + 0.1);
}
else
{
ACTIVATE_TIMER.Stop();

SetImage();

ActiveSearchBox.Text = InactiveSearchBox.Text;
InactiveGrid.Visibility = Visibility.Collapsed;
ActiveGrid.Visibility = Visibility.Visible;

IS_ACTIVE = true;
}
}
private void IN_TIMER_Tick(object? sender, EventArgs e)
{
if (ActiveRightGrid.Margin.Right < -10)
Expand All @@ -219,24 +265,6 @@ private void OUT_TIMER_Tick(object? sender, EventArgs e)
OUT_TIMER.Stop();
}

private void SearchBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
if ((IS_ACTIVE ? ActiveSearchBox : InactiveSearchBox).Text == "")
{
ActiveSearchButton.IsEnabled = false;
ActiveDownloadButton.IsEnabled = false;
InactiveSearchButton.IsEnabled = false;
InactiveDownloadButton.IsEnabled = false;
}
else
{
ActiveSearchButton.IsEnabled = true;
ActiveDownloadButton.IsEnabled = true;
InactiveSearchButton.IsEnabled = true;
InactiveDownloadButton.IsEnabled = true;
}
}

private async void Smms_SetImageUrl(dynamic value)
{
await Dispatcher.Invoke(async () =>
Expand Down Expand Up @@ -404,29 +432,25 @@ private async Task GetImage(string imageUri)

HttpResponseMessage imageMessage = await Http.GetAsync<HttpResponseMessage>(imageUri, Define.MAIN_CLIENT, HttpCompletionOption.ResponseContentRead);
imageMessage.EnsureSuccessStatusCode();
IMAGE_MESSAGE = imageMessage;

SetImage(imageMessage);
if (IS_ACTIVE)
SetImage();
else
ACTIVATE_TIMER.Start();

Title = "图片获取完成";
}
private void SetImage(HttpResponseMessage imageMessage)
private void SetImage()
{
Title = "正在读取图片";

BitmapImage bitmapImage = new();
bitmapImage.BeginInit();
bitmapImage.StreamSource = imageMessage.Content.ReadAsStream();
bitmapImage.StreamSource = IMAGE_MESSAGE.Content.ReadAsStream();
bitmapImage.EndInit();
ImageBehavior.SetAnimatedSource(ShowImage, bitmapImage);

if (!IS_ACTIVE)
{
ActiveSearchBox.Text = InactiveSearchBox.Text;
InactiveGrid.Visibility = Visibility.Hidden;
ActiveGrid.Visibility = Visibility.Visible;
IS_ACTIVE = true;
}

Title = "图片读取完成";
}

Expand Down

0 comments on commit 04d2d4e

Please sign in to comment.