Пример #1
0
 /// <summary>
 /// Check if two rectangles, of the same size in different locations, overlap each other.
 /// </summary>
 /// <param name="x1"></param>
 /// <param name="y1"></param>
 /// <param name="x2"></param>
 /// <param name="y2"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <returns></returns>
 public static bool RectsIntersect(int x1, int y1, int x2, int y2, int width, int height)
 {
     System.Drawing.Rectangle a, b;
     a = new System.Drawing.Rectangle(x1, y1, width, height);
     b = new System.Drawing.Rectangle(x2, y2, width, height);
     return(a.IntersectsWith(b));
 }
Пример #2
0
        public void Render(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (viewport.Width < 1 || viewport.Height < 1 || renderingRegion.Width < 1 || renderingRegion.Height < 1)
            {
                return;
            }

            if (canvas == null)
            {
                throw new System.ArgumentNullException("canvas");
            }
            if (canvas.IsEmpty)
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrBitmapCannotBeEmpty"), "canvas");
            }
            if (!viewport.Contains(renderingRegion))
            {
                throw new System.ArgumentException(StringResources.GetString("ExStrRenderingRegionShouldBeInsideViewport"), "renderingRegion");
            }

            System.Drawing.Rectangle viewportInvalidatedRect = CoordinateMapper.WorkspaceToControl(this.InvalidatedRegion, zoom, System.Drawing.Point.Empty, Aurigma.GraphicsMill.Unit.Point, _renderingResolution);
            if (renderingRegion.IntersectsWith(viewportInvalidatedRect) || !_viewportCache.IsEntirelyInCache(zoom, renderingRegion))
            {
                BuildUpViewportImage(canvas, zoom, viewport, viewportInvalidatedRect);
                this.InvalidatedRegion = System.Drawing.RectangleF.Empty;
                _viewportCache.UpdateCache(canvas, zoom, viewport);
            }
            else
            {
                System.Diagnostics.Debug.Assert(_viewportCache.IsEntirelyInCache(zoom, renderingRegion), "At this point we should already have actual image in cache.");
                _viewportCache.DrawCached(canvas, zoom, viewport, renderingRegion);
            }
        }
Пример #3
0
        private void DrawAutotile(int id, int typeid, int imgid, int offx, int offy, System.Drawing.Graphics g)
        {
            int subid = id % 48;

            byte[] info = autotilesInfo[typeid][subid];
            for (int i = 0; i < 4; i++)
            {
                int pos = info[i] - 1;
                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                    offx + pos % 4 * (this.TileSize.Width / 2),
                    offy + pos / 4 * (this.TileSize.Height / 2),
                    this.TileSize.Width / 2,
                    this.TileSize.Height / 2
                    );
                if (rect.IntersectsWith(this.imagesBounds[imgid].Value))
                {
                    System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(
                        i % 2 * (this.TileSize.Width / 2),
                        i / 2 * (this.TileSize.Height / 2),
                        this.TileSize.Width / 2,
                        this.TileSize.Height / 2
                        );
                    g.DrawImage(
                        this.images[imgid],
                        rect2,
                        rect,
                        System.Drawing.GraphicsUnit.Pixel
                        );
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 绘制页面设置预览区域
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">绘图事件参数对象</param>
        public void OnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            int    PageWidth  = (bolLandscape == false ? myPaperSize.Width : myPaperSize.Height);
            int    PageHeight = (bolLandscape == false ? myPaperSize.Height : myPaperSize.Width);
            double Rate       = 1;

            if ((PageWidth / (double)myBounds.Width) > (PageHeight / (double)myBounds.Height))
            {
                Rate = (1.1 * PageWidth / ( double )myBounds.Width);
            }
            else
            {
                Rate = (1.1 * PageHeight / ( double )myBounds.Height);
            }
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, ( int )(PageWidth / Rate), ( int)(PageHeight / Rate));
            rect.X = myBounds.Left + (myBounds.Width - rect.Width) / 2;
            rect.Y = myBounds.Top + (myBounds.Height - rect.Height) / 2;
            if (rect.IntersectsWith(e.ClipRectangle))
            {
                e.Graphics.FillRectangle(System.Drawing.Brushes.White, rect);
                e.Graphics.DrawRectangle(System.Drawing.Pens.Black, rect);
                System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(
                    (int)(rect.Left + myMargins.Left / Rate),
                    (int)(rect.Top + myMargins.Top / Rate),
                    (int)(rect.Width - (myMargins.Left + myMargins.Right) / Rate),
                    (int)(rect.Height - (myMargins.Top + myMargins.Bottom) / Rate));
                e.Graphics.DrawRectangle(System.Drawing.Pens.Red, rect2);
            }
        }
Пример #5
0
 private void BallMMTimerCallback(IntPtr pWhat, bool success)
 {
     _ballRectangle = new System.Drawing.Rectangle((int)ballCanvasLeft, (int)ballCanvasTop, (int)BallWidth, (int)BallHeight);
     if (_ballRectangle.IntersectsWith(_paddleRectangle))
     {
         // hit paddle. reverse direction in Y direction
         paddleCanvasLeft -= _paddleMoveSize;
     }
 }
Пример #6
0
        /// <summary>
        /// Returns true if cached data is actual for specified zoom and cached region intersects witch specified rectangle.
        /// </summary>
        public bool HasActualData(float zoom, System.Drawing.Rectangle rect)
        {
            if (zoom != _zoom || _image == null)
            {
                return(false);
            }

            return(_viewport.IntersectsWith(rect));
        }
Пример #7
0
 public void Select(ref Rectangle rect, ref List <InteractiveObject2D> result)
 {
     foreach (InteractiveObject2D obj in list)
     {
         if (rect.Contains(obj.rect) || rect.IntersectsWith(obj.rect))
         {
             result.Add(obj);
         }
     }
 }
Пример #8
0
        public static bool inTheRoom(GameElements.Stuff.BeautifulSquare room, GameElements.Stuff.Player hero)
        {
            System.Drawing.Rectangle heroBounds = new System.Drawing.Rectangle(hero.posX, hero.posY, hero.image.Width, hero.image.Height);
            int border = 40; // Чтобы игрок не мог зайти в одну комнату "одной ногой" и сразу же вернуться в первую, закрыв тем самым дверь путём обмана

            System.Drawing.Rectangle roomRectangle = new System.Drawing.Rectangle(room.posX1 + border, room.posY1 + border, room.posX2 - room.posX1 - border, room.posY2 - room.posY1 - border);
            if (heroBounds.IntersectsWith(roomRectangle))
            {
                return(true);
            }
            return(false);
        }
Пример #9
0
        public Sip_window(MainWindow mainwindow) /* main sip */
        {
            findcolor = ContentPanelMaster.inputColor.ToColor();

            subwindows = new List <sipSubWindow>();
            var screens = Screen.AllScreens;

            System.Drawing.Rectangle mainwindowRect = new System.Drawing.Rectangle((int)Application.Current.MainWindow.Left, (int)Application.Current.MainWindow.Top, (int)mainwindow.Width, (int)mainwindow.Height);

            Screen activeScreen = null;

            foreach (var screen in screens)
            {
                System.Drawing.Rectangle screenrect = new System.Drawing.Rectangle((int)screen.WorkingArea.Left, (int)screen.WorkingArea.Top, (int)screen.WorkingArea.Width, (int)screen.WorkingArea.Height);

                if (mainwindowRect.IntersectsWith(screenrect))
                {
                    Console.WriteLine("OVERLAP!\n {0} {1} {2} {3} \n{4} {5} {6} {7}", Application.Current.MainWindow.Left, Application.Current.MainWindow.Top,
                                      Application.Current.MainWindow.Width, Application.Current.MainWindow.Height, screenrect.Left, screenrect.Top,
                                      screenrect.Width + screenrect.Left, screenrect.Height + screenrect.Top);

                    activeScreen = screen;

                    this.Left   = activeScreen.Bounds.Left;
                    this.Top    = activeScreen.Bounds.Top;
                    this.Width  = activeScreen.Bounds.Width;
                    this.Height = activeScreen.Bounds.Height;

                    Console.WriteLine("{0} {1} {2} {3}", this.Left, this.Top, this.Width, this.Height);

                    break;
                }
            }

            InitializeComponent();

            this.sipScreenImage.Source = Util.getWindowScreen(activeScreen);

            if (Properties.Settings.Default.SipType == 0)
            {
                this.createSubwindows(screens, activeScreen);
            }

            sipControl _control = new sipControl(this, ContentPanelMaster.inputColor.ToColor())
            {
                RenderTransform = new TranslateTransform(Application.Current.MainWindow.Left - activeScreen.Bounds.Left, Application.Current.MainWindow.Top - activeScreen.Bounds.Top)
            };

            control = _control;
            this.Canvas.Children.Add(control);
            this.Topmost = true;
        }
Пример #10
0
 public void DrawTile(int x, int y)
 {
     System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
         x * size.Width - ScrollOffsetX,
         y * size.Height - ScrollOffsetY,
         size.Width,
         size.Height
         );
     if (rect.IntersectsWith(this.panel.ClientRectangle))
     {
         this.panel.Invalidate(rect);
     }
 }
Пример #11
0
 public static void touchTheDoor(List <GameElements.Stuff.ScenicObject> allDoors, GameElements.Stuff.Player hero, GameElements.Stuff.BeautifulSquare previousRoom, GameElements.Stuff.BeautifulSquare currentRoom)
 {
     System.Drawing.Rectangle heroBounds            = new System.Drawing.Rectangle(hero.posX, hero.posY, hero.image.Width, hero.image.Height);
     System.Drawing.Rectangle previousRoomRectangle = new System.Drawing.Rectangle(previousRoom.posX1, previousRoom.posY1, previousRoom.posX2 - previousRoom.posX1, previousRoom.posY2 - previousRoom.posY1);
     System.Drawing.Rectangle currentRoomRectangle  = new System.Drawing.Rectangle(currentRoom.posX1, currentRoom.posY1, currentRoom.posX2 - currentRoom.posX1, currentRoom.posY2 - currentRoom.posY1);
     foreach (GameElements.Stuff.ScenicObject door in allDoors)
     {
         System.Drawing.Rectangle doorBounds = new System.Drawing.Rectangle(door.X + 5, door.Y, door.Width - 5, door.Height); // "Сузил" двери на 5 пикселей справа и слева. Почему? Потому что я могу.
         if (previousRoomRectangle != currentRoomRectangle)
         {
             if (doorBounds.IntersectsWith(previousRoomRectangle) && doorBounds.IntersectsWith(currentRoomRectangle))
             {
                 if (!doorBounds.IntersectsWith(heroBounds))
                 {
                     door.noclip = false;
                     //allDoors.Remove(door); // По-хорошему надо бы удалять ту дверь, которую уже закрыли, из массива allDoors, потому что он нигде не используется, а так дверь будет лишний раз "прогоняться" в foreach. Но я не стал удалять, потому что, по-моему, иначе после загрузки сохранения на мести двери окажется пустое место
                     break;
                 }
             }
         }
     }
 }
Пример #12
0
        public override void Draw(RangePaintEventArgs e)
        {
            RangeRegion region = mSelection.GetSelectionRegion();

            if (region.IsEmpty())
            {
                return;
            }

            System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor);

            CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition);

            System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(mSelection.ActivePosition);

            RangeCollection ranges = region.GetRanges();

            //Draw each selection range
            foreach (Range rng in ranges)
            {
                System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng);
                if (rectToDraw == System.Drawing.Rectangle.Empty)
                {
                    continue;
                }

                System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw);

                if (rectToDraw.IntersectsWith(focusRect))
                {
                    regionToDraw.Exclude(focusRect);
                }

                e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw);

                //Draw the border only if there isn't a editing cell
                // and is the range that contains the focus or there is a single range
                if (rng.Contains(mSelection.ActivePosition) || ranges.Count == 1)
                {
                    if (focusContext == null || focusContext.IsEditing() == false)
                    {
                        mSelection.Border.Draw(e.GraphicsCache, rectToDraw);
                    }
                }
            }

            //Draw Focus
            System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor);
            e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect);
        }
        public bool Collision(Paddle paddle)
        {
            System.Drawing.Rectangle rect1 = new System.Drawing.Rectangle(xCoord, yCoord, 20, 20);
            System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(paddle.x, paddle.y, paddle.width, paddle.height);

            if (rect1.IntersectsWith(rect2))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #14
0
        public void Select(System.Drawing.Point e)
        {
            System.Drawing.Rectangle MouseRec = new System.Drawing.Rectangle(e.X + ScriptStartingPos.X, e.Y + ScriptStartingPos.Y, 1, 1);
            MousePosOld = e;

            for (int S = ListMapScript.Count - 1; S >= 0; --S)
            {
                if (MouseRec.IntersectsWith(ListMapScript[S].ScriptSize))
                {
                    OnSelect(ListMapScript[S], false);
                    ActiveScriptIndex = S;
                    return;
                }
                else
                {
                    //Triggers.
                    for (int T = ListMapScript[S].ArrayNameTrigger.Length - 1; T >= 0; --T)
                    {
                        if (MouseRec.X >= ListMapScript[S].ScriptSize.X - 10 && MouseRec.X <= ListMapScript[S].ScriptSize.X - 5 &&
                            MouseRec.Y >= ListMapScript[S].ScriptSize.Y + 19 + T * 12 && MouseRec.Y <= ListMapScript[S].ScriptSize.Y + 24 + T * 12)
                        {
                            ScriptLink           = ListMapScript[S];
                            ScriptLinkIndex      = S;
                            ScriptLinkType       = ScriptLinkTypes.Trigger;
                            ScriptLinkEventIndex = T;
                            ScriptLinkStartPos   = new Point(ListMapScript[S].ScriptSize.X - 7, ListMapScript[S].ScriptSize.Y + 21 + T * 12);
                            return;
                        }
                    }
                    //Events.
                    for (int E = ListMapScript[S].ArrayNameCondition.Length - 1; E >= 0; --E)
                    {
                        if (MouseRec.X >= ListMapScript[S].ScriptSize.X + ListMapScript[S].ScriptSize.Width + 5 &&
                            MouseRec.X <= ListMapScript[S].ScriptSize.X + ListMapScript[S].ScriptSize.Width + 10 &&
                            MouseRec.Y >= ListMapScript[S].ScriptSize.Y + ListMapScript[S].ScriptSize.Height - ListMapScript[S].ArrayNameCondition.Length * 12 + 1 + E * 12 &&
                            MouseRec.Y <= ListMapScript[S].ScriptSize.Y + ListMapScript[S].ScriptSize.Height - ListMapScript[S].ArrayNameCondition.Length * 12 + 6 + E * 12)
                        {
                            ScriptLink           = ListMapScript[S];
                            ScriptLinkIndex      = S;
                            ScriptLinkType       = ScriptLinkTypes.Event;
                            ScriptLinkEventIndex = E;
                            ScriptLinkStartPos   = new Point(ListMapScript[S].ScriptSize.X + ListMapScript[S].ScriptSize.Width + 7, ListMapScript[S].ScriptSize.Y + ListMapScript[S].ScriptSize.Height - ListMapScript[S].ArrayNameCondition.Length * 12 + 3 + E * 12);
                            return;
                        }
                    }
                }
            }
        }
Пример #15
0
 public static bool DrawRectangle(
     System.Drawing.Graphics g,
     System.Drawing.Pen BorderPen,
     System.Drawing.Brush FillBrush,
     System.Drawing.Rectangle Bounds,
     System.Drawing.Rectangle ClipRectangle,
     bool ForceDrawBorder)
 {
     System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty;
     if (ClipRectangle.IsEmpty)
     {
         rect = Bounds;
     }
     else
     {
         rect = System.Drawing.Rectangle.Intersect(Bounds, ClipRectangle);
     }
     if (rect.IsEmpty)
     {
         return(false);
     }
     if (FillBrush != null)
     {
         g.FillRectangle(FillBrush, rect);
     }
     if (BorderPen != null)
     {
         rect = new System.Drawing.Rectangle(
             Bounds.Left,
             Bounds.Top,
             Bounds.Width - (int)Math.Ceiling(BorderPen.Width / 2.0),
             Bounds.Height - (int)Math.Ceiling(BorderPen.Width / 2.0));
         if (ForceDrawBorder || ClipRectangle.IsEmpty)
         {
             g.DrawRectangle(BorderPen, rect);
         }
         else
         {
             if (rect.IntersectsWith(ClipRectangle))
             {
                 g.DrawRectangle(BorderPen, rect);
             }
         }
     }
     return(true);
 }
Пример #16
0
        public bool Collision(Paddle paddle)
        {
            System.Drawing.Rectangle rect1 = new System.Drawing.Rectangle(xCoord, yCoord, 20, 20);
            System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(paddle.x, paddle.y, paddle.width, paddle.height);

            if (rect1.IntersectsWith(rect2))
            {
                //Play powerup sound
                Form1.powerUp.Stop();
                Form1.powerUp.Play();

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #17
0
        public static bool clash(int ulX, int ulY, List <GameElements.Stuff.ScenicObject> Objects) // ul - up left
        {
            int playerWidth = 25;

            System.Drawing.Rectangle heroBounds = new System.Drawing.Rectangle(ulX, ulY, playerWidth, playerWidth);
            System.Drawing.Rectangle obctBounds;
            foreach (GameElements.Stuff.ScenicObject obct in Objects)
            {
                if (!obct.noclip)
                {
                    obctBounds = new System.Drawing.Rectangle(obct.X, obct.Y + 3, obct.Width - 3, obct.Height - 6);
                    if (heroBounds.IntersectsWith(obctBounds))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #18
0
        public static List <System.Drawing.Rectangle> getRectangle(ChangesRecord[] pointrect, long from, uint to)
        {
            Console.WriteLine("numbers:" + (to - from));
            List <System.Drawing.Rectangle> toReturn = new List <System.Drawing.Rectangle>();

            System.Drawing.Rectangle tempRect = new System.Drawing.Rectangle();
            for (long j = from; j < to; j++)
            {
                ChangesRecord cr = pointrect[j];
                if (cr.rect.x1 == cr.rect.x2 || cr.rect.y1 == cr.rect.y2)
                {
                    continue;
                }
                {
                    Console.Write("rec:" + cr.rect.x1 + "   " + cr.rect.y1);
                    Console.WriteLine("" + cr.rect.x2 + "   " + cr.rect.y2);

                    tempRect.X      = cr.rect.x1;
                    tempRect.Y      = cr.rect.y1;
                    tempRect.Width  = (cr.rect.x2 - cr.rect.x1);
                    tempRect.Height = (cr.rect.y2 - cr.rect.y1);
                    bool intersect = false;
                    for (int i = 0; i < toReturn.Count; i++)
                    {
                        System.Drawing.Rectangle rect = toReturn[i];
                        if (rect.IntersectsWith(tempRect))
                        {
                            rect      = System.Drawing.Rectangle.Union(rect, tempRect);
                            intersect = true;
                        }
                    }
                    if (!intersect)
                    {
                        System.Drawing.Rectangle toAdd =
                            new System.Drawing.Rectangle(tempRect.X, tempRect.Y, tempRect.Width, tempRect.Height);
                        toReturn.Add(toAdd);
                    }
                }
            }
            //foreach (ChangesRecord cr in pointrect)

            return(toReturn);
        }
Пример #19
0
        public void DrawContent(System.Drawing.Graphics g, System.Drawing.Rectangle rect, ICoordinateMapper coordinateMapper)
        {
            for (int i = 0; i < _layers.Count; i++)
            {
                if (!_layers[i].Visible)
                {
                    continue;
                }

                for (int j = 0; j < _layers[i].VObjects.Count; j++)
                {
                    IVObject obj = _layers[i].VObjects[j];
                    if (rect.IntersectsWith(coordinateMapper.WorkspaceToControl(obj.GetTransformedVObjectBounds(), Aurigma.GraphicsMill.Unit.Point)))
                    {
                        obj.Draw(rect, g, coordinateMapper);
                    }
                }
            }
        }
Пример #20
0
 private void srcRenderAll(Graphics g, int x, int y, System.Drawing.Rectangle screen, Boolean showimageborder)
 {
     for (int i = currentImages.getDstImageCount() - 1; i >= 0; i--)
     {
         Image img = currentImages.getDstImage(i);
         if (img != null &&
             screen.IntersectsWith(new System.Drawing.Rectangle(
                                       x + img.x,
                                       y + img.y,
                                       img.getWidth(),
                                       img.getHeight())
                                   ))
         {
             srcRender(g, i, 0,
                       x + img.x,
                       y + img.y,
                       showimageborder);
         }
     }
 }
Пример #21
0
        public void OnUpdate()
        {
            foreach (var e in _entities)
            {
                var collider = e.GetComponent(ComponentTypes.COMPONENT_2D_COLLIDER) as Component2DCollider;
                var script   = e.GetComponents(ComponentTypes.COMPONENT_SCRIPT);
                var pos      = e.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition;
                var position = pos != null ? pos.Position : Vector3.Zero;
                var rect     = new System.Drawing.Rectangle(collider.rectangle.Left + (int)position.X, collider.rectangle.Top + (int)position.Y, collider.rectangle.Width, collider.rectangle.Height);

                if (rect.IntersectsWith(new System.Drawing.Rectangle((int)_mouseCoords.X, (int)_mouseCoords.Y, 1, 1)))
                {
                    foreach (var s in script)
                    {
                        var sci = (s as ComponentScript).script;
                        sci.OnMouseColide();

                        if (_leftHeld)
                        {
                            sci.OnLeftClickHeld();
                        }
                        else if (_leftClick)
                        {
                            sci.OnLeftClicked();
                        }
                        if (_rightHeld)
                        {
                            sci.OnRightClickHeld();
                        }
                        else if (_rightClick)
                        {
                            sci.OnRightClicked();
                        }
                    }
                }
            }
            _leftHeld = _leftClick = _rightHeld = _rightClick = false;
        }
        void Stick(Figure figure)
        {
            for (var f = figures.CreateIterator(); !f.EOL; f.Next())
            {
                var compare = f.GetCurrent().Value;
                var area1   = new System.Drawing.Rectangle(figure.X - figure.Width / 2, figure.Y - figure.Height / 2, figure.Width, figure.Height);
                var area2   = new System.Drawing.Rectangle(compare.X - compare.Width / 2, compare.Y - compare.Height / 2, compare.Width, compare.Height);

                if (!figure.isObserver(compare) && !figure.Equals(compare) && area1.IntersectsWith(area2))
                {
                    for (int i = area1.Left; i <= area1.Right; i++)
                    {
                        for (int j = area1.Top; j < area1.Bottom; j++)
                        {
                            if (figure.isPointInFigure(i, j) && compare.isPointInFigure(i, j))
                            {
                                figure.AddObserver(compare);
                                return;
                            }
                        }
                    }
                }
            }
        }
Пример #23
0
        /// <summary>
        /// Subtracts one rectangle from another. Returns an array of four rectangles (some of them may
        /// be zero-size) than make up the difference between the two rectangles areas. Indexes of the
        /// resulting rectangles are shown on the picture below. "s" is subtrahend
        ///
        ///   -----------
        ///  |     0     |
        ///  |-----------|
        ///  | 2 | s | 3 |
        ///  |-----------|
        ///  |     1     |
        ///   -----------
        ///
        /// </summary>
        public static System.Drawing.Rectangle[] SubstractRectangle(System.Drawing.Rectangle minuend, System.Drawing.Rectangle subtrahend)
        {
            System.Drawing.Rectangle[] result = new System.Drawing.Rectangle[4];
            if (subtrahend.Contains(minuend) || minuend.IsEmpty)
            {
                result[0] = result[1] = result[2] = result[3] = System.Drawing.Rectangle.Empty;
            }
            else if (subtrahend.Width < 1 || subtrahend.Height < 1 || !subtrahend.IntersectsWith(minuend))
            {
                result[0] = minuend;
                result[1] = result[2] = result[3] = System.Drawing.Rectangle.Empty;
            }
            else
            {
                // Rectangle above already subtrahend.
                result[0]        = minuend;
                result[0].Height = subtrahend.Top - minuend.Y;

                // Rectangle below subtrahend.
                result[1]        = minuend;
                result[1].Y      = subtrahend.Bottom;
                result[1].Height = minuend.Bottom - subtrahend.Bottom;

                // Rectangle to the left from subtrahend.
                result[2]       = subtrahend;
                result[2].X     = minuend.Left;
                result[2].Width = subtrahend.Left - minuend.Left;

                // And at last - rectangle to the right from subtrahend.
                result[3]       = subtrahend;
                result[3].X     = subtrahend.Right;
                result[3].Width = minuend.Right - subtrahend.Right;
            }

            return(result);
        }
        private void RectangleSelection_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (scrollBar == null)
            {
                return;
            }

            var currentPoint   = e.GetCurrentPoint(uiElement);
            var verticalOffset = scrollBar.Value - uiElement.ColumnHeaderHeight;

            if (selectionState == SelectionState.Starting)
            {
                if (!HasMovedMinimalDelta(originDragPoint.X, originDragPoint.Y - verticalOffset, currentPoint.Position.X, currentPoint.Position.Y))
                {
                    return;
                }

                if (uiElement.CurrentColumn != null)
                {
                    uiElement.CancelEdit();
                }
                selectionStrategy.StartSelection();
                OnSelectionStarted();
                selectionState = SelectionState.Active;
            }

            if (currentPoint.Properties.IsLeftButtonPressed)
            {
                var originDragPointShifted = new Point(originDragPoint.X, originDragPoint.Y - verticalOffset); // Initial drag point relative to the topleft corner
                base.DrawRectangle(currentPoint, originDragPointShifted, uiElement);
                // Selected area considering scrolled offset
                var    rect = new System.Drawing.Rectangle((int)Canvas.GetLeft(selectionRectangle), (int)Math.Min(originDragPoint.Y, currentPoint.Position.Y + verticalOffset), (int)selectionRectangle.Width, (int)Math.Abs(originDragPoint.Y - (currentPoint.Position.Y + verticalOffset)));
                var    dataGridRowsPosition = new Dictionary <DataGridRow, System.Drawing.Rectangle>();
                double actualWidth          = -1;
                foreach (var row in dataGridRows)
                {
                    if (row.Visibility != Visibility.Visible)
                    {
                        continue; // Skip invalid/invisible rows
                    }

                    if (actualWidth < 0)
                    {
                        var temp = new List <DataGridCell>();
                        DependencyObjectHelpers.FindChildren <DataGridCell>(temp, row); // Find cells inside row
                        actualWidth = temp.Sum(x => x.ActualWidth);                     // row.ActualWidth reports incorrect width
                    }

                    var gt             = row.TransformToVisual(uiElement);
                    var itemStartPoint = gt.TransformPoint(new Point(0, verticalOffset)); // Get item position relative to the top of the list (considering scrolled offset)
                    var itemRect       = new System.Drawing.Rectangle((int)itemStartPoint.X, (int)itemStartPoint.Y, (int)actualWidth, (int)row.ActualHeight);
                    itemsPosition[row.DataContext] = itemRect;                            // Update item position
                    dataGridRowsPosition[row]      = itemRect;                            // Update ui row position
                }

                foreach (var item in itemsPosition.ToList())
                {
                    try
                    {
                        if (rect.IntersectsWith(item.Value))
                        {
                            selectionStrategy.HandleIntersectionWithItem(item.Key);
                        }
                        else
                        {
                            selectionStrategy.HandleNoIntersectionWithItem(item.Key);
                        }
                    }
                    catch (ArgumentException)
                    {
                        // Item is not present in the ItemsSource
                        itemsPosition.Remove(item);
                    }
                }
                if (currentPoint.Position.Y > uiElement.ActualHeight - 20)
                {
                    // Scroll down the list if pointer is at the bottom
                    // Check if there is a loaded row outside the viewport
                    var item = dataGridRowsPosition.OrderBy(x => x.Value.Y).SkipWhile(x => x.Value.Y <= verticalOffset + uiElement.ActualHeight).Select(x => x.Key).FirstOrDefault();
                    if (item == null)
                    {
                        if (dataGridRowsPosition.Any())
                        {
                            // Last loaded item is fully visible, ge thet next one from bound item source
                            var index  = dataGridRowsPosition.OrderBy(x => x.Value.Y).Last().Key.GetIndex();
                            var source = (System.Collections.IList)uiElement.ItemsSource;
                            uiElement.ScrollIntoView(source[Math.Min(Math.Max(index + 1, 0), source.Count - 1)], null);
                        }
                    }
                    else
                    {
                        uiElement.ScrollIntoView(item.DataContext, null);
                    }
                }
                else if (currentPoint.Position.Y < 20)
                {
                    // Scroll up the list if pointer is at the top
                    // Check if there is a loaded row outside the viewport
                    var item = dataGridRowsPosition.OrderBy(x => x.Value.Y).TakeWhile(x => x.Value.Y + x.Value.Height <= scrollBar.Value).Select(x => x.Key).LastOrDefault();
                    if (item == null)
                    {
                        if (dataGridRowsPosition.Any())
                        {
                            // First loaded item is fully visible, ge thet previous one from bound item source
                            var index  = dataGridRowsPosition.OrderBy(x => x.Value.Y).First().Key.GetIndex();
                            var source = (System.Collections.IList)uiElement.ItemsSource;
                            uiElement.ScrollIntoView(source[Math.Min(Math.Max(index - 1, 0), source.Count - 1)], null);
                        }
                    }
                    else
                    {
                        uiElement.ScrollIntoView(item.DataContext, null);
                    }
                }
            }
        }
Пример #25
0
 public void DrawTile(int x, int y)
 {
     System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
         x * size.Width - ScrollOffsetX,
         y * size.Height - ScrollOffsetY,
         size.Width,
         size.Height
     );
     if (rect.IntersectsWith(this.panel.ClientRectangle))
         this.panel.Invalidate(rect);
 }
Пример #26
0
        private void RectangleSelection_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (selectionState == SelectionState.Starting)
            {
                // Clear selected items once if the pointer is pressed and moved
                uiElement.SelectedItems.Clear();
                OnSelectionStarted();
                selectionState = SelectionState.Active;
            }
            var currentPoint = e.GetCurrentPoint(uiElement);

            if (currentPoint.Properties.IsLeftButtonPressed && scrollBar != null)
            {
                var verticalOffset         = scrollBar.Value - 38;                                             // Header height
                var originDragPointShifted = new Point(originDragPoint.X, originDragPoint.Y - verticalOffset); // Initial drag point relative to the topleft corner
                base.DrawRectangle(currentPoint, originDragPointShifted);
                // Selected area considering scrolled offset
                var rect = new System.Drawing.Rectangle((int)Canvas.GetLeft(selectionRectangle), (int)Math.Min(originDragPoint.Y, currentPoint.Position.Y + verticalOffset), (int)selectionRectangle.Width, (int)Math.Abs(originDragPoint.Y - (currentPoint.Position.Y + verticalOffset)));
                var dataGridRowsPosition = new Dictionary <DataGridRow, System.Drawing.Rectangle>();
                foreach (var row in dataGridRows)
                {
                    if (row.Visibility != Visibility.Visible)
                    {
                        continue;                                       // Skip invalid/invisible rows
                    }
                    var gt             = row.TransformToVisual(uiElement);
                    var itemStartPoint = gt.TransformPoint(new Point(0, verticalOffset)); // Get item position relative to the top of the list (considering scrolled offset)
                    var itemRect       = new System.Drawing.Rectangle((int)itemStartPoint.X, (int)itemStartPoint.Y, (int)row.ActualWidth, (int)row.ActualHeight);
                    itemsPosition[row.DataContext] = itemRect;                            // Update item position
                    dataGridRowsPosition[row]      = itemRect;                            // Update ui row position
                }
                foreach (var item in itemsPosition.ToList())
                {
                    try
                    {
                        // Update selected items
                        if (rect.IntersectsWith(item.Value))
                        {
                            // Selection rectangle intersects item, add to selected items
                            if (!uiElement.SelectedItems.Contains(item.Key))
                            {
                                uiElement.SelectedItems.Add(item.Key);
                            }
                        }
                        else
                        {
                            uiElement.SelectedItems.Remove(item.Key);
                        }
                    }
                    catch (ArgumentException)
                    {
                        // Item is not present in the ItemsSource
                        itemsPosition.Remove(item);
                    }
                }
                if (currentPoint.Position.Y > uiElement.ActualHeight - 20)
                {
                    // Scroll down the list if pointer is at the bottom
                    // Check if there is a loaded row outside the viewport
                    var item = dataGridRowsPosition.OrderBy(x => x.Value.Y).SkipWhile(x => x.Value.Y <= verticalOffset + uiElement.ActualHeight).Select(x => x.Key).FirstOrDefault();
                    if (item == null)
                    {
                        if (dataGridRowsPosition.Any())
                        {
                            // Last loaded item is fully visible, ge thet next one from bound item source
                            var index  = dataGridRowsPosition.OrderBy(x => x.Value.Y).Last().Key.GetIndex();
                            var source = (System.Collections.IList)uiElement.ItemsSource;
                            uiElement.ScrollIntoView(source[Math.Min(Math.Max(index + 1, 0), source.Count - 1)], null);
                        }
                    }
                    else
                    {
                        uiElement.ScrollIntoView(item.DataContext, null);
                    }
                }
                else if (currentPoint.Position.Y < 20)
                {
                    // Scroll up the list if pointer is at the top
                    // Check if there is a loaded row outside the viewport
                    var item = dataGridRowsPosition.OrderBy(x => x.Value.Y).TakeWhile(x => x.Value.Y + x.Value.Height <= scrollBar.Value).Select(x => x.Key).LastOrDefault();
                    if (item == null)
                    {
                        if (dataGridRowsPosition.Any())
                        {
                            // First loaded item is fully visible, ge thet previous one from bound item source
                            var index  = dataGridRowsPosition.OrderBy(x => x.Value.Y).First().Key.GetIndex();
                            var source = (System.Collections.IList)uiElement.ItemsSource;
                            uiElement.ScrollIntoView(source[Math.Min(Math.Max(index - 1, 0), source.Count - 1)], null);
                        }
                    }
                    else
                    {
                        uiElement.ScrollIntoView(item.DataContext, null);
                    }
                }
            }
        }
Пример #27
0
        public override System.Drawing.Image this[int id]
        {
            get
            {
                if (this.tiles.ContainsKey(id))
                    return this.tiles[id];
                else
                {
                    System.Drawing.Bitmap tile = new System.Drawing.Bitmap(this.TileSize.Width, this.TileSize.Height);
                    System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(tile);
                    if (id >= 384 && this.images.Count > 1 && this.images[0] != null)
                    {
                            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                                new System.Drawing.Point(
                                    (id - 384) % 8 * this.TileSize.Width,
                                    (id - 384) / 8 * this.TileSize.Height
                                ),
                                this.TileSize
                            );
                            if (rect.IntersectsWith(this.imagesBounds[0].Value))
                                g.DrawImage(this.images[0], 0, 0, rect, System.Drawing.GraphicsUnit.Pixel);
                    }
                    else if (id >= 48 && id < 384)
                    {
                        int tileid = id / 48 - 1;
                        if (this.images[tileid + 1] != null)
                        {
                            int subid = id % 48;
                            byte[] info = autotilesInfo[subid / 8][subid % 8];
                            for (int i = 0; i < 4; i++)
                            {
                                int pos = info[i] - 1;
                                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                                    pos % 6 * (this.TileSize.Width / 2),
                                    pos / 6 * (this.TileSize.Height / 2),
                                    this.TileSize.Width / 2,
                                    this.TileSize.Height / 2
                                );
                                if (rect.IntersectsWith(this.imagesBounds[tileid + 1].Value))
                                {
                                    System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(
                                        i % 2 * (this.TileSize.Width / 2),
                                        i / 2 * (this.TileSize.Height / 2),
                                        this.TileSize.Width / 2,
                                        this.TileSize.Height / 2
                                    );
                                    g.DrawImage(
                                        this.images[tileid + 1],
                                        rect2,
                                        rect,
                                        System.Drawing.GraphicsUnit.Pixel
                                    );
                                }
                            }
                        }
                    }

                    g.Dispose();
                    this.tiles.Add(id, tile);
                    return tile;
                }
            }
        }
Пример #28
0
        private void RectangleSelection_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            if (scrollViewer == null)
            {
                return;
            }

            var currentPoint   = e.GetCurrentPoint(uiElement);
            var verticalOffset = scrollViewer.VerticalOffset;

            if (selectionState == SelectionState.Starting)
            {
                if (!HasMovedMinimalDelta(originDragPoint.X, originDragPoint.Y - verticalOffset, currentPoint.Position.X, currentPoint.Position.Y))
                {
                    return;
                }

                // Clear selected items once if the pointer is pressed and moved
                selectionStrategy.StartSelection();
                OnSelectionStarted();
                selectionState = SelectionState.Active;
            }
            if (currentPoint.Properties.IsLeftButtonPressed)
            {
                var originDragPointShifted = new Point(originDragPoint.X, originDragPoint.Y - verticalOffset); // Initial drag point relative to the topleft corner
                base.DrawRectangle(currentPoint, originDragPointShifted, uiElement);
                // Selected area considering scrolled offset
                var rect = new System.Drawing.Rectangle((int)Canvas.GetLeft(selectionRectangle), (int)Math.Min(originDragPoint.Y, currentPoint.Position.Y + verticalOffset), (int)selectionRectangle.Width, (int)Math.Abs(originDragPoint.Y - (currentPoint.Position.Y + verticalOffset)));
                foreach (var item in uiElement.Items.ToList().Except(itemsPosition.Keys))
                {
                    var listViewItem = (FrameworkElement)uiElement.ContainerFromItem(item); // Get ListViewItem
                    if (listViewItem == null)
                    {
                        continue; // Element is not loaded (virtualized list)
                    }

                    var gt             = listViewItem.TransformToVisual(uiElement);
                    var itemStartPoint = gt.TransformPoint(new Point(0, verticalOffset)); // Get item position relative to the top of the list (considering scrolled offset)
                    var itemRect       = new System.Drawing.Rectangle((int)itemStartPoint.X, (int)itemStartPoint.Y, (int)listViewItem.ActualWidth, (int)listViewItem.ActualHeight);
                    itemsPosition[item] = itemRect;
                }

                foreach (var item in itemsPosition.ToList())
                {
                    try
                    {
                        if (rect.IntersectsWith(item.Value))
                        {
                            selectionStrategy.HandleIntersectionWithItem(item.Key);
                        }
                        else
                        {
                            selectionStrategy.HandleNoIntersectionWithItem(item.Key);
                        }
                    }
                    catch (ArgumentException)
                    {
                        // Item is not present in the ItemsSource
                        itemsPosition.Remove(item);
                    }
                }
                if (currentPoint.Position.Y > uiElement.ActualHeight - 20)
                {
                    // Scroll down the list if pointer is at the bottom
                    var scrollIncrement = Math.Min(currentPoint.Position.Y - (uiElement.ActualHeight - 20), 40);
                    scrollViewer.ChangeView(null, verticalOffset + scrollIncrement, null, false);
                }
                else if (currentPoint.Position.Y < 20)
                {
                    // Scroll up the list if pointer is at the top
                    var scrollIncrement = Math.Min(20 - currentPoint.Position.Y, 40);
                    scrollViewer.ChangeView(null, verticalOffset - scrollIncrement, null, false);
                }
            }
        }
Пример #29
0
 /// <summary>
 /// 判断是否和指定矩形区域相交
 /// </summary>
 /// <param name="x">矩形区域的左端位置</param>
 /// <param name="y">矩形区域的顶端位置</param>
 /// <param name="vWidth">矩形区域的宽度</param>
 /// <param name="vHeight">矩形区域的高度</param>
 /// <returns>是否相交</returns>
 public bool IntersectsWith(int x, int y, int vWidth, int vHeight)
 {
     System.Drawing.Rectangle r1 = new System.Drawing.Rectangle(intLeft, intTop, intWidth, intHeight);
     System.Drawing.Rectangle r2 = new System.Drawing.Rectangle(x, y, vWidth, vHeight);
     return(r1.IntersectsWith(r2));
 }
Пример #30
0
        public override System.Drawing.Image this[int id]
        {
            get
            {
                if (this.tiles.ContainsKey(id))
                {
                    return(this.tiles[id]);
                }
                else
                {
                    System.Drawing.Bitmap   tile = new System.Drawing.Bitmap(this.TileSize.Width, this.TileSize.Height);
                    System.Drawing.Graphics g    = System.Drawing.Graphics.FromImage(tile);
                    if (id >= 384 && this.images.Count > 1 && this.images[0] != null)
                    {
                        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                            new System.Drawing.Point(
                                (id - 384) % 8 * this.TileSize.Width,
                                (id - 384) / 8 * this.TileSize.Height
                                ),
                            this.TileSize
                            );
                        if (rect.IntersectsWith(this.imagesBounds[0].Value))
                        {
                            g.DrawImage(this.images[0], 0, 0, rect, System.Drawing.GraphicsUnit.Pixel);
                        }
                    }
                    else if (id >= 48 && id < 384)
                    {
                        int tileid = id / 48 - 1;
                        if (this.images[tileid + 1] != null)
                        {
                            int    subid = id % 48;
                            byte[] info  = autotilesInfo[subid / 8][subid % 8];
                            for (int i = 0; i < 4; i++)
                            {
                                int pos = info[i] - 1;
                                System.Drawing.Rectangle rect = new System.Drawing.Rectangle(
                                    pos % 6 * (this.TileSize.Width / 2),
                                    pos / 6 * (this.TileSize.Height / 2),
                                    this.TileSize.Width / 2,
                                    this.TileSize.Height / 2
                                    );
                                if (rect.IntersectsWith(this.imagesBounds[tileid + 1].Value))
                                {
                                    System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(
                                        i % 2 * (this.TileSize.Width / 2),
                                        i / 2 * (this.TileSize.Height / 2),
                                        this.TileSize.Width / 2,
                                        this.TileSize.Height / 2
                                        );
                                    g.DrawImage(
                                        this.images[tileid + 1],
                                        rect2,
                                        rect,
                                        System.Drawing.GraphicsUnit.Pixel
                                        );
                                }
                            }
                        }
                    }

                    g.Dispose();
                    this.tiles.Add(id, tile);
                    return(tile);
                }
            }
        }
Пример #31
0
        public override void Draw(RangePaintEventArgs e)
        {
            RangeRegion region = mSelection.GetSelectionRegion();

            if (region.IsEmpty())
            {
                return;
            }

            // get visible range for scrollable area
            // AlanP: June 2014.  Changed the call from RangeAtAreaExpanded to RangeAtArea to fix a bug that occurred on Partner/Find screen
            // The grid on this screen has 3 fixed columns on the left but the highlight was always applied to the cell 'behind' the last fixed column
            //   as well as the rest of the row.  This is because of getting the 'expanded' range.
            // To be honest I don't understand what the expanded range is for.  The comment for it is not helpful (to me anyway).
            // It may be something to do with drawing the focus cell?  If we see a problem later we could revies this code
            //Range visibleScrollabeRange = mSelection.Grid.RangeAtAreaExpanded(CellPositionType.Scrollable);
            Range visibleScrollableRange = mSelection.Grid.RangeAtArea(CellPositionType.Scrollable);

            System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor);

            // In OP we would like to have the rows of fixed columns highlighted as well - this seems non-standard
            // This code is the same as is used in the standard code below, but for the FixedLeft Range
            Range visibleFixedLeftRange = mSelection.Grid.RangeAtArea(CellPositionType.FixedLeft);

            foreach (Range rangeToLoop in region)
            {
                Range rng = visibleFixedLeftRange.Intersect(rangeToLoop);
                System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng);
                if (rectToDraw == System.Drawing.Rectangle.Empty)
                {
                    continue;
                }

                System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw);
                e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw);
            }

            // Deal with the focus rectangle...  The original grid code does not seem to support the focus being on a fixed column, which seems like a bug
            //  but does not affect OpenPetra
            CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition);
            // get focus rectangle
            // clipped to visible range
            Range focusClippedRange = visibleScrollableRange.Intersect(new Range(mSelection.ActivePosition, mSelection.ActivePosition));

            System.Drawing.Rectangle focusRect = e.Grid.PositionToRectangle(focusClippedRange.Start);

            //Draw each selection range
            foreach (Range rangeToLoop in region)
            {
                // intersect given range with visible range
                // this way we ensure we don't loop through thousands
                // of rows to calculate rectToDraw
                Range rng = visibleScrollableRange.Intersect(rangeToLoop);

                System.Drawing.Rectangle rectToDraw = e.Grid.RangeToRectangle(rng);
                if (rectToDraw == System.Drawing.Rectangle.Empty)
                {
                    continue;
                }

                System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw);

                if (rectToDraw.IntersectsWith(focusRect))
                {
                    regionToDraw.Exclude(focusRect);
                }

                e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw);

                //Draw the border only if there isn't a editing cell
                // and is the range that contains the focus or there is a single range
                if (rng.Contains(mSelection.ActivePosition) || region.Count == 1)
                {
                    if (focusContext.IsEditing() == false)
                    {
                        mSelection.Border.Draw(e.GraphicsCache, rectToDraw);
                    }
                }
            }

            //Draw Focus
            System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor);
            e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect);
        }
Пример #32
0
        public override void Draw(RangePaintEventArgs e)
        {
            RangeRegion region = mSelection.GetSelectionRegion();

            if (region.IsEmpty())
            {
                return;
            }

            //[email protected]: To support freezePanes enahancement
            // get visible range for data area
            Range dataRange = mSelection.Grid.CompleteRange;

            System.Drawing.Brush brush = e.GraphicsCache.BrushsCache.GetBrush(mSelection.BackColor);

            CellContext focusContext = new CellContext(e.Grid, mSelection.ActivePosition);
            // get focus rectangle
            // clipped to visible range
            Range focusClippedRange = dataRange.Intersect(new Range(mSelection.ActivePosition, mSelection.ActivePosition));

            System.Drawing.Rectangle focusRect = e.Grid.PositionToVisibleRectangle(focusClippedRange.Start);

            //[email protected]: To support smooth scrolling. Otherwise transform will not be applied.
            focusRect.X -= (int)e.GraphicsCache.Graphics.Transform.OffsetX;
            focusRect.Y -= (int)e.GraphicsCache.Graphics.Transform.OffsetY;

            bool isFocusCellVisible = e.Grid.IsCellVisible(focusContext.Position, true);

            //Draw each selection range
            foreach (Range rangeToLoop in region)
            {
                // intersect given range with visible range
                // this way we ensure we don't loop through thousands
                // of rows to calculate rectToDraw
                Range rng = dataRange.Intersect(rangeToLoop);

                //[email protected]: To support freezePanes enahancement
                System.Drawing.Rectangle rectToDraw = e.Grid.RangeToVisibleRectangle(rng);

                //[email protected]: To support smooth scrolling. Otherwise transform will not be applied.
                rectToDraw.X -= (int)e.GraphicsCache.Graphics.Transform.OffsetX;
                rectToDraw.Y -= (int)e.GraphicsCache.Graphics.Transform.OffsetY;

                if (rectToDraw == System.Drawing.Rectangle.Empty)
                {
                    continue;
                }

                System.Drawing.Region regionToDraw = new System.Drawing.Region(rectToDraw);

                Range cellRange = e.Grid.PositionToCellRange(focusContext.Position);
                //[email protected]: To support freezePanes enahancement: Only if the cell is visible exclude it. It can be hidden under a fixedrow\column
                if (rectToDraw.IntersectsWith(focusRect) && (isFocusCellVisible || rng.Contains(cellRange)))
                {
                    regionToDraw.Exclude(focusRect);
                }

                e.GraphicsCache.Graphics.FillRegion(brush, regionToDraw);

                var partType = GetBorderType(e.Grid, rng);

                //Draw the border only if there isn't a editing cell
                // and is the range that contains the focus or there is a single range
                if ((rng.Contains(mSelection.ActivePosition) || region.Count == 1) && partType != BorderPartType.None)
                {
                    //if (!focusContext.IsEditing())
                    //[email protected]: the border should be drawn even when editing,

                    mSelection.Border.Draw(e.GraphicsCache, rectToDraw, partType);
                }
            }

            //[email protected]: To support freezePanes enahancement: Only if the cell is visible exclude it. It can be hidden under a fixedrow\column
            if (isFocusCellVisible)
            //Draw Focus
            {
                System.Drawing.Brush brushFocus = e.GraphicsCache.BrushsCache.GetBrush(mSelection.FocusBackColor);
                e.GraphicsCache.Graphics.FillRectangle(brushFocus, focusRect);
            }
        }