Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
完成临摹功能(无法保存)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed Apr 23, 2019
1 parent a483ee3 commit f224ff2
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 9 deletions.
35 changes: 30 additions & 5 deletions PixivFSUWP/BigImage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,45 @@
xmlns:local="using:PixivFSUWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Loaded="Page_Loaded"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
mc:Ignorable="d" SizeChanged="Page_SizeChanged">

<Page.Background>
<AcrylicBrush BackgroundSource="HostBackdrop" TintColor="White" TintOpacity="0.5" FallbackColor="White"/>
</Page.Background>

<Grid x:Name="layoutRoot">
<ScrollViewer ZoomMode="Enabled"
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock x:Name="txtTitle" Margin="10,0,0,0" FontSize="12" VerticalAlignment="Center" HorizontalAlignment="Left"/>
<CommandBar Grid.Row="1" DefaultLabelPosition="Right" Background="Transparent">
<CommandBar.Content>
<InkToolbar x:Name="inkToolbar" Visibility="Collapsed"
VerticalAlignment="Center" InitialControls="None"
TargetInkCanvas="{x:Bind mainCanvas}">
<InkToolbarBallpointPenButton/>
<InkToolbarPencilButton/>
<InkToolbarEraserButton/>
<InkToolbarRulerButton/>
</InkToolbar>
</CommandBar.Content>
<AppBarButton Icon="Save" Label="保存"/>
<AppBarToggleButton x:Name="btnDraw" Icon="Edit" Label="临摹" Unchecked="BtnDraw_Unchecked" Checked="BtnDraw_Checked"/>
</CommandBar>
<ScrollViewer ZoomMode="Enabled" x:Name="scrollRoot"
MinZoomFactor="1" Grid.Row="2"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
HorizontalScrollMode="Enabled"
VerticalScrollMode="Enabled">
<Grid>
<Grid x:Name="gridImg">
<Grid x:Name="paper" Background="White" Visibility="Collapsed"/>
<Image x:Name="mainImg"/>
<InkCanvas x:Name="mainCanvas"/>
<InkCanvas x:Name="mainCanvas" Visibility="Collapsed"/>
</Grid>
</ScrollViewer>
</Grid>
Expand Down
64 changes: 60 additions & 4 deletions PixivFSUWP/BigImage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace PixivFSUWP
/// </summary>
public sealed partial class BigImage : Page
{
bool _locked = false;
Data.BigImageDetail parameter;
public BigImage()
{
Expand All @@ -34,7 +35,7 @@ public BigImage()
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
parameter = e.Parameter as Data.BigImageDetail;
//CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
var view = ApplicationView.GetForCurrentView();
view.TitleBar.ButtonBackgroundColor = Colors.Transparent;
view.TitleBar.ButtonForegroundColor = Colors.White;
Expand All @@ -43,14 +44,69 @@ protected override async void OnNavigatedTo(NavigationEventArgs e)
view.Title = string.Format("{0} by {1} - {2}x{3}",
parameter.Title, parameter.Author,
parameter.Width, parameter.Height);
txtTitle.Text = view.Title;
mainImg.Source = await Data.OverAll.BytesToImage(parameter.Image, parameter.Width, parameter.Height);
base.OnNavigatedTo(e);
}

private void Page_Loaded(object sender, RoutedEventArgs e)
private void Page_SizeChanged(object sender, SizeChangedEventArgs e)
{
mainImg.MaxHeight = Frame.ActualHeight;
mainImg.MaxWidth = Frame.ActualWidth;
if (_locked) return;
gridImg.MaxHeight = scrollRoot.ActualHeight;
gridImg.MaxWidth = scrollRoot.ActualWidth;
gridImg.MinHeight = scrollRoot.ActualHeight;
gridImg.MinWidth = scrollRoot.ActualWidth;
}

void lockView()
{
_locked = true;
gridImg.MaxHeight = gridImg.ActualHeight;
gridImg.MaxWidth = gridImg.ActualWidth;
gridImg.MinHeight = gridImg.ActualHeight;
gridImg.MinWidth = gridImg.ActualWidth;
mainImg.Opacity = 0.3;
paper.MinHeight = mainImg.ActualHeight;
paper.MinWidth = mainImg.ActualWidth;
paper.MaxHeight = mainImg.ActualHeight;
paper.MaxWidth = mainImg.ActualWidth;
paper.Height = mainImg.ActualHeight;
paper.Width = mainImg.ActualWidth;
mainCanvas.MinHeight = mainImg.ActualHeight;
mainCanvas.MinWidth = mainImg.ActualWidth;
mainCanvas.MaxHeight = mainImg.ActualHeight;
mainCanvas.MaxWidth = mainImg.ActualWidth;
mainCanvas.Height = mainImg.ActualHeight;
mainCanvas.Width = mainImg.ActualWidth;
}

void unlockView()
{
_locked = false;
mainImg.Opacity = 1;
gridImg.Height = scrollRoot.ActualHeight;
gridImg.Width = scrollRoot.ActualWidth;
gridImg.MaxHeight = scrollRoot.ActualHeight;
gridImg.MaxWidth = scrollRoot.ActualWidth;
gridImg.MinHeight = scrollRoot.ActualHeight;
gridImg.MinWidth = scrollRoot.ActualWidth;
}

private void BtnDraw_Checked(object sender, RoutedEventArgs e)
{
mainCanvas.Visibility = Visibility.Visible;
inkToolbar.Visibility = Visibility.Visible;
paper.Visibility = Visibility.Visible;
lockView();
}

private void BtnDraw_Unchecked(object sender, RoutedEventArgs e)
{
mainCanvas.Visibility = Visibility.Collapsed;
inkToolbar.Visibility = Visibility.Collapsed;
paper.Visibility = Visibility.Collapsed;
mainCanvas.InkPresenter.StrokeContainer.Clear();
unlockView();
}
}
}

0 comments on commit f224ff2

Please sign in to comment.