public void ShowError(string message)
 {
     UiDispatcherHelper.BeginInvokeOnUi(() =>
     {
         _notifier.ShowError(message);
     });
 }
 public void ShowWarning(string message, MessageOptions opts)
 {
     UiDispatcherHelper.BeginInvokeOnUi(() =>
     {
         _notifier.ShowWarning(message, opts);
     });
 }
 public void ShowInformation(string message)
 {
     UiDispatcherHelper.BeginInvokeOnUi(() =>
     {
         _notifier.ShowInformation(message);
     });
 }
 internal void ClearMessages(string msg)
 {
     UiDispatcherHelper.BeginInvokeOnUi(() =>
     {
         _notifier.ClearMessages(msg);
     });
 }
 public MainWindow()
 {
     InitializeComponent();
     SourceInitialized += (s, e) => WindowCromeResizeHelper.SourceInitialize(s, e);
     UiDispatcherHelper.Initialize();
     MinimazeButton.Click += (s, e) => WindowState = WindowState.Minimized;
     // MaximixeButton.Click += (s, e) => WindowState=(WindowState == WindowState.Maximized) ? WindowState.Minimized : WindowState.Maximized;
     CloseButton.Click += (s, e) => Close();
 }
        private void OnColorInfosChangedEvent(object sender, List <ColorInfo> e)
        {
            _lastOperateTokenSource?.Cancel();
            _lastOperateTokenSource = new CancellationTokenSource();

            UiDispatcherHelper.Invoke(() =>
            {
                CacheColors(((FirstViewModel)sender).ColorInfos, _lastOperateTokenSource.Token);
            });
        }
        private void GenerateVisibleKeyPress(ScanCode currentCode)
        {
            ushort key = currentCode.Code;

            if (currentCode.isControlDown)
            {
                currentCode.isControlDown = false;
                currentCode.isControlUp   = false;
                key |= ScanCodeHelper.CONTROL_KEY << 8;
            }

            if (ScanCodeHelper.Instance.VirtualKeyCodes.ContainsKey(key))
            {
                VirtualKeyCode code = ScanCodeHelper.Instance.VirtualKeyCodes[key];

                switch (code)
                {
                case VirtualKeyCode.LEFT: {
                    Index--;
                    break;
                }

                case VirtualKeyCode.RIGHT: {
                    if (Index < (InputString.Length - 1))
                    {
                        Index++;
                    }
                    break;
                }

                case VirtualKeyCode.BACK: {
                    if (Index > 0)
                    {
                        Index--;
                    }
                    break;
                }

                case VirtualKeyCode.SPACE: {
                    Index++;
                    break;
                }

                default: break;
                }

                UiDispatcherHelper.BeginInvokeOnUi(() => {
                    InputSimulator.SimulateKeyPress(code);
                });
            }
        }
        private void RemoveAll()
        {
            _uniqueColorInfos.Clear();

            UiDispatcherHelper.Invoke(() =>
            {
                foreach (ColorRectangle maskChild in Mask.Children)
                {
                    maskChild.Tag = null;
                    _colorRectanglesCache.Enqueue(maskChild);
                }

                Mask.Children.Clear();
            });
        }
        private void OnSelectedBitmapRectangleChanged()
        {
            var rectangle = _viewModel.SelectedBitmapRectangle;

            UiDispatcherHelper.Invoke(() =>
            {
                Sketchpad.Children.Clear();

                if (rectangle != null)
                {
                    var uiRectangle = new System.Windows.Shapes.Rectangle
                    {
                        Width           = rectangle.Value.Width * _canvasScreenWidthRatio,
                        Height          = rectangle.Value.Height * _canvasScreenHeightRatio,
                        Fill            = (SolidColorBrush)Application.Current.TryFindResource("AccentColorBrush"),
                        StrokeThickness = 2,
                        Stroke          = new SolidColorBrush(Colors.Black),
                        Opacity         = 0.3,
                        ContextMenu     = new ContextMenu
                        {
                            ItemsSource = new List <MenuItem>
                            {
                                new MenuItem
                                {
                                    Header           = "复制小图", Command = _viewModel.CopyTargetBitmapCommand,
                                    CommandParameter = _viewModel.SelectedBitmapInfo
                                },
                                new MenuItem
                                {
                                    Header           = "复制代码", Command = _viewModel.CopyCodeCommand,
                                    CommandParameter = _viewModel.SelectedBitmapInfo
                                },
                                new MenuItem
                                {
                                    Header           = "删除", Command = _viewModel.DeleteTargetBitmapCommand,
                                    CommandParameter = _viewModel.SelectedBitmapInfo
                                }
                            }
                        }
                    };

                    Canvas.SetLeft(uiRectangle, rectangle.Value.X * _canvasScreenWidthRatio);
                    Canvas.SetTop(uiRectangle, rectangle.Value.Y * _canvasScreenHeightRatio);
                    Sketchpad.Children.Add(uiRectangle);
                }
            });
        }
Exemplo n.º 10
0
        private void SimulateKeyPress(ScanCode currentCode)
        {
            ushort key   = currentCode.Code;
            byte   shift = ScanCodeHelper.CONTROL_KEY;

            if (currentCode.isControlDown)
            {
                currentCode.isControlDown = false;
                currentCode.isControlUp   = false;
                key |= (ushort)(shift << 8);
            }

            if (ScanCodeHelper.Instance.VirtualKeyCodes.ContainsKey(key))
            {
                VirtualKeyCode code = ScanCodeHelper.Instance.VirtualKeyCodes[key];

                if (code == VirtualKeyCode.LEFT)
                {
                    Index--;
                }

                if (code == VirtualKeyCode.RIGHT && Index < InputString.Length - 1)
                {
                    Index++;
                }

                if (code == VirtualKeyCode.SPACE)
                {
                    Index++;
                }

                if (code == VirtualKeyCode.BACK && Index != 0)
                {
                    Index--;
                }

                UiDispatcherHelper.BeginInvokeOnUi(() =>
                {
                    InputSimulator.SimulateKeyPress(code);
                });
            }
        }
Exemplo n.º 11
0
        private void DisplayCode(byte code)
        {
            UiDispatcherHelper.BeginInvokeOnUi(() =>
            {
                if (Index < InputString.Length - 1)
                {
                    List <char> chars = new List <char>(InputString.ToCharArray());
                    if (Index > chars.Count)
                    {
                        Index = chars.Count;
                    }

                    chars.Insert(Index, (char)code);
                    InputString = ConvertToString(chars);
                }
                else
                {
                    InputString += (char)code;
                }
                Index++;
            });
        }
        private async void MouseMoveHandler(object obj)
        {
            _lastOperateTokenSource?.Cancel();
            _lastOperateTokenSource = new CancellationTokenSource();

            if (CheckGoOn())
            {
                System.Windows.Point?point = null;

                await UiDispatcherHelper.InvokeAsync(() =>
                {
                    if (Mask.IsMouseOver)
                    {
                        if (!CheckGoOn())
                        {
                            return;
                        }

                        //获取鼠标位置
                        point = Mouse.GetPosition(Mask);
                    }
                });

                if (point != null)
                {
                    //查找屏幕长宽10%的矩形范围
                    var screenPoint = new PointF((float)point.Value.X / _canvasScreenWidthRatio,
                                                 (float)point.Value.Y / _canvasScreenHeightRatio);

                    var screenSize = GetScreenSize();

                    var rectangle = new Rectangle((int)(screenPoint.X - screenSize.Width * 0.1 / 2),
                                                  (int)(screenPoint.Y - screenSize.Height * 0.1 / 2), (int)(screenSize.Width * 0.1),
                                                  (int)(screenSize.Height * 0.1));

                    //需要呈现的点
                    var contains = _uniqueColorInfos.Where(s => rectangle.Contains(s.Key)).Select(s => s.Value)
                                   .ToDictionary(s => s.Point);

                    if (!CheckGoOn())
                    {
                        return;
                    }

                    var tobeRemoves = new List <ColorRectangle>();

                    await UiDispatcherHelper.InvokeAsync(() =>
                    {
                        foreach (ColorRectangle maskChild in Mask.Children)
                        {
                            if (!CheckGoOn())
                            {
                                return;
                            }

                            var colorInfo = (ColorInfo)maskChild.Tag;

                            if (!contains.ContainsKey(colorInfo.Point))
                            {
                                tobeRemoves.Add(maskChild);
                            }
                            else
                            {
                                contains.Remove(colorInfo.Point);
                            }
                        }

                        foreach (var tobeRemove in tobeRemoves)
                        {
                            if (!CheckGoOn())
                            {
                                return;
                            }

                            Mask.Children.Remove(tobeRemove);
                            _colorRectanglesCache.Enqueue(tobeRemove);
                        }

                        //最多呈现10个元素
                        var maxCount = 500;

                        foreach (var keyValuePair in contains.Take(maxCount))
                        {
                            if (!CheckGoOn() || Mask.Children.Count >= maxCount)
                            {
                                return;
                            }

                            if (_colorRectanglesCache.TryDequeue(out var colorRectangle))
                            {
                                colorRectangle.UpdateColorInfo(keyValuePair.Value);
                            }
                            else
                            {
                                colorRectangle = new ColorRectangle(keyValuePair.Value);
                            }

                            colorRectangle.Tag = keyValuePair.Value;
                            var location       = GetLocationInCanvas(Mask, keyValuePair.Value);

                            Panel.SetZIndex(colorRectangle, 1);
                            Canvas.SetLeft(colorRectangle, location.X);
                            Canvas.SetTop(colorRectangle, location.Y);

                            Mask.Children.Add(colorRectangle);
                        }
                    });
                }
            }
        }