/// <summary>
        /// 选择墙纸
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void WallPapersList_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var item in WallPapersList.Items)
            {
                (((WallPapersList.ContainerFromItem(item) as GridViewItem).ContentTemplateRoot as RelativePanel).Children[1] as Rectangle).Visibility = Visibility.Collapsed;
            }

            (((WallPapersList.ContainerFromItem(e.ClickedItem) as GridViewItem).ContentTemplateRoot as RelativePanel).Children[1] as Rectangle).Visibility = Visibility.Visible;

            //创建墙纸
            _wall_paperUI = new WallPaperUI()
            {
                Editing = true, Height = 100, Width = 100, Image = null, X = 150, Y = 150
            };
            MainCanvas.Invalidate();

            CanvasDevice device = CanvasDevice.GetSharedDevice();
            var          img    = await CanvasBitmap.LoadAsync(device, new Uri(e.ClickedItem.ToString()));

            if (img != null)
            {
                if (_wallpapers != null)
                {
                    (_wall_paperUI as WallPaperUI).Width  = img.Size.Width;
                    (_wall_paperUI as WallPaperUI).Height = img.Size.Height;
                    (_wall_paperUI as WallPaperUI).Image  = img;

                    MainCanvas.Invalidate();
                }
            }
            ;
        }
        /// <summary>
        /// PC窗体大小改变时,保证居中显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
        {
            var height = ApplicationView.GetForCurrentView().VisibleBounds.Height;
            var width  = ApplicationView.GetForCurrentView().VisibleBounds.Width;

            if (UWPPlatformTool.IsMobile)
            {
                border.Width  = this.Width = width;
                border.Height = this.Height = height;
            }
            else
            {
                border.Width  = width;
                border.Height = height;

                this.Height = height * 3 / 4;
                this.Width  = this.Height * 3 / 4;
            }
            tab1.Width = tab2.Width = tab3.Width = tab4.Width = tab5.Width = this.Width / 5;
            SetCanvas();
            MainCanvas.Invalidate();
            await Task.Delay(10);

            SetCanvas();
            MainCanvas.Invalidate();
        }
 /// <summary>
 /// 涂鸦撤销
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SymbolIcon_Tapped(object sender, TappedRoutedEventArgs e)
 {
     if (_doodleUIs != null && _doodleUIs.Count > 0)
     {
         _doodleUIs.Pop();  //删除最近一次涂鸦 立即重绘
         MainCanvas.Invalidate();
     }
 }
        /// <summary>
        /// 设置画布尺寸比例
        /// </summary>
        private void SetCanvas()
        {
            var w = MainWorkSapce.ActualWidth - 40;  //
            var h = MainWorkSapce.ActualHeight - 40; //

            if (w <= 0 || h <= 0)
            {
                return;
            }
            if (_size_mode == 0)  //1:1
            {
                var l = w > h ? h : w;
                MainCanvas.Width = MainCanvas.Height = l;
            }
            else if (_size_mode == 1)  //4:3
            {
                if (w <= h)
                {
                    MainCanvas.Width  = w;
                    MainCanvas.Height = MainCanvas.Width * 3 / 4;
                }
                else
                {
                    if (w / h <= (double)4 / 3)
                    {
                        MainCanvas.Width  = w;
                        MainCanvas.Height = MainCanvas.Width * 3 / 4;
                    }
                    else
                    {
                        MainCanvas.Height = h;
                        MainCanvas.Width  = MainCanvas.Height * 4 / 3;
                    }
                }
            }
            else  //3:4
            {
                if (h <= w)
                {
                    MainCanvas.Height = h;
                    MainCanvas.Width  = MainCanvas.Height * 3 / 4;
                }
                else
                {
                    if (h / w <= (double)4 / 3)
                    {
                        MainCanvas.Height = h;
                        MainCanvas.Width  = MainCanvas.Height * 3 / 4;
                    }
                    else
                    {
                        MainCanvas.Width  = w;
                        MainCanvas.Height = MainCanvas.Width * 4 / 3;
                    }
                }
            }
            MainCanvas.Invalidate();
        }
        /// <summary>
        /// 布局命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LayoutCommand_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var layout_command = sender as GridViewItem;

            if (layout_command == LayoutCommand1) //白边 填充
            {
                _stretch = (_stretch == Stretch.Uniform) ? Stretch.UniformToFill : Stretch.Uniform;
                (LayoutCommand1_Panel.Children[1] as TextBlock).Text = (_stretch == Stretch.Uniform) ? "填充" : "白边";
            }
            else if (layout_command == LayoutCommand2)  //黑底 白底
            {
                _back_color = (_back_color == Colors.White) ? Colors.Black : Colors.White;
                (LayoutCommand2_Panel.Children[1] as TextBlock).Text = (_back_color == Colors.White) ? "黑底" : "白底";
            }
            else if (layout_command == LayoutCommand3)  //画布比例
            {
                _size_mode = (_size_mode + 1) % 3;
                var t = "";
                if (_size_mode == 0)
                {
                    t = "4:3";
                }
                else if (_size_mode == 1)
                {
                    t = "3:4";
                }
                else
                {
                    t = "1:1";
                }
                (LayoutCommand3_Panel.Children[1] as TextBlock).Text = t;
            }
            else if (layout_command == LayoutCommand4)  //旋转
            {
                _rotate = (_rotate + 90) % 360;
            }
            else if (layout_command == LayoutCommand5)  //剪切
            {
                if (_cropUI == null)
                {
                    _cropUI = new CropUI()
                    {
                        Top = 20, Left = 20, Height = 100, Width = 100, DrawColor = Colors.Orange
                    };
                }
            }
            else if (layout_command == LayoutCommand6)  //重选底图
            {
                SelectImage();
            }
            MainCanvas.Invalidate();
            SetCanvas();
        }
Exemple #6
0
        private void SetCanvas()
        {
            try
            {
                var w = MainWorkSapce.ActualWidth - 40;
                var h = MainWorkSapce.ActualHeight - 40;

                MainCanvas.Width  = w;
                MainCanvas.Height = h;
                MainCanvas.Invalidate();
            }
            catch { }
        }
        private void CurrentSizeChanged(object sender, WindowSizeChangedEventArgs e)
        {
            //var height = ApplicationView.GetForCurrentView().VisibleBounds.Height;
            //var width = ApplicationView.GetForCurrentView().VisibleBounds.Width;

            //Height = height;
            //Width = width;
            //SetCanvas();
            //MainCanvas.Invalidate();
            //await Task.Delay(10);
            SetCanvas();
            MainCanvas.Invalidate();
        }
        public async void Show(StorageFile image)
        {
            try
            {
                Show();
                CanvasDevice cd     = CanvasDevice.GetSharedDevice();
                var          stream = await image.OpenAsync(FileAccessMode.Read);

                _image = await CanvasBitmap.LoadAsync(cd, stream);

                MainCanvas.Invalidate();
            }
            catch { }
        }
        /// <summary>
        /// 选择滤镜
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Filters_ItemClick(object sender, ItemClickEventArgs e)
        {
            foreach (var item in Filters.Items)
            {
                (((item as GridViewItem).Content as StackPanel).Children[1] as Border).Background = new SolidColorBrush(Colors.Transparent);
                ((((item as GridViewItem).Content as StackPanel).Children[1] as Border).Child as TextBlock).Foreground = new SolidColorBrush(Colors.Gray);
            }
            ((e.ClickedItem as StackPanel).Children[1] as Border).Background = new SolidColorBrush(Colors.Orange);
            (((e.ClickedItem as StackPanel).Children[1] as Border).Child as TextBlock).Foreground = new SolidColorBrush(Colors.White);

            _filter_index = int.Parse((e.ClickedItem as StackPanel).Tag.ToString());

            MainCanvas.Invalidate();
        }
        /// <summary>
        /// 显示编辑器(带底图片url)
        /// </summary>
        /// <param name="uri"></param>
        public async void Show(Uri uri)
        {
            try
            {
                Show();
                WaitLoading.IsActive = true;
                CanvasDevice cd = CanvasDevice.GetSharedDevice();
                _image = await CanvasBitmap.LoadAsync(cd, uri, 96);

                WaitLoading.IsActive = false;
                MainCanvas.Invalidate();
            }
            catch
            {
            }
        }
        /// <summary>
        /// 选择底图
        /// </summary>
        private void SelectImage()
        {
            Popup pop = new Popup();

            Border bod = new Border();

            bod.Background = new SolidColorBrush(Color.FromArgb(100, 0x00, 0x00, 0x00));
            bod.Width      = this.Width;
            bod.Height     = this.Height;

            MainGrid.Children.Add(pop);
            Grid.SetRow(pop, 0);
            Grid.SetRowSpan(pop, 3);

            var imageSelector = new ImageSeletorControl();

            imageSelector.Height = 175;
            imageSelector.Width  = bod.Width;

            bod.Child = imageSelector;
            imageSelector.VerticalAlignment = VerticalAlignment.Bottom;

            bod.Tapped += (sender, e) =>  //点击空白区域关闭popup
            {
                pop.IsOpen = false;
                MainGrid.Children.Remove(pop);
            };

            imageSelector.ImageSelected += async(image_file) =>   //选择image
            {
                CanvasDevice cd     = CanvasDevice.GetSharedDevice();
                var          stream = await image_file.OpenAsync(FileAccessMode.Read);

                var tmp = await CanvasBitmap.LoadAsync(cd, stream);

                if (tmp != null)
                {
                    _image = tmp;
                    MainCanvas.Invalidate();
                }
            };
            pop.Child  = bod;
            pop.IsOpen = true;
        }
        /// <summary>
        /// 点击画布
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainCanvas_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (!ClickEmpty(e.GetPosition(MainCanvas)))
            {
                return;
            }
            TagInsertControl tic = new TagInsertControl();

            tic.TagSelected += (tag, type) =>
            {
                if (_tagsUIs == null)
                {
                    _tagsUIs = new List <IDrawingUI>();
                }
                _tagsUIs.Add(new TagUI()
                {
                    Bound = MainCanvas.Size, TagText = tag, TagType = type, X = (float)e.GetPosition(MainCanvas).X, Y = (float)e.GetPosition(MainCanvas).Y
                });
                MainCanvas.Invalidate();
            };
            tic.Show();
        }
 /// <summary>
 /// 操作画布结束
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MainCanvas_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
 {
     if (MainCommandPanel.SelectedIndex == 4)
     {
         if (_current_editing_doodleUI != null)
         {
             _doodleUIs.Push(_current_editing_doodleUI);
             _current_editing_doodleUI = null;
             MainCanvas.Invalidate();
         }
         return;
     }
     if (_current_tag != null)
     {
         if (_manipulation_type == 2)
         {
             _pre_manipulation_position = null;
             _current_tag = null;
         }
     }
     if (MainCommandPanel.SelectedIndex == 0)
     {
         if (_cropUI != null)
         {
             _pre_manipulation_position = null;
         }
         return;
     }
     if (MainCommandPanel.SelectedIndex == 2)
     {
         if (_wall_paperUI != null)
         {
             _pre_manipulation_position = null;
         }
         return;
     }
 }
Exemple #14
0
        private async void HeaderMenu_HeaderMenuEventOccur(object sender, RoutedEventArgs e)
        {
            switch (((HeaderMenuUpdateEventArgs)e).UpdateEvent)
            {
            case HeaderMenuUpdateEvent.Open:
                var picker = new Windows.Storage.Pickers.FileOpenPicker();
                picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
                picker.FileTypeFilter.Add(".txt");

                StorageFile openingFile = await picker.PickSingleFileAsync();

                if (openingFile != null)
                {
                    FileOperationOutput.Text = "File is successfully loaded.";
                }
                break;

            case HeaderMenuUpdateEvent.Save:
                var savePicker = new Windows.Storage.Pickers.FileSavePicker
                {
                    SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary
                };

                savePicker.FileTypeChoices.Add("Sample Text", new List <string>()
                {
                    ".txt"
                });

                savePicker.SuggestedFileName = "sample";

                StorageFile savingFile = await savePicker.PickSaveFileAsync();

                if (savingFile != null)
                {
                    CachedFileManager.DeferUpdates(savingFile);

                    await FileIO.WriteTextAsync(savingFile, "Something");

                    Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(savingFile);

                    if (status == Windows.Storage.Provider.FileUpdateStatus.Complete)
                    {
                        FileOperationOutput.Text = "File is successfully saved.";
                    }
                }
                break;

            case HeaderMenuUpdateEvent.ShowCanvas:
                _isShowingCanvas = !_isShowingCanvas;

                MainCanvas.Visibility = _isShowingCanvas ? Visibility.Visible : Visibility.Collapsed;

                break;

            case HeaderMenuUpdateEvent.DrawGridOnCanvas:

                _isDisplayingGrid = !_isDisplayingGrid;

                MainCanvas.Invalidate();

                break;

            default:
                break;
            }
        }
Exemple #15
0
 private void CurrentSizeChanged(object sender, WindowSizeChangedEventArgs e)
 {
     SetCanvas();
     MainCanvas.Invalidate();
 }
        /// <summary>
        /// 判断是否点击空白区域 若是,返回true;否则进行相应操作
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        private bool ClickEmpty(Point p)
        {
            if (_cropUI != null)
            {
                if ((_cropUI as CropUI).LeftTopRegion.Contains(p))  //取消
                {
                    _cropUI = null;
                    MainCanvas.Invalidate();
                    return(false);
                }
                if ((_cropUI as CropUI).RightTopRegion.Contains(p))  //OK
                {
                    //
                    return(false);
                }
                if ((_cropUI as CropUI).Region.Contains(p))  //点击的是 剪切对象 区域
                {
                    return(false);
                }
            }
            if (_wall_paperUI != null)
            {
                if ((_wall_paperUI as WallPaperUI).RightTopRegion.Contains(p)) //取消墙纸
                {
                    _wall_paperUI = null;
                    MainCanvas.Invalidate();
                    return(false);
                }
                if ((_wall_paperUI as WallPaperUI).Region.Contains(p)) //点击墙纸
                {
                    (_wall_paperUI as WallPaperUI).Editing = !(_wall_paperUI as WallPaperUI).Editing;
                    MainCanvas.Invalidate();
                    return(false);
                }
            }
            if (_tagsUIs != null)
            {
                foreach (var tag in _tagsUIs)
                {
                    if ((tag as TagUI).Region.Contains(p))  //点击的是 tag 区域
                    {
                        (tag as TagUI).ShowCloseBtn = !(tag as TagUI).ShowCloseBtn;
                        MainCanvas.Invalidate();

                        return(false);
                    }

                    if ((tag as TagUI).CloseRegion.Contains(p) && (tag as TagUI).ShowCloseBtn) //点击的是tag 关闭按钮
                    {
                        _tagsUIs.Remove(tag);
                        MainCanvas.Invalidate();
                        return(false);
                    }
                }
            }
            //点击空白区域  所有元素失去编辑(选中)状态
            if (_wall_paperUI != null)
            {
                (_wall_paperUI as WallPaperUI).Editing = false;
            }
            if (_tagsUIs != null)
            {
                _tagsUIs.ForEach((tag) => { (tag as TagUI).ShowCloseBtn = false; });
            }

            return(true);
        }
 /// <summary>
 /// Slider的值发生变化
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Slider_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
 {
     MainCanvas.Invalidate();
 }
        /// <summary>
        /// 操作画布进行时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainCanvas_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            if (MainCommandPanel.SelectedIndex == 4) //涂鸦状态
            {
                if (_current_editing_doodleUI != null)
                {
                    _current_editing_doodleUI.Points.Add(e.Position);
                    MainCanvas.Invalidate();
                }
                return;
            }
            if (_current_tag != null)
            {
                if (_manipulation_type == 2)
                {
                    var deltaX = e.Position.X - _pre_manipulation_position.Value.X;
                    var deltaY = e.Position.Y - _pre_manipulation_position.Value.Y;

                    (_current_tag as TagUI).X += deltaX;
                    (_current_tag as TagUI).Y += deltaY;
                    _pre_manipulation_position = e.Position;

                    MainCanvas.Invalidate();
                }
            }
            if (MainCommandPanel.SelectedIndex == 0)  //剪切
            {
                if (_cropUI != null && _pre_manipulation_position != null)
                {
                    var deltaX = e.Position.X - _pre_manipulation_position.Value.X;
                    var deltaY = e.Position.Y - _pre_manipulation_position.Value.Y;

                    if (_manipulation_type == 0) //移动
                    {
                        (_cropUI as CropUI).Left += deltaX;
                        (_cropUI as CropUI).Top  += deltaY;
                    }
                    else if (_manipulation_type == 1) //缩放
                    {
                        (_cropUI as CropUI).Width  += deltaX;
                        (_cropUI as CropUI).Height += deltaY;
                    }

                    _pre_manipulation_position = e.Position;
                    MainCanvas.Invalidate();
                }
                return;
            }
            if (MainCommandPanel.SelectedIndex == 2) //墙纸
            {
                if (_wall_paperUI != null && _pre_manipulation_position != null)
                {
                    var deltaX = e.Position.X - _pre_manipulation_position.Value.X;
                    var deltaY = e.Position.Y - _pre_manipulation_position.Value.Y;
                    if (_manipulation_type == 3)  //移动
                    {
                        (_wall_paperUI as WallPaperUI).X += deltaX;
                        (_wall_paperUI as WallPaperUI).Y += deltaY;
                    }
                    else if (_manipulation_type == 4)  //缩放
                    {
                        (_wall_paperUI as WallPaperUI).Width += deltaX * 2;
                        (_wall_paperUI as WallPaperUI).SyncWH();  //只需要设置宽度  高度自动同步
                    }
                    _pre_manipulation_position = e.Position;

                    MainCanvas.Invalidate();
                }
            }
        }
 /// <summary>
 /// 操作画布开始
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MainCanvas_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
 {
     if (MainCommandPanel.SelectedIndex == 4)  //涂鸦状态
     {
         if (_current_editing_doodleUI == null)
         {
             _current_editing_doodleUI = new DoodleUI()
             {
                 DrawingColor = _pen_color, DrawingSize = _pen_size
             };
             _current_editing_doodleUI.InitImageBrush();  //可能是图片图片画刷  需要提前初始化
         }
         return;
     }
     if (_tagsUIs != null)
     {
         foreach (var tag in _tagsUIs)
         {
             if ((tag as TagUI).Region.Contains(e.Position))
             {
                 _current_tag = tag;
                 _pre_manipulation_position = e.Position;
                 _manipulation_type         = 2;
                 break;
             }
         }
     }
     if (MainCommandPanel.SelectedIndex == 0)                     //可能是剪切状态
     {
         if (_cropUI != null)                                     //确实是剪切状态
         {
             if ((_cropUI as CropUI).Region.Contains(e.Position)) //移动剪切对象
             {
                 _manipulation_type         = 0;
                 _pre_manipulation_position = e.Position;
             }
             if ((_cropUI as CropUI).RightBottomRegion.Contains(e.Position)) //缩放剪切区域
             {
                 _manipulation_type         = 1;
                 _pre_manipulation_position = e.Position;
             }
         }
         return;
     }
     if (MainCommandPanel.SelectedIndex == 2)  //可能是墙纸编辑状态
     {
         if (_wall_paperUI != null)
         {
             if ((_wall_paperUI as WallPaperUI).Region.Contains(e.Position))  //移动墙纸
             {
                 _manipulation_type                     = 3;
                 _pre_manipulation_position             = e.Position;
                 (_wall_paperUI as WallPaperUI).Editing = true;
             }
             if ((_wall_paperUI as WallPaperUI).RightBottomRegion.Contains(e.Position) && (_wall_paperUI as WallPaperUI).Editing)  //缩放墙纸
             {
                 _manipulation_type         = 4;
                 _pre_manipulation_position = e.Position;
             }
             MainCanvas.Invalidate();
         }
         return;
     }
 }