IsVisible() public method

public IsVisible ( Point point ) : bool
point Point
return bool
        private void PaintColumnHeaders(Graphics g, Rectangle clipBounds, bool singleBorderAdded)
        {
            if (g.IsVisible(this.layout.ColumnHeaders))
            {
                Rectangle bandBounds, cellBounds;
                bandBounds = cellBounds = this.layout.ColumnHeaders;
                bandBounds.Height = cellBounds.Height = this.columnHeadersHeight;
                int cx = 0;
                bool isFirstDisplayedColumn = true, isLastVisibleColumn = false;
                DataGridViewCell cell;
                DataGridViewCellStyle inheritedCellStyle = new DataGridViewCellStyle();
                DataGridViewAdvancedBorderStyle dataGridViewAdvancedBorderStylePlaceholder = new DataGridViewAdvancedBorderStyle(), dgvabsEffective;
                DataGridViewColumn dataGridViewColumnNext = null;

                // first paint the visible frozen columns
                DataGridViewColumn dataGridViewColumn = this.Columns.GetFirstColumn(DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen);
                while (dataGridViewColumn != null)
                {
                    cell = dataGridViewColumn.HeaderCell;
                    cellBounds.Width = dataGridViewColumn.Thickness;
                    if (singleBorderAdded && isFirstDisplayedColumn)
                    {
                        cellBounds.Width++;
                    }
                    Debug.Assert(cellBounds.Width > 0);
                    if (this.RightToLeftInternal)
                    {
                        cellBounds.X = bandBounds.Right - cx - cellBounds.Width;
                    }
                    else
                    {
                        cellBounds.X = bandBounds.X + cx;
                    }

                    BuildInheritedColumnHeaderCellStyle(inheritedCellStyle, cell);

                    dataGridViewColumnNext = this.Columns.GetNextColumn(dataGridViewColumn,
                        DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen,
                        DataGridViewElementStates.None);
                    if (dataGridViewColumnNext == null)
                    {
                        isLastVisibleColumn = (this.displayedBandsInfo.FirstDisplayedScrollingCol < 0);
                    }

                    dgvabsEffective = AdjustColumnHeaderBorderStyle(this.AdvancedColumnHeadersBorderStyle, dataGridViewAdvancedBorderStylePlaceholder,
                                                                    isFirstDisplayedColumn, isLastVisibleColumn);

                    // [....]: should paintSelectionBackground be dev-settable?
                    cell.PaintWork(g, 
                                   clipBounds, 
                                   cellBounds, 
                                   -1, 
                                   dataGridViewColumn.State, 
                                   inheritedCellStyle, 
                                   dgvabsEffective,
                                   DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.SelectionBackground);

                    cx += cellBounds.Width;
                    if (cx >= bandBounds.Width)
                    {
                        break;
                    }

                    dataGridViewColumn = dataGridViewColumnNext;
                    isFirstDisplayedColumn = false;
                }

                // then paint the visible scrolling ones
                Rectangle scrollingBounds = bandBounds;
                if (!this.RightToLeftInternal)
                {
                    scrollingBounds.X -= this.negOffset;
                }
                scrollingBounds.Width += this.negOffset;

                if (this.displayedBandsInfo.FirstDisplayedScrollingCol >= 0 && cx < scrollingBounds.Width)
                {
                    Region clipRegion = null;
                    if (this.negOffset > 0)
                    {
                        clipRegion = g.Clip;
                        Rectangle rowRect = bandBounds;
                        if (!this.RightToLeftInternal)
                        {
                            rowRect.X += cx;
                        }
                        rowRect.Width -= cx;
                        g.SetClip(rowRect);
                    }

                    dataGridViewColumn = this.Columns[this.displayedBandsInfo.FirstDisplayedScrollingCol];
                    while (dataGridViewColumn != null)
                    {
                        Debug.Assert(dataGridViewColumn.Visible && !dataGridViewColumn.Frozen);

                        cell = dataGridViewColumn.HeaderCell;
                        cellBounds.Width = dataGridViewColumn.Thickness;
                        if (singleBorderAdded && isFirstDisplayedColumn)
                        {
                            cellBounds.Width++;
                        }
                        Debug.Assert(cellBounds.Width > 0);
                        if (this.RightToLeftInternal)
                        {
                            cellBounds.X = scrollingBounds.Right - cx - cellBounds.Width;
                        }
                        else
                        {
                            cellBounds.X = scrollingBounds.X + cx;
                        }

                        BuildInheritedColumnHeaderCellStyle(inheritedCellStyle, cell);

                        dataGridViewColumnNext = this.Columns.GetNextColumn(dataGridViewColumn,
                            DataGridViewElementStates.Visible,
                            DataGridViewElementStates.None);
                        isLastVisibleColumn = (dataGridViewColumnNext == null);

                        dgvabsEffective = AdjustColumnHeaderBorderStyle(this.AdvancedColumnHeadersBorderStyle, dataGridViewAdvancedBorderStylePlaceholder,
                                                                        isFirstDisplayedColumn, isLastVisibleColumn);

                        cell.PaintWork(g, 
                                       clipBounds, 
                                       cellBounds, 
                                       -1, 
                                       dataGridViewColumn.State, 
                                       inheritedCellStyle, 
                                       dgvabsEffective,
                                       DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.SelectionBackground);

                        cx += cellBounds.Width;
                        if (cx >= scrollingBounds.Width)
                        {
                            break;
                        }

                        dataGridViewColumn = dataGridViewColumnNext;
                        isFirstDisplayedColumn = false;
                    }

                    if (this.negOffset > 0)
                    {
                        Debug.Assert(clipRegion != null);
                        g.Clip = clipRegion;
                        clipRegion.Dispose();
                    }
                }
            }
        }
 private void PaintTopLeftHeaderCell(Graphics g)
 {
     if (g.IsVisible(this.layout.TopLeftHeader))
     {
         DataGridViewCell cell = this.TopLeftHeaderCell;
         DataGridViewCellStyle inheritedCellStyle = new DataGridViewCellStyle();
         BuildInheritedColumnHeaderCellStyle(inheritedCellStyle, cell);
         Rectangle cellBounds = this.layout.TopLeftHeader;
         cellBounds.Width = this.rowHeadersWidth;
         cellBounds.Height = this.columnHeadersHeight;
         // [....]: Should paintSelectionBackground be dev-settable?
         cell.PaintWork(g, 
                        this.layout.TopLeftHeader, 
                        cellBounds, 
                        -1, 
                        cell.State, 
                        inheritedCellStyle, 
                        this.AdjustedTopLeftHeaderBorderStyle,
                        DataGridViewPaintParts.Background | DataGridViewPaintParts.Border | DataGridViewPaintParts.ContentBackground | DataGridViewPaintParts.ContentForeground | DataGridViewPaintParts.ErrorIcon | DataGridViewPaintParts.SelectionBackground);
     }
 }
        /// <summary>
        /// Draw single character
        /// Called by onPaint
        /// </summary>
        /// <param name="cx">Horizontal character position</param>
        /// <param name="cy">Vertical character position</param>
        /// <param name="g">Active graphics object</param>
		private void DrawCharacter(int cx, int cy, Graphics g) 
		{
			try 
			{
				int code = CharacterCode[cy,cx];
				if (CharacterBitmap[code] == null)	
				{
					CharacterBitmap[code] = this.MakeCharacterBitmap(code, g);
				}

				if (g.IsVisible(GetCharacterRectangle(cy,cx)))
				{
					// GDI+ Method is definitely TOO SLOW!!!!
					// g.DrawImageUnscaled(CharacterBitmap[code], cx * CharacterWidth + iFrameEffective, cy * CharacterHeight + iFrameEffective);

					// Use old and unmanaged BitBlt instead...
					Win32.TurboBitmapCopy(g,CharacterBitmap[code],cx * CharacterWidth + iFrameEffective,cy * CharacterHeight + iFrameEffective);
				}
			}
			catch 
			{
				System.Diagnostics.Debug.WriteLine("Error in " + Name + " DrawCharacter routine");
			}
		}
        public void DrawBorder(Graphics g, Rectangle rect)
        {
            Rectangle rectTopCenter = Rectangle.Empty;
            bool showTopCenter = false;
            if (!IsEmpty(TOPCENTER))
            {
                rectTopCenter = new Rectangle(
                    rect.Left + GetWidth(TOPLEFT),
                    rect.Top,
                    rect.Width - GetWidth(TOPLEFT) - GetWidth(TOPRIGHT),
                    _slices[TOPCENTER].Height);
                showTopCenter = g.IsVisible(rectTopCenter);
            }

            Rectangle rectBottomCenter = Rectangle.Empty;
            bool showBottomCenter = false;
            if (!IsEmpty(BOTTOMCENTER))
            {
                rectBottomCenter = new Rectangle(
                    rect.Left + GetWidth(BOTTOMLEFT),
                    rect.Bottom - _slices[BOTTOMCENTER].Height,
                    rect.Width - GetWidth(BOTTOMLEFT) - GetWidth(BOTTOMRIGHT),
                    _slices[BOTTOMCENTER].Height);
                showBottomCenter = g.IsVisible(rectBottomCenter);
            }

            Rectangle rectMiddleLeft = Rectangle.Empty;
            bool showMiddleLeft = false;
            if (!IsEmpty(MIDDLELEFT))
            {
                rectMiddleLeft = new Rectangle(
                    rect.Left,
                    rect.Top + GetHeight(TOPLEFT),
                    _slices[MIDDLELEFT].Width,
                    rect.Height - GetHeight(TOPLEFT) - GetHeight(BOTTOMLEFT));
                showMiddleLeft = g.IsVisible(rectMiddleLeft);
            }

            Rectangle rectMiddleCenter = Rectangle.Empty;
            bool showMiddleCenter = false;
            if (!IsEmpty(MIDDLECENTER) && IsFlagSet(_flags, BorderPaintMode.PaintMiddleCenter))
            {
                rectMiddleCenter = new Rectangle(
                    rect.Left + GetWidth(MIDDLELEFT),
                    rect.Top + GetHeight(TOPCENTER),
                    rect.Width - GetWidth(MIDDLELEFT) - GetWidth(MIDDLERIGHT),
                    rect.Height - GetHeight(TOPCENTER) - GetHeight(BOTTOMCENTER));
                showMiddleCenter = g.IsVisible(rectMiddleCenter);
            }

            Rectangle rectMiddleRight = Rectangle.Empty;
            bool showMiddleRight = false;
            if (!IsEmpty(MIDDLERIGHT))
            {
                rectMiddleRight = new Rectangle(
                    rect.Right - _slices[MIDDLERIGHT].Width,
                    rect.Top + GetHeight(TOPRIGHT),
                    _slices[MIDDLERIGHT].Width,
                    rect.Height - GetHeight(TOPRIGHT) - GetHeight(BOTTOMRIGHT));
                showMiddleRight = g.IsVisible(rectMiddleRight);
            }

            bool useGdi = IsFlagSet(_flags, BorderPaintMode.GDI);
            IntPtr pTarget = !useGdi ? IntPtr.Zero : g.GetHdc();
            try
            {
                IntPtr pSource = !useGdi ? IntPtr.Zero : Gdi32.CreateCompatibleDC(pTarget);
                try
                {
                    IntPtr pOrig = !useGdi ? IntPtr.Zero : Gdi32.SelectObject(pSource, _hBitmap);
                    try
                    {

                        if (!IsEmpty(TOPLEFT))
                            DrawSlice(g, TOPLEFT, rect.Location, pSource, pTarget);
                        if (!IsEmpty(TOPRIGHT))
                            DrawSlice(g, TOPRIGHT, new Point(rect.Right - _slices[TOPRIGHT].Width, rect.Top), pSource, pTarget);
                        if (!IsEmpty(BOTTOMLEFT))
                            DrawSlice(g, BOTTOMLEFT, new Point(rect.Left, rect.Bottom - _slices[BOTTOMLEFT].Height), pSource, pTarget);
                        if (!IsEmpty(BOTTOMRIGHT))
                            DrawSlice(g, BOTTOMRIGHT, new Point(rect.Right - _slices[BOTTOMRIGHT].Width, rect.Bottom - _slices[BOTTOMRIGHT].Height), pSource, pTarget);

                        if (showTopCenter)
                            HorizontalFill(g, TOPCENTER, rectTopCenter, pSource, pTarget);
                        if (showBottomCenter)
                            HorizontalFill(g, BOTTOMCENTER, rectBottomCenter, pSource, pTarget);
                        if (showMiddleLeft)
                            VerticalFill(g, MIDDLELEFT, rectMiddleLeft, pSource, pTarget);
                        if (showMiddleRight)
                            VerticalFill(g, MIDDLERIGHT, rectMiddleRight, pSource, pTarget);
                        if (showMiddleCenter)
                            StretchFill(g, MIDDLECENTER, rectMiddleCenter, pSource, pTarget);

                    }
                    finally
                    {
                        if (pSource != IntPtr.Zero)
                            Gdi32.SelectObject(pSource, pOrig);
                    }
                }
                finally
                {
                    if (pSource != IntPtr.Zero)
                        Gdi32.DeleteDC(pSource);
                }
            }
            finally
            {
                if (pTarget != IntPtr.Zero)
                    g.ReleaseHdc(pTarget);
            }
            GC.KeepAlive(this);
        }
            public void DrawText(
                Graphics graphics,
                Bitmap backing,
                Point position,
                Color foreColor,
                Color backColor)
            {
                COLORREF foreColorRef = new COLORREF(foreColor);

                int width = backing.Width;
                int height = backing.Height;
                Rectangle bounds = new Rectangle(0, 0, width, height);
                Rectangle margin = new Rectangle(-height, 0, width + 2 * height, height);
                Debug.Assert(service.offscreenStrip != null);
                Debug.Assert(service.offscreenStrip.Width == width);
                Debug.Assert(service.offscreenStrip.Height == height);

                using (GDIBrush backBrush = new GDIBrush(backColor))
                {
                    GDI.FillRect(service.hdcOffscreenStrip, ref bounds, backBrush);
                }

                ProcessText(
                    position,
                    delegate (
                        int iItem,
                        Point where,
                        int endX,
                        ref SCRIPT_ITEM item,
                        ref ItemInfo itemExtra,
                        Font font)
                    {
                        if (!graphics.IsVisible(new Rectangle(where.X - height, 0, endX - where.X + 2 * height, height)))
                        {
                            return true;
                        }

                        int fontCacheIndex = service.FontCacheIndex(font);

                        GDI.SetTextColor(service.hdcOffscreenStrip, foreColorRef);
                        GDI.SetBkMode(service.hdcOffscreenStrip, GDI.TRANSPARENT);
                        GDI.SelectObject(service.hdcOffscreenStrip, service.fontToHFont[font]);

                        int hr = ScriptTextOut(
                            service.hdcOffscreenStrip,
                            ref service.caches[fontCacheIndex].cache,
                            where.X,
                            where.Y,
                            (ScriptTextOutOptions)0,
                            IntPtr.Zero/*cliprect*/,
                            ref item.a,
                            IntPtr.Zero/*reserved*/,
                            0/*reserved*/,
                            itemExtra.glyphs,
                            itemExtra.cGlyphs,
                            itemExtra.iAdvances,
                            null/*piJustify*/,
                            itemExtra.goffsets);
                        if (hr < 0)
                        {
                            Marshal.ThrowExceptionForHR(hr);
                        }

                        return true;
                    });

                using (GDIRegion gdiRgnClip = new GDIRegion(graphics.Clip.GetHrgn(graphics)))
                {
                    using (GraphicsHDC gdiHdcOffscreen = new GraphicsHDC(graphics))
                    {
                        // Graphics/GDI+ doesn't pass clip region through so we have to reset it explicitly
                        GDI.SelectClipRgn(gdiHdcOffscreen, gdiRgnClip);

                        GDI.BitBlt(
                            gdiHdcOffscreen,
                            0,
                            0,
                            width,
                            height,
                            service.hdcOffscreenStrip,
                            0,
                            0,
                            GDI.SRCCOPY);
                    }
                }
            }
Example #6
0
        public override void Render(Graphics graphics, SizeF minimumSize, PointF location)
        {
            if (Node.Tag is ShaderFragmentNodeTag)
            {
                SizeF size = Measure(graphics);
                if (!graphics.IsVisible(new Rectangle() {X = (int)location.X, Y = (int)location.Y, Width = (int)size.Width, Height = (int)size.Height }))
                    return;

                if (_builder == null)
                {
                    var nodeGraph = ModelConversion.ToShaderPatcherLayer(_graphControl);
                    var shader = ShaderPatcherLayer.NodeGraph.GeneratePreviewShader(nodeGraph, ((ShaderFragmentNodeTag)Node.Tag).Id);

                    _builder  = PreviewRender.Manager.Instance.CreatePreview(shader);
                }

                    // (assuming no rotation on this transformation -- scale is easy to find)
                Size idealSize = new Size((int)(graphics.Transform.Elements[0] * size.Width), (int)(graphics.Transform.Elements[3] * size.Height));
                if (_builder != null && _builder.Bitmap != null) {
                        // compare the current bitmap size to the size we'd like
                    Size bitmapSize = _builder.Bitmap.Size;
                    float difference = System.Math.Max(System.Math.Abs(1.0f - bitmapSize.Width / (float)(idealSize.Width)), System.Math.Abs(1.0f - bitmapSize.Height / (float)(idealSize.Height)));
                    if (difference > 0.1f) {
                        _builder.Invalidate();
                    }
                }

                if (_builder.Bitmap==null) {
                    _builder.Update(_document, idealSize);
                }

                if (_builder.Bitmap!=null) {
                    graphics.DrawImage(_builder.Bitmap, new RectangleF() { X = location.X, Y = location.Y, Width = size.Width, Height = size.Height });
                }
            }
        }
 private void PaintRows(Graphics g, ref Rectangle boundingRect)
 {
     int num = 0;
     bool alignToRight = this.isRightToLeft();
     Rectangle rect = boundingRect;
     Rectangle empty = Rectangle.Empty;
     bool rowHeadersVisible = this.layout.RowHeadersVisible;
     Rectangle rectangle3 = Rectangle.Empty;
     int dataGridRowsLength = this.DataGridRowsLength;
     DataGridRow[] dataGridRows = this.DataGridRows;
     int numVisibleColumns = this.myGridTable.GridColumnStyles.Count - this.firstVisibleCol;
     for (int i = this.firstVisibleRow; i < dataGridRowsLength; i++)
     {
         if (num > boundingRect.Height)
         {
             break;
         }
         rect = boundingRect;
         rect.Height = dataGridRows[i].Height;
         rect.Y = boundingRect.Y + num;
         if (rowHeadersVisible)
         {
             rectangle3 = rect;
             rectangle3.Width = this.layout.RowHeaders.Width;
             if (alignToRight)
             {
                 rectangle3.X = rect.Right - rectangle3.Width;
             }
             if (g.IsVisible(rectangle3))
             {
                 dataGridRows[i].PaintHeader(g, rectangle3, alignToRight, this.gridState[0x8000]);
                 g.ExcludeClip(rectangle3);
             }
             if (!alignToRight)
             {
                 rect.X += rectangle3.Width;
             }
             rect.Width -= rectangle3.Width;
         }
         if (g.IsVisible(rect))
         {
             empty = rect;
             if (!alignToRight)
             {
                 empty.X -= this.negOffset;
             }
             empty.Width += this.negOffset;
             dataGridRows[i].Paint(g, empty, rect, this.firstVisibleCol, numVisibleColumns, alignToRight);
         }
         num += rect.Height;
     }
     boundingRect.Y += num;
     boundingRect.Height -= num;
 }