public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } GraphicsState state = graphics.Save(); if (Invert) { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); } ColorMatrix grayscaleMatrix = new ColorMatrix(new[] { new[] {.3f, .3f, .3f, 0, 0}, new[] {.59f, .59f, .59f, 0, 0}, new[] {.11f, .11f, .11f, 0, 0}, new float[] {0, 0, 0, 1, 0}, new float[] {0, 0, 0, 0, 1} }); using (ImageAttributes ia = new ImageAttributes()) { ia.SetColorMatrix(grayscaleMatrix); graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); } graphics.Restore(state); }
public void RedrawDeck() { if (m_ShowDeck != null) { System.Drawing.Graphics pGraphics = this.CreateGraphics(); m_ShowDeck.DrawToGraphics(pGraphics); } else if (m_DeckList != null) { System.Drawing.Graphics pGraphics = this.CreateGraphics(); pGraphics.Clear(Color.Honeydew); int count = m_DeckList.Count; int CurrentX = 0; for (int i = 0; i < count; i++) { kernal.PlayedDeck deck = m_DeckList[i]; Size deckSize = deck.GetSize(); var saveState = pGraphics.Save(); pGraphics.TranslateTransform(CurrentX, 0); deck.DrawToGraphics(pGraphics); pGraphics.Restore(saveState); CurrentX += deckSize.Width; } } }
public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } int magnificationFactor = GetFieldValueAsInt(FieldType.MAGNIFICATION_FACTOR); GraphicsState state = graphics.Save(); if (Invert) { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); } graphics.SmoothingMode = SmoothingMode.None; graphics.InterpolationMode = InterpolationMode.NearestNeighbor; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.None; int halfWidth = rect.Width / 2; int halfHeight = rect.Height / 2; int newWidth = rect.Width / magnificationFactor; int newHeight = rect.Height / magnificationFactor; Rectangle source = new Rectangle(rect.X + halfWidth - (newWidth / 2), rect.Y + halfHeight - (newHeight / 2), newWidth, newHeight); graphics.DrawImage(applyBitmap, rect, source, GraphicsUnit.Pixel); graphics.Restore(state); }
protected void PaintTransparentBackground(Graphics g, Rectangle clipRect) { // check if we have a parent if (this.Parent != null) { // convert the clipRects coordinates from ours to our parents clipRect.Offset(this.Location); PaintEventArgs e = new PaintEventArgs(g, clipRect); GraphicsState state = g.Save(); try { // move the graphics object so that we are drawing in // the correct place g.TranslateTransform((float)-this.Location.X, (float)-this.Location.Y); // draw the parents background and foreground this.InvokePaintBackground(this.Parent, e); this.InvokePaint(this.Parent, e); return; } finally { // reset everything back to where they were before g.Restore(state); clipRect.Offset(-this.Location.X, -this.Location.Y); } } // we don't have a parent, so fill the rect with // the default control color g.FillRectangle(SystemBrushes.Control, clipRect); }
public unsafe override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { int blurRadius = GetFieldValueAsInt(FieldType.BLUR_RADIUS); double previewQuality = GetFieldValueAsDouble(FieldType.PREVIEW_QUALITY); Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { return; } GraphicsState state = graphics.Save(); if (Invert) { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); } if (GDIplus.IsBlurPossible(blurRadius)) { GDIplus.DrawWithBlur(graphics, applyBitmap, applyRect, null, null, blurRadius, false); } else { using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) { ImageHelper.ApplyBoxBlur(fastBitmap, blurRadius); fastBitmap.DrawTo(graphics, applyRect); } } graphics.Restore(state); return; }
public static void DrawFocusedItemMark(System.Drawing.Graphics g, float x, float y, bool drawWhiteBounds = false) { if (focusedItemMark == null) { var b = FocusedItemMarkBounds; focusedItemMark = new GraphicsPath(); focusedItemMark.AddPolygon(new [] { new PointF(0, b.Top), new PointF(b.Width - 1, 0), new PointF(0, b.Bottom), }); focusedItemMarkBorder = new GraphicsPath(); focusedItemMarkBorder.AddPolygon(new[] { new PointF(0, b.Top - 1.5f), new PointF(b.Width, 0), new PointF(0, b.Bottom + 1.5f), }); } GraphicsState state = g.Save(); g.TranslateTransform(x, y); g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(System.Drawing.Brushes.Blue, focusedItemMark); if (drawWhiteBounds) { g.DrawPath(System.Drawing.Pens.White, focusedItemMarkBorder); } g.Restore(state); }
/// <summary> /// Prints an image box onto the specified graphics. /// </summary> /// <param name="imageBox">Image box to print.</param> /// <param name="graphics">Graphics in which image box should be contained.</param> /// <param name="box">Rectangle within which the image box should be contained.</param> /// <param name="imageResolution">Image resolution.</param> public static void Print(this ImageBox imageBox, Graphics graphics, RectF box, int imageResolution) { var state = graphics.Save(); FillBox(imageBox.FilmBox, box, graphics); var boxCopy = box; if (imageBox.FilmBox.Trim == "YES") { boxCopy.Inflate(-BORDER, -BORDER); } if (imageBox.ImageSequence != null && imageBox.ImageSequence.Contains(DicomTag.PixelData)) { Image bitmap = null; try { var image = new DicomImage(imageBox.ImageSequence); var frame = image.RenderImage().As<Image>(); bitmap = frame; DrawBitmap(graphics, boxCopy, bitmap, imageResolution, imageBox.FilmBox.EmptyImageDensity); } finally { if (bitmap != null) { bitmap.Dispose(); } } } graphics.Restore(state); }
/// <summary> /// Implements the Apply code for the Brightness Filet /// </summary> /// <param name="graphics"></param> /// <param name="applyBitmap"></param> /// <param name="rect"></param> /// <param name="renderMode"></param> public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } GraphicsState state = graphics.Save(); if (Invert) { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); } using (IFastBitmap fastBitmap = FastBitmap.CreateCloneOf(applyBitmap, applyRect)) { Color highlightColor = GetFieldValueAsColor(FieldType.FILL_COLOR); for (int y = fastBitmap.Top; y < fastBitmap.Bottom; y++) { for (int x = fastBitmap.Left; x < fastBitmap.Right; x++) { Color color = fastBitmap.GetColorAt(x, y); color = Color.FromArgb(color.A, Math.Min(highlightColor.R, color.R), Math.Min(highlightColor.G, color.G), Math.Min(highlightColor.B, color.B)); fastBitmap.SetColorAt(x, y, color); } } fastBitmap.DrawTo(graphics, applyRect.Location); } graphics.Restore(state); }
private void DrawGrid(System.Drawing.Graphics gfx) { GraphicsState gstate = gfx.Save(); Pen pen = new Pen(Color.Red); Rectangle destRect = new Rectangle(0, 0, this.BackBuffer.Width, this.BackBuffer.Height); GraphicsPath path = new GraphicsPath(FillMode.Alternate); for (int index1 = 0; index1 < this._rows; ++index1) { for (int index2 = 0; index2 < this._cols; ++index2) { int x = index2 * this.SnapSize.Width; int y = index1 * this.SnapSize.Height; path.AddRectangle(new Rectangle(x, y, this.SnapSize.Width, this.SnapSize.Height)); } } path.Widen(pen); Region region = new Region(path); gfx.Clip = region; gfx.DrawImage((Image)this.BackBuffer, destRect, 0, 0, destRect.Width, destRect.Height, GraphicsUnit.Pixel, this._atts); gfx.Restore(gstate); region.Dispose(); pen.Dispose(); }
public void Draw (Graphics graphics, Route route, bool atEnd) { if (graphics == null) return; if (route == null) return; GraphicsState state = graphics.Save(); float direction = 0; PointF pos = default(PointF); if (atEnd) { pos = route.GetEndPoint(); direction = ConvertDirection(route.GetEndDirection()); } else { pos = route.GetStartPoint(); direction = ConvertDirection(route.GetStartDirection()); } // In matrix math, the correct way is to put rotation BEFORE // translation. However, the simple transformation maethods of // GDI+ works in "Prepend" mode, which reverses the order of // operations. graphics.TranslateTransform(pos.X, pos.Y); graphics.RotateTransform(direction); Paint(graphics); graphics.Restore(state); }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { // save graphics state to prevent artifacts in other paint operations in the grid var state = graphics.Save(); if (!ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null) { cachedGraphicsKey = graphics; cachedGraphics = new Graphics(new GraphicsHandler(graphics, dispose: false)); } else { ((GraphicsHandler)cachedGraphics.Handler).SetInitialState(); } graphics.PixelOffsetMode = sd.Drawing2D.PixelOffsetMode.Half; graphics.SetClip(cellBounds); var color = new sd.SolidBrush(cellState.HasFlag(swf.DataGridViewElementStates.Selected) ? cellStyle.SelectionBackColor : cellStyle.BackColor); graphics.FillRectangle(color, cellBounds); var args = new CellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value); Handler.Callback.OnPaint(Handler.Widget, args); graphics.ResetClip(); graphics.Restore(state); }
protected override void Render(System.Drawing.Graphics gfx) { base.Render(gfx); System.Drawing.Drawing2D.GraphicsState graph = gfx.Save(); if (TitleImage != null) { gfx.DrawImage(TitleImage, (this.PinPoint.X - 25) + (this.Size.Width - this.PinPoint.X), 5, 17.5f, 17.5f); } gfx.Restore(graph); }
protected override void Render(System.Drawing.Graphics gfx) { base.Render(gfx); System.Drawing.Drawing2D.GraphicsState graph = gfx.Save(); if (TextImage != null && DrawImage) { gfx.DrawImage(TextImage, ImageOffsetX, ImageOffsetY, 17.5f, 17.5f); gfx.Restore(graph); } }
/// <summary> /// 重新绘制本区域内的内容 /// </summary> /// <param name="rect">相对当前屏幕的坐标矩形</param> public void paintArea(GDI.Rectangle rect) { if (rect.Height == 0 || rect.Width == 0) { return; } GDI.Drawing2D.GraphicsState state = g.Save(); g.SetClip(rect); // 开始画图吧 double iOffsetX = rect.X; int iColumn = GetCellColumn(ref iOffsetX); if (iColumn == -1) { g.Restore(state); return; } GB_GridView.CellPaintEventArgs e = new GB_GridView.CellPaintEventArgs(); g.FillRectangle(m_background, rect); double iColumnWidth = rect.X - iOffsetX; for (int j = iColumn; j < Columns.Count; ++j) { if (iColumnWidth > ActualWidth) { break; // 说明这一行画完了,开始画下一行吧 } e.Bounds = new GDI.Rectangle((int)iColumnWidth, 0, (int)Columns[j].Width, m_bufferedBmp.PixelHeight); iColumnWidth += Columns[j].Width; e.ColumnIndex = j; e.RowIndex = -1; e.States = GB_GridView.GridViewElementStates.Visible; e.Graphics = g; e.Value = Columns[j].Header.ToString(); DefaultPaintCell(e); } g.Restore(state); }
protected override void Render(System.Drawing.Graphics gfx) { base.Render(gfx); System.Drawing.Drawing2D.GraphicsState graph = gfx.Save(); if (RowImage != null) { gfx.DrawImage(RowImage, this.Labels[0].OffsetX - 20, 2, 17.5f, 17.5f); gfx.Restore(graph); } }
public virtual void DrawToGraphics (Graphics graphics, float x, float y, float scaleX, float scaleY) { if (graphics == null) return; GraphicsState state = graphics.Save(); graphics.TranslateTransform (x, y); graphics.ScaleTransform(scaleX, scaleY); Draw(graphics); //graphics.DrawRectangle(Pens.Magenta, 0, 0, ShapeWidth, ShapeHeight); graphics.Restore(state); }
public override void Draw(Graphics graphics) { if (graphics == null) return; GraphicsState state = graphics.Save(); graphics.TranslateTransform(17.0f, 0.0f); graphics.ScaleTransform(-1.0f, 1.0f); MethodShape.DrawBrick(graphics, brickBrush1, brickBrush2, brickBrush3); graphics.Restore(state); graphics.FillRectangle(Brushes.Gray, 1.0f, 4.5f, 3.5f, 0.5f); graphics.FillRectangle(Brushes.Gray, 0.0f, 6.5f, 3.5f, 0.5f); graphics.FillRectangle(Brushes.Gray, 2.0f, 8.5f, 3.5f, 0.5f); }
protected override void PaintPanel(Graphics g) { if (g == null) throw new ArgumentNullException("g"); var scroll = Hexgrid.ScrollPosition; if (DesignMode) { g.FillRectangle(Brushes.Gray, ClientRectangle); return; } g.Clear(Color.Black); if (IsTransposed) { g.Transform = TransposeMatrix; } g.TranslateTransform(scroll.X, scroll.Y); g.ScaleTransform(MapScale, MapScale); var state = g.Save(); g.DrawImageUnscaled(MapBuffer, Point.Empty); g.Restore(state); state = g.Save(); Host.PaintUnits(g); g.Restore(state); state = g.Save(); Host.PaintHighlight(g); }
public override void Render(System.Drawing.Rectangle rectangle, System.Drawing.Graphics graphics) { GraphicsState s = graphics.Save(); Rectangle rt = new System.Drawing.Rectangle(0, 0, 57, 88); graphics.TranslateTransform(-rt.Width / 2, -rt.Height / 2, MatrixOrder.Append); graphics.RotateTransform(20, MatrixOrder.Append); graphics.TranslateTransform(((rectangle.X + rectangle.Width)) / 2, ((rectangle.Y + rectangle.Height)) / 2, MatrixOrder.Append); graphics.FillRectangle(Brushes.White, rt); graphics.Restore(s); }
private void DrawElement(Graphics g, Act2DMapLayoutObject.Element e) { var bitmap = file.CreateBitmapForResource(e.resourceID); if (bitmap == null) return; var saved = g.Save(); g.TranslateTransform(e.x, e.y); g.TranslateTransform(bitmap.Width * 0.5f, bitmap.Height * 0.5f); g.RotateTransform(e.rotate); g.ScaleTransform(e.scale_x, e.scale_y); g.TranslateTransform(-bitmap.Width * 0.5f, -bitmap.Height * 0.5f); g.DrawImage(bitmap, new PointF(0.0f, 0.0f)); g.Restore(saved); }
internal override void draw(Graphics g) { RectangleF rcNode = item.getRotatedBounds(); Rectangle rcDev = Utilities.docToDevice(g, getIconRect(rcNode)); if (rcDev.Width < 6 || rcDev.Height < 6) return; GraphicsState state = g.Save(); item.flowChart.unsetTransforms(g); if ((item as Node).Expanded) g.DrawIcon(imgExpanded, rcDev.X, rcDev.Y); else g.DrawIcon(imgCollapsed, rcDev.X, rcDev.Y); g.Restore(state); }
/// <summary> /// Draw grid cells /// </summary> private void DrawGrid(System.Drawing.Graphics gfx) { // Save state GraphicsState state = gfx.Save(); // Created invert pen Pen pen = new Pen(Color.Red); // Get rendering rectangle Rectangle rect = new Rectangle(0, 0, BackBuffer.Width, BackBuffer.Height); // Create a new graphics path for inverted lines GraphicsPath path = new GraphicsPath(FillMode.Alternate); // Iterate through vertical tiles for (int row = 0; row < _rows; row++) { // Iterate through horizontal tiles for (int col = 0; col < _cols; col++) { // Get position coordinates int x = col * SnapSize.Width; int y = row * SnapSize.Height; // Add rectangle path path.AddRectangle(new Rectangle(x, y, SnapSize.Width, SnapSize.Height)); } } // Widen the path with pen path.Widen(pen); // Create new region Region region = new Region(path); // Set the region gfx.Clip = region; // Draw the backbuffer image gfx.DrawImage(BackBuffer, rect, 0, 0, rect.Width, rect.Height, GraphicsUnit.Pixel, _atts); // Restore the graphics state to non-inverted gfx.Restore(state); // Dispose of all temp objects region.Dispose(); pen.Dispose(); }
protected override void DrawToolTip(Graphics g, GMapMarker m, int x, int y) { GraphicsState s = g.Save(); g.SmoothingMode = SmoothingMode.AntiAlias; System.Drawing.Size st = g.MeasureString(m.ToolTipText, TooltipFont).ToSize(); System.Drawing.Rectangle rect = new System.Drawing.Rectangle(x, y, st.Width + Control.TooltipTextPadding.Width, st.Height + Control.TooltipTextPadding.Height); rect.Offset(m.ToolTipOffset.X, m.ToolTipOffset.Y); g.DrawLine(TooltipPen, x, y, rect.X + rect.Width / 2, rect.Y + rect.Height / 2); g.FillRectangle(TooltipBackground, rect); g.DrawRectangle(TooltipPen, rect); g.DrawString(m.ToolTipText, TooltipFont, Brushes.Navy, rect, TooltipFormat); g.Restore(s); }
public override void Draw(Graphics graphics) { if (graphics == null) return; GraphicsState state = graphics.Save(); CollapseExpandShape.DrawButton(graphics); if (collapsed) { graphics.TranslateTransform(0, 21); graphics.ScaleTransform(1, -1); } CollapseExpandShape.DrawArrow(graphics); graphics.TranslateTransform(0, 6); CollapseExpandShape.DrawArrow(graphics); graphics.Restore(state); }
public override void Render(GDI.Graphics g, Map map) { if (map.Center == null) { throw (new ApplicationException("Cannot render map. View center not specified")); } g.SmoothingMode = SmoothingMode; var envelope = ToSource(map.Envelope); //View to render if (DataSource == null) { throw (new ApplicationException("DataSource property not set on layer '" + LayerName + "'")); } // Get the transform var transform = new Matrix3x2(g.Transform.Elements); // Save state of the graphics object var gs = g.Save(); // Create and prepare the render target var rt = RenderTargetFactory.Create(_d2d1Factory, g, map); // Set anti-alias mode and transform rt.AntialiasMode = AntialiasMode; rt.Transform = transform; if (Theme != null) { RenderInternal(_d2d1Factory, rt, map, envelope, Theme); } else { RenderInternal(_d2d1Factory, rt, map, envelope); } // Clean up the render target RenderTargetFactory.CleanUp(rt, g, map); // Restore the graphics object g.Restore(gs); // Invoke LayerRendered event OnLayerRendered(g); }
public RectangleF PaintSymbol(System.Drawing.Graphics g, System.Drawing.RectangleF bounds) { if (Shape != XYPlotScatterStyles.Shape.NoSymbol) { GraphicsState gs = g.Save(); g.TranslateTransform(bounds.X + 0.5f * bounds.Width, bounds.Y + 0.5f * bounds.Height); Paint(g); g.Restore(gs); if (this.SymbolSize > bounds.Height) { bounds.Inflate(0, this.SymbolSize - bounds.Height); } } return(bounds); }
public RectangleF PaintSymbol(System.Drawing.Graphics g, System.Drawing.RectangleF bounds) { if (_scatterSymbol is NoSymbol) { return(bounds); } var cachedPathData = new CachedPathData(); var cachedBrushData = new CachedBrushData(); var scatterSymbol = CalculateOverriddenScatterSymbol(); CalculatePaths(scatterSymbol, _symbolSize, ref cachedPathData); CalculateBrushes(scatterSymbol, _color, cachedPathData, ref cachedBrushData); GraphicsState gs = g.Save(); g.TranslateTransform(bounds.X + 0.5f * bounds.Width, bounds.Y + 0.5f * bounds.Height); if (null != cachedPathData.InsetPath) { g.FillPath(cachedBrushData.InsetBrush, cachedPathData.InsetPath); } if (null != cachedPathData.FillPath) { g.FillPath(cachedBrushData.FillBrush, cachedPathData.FillPath); } if (null != cachedPathData.FramePath) { g.FillPath(cachedBrushData.FrameBrush, cachedPathData.FramePath); } cachedBrushData.Clear(); cachedPathData.Clear(); g.Restore(gs); if (SymbolSize > bounds.Height) { bounds.Inflate(0, (float)(SymbolSize - bounds.Height)); } return(bounds); }
/// <summary> /// Draws a shadow around a defined path. /// </summary> /// <param name="g">The current Graphics handle.</param> /// <param name="path">The path which should have a shadow.</param> /// <param name="color">The color of the shadow.</param> /// <param name="dx">The horizontal shift.</param> /// <param name="dy">The vertical shift.</param> /// <param name="blur">The blurness.</param> public static void DrawShadow(this System.Drawing.Graphics g, GraphicsPath path, Color color, float dx, float dy, float blur) { var bounds = path.GetBounds(); var bpw = blur / (float)bounds.Width / 2f; var bph = blur / (float)bounds.Height / 2f; var tdx = -(float)bounds.Left - (float)bounds.Width / 2f; var tdy = -(float)bounds.Top - (float)bounds.Height / 2f; path.Transform(new Matrix(1f, 0f, 0f, 1f, tdx, tdy)); Region original = new Region(path); path.Transform(new Matrix(1f + bpw, 0f, 0f, 1f + bph, dx, dy)); Region transform = new Region(path); transform.Exclude(original); var gs = g.Save(); g.TranslateTransform(-tdx, -tdy); if (blur <= 0f) { g.FillRegion(new SolidBrush(color), transform); } else { var lgb = new PathGradientBrush(path); lgb.CenterColor = color; lgb.SurroundColors = new Color[] { Color.Transparent }; var colors = new Color[3]; var positions = new float[3]; for (var i = 0; i < 3; i++) { colors[i] = Color.FromArgb(255 * (2 - i) / 2, color); positions[i] = (2f - i) / 2f; } lgb.InterpolationColors.Colors = colors; lgb.InterpolationColors.Positions = positions; g.FillRegion(lgb, transform); } g.Restore(gs); }
public static void DoGrid(this WidgetMidiList widget, FloatRect grid, Graphics g) { var gs = g.Save(); using (g.Clip = new Region(grid)) { using (var p0 = new Pen(Color.Black)) foreach (var i in widget.GetHLines(4)) g.DrawLines(p0, new Point[] { new FloatPoint(i.XO, grid.Top), new FloatPoint(i.XO, grid.Bottom) }); using (var p1 = new Pen(Gray130)) foreach (var i in widget.GetHLines(Convert.ToInt32(Math.Pow(4, 2)))) g.DrawLines(p1, new Point[] { new FloatPoint(i.XO, grid.Top), new FloatPoint(i.XO, grid.Bottom) }); using (var p2 = new Pen(White)) foreach (var i in widget.GetHLines(Convert.ToInt32(Math.Pow(4, 3)))) g.DrawLines(p2, new Point[] { new FloatPoint(i.XO, grid.Top), new FloatPoint(i.XO, grid.Bottom) }); g.ResetClip(); } g.Restore(gs); }
/// <summary> /// Implements the Apply code for the Brightness Filet /// </summary> /// <param name="graphics"></param> /// <param name="applyBitmap"></param> /// <param name="rect"></param> /// <param name="renderMode"></param> public override void Apply(Graphics graphics, Bitmap applyBitmap, Rectangle rect, RenderMode renderMode) { Rectangle applyRect = ImageHelper.CreateIntersectRectangle(applyBitmap.Size, rect, Invert); if (applyRect.Width == 0 || applyRect.Height == 0) { // nothing to do return; } GraphicsState state = graphics.Save(); if (Invert) { graphics.SetClip(applyRect); graphics.ExcludeClip(rect); } float brightness = GetFieldValueAsFloat(FieldType.BRIGHTNESS); using (ImageAttributes ia = ImageHelper.CreateAdjustAttributes(brightness, 1f, 1f)) { graphics.DrawImage(applyBitmap, applyRect, applyRect.X, applyRect.Y, applyRect.Width, applyRect.Height, GraphicsUnit.Pixel, ia); } graphics.Restore(state); }
public override void OnDraw(System.Drawing.Graphics g) { SizeF size1 = this[0].CalculateDrawSize(g); string s = new string((char)0xD6, 1); Font ft = new Font("Symbol", size1.Height, FontStyle.Regular, GraphicsUnit.Pixel); SizeF size = g.MeasureString(s, ft); // float w = size1.Width + size.Width; float h = size1.Height; // float a1 = (float)0.5177618; float b1 = (float)0.1262125; float a2 = (float)0.0719113648; float b2 = (float)0.378640622; int nLineTop = (int)(a2 * size.Height + b2); int nLineLeft = (int)(a1 * size.Height + b1); if (IsFocused) { g.FillRectangle(TextBrushBKFocus0, (float)0, (float)0, w, h); g.FillRectangle(TextBrushBKFocus, (float)0, (float)0, w, h); g.DrawString(s, ft, TextBrushFocus, 0, 0); } else { g.DrawString(s, ft, TextBrush, 0, 0); } if (IsFocused) { g.DrawLine(new Pen(TextBrushFocus), nLineLeft, nLineTop, nLineLeft + size1.Width, nLineTop); } else { g.DrawLine(new Pen(TextBrush), nLineLeft, nLineTop, nLineLeft + size1.Width, nLineTop); } // System.Drawing.Drawing2D.GraphicsState gt = g.Save(); g.TranslateTransform(nLineLeft + 1, nLineTop + 1); this[0].Position = new Point(this.Position.X + nLineLeft + 1, Position.Y + nLineTop + 1); this[0].Draw(g); g.Restore(gt); }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { this.checkBox.Size = CheckBoxRenderer.GetGlyphSize(graphics, CheckBoxState.UncheckedNormal); this.checkBox.Location = new Point(2, cellBounds.Height / 2 - this.checkBox.Height / 2); this.checkRectangle.Size = new Size(this.checkBox.Right + 1, clipBounds.Height); Point realLocation = this.checkBox.Location + (Size)cellBounds.Location; ButtonState state = GetCheckBoxState(); Padding newPadding = cellStyle.Padding; newPadding.Left = checkRectangle.Width; cellStyle.Padding = newPadding; GraphicsState gstate = graphics.Save(); graphics.ExcludeClip(new Rectangle(realLocation, this.checkBox.Size)); base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); graphics.Restore(gstate); CheckBoxRenderer.DrawCheckBox(graphics, realLocation, ConvertFromButtonState(state, false, this.mouseInCheckBox)); }
public static void DoNoteIds(this WidgetMidiList widget, FloatRect grid, Graphics g) { var gs = g.Save(); using (g.Clip = new Region(grid)) { foreach (var i in widget.GetHLines(Convert.ToInt32(Math.Pow(4, 2)))) { var r2=new FloatRect(i.XO-16,grid.Top,32,24); g.FillEllipse(Brushes.Black,r2); g.DrawText((i.Index / 4).ToString(),Color.White,widget.Font,r2); } foreach (var i in widget.GetHLines(Convert.ToInt32(Math.Pow(4, 3)))) { var r2=new FloatRect(i.XO-16,grid.Top+32,32,24); g.FillEllipse(Brushes.Black,r2); g.DrawText((i.Index / 64).ToString(),Color.White,widget.Font,r2); } g.ResetClip(); } g.Restore(gs); }
protected override void Paint(sd.Graphics graphics, sd.Rectangle clipBounds, sd.Rectangle cellBounds, int rowIndex, swf.DataGridViewElementStates cellState, object value, object formattedValue, string errorText, swf.DataGridViewCellStyle cellStyle, swf.DataGridViewAdvancedBorderStyle advancedBorderStyle, swf.DataGridViewPaintParts paintParts) { // save graphics state to prevent artifacts in other paint operations in the grid var state = graphics.Save(); if (!object.ReferenceEquals(cachedGraphicsKey, graphics) || cachedGraphics == null) { cachedGraphicsKey = graphics; cachedGraphics = new Graphics(new GraphicsHandler(graphics, shouldDisposeGraphics: false)); } else { ((GraphicsHandler)cachedGraphics.Handler).SetInitialState(); } graphics.SetClip(cellBounds); var args = new DrawableCellPaintEventArgs(cachedGraphics, cellBounds.ToEto(), cellState.ToEto(), value); Handler.Callback.OnPaint(Handler.Widget, args); graphics.ResetClip(); graphics.Restore(state); }
public static void DrawWatermarkText(Graphics graphics, string text, string fontName) { int imageHeight = (int)graphics.VisibleClipBounds.Height; int imageWidth = (int)graphics.VisibleClipBounds.Width; int maxTextWidth = (int)(imageHeight * 0.4); int[] fontSizes = new int[] { 72, 48, 36, 24, 18, 18, 14, 12, 10 }; Font font = null; foreach(int fontSize in fontSizes) { font = new Font(fontName, fontSize, GraphicsUnit.Pixel); if(graphics.MeasureString(text, font).Width <= maxTextWidth) break; } GraphicsState state = graphics.Save(); SmoothGraphics(graphics); graphics.RotateTransform(-90); float padding = font.Size / 2; graphics.TranslateTransform(-imageHeight + padding, imageWidth - font.GetHeight() - padding); graphics.TextContrast = 12; graphics.PageUnit = font.Unit; graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(120, Color.Black)), 1, 1); graphics.DrawString(text, font, new SolidBrush(Color.FromArgb(120, Color.White)), 0, 0); graphics.Restore(state); }
public RectangleF PaintSymbol(System.Drawing.Graphics g, System.Drawing.RectangleF bounds) { if (!LineConnectionStyles.NoConnection.Instance.Equals(_connectionStyle)) { GraphicsState gs = g.Save(); g.TranslateTransform(bounds.X + 0.5f * bounds.Width, bounds.Y + 0.5f * bounds.Height); float halfwidth = bounds.Width / 2; if (UseSymbolGap == true) { // plot a line with the length of symbolsize from var symGap = (float)(_symbolGapOffset + _symbolGapFactor * _symbolSize); PaintLine(g, new PointF(-halfwidth, 0), new PointF(-symGap / 2, 0)); PaintLine(g, new PointF(symGap / 2, 0), new PointF(halfwidth, 0)); } else // no gap { PaintLine(g, new PointF(-halfwidth, 0), new PointF(halfwidth, 0)); } g.Restore(gs); } return(bounds); }
private static void PaintText(Graphics graphics, Rectangle cellBounds, string valueString) { RectangleF drawArea = DrawAreaFromCellBounds(cellBounds); RectangleF textRect = drawArea; GraphicsPath pathText = new GraphicsPath(); pathText.AddString(valueString, ValueFont.FontFamily, (int)ValueFont.Style, ValueFont.Size, textRect, ValueStringFormat); GraphicsState state = graphics.Save(); graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.DrawPath(ValuePen, pathText); graphics.FillPath(ValueFill, pathText); graphics.Restore(state); }
/// <summary> /// 绘制透明背景 /// </summary> /// <param name="graphics"></param> /// <param name="clipRect"></param> protected void PaintTransparentBackground(Graphics graphics, Rectangle clipRect) { if ((this.Parent != null)) { //相对于父容器,设置cliprect clipRect.Offset(this.Location); //保存graphics当前的状态 GraphicsState state = graphics.Save(); //相对于父容器,设置graphicsobject graphics.TranslateTransform((float)-this.Location.X, (float)-this.Location.Y); graphics.SmoothingMode = SmoothingMode.HighSpeed; //绘制父容器 PaintEventArgs e = new PaintEventArgs(graphics, clipRect); try { this.InvokePaintBackground(this.Parent, e); this.InvokePaint(this.Parent, e); } finally { //还原graphics状态,还原clipRect先前的位置 graphics.Restore(state); clipRect.Offset(-this.Location.X, -this.Location.Y); } } }
public override void OnDraw(System.Drawing.Graphics g) { Type t = typeof(LogicValueEquality); System.Drawing.ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(t)[typeof(System.Drawing.ToolboxBitmapAttribute)] as System.Drawing.ToolboxBitmapAttribute; Bitmap bmp = (System.Drawing.Bitmap)tba.GetImage(t); float enclosureWidth = 0; float enclosureHeight = 0; float yParenthesis = 0; SizeF size1 = this[0].CalculateDrawSize(g); SizeF size2 = this[1].CalculateDrawSize(g); float h = size1.Height; if (h < size2.Height) { h = size2.Height; } SizeF size3 = new SizeF(h, h); bool useParenthesis = (this.Rank() < this.Parent.Rank()); if (useParenthesis) { SizeF size4 = g.MeasureString("(", ftParenthesis); enclosureWidth = size4.Width; enclosureHeight = size4.Height; } float w = size1.Width + size2.Width + size3.Width + enclosureWidth + enclosureWidth; if (IsFocused) { g.FillRectangle(this.TextBrushBKFocus0, new Rectangle(0, 0, (int)w, (int)h)); } float y = 0; if (size1.Height < h) { y = (h - size1.Height) / (float)2; } float x = size1.Width + size3.Width + enclosureWidth; if (useParenthesis) { if (enclosureHeight < h) { yParenthesis = (h - enclosureHeight) / (float)2; } if (IsFocused) { g.DrawString("(", ftParenthesis, this.TextBrushFocus, new PointF(0, yParenthesis)); } else { g.DrawString("(", ftParenthesis, this.TextBrush, new PointF(0, yParenthesis)); } } // System.Drawing.Drawing2D.GraphicsState gt = g.Save(); g.TranslateTransform(enclosureWidth, y); this[0].Position = new Point(this.Position.X + (int)enclosureWidth, Position.Y + (int)y); this[0].Draw(g); g.Restore(gt); y = 0; if (size3.Height < h) { y = (h - size3.Height) / (float)2; } //draw operator gt = g.Save(); g.TranslateTransform(size1.Width + enclosureWidth, y); g.DrawImage(bmp, new RectangleF(0, 0, size3.Width, size3.Height)); g.Restore(gt); // y = 0; if (size2.Height < h) { y = (h - size2.Height) / (float)2; } gt = g.Save(); g.TranslateTransform(x, y); this[1].Position = new Point(Position.X + (int)x, (int)y + Position.Y); this[1].Draw(g); g.Restore(gt); // if (useParenthesis) { if (IsFocused) { g.DrawString(")", ftParenthesis, this.TextBrushFocus, new PointF(x + size2.Width, yParenthesis)); } else { g.DrawString(")", ftParenthesis, this.TextBrush, new PointF(x + size2.Width, yParenthesis)); } } }
public override void Paint(System.Drawing.Graphics g, IPaintContext paintContext) { if (null == _cachedArea) { return; } bool orientationIsVertical = IsOrientationVertical; bool scaleIsReversed = IsScaleReversed; int pixelH = orientationIsVertical ? _bitmapPixelsAcross : _bitmapPixelsAlong; int pixelV = orientationIsVertical ? _bitmapPixelsAlong : _bitmapPixelsAcross; if (null == _bitmap || _bitmap.Width != pixelH || _bitmap.Height != pixelV) { if (null != _bitmap) { _bitmap.Dispose(); } _bitmap = new Bitmap(pixelH, pixelV, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } Data.AltaxoVariant porg; Data.AltaxoVariant pend; NumericalScale originalZScale; Plot.IColorProvider colorProvider; if (null != PlotItem) { porg = PlotItem.Style.Scale.OrgAsVariant; pend = PlotItem.Style.Scale.EndAsVariant; originalZScale = PlotItem.Style.Scale; colorProvider = PlotItem.Style.ColorProvider; } else { porg = 0; pend = 1; originalZScale = new LinearScale(); colorProvider = new Plot.ColorProvider.ColorProviderBGRY(); } var legendScale = (NumericalScale)ScaleWithTicks; var legendTickSpacing = ScaleWithTicks.TickSpacing; // Fill the bitmap for (int i = 0; i < _bitmapPixelsAlong; i++) { double r = (scaleIsReversed ^ orientationIsVertical) ? 1 - i / (double)(_bitmapPixelsAlong - 1) : i / (double)(_bitmapPixelsAlong - 1); double l = originalZScale.PhysicalToNormal(legendScale.NormalToPhysical(r)); var color = colorProvider.GetColor(l); if (orientationIsVertical) { for (int j = 0; j < _bitmapPixelsAcross; j++) { _bitmap.SetPixel(j, i, color); } } else { for (int j = 0; j < _bitmapPixelsAcross; j++) { _bitmap.SetPixel(i, j, color); } } } var graphicsState = g.Save(); TransformGraphics(g); { // Three tricks are neccessary to get the color legend (which is the bitmap) drawn smooth and uniformly: // Everything other than this will result in distorted image, or soft (unsharp) edges var graphicsState2 = g.Save(); // Of course, save the graphics state so we can make our tricks undone afterwards g.InterpolationMode = InterpolationMode.Default; // Trick1: Set the interpolation mode, whatever it was before, back to default g.PixelOffsetMode = PixelOffsetMode.Default; // Trick2: Set the PixelOffsetMode, whatever it was before, back to default g.DrawImage(_bitmap, new RectangleF(0, 0, (float)Size.X, (float)Size.Y), new Rectangle(0, 0, pixelH - 1, pixelV - 1), GraphicsUnit.Pixel); // Trick3: Paint both in X and Y direction one pixel less than the source bitmap acually has, this prevents soft edges g.Restore(graphicsState2); // make our tricks undone here } _axisStyles.Paint(g, paintContext, _cachedArea); g.Restore(graphicsState); }
public override void Paint(Graphics g, object obj) { System.Drawing.Drawing2D.GraphicsState gs = g.Save(); g.TranslateTransform(X,Y); g.RotateTransform(-_rotation); // Modification of StringFormat is necessary to avoid // too big spaces between successive words StringFormat strfmt = (StringFormat)StringFormat.GenericTypographic.Clone(); strfmt.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; strfmt.LineAlignment = StringAlignment.Near; strfmt.Alignment = StringAlignment.Near; // next statement is necessary to have a consistent string length both // on 0 degree rotated text and rotated text // without this statement, the text is fitted to the pixel grid, which // leads to "steps" during scaling g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; if(this.AutoSize) { SizeF mySize = g.MeasureString(_text, _font); this.Width = mySize.Width; this.Height = mySize.Height; g.DrawString(_text, _font, new SolidBrush(_color), 0, 0, strfmt); } else { System.Drawing.RectangleF rect = new RectangleF(0, 0, this.Width, this.Height); g.DrawString(_text, _font, new SolidBrush(_color), rect, strfmt); } g.Restore(gs); }
private void AddLabels(Graphics g, ChartStyle cs3d, ChartLabels cl, Axes ax) { float xOffset = ChartArea.Width / 30.0f; float yOffset = ChartArea.Height / 30.0f; SizeF labelFontSize = g.MeasureString("A", cl.LabelFont); SizeF titleFontSize = g.MeasureString("A", cl.TitleFont); SizeF tickFontSize = g.MeasureString("A", cl.TickFont); SolidBrush aBrush = new SolidBrush(cl.TickFontColor); StringFormat sFormat = new StringFormat(); // Create the x-axis tick marks: aBrush = new SolidBrush(cl.TickFontColor); for (float fX = ax.XMin; fX <= ax.XMax; fX += ax.XTick) { PointF yAxisPoint = Point2D(new PointF(fX, ax.YMin), ax); sFormat.Alignment = StringAlignment.Far; SizeF sizeXTick = g.MeasureString(fX.ToString(), cl.TickFont); g.DrawString(fX.ToString(), cl.TickFont, aBrush, new PointF(yAxisPoint.X + sizeXTick.Width / 2, yAxisPoint.Y + 4f), sFormat); } // Create the y-axis tick marks: for (float fY = ax.YMin; fY <= ax.YMax; fY += ax.YTick) { PointF xAxisPoint = Point2D(new PointF(ax.XMin, fY), ax); sFormat.Alignment = StringAlignment.Far; g.DrawString(fY.ToString(), cl.TickFont, aBrush, new PointF(xAxisPoint.X - 3f, xAxisPoint.Y - tickFontSize.Height / 2), sFormat); } // Add horizontal axis label: aBrush = new SolidBrush(cl.LabelFontColor); SizeF stringSize = g.MeasureString(cl.XLabel, cl.LabelFont); g.DrawString(cl.XLabel, cl.LabelFont, aBrush, new Point(PlotArea.X + PlotArea.Width / 2 - (int)stringSize.Width / 2, ChartArea.Bottom - (int)yOffset - (int)labelFontSize.Height)); // Add y-axis label: sFormat.Alignment = StringAlignment.Center; stringSize = g.MeasureString(cl.YLabel, cl.LabelFont); // Save the state of the current Graphics object GraphicsState gState = g.Save(); g.TranslateTransform(xOffset, yOffset + titleFontSize.Height + yOffset / 3 + PlotArea.Height / 2); g.RotateTransform(-90); g.DrawString(cl.YLabel, cl.LabelFont, aBrush, 0, 0, sFormat); // Restore it: g.Restore(gState); // Add title: aBrush = new SolidBrush(cl.TitleColor); stringSize = g.MeasureString(cl.Title, cl.TitleFont); if (cl.Title.ToUpper() != "NO TITLE") { g.DrawString(cl.Title, cl.TitleFont, aBrush, new Point(PlotArea.X + PlotArea.Width / 2 - (int)stringSize.Width / 2, ChartArea.Top + (int)yOffset)); } aBrush.Dispose(); }
/// <summary> /// Simply restores the original state of the Graphics object /// </summary> /// <param name="g">The Graphics object being drawn upon</param> protected void RestoreTransform(Graphics g) { g.Restore(state); }
partial void PopStateImp() { g.Restore(stateStack.Peek()); stateStack.Pop(); }
private void drawPlaybackIndicators(Graphics g) { // Playback start/end arrows if (PlaybackStartTime.HasValue || PlaybackEndTime.HasValue) { GraphicsState gstate = g.Save(); g.TranslateTransform(0, -_arrowBase/2); if (PlaybackStartTime.HasValue) { // start arrow (faces left) |<| int x = (int) timeToPixels(PlaybackStartTime.Value); g.FillPolygon(Brushes.DarkGray, new Point[] { new Point(x, Height - _arrowBase/2), // left mid point new Point(x + _arrowLength, Height - _arrowBase), // right top point new Point(x + _arrowLength, Height) // right bottom point }); g.DrawLine(Pens.DarkGray, x, Height - _arrowBase, x, Height); } if (PlaybackEndTime.HasValue) { // end arrow (faces right) |>| int x = (int) timeToPixels(PlaybackEndTime.Value); g.FillPolygon(Brushes.DarkGray, new Point[] { new Point(x, Height - _arrowBase/2), // right mid point new Point(x - _arrowLength, Height - _arrowBase), // left top point new Point(x - _arrowLength, Height) // left bottom point }); g.DrawLine(Pens.DarkGray, x, Height - _arrowBase, x, Height); } if (PlaybackStartTime.HasValue && PlaybackEndTime.HasValue) { // line between the two using (Pen p = new Pen(Color.DarkGray)) { p.Width = 4; int x1 = (int) timeToPixels(PlaybackStartTime.Value) + _arrowLength; int x2 = (int) timeToPixels(PlaybackEndTime.Value) - _arrowLength; int y = Height - _arrowBase/2; g.DrawLine(p, x1, y, x2, y); } } g.Restore(gstate); } // Current position arrow if (PlaybackCurrentTime.HasValue) { int x = (int) timeToPixels(PlaybackCurrentTime.Value); g.FillPolygon(Brushes.Green, new Point[] { new Point(x, _arrowLength), // bottom mid point new Point(x - _arrowBase/2, 0), // top left point new Point(x + _arrowBase/2, 0), // top right point }); } }
public override void OnDraw(System.Drawing.Graphics g) { SizeF sizeS = g.MeasureString(sybmol, ftSymbol); SizeF sizeFunction = this[0].CalculateDrawSize(g); this[1].IsSuperscript = true; SizeF sizeIndex = this[1].CalculateDrawSize(g); this[2].IsSuperscript = true; SizeF sizeBegin = this[2].CalculateDrawSize(g); this[3].IsSuperscript = true; SizeF sizeEnd = this[3].CalculateDrawSize(g); SizeF sizeEq = g.MeasureString("=", root.FontSuperscript); // float w0 = sizeIndex.Width + sizeEq.Width + sizeBegin.Width; float w1 = w0; if (w1 < sizeS.Width) { w1 = sizeS.Width; } if (w1 < sizeEnd.Width) { w1 = sizeEnd.Width; } float w = sizeFunction.Width + w1; float h1 = sizeIndex.Height; if (h1 < sizeEq.Height) { h1 = sizeEq.Height; } if (h1 < sizeBegin.Height) { h1 = sizeBegin.Height; } float h2 = h1 + sizeS.Height + sizeEnd.Height; float h = sizeFunction.Height; if (h < h2) { h = h2; } // float x = 0; if (sizeEnd.Width < w1) { x = (w1 - sizeEnd.Width) / (float)2; } if (IsFocused) { g.FillRectangle(this.TextBrushBKFocus0, new Rectangle(0, 0, (int)w, (int)h)); } System.Drawing.Drawing2D.GraphicsState gt = g.Save(); g.TranslateTransform(x, 0); this[3].Position = new Point(this.Position.X + (int)x, Position.Y); this[3].Draw(g); g.Restore(gt); // x = 0; if (sizeS.Width < w1) { x = (w1 - sizeS.Width) / (float)2; } float y = sizeEnd.Height; if (IsFocused) { g.FillRectangle(this.TextBrushBKFocus, new Rectangle((int)x, (int)y, (int)sizeS.Width, (int)sizeS.Height)); g.DrawString(sybmol, ftSymbol, TextBrushFocus, x, y); } else { g.DrawString(sybmol, ftSymbol, TextBrush, x, y); } // x = 0; if (w0 < w1) { x = (w1 - w0) / (float)2; } float y1 = y + sizeS.Height; y = y1; if (sizeIndex.Height < (h - y1)) { y = y1 + ((h - y1) - sizeIndex.Height) / (float)2; } gt = g.Save(); g.TranslateTransform(x, y); this[1].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[1].Draw(g); g.Restore(gt); // x = x + sizeIndex.Width; y = y1; if (sizeEq.Height < (h - y1)) { y = y1 + ((h - y1) - sizeEq.Height) / (float)2; } g.DrawString("=", root.FontSuperscript, TextBrush, x, y); // x = x + sizeEq.Width; y = y1; if (sizeBegin.Height < (h - y1)) { y = y1 + ((h - y1) - sizeBegin.Height) / (float)2; } gt = g.Save(); g.TranslateTransform(x, y); this[2].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[2].Draw(g); g.Restore(gt); // x = w1; y = 0; if (sizeFunction.Height < h) { y = (h - sizeFunction.Height) / (float)2; } gt = g.Save(); g.TranslateTransform(x, y); this[0].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[0].Draw(g); g.Restore(gt); }
protected void PaintTransparentBackground(Graphics graphics, Rectangle clipRect) { graphics.Clear(Color.Transparent); if ((Parent != null)) { clipRect.Offset(Location); PaintEventArgs e = new PaintEventArgs(graphics, clipRect); GraphicsState state = graphics.Save(); graphics.SmoothingMode = SmoothingMode.HighSpeed; try { graphics.TranslateTransform(-Location.X, -Location.Y); InvokePaintBackground(Parent, e); InvokePaint(Parent, e); } finally { graphics.Restore(state); clipRect.Offset(-Location.X, -Location.Y); } } }
public void DrawTextField(Graphics g, Rectangle rect, string text, Font font, Color textColor, Color backColor, TextBoxState state, TextBoxStyle style, int scroll = 0, int cursorPos = -1, int selLength = 0) { if (rect.Width < 4 || rect.Height < 4) return; GraphicsState oldState = g.Save(); // Draw Background Rectangle textRect = DrawTextBoxBorder(g, rect, state, style, backColor); Rectangle textRectScrolled = new Rectangle( textRect.X - scroll, textRect.Y, textRect.Width + scroll, textRect.Height); if (text == null) return; RectangleF clipRect = g.ClipBounds; clipRect = textRect; g.SetClip(clipRect); // Draw Selection if ((state & TextBoxState.Focus) == TextBoxState.Focus && cursorPos >= 0 && selLength != 0) { int selPos = Math.Min(cursorPos + selLength, cursorPos); CharacterRange[] charRanges = new [] { new CharacterRange(selPos, Math.Abs(selLength)) }; Region[] charRegions = MeasureStringLine(g, text, charRanges, font, textRectScrolled); RectangleF selectionRect = charRegions.Length > 0 ? charRegions[0].GetBounds(g) : RectangleF.Empty; selectionRect.Inflate(0, 2); selectionRect.Y += GetFontYOffset(font); if (selPos == 0) { selectionRect.X -= 2; selectionRect.Width += 2; } if (selPos + Math.Abs(selLength) == text.Length) { selectionRect.Width += 2; } if ((state & TextBoxState.ReadOnlyFlag) == TextBoxState.ReadOnlyFlag) g.FillRectangle(new SolidBrush(Color.FromArgb(128, this.ColorGrayText)), selectionRect); else g.FillRectangle(new SolidBrush(Color.FromArgb(128, this.ColorHightlight)), selectionRect); } // Draw Text if ((state & TextBoxState.Disabled) == TextBoxState.Disabled || (state & TextBoxState.ReadOnlyFlag) == TextBoxState.ReadOnlyFlag) textColor = Color.FromArgb(128, textColor); DrawStringLine(g, text, font, textRectScrolled, textColor); // Draw Cursor if ((state & TextBoxState.ReadOnlyFlag) != TextBoxState.ReadOnlyFlag && cursorPos >= 0 && selLength == 0) { CharacterRange[] charRanges = new [] { new CharacterRange(0, cursorPos) }; Region[] charRegions = MeasureStringLine(g, text, charRanges, font, textRectScrolled); RectangleF textRectUntilCursor = charRegions.Length > 0 ? charRegions[0].GetBounds(g) : RectangleF.Empty; int curPixelPos = textRectScrolled.X + (int)textRectUntilCursor.Width + 2; DrawCursor(g, new Rectangle(curPixelPos, textRectScrolled.Top + 1, 1, textRectScrolled.Height - 2)); } g.Restore(oldState); }
/// <summary> /// Paint the shape group in the graphic context. /// </summary> /// <param name="g">Graphic context.</param> /// <param name="paintContext">The paint context.</param> public override void Paint(Graphics g, IPaintContext paintContext) { GraphicsState gs = g.Save(); this.TransformGraphics(g); foreach (GraphicBase graphics in _groupedObjects) graphics.Paint(g, paintContext); g.Restore(gs); }
public void DrawComboButton(Graphics g, Rectangle rect, ButtonState state, string text, Image icon = null) { if (rect.Width < 8 + dropDownIcon.Width || rect.Height < 4) return; GraphicsState graphicsState = g.Save(); DrawButtonBackground(g, rect, state); Rectangle innerRect = new Rectangle(rect.X + 1, rect.Y + 1, rect.Width - 2, rect.Height - 2); Color colorText; if (state == ButtonState.Disabled) colorText = this.ColorGrayText; else colorText = this.ColorText; Rectangle dropDownIconRect = new Rectangle( innerRect.Right - dropDownIcon.Width - 4, innerRect.Y + innerRect.Height / 2 - dropDownIcon.Height / 2, dropDownIcon.Width, dropDownIcon.Height); innerRect = new Rectangle(innerRect.X + 2, innerRect.Y, innerRect.Width - dropDownIconRect.Width - 6, innerRect.Height); Image stateDropDownIcon = dropDownIcon.Normal; if (state == ButtonState.Disabled) stateDropDownIcon = dropDownIcon.Disabled; g.DrawImageUnscaled(stateDropDownIcon, dropDownIconRect.Location); RectangleF clipRect = innerRect; clipRect.Intersect(g.ClipBounds); g.SetClip(clipRect); if (icon == null && !string.IsNullOrEmpty(text)) { DrawStringLine(g, text, this.DefaultFont, innerRect, colorText); } else if (string.IsNullOrEmpty(text)) { Rectangle iconRect; iconRect = new Rectangle( innerRect.X + innerRect.Width / 2 - icon.Width / 2, innerRect.Y + innerRect.Height / 2 - icon.Height / 2, icon.Width, icon.Height); g.DrawImageUnscaled(icon, iconRect); } else { Region[] charRegions = MeasureStringLine(g, text, new [] { new CharacterRange(0, text.Length) }, this.DefaultFont, innerRect); SizeF textSize = charRegions[0].GetBounds(g).Size; Size iconTextSize; Rectangle textRect; Rectangle iconRect; iconTextSize = new Size(icon.Width + (int)textSize.Width, innerRect.Height); iconRect = new Rectangle( innerRect.X, innerRect.Y + innerRect.Height / 2 - icon.Height / 2, icon.Width, icon.Height); textRect = new Rectangle( iconRect.Right, innerRect.Y, innerRect.Width - iconRect.Width, innerRect.Height); g.DrawImageUnscaled(icon, iconRect); DrawStringLine(g, text, this.DefaultFont, textRect, colorText); } g.Restore(graphicsState); }
public void DrawEan13Barcode(System.Drawing.Graphics g, System.Drawing.Point pt) { float width = this.Width * this.Scale; float height = this.Height * this.Scale; // EAN13 Barcode should be a total of 113 modules wide. float lineWidth = width / 113f; // Save the GraphicsState. System.Drawing.Drawing2D.GraphicsState gs = g.Save(); // Set the PageUnit to Inch because all of our measurements are in inches. g.PageUnit = System.Drawing.GraphicsUnit.Millimeter; // Set the PageScale to 1, so a millimeter will represent a true millimeter. g.PageScale = 1; System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black); float xPosition = 0; System.Text.StringBuilder strbEAN13 = new System.Text.StringBuilder(); System.Text.StringBuilder sbTemp = new System.Text.StringBuilder(); float xStart = pt.X; float yStart = pt.Y; float xEnd = 0; System.Drawing.Font font = new System.Drawing.Font("Arial", this._fFontSize * this.Scale); // Calculate the Check Digit. this.CalculateChecksumDigit(); sbTemp.AppendFormat("{0}{1}{2}{3}", this.CountryCode, this.ManufacturerCode, this.ProductCode, this.ChecksumDigit); string sTemp = sbTemp.ToString(); string sLeftPattern = ""; // Convert the left hand numbers. sLeftPattern = ConvertLeftPattern(sTemp.Substring(0, 7)); // Build the UPC Code. strbEAN13.AppendFormat("{0}{1}{2}{3}{4}{1}{0}", this._sQuiteZone, this._sLeadTail, sLeftPattern, this._sSeparator, ConvertToDigitPatterns(sTemp.Substring(7), this._aRight)); string sTempUPC = strbEAN13.ToString(); float fTextHeight = g.MeasureString(sTempUPC, font).Height; // Draw the barcode lines. for (int i = 0; i < strbEAN13.Length; i++) { if (sTempUPC.Substring(i, 1) == "1") { if (xStart == pt.X) { xStart = xPosition; } // Save room for the UPC number below the bar code. if ((i > 12 && i < 55) || (i > 57 && i < 101)) { // Draw space for the number g.FillRectangle(brush, xPosition, yStart, lineWidth, height - fTextHeight); } else { // Draw a full line. g.FillRectangle(brush, xPosition, yStart, lineWidth, height); } } xPosition += lineWidth; xEnd = xPosition; } // Draw the upc numbers below the line. xPosition = xStart - g.MeasureString(this.CountryCode.Substring(0, 1), font).Width; float yPosition = yStart + (height - fTextHeight); // Draw 1st digit of the country code. g.DrawString(sTemp.Substring(0, 1), font, brush, new System.Drawing.PointF(xPosition, yPosition)); xPosition += (g.MeasureString(sTemp.Substring(0, 1), font).Width + 43 * lineWidth) - (g.MeasureString(sTemp.Substring(1, 6), font).Width); // Draw MFG Number. g.DrawString(sTemp.Substring(1, 6), font, brush, new System.Drawing.PointF(xPosition, yPosition)); xPosition += g.MeasureString(sTemp.Substring(1, 6), font).Width + (11 * lineWidth); // Draw Product ID. g.DrawString(sTemp.Substring(7), font, brush, new System.Drawing.PointF(xPosition, yPosition)); // Restore the GraphicsState. g.Restore(gs); }
// TODO: Correctly Draw the Slide Annotation private void DrawSlide(DeckTraversalModel traversal, int index, System.Drawing.Rectangle rect, System.Drawing.Graphics buffer) { // Save the old state System.Drawing.Drawing2D.GraphicsState oldState; using (Synchronizer.Lock(traversal.SyncRoot)) { using (Synchronizer.Lock(traversal.Deck.SyncRoot)) { using (Synchronizer.Lock(traversal.Deck.TableOfContents.SyncRoot)) { TableOfContentsModel.Entry entry = traversal.Deck.TableOfContents.Entries[index]; using (Synchronizer.Lock(entry.Slide.SyncRoot)) { //Draw the background color //First see if there is a Slide BG, if not, try the Deck. Otherwise, use transparent. if (entry.Slide.BackgroundColor != Color.Empty) { buffer.FillRectangle(new System.Drawing.SolidBrush(entry.Slide.BackgroundColor), rect); } else if (traversal.Deck.DeckBackgroundColor != Color.Empty) { buffer.FillRectangle(new System.Drawing.SolidBrush(traversal.Deck.DeckBackgroundColor), rect); } else { buffer.FillRectangle(new System.Drawing.SolidBrush(Color.Transparent), rect); } //Draw the background Template if (entry.Slide.BackgroundTemplate != null) { using (BackgroundTemplateRenderer render = new BackgroundTemplateRenderer(entry.Slide.BackgroundTemplate)) { render.Zoom = entry.Slide.Zoom; render.DrawAll(buffer, rect); } } //Get the Slide content and draw it oldState = buffer.Save(); Model.Presentation.SlideModel.SheetCollection sheets = entry.Slide.ContentSheets; for (int i = 0; i < sheets.Count; i++) { SlideDisplayModel display = new SlideDisplayModel(buffer, null); Rectangle slide = rect; float zoom = 1f; if (entry.Slide != null) { slide = entry.Slide.Bounds; zoom = entry.Slide.Zoom; } System.Drawing.Drawing2D.Matrix pixel, ink; display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink); using (Synchronizer.Lock(display.SyncRoot)) { display.Bounds = slide; display.PixelTransform = pixel; display.InkTransform = ink; } Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]); r.Paint(new System.Windows.Forms.PaintEventArgs(buffer, rect)); r.Dispose(); } //Restore the Old State buffer.Restore(oldState); oldState = buffer.Save(); //Get the Annotation content and draw it sheets = entry.Slide.AnnotationSheets; for (int i = 0; i < sheets.Count; i++) { SlideDisplayModel display = new SlideDisplayModel(buffer, null); Rectangle slide = rect; float zoom = 1f; if (entry.Slide != null) { slide = entry.Slide.Bounds; zoom = entry.Slide.Zoom; } System.Drawing.Drawing2D.Matrix pixel, ink; display.FitSlideToBounds(System.Windows.Forms.DockStyle.Fill, rect, zoom, ref slide, out pixel, out ink); using (Synchronizer.Lock(display.SyncRoot)) { display.Bounds = slide; display.PixelTransform = pixel; display.InkTransform = ink; } Viewer.Slides.SheetRenderer r = Viewer.Slides.SheetRenderer.ForStaticSheet(display, sheets[i]); if (r is Viewer.Slides.InkSheetRenderer) { ((Viewer.Slides.InkSheetRenderer)r).Paint(buffer, rect); } else { r.Paint(new System.Windows.Forms.PaintEventArgs(buffer, rect)); } r.Dispose(); } //Restore the Old State buffer.Restore(oldState); /* * Microsoft.Ink.Renderer renderer = new Microsoft.Ink.Renderer(); * for( int i = 0; i < sheets.Count; i++ ) { * SheetModel sm = sheets[i]; * if( sm is InkSheetModel ) { * InkSheetModel ism = sm as InkSheetModel; * using( Synchronizer.Lock( ism.SyncRoot ) ) { * foreach( Microsoft.Ink.Stroke stroke in ism.Ink.Strokes ) { * renderer.Draw( buffer, stroke ); * } * } * } else if( sm is TextSheetModel ) { * TextSheetModel tsm = sm as TextSheetModel; * using( Synchronizer.Lock( tsm.SyncRoot ) ) { * buffer.DrawString( tsm.Text, tsm.Font, new SolidBrush( tsm.Color ), tsm.Bounds ); * } * } else if( sm is ImageSheetModel ) { * //add any images in the AnnotationSheets * ImageSheetModel image_sheet_model = (ImageSheetModel)sm; * using( Synchronizer.Lock( image_sheet_model.SyncRoot ) ) { * buffer.DrawImage( image_sheet_model.Image, image_sheet_model.Bounds ); * } * } else { * //Unknown, skip it * continue; * } * } */ } } } } }
private void AddLabels(Graphics g) { float xOffset = ChartArea.Width / 30.0f; float yOffset = ChartArea.Height / 30.0f; SizeF labelFontSize = g.MeasureString("A", LabelFont); SizeF titleFontSize = g.MeasureString("A", TitleFont); // Add horizontal axis label: SolidBrush aBrush = new SolidBrush(LabelFontColor); SizeF stringSize = g.MeasureString(XLabel, LabelFont); g.DrawString(XLabel, LabelFont, aBrush, new Point(form1.PlotPanel.Left + form1.PlotPanel.Width / 2 - (int)stringSize.Width / 2, ChartArea.Bottom - (int)yOffset - (int)labelFontSize.Height)); // Add y-axis label: StringFormat sFormat = new StringFormat(); sFormat.Alignment = StringAlignment.Center; stringSize = g.MeasureString(YLabel, LabelFont); // Save the state of the current Graphics object GraphicsState gState = g.Save(); g.TranslateTransform(ChartArea.X + xOffset, ChartArea.Y + yOffset + titleFontSize.Height + yOffset / 3 + form1.PlotPanel.Height / 2); g.RotateTransform(-90); g.DrawString(YLabel, LabelFont, aBrush, 0, 0, sFormat); // Restore it: g.Restore(gState); // Add title: aBrush = new SolidBrush(TitleFontColor); stringSize = g.MeasureString(Title, TitleFont); if (Title.ToUpper() != "NO TITLE") { g.DrawString(Title, TitleFont, aBrush, new Point(form1.PlotPanel.Left + form1.PlotPanel.Width / 2 - (int)stringSize.Width / 2, ChartArea.Top + (int)yOffset)); } aBrush.Dispose(); }
public override void OnDraw(System.Drawing.Graphics g) { string s = methodDisplayName; string s1, s2; if (isArrayMethod) { s1 = "["; s2 = "]"; } else { s1 = "("; s2 = ")"; } SizeF size0 = g.MeasureString(s, TextFont); SizeF size1 = g.MeasureString(s1, TextFont); SizeF size2 = g.MeasureString(",", TextFont); float w = DrawSize.Width; float h = DrawSize.Height; float y, x = 0; if (IsFocused) { g.FillRectangle(TextBrushBKFocus0, (float)0, (float)0, w, h); g.FillRectangle(TextBrushBKFocus, (float)0, (float)0, size0.Width + size1.Width, h); y = 0; if (size0.Height < h) { y = (h - size0.Height) / (float)2; } g.DrawString(s, TextFont, TextBrushFocus, x, y); x = size0.Width; y = 0; if (size1.Height < h) { y = (h - size1.Height) / (float)2; } g.DrawString(s1, TextFont, TextBrushFocus, x, y); } else { y = 0; if (size0.Height < h) { y = (h - size0.Height) / (float)2; } g.DrawString(s, TextFont, TextBrush, x, y); x = size0.Width; y = 0; if (size1.Height < h) { y = (h - size1.Height) / (float)2; } g.DrawString(s1, TextFont, TextBrush, x, y); } x = size0.Width + size1.Width; int n = ChildNodeCount; for (int i = 0; i < n; i++) { this[i].CalculateDrawSize(g); if (i > 0) { if (IsFocused) { g.FillRectangle(TextBrushBKFocus, x, (float)0, size2.Width, h); g.DrawString(",", TextFont, TextBrushFocus, x, h - size2.Height); } else { g.DrawString(",", TextFont, TextBrush, x, h - size2.Height); } x = x + size2.Width; } y = h - this[i].DrawSize.Height; System.Drawing.Drawing2D.GraphicsState gt = g.Save(); g.TranslateTransform(x, y); this[i].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[i].Draw(g); g.Restore(gt); x = x + this[i].DrawSize.Width; } // y = 0; if (size1.Height < h) { y = (h - size1.Height) / (float)2; } if (IsFocused) { g.FillRectangle(TextBrushBKFocus, x, (float)0, size1.Width, h); g.DrawString(s2, TextFont, TextBrushFocus, x, y); } else { g.DrawString(s2, TextFont, TextBrush, x, y); } }
public override void OnDraw(System.Drawing.Graphics g) { SizeF size0 = this[0].CalculateDrawSize(g); SizeF sizeS = g.MeasureString(";", TextFont); SizeF size1 = this[1].CalculateDrawSize(g); float w = size0.Width + sizeS.Width + size1.Width; float h = size0.Height; if (h < sizeS.Height) { h = sizeS.Height; } if (h < size1.Height) { h = size1.Height; } if (IsFocused) { g.FillRectangle(TextBrushBKFocus0, (float)0, (float)0, w, h); } float x = 0; float y = 0; if (size0.Height < h) { y = (h - size0.Height) / (float)2; } System.Drawing.Drawing2D.GraphicsState gt = g.Save(); g.TranslateTransform(x, y); this[0].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[0].Draw(g); g.Restore(gt); x = size0.Width; if (sizeS.Height < h) { y = (h - sizeS.Height) / (float)2; } else { y = 0; } if (IsFocused) { g.FillRectangle(TextBrushBKFocus, x, (float)0, sizeS.Width, h); g.DrawString(";", TextFont, TextBrushFocus, x, y); } else { g.DrawString(";", TextFont, TextBrush, x, y); } x = x + sizeS.Width; if (size1.Height < h) { y = (h - size1.Height) / (float)2; } else { y = 0; } gt = g.Save(); g.TranslateTransform(x, y); this[1].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[1].Draw(g); g.Restore(gt); }
public override void OnDraw(System.Drawing.Graphics g) { int n = Branches; float w = DrawSize.Width; float h = DrawSize.Height; SizeF sizeB = g.MeasureString(symbol, ftBrace); float x = 0; float y; if (sizeB.Height < h) { y = (h - sizeB.Height) / (float)2; } else { y = 0; } if (IsFocused) { g.FillRectangle(TextBrushBKFocus0, (float)0, (float)0, w, h); g.FillRectangle(TextBrushBKFocus, (float)0, (float)0, sizeB.Width, h); g.DrawString(symbol, ftBrace, TextBrushFocus, x, y); } else { g.DrawString(symbol, ftBrace, TextBrush, x, y); } x = sizeB.Width; y = 0; if (nContentHeight < h) { y = (h - nContentHeight) / (float)2; } System.Drawing.Drawing2D.GraphicsState gt; for (int i = 0; i < n; i++) { SizeF size = this[i].CalculateDrawSize(g); gt = g.Save(); g.TranslateTransform(x, y); this[i].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[i].Draw(g); g.Restore(gt); y = y + size.Height; } SizeF size01 = g.MeasureString("default; ", TextFont); if (IsFocused) { g.FillRectangle(TextBrushBKFocus, x, y, size01.Width, size01.Height); g.DrawString("default; ", TextFont, TextBrushFocus, x, y); } else { g.DrawString("default; ", TextFont, TextBrush, x, y); } x = x + size01.Width; gt = g.Save(); g.TranslateTransform(x, y); this[n].Position = new Point(this.Position.X + (int)x, Position.Y + (int)y); this[n].Draw(g); g.Restore(gt); }