private void Brainf_ckEditBox_SelectionChanged(object sender, RoutedEventArgs e)
        {
            ScrollToSelection(out Rect rect);

            // Adjust the UI of the selected line highlight and the cursor indicator.
            // Both elements are translated to the right position and made visible
            // if the current selection is not collapsed to a single point, otherwise
            // they're both hidden. This is the same behavior of Visual Studio.
            if (_SelectionLength > 0)
            {
                _SelectionHighlightBorder !.Opacity    = 0;
                _CursorIndicatorRectangle !.Visibility = Visibility.Collapsed;
            }
            else
            {
                // Line highlight
                _SelectionHighlightBorder !.Opacity = 1;
                ((TranslateTransform)_SelectionHighlightBorder.RenderTransform).Y = rect.Top + Padding.Top;

                // Cursor indicator
                _CursorIndicatorRectangle !.Visibility = Visibility.Visible;
                TranslateTransform cursorTransform = (TranslateTransform)_CursorIndicatorRectangle.RenderTransform;
                cursorTransform.X = rect.X + Padding.Left;
                cursorTransform.Y = rect.Y + Padding.Top;
            }

            var position = Text.CalculateCoordinates(Document.Selection.EndPosition);
            var args     = new CursorPositionChangedEventArgs(position.Row + 1, position.Column + 1);

            // Signal the cursor movement
            CursorPositionChanged?.Invoke(this, args);
        }
示例#2
0
        /// <summary>
        /// Handles control's MouseMove event
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            var s = CurrentScale;
            var c = new PointF(e.X - CtlCenter.X, e.Y - CtlCenter.Y);
            var p = new PointF(c.X / s - Offset.X, c.Y / s - Offset.Y);
            var d = new PointF(p.X - P0.X, p.Y - P0.Y);

            if (MoveMode && d != PointF.Empty)
            {
                Cursor = Cursors.SizeAll;
                Offset = new PointF(Offset.X + d.X, Offset.Y + d.Y);
                if (PositionChanged != null)
                {
                    PositionChanged.Invoke(this, EventArgs.Empty);
                }
                Invalidate();
                MapMoved = true;
            }
            MapPointed = new PointF(-p.X - MapCenter.X, -p.Y - MapCenter.Y);
            if (CursorPositionChanged != null)
            {
                CursorPositionChanged.Invoke(this, EventArgs.Empty);
            }
            base.OnMouseMove(e);
        }
示例#3
0
 void SetCurrentPosition(int position)
 {
     _nativeSelectionIsUpdating = true;
     CursorPosition             = position;
     CursorPositionChanged?.Invoke(this, EventArgs.Empty);
     _nativeSelectionIsUpdating = false;
 }
        /// <summary>
        /// Enable Zoom and Pan Controls.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="selectionChanged">Selection changed callabck. Triggered when user select a point with selec tool.</param>
        /// <param name="cursorMoved">Cursor moved callabck. Triggered when user move the mouse in chart area.</param>
        /// <param name="zoomChanged">Callback triggered when chart has 
        /// zoomed in or out (and on first painting of the chart).</param>
        /// <remarks>Callback are optional (pass in null to ignore).</remarks>
        public static void EnableZoomAndPanControls(this Chart sender,
            CursorPositionChanged selectionChanged,
            CursorPositionChanged cursorMoved,
            ZoomChanged zoomChanged = null)
        {
            if (!ChartTool.ContainsKey(sender))
            {
                ChartTool[sender] = new ChartData(sender);
                ChartData ptrChartData = ChartTool[sender];
                ptrChartData.Backup();
                ptrChartData.SelectionChangedCallback = selectionChanged;
                ptrChartData.CursorMovedCallback = cursorMoved;
                ptrChartData.ZoomChangedCallback = zoomChanged;

                //Populate Context menu
                Chart ptrChart = sender;
                if (ptrChart.ContextMenuStrip == null)
                {
                    //Context menu is empty, use ChartContextMenuStrip directly
                    ptrChart.ContextMenuStrip = new ContextMenuStrip();
                    ptrChart.ContextMenuStrip.Items.AddRange(ChartTool[ptrChart].MenuItems.ToArray());
                }
                else
                {
                    //User assigned context menu to chart. Merge current menu with ChartContextMenuStrip.
                    ContextMenuStrip newMenu = new ContextMenuStrip();
                    newMenu.Items.AddRange(ChartTool[sender].MenuItems.ToArray());

                    foreach (object ptrItem in ChartTool[sender].ContextMenuStrip.Items)
                    {
                        if (ptrItem is ToolStripMenuItem) newMenu.Items.Add(((ToolStripMenuItem)ptrItem).Clone());
                        else if (ptrItem is ToolStripSeparator) newMenu.Items.Add(new ToolStripSeparator());
                    }
                    newMenu.Items.Add(new ToolStripSeparator());
                    ptrChart.ContextMenuStrip = newMenu;
                    ptrChart.ContextMenuStrip.AddHandlers(ChartTool[sender].ContextMenuStrip);
                }
                ptrChart.ContextMenuStrip.Opening += ChartContext_Opening;
                ptrChart.ContextMenuStrip.ItemClicked += ChartContext_ItemClicked;
                ptrChart.MouseDown += ChartControl_MouseDown;
                ptrChart.MouseMove += ChartControl_MouseMove;
                ptrChart.MouseUp += ChartControl_MouseUp;
                ptrChart.PostPaint += ChartOnPostPaint; // Necessary to kickstart ZoomChanged callback

                // The following is for testing out the built-in events.
                //  They don't seem to be as reliable as just handling mouse up/move/down
                //ptrChart.CursorPositionChanging += (sender1, e) =>
                //    {
                //        // Changed event isn't triggered with any zoom or select operations! From looking at the Cursor.cs code, it seems to be a bug.
                //        // Changing event is raised twice, once for each cursor (X, Y)
                //        var axis = e.Axis;
                //    };
                //ptrChart.SelectionRangeChanging += (o, args) =>
                //    {
                //        // Changed event isn't triggered with any zoom or select operations!
                //        // Neither is changed event... odd
                //        Console.WriteLine("SelectionRangeChanging raised " + args.ToString());
                //        var axis = args.Axis;
                //        var chartArea = args.ChartArea;
                //    };

                //Override settings.
                ChartArea ptrChartArea = ptrChart.ChartAreas[0];
                ptrChartArea.CursorX.AutoScroll = false;
                ptrChartArea.CursorX.Interval = 1e-06;
                ptrChartArea.CursorY.AutoScroll = false;
                ptrChartArea.CursorY.Interval = 1e-06;

                ptrChartArea.AxisX.ScrollBar.Enabled = false;
                ptrChartArea.AxisX2.ScrollBar.Enabled = false;
                ptrChartArea.AxisY.ScrollBar.Enabled = false;
                ptrChartArea.AxisY2.ScrollBar.Enabled = false;

                SetChartControlState(sender, MSChartExtensionToolState.Select);
            }
        }
示例#5
0
        /// <summary>
        /// Enable Zoom and Pan Controls.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="selectionChanged">Selection changed callabck. Triggered when user select a point with selec tool.</param>
        /// <param name="cursorMoved">Cursor moved callabck. Triggered when user move the mouse in chart area.</param>
        /// <remarks>Callback are optional.</remarks>
        public static void EnableZoomAndPanControls(this Chart sender,
                                                    CursorPositionChanged selectionChanged,
                                                    CursorPositionChanged cursorMoved)
        {
            if (!ChartTool.ContainsKey(sender))
            {
                ChartTool[sender] = new ChartData(sender);
                ChartData ptrChartData = ChartTool[sender];
                ptrChartData.Backup();
                ptrChartData.SelectionChangedCallback = selectionChanged;
                ptrChartData.CursorMovedCallback      = cursorMoved;

                //Populate Context menu
                Chart ptrChart = sender;
                if (ptrChart.ContextMenuStrip == null)
                {
                    //Context menu is empty, use ChartContextMenuStrip directly
                    ptrChart.ContextMenuStrip = new ContextMenuStrip();
                    ptrChart.ContextMenuStrip.Items.AddRange(ChartTool[ptrChart].MenuItems.ToArray());
                }
                else
                {
                    //User assigned context menu to chart. Merge current menu with ChartContextMenuStrip.
                    ContextMenuStrip newMenu = new ContextMenuStrip();
                    newMenu.Items.AddRange(ChartTool[sender].MenuItems.ToArray());

                    foreach (object ptrItem in ChartTool[sender].ContextMenuStrip.Items)
                    {
                        if (ptrItem is ToolStripMenuItem)
                        {
                            newMenu.Items.Add(((ToolStripMenuItem)ptrItem).Clone());
                        }
                        else if (ptrItem is ToolStripSeparator)
                        {
                            newMenu.Items.Add(new ToolStripSeparator());
                        }
                    }
                    newMenu.Items.Add(new ToolStripSeparator());
                    ptrChart.ContextMenuStrip = newMenu;
                    ptrChart.ContextMenuStrip.AddHandlers(ChartTool[sender].ContextMenuStrip);
                }
                ptrChart.ContextMenuStrip.Opening     += ChartContext_Opening;
                ptrChart.ContextMenuStrip.ItemClicked += ChartContext_ItemClicked;
                ptrChart.MouseDown += ChartControl_MouseDown;
                ptrChart.MouseMove += ChartControl_MouseMove;
                ptrChart.MouseUp   += ChartControl_MouseUp;
                ptrChart.KeyDown   += ChartControl_KeyDown;

                //Override settings.
                ChartArea ptrChartArea = ptrChart.ChartAreas[0];
                ptrChartArea.CursorX.AutoScroll = false;
                ptrChartArea.CursorX.Interval   = 1e-06;
                ptrChartArea.CursorY.AutoScroll = false;
                ptrChartArea.CursorY.Interval   = 1e-06;

                ptrChartArea.AxisX.ScrollBar.Enabled  = false;
                ptrChartArea.AxisX2.ScrollBar.Enabled = false;
                ptrChartArea.AxisY.ScrollBar.Enabled  = false;
                ptrChartArea.AxisY2.ScrollBar.Enabled = false;

                SetChartControlState(sender, MSChartExtensionToolState.Select);
            }
        }
示例#6
0
文件: TextBox.cs 项目: xvwvx/Myra
        private void OnCursorIndexChanged()
        {
            UpdateScrolling();

            CursorPositionChanged.Invoke(this);
        }
示例#7
0
        private void OnCursorIndexChanged()
        {
            UpdateScrolling();

            CursorPositionChanged?.Invoke(this, EventArgs.Empty);
        }
示例#8
0
 protected virtual void OnCursorPositionChanged(EventArgs e)
 {
     CursorPositionChanged?.Invoke(this, e);
 }
 public void RaiseCursorPositionChanged()
 {
     CursorPositionChanged?.Invoke(this, EventArgs.Empty);
 }
        /// <summary>
        /// Enable Zoom and Pan Controls.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="selectionChanged">Selection changed callabck. Triggered when user select a point with selec tool.</param>
        /// <param name="cursorMoved">Cursor moved callabck. Triggered when user move the mouse in chart area.</param>
        /// <param name="zoomChanged">Callback triggered when chart has
        /// zoomed in or out (and on first painting of the chart).</param>
        /// <remarks>Callback are optional (pass in null to ignore).</remarks>
        public static void EnableZoomAndPanControls(this Chart sender,
                                                    CursorPositionChanged selectionChanged,
                                                    CursorPositionChanged cursorMoved,
                                                    ZoomChanged zoomChanged = null)
        {
            if (!ChartTool.ContainsKey(sender))
            {
                ChartTool[sender] = new ChartData(sender);
                ChartData ptrChartData = ChartTool[sender];
                ptrChartData.Backup();
                ptrChartData.SelectionChangedCallback = selectionChanged;
                ptrChartData.CursorMovedCallback      = cursorMoved;
                ptrChartData.ZoomChangedCallback      = zoomChanged;

                //Populate Context menu
                Chart ptrChart = sender;
                if (ptrChart.ContextMenuStrip == null)
                {
                    //Context menu is empty, use ChartContextMenuStrip directly
                    ptrChart.ContextMenuStrip = new ContextMenuStrip();
                    ptrChart.ContextMenuStrip.Items.AddRange(ChartTool[ptrChart].MenuItems.ToArray());
                }
                else
                {
                    //User assigned context menu to chart. Merge current menu with ChartContextMenuStrip.
                    ContextMenuStrip newMenu = new ContextMenuStrip();
                    newMenu.Items.AddRange(ChartTool[sender].MenuItems.ToArray());

                    foreach (object ptrItem in ChartTool[sender].ContextMenuStrip.Items)
                    {
                        if (ptrItem is ToolStripMenuItem)
                        {
                            newMenu.Items.Add(((ToolStripMenuItem)ptrItem).Clone());
                        }
                        else if (ptrItem is ToolStripSeparator)
                        {
                            newMenu.Items.Add(new ToolStripSeparator());
                        }
                    }
                    newMenu.Items.Add(new ToolStripSeparator());
                    ptrChart.ContextMenuStrip = newMenu;
                    ptrChart.ContextMenuStrip.AddHandlers(ChartTool[sender].ContextMenuStrip);
                }
                ptrChart.ContextMenuStrip.Opening     += ChartContext_Opening;
                ptrChart.ContextMenuStrip.ItemClicked += ChartContext_ItemClicked;
                ptrChart.MouseDown += ChartControl_MouseDown;
                ptrChart.MouseMove += ChartControl_MouseMove;
                ptrChart.MouseUp   += ChartControl_MouseUp;
                ptrChart.PostPaint += ChartOnPostPaint; // Necessary to kickstart ZoomChanged callback

                // The following is for testing out the built-in events.
                //  They don't seem to be as reliable as just handling mouse up/move/down
                //ptrChart.CursorPositionChanging += (sender1, e) =>
                //    {
                //        // Changed event isn't triggered with any zoom or select operations! From looking at the Cursor.cs code, it seems to be a bug.
                //        // Changing event is raised twice, once for each cursor (X, Y)
                //        var axis = e.Axis;
                //    };
                //ptrChart.SelectionRangeChanging += (o, args) =>
                //    {
                //        // Changed event isn't triggered with any zoom or select operations!
                //        // Neither is changed event... odd
                //        Console.WriteLine("SelectionRangeChanging raised " + args.ToString());
                //        var axis = args.Axis;
                //        var chartArea = args.ChartArea;
                //    };


                //Override settings.
                ChartArea ptrChartArea = ptrChart.ChartAreas[0];
                ptrChartArea.CursorX.AutoScroll = false;
                ptrChartArea.CursorX.Interval   = 1e-06;
                ptrChartArea.CursorY.AutoScroll = false;
                ptrChartArea.CursorY.Interval   = 1e-06;

                ptrChartArea.AxisX.ScrollBar.Enabled  = false;
                ptrChartArea.AxisX2.ScrollBar.Enabled = false;
                ptrChartArea.AxisY.ScrollBar.Enabled  = false;
                ptrChartArea.AxisY2.ScrollBar.Enabled = false;

                SetChartControlState(sender, MSChartExtensionToolState.Select);
            }
        }
示例#11
0
 private void OnCursorPositionChanged(object o, MouseInputArgs e)
 {
     CursorPositionChanged?.Invoke(o, e);
 }
        /// <summary>
        /// Enable Zoom and Pan Controls.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="selectionChanged">Selection changed callabck. Triggered when user select a point with selec tool.</param>
        /// <param name="cursorMoved">Cursor moved callabck. Triggered when user move the mouse in chart area.</param>
        /// <param name="zoomChanged">Callback triggered when chart has 
        /// zoomed in or out (and on first painting of the chart).</param>
        /// <param name="option">Additional user options</param>
        /// <remarks>
        /// <para>Callback are optional (pass in null to ignore).</para>
        /// <para>WARNING: Add or Remove Chart Area or Chart Series after enabled zoom and pan controls may cause unexpected behavior.</para>
        /// <para>Recommended to enable the zoom and pan controls after configure the <see cref="ChartArea"/> and <see cref="Series"/>.</para>
        /// </remarks>
        public static void EnableZoomAndPanControls(this Chart sender,
            CursorPositionChanged selectionChanged,
            CursorPositionChanged cursorMoved,
            ZoomChanged zoomChanged = null, ChartOption option = null)
        {
            if (!ChartTool.ContainsKey(sender))
            {
                ChartTool[sender] = new ChartData(sender);
                ChartData ptrChartData = ChartTool[sender];
                ptrChartData.Option = (option == null) ? new ChartOption() : option;
                ptrChartData.Backup();
                ptrChartData.PositionChangedCallback = selectionChanged;
                ptrChartData.CursorMovedCallback = cursorMoved;
                ptrChartData.ZoomChangedCallback = zoomChanged;

                //Scan through series to identify valid ChartArea
                Chart ptrChart = sender;
                foreach (ChartArea cArea in ptrChart.ChartAreas)
                {
                    IEnumerable<Series> chartSeries = ptrChart.Series.Where(n => n.ChartArea == cArea.Name);
                    if (chartSeries.Count() == 0)
                    {
                        Debug.WriteLine(string.Format("WARNING: Chart Area [{0}] does not contains any series.", cArea.Name));
                    }
                    else if (chartSeries.Where(n => UnsupportedChartType.Contains(n.ChartType)).Count() > 0)
                    {
                        Debug.WriteLine(string.Format("WARNING: Chart Area [{0}] contains unsupported series.", cArea.Name));
                    }
                    else ptrChartData.SupportedChartArea.Add(cArea);
                }

                //Populate Context menu
                if (ptrChart.ContextMenuStrip == null)
                {
                    //Context menu is empty, use ChartContextMenuStrip directly
                    ptrChart.ContextMenuStrip = new ContextMenuStrip();
                    ptrChart.ContextMenuStrip.Items.AddRange(ChartTool[ptrChart].MenuItems.ToArray());
                }
                else
                {
                    //User assigned context menu to chart. Merge current menu with ChartContextMenuStrip.
                    ContextMenuStrip newMenu = new ContextMenuStrip();
                    newMenu.Items.AddRange(ChartTool[sender].MenuItems.ToArray());

                    foreach (object ptrItem in ChartTool[sender].ContextMenuStrip.Items)
                    {
                        if (ptrItem is ToolStripMenuItem) newMenu.Items.Add(((ToolStripMenuItem)ptrItem).Clone());
                        else if (ptrItem is ToolStripSeparator) newMenu.Items.Add(new ToolStripSeparator());
                    }
                    ptrChart.ContextMenuStrip = newMenu;
                    ptrChart.ContextMenuStrip.AddHandlers(ChartTool[sender].ContextMenuStrip);
                }
                ptrChart.ContextMenuStrip.Opening += ChartContext_Opening;
                ptrChart.ContextMenuStrip.ItemClicked += ChartContext_ItemClicked;
                ptrChart.MouseWheel += ChartControl_MouseWheel;
                ptrChart.MouseDown += ChartControl_MouseDown;
                ptrChart.MouseMove += ChartControl_MouseMove;
                ptrChart.MouseUp += ChartControl_MouseUp;

                //Override settings.
                foreach (ChartArea ptrChartArea in ptrChart.ChartAreas)
                {
                    ptrChartArea.CursorX.AutoScroll = false;
                    ptrChartArea.CursorX.Interval = 1e-06;
                    ptrChartArea.CursorY.AutoScroll = false;
                    ptrChartArea.CursorY.Interval = 1e-06;

                    ptrChartArea.AxisX.ScrollBar.Enabled = false;
                    ptrChartArea.AxisX2.ScrollBar.Enabled = false;
                    ptrChartArea.AxisY.ScrollBar.Enabled = false;
                    ptrChartArea.AxisY2.ScrollBar.Enabled = false;
                }
                SetChartControlState(sender, MSChartExtensionToolState.Select);
            }
        }
示例#13
0
        /// <param name="win">Окно управления</param>
        public Controller(Control win)
        {
            Form main = win.FindForm();

            win.MouseDown += (s, e) =>
            {
                switch (e.Button)
                {
                case MouseButtons.Left:
                    _isLeftMouseDown     = true;
                    CurrentMousePosition = new Point(e.X, e.Y);
                    break;

                case MouseButtons.Right:
                    _isRightMouseDown    = true;
                    CurrentMousePosition = new Point(e.X, e.Y);
                    break;

                case MouseButtons.Middle:
                    _isMiddleMouseDown   = true;
                    CurrentMousePosition = new Point(e.X, e.Y);
                    break;
                }
            };
            win.MouseUp += (s, e) =>
            {
                switch (e.Button)
                {
                case MouseButtons.Left:
                    _isLeftMouseDown = false;
                    break;

                case MouseButtons.Right:
                    _isRightMouseDown = false;
                    break;

                case MouseButtons.Middle:
                    _isMiddleMouseDown = false;
                    break;
                }
            };
            win.MouseMove += (s, e) =>
            {
                CursorPositionChanged?.Invoke(e.X, e.Y);
                // определить обработку только одной кнопки мыши
                if (_isLeftMouseDown)
                {
                    ShiftByPixel?.Invoke(e.X - CurrentMousePosition.X, e.Y - CurrentMousePosition.Y);
                    CurrentMousePosition = new Point(e.X, e.Y);
                }
                else if (_isMiddleMouseDown)
                {
                    main.Location = new Point(main.Location.X + e.X - CurrentMousePosition.X, main.Location.Y + e.Y - CurrentMousePosition.Y);
                }
            };
            win.MouseWheel += (s, e) =>
            {
                if (e.Delta > 0)
                {
                    ZoomIn?.Invoke(e.X, e.Y);
                }
                else
                {
                    ZoomOut?.Invoke(e.X, e.Y);
                }
            };
            win.KeyUp += (s, e) =>
            {
                Console.WriteLine(e.KeyValue);
                // нажатия на цифру и
                // ЛКМ - уменьшение параметра
                // ПКМ - увеличение параметра
                if (e.KeyValue > 48 && e.KeyValue < 58)
                {
                    if (_isLeftMouseDown)
                    {
                        ParameterReduced?.Invoke(e.KeyValue - 48);
                    }
                    if (_isRightMouseDown)
                    {
                        ParameterIncreased?.Invoke(e.KeyValue - 48);
                    }
                }
                switch ((HotKeys)e.KeyCode)
                {
                case HotKeys.SpeedDown:
                    SpeedDown?.Invoke();
                    break;

                case HotKeys.SpeedUp:
                    SpeedUp?.Invoke();
                    break;

                case HotKeys.StopPlay:
                    StopPlay?.Invoke();
                    break;

                case HotKeys.Statistic:
                    StatisticModeChange?.Invoke();
                    break;

                case HotKeys.ChangeWindowMode:
                    WindowModeChanged?.Invoke();
                    break;

                case HotKeys.FpsUp:
                case HotKeys.FpsUp2:
                    FpsUp?.Invoke();
                    break;

                case HotKeys.FpsDown:
                case HotKeys.FpsDown2:
                    FpsDown?.Invoke();
                    break;

                case HotKeys.SpfUp:
                    StagesByFrameUp?.Invoke();
                    break;

                case HotKeys.SpfDown:
                    StagesByFrameDown?.Invoke();
                    break;

                case HotKeys.Exit:
                    Exit?.Invoke();
                    break;
                }
            };
        }
 /// <summary>
 /// Raises the <see cref="CursorPositionChanged"/> event
 /// </summary>
 /// <param name="sender">The <see cref="Brainf_ckEditBox"/> instance in use</param>
 /// <param name="args">The arguments for the cursor movement</param>
 private void CodeEditBox_CursorPositionChanged(Brainf_ckEditBox sender, CursorPositionChangedEventArgs args)
 {
     CursorPositionChanged?.Invoke(this, args);
 }
示例#15
0
 internal void RaisePositionChanged()
 {
     CursorPositionChanged.Raise(this);
 }