private void SelectObject(object obj) { if (obj == null) { throw(new ArgumentNullException("obj")); } if (obj is GdiPen) { GdiPen pen = (GdiPen)obj; _currentPen = pen; Win32.SelectObject(_hdc, pen.NativePen); } else if (obj is GdiBrush) { GdiBrush brush = (GdiBrush)obj; _currentBrush = brush; Win32.SelectObject(_hdc, brush.NativeBrush); } else if (obj is GdiFont) { GdiFont font = (GdiFont)obj; _currentFont = font; Win32.SelectObject(_hdc, font.NativeFont); } else { throw(new Exception("Unknow gdi object")); } }
public GdiBrush SelectBrush(GdiBrush brush) { if (brush == null) { throw (new ArgumentNullException("pen")); } if (brush.NativeBrush != IntPtr.Zero) { this.SelectObject(brush); return(brush); } GdiBrush gdiBrush = null; _brushTable.TryGetValue(brush.Key, out gdiBrush); if (gdiBrush == null) { gdiBrush = brush; _brushTable.Add(gdiBrush.Key, gdiBrush); } this.CheckNativeBrush(gdiBrush); this.SelectObject(gdiBrush); return(gdiBrush); }
private void CheckNativeBrush(GdiBrush brush) { if (brush.NativeBrush == IntPtr.Zero) { brush.SetNativeBrush(Win32.CreateSolidBrush(brush.GdiColor)); } }
public void FillRectangleExt(GdiBrush brush, int x, int y, int width, int height) { if (brush == null) { throw (new ArgumentNullException("brush")); } this.CheckNativeBrush(brush); Win32.FillRect(this._hdc, x, y, width, height, brush.NativeBrush); }
public void FillRectangleExt(GdiBrush brush, Rectangle rect) { this.FillRectangleExt(brush, rect.X, rect.Y, rect.Width, rect.Height); }
protected override void OnPaint(ChartGraphics g) { int beginIndex = this.Owner.HorizontalScale.Position; int endIndex = beginIndex + this.Owner.HorizontalScale.CountBarView; IBarsData bars = this.Owner.Owner.Bars; int countBar = bars.Count; endIndex = Math.Min(endIndex, countBar); g.SelectPen(this.Color); GdiBrush brushUp = g.SelectBrush(ColorUp); GdiBrush brushDown = g.SelectBrush(ColorDown); int barWidth = 0; switch (this.Owner.HorizontalScale.Zoom) { case ChartBox.ChartHorizontalScale.HorizontalZoom.Smaller: case ChartBox.ChartHorizontalScale.HorizontalZoom.Small: barWidth = 0; break; case ChartBox.ChartHorizontalScale.HorizontalZoom.Medium: barWidth = 2; break; case ChartBox.ChartHorizontalScale.HorizontalZoom.Larger: barWidth = 4; break; case ChartBox.ChartHorizontalScale.HorizontalZoom.Large: barWidth = 10; break; case ChartBox.ChartHorizontalScale.HorizontalZoom.BigLarge: barWidth = 24; break; } iBars ibars = this.Owner.Owner.iBars; for (int i = beginIndex; i < endIndex; i++) { Bar bar = ibars.GetBar(i); int x = this.Owner.HorizontalScale.GetX(i); int yLow = this.GetY(bar.Low); int yHigh = this.GetY(bar.High); if (_barsStyle != FigureBarsStyle.Line) { g.DrawLine(x, yLow, x, yHigh); if (barWidth == 0) { continue; } int yClose = this.GetY(bar.Close); int yOpen = this.GetY(bar.Open); int barWD = barWidth / 2; int x1 = x - barWD, h = 0, y = 0; if (bar.Close > bar.Open) { h = yOpen - yClose; y = yClose; g.FillRectangleExt(brushUp, x1, y, barWidth, h); } else if (bar.Close < bar.Open) { h = yClose - yOpen; y = yOpen; g.FillRectangleExt(brushDown, x1, y, barWidth, h); } if (h > 0) { g.DrawRectangle(x1, y, barWidth, h); } } else { } } }