Exemple #1
0
        private void InitInfoBar()
        {
            #region Main Infor Bar
            bdrInfo.ToolTip = Comisor.Resource.Info_c;
            bdrInfo.CornerRadius = new CornerRadius(3);
            bdrInfo.BorderThickness = new Thickness(1);
            bdrInfo.BorderBrush = new SolidColorBrush(colorBorder);
            bdrInfo.Opacity = 0;
            bdrInfo.Visibility = Visibility.Hidden;

            Border bdrContent = new Border();
            StackPanel stpContent = new StackPanel();
            TextBlock txtTitle = new TextBlock();
            Border bdrTitle = new Border();
            bdrContent.Background = new SolidColorBrush(colorInfoBg);
            bdrContent.CornerRadius = new CornerRadius(2);
            bdrContent.Margin = new Thickness(2);

            txtTitle.Text = Comisor.Resource.Info_Title;
            txtTitle.Foreground = new SolidColorBrush(colorFont);
            txtTitle.FontSize = 12;
            bdrTitle.Padding = new Thickness(5, 5, 5, 3);
            bdrTitle.BorderThickness = new Thickness(0, 0, 0, 1);
            bdrTitle.BorderBrush = new LinearGradientBrush(Color.FromArgb(100, 255, 255, 255), Color.FromArgb(0, 255, 255, 255), 0);
            bdrTitle.Child = txtTitle;
            bdrTitle.Cursor = main.resource.curHand_Over;

            txtInfo.IsReadOnly = true;
            txtInfo.BorderThickness = new Thickness(0);
            txtInfo.Padding = new Thickness(3);
            txtInfo.Background = Brushes.Transparent;
            txtInfo.Foreground = new SolidColorBrush(colorFont);
            txtInfo.FontSize = 12;

            stpContent.Children.Add(bdrTitle);
            stpContent.Children.Add(txtInfo);
            bdrContent.Child = stpContent;
            bdrInfo.Child = bdrContent;

            MouseEventHandler InfoDragOn = (o, e) =>
            {
                Point pt = Mouse.GetPosition(cavStage);
                pt.Offset(-ptDragOffset.X, -ptDragOffset.Y);
                TranslateInCanvas(ref bdrInfo, pt, false);
            };

            bdrTitle.PreviewMouseLeftButtonDown += (o, e) =>
            {
                bdrTitle.CaptureMouse();
                bdrTitle.Cursor = main.resource.curHand_Drag;

                ptDragOffset = Mouse.GetPosition(bdrInfo);
                bdrTitle.MouseMove += InfoDragOn;
                e.Handled = true;
            };

            bdrTitle.PreviewMouseLeftButtonUp += (o, e) =>
            {
                bdrTitle.ReleaseMouseCapture();
                bdrTitle.Cursor = main.resource.curHand_Over;
                bdrTitle.MouseMove -= InfoDragOn;
                e.Handled = true;
            };

            bdrInfo.PreviewMouseRightButtonUp += (o, e) =>
            {
                string info = txtInfo.SelectedText.Replace("\t", "\r\n");
                if (info == "") info = txtInfo.Text;
                Clipboard.SetText(info);
                txtPopup.Text = Comisor.Resource.Copied;
                ShowPopup();

                DispatcherTimer tmr = new DispatcherTimer();
                tmr.Interval = TimeSpan.FromMilliseconds(1000);
                EventHandler tmrHidePopup = (oo, ee) =>
                {
                    tmr.Stop();
                    HidePopup();
                };
                tmr.Tick += tmrHidePopup;
                tmr.Start();

                e.Handled = true;
            };

            bdrInfo.PreviewMouseRightButtonDown += (o, e) => { e.Handled = true; };	// Fix the right button up Zoom trigger.

            cavStage.Children.Add(bdrInfo);
            Canvas.SetLeft(bdrInfo, 5);
            Canvas.SetTop(bdrInfo, 5);
            #endregion

            #region Ratio Info Bar
            txtPopup = new TextBlock();
            txtPopup.FontFamily = new FontFamily("Arial");
            txtPopup.FontWeight = FontWeights.Bold;
            txtPopup.FontSize = 14;
            txtPopup.TextAlignment = TextAlignment.Center;
            txtPopup.Foreground = new SolidColorBrush(colorFont);

            txtOriginalSize = new TextBlock();
            txtOriginalSize.FontFamily = new FontFamily("Arial");
            txtOriginalSize.FontSize = 10;
            txtOriginalSize.TextAlignment = TextAlignment.Center;
            txtOriginalSize.Foreground = new SolidColorBrush(Colors.White);

            bdrPopup = new Border();
            bdrPopup.Background = new SolidColorBrush(colorInfoBg);
            bdrPopup.CornerRadius = new CornerRadius(3);
            bdrPopup.Padding = new Thickness(5, 2, 5, 2);
            bdrPopup.Opacity = 0;
            bdrPopup.Visibility = Visibility.Collapsed;

            stpZoomInfoBar = new StackPanel();
            stpZoomInfoBar.Children.Add(txtPopup);
            stpZoomInfoBar.Children.Add(txtOriginalSize);

            bdrPopup.Child = stpZoomInfoBar;
            cavStage.Children.Add(bdrPopup);
            #endregion
        }
Exemple #2
0
        /// <summary>
        /// Registers the events for a draggable (outer) border
        /// </summary>
        /// <param name="borderEdge"></param>
        /// <param name="border"></param>
        void RegisterBorderEvents(WindowBorderEdge borderEdge, Border border)
        {
            border.MouseEnter += (sender, e) => {
                if(WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize) {
                    switch(borderEdge) {
                        case WindowBorderEdge.Left:
                        case WindowBorderEdge.Right:
                            border.Cursor = Cursors.SizeWE;
                            break;
                        case WindowBorderEdge.Top:
                        case WindowBorderEdge.Bottom:
                            border.Cursor = Cursors.SizeNS;
                            break;
                        case WindowBorderEdge.TopLeft:
                        case WindowBorderEdge.BottomRight:
                            border.Cursor = Cursors.SizeNWSE;
                            break;
                        case WindowBorderEdge.TopRight:
                        case WindowBorderEdge.BottomLeft:
                            border.Cursor = Cursors.SizeNESW;
                            break;
                    }
                }
                else
                    border.Cursor = Cursors.Arrow;
            };

            border.MouseLeftButtonDown += (sender, e) => {
                if(WindowState != WindowState.Maximized && ResizeMode == ResizeMode.CanResize) {
                    var cursorLocation = e.GetPosition(this);
                    var cursorOffset = new Point();

                    switch(borderEdge) {
                        case WindowBorderEdge.Left:
                            cursorOffset.X = cursorLocation.X;
                            break;
                        case WindowBorderEdge.TopLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Top:
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.TopRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = cursorLocation.Y;
                            break;
                        case WindowBorderEdge.Right:
                            cursorOffset.X = (Width - cursorLocation.X);
                            break;
                        case WindowBorderEdge.BottomRight:
                            cursorOffset.X = (Width - cursorLocation.X);
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.Bottom:
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                        case WindowBorderEdge.BottomLeft:
                            cursorOffset.X = cursorLocation.X;
                            cursorOffset.Y = (Height - cursorLocation.Y);
                            break;
                    }

                    _cursorOffset = cursorOffset;
                    border.CaptureMouse();
                }
            };

            border.MouseMove += (sender, e) => {
                if(WindowState == WindowState.Maximized || !border.IsMouseCaptured || ResizeMode != ResizeMode.CanResize)
                    return;

                var cursorLocation = e.GetPosition(this);

                var nHorizontalChange = (cursorLocation.X - _cursorOffset.X);
                var pHorizontalChange = (cursorLocation.X + _cursorOffset.X);
                var nVerticalChange = (cursorLocation.Y - _cursorOffset.Y);
                var pVerticalChange = (cursorLocation.Y + _cursorOffset.Y);

                switch(borderEdge) {
                    case WindowBorderEdge.Left:
                        if(Width - nHorizontalChange <= MinWidth)
                            break;
                        Left += nHorizontalChange;
                        Width -= nHorizontalChange;
                        break;
                    case WindowBorderEdge.TopLeft:
                        if(Width - nHorizontalChange <= MinWidth)
                            break;
                        Left += nHorizontalChange;
                        Width -= nHorizontalChange;
                        if(Height - nVerticalChange <= MinHeight)
                            break;
                        Top += nVerticalChange;
                        Height -= nVerticalChange;
                        break;
                    case WindowBorderEdge.Top:
                        if(Height - nVerticalChange <= MinHeight)
                            break;
                        Top += nVerticalChange;
                        Height -= nVerticalChange;
                        break;
                    case WindowBorderEdge.TopRight:
                        if(pHorizontalChange <= MinWidth)
                            break;
                        Width = pHorizontalChange;
                        if(Height - nVerticalChange <= MinHeight)
                            break;
                        Top += nVerticalChange;
                        Height -= nVerticalChange;
                        break;
                    case WindowBorderEdge.Right:
                        if(pHorizontalChange <= MinWidth)
                            break;
                        Width = pHorizontalChange;
                        break;
                    case WindowBorderEdge.BottomRight:
                        if(pHorizontalChange <= MinWidth)
                            break;
                        Width = pHorizontalChange;
                        if(pVerticalChange <= MinHeight)
                            break;
                        Height = pVerticalChange;
                        break;
                    case WindowBorderEdge.Bottom:
                        if(pVerticalChange <= MinHeight)
                            break;
                        Height = pVerticalChange;
                        break;
                    case WindowBorderEdge.BottomLeft:
                        if(Width - nHorizontalChange <= MinWidth)
                            break;
                        Left += nHorizontalChange;
                        Width -= nHorizontalChange;
                        if(pVerticalChange <= MinHeight)
                            break;
                        Height = pVerticalChange;
                        break;
                }
            };

            border.MouseLeftButtonUp += (sender, e) => border.ReleaseMouseCapture();
        }