Esempio n. 1
0
        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
            };
            //MyCanvas.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;

                    MyCanvas.Invalidate();
                }
            }
            ;
        }
Esempio n. 2
0
        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 * 0.8;
                this.Width  = this.Height * 1.6;
            }
            SetCanvas();
            MyCanvas.Invalidate();
            await Task.Delay(10);

            SetCanvas();
            MyCanvas.Invalidate();
        }
Esempio n. 3
0
 /// <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();  //删除最近一次涂鸦 立即重绘
         MyCanvas.Invalidate();
     }
 }
Esempio n. 4
0
 /// <summary>
 /// 操作画布进行时
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MyCanvas_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
 {
     if (_current_editing_doodleUI != null)
     {
         _current_editing_doodleUI.Points.Add(e.Position);
         MyCanvas.Invalidate();
     }
 }
Esempio n. 5
0
        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;
                MyCanvas.Width = MyCanvas.Height = l;
            }
            else if (_size_mode == 1)  //4:3
            {
                if (w <= h)
                {
                    MyCanvas.Width  = w;
                    MyCanvas.Height = MyCanvas.Width * 3 / 4;
                }
                else
                {
                    if (w / h <= (double)4 / 3)
                    {
                        MyCanvas.Width  = w;
                        MyCanvas.Height = MyCanvas.Width * 3 / 4;
                    }
                    else
                    {
                        MyCanvas.Height = h;
                        MyCanvas.Width  = MyCanvas.Height * 4 / 3;
                    }
                }
            }
            else  //3:4
            {
                if (h <= w)
                {
                    MyCanvas.Height = h;
                    MyCanvas.Width  = MyCanvas.Height * 3 / 4;
                }
                else
                {
                    if (h / w <= (double)4 / 3)
                    {
                        MyCanvas.Height = h;
                        MyCanvas.Width  = MyCanvas.Height * 3 / 4;
                    }
                    else
                    {
                        MyCanvas.Width  = w;
                        MyCanvas.Height = MyCanvas.Width * 4 / 3;
                    }
                }
            }
            MyCanvas.Invalidate();
        }
Esempio n. 6
0
 /// <summary>
 /// 操作画布结束
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MyCanvas_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
 {
     if (_current_editing_doodleUI != null)
     {
         _doodleUIs.Push(_current_editing_doodleUI);
         _current_editing_doodleUI = null;
         MyCanvas.Invalidate();
     }
 }
Esempio n. 7
0
        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;
                MyCanvas.Invalidate();
            }
            catch
            {
            }
        }
Esempio n. 8
0
        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);

                MyCanvas.Invalidate();
            }
            catch
            {
            }
        }
Esempio n. 9
0
        /* 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;
         *   }*/

        /// <summary>
        /// 操作画布开始
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MyCanvas_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            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;
                }
                MyCanvas.Invalidate();
            }
            return;
        }
Esempio n. 10
0
        /// <summary>
        /// 操作画布进行时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MyCanvas_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
        {
            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;

                MyCanvas.Invalidate();
            }
        }