public override void Render(RenderingBuffer buffer) { Attr attr = Colors.Blend(Color.Black, Color.Gray); buffer.FillRectangle(0, 0, ActualWidth, ActualHeight, ' ', attr); }
public override void Render(RenderingBuffer buffer) { Attr attr = Colors.Blend(Color.Black, Color.DarkGreen); // прозрачный фон для рамки buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 3); // полностью прозрачный внутри if (ActualWidth > 2 && ActualHeight > 2) { buffer.SetOpacityRect(1, 1, ActualWidth - 2, ActualHeight - 2, 2); } // title int titleRenderedWidth = 0; if (!string.IsNullOrEmpty(title)) { titleRenderedWidth = RenderString(title, buffer, 2, 0, ActualWidth - 4, attr); } // upper border for (int x = 0; x < ActualWidth; x++) { char?c = null; if (x == 0) { c = UnicodeTable.SingleFrameTopLeftCorner; } else if (x == ActualWidth - 1) { c = UnicodeTable.SingleFrameTopRightCorner; } else if (x == 1 || x == 2 + titleRenderedWidth) { c = ' '; } else if (x > 2 + titleRenderedWidth && x < ActualWidth - 1) { c = UnicodeTable.SingleFrameHorizontal; } if (c != null) { buffer.SetPixel(x, 0, c.Value, attr); } } // left border if (ActualHeight > 2) { buffer.FillRectangle(0, 1, 1, ActualHeight - 2, UnicodeTable.SingleFrameVertical, attr); } if (ActualHeight > 1) { buffer.SetPixel(0, ActualHeight - 1, UnicodeTable.SingleFrameBottomLeftCorner, attr); } // right border if (ActualWidth > 1) { if (ActualHeight > 2) { buffer.FillRectangle(ActualWidth - 1, 1, 1, ActualHeight - 2, UnicodeTable.SingleFrameVertical, attr); } if (ActualHeight > 1) { buffer.SetPixel(ActualWidth - 1, ActualHeight - 1, UnicodeTable.SingleFrameBottomRightCorner, attr); } } // bottom border if (ActualHeight > 1 && ActualWidth > 2) { buffer.FillRectangle(1, ActualHeight - 1, ActualWidth - 2, 1, UnicodeTable.SingleFrameHorizontal, attr); } }
public override void Render(RenderingBuffer buffer) { Attr attr = Colors.Blend(Color.DarkCyan, Color.DarkBlue); buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 2); if (horizontalScrollVisible) { buffer.SetOpacityRect(0, ActualHeight - 1, ActualWidth, 1, 0); buffer.SetPixel(0, ActualHeight - 1, UnicodeTable.ArrowLeft, attr); // ◄ // оставляем дополнительный пиксель справа, если одновременно видны оба скроллбара int rightOffset = verticalScrollVisible ? 1 : 0; if (ActualWidth > 2 + rightOffset) { buffer.FillRectangle(1, ActualHeight - 1, ActualWidth - (2 + rightOffset), 1, UnicodeTable.MediumShade, attr); // ▒ } if (ActualWidth > 1 + rightOffset) { buffer.SetPixel(ActualWidth - (1 + rightOffset), ActualHeight - 1, UnicodeTable.ArrowRight, attr); // ► } // определим, в каком месте находится ползунок if (ActualWidth > 3 + (verticalScrollVisible ? 1 : 0)) { int remainingWidth = ActualWidth - (verticalScrollVisible ? 1 : 0); int extraWidth = Content.RenderSize.Width - remainingWidth; int pages = extraWidth / (remainingWidth - 2 - 1); //Debugger.Log( 1, "", "pages: " + pages + "\n" ); int scrollerPos; if (pages == 0) { double posInDelta = (remainingWidth * 1.0 - 2 - 1) / extraWidth; //Debugger.Log( 1, "", "posInDelta: " + posInDelta + "\n" ); scrollerPos = ( int )Math.Round(posInDelta * deltaX); } else { double deltaInPos = (extraWidth * 1.0) / (remainingWidth - 2 - 1); //Debugger.Log( 1, "", "deltaX/( deltaInPos ): " + deltaX/( deltaInPos ) + "\n" ); scrollerPos = ( int )Math.Round(deltaX / (deltaInPos)); } buffer.SetPixel(1 + scrollerPos, ActualHeight - 1, UnicodeTable.BlackSquare, attr); // ■ } else if (ActualWidth == 3 + (verticalScrollVisible ? 1 : 0)) { buffer.SetPixel(1, ActualHeight - 1, UnicodeTable.BlackSquare, attr); // ■ } } if (verticalScrollVisible) { buffer.SetOpacityRect(ActualWidth - 1, 0, 1, ActualHeight, 0); buffer.SetPixel(ActualWidth - 1, 0, UnicodeTable.ArrowUp, attr); // ▲ // оставляем дополнительный пиксель снизу, если одновременно видны оба скроллбара int downOffset = horizontalScrollVisible ? 1 : 0; if (ActualHeight > 2 + downOffset) { buffer.FillRectangle(ActualWidth - 1, 1, 1, ActualHeight - (2 + downOffset), UnicodeTable.MediumShade, attr); // ▒ } if (ActualHeight > 1 + downOffset) { buffer.SetPixel(ActualWidth - 1, ActualHeight - (1 + downOffset), UnicodeTable.ArrowDown, attr); // ▼ } // определим, в каком месте находится ползунок if (ActualHeight > 3 + (horizontalScrollVisible ? 1 : 0)) { int remainingHeight = ActualHeight - (horizontalScrollVisible ? 1 : 0); int extraHeight = Content.RenderSize.Height - remainingHeight; int pages = extraHeight / (remainingHeight - 2 - 1); //Debugger.Log( 1, "", "pages: " + pages + "\n" ); int scrollerPos; if (pages == 0) { double posInDelta = (remainingHeight * 1.0 - 2 - 1) / extraHeight; //Debugger.Log( 1, "", "posInDelta: " + posInDelta + "\n" ); scrollerPos = ( int )Math.Round(posInDelta * deltaY); } else { double deltaInPos = (extraHeight * 1.0) / (remainingHeight - 2 - 1); //Debugger.Log( 1, "", "deltaY/( deltaInPos ): " + deltaY/( deltaInPos ) + "\n" ); scrollerPos = ( int )Math.Round(deltaY / (deltaInPos)); } buffer.SetPixel(ActualWidth - 1, 1 + scrollerPos, UnicodeTable.BlackSquare, attr); // ■ } else if (ActualHeight == 3 + (horizontalScrollVisible ? 1 : 0)) { buffer.SetPixel(ActualWidth - 1, 1, UnicodeTable.BlackSquare, attr); // ■ } } if (horizontalScrollVisible && verticalScrollVisible) { buffer.SetPixel(ActualWidth - 1, ActualHeight - 1, UnicodeTable.SingleFrameBottomRightCorner, attr); // ┘ } }
public override void Render(RenderingBuffer buffer) { Attr attr = Colors.Blend(Color.Black, Color.DarkGreen); Attr inactiveAttr = Colors.Blend(Color.DarkGray, Color.DarkGreen); // Transparent background for borders buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 3); buffer.FillRectangle(0, 0, ActualWidth, ActualHeight, ' ', attr); // Transparent child content part if (ActualWidth > 2 && ActualHeight > 3) { buffer.SetOpacityRect(1, 3, ActualWidth - 2, ActualHeight - 4, 2); } renderBorderSafe(buffer, 0, 2, Math.Max(getTabHeaderWidth( ) - 1, ActualWidth - 1), ActualHeight - 1); // Start to render header buffer.FillRectangle(0, 0, ActualWidth, Math.Min(2, ActualHeight), ' ', attr); int x = 0; // Render tabs before active tab for (int tab = 0; tab < tabDefinitions.Count; x += TabDefinitions[tab++].Title.Length + 3) { var tabDefinition = TabDefinitions[tab]; if (tab <= activeTabIndex) { buffer.SetPixelSafe(x, 0, UnicodeTable.SingleFrameTopLeftCorner); buffer.SetPixelSafe(x, 1, UnicodeTable.SingleFrameVertical); } if (tab == activeTabIndex) { buffer.SetPixelSafe(x, 2, activeTabIndex == 0 ? UnicodeTable.SingleFrameVertical : UnicodeTable.SingleFrameBottomRightCorner); } for (int i = 0; i < tabDefinition.Title.Length + 2; i++) { buffer.SetPixelSafe(x + 1 + i, 0, UnicodeTable.SingleFrameHorizontal); if (tab == activeTabIndex) { buffer.SetPixelSafe(x + 1 + i, 2, ' '); } } buffer.RenderStringSafe(" " + tabDefinition.Title + " ", x + 1, 1, activeTabIndex == tab ? attr : inactiveAttr); if (tab >= activeTabIndex) { buffer.SetPixelSafe(x + tabDefinition.Title.Length + 3, 0, UnicodeTable.SingleFrameTopRightCorner); buffer.SetPixelSafe(x + tabDefinition.Title.Length + 3, 1, UnicodeTable.SingleFrameVertical); } if (tab == activeTabIndex) { buffer.SetPixelSafe(x + tabDefinition.Title.Length + 3, 2, activeTabIndex == tabDefinitions.Count - 1 && ActualWidth - 1 == x + tabDefinition.Title.Length + 3 ? UnicodeTable.SingleFrameVertical : UnicodeTable.SingleFrameBottomLeftCorner); } } }
public override void Render(RenderingBuffer buffer) { buffer.SetOpacityRect(0, 0, ActualWidth, ActualHeight, 2); }
public override void Render(RenderingBuffer buffer) { Attr borderAttrs = moving ? Colors.Blend(Color.Green, Color.Gray) : Colors.Blend(Color.White, Color.Gray); // background buffer.FillRectangle(0, 0, this.ActualWidth, this.ActualHeight, ' ', borderAttrs); // Borders RenderBorders(buffer, new Point(0, 0), new Point(ActualWidth - 3, ActualHeight - 2), this.moving || this.resizing, borderAttrs); // close button if (ActualWidth > 4) { buffer.SetPixel(2, 0, '['); buffer.SetPixel(3, 0, showClosingGlyph ? UnicodeTable.WindowClosePressedSymbol : UnicodeTable.WindowCloseSymbol, Colors.Blend(Color.Green, Color.Gray)); buffer.SetPixel(4, 0, ']'); } // shadows buffer.SetOpacity(0, ActualHeight - 1, 2 + 4); buffer.SetOpacity(1, ActualHeight - 1, 2 + 4); buffer.SetOpacity(ActualWidth - 1, 0, 2 + 4); buffer.SetOpacity(ActualWidth - 2, 0, 2 + 4); buffer.SetOpacityRect(2, ActualHeight - 1, ActualWidth - 2, 1, 1 + 4); buffer.SetOpacityRect(ActualWidth - 2, 1, 2, ActualHeight - 1, 1 + 4); // title if (!string.IsNullOrEmpty(Title)) { int titleStartX = 7; bool renderTitle = false; string renderTitleString = null; int availablePixelsCount = ActualWidth - titleStartX * 2; if (availablePixelsCount > 0) { renderTitle = true; if (Title.Length <= availablePixelsCount) { // dont truncate title titleStartX += (availablePixelsCount - Title.Length) / 2; renderTitleString = Title; } else { renderTitleString = Title.Substring(0, availablePixelsCount); if (renderTitleString.Length > 2) { renderTitleString = renderTitleString.Substring(0, renderTitleString.Length - 2) + ".."; } else { renderTitle = false; } } } if (renderTitle) { // assert !string.IsNullOrEmpty(renderingTitleString); buffer.SetPixel(titleStartX - 1, 0, ' ', borderAttrs); for (int i = 0; i < renderTitleString.Length; i++) { buffer.SetPixel(titleStartX + i, 0, renderTitleString[i], borderAttrs); } buffer.SetPixel(titleStartX + renderTitleString.Length, 0, ' ', borderAttrs); } } }
static unsafe void Main(String[] args) { rng = new Random(123); // Allocate the framebuffer byte[] buf = new byte[width * height * 3]; // Create the rendering buffer RenderingBuffer rbuf = new RenderingBuffer(buf, width, height, width * 3); // Create the renderer and the rasterizer Renderer ren = new Renderer(rbuf, new SpanBgr24()); Rasterizer ras = new Rasterizer(); // Setup the rasterizer ras.SetGamma(1.3); ras.FillRule = FillingRule.FillNonZero; ren.Clear(new Color(255, 255, 255)); #if !TEST_CURVE double pieceWidth = 0.59 * width / 2; double pieceHeight = 0.59 * height / 2; double ox = rbuf.Width / 4; double oy = rbuf.Height / 3; double cx = rbuf.Width / 2; double cy = rbuf.Height / 2; Point[] cpts = new Point[] { new Point(-1, 0), new Point(1 - 1.0 / 8, 1.0 / 3), new Point(-1, -1.0 / 3), new Point(0, -1.0 / 3), new Point(0, -1.0 / 3), new Point(1, -1.0 / 3), new Point(-1 + 1.0 / 8, 1.0 / 3), new Point(1, 0), Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, Point.Empty, }; int ci2 = 8; int ci3 = 16; double x; double y; AffineTransform trans = AffineTransform.CreateScale(1, 1.5) * AffineTransform.CreateTranslation(0, -1); AffineTransform rot = AffineTransform.CreateTranslation(0, -1) * AffineTransform.CreateScale(-1, 1) * AffineTransform.CreateRotation(-Math.PI / 2); AffineTransform rot2 = AffineTransform.CreateScale(1, 1.5) * AffineTransform.CreateTranslation(0, 1) * AffineTransform.CreateScale(1, -1) * AffineTransform.CreateRotation(-Math.PI); for (int ci = 0; ci < ci2; ci++) { double sx = cpts[ci].X; double sy = cpts[ci].Y; x = sx; y = sy; trans.Transform(ref x, ref y); cpts[ci].X = x; cpts[ci].Y = y; x = sx; y = sy; rot.Transform(ref x, ref y); cpts[ci2 + ci].X = x; cpts[ci2 + ci].Y = y; x = sx; y = sy; rot2.Transform(ref x, ref y); cpts[ci3 + ci].X = x; cpts[ci3 + ci].Y = y; } trans = new AffineTransform( pieceWidth, 0, 0, pieceHeight, rbuf.Width / 2, rbuf.Height / 2); for (int ci = 0; ci < cpts.Length; ci++) { x = cpts[ci].X; y = cpts[ci].Y; trans.Transform(ref x, ref y); cpts[ci].X = x; cpts[ci].Y = y; } Curve4 curve = new Curve4(); curve.ApproximationMethod = CurveApproximationMethod.Incremental; PathCommand cmd; for (int ci = 0; ci < cpts.Length; ci += 4) { curve.Initialize( cpts[ci + 0].X, cpts[ci + 0].Y, cpts[ci + 1].X, cpts[ci + 1].Y, cpts[ci + 2].X, cpts[ci + 2].Y, cpts[ci + 3].X, cpts[ci + 3].Y); do { cmd = curve.GetVertex(out x, out y); if (ci == 0 && cmd == PathCommand.MoveTo) { ras.MoveToD(x, y); } else if (cmd == PathCommand.LineTo) { ras.LineToD(x, y); } } while (cmd != PathCommand.Stop); } ras.Render(ren, Color.Red); for (int i = 1; i < 4; i++) { draw_line(ras, cpts[i - 1].X, cpts[i - 1].Y, cpts[i].X, cpts[i].Y, 1.0); ras.Render(ren, Color.Gray); int j = ci2 + i; draw_line(ras, cpts[j - 1].X, cpts[j - 1].Y, cpts[j].X, cpts[j].Y, 1.0); ras.Render(ren, Color.Gray); j = ci3 + i; draw_line(ras, cpts[j - 1].X, cpts[j - 1].Y, cpts[j].X, cpts[j].Y, 1.0); ras.Render(ren, Color.Gray); } #endif #if HIDE int i; // Draw random polygons for (i = 0; i < 10; i++) { int n = rng.Next() % 6 + 3; // Make the polygon. One can call move_to() more than once. // In this case the rasterizer behaves like Win32 API PolyPolygon(). ras.MoveToD(random(-30, rbuf.Width + 30), random(-30, rbuf.Height + 30)); for (int j = 1; j < n; j++) { ras.LineToD(random(-30, rbuf.Width + 30), random(-30, rbuf.Height + 30)); } // Render ras.Render(ren, new Color((byte)(rng.Next() & 0xFF), (byte)(rng.Next() & 0xFF), (byte)(rng.Next() & 0xFF), (byte)((rng.Next() & 0x7F) + 100))); } // Draw random ellipses for (i = 0; i < 50; i++) { draw_ellipse(ras, random(-30, rbuf.Width + 30), random(-30, rbuf.Height + 30), random(3, 50), random(3, 50)); ras.Render(ren, new Color((byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)((rng.Next() & 0x7F) + 100))); } // Draw random straight lines for (i = 0; i < 20; i++) { draw_line(ras, random(-30, rbuf.Width + 30), random(-30, rbuf.Height + 30), random(-30, rbuf.Width + 30), random(-30, rbuf.Height + 30), random(0.1, 10)); ras.Render(ren, new Color((byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F), (byte)(rng.Next() & 0x7F))); } #endif System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0, 0, (int)rbuf.Width, (int)rbuf.Height); System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(rc.Width, rc.Height, PixelFormat.Format24bppRgb); BitmapData bmpData = bmp.LockBits( rc, System.Drawing.Imaging.ImageLockMode.WriteOnly, bmp.PixelFormat); IntPtr p = bmpData.Scan0; int bytes = bmpData.Stride * bmp.Height; System.Runtime.InteropServices.Marshal.Copy(buf, 0, p, bytes); bmp.UnlockBits(bmpData); bmp.Save("agg_test.bmp"); #if PPM // Write a .ppm file String hdr = String.Format("P6\n{0} {1}\n255\n", rbuf.width(), rbuf.height()); byte[] hdrBuf = ASCIIEncoding.ASCII.GetBytes(hdr); using (FileStream strm = new FileStream("agg_test.ppm", FileMode.Create)) { strm.Write(hdrBuf, 0, hdrBuf.Length); strm.Write(buf, 0, (int)(rbuf.width() * rbuf.height() * 3)); } #endif }