/// <summary> /// Initializes a new instance of the <see cref="Axis"/> class /// mostly with default values. /// </summary> /// <param name="TextInstance">The text instance.</param> public Axis(TextInstance TextInstance) { _majorTic = new MajorTic(); _minorTic = new MinorTic(); _zoomCorrection = Default.zoomCorrection; _zoomDiff = Default.zoomDiff; _axisGap = Default.AxisGap; _numSpace = Default.numSpace; _scale = new Scale(this, TextInstance); _textInstance = TextInstance; }
/// <summary> /// Draws the major tics. First their Number and their /// Positions are calculated, then they are given to the /// VBO as vertices to then be drawn. /// </summary> /// <param name="nTics">The n tics.</param> /// <param name="pane">The pane.</param> /// <param name="chart">The chart.</param> internal void DrawMajorTics(int nTics, GraphPane pane, Chart chart) { double dVal; float pixVal; MajorTic tic = _ownerAxis._majorTic; int firstTic = (int)(_min / _majorStep + 0.99); int k = 0; _ticsArray = new Vector2[2 * nTics + 2]; for (int i = firstTic; i < nTics + firstTic; i++) { dVal = _majorStep * i; // If we're before the start of the scale, just go to the next tic if (dVal < _min) { continue; } // if we've already past the end of the scale, then we're done if (dVal > _max) { break; } pixVal = LocalTransform(dVal); if (this._ownerAxis is XAxis)//Add two x/y-tupels to the array, one above, one below the axis { _ticsArray[k].X = -2 * pixVal / chart.Rect.Width + 1; _ticsArray[k + 1].X = -2 * pixVal / chart.Rect.Width + 1; _ticsArray[k].Y = -1; _ticsArray[k + 1].Y = 1; } else if (this._ownerAxis is YAxis) { _ticsArray[k].X = -1; _ticsArray[k + 1].X = 1; _ticsArray[k].Y = -2 * pixVal / chart.Rect.Height + 1; _ticsArray[k + 1].Y = -2 * pixVal / chart.Rect.Height + 1; } DrawTicValue(pane, chart, this._ownerAxis, pixVal, dVal);//at the position of every majorTic, draw a number k += 2; } if (this._ownerAxis is XAxis) {//the Viewports are directly put over the axis, so the _ticsArray has numbers rangig from -1 to 1 int one direction, just fitting the rectangle GL.Viewport((int)chart.Rect.X, (int)(chart.Rect.Y - tic.Size), (int)chart.Rect.Width, (int)(2 * tic.Size)); } else if (this._ownerAxis is YAxis) { GL.Viewport((int)(chart.Rect.X - tic.Size - _ownerAxis._fixedSpace * (this._ownerAxis as YAxis).Index), (int)chart.Rect.Y, (int)(2 * tic.Size), (int)chart.Rect.Height); if ((this._ownerAxis as YAxis).Index != 0) {//Draw the vertical line for yAxes that dont border the pChart area and so dont have one by default. _ticsArray[k].X = 0; _ticsArray[k + 1].X = 0; _ticsArray[k].Y = -1; _ticsArray[k + 1].Y = 1; k += 2; } } _linesShader.Use();//use Shader, bind VAO, bind VBO and give the tic values to the VBO GL.BindVertexArray(_VAO); GL.BindBuffer(BufferTarget.ArrayBuffer, _VBO); GL.BufferData <Vector2>(BufferTarget.ArrayBuffer, (IntPtr)(Vector2.SizeInBytes * _ticsArray.Length), _ticsArray, BufferUsageHint.StaticDraw); GL.VertexAttribPointer(_linesShader.VertexLocation, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0); GL.Uniform4(_linesShader.ColorLocation, Color.Black);//set uniform variables Color and Transformationmatrix GL.UniformMatrix4(_linesShader.MatrixLocation, false, ref _mat); GL.DrawArrays(PrimitiveType.Lines, 0, k);//draw the lines GL.BindVertexArray(0); _linesShader.StopUse(); }