Offset() public static method

public static Offset ( Rect rect, double offsetX, double offsetY ) : Rect
rect Rect
offsetX double
offsetY double
return Rect
        protected override void OnRender(DrawingContext drawingContext)
        {
            Rect rect = new Rect(startPoint, endPoint);
            rect.Offset(-0.5d, -0.5d);

            drawingContext.DrawRectangle(fill, stroke, rect);
        }
        protected override void OnRender( DrawingContext dc )
        {
            Rect rect;

            if ( myLocation == DropLocation.InPlace )
            {
                rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight ) );
                rect.Inflate( -1, -1 );
            }
            else
            {
                rect = new Rect( new Size( myOwner.ActualWidth, myOwner.ActualHeight * 0.2 ) );
                if ( myLocation == DropLocation.Before )
                {
                    rect.Offset( 0, -myOwner.ActualHeight * 0.1 );
                }
                else if ( myLocation == DropLocation.After )
                {
                    rect.Offset( 0, myOwner.ActualHeight * 0.9 );
                }
                rect.Inflate( -1, 0 );
            }

            var brush = new SolidColorBrush( Colors.LightSkyBlue );
            brush.Opacity = 0.5;

            var pen = new Pen( new SolidColorBrush( Colors.White ), 1 );

            dc.DrawRectangle( brush, pen, rect );
        }
 private static bool FitIntoScreen(Rect workArea, Rect formSize, out Rect newFormSize)
 {
     var hasChanged = false;
       newFormSize = formSize == Rect.Empty ? new Rect() : formSize;
       if (!workArea.Contains(formSize)) {
     // limiting size guarantees form fits into screen
     newFormSize.Width = Math.Min(newFormSize.Width, workArea.Width);
     newFormSize.Height = Math.Min(newFormSize.Height, workArea.Height);
     if (newFormSize.Right > workArea.Right) {
       newFormSize.Offset(workArea.Right - newFormSize.Right, 0);
       hasChanged = true;
     } else if (newFormSize.Left < workArea.Left) {
       newFormSize.Offset(workArea.Left - newFormSize.Left, 0);
       hasChanged = true;
     }
     if (newFormSize.Top < workArea.Top) {
       newFormSize.Offset(0, workArea.Top - newFormSize.Top);
       hasChanged = true;
     } else if (newFormSize.Bottom > workArea.Bottom) {
       newFormSize.Offset(0, workArea.Bottom - newFormSize.Bottom);
       hasChanged = true;
     }
       }
       return hasChanged;
 }
 public static Rect OffsetRect(Rect rect, Vector offset, double scale)
 {
     Rect result = new Rect(rect.TopLeft, rect.BottomRight);
     result.Offset(offset);
     result.Scale(scale, scale);
     return result;
 }
Example #5
0
 // Methods
 protected override Size ArrangeOverride(Size finalSize)
 {
     if (base.Children.Count < 2)
     {
         return base.ArrangeOverride(finalSize);
     }
     bool flag = false;
     double num = 0.0;
     if (((base.Children[0].DesiredSize.Height + base.Children[1].DesiredSize.Height) > finalSize.Height) || ((base.Children[0].DesiredSize.Width + base.Children[1].DesiredSize.Width) < finalSize.Width))
     {
         flag = true;
         num = Math.Max(base.Children[0].DesiredSize.Height, base.Children[1].DesiredSize.Height);
     }
     else
     {
         flag = false;
         num = base.Children[0].DesiredSize.Height + base.Children[1].DesiredSize.Height;
     }
     int num2 = 2;
     for (int i = 2; i < base.Children.Count; i++)
     {
         if ((num + base.Children[i].DesiredSize.Height) > finalSize.Height)
         {
             break;
         }
         num2 = i + 1;
         num += base.Children[i].DesiredSize.Height;
     }
     Rect finalRect = new Rect(0.0, (finalSize.Height - num) / 2.0, finalSize.Width, 0.0);
     if (flag)
     {
         double num4 = Math.Max(base.Children[0].DesiredSize.Height, base.Children[1].DesiredSize.Height);
         finalRect.Width = Math.Min(base.Children[0].DesiredSize.Width, finalSize.Width);
         finalRect.Height = num4;
         base.Children[0].Arrange(finalRect);
         finalRect.X = base.Children[0].DesiredSize.Width;
         finalRect.Width = Math.Max((double)0.0, (double)(finalSize.Width - base.Children[0].DesiredSize.Width));
         base.Children[1].Arrange(finalRect);
         finalRect.X = 0.0;
         finalRect.Y += num4;
         finalRect.Width = finalSize.Width;
     }
     for (int j = flag ? 2 : 0; j < num2; j++)
     {
         finalRect.Height = base.Children[j].DesiredSize.Height;
         base.Children[j].Arrange(finalRect);
         finalRect.Offset(0.0, finalRect.Height);
     }
     finalRect.Height = 0.0;
     for (int k = num2; k < base.Children.Count; k++)
     {
         base.Children[k].Arrange(finalRect);
     }
     return finalSize;
 }
        private void ShowCategoryLabel()
        {
            // Get selected item rectangle.
            ListBoxItem SelectedItem = CategoriesList.ItemContainerGenerator.ContainerFromIndex(CategoriesList.SelectedIndex) as ListBoxItem;

            if (SelectedItem == null || !IsItemVisible(SelectedItem, CategoriesList))
            {
                int VisibleItemIndex = (int)CategoriesList.FindVisualChildren <VirtualizingStackPanel>().FirstOrDefault().VerticalOffset;
                SelectedItem = CategoriesList.ItemContainerGenerator.ContainerFromIndex(VisibleItemIndex) as ListBoxItem;
            }

            Point transform = SelectedItem.TransformToVisual(GridCategories).Transform(new Point());

            System.Windows.Rect SelectedItemBounds = VisualTreeHelper.GetDescendantBounds(SelectedItem);
            SelectedItemBounds.Offset(transform.X, transform.Y);

            // Prepare box for display.
            SelectedCategoryLabel.Content = ((SearchCategoryItem)CategoriesList.SelectedItem).Text;
            SelectedCategoryLabel.Margin  = new Thickness(SelectedItemBounds.Left, SelectedItemBounds.Top, 0, 0);
            SelectedCategoryLabel.Height  = SelectedItemBounds.Bottom - SelectedItemBounds.Top;
            SelectedCategoryLabel.Width   = SelectedItemBounds.Right - SelectedItemBounds.Left;
        }
Example #7
0
 /// <summary> 
 /// Transforms Rect from subpage coordinates
 /// </summary> 
 /// <param name="rect">Rect to which content's offset is applied.</param>
 /// <param name="subpageOffset"> Subpage offset.</param>
 private static void TransformFromSubpage(ref Rect rect, Vector subpageOffset)
 { 
     if (rect == Rect.Empty)
     { 
         return; 
     }
     rect.Offset(subpageOffset); 
 }
Example #8
0
        /// <summary>
        /// Show popup with geocoded address.
        /// </summary>
        /// <param name="e">Reverse geocoding completed event args.</param>
        private void _ShowAddress(AsyncReverseGeocodedEventArgs e)
        {
            IGeocodable geocodable = _GetCurrentGeocodableObject(_mapControl);

            System.Windows.Point initialPoint = (System.Windows.Point)e.UserState;

            if (geocodable != null && _enabled && _mapControl.LastCursorPos.HasValue &&
                _mapControl.LastCursorPos.Value.X == initialPoint.X &&
                _mapControl.LastCursorPos.Value.Y == initialPoint.Y)
            {
                Point cursorPos = _mapControl.LastCursorPos.Value;

                _HideAddressPopups();

                Rect mapRect = new Rect(0, 0, _mapControl.map.ActualWidth, _mapControl.map.ActualHeight);

                Point objectLocation = _ConvertToScreenPos(e.Location);

                // Create canvas with dotted line.
                Canvas canvas = _CreateDottedLineCanvas(objectLocation, _mapControl.LastCursorPos.Value);

                // Get coordinates of top left of canvas.
                double canvasLeft = cursorPos.X;
                if (objectLocation.X < canvasLeft)
                {
                    canvasLeft = objectLocation.X;
                }

                double canvasTop = cursorPos.Y;
                if (objectLocation.Y < canvasTop)
                {
                    canvasTop = objectLocation.Y;
                }

                Rect canvasRect = new System.Windows.Rect(canvasLeft,
                                                          canvasTop, canvas.Width, canvas.Height);

                if (mapRect.Contains(canvasRect))
                {
                    canvasRect.Offset(0, -canvasRect.Height);

                    _dottedLinePopup = _CreatePopup(null, canvas, canvasRect);

                    Point popupPosition = _ConvertToScreenPos(e.Location);

                    // Show ellipse popup in position of reverse geocoded object.
                    Rect ellipseRect = new System.Windows.Rect(popupPosition.X - _sizeOfEllipse / 2,
                                                               popupPosition.Y - 3 * _sizeOfEllipse / 2, _popupWidth, _popupHeigth);
                    _ellipsePopup = _CreatePopup("MapPopupEllipseStyle", null, ellipseRect);

                    // Set cursor to popup. Cursor will be set on ellipse.
                    _ellipsePopup.Cursor = _mapControl.map.Cursor;

                    // Subscribe on mouse down to reraise mouse down on map.
                    _ellipsePopup.MouseDown += new MouseButtonEventHandler(_EllipsePopupMouseDown);

                    // Show address popup higher than IGeocodable object.
                    Rect addressRect = new System.Windows.Rect(popupPosition.X + _popupX,
                                                               popupPosition.Y - _popupY, _popupWidth, _popupHeigth);

                    string address = _GetAddressValue(e.Address);
                    _addressPopup = _CreatePopup("MapPopupStyle", address, addressRect);
                }
            }
        }
Example #9
0
      public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
      {
        Rect viewport = ( Rect )value;
        if( viewport.IsEmpty )
          return viewport;

        // adjust the viewport from the coordinate space of the Content element
        // to the coordinate space of the view finder display panel
        double scale = _zoombox._viewFinderDisplay.Scale * _zoombox._viewboxFactor;
        Rect result = new Rect( viewport.Left * scale, viewport.Top * scale,
            viewport.Width * scale, viewport.Height * scale );
        result.Offset( _zoombox._viewFinderDisplay.ContentBounds.Left,
            _zoombox._viewFinderDisplay.ContentBounds.Top );
        return result;
      }
        /// <summary>
        /// Create Gant TimeLine ranges.
        /// </summary>
        protected override Size _CreateVisualChildren(Size dimension, double rangeWidth, int rangeStepInHour)
        {
            Rect boundingRect = new Rect();

            // Calculate range boundbox.
            Size itemSize = new Size(rangeWidth, dimension.Height);
            Rect itemRect = new Rect(new Point(0, 0), itemSize);

            DateTime currentHour;

            // Define start hour: "0" if _startDate in MaxValue
            if (_startHour.Date == DateTime.MaxValue.Date)
                currentHour = DateTime.MinValue;
            else
                currentHour = _startHour;

            int current = 0;
            while (current < (int)_duration)
            {
                // Create TimeLine range.
                DrawingVisual visualItem = _CreateVisualItem(currentHour, rangeStepInHour, itemRect);
                _children.Add(visualItem);

                boundingRect.Union(visualItem.ContentBounds);

                // Relocate for next element.
                itemRect.Offset(rangeWidth, 0);

                currentHour = currentHour.AddHours(rangeStepInHour);
                current += rangeStepInHour;
            }

            return boundingRect.Size;
        }
Example #11
0
        /// <summary>
        /// LinearPanel computes a position for each of its children taking into account their  
        /// </summary>
        /// <param name="arrangeSize">Size that LinearPanel will assume to position children.</param>
        protected override Size ArrangeOverride(Size arrangeSize)
        {
            var arc = Arc.Fill(arrangeSize, this.MinAngle, this.MaxAngle, this.IsDirectionReversed);
            var rotateTransform = new RotateTransform(0, arc.Centre.X, arc.Centre.Y);
            foreach (UIElement child in this.InternalChildren)
            {
                if (child == null)
                {
                    continue;
                }

                Point ps;
                Point pe;

                double start = GetStart(child);
                double end = GetEnd(child);

                if (double.IsNaN(start) || double.IsNaN(end))
                {
                    double center = GetAtValue(child);

                    if (!double.IsNaN(center))
                    {
                        var angle = TickHelper.ToAngle(center, this.Minimum, this.Maximum, arc);
                        var p1 = arc.GetPoint(angle);
                        var rect = new Rect(child.DesiredSize);
                        rect.Offset(new Vector(p1.X, p1.Y));
                        child.Arrange(rect);
                    }
                }
                else
                {
                    ps = arc.GetPoint(start);
                    pe = arc.GetPoint(end);
                    child.Arrange(new Rect(ps, pe));
                }
            }
            return arrangeSize;
        }
        protected override void OnRender(DrawingContext dc)
        {
            //warning : много хаков!
            if (_diagram == null)
                return;

            Rect actualViewport = new Rect(0, 0, ActualWidth, ActualHeight);

            dc.DrawRectangle(Brushes.White, null, actualViewport);

            Rect boundaries = _diagram.Boundaries;
            Rect viewport = _diagram.Viewport;

            double scale;

            double scaleX = actualViewport.Width / boundaries.Width;
            double scaleY = actualViewport.Height / boundaries.Height;

            scale = scaleX > scaleY ? scaleY : scaleX;

            //прямоугольник с элементами
            Rect viewerBoundaries = new Rect(0, 0, boundaries.Width * scale, boundaries.Height * scale);
            dc.DrawRectangle(Brushes.White, GlobalData.BorderPen, viewerBoundaries);

            //вьюпорт
            Vector offset = new Vector(-boundaries.Left, -boundaries.Top);
            Rect viewerViewport = new Rect(viewport.TopLeft, viewport.BottomRight);
            viewerViewport.Offset(offset.X , offset.Y);
            viewerViewport.Scale(scale, scale);

            //пересекаем
            RectangleGeometry geometryBoundaries = new RectangleGeometry(viewerBoundaries);
            RectangleGeometry geometryViewport = new RectangleGeometry(viewerViewport);
            CombinedGeometry geometryCombined = new CombinedGeometry(GeometryCombineMode.Exclude,
                geometryBoundaries, geometryViewport);

            SolidColorBrush brush = new SolidColorBrush(Colors.LightGray);
            dc.PushOpacity(0.3);

            dc.DrawGeometry(brush, null, geometryCombined);

            dc.Pop();

            dc.PushTransform(new ScaleTransform(scale, scale));
            dc.PushTransform(new TranslateTransform(offset.X, offset.Y));

            _diagram.DrawItems(dc);

            dc.Pop();
            dc.Pop();
        }
Example #13
0
        /// <summary>
        /// Draw the connector lines at a lower level (OnRender) instead
        /// of creating visual tree objects.
        /// </summary>
        protected override void OnRender(DrawingContext drawingContext)
        {
#if DEBUG
            if (displayBorder)
            {
                // Draws borders around the rows and groups.
                foreach (DiagramRow row in rows)
                {
                    // Display row border.
                    Rect bounds = new Rect(row.Location, row.DesiredSize);
                    drawingContext.DrawRectangle(null, new Pen(Brushes.DarkKhaki, 1), bounds);

                    foreach (DiagramGroup group in row.Groups)
                    {
                        // Display group border.
                        bounds = new Rect(group.Location, group.DesiredSize);
                        bounds.Offset(row.Location.X, row.Location.Y);
                        bounds.Inflate(-1, -1);
                        drawingContext.DrawRectangle(null, new Pen(Brushes.Gray, 1), bounds);
                    }
                }
            }
#endif

            // Draw child connectors first, so marriage information appears on top.
            foreach (DiagramConnector connector in logic.Connections)
            {
                if (connector.IsChildConnector)
                    connector.Draw(drawingContext);
            }

            // Draw all other non-child connectors.
            foreach (DiagramConnector connector in logic.Connections)
            {
                if (!connector.IsChildConnector)
                    connector.Draw(drawingContext);
            }
        }
Example #14
0
        private static void Overlap_Delegate()
        {
            int i = 0;
            Canvas _mainCanvas = (Canvas)delegate_Data[i++];
            UIElement obj1 = (UIElement)delegate_Data[i++];

            Rect rect1 = new Rect(obj1.RenderSize);
            rect1.Offset(VisualTreeHelper.GetOffset(obj1));

            if (obj1.GetType() == typeof(Ellipse))
            {
                EllipseGeometry geometry = new EllipseGeometry(rect1);
                HitTestResults.Clear();
                VisualTreeHelper.HitTest(_mainCanvas, new HitTestFilterCallback(_HitTestFilterGeometry), new HitTestResultCallback(_HitTestResultGeometry), new GeometryHitTestParameters(geometry));
            }
            else
            {
                RectangleGeometry geometry = new RectangleGeometry(rect1);
                HitTestResults.Clear();
                VisualTreeHelper.HitTest(_mainCanvas, new HitTestFilterCallback(_HitTestFilterGeometry), new HitTestResultCallback(_HitTestResultGeometry), new GeometryHitTestParameters(geometry));
            }
        }
Example #15
0
        /// <summary>
        /// Checks for shape overlap of bounding boxes (collision detection).
        /// </summary>
        /// <param name="shape1">
        /// The first shape name.
        /// </param>
        /// <param name="shape2">
        /// The second shape name.
        /// </param>
        /// <returns>
        /// "True" or "False".
        /// </returns>
        public static Primitive OverlapBox(Primitive shape1, Primitive shape2)
        {
            UIElement obj1, obj2;

            try
            {
                if (!_objectsMap.TryGetValue((string)shape1, out obj1))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape1);
                    return "False";
                }
                if (!_objectsMap.TryGetValue((string)shape2, out obj2))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape2);
                    return "False";
                }

                Rect rect1 = new Rect(obj1.RenderSize);
                Rect rect2 = new Rect(obj2.RenderSize);
                rect1.Offset(VisualTreeHelper.GetOffset(obj1));
                rect2.Offset(VisualTreeHelper.GetOffset(obj2));
                return rect1.IntersectsWith(rect2) ? "True" : "False";
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "False";
            }
        }
Example #16
0
        protected override DrawingVisual RenderCore(RenderParameters renderParams)
        {
            caretRect.Height = Configurations.FontDisplayHeight;
            if (null == drawingVisual)
            {
                drawingVisual = new DrawingVisual();
                PauseCaretTimer(false); // Get timer going!
            }

            // There's no script yet.
            if (null == this.currentScript)
            {
                return(drawingVisual);
            }

            DrawingContext context = drawingVisual.RenderOpen();

            CodeFragment[] crossHighlight = textEditorCanvas.TextEditorCore.GetCrossHighlightArray();

            if (crossHighlight != null)
            {
                if (crossHighlight.Length != 0)
                {
                    List <Rect> rectList = new List <Rect>();
                    foreach (CodeFragment codeFragment in crossHighlight)
                    {
                        CharPosition start = currentScript.CreateCharPosition();
                        start.SetCharacterPosition(codeFragment.ColStart, codeFragment.Line);
                        CharPosition end = currentScript.CreateCharPosition();
                        end.SetCharacterPosition(codeFragment.ColEnd + 1, codeFragment.Line);
                        List <Rect> tempList = CalculateRectangles(start, end, renderParams.firstVisibleLine);
                        if (tempList != null)
                        {
                            rectList.AddRange(tempList);
                        }
                    }
                    //SolidColorBrush crossHighlightBrush = new SolidColorBrush(Color.FromRgb(226, 230, 214));
                    RenderRectangles(context, rectList, UIColors.CrossHighlightColor);
                }
            }

            // We don't care about keyboard focus when in playback mode.
            if (false == TextEditorControl.Instance.IsInPlaybackMode)
            {
                // If the focus is not within the canvas, or on any extension popup,
                // then there's no need to show the caret (focus is probably other app).
                if (false == TextEditorControl.Instance.ShouldDisplayCaret())
                {
                    caretVisibility = System.Windows.Visibility.Hidden;
                }
            }

            // Cursor rendering pass...
            if (caretVisibility == System.Windows.Visibility.Visible)
            {
                System.Windows.Rect displayRect = caretRect;
                double firstVisibleColumn       = textEditorCanvas.FirstVisibleColumn * Configurations.FormatFontWidth;
                displayRect.Offset(-firstVisibleColumn, -renderParams.firstVisibleLine * Configurations.FontDisplayHeight);
                context.DrawRectangle(Brushes.Black, null, displayRect);
            }

            context.Close();
            return(drawingVisual);
        }
        /// -------------------------------------------------------------------
        /// <summary>
        /// Remove any point where the logicla element falls outside of
        /// the boundaries of the parent containing control.
        /// </summary>
        /// -------------------------------------------------------------------
        void TS_MaskOutParentRect(AutomationElement element, ref Drawing.Bitmap bm)
        {
            Rect leRect = element.Current.BoundingRectangle;
            Rect parentRect = ControlParent(element).Current.BoundingRectangle;

            // Cut it at the edge of the screen
            parentRect = new Rect(parentRect.Left < 0 ? 0 : parentRect.Left, parentRect.Top < 0 ? 0 : parentRect.Top, parentRect.Right - parentRect.Left, parentRect.Bottom - parentRect.Top);
            leRect = new Rect(leRect.Left < 0 ? 0 : leRect.Left, leRect.Top < 0 ? 0 : leRect.Top, leRect.Right - leRect.Left, leRect.Bottom - leRect.Top);

            // Offset it since the origin of the bitmap is 0,0
            parentRect.Offset(leRect.X, leRect.Y);

            Rect outsideRect;
            Drawing.Brush brush = new Drawing.SolidBrush(m_maskColor);
            Drawing.Graphics g = Drawing.Graphics.FromImage(bm);

            // Is the element wholy within the parent, just return...most cases
            if (parentRect.Contains(leRect))
            {
                Comment("Element is not cliped by the parent");
                m_TestStep++;
                return;
            }

            // TODO: Get rid of the new Rect and just go new RectangleF
            // Extents out the top
            outsideRect = new Rect(leRect.Left, leRect.Top, leRect.Right, parentRect.Top);
            g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));

            // Extends out the right
            outsideRect = new Rect(parentRect.Right, leRect.Top, leRect.Bottom, leRect.Right);
            g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));

            // Extends out the left
            outsideRect = new Rect(leRect.Left, leRect.Top, parentRect.Left, leRect.Bottom);
            g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));

            // Extends out the bottom
            outsideRect = new Rect(leRect.Left, parentRect.Bottom, leRect.Right, leRect.Bottom);
            g.FillRectangle(brush, new Drawing.RectangleF((float)outsideRect.X, (float)outsideRect.Y, (float)outsideRect.Width, (float)outsideRect.Height));

            brush.Dispose();

            Comment("Element is cliped by the parent and it's rectangle has been removed from the element's displayed rectangle");
            m_TestStep++;
        }
    GetFormattedTextBounds
    (
        FormattedText formattedText,
        Point origin
    )
    {
        Debug.Assert(formattedText != null);

        Double dTextBottom =
            formattedText.Height + formattedText.OverhangAfter;

        Double dTextTop = dTextBottom - formattedText.Extent;
        Size oSize = GetFormattedTextSize(formattedText);

        Rect oBounds = new Rect(formattedText.OverhangLeading, dTextTop,
            oSize.Width, oSize.Height);

        oBounds.Offset(origin.X, origin.Y);

        return (oBounds);
    }
Example #19
0
 /// <summary>
 /// Offset - return the result of offsetting rect by the offset provided
 /// If this is Empty, this method is illegal.
 /// </summary>
 public static Rect Offset(Rect rect, double offsetX, double offsetY)
 {
     rect.Offset(offsetX, offsetY);
     return(rect);
 }
        private void _LegacyInitializeCaptionButtonLocation()
        {
            // This calculation isn't quite right, but it's pretty close.
            // I expect this is good enough for the scenarios where this is expected to be used.
            int captionX = NativeMethods.GetSystemMetrics(SM.CXSIZE);
            int captionY = NativeMethods.GetSystemMetrics(SM.CYSIZE);

            int frameX = NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CXEDGE);
            int frameY = NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CYEDGE);

            Rect deviceCaptionLocation = new Rect(0.0, 0.0, (captionX * 3), captionY);
            deviceCaptionLocation.Offset(-frameX - deviceCaptionLocation.Width, frameY);
            Rect logicalCaptionLocation = DpiHelper.DeviceRectToLogical(deviceCaptionLocation);

            WindowCaptionButtonsLocation = logicalCaptionLocation;
        }
        private void _SetRoundingRegion(WINDOWPOS? wp)
        {
            const int MONITOR_DEFAULTTONEAREST = 0x00000002;

            // We're early - WPF hasn't necessarily updated the state of the window.
            // Need to query it ourselves.
            WINDOWPLACEMENT wpl = NativeMethods.GetWindowPlacement(_hwnd);

            if (wpl.showCmd == SW.SHOWMAXIMIZED)
            {
                int left;
                int top;

                if (wp.HasValue)
                {
                    left = wp.Value.x;
                    top = wp.Value.y;
                }
                else
                {
                    Rect r = _GetWindowRect();
                    left = (int)r.Left;
                    top = (int)r.Top;
                }

                IntPtr hMon = NativeMethods.MonitorFromWindow(_hwnd, MONITOR_DEFAULTTONEAREST);

                MONITORINFO mi = NativeMethods.GetMonitorInfo(hMon);
                RECT rcMax = mi.rcWork;
                // The location of maximized window takes into account the border that Windows was
                // going to remove, so we also need to consider it.
                rcMax.Offset(-left, -top);

                IntPtr hrgn = IntPtr.Zero;
                try
                {
                    hrgn = NativeMethods.CreateRectRgnIndirect(rcMax);
                    NativeMethods.SetWindowRgn(_hwnd, hrgn, NativeMethods.IsWindowVisible(_hwnd));
                    hrgn = IntPtr.Zero;
                }
                finally
                {
                    Utility.SafeDeleteObject(ref hrgn);
                }
            }
            else
            {
                Size windowSize;

                // Use the size if it's specified.
                if (null != wp && !Utility.IsFlagSet(wp.Value.flags, (int)SWP.NOSIZE))
                {
                    windowSize = new Size((double)wp.Value.cx, (double)wp.Value.cy);
                }
                else if (null != wp && (_lastRoundingState == _window.WindowState))
                {
                    return;
                }
                else
                {
                    windowSize = _GetWindowRect().Size;
                }

                _lastRoundingState = _window.WindowState;

                IntPtr hrgn = IntPtr.Zero;
                try
                {
                    double shortestDimension = Math.Min(windowSize.Width, windowSize.Height);

                    double topLeftRadius = DpiHelper.LogicalPixelsToDevice(new Point(_chromeInfo.CornerRadius.TopLeft, 0)).X;
                    topLeftRadius = Math.Min(topLeftRadius, shortestDimension / 2);

                    if (_IsUniform(_chromeInfo.CornerRadius))
                    {
                        // RoundedRect HRGNs require an additional pixel of padding.
                        hrgn = _CreateRoundRectRgn(new Rect(windowSize), topLeftRadius);
                    }
                    else
                    {
                        // We need to combine HRGNs for each of the corners.
                        // Create one for each quadrant, but let it overlap into the two adjacent ones
                        // by the radius amount to ensure that there aren't corners etched into the middle
                        // of the window.
                        hrgn = _CreateRoundRectRgn(new Rect(0, 0, windowSize.Width / 2 + topLeftRadius, windowSize.Height / 2 + topLeftRadius), topLeftRadius);

                        double topRightRadius = DpiHelper.LogicalPixelsToDevice(new Point(_chromeInfo.CornerRadius.TopRight, 0)).X;
                        topRightRadius = Math.Min(topRightRadius, shortestDimension / 2);
                        Rect topRightRegionRect = new Rect(0, 0, windowSize.Width / 2 + topRightRadius, windowSize.Height / 2 + topRightRadius);
                        topRightRegionRect.Offset(windowSize.Width / 2 - topRightRadius, 0);
                        Assert.AreEqual(topRightRegionRect.Right, windowSize.Width);

                        _CreateAndCombineRoundRectRgn(hrgn, topRightRegionRect, topRightRadius);

                        double bottomLeftRadius = DpiHelper.LogicalPixelsToDevice(new Point(_chromeInfo.CornerRadius.BottomLeft, 0)).X;
                        bottomLeftRadius = Math.Min(bottomLeftRadius, shortestDimension / 2);
                        Rect bottomLeftRegionRect = new Rect(0, 0, windowSize.Width / 2 + bottomLeftRadius, windowSize.Height / 2 + bottomLeftRadius);
                        bottomLeftRegionRect.Offset(0, windowSize.Height / 2 - bottomLeftRadius);
                        Assert.AreEqual(bottomLeftRegionRect.Bottom, windowSize.Height);

                        _CreateAndCombineRoundRectRgn(hrgn, bottomLeftRegionRect, bottomLeftRadius);

                        double bottomRightRadius = DpiHelper.LogicalPixelsToDevice(new Point(_chromeInfo.CornerRadius.BottomRight, 0)).X;
                        bottomRightRadius = Math.Min(bottomRightRadius, shortestDimension / 2);
                        Rect bottomRightRegionRect = new Rect(0, 0, windowSize.Width / 2 + bottomRightRadius, windowSize.Height / 2 + bottomRightRadius);
                        bottomRightRegionRect.Offset(windowSize.Width / 2 - bottomRightRadius, windowSize.Height / 2 - bottomRightRadius);
                        Assert.AreEqual(bottomRightRegionRect.Right, windowSize.Width);
                        Assert.AreEqual(bottomRightRegionRect.Bottom, windowSize.Height);

                        _CreateAndCombineRoundRectRgn(hrgn, bottomRightRegionRect, bottomRightRadius);
                    }

                    NativeMethods.SetWindowRgn(_hwnd, hrgn, NativeMethods.IsWindowVisible(_hwnd));
                    hrgn = IntPtr.Zero;
                }
                finally
                {
                    // Free the memory associated with the HRGN if it wasn't assigned to the HWND.
                    Utility.SafeDeleteObject(ref hrgn);
                }
            }
        }
Example #22
0
        public void CalculateViewport()
        {
            Rect actualView = new Rect(0, 0, this.ActualWidth, this.ActualHeight);

            actualView.Scale(1 / Scale, 1 / Scale);
            actualView.Offset(-this.XViewOffset, -this.YViewOffset);

            _viewport = actualView;
        }
Example #23
0
 /// <summary>
 /// Offset - return the result of offsetting rect by the offset provided
 /// If this is Empty, this method is illegal.
 /// </summary>
 public static Rect Offset(Rect rect, Vector offsetVector)
 {
     rect.Offset(offsetVector.X, offsetVector.Y);
     return(rect);
 }
        private void SetRoundingRegion(NativeMethods.WINDOWPOS? wp)
        {
            const int MONITOR_DEFAULTTONEAREST = 0x00000002;

            // We're early - WPF hasn't necessarily updated the state of the window.
            // Need to query it ourselves.
            NativeMethods.WINDOWPLACEMENT wpl = new NativeMethods.WINDOWPLACEMENT();
            NativeMethods.GetWindowPlacement(handle, wpl);

            if (wpl.showCmd == NativeMethods.SW_SHOWMAXIMIZED && IsDwmEnabled == true)
            {
                int left;
                int top;

                if (wp.HasValue)
                {
                    left = wp.Value.x;
                    top = wp.Value.y;
                }
                else
                {
                    NativeMethods.Rect r = new NativeMethods.Rect();
                    NativeMethods.GetWindowRect(handle, ref r);
                    left = r.Left;
                    top = r.Top;
                }

                IntPtr hMon = NativeMethods.MonitorFromWindow(handle, MONITOR_DEFAULTTONEAREST);

                NativeMethods.MonitorInfo mi = new NativeMethods.MonitorInfo();
                NativeMethods.GetMonitorInfo(hMon, mi);
                NativeMethods.Rect rcMax = mi.Work;
                // The location of maximized window takes into account the border that Windows was
                // going to remove, so we also need to consider it.
                rcMax.Left -= left; rcMax.Right -= left;
                rcMax.Top -= top; rcMax.Bottom -= top;

                IntPtr hrgn = IntPtr.Zero;
                try
                {
                    hrgn = NativeMethods.CreateRectRgnIndirect(ref rcMax);
                    NativeMethods.SetWindowRgn(handle, hrgn, NativeMethods.IsWindowVisible(handle));
                    hrgn = IntPtr.Zero;
                }
                finally
                {
                    NativeMethods.DeleteObject(hrgn);
                }
            }
            else
            {
                Size windowSize;

                // Use the size if it's specified.
                if (null != wp && !IsFlagSet(wp.Value.flags, NativeMethods.SWP_NOSIZE))
                {
                    windowSize = new Size((double)wp.Value.cx, (double)wp.Value.cy);
                }
                else if (null != wp && (lastRoundingState == WindowState))
                {
                    return;
                }
                else
                {
                    NativeMethods.Rect r = new NativeMethods.Rect();
                    NativeMethods.GetWindowRect(handle, ref r);
                    Rect rect = new Rect(r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top);
                    windowSize = rect.Size;
                }

                lastRoundingState = WindowState;

                IntPtr hrgn = IntPtr.Zero;
                try
                {
                    double shortestDimension = Math.Min(windowSize.Width, windowSize.Height);

                    double topLeftRadius = DpiHelper.LogicalPixelsToDevice(new Point(CornerRadius.TopLeft, 0)).X;
                    topLeftRadius = Math.Min(topLeftRadius, shortestDimension / 2);

                    if (IsUniform(CornerRadius))
                    {
                        // RoundedRect HRGNs require an additional pixel of padding.
                        hrgn = CreateRoundRectRgn(new Rect(windowSize), topLeftRadius);
                    }
                    else
                    {
                        // We need to combine HRGNs for each of the corners.
                        // Create one for each quadrant, but let it overlap into the two adjacent ones
                        // by the radius amount to ensure that there aren't corners etched into the middle
                        // of the window.
                        hrgn = CreateRoundRectRgn(new Rect(0, 0, windowSize.Width / 2 + topLeftRadius, windowSize.Height / 2 + topLeftRadius), topLeftRadius);

                        double topRightRadius = DpiHelper.LogicalPixelsToDevice(new Point(CornerRadius.TopRight, 0)).X;
                        topRightRadius = Math.Min(topRightRadius, shortestDimension / 2);
                        Rect topRightRegionRect = new Rect(0, 0, windowSize.Width / 2 + topRightRadius, windowSize.Height / 2 + topRightRadius);
                        topRightRegionRect.Offset(windowSize.Width / 2 - topRightRadius, 0);

                        CreateAndCombineRoundRectRgn(hrgn, topRightRegionRect, topRightRadius);

                        double bottomLeftRadius = /*DpiHelper.LogicalPixelsToDevice*/(new Point(CornerRadius.BottomLeft, 0)).X;
                        bottomLeftRadius = Math.Min(bottomLeftRadius, shortestDimension / 2);
                        Rect bottomLeftRegionRect = new Rect(0, 0, windowSize.Width / 2 + bottomLeftRadius, windowSize.Height / 2 + bottomLeftRadius);
                        bottomLeftRegionRect.Offset(0, windowSize.Height / 2 - bottomLeftRadius);

                        CreateAndCombineRoundRectRgn(hrgn, bottomLeftRegionRect, bottomLeftRadius);

                        double bottomRightRadius = DpiHelper.LogicalPixelsToDevice(new Point(CornerRadius.BottomRight, 0)).X;
                        bottomRightRadius = Math.Min(bottomRightRadius, shortestDimension / 2);
                        Rect bottomRightRegionRect = new Rect(0, 0, windowSize.Width / 2 + bottomRightRadius, windowSize.Height / 2 + bottomRightRadius);
                        bottomRightRegionRect.Offset(windowSize.Width / 2 - bottomRightRadius, windowSize.Height / 2 - bottomRightRadius);

                        CreateAndCombineRoundRectRgn(hrgn, bottomRightRegionRect, bottomRightRadius);
                    }

                    NativeMethods.SetWindowRgn(handle, hrgn, NativeMethods.IsWindowVisible(handle));
                    hrgn = IntPtr.Zero;
                }
                finally
                {
                    // Free the memory associated with the HRGN if it wasn't assigned to the HWND.
                    NativeMethods.DeleteObject(hrgn);
                }
            }
        }
		private void UpdateZoomRect(Point zoomEndPoint) {
			Rect output = Viewport.Output;
			Rect tmpZoomRect = new Rect(zoomStartPoint, zoomEndPoint);
			tmpZoomRect = Rect.Intersect(tmpZoomRect, output);

			shouldKeepRatioWhileZooming = IsShiftPressed();
			if (shouldKeepRatioWhileZooming) {
				double currZoomRatio = tmpZoomRect.Width / tmpZoomRect.Height;
				double zoomRatio = output.Width / output.Height;
				if (currZoomRatio < zoomRatio) {
					double oldHeight = tmpZoomRect.Height;
					double height = tmpZoomRect.Width / zoomRatio;
					tmpZoomRect.Height = height;
					if (!tmpZoomRect.Contains(zoomStartPoint)) {
						tmpZoomRect.Offset(0, oldHeight - height);
					}
				}
				else {
					double oldWidth = tmpZoomRect.Width;
					double width = tmpZoomRect.Height * zoomRatio;
					tmpZoomRect.Width = width;
					if (!tmpZoomRect.Contains(zoomStartPoint)) {
						tmpZoomRect.Offset(oldWidth - width, 0);
					}
				}
			}

			zoomRect = tmpZoomRect;
			UpdateSelectionAdorner();
		}
Example #26
0
        /// <summary>
        /// Checks for shape overlap of bounding circles (collision detection).
        /// </summary>
        /// <param name="shape1">
        /// The first shape name.
        /// </param>
        /// <param name="shape2">
        /// The second shape name.
        /// </param>
        /// <returns>
        /// "True" or "False".
        /// </returns>
        public static Primitive OverlapCircle(Primitive shape1, Primitive shape2)
        {
            UIElement obj1, obj2;

            try
            {
                if (!_objectsMap.TryGetValue((string)shape1, out obj1))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape1);
                    return "False";
                }
                if (!_objectsMap.TryGetValue((string)shape2, out obj2))
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shape2);
                    return "False";
                }

                Rect rect1 = new Rect(obj1.RenderSize);
                Rect rect2 = new Rect(obj2.RenderSize);
                rect1.Offset(VisualTreeHelper.GetOffset(obj1));
                rect2.Offset(VisualTreeHelper.GetOffset(obj2));

                double rad1 = System.Math.Sqrt((rect1.Width * rect1.Width + rect1.Height * rect1.Height) / 2.0) / 2.0;
                double rad2 = System.Math.Sqrt((rect2.Width * rect2.Width + rect2.Height * rect2.Height) / 2.0) / 2.0;
                double dx = (rect1.X + rect1.Width / 2.0) - (rect2.X + rect2.Width / 2.0);
                double dy = (rect1.Y + rect1.Height / 2.0) - (rect2.Y + rect2.Height / 2.0);
                double dist = System.Math.Sqrt(dx * dx + dy * dy);

                return dist <= rad1 + rad2 ? "True" : "False";

            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "False";
            }
        }
Example #27
0
        protected void ArrangeChild( UIElement child, Rect placementRect )
        {
            // Offset in case SwitchPanel is handling scroll.
              if( placementRect.IsEmpty == false && this.PhysicalScrollOffset.Length > 0 )
              {
            placementRect.Offset( -this.PhysicalScrollOffset );
              }

              // cannot start animations unless the panel is loaded
              if( this.HasLoaded )
              {
            if( this.BeginChildAnimation( child, placementRect ) )
            {
              this.AnimatingChildCount++;
            }
              }
              else
              {
            // just arrange the child if the panel has not yet loaded
            child.Arrange( placementRect );
              }
        }
Example #28
0
    protected override Size ArrangeOverride( Size finalSize )
    {
      Rect finalRect = new Rect();

      if( _visibleElements == null )
      {
        LayoutItems( InternalChildren, finalSize );
      }

      foreach( DateElement child in _visibleElements )
      {
        if( IsScrolling )
        {
          Rect placement = new Rect( child.PlacementRectangle.Location, child.PlacementRectangle.Size );
          placement.Offset( -_offset );

          child.Element.Arrange( placement );
        }
        else
        {
          child.Element.Arrange( child.PlacementRectangle );
        }

        finalRect.Union( child.PlacementRectangle );
      }

      Size renderSize;

      if( Orientation == Orientation.Horizontal )
      {
        renderSize = new Size( finalSize.Width, finalRect.Size.Height );
      }
      else
      {
        renderSize = new Size( finalRect.Size.Width, finalSize.Height );
      }

      return renderSize;
    }
Example #29
0
 internal override void TransformRect(ref Rect rect)
 {
     if (!rect.IsEmpty)
     {
         rect.Offset(X, Y);
     }
 }
        private void _LegacyInitializeCaptionButtonLocation()
        {
            // This calculation isn't quite right, but it's pretty close.
            // I expect this is good enough for the scenarios where this is expected to be used.
            int captionX = NativeMethods.GetSystemMetrics(SM.CXSIZE);
            int captionY = NativeMethods.GetSystemMetrics(SM.CYSIZE);

            int frameX = NativeMethods.GetSystemMetrics(SM.CXSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CXEDGE);
            int frameY = NativeMethods.GetSystemMetrics(SM.CYSIZEFRAME) + NativeMethods.GetSystemMetrics(SM.CYEDGE);

            Rect captionRect = new Rect(0, 0, captionX * 3, captionY);
            captionRect.Offset(-frameX - captionRect.Width, frameY);

            WindowCaptionButtonsLocation = captionRect;
        }
        double[] ITextRangeProvider.GetBoundingRectangles()
        {
            // Return zero rectangles for a degenerate range.   We don't return an empty, 
            // but properly positioned, rectangle for degenerate ranges because
            // there is ambiguity at line breaks and some international scenarios.
            if (IsDegenerate)
            {
                return new double[0];
            }

            // we'll need to have the text eventually (so we can measure characters) so get it up
            // front so we can check the endpoints before proceeding.
            string text = _provider.GetText();
            ValidateEndpoints();

            // get the mapping from client coordinates to screen coordinates
            NativeMethods.Win32Point w32point;
            w32point.x = 0;
            w32point.y = 0;
            if (!Misc.MapWindowPoints(_provider.WindowHandle, IntPtr.Zero, ref w32point, 1))
            {
                return new double[0];
            }
            Point mapClientToScreen = new Point(w32point.x, w32point.y);

            // clip the rectangles to the edit control's formatting rectangle
            Rect clippingRectangle = _provider.GetRect();

            // we accumulate rectangles onto a list
            ArrayList rects;

            if (_provider.IsMultiline)
            {
                rects = GetMultilineBoundingRectangles(text, mapClientToScreen, clippingRectangle);
            }
            else
            {
                // single line edit control

                rects = new ArrayList(1);

                // figure out the rectangle for this one line
                Point startPoint = _provider.PosFromChar(Start);
                Point endPoint = _provider.PosFromCharUR(End - 1, text);
                Rect rect = new Rect(startPoint.X, startPoint.Y, endPoint.X - startPoint.X, clippingRectangle.Height);
                rect.Intersect(clippingRectangle);

                // use the rectangle if it is non-empty.
                if (rect.Width > 0 && rect.Height > 0)  // r.Empty is true only if both width & height are zero.  Duh!
                {
                    rect.Offset(mapClientToScreen.X, mapClientToScreen.Y);
                    rects.Add(rect);
                }
            }

            // convert the list of rectangles into an array for returning
            Rect[] rectArray = new Rect[rects.Count];
            rects.CopyTo(rectArray);

            return Misc.RectArrayToDoubleArray(rectArray);
        }
Example #32
0
    DrawStraightLabel
    (
        DrawingContext oDrawingContext,
        GraphDrawingContext oGraphDrawingContext,
        FormattedText oFormattedText,
        Point oEdgeEndpoint1,
        Point oEdgeEndpoint2,
        Double dLabelOriginAsFractionOfEdgeLength,
        Double dEdgeLength,
        Double dBufferWidth,
        Color oTranslucentRectangleColor
    )
    {
        Debug.Assert(oDrawingContext != null);
        Debug.Assert(oGraphDrawingContext != null);
        Debug.Assert(oFormattedText != null);
        Debug.Assert(dLabelOriginAsFractionOfEdgeLength >= 0);
        Debug.Assert(dEdgeLength >= 0);
        Debug.Assert(dBufferWidth >= 0);
        AssertValid();

        if (oEdgeEndpoint2.X < oEdgeEndpoint1.X)
        {
            // Don't let text be drawn upside-down.

            WpfGraphicsUtil.SwapPoints(ref oEdgeEndpoint1, ref oEdgeEndpoint2);
        }

        // To avoid trigonometric calculations, use a RotateTransform to make
        // the edge look as if it is horizontal, with oEdgeEndpoint2 to the
        // right of oEdgeEndpoint1.

        Double dEdgeAngleDegrees = MathUtil.RadiansToDegrees(
            WpfGraphicsUtil.GetAngleBetweenPointsRadians(
                oEdgeEndpoint1, oEdgeEndpoint2) );

        RotateTransform oRotateTransform = new RotateTransform(
            dEdgeAngleDegrees, oEdgeEndpoint1.X, oEdgeEndpoint1.Y);

        oRotateTransform.Angle = -dEdgeAngleDegrees;
        oDrawingContext.PushTransform(oRotateTransform);

        Double dTextWidth = oFormattedText.Width;
        Double dEdgeLengthMinusBuffers = dEdgeLength - 2 * dBufferWidth;

        Point oLabelOrigin = oEdgeEndpoint1;

        // The text should be vertically centered on the edge.

        oLabelOrigin.Offset(dLabelOriginAsFractionOfEdgeLength * dEdgeLength,
            -oFormattedText.Height / 2.0);

        // Determine where to draw a translucent rectangle behind the text.
        // The translucent rectangle serves to obscure, but not completely
        // hide, the underlying edge.

        Rect oTranslucentRectangle;

        if (dTextWidth > dEdgeLengthMinusBuffers)
        {
            // The translucent rectangle should be the same width as the text.

            oTranslucentRectangle = new Rect( oLabelOrigin,
                new Size(dEdgeLengthMinusBuffers, oFormattedText.Height) );
        }
        else
        {
            // The label is centered along the edge's length.

            // The translucent rectangle should extend between zero and one
            // buffer units beyond the ends of the text.  This provides a
            // margin between the text and the unobscured edge, if there is
            // enough space.

            oTranslucentRectangle = new Rect( oLabelOrigin,

                new Size(
                    Math.Min(dTextWidth + 2 * dBufferWidth,
                        dEdgeLengthMinusBuffers),

                    oFormattedText.Height)
                );

            oTranslucentRectangle.Offset(-dBufferWidth, 0);
        }

        DrawTranslucentRectangle(oDrawingContext, oTranslucentRectangle,
            oTranslucentRectangleColor);

        oDrawingContext.DrawText(oFormattedText, oLabelOrigin);

        oDrawingContext.Pop();
    }
        // helper function to accumulate a list of bounding rectangles for a potentially mult-line range
        private ArrayList GetMultilineBoundingRectangles(string text, Point mapClientToScreen, Rect clippingRectangle)
        {
            // remember the line height
            int height = Math.Abs(_provider.GetLogfont().lfHeight);;

            // get the starting and ending lines for the range.
            int start = Start;
            int end = End;

            int startLine = _provider.LineFromChar(start);
            int endLine = _provider.LineFromChar(end - 1);

            // adjust the start based on the first visible line

            int firstVisibleLine = _provider.GetFirstVisibleLine();
            if (firstVisibleLine > startLine)
            {
                startLine = firstVisibleLine;
                start = _provider.LineIndex(startLine);
            }

            // adjust the end based on the last visible line
            int lastVisibleLine = firstVisibleLine + _provider.LinesPerPage() - 1;
            if (lastVisibleLine < endLine)
            {
                endLine = lastVisibleLine;
                end = _provider.LineIndex(endLine) - 1;
            }

            // adding a rectangle for each line
            ArrayList rects = new ArrayList(Math.Max(endLine - startLine + 1, 0));
            int nextLineIndex = _provider.LineIndex(startLine);
            for (int i = startLine; i <= endLine; i++)
            {
                // determine the starting coordinate on this line
                Point startPoint;
                if (i == startLine)
                {
                    startPoint = _provider.PosFromChar(start);
                }
                else
                {
                    startPoint = _provider.PosFromChar(nextLineIndex);
                }

                // determine the ending coordinate on this line
                Point endPoint;
                if (i == endLine)
                {
                    endPoint = _provider.PosFromCharUR(end-1, text); 
                }
                else
                {
                    nextLineIndex = _provider.LineIndex(i + 1);
                    endPoint = _provider.PosFromChar(nextLineIndex - 1);
                }

                // add a bounding rectangle for this line if it is nonempty
                Rect rect = new Rect(startPoint.X, startPoint.Y, endPoint.X - startPoint.X, height);
                rect.Intersect(clippingRectangle);
                if (rect.Width > 0 && rect.Height > 0)  // r.Empty is true only if both width & height are zero.  Duh!
                {
                    rect.Offset(mapClientToScreen.X, mapClientToScreen.Y);
                    rects.Add(rect);
                }
            }

            return rects;
        }
 protected static Rect CreateBarRect(double x, double y, double width, double yOrigin, double xOffset, double yOffset)
 {
     var rect = new Rect(RectLocation(x, y, width, yOrigin), RectSize(width, y, yOrigin));
     rect.Offset(xOffset, yOffset);
     return rect;
 }
Example #35
0
        private void ProcessAreaTriggers(TPadLocation tPadLocation, Point locationPx)
        {
            if (tPadLocation.PageIndex != 2)
            return;

              Rect deviceCenterArea = new Rect(new Point(-100, -100), new Size(200, 200));
              deviceCenterArea.Offset(locationPx.X, locationPx.Y);

              Point areaTrigger = new Point(950, 1200);

              if (deviceCenterArea.Contains(areaTrigger))
              {
            //if (isPlaying)
            //  return;

            System.Windows.Interop.HwndSource hwndSource = PresentationSource.FromVisual(this) as System.Windows.Interop.HwndSource;
            System.Windows.Interop.HwndTarget hwndTarget = hwndSource.CompositionTarget;
            hwndTarget.RenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;

            //Console.WriteLine("meVideo.Play();");
            meVideo.Visibility = System.Windows.Visibility.Visible;
            meVideo.Play();
            isPlaying = true;
              }
              else if (isPlaying)
              {
            //Console.WriteLine("meVideo.Pause();");
            //meVideo.Visibility = System.Windows.Visibility.Collapsed;
            //meVideo.Pause();
            //isPlaying = false;
              }
        }