unsafe private void GenerateVerticalLines(ColorIndicatorData data) { int blockCount = data.GetBlockCount(); //int blockCount = data.BlockCount; int segmentCount = blockCount + 1; ScientificModel verticalLines = new ScientificModel(segmentCount * 2, Enumerations.BeginMode.Lines); float[] positions = verticalLines.Positions; for (int i = 0; i < segmentCount; i++) { if (i + 1 != segmentCount) { if (data.MaxValue != data.MinValue) { positions[i * 2 * 3 + 0] = barWidth * (i * data.Step / (data.MaxValue - data.MinValue)); } else { positions[i * 2 * 3 + 0] = barWidth * 0; } } else { positions[i * 2 * 3 + 0] = barWidth; } positions[i * 2 * 3 + 1] = -9; positions[i * 2 * 3 + 2] = 0; positions[i * 2 * 3 + 3 + 0] = positions[i * 2 * 3 + 0]; positions[i * 2 * 3 + 3 + 1] = barHeight; positions[i * 2 * 3 + 3 + 2] = 0; } // move the vertical lines' center to (0, 0, 0) for (int i = 0; i < segmentCount * 2; i++) { positions[i * 3 + 0] -= barWidth / 2; positions[i * 3 + 1] -= barHeight / 2; } float[] colors = verticalLines.Colors; for (int i = 0; i < segmentCount * 2; i++) { colors[i * 3 + 0] = 1; colors[i * 3 + 1] = 1; colors[i * 3 + 2] = 1; //colors[i].red = byte.MaxValue / 2; //colors[i].green = byte.MaxValue / 2; //colors[i].blue = byte.MaxValue / 2; } this.verticalLines = verticalLines; }
public void Render(OpenGL gl, RenderMode renderMode) { SimpleUIRectArgs lastArgs = this.CurrentArgs; if (lastArgs == null) { return; } ColorIndicatorData data = this.Data; if (data == null) { return; } int blockCount = data.GetBlockCount(); if (blockCount <= 0) { return; } String formatStr = MinorFormatString(data.Step); GLColor[] colors = data.ColorPalette.Colors; int blockWidth = 0; if (data.MaxValue - data.MinValue == 0) { blockWidth = lastArgs.UIWidth; } else { blockWidth = (int)(lastArgs.UIWidth * (data.Step / (data.MaxValue - data.MinValue))); } //draw numbers for (int i = 0; i <= blockCount; i++) { string value = null; if (i == blockCount) { if (!data.UseLogarithmic) { value = data.MaxValue.ToString(formatStr, CultureInfo.InvariantCulture); } else { value = Math.Pow(data.LogBase, data.MaxValue).ToString(formatStr, CultureInfo.InvariantCulture); } } else { float tickValue = data.MinValue + data.Step * i; if (!data.UseLogarithmic) { value = tickValue.ToString(formatStr, CultureInfo.InvariantCulture); } else { value = Math.Pow(data.LogBase, tickValue).ToString(formatStr, CultureInfo.InvariantCulture); } } double valueLength = 100.0 * value.Length / fontSize; double x = 0; if (i == blockCount) { x = -(double)lastArgs.UIWidth / 2 - lastArgs.left + lastArgs.UIWidth - valueLength / 2; } else { x = -(double)lastArgs.UIWidth / 2 - lastArgs.left + i * blockWidth - valueLength / 2; } double y = -(double)lastArgs.UIHeight / 2 - lastArgs.bottom - 14; gl.DrawText((int)x, (int)y, 1, 1, 1, "Courier New", fontSize, value); } }