public void RenderLine(IDrawingContext ctx, char[] text, DisplayPixel color) { for (int i = 0; i < text.Length; i += 1) { RenderCharacter(ctx.GetOffsetContext(i * width, 0), text[i], color); } }
public TextComponent(IDrawingContext parent, SdrFontPack font, string text, DisplayPixel color, AlignHorizontal horizontalTextAlign = AlignHorizontal.Left, AlignVertical verticalTextAlign = AlignVertical.Top) : base(parent) { this.font = font; this.text = text.ToCharArray(); this.color = color; this.horizontalTextAlign = horizontalTextAlign; this.verticalTextAlign = verticalTextAlign; }
private static DisplayPixel InterpColor(float percent, DisplayPixel c1, DisplayPixel c2) { var invPercent = 1 - percent; return(new DisplayPixel( (byte)((c1.r * percent) + (c2.r * invPercent)), (byte)((c1.g * percent) + (c2.g * invPercent)), (byte)((c1.b * percent) + (c2.b * invPercent)) )); }
private void Debugger_OnScreencapData(byte[] buffer, int bufferOffset, int count) { if (imagePtr == null) { return; } for (int i = 0; i < count; i += 4) { imagePtr[imageIndex] = new DisplayPixel(buffer[DebuggerBase.HEADER_LENGTH + i + 2], buffer[DebuggerBase.HEADER_LENGTH + i + 1], buffer[DebuggerBase.HEADER_LENGTH + i + 0], buffer[DebuggerBase.HEADER_LENGTH + i + 3]); imageIndex = (imageIndex + 1) % imageSize; } frame.Invalidate(); }
private void PrecomputeGradients() { //Precompute spectrum gradient gradient = new DisplayPixel[Height]; gradientDark = new DisplayPixel[Height]; for (int i = 0; i < Height; i++) { float scale = i * (1 / (float)Height); gradient[i] = new DisplayPixel(0, 0, 0); gradientDark[i] = new DisplayPixel(0, 0, 0); //R gradient[i].r = (byte)(((1 - scale) * SPECTRUM_TOP_COLOR[0]) + (scale * SPECTRUM_BOTTOM_COLOR[0])); gradientDark[i].r = (byte)(gradient[i].r / 4); //G gradient[i].g = (byte)(((1 - scale) * SPECTRUM_TOP_COLOR[1]) + (scale * SPECTRUM_BOTTOM_COLOR[1])); gradientDark[i].g = (byte)(gradient[i].g / 4); //B gradient[i].b = (byte)(((1 - scale) * SPECTRUM_TOP_COLOR[2]) + (scale * SPECTRUM_BOTTOM_COLOR[2])); gradientDark[i].b = (byte)(gradient[i].b / 4); } }
public unsafe void RenderCharacter(IDrawingContext ctx, char c, DisplayPixel color) { //Make sure we have this if (!font.ContainsKey(c)) { return; } //Get lines byte[] data = font[c]; //Copy for (int y = 0; y < height; y++) { //Get pointer and offset DisplayPixel *line = ctx.GetPixelPointer(0, y); int offset = width * y; //Transfer for (int x = 0; x < width; x++) { //Cheap out if (data[offset + x] == byte.MaxValue) { line[x] = color; } else if (data[offset + x] == 0) { continue; } //Mix DisplayPixel.Mix(&color, line + x, data[offset + x] / 255f, line + x); } } }
public void RenderPretty(IDrawingContext ctx, char[][] text, DisplayPixel color, AlignHorizontal horizTextAlign, AlignVertical vertTextAlign, int boundsWidth, int boundsHeight) { //Determine Y offset int offsetY; switch (vertTextAlign) { case AlignVertical.Top: offsetY = 0; break; case AlignVertical.Bottom: offsetY = boundsHeight - (text.Length * height); break; case AlignVertical.Center: offsetY = (boundsHeight - (text.Length * height)) / 2; break; default: throw new Exception("Unknown alignment."); } //Draw for (int ln = 0; ln < text.Length; ln++) { //Calculate X offset int offsetX; switch (horizTextAlign) { case AlignHorizontal.Left: offsetX = 0; break; case AlignHorizontal.Right: offsetX = boundsWidth - (text[ln].Length * width); break; case AlignHorizontal.Center: offsetX = (boundsWidth - (text[ln].Length * width)) / 2; break; default: throw new Exception("Unknown alignment."); } //Write RenderLine(ctx.GetOffsetContext(offsetX, offsetY + (height * ln)), text[ln], color); } }
protected override void RedrawView() { //Check if the height has changed if (gradient == null || gradient.Length != Height) { PrecomputeGradients(); } //Make sure buffer is OK if (fftBuffer == null || fftBuffer.Length - 2 != Width) { return; } //Get base pixel var ptr = GetPixelPointer(0, 0); //Loop for (var x = 0; x < Width; x += 1) { //Get where this pixel is var max = Math.Max(fftPtr[x - 1], Math.Max(fftPtr[x], fftPtr[x + 1])); var value = fftPtr[x]; var min = Math.Min(fftPtr[x - 1], Math.Min(fftPtr[x], fftPtr[x + 1])); //Loop for (var y = 0; y < Height; y++) { //Get offset var offset = ((y * Width) + x); //Determine color if (y > max) { //Full gradient ptr[offset] = gradient[y]; } else if (y == value) { //Point ptr[offset] = new DisplayPixel(255, 255, 255); } else if (y <= max && y > value) { //Interp top var c = InterpColor((float)Math.Pow((y - value) / (max - value), 3), gradient[y], new DisplayPixel(255, 255, 255)); ptr[offset + 0] = c; } else if (y < value && y >= min) { //Intep bottom var c = InterpColor((float)Math.Pow((y - min) / (value - min), 3), new DisplayPixel(255, 255, 255), gradientDark[y]); ptr[offset + 0] = c; } else { //Dark gradient ptr[offset] = gradientDark[y]; } } } }
public BoxComponent(IDrawingContext ctx, DisplayPixel color) : base(ctx) { this.color = color; }
public TextComponent SetTextColor(DisplayPixel color) { TextColor = color; return(this); }
public TextComponent SetBackgroundColor(DisplayPixel color) { BackgroundColor = color; return(this); }
public void WritePixel(int offsetX, int offsetY, DisplayPixel pixel) { bufferPtr[offsetX + (offsetY * FRAME_WIDTH)] = pixel; }
public void RenderPretty(IDrawingContext ctx, char[] text, DisplayPixel color, AlignHorizontal horizTextAlign, AlignVertical vertTextAlign, int boundsWidth, int boundsHeight) { char[][] lines = SplitLines(text, boundsWidth, boundsHeight); RenderPretty(ctx, lines, color, horizTextAlign, vertTextAlign, boundsWidth, boundsHeight); }