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); } }
public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Calendar.Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect) { if (appointment == null) { throw new ArgumentNullException("appointment"); } if (g == null) { throw new ArgumentNullException("g"); } if (rect.Width != 0 && rect.Height != 0) { CalendarItem taskItem = (appointment as CalendarItem); bool isLongAppt = taskItem.IsLongAppt(); // Recalculate colours Color textColor = taskItem.TaskTextColor; Color fillColor = DrawingColor.SetLuminance(textColor, 0.95f); Color borderColor = textColor; Color barColor = textColor; if (taskItem.HasTaskTextColor) { if (isSelected) { textColor = DrawingColor.SetLuminance(textColor, 0.3f); } else if (TaskColorIsBackground && !taskItem.IsDoneOrGoodAsDone) { barColor = textColor; fillColor = textColor; borderColor = DrawingColor.AdjustLighting(textColor, -0.5f, true); textColor = DrawingColor.GetBestTextColor(textColor); } } // Draw the background of the appointment g.SmoothingMode = SmoothingMode.None; if (isSelected) { if (isLongAppt) { rect.Height++; } UIExtension.SelectionRect.Draw(m_hWnd, g, rect.Left, rect.Top, rect.Width, rect.Height, false); // opaque } else { using (SolidBrush brush = new SolidBrush(fillColor)) g.FillRectangle(brush, rect); if (taskItem.DrawBorder) { if (!isLongAppt) { rect.Height--; // drawing with pen adds 1 to height rect.Width--; } using (Pen pen = new Pen(borderColor, 1)) g.DrawRectangle(pen, rect); } } // Draw appointment icon bool hasIcon = false; taskItem.IconRect = Rectangle.Empty; if (TaskHasIcon(taskItem)) { Rectangle rectIcon; int imageSize = DPIScaling.Scale(16); if (isLongAppt) { int yCentre = ((rect.Top + rect.Bottom + 1) / 2); rectIcon = new Rectangle((rect.Left + TextPadding), (yCentre - (imageSize / 2)), imageSize, imageSize); } else { rectIcon = new Rectangle(rect.Left + TextPadding, rect.Top + TextPadding, imageSize, imageSize); } if (g.IsVisible(rectIcon) && m_TaskIcons.Get(taskItem.Id)) { if (isLongAppt) { rectIcon.X = (gripRect.Right + TextPadding); } else { gripRect.Y += (imageSize + TextPadding); gripRect.Height -= (imageSize + TextPadding); } var clipRgn = g.Clip; if (rect.Bottom < (rectIcon.Y + imageSize)) { g.Clip = new Region(RectangleF.Intersect(rect, g.ClipBounds)); } m_TaskIcons.Draw(g, rectIcon.X, rectIcon.Y); g.Clip = clipRgn; hasIcon = true; taskItem.IconRect = rectIcon; rect.Width -= (rectIcon.Right - rect.Left); rect.X = rectIcon.Right; } } // Draw gripper bar if (gripRect.Width > 0) { using (SolidBrush brush = new SolidBrush(barColor)) g.FillRectangle(brush, gripRect); if (!isLongAppt) { gripRect.Height--; // drawing with pen adds 1 to height } // Draw gripper border using (Pen pen = new Pen(DrawingColor.AdjustLighting(barColor, -0.5f, true), 1)) g.DrawRectangle(pen, gripRect); if (!hasIcon) { rect.X = gripRect.Right; rect.Width -= (gripRect.Width + (TextPadding * 2)); } } // draw appointment text using (StringFormat format = new StringFormat()) { format.Alignment = StringAlignment.Near; format.LineAlignment = (isLongAppt ? StringAlignment.Center : StringAlignment.Near); rect.Y += 3; if (isLongAppt) { rect.Height = m_BaseFont.Height; } else { rect.Height -= 3; } taskItem.TextRect = rect; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; using (SolidBrush brush = new SolidBrush(textColor)) { if (taskItem.IsDone && StrikeThruDoneTasks) { using (Font font = new Font(this.BaseFont, FontStyle.Strikeout)) { g.DrawString(appointment.Title, font, brush, rect, format); } } else { g.DrawString(appointment.Title, this.BaseFont, brush, rect, format); } } g.TextRenderingHint = TextRenderingHint.SystemDefault; } } }
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(); } } } }
/// <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); } } }
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; }