public override void RenderImage(int[] imagekey, TransformedImage image, ImageCloud.FreeView freeview) { float x = (float)imagekey[idx[0]]; float z = (float)imagekey[idx[1]]; Matrix4 worldmatrix = Matrix4.CreateScale(x * 2.1f, y[(imagekey[idx[0]] + arguments[idx[0]].values.Length * imagekey[idx[1]]) % 1024], z * 2.1f); Common.sdrSolidColor.Bind(worldmatrix * freeview.viewprojmatrix); meshValueLine.Bind(Common.sdrSolidColor, null); meshValueLine.Draw(); }
public void Draw(Rectangle bounds, int argidx, Size backbufferSize, GLShader sdr, int colorUniform) { float x, y; this.bounds = bounds; Matrix4 trans = Matrix4.Identity; trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f); trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, BORDER_COLOR); meshBorders.Bind(sdr, null); meshBorders.Draw(); GL.Uniform4(colorUniform, SLIDER_COLOR); meshSlider.Bind(sdr, null); y = 0.0f; //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height; //int xi = 0; float sliderWidth = 20.0f; //x = (float)(xi + 1) / (float)(values.Length + 1); x = (currentValue - minValue) / valueRange; x *= (2.0f * bounds.Width) / backbufferSize.Width; x = (sliderWidth + x * (bounds.Width - sliderWidth)) / bounds.Width; sdr.Bind(Matrix4.CreateScale(sliderWidth / (2.0f * bounds.Width), 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f)); meshSlider.Draw(); GL.LineWidth(2.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, TICK_COLOR); meshTick.Bind(sdr, null); for (int i = 0; i < values.Length; ++i) { //x = (float)(i + 1) / (float)(values.Length + 1); x = (values[i] - minValue) / valueRange; sdr.Bind(trans * Matrix4.CreateTranslation((x * 2.0f * (bounds.Width - sliderWidth) + sliderWidth) / backbufferSize.Width, 0.0f, 0.0f)); meshTick.Draw(); } GL.LineWidth(1.0f); Vector2 strsize = Common.fontText2.MeasureString(label); Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize); this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y); }
protected override void DrawString(float x, float y, float w, string strnumber, System.Drawing.Size backbufferSize, Color4 color) { // Fonts look best when they are drawn on integer positions (so they don't have to be interpolated over multiple pixels) x = (float)(int)x; y = (float)(int)y; // Bind texture and save the size of a pixel in the texture's coordinate system fontshader.Bind(); GL.Uniform4(fontshader_coloruniform, color); meshquad.Bind(fontshader, texture); /*if(sdr.InvTexSizeUniform) * gl.uniform2f(sdr.InvTexSizeUniform, 1.0 / texture.image.width, 1.0 / texture.image.height);*/ for (int i = 0; i < strnumber.Length; ++i) { int digit = strnumber[i] - '0'; Vector2 digit_pos = new Vector2(fontdef.charpos_x[digit], fontdef.charpos_y[0]); Vector2 digit_size = new Vector2(fontdef.charpos_x[digit + 1] - fontdef.charpos_x[digit], fontdef.charpos_y[1] - fontdef.charpos_y[0]); // Transform texture quad texture coordinates to select the letter Matrix3 texcoordtrans = Matrix3.Identity; //texcoordtrans *= Matrix3_CreateScale(digit_size.X / texture.width, digit_size.Y / texture.height); texcoordtrans *= GLTextFont.Matrix3_CreateScale(digit_size.X / texture.width, (digit_size.Y - 2.0f) / texture.height); texcoordtrans *= Matrix3_CreateTranslation(digit_pos.X / texture.width, digit_pos.Y / texture.height); GL.UniformMatrix3(fontshader.defparams.textransform, false, ref texcoordtrans); /*// Save digit bounds so that digits can be clamped to avoid bleeding over of neighboring digits * if(sdr.texboundsUniform) * gl.uniform1fv(sdr.texboundsUniform, [digit_pos[0] / texture.image.width, (digit_pos[0] + digit_size[0]) / texture.image.width, * digit_pos[1] / texture.image.height, (digit_pos[1] + digit_size[1]) / texture.image.height]);*/ if (fixedwidth != 0) { digit_size.X = fixedwidth; } // Transform texture quad vertices to position the letter Matrix4 trans = Matrix4.Identity; trans *= Matrix4.CreateScale(2.0f * digit_size.X / backbufferSize.Width, (2.0f * digit_size.Y - 4.0f) / backbufferSize.Height, 1.0f); trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (x + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (y + texture.height) / backbufferSize.Height, w); GL.UniformMatrix4(fontshader.defparams.worldviewproj, false, ref trans); meshquad.Draw(); x += digit_size.X; } }
public void Draw(Rectangle bounds, Selection selection, Size backbufferSize, GLShader sdr, int colorUniform) { float x, y; this.bounds = bounds; Matrix4 trans = Matrix4.Identity; trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f); trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, BORDER_COLOR); meshBorders.Bind(sdr, null); meshBorders.Draw(); if (selection != null) { GL.Uniform4(colorUniform, SELECTION_COLOR); meshSelection.Bind(sdr, null); y = 0.0f; //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height; foreach (TransformedImage selectedimage in selection) { /*int xi = -1; * for(int i = 0; i < selectedimage.args.Length; ++i) * if(selectedimage.args[i] == Global.arguments[argidx]) * { * xi = Array.IndexOf(selectedimage.args[i].values, selectedimage.values[i]); * break; * } * if(xi == -1) * continue;*/ if (selectedimage.globalargindices.Length <= argidx || selectedimage.globalargindices[argidx] == -1) { continue; } int xi = Array.IndexOf(Global.arguments[argidx].values, selectedimage.values[selectedimage.globalargindices[argidx]]); if (xi == -1) { continue; } /*if(selectedimage.args.Length <= argidx) * continue; * int xi = Array.IndexOf(selectedimage.args[argidx].values, selectedimage.values[argidx]);*/ float halfwidth = argument.strValues.Length <= MAX_NUM_ARGS_SHOWING_VALUES?Common.fontTextSmall.MeasureString(argument.strValues[xi]).X / 2.0f + 2.0f : 3.0f; x = (float)(xi + 1) / (float)(argument.strValues.Length + 1); x *= 2.0f * bounds.Width / backbufferSize.Width; sdr.Bind(Matrix4.CreateScale(halfwidth / bounds.Width, 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f)); meshSelection.Draw(); } } /*Point preSelectedTick; * if(TickFromMousePosition(mousepos, backbufferSize, out preSelectedTick)) * { * GL.Uniform4(sdrColored_colorParam, PRESELECTION_COLOR); * if(preSelectedTick.X == -1) * for(preSelectedTick.X = 0; preSelectedTick.X < arguments[preSelectedTick.Y].values.Length; ++preSelectedTick.X) * { * x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1); * sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f)); * meshSelection.Draw(); * } * else * { * x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1); * sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f)); * meshSelection.Draw(); * } * }*/ if (argument.strValues.Length > MAX_NUM_ARGS_SHOWING_VALUES) { GL.LineWidth(2.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, TICK_COLOR); meshTick.Bind(sdr, null); for (int i = 0; i < argument.strValues.Length; ++i) { //x = (float)(i + 1) / (float)(argument.strValues.Length + 1); x = argument.values[i] / 10.0f; sdr.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, 0.0f, 0.0f)); meshTick.Draw(); } } else { y = bounds.Bottom - Common.fontTextSmall.MeasureString(" ").Y + 2.0f; for (int i = 0; i < argument.values.Length; ++i) { x = (float)(i + 1) / (float)(argument.strValues.Length + 1); Common.fontTextSmall.DrawString(bounds.Left + x * bounds.Width - Common.fontTextSmall.MeasureString(argument.strValues[i]).X / 2.0f, y, argument.strValues[i], backbufferSize); } } GL.LineWidth(1.0f); Vector2 strsize = Common.fontText2.MeasureString(label); Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize); this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y); }
public void Draw(Rectangle bounds, HashSet <int> selection, Size backbufferSize, GLShader sdr, int colorUniform) { float x, y; this.bounds = bounds; Matrix4 trans = Matrix4.Identity; trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f); trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, BORDER_COLOR); meshBorders.Bind(sdr, null); meshBorders.Draw(); GL.LineWidth(6.0f); if (selection != null) { GL.Uniform4(colorUniform, SELECTION_COLOR); meshSelection.Bind(sdr, null); y = 0.0f; //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height; foreach (int xi in selection) { x = (float)(xi + 1) / (float)(numvalues + 1); x *= 2.0f * bounds.Width / backbufferSize.Width; sdr.Bind(trans * Matrix4.CreateTranslation(x, y, 0.0f)); meshSelection.Draw(); } } /*Point preSelectedTick; * if(TickFromMousePosition(mousepos, backbufferSize, out preSelectedTick)) * { * GL.Uniform4(sdrColored_colorParam, PRESELECTION_COLOR); * if(preSelectedTick.X == -1) * for(preSelectedTick.X = 0; preSelectedTick.X < arguments[preSelectedTick.Y].values.Length; ++preSelectedTick.X) * { * x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1); * sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f)); * meshSelection.Draw(); * } * else * { * x = (float)(preSelectedTick.X + 1) / (float)(arguments[preSelectedTick.Y].values.Length + 1); * sdrColored.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, preSelectedTick.Y * -1.5f * (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 0.0f)); * meshSelection.Draw(); * } * }*/ GL.LineWidth(2.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, TICK_COLOR); meshTicks.Bind(sdr, null); meshTicks.Draw(); GL.LineWidth(1.0f); Vector2 strsize = Common.fontText.MeasureString(label); Common.fontText.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize); this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y); }
public void Draw(ImageCloud.FreeView freeview, AABB selectionAabb, Color4 selectionAabbColor, Size backbuffersize, int numdims = 3) { /*// Use custom projection matrix with z-far tailored to include all axes * float maxdist = 0.0f; * maxdist = Math.Max(maxdist, (new Vector3(1000.0f, 0.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(-1000.0f, 0.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, 1000.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, -1000.0f, 0.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, 0.0f, 1000.0f) - freeview.viewpos).Length); * maxdist = Math.Max(maxdist, (new Vector3(0.0f, 0.0f, -1000.0f) - freeview.viewpos).Length); * Matrix4 viewprojmatrix = freeview.viewmatrix * Matrix4.CreatePerspectiveFieldOfView(ImageCloud.FOV_Y, (float)backbuffersize.Width / (float)backbuffersize.Height, maxdist / 10000.0f, maxdist);*/ Matrix4 viewprojmatrix = freeview.viewprojmatrix; Vector3 __axis_dist = new Vector3((new Vector2(freeview.viewpos.Y, freeview.viewpos.Z)).Length, (new Vector2(freeview.viewpos.X, freeview.viewpos.Z)).Length, (new Vector2(freeview.viewpos.X, freeview.viewpos.Y)).Length); Vector3 axis_dist = new Vector3(), _axis_dist = new Vector3(); for (int i = 0; i < numdims; ++i) { _axis_dist[i] = (float)Math.Log10(Math.Max(freeview.znear, __axis_dist[i])); axis_dist[i] = (float)Math.Pow(10.0, Math.Floor(_axis_dist[i])); } int[] floor_viewpos = new int[numdims]; float[] floor_viewpos10 = new float[numdims], axis_dist_fract = new float[numdims]; Matrix4[] scalematrix = new Matrix4[numdims]; for (int d = 0; d < numdims; ++d) { floor_viewpos[d] = Math.Abs((int)(Math.Floor(freeview.viewpos[d] / axis_dist[d] * 10.0f) / 10.0f)); floor_viewpos10[d] = Math.Abs((float)Math.Floor(freeview.viewpos[d] / axis_dist[d] / 10.0f) * axis_dist[d] * 10.0f); axis_dist_fract[d] = (_axis_dist[d] + 100.0f) % 1.0f; //EDIT: 100.0f ... constant to keep log positive scalematrix[d] = Matrix4.CreateScale(axis_dist[d]); } Vector3[] unitvector = { new Vector3(1.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f), new Vector3(0.0f, 0.0f, 1.0f) }; Matrix4[] tickrotmatrix = { Matrix4.CreateRotationY(MathHelper.PiOver2) * Matrix4.CreateRotationX(MathHelper.PiOver2), Matrix4.CreateRotationX(-MathHelper.PiOver2) * Matrix4.CreateRotationY(-MathHelper.PiOver2), Matrix4.Identity }; // >>> Draw axes GL.LineWidth(4.0f); axismesh.Bind(Common.sdrSolidColor); // Draw axes in positive directions Common.sdrSolidColor.Bind(viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, POSITIVE_AXIS_COLOR); axismesh.Draw(0, 2 * numdims); // Draw axes in negative directions Common.sdrSolidColor.Bind(Matrix4.CreateRotationY(MathHelper.Pi) * Matrix4.CreateRotationZ(MathHelper.PiOver2) * viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, NEGATIVE_AXIS_COLOR); axismesh.Draw(0, 2 * numdims); // >>> Draw selection AABB if (selectionAabb != null) { linemesh.Bind(Common.sdrSolidColor); Matrix4 selectionAabbTransform = selectionAabb.GetTransform(); Matrix4 offsetTransform = Matrix4.CreateTranslation(0.0f, 0.0f, -0.00001f); Common.sdrSolidColor.Bind(tickrotmatrix[0] * selectionAabbTransform * Matrix4.CreateScale(unitvector[0]) * viewprojmatrix * offsetTransform); GL.Uniform4(Common.sdrSolidColor_colorUniform, selectionAabbColor); linemesh.Draw(); Common.sdrSolidColor.Bind(tickrotmatrix[1] * selectionAabbTransform * Matrix4.CreateScale(unitvector[1]) * viewprojmatrix * offsetTransform); linemesh.Draw(); Common.sdrSolidColor.Bind(tickrotmatrix[2] * selectionAabbTransform * Matrix4.CreateScale(unitvector[2]) * viewprojmatrix * offsetTransform); linemesh.Draw(); } // >>> Draw ticks GL.LineWidth(2.0f); tickmesh.Bind(Common.sdrSolidColor); for (int d = 0; d < numdims; ++d) { if (__axis_dist[d] < freeview.znear) { continue; } for (int t = floor_viewpos[d] + LABEL_CAM_DISTANCE; t >= floor_viewpos[d]; --t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); float scale = axis_dist_fract[d]; if (t % 10 == 0) { scale *= 0.01f; } Color4 clr = t > 0 ? POSITIVE_AXIS_COLOR : NEGATIVE_AXIS_COLOR; clr.A = 1.0f - opacity; Common.sdrSolidColor.Bind(Matrix4.CreateScale(__axis_dist[d] * (1.0f - 0.5f * scale)) * tickrotmatrix[d] * Matrix4.CreateTranslation(lblpos) * viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, clr); tickmesh.Draw(); } for (int t = floor_viewpos[d] - LABEL_CAM_DISTANCE; t < floor_viewpos[d]; ++t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); float scale = axis_dist_fract[d]; if (t % 10 == 0) { scale *= 0.01f; } Color4 clr = t > 0 ? POSITIVE_AXIS_COLOR : NEGATIVE_AXIS_COLOR; clr.A = 1.0f - opacity; Common.sdrSolidColor.Bind(Matrix4.CreateScale(__axis_dist[d] * (1.0f - 0.5f * scale)) * tickrotmatrix[d] * Matrix4.CreateTranslation(lblpos) * viewprojmatrix); GL.Uniform4(Common.sdrSolidColor_colorUniform, clr); tickmesh.Draw(); } } GL.LineWidth(1.0f); // >>> Draw labels Matrix4 vieworient = freeview.viewmatrix, invvieworient; vieworient.M41 = vieworient.M42 = vieworient.M43 = 0.0f; invvieworient = vieworient; invvieworient.Transpose(); for (int d = 0; d < numdims; ++d) { if (__axis_dist[d] < freeview.znear) { continue; } for (int t = floor_viewpos[d] + LABEL_CAM_DISTANCE; t >= floor_viewpos[d]; --t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); Color4 clr = new Color4(1.0f, 1.0f, 1.0f, 1.0f - opacity); //Vector3 offset = (freeview.viewpos - lblpos).Normalized() * 1.0f; Common.fontText2.DrawStringAt(lblpos /*+ offset*/, viewprojmatrix, ((decimal)t * (decimal)axis_dist[d]).ToString(), backbuffersize, clr); } for (int t = floor_viewpos[d] - LABEL_CAM_DISTANCE; t < floor_viewpos[d]; ++t) { if (t == 0) { continue; } Vector3 lblpos = unitvector[d] * (float)t * axis_dist[d]; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = (float)Math.Pow(axis_dist_fract[d], LABEL_AXIS_DISTANCE_FADE); if (t % 10 == 0) { opacity *= 0.1f; } opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); Color4 clr = new Color4(1.0f, 1.0f, 1.0f, 1.0f - opacity); //Vector3 offset = (freeview.viewpos - lblpos).Normalized() * 1.0f; Common.fontText2.DrawStringAt(lblpos /*+ offset*/, viewprojmatrix, ((decimal)t * (decimal)axis_dist[d]).ToString(), backbuffersize, clr); } } // >>> Draw selection AABB labels if (selectionAabb != null) { for (int d = 0; d < numdims; ++d) { if (Math.Abs(selectionAabb.max[d] - selectionAabb.min[d]) < 0.1f) { continue; } float value = (selectionAabb.max[d] + selectionAabb.min[d]) / 2.0f; Vector3 lblpos = unitvector[d] * value; float lbldist = (freeview.viewpos - lblpos).Length; float opacity = 0.0f; opacity += (float)Math.Pow(lbldist / LABEL_CAM_DISTANCE, LABEL_CAM_DISTANCE_FADE); Color4 clr = selectionAabbColor; clr.A = 1.0f - opacity; Vector3 offset = (freeview.viewpos - lblpos).Normalized() * 1.0f; Common.fontText2.DrawStringAt(lblpos + offset, viewprojmatrix, ((decimal)value).ToString(), backbuffersize, clr); } } }
protected override void DrawString(float x, float y, float w, string text, System.Drawing.Size backbufferSize, Color4 color) { // Fonts look best when they are drawn on integer positions (so they don't have to be interpolated over multiple pixels) float linestart = x = (float)(int)x; y = (float)(int)y; // Bind texture and save the size of a pixel in the texture's coordinate system fontshader.Bind(); GL.Uniform4(fontshader_coloruniform, color); meshquad.Bind(fontshader, texture); /*if(sdr.InvTexSizeUniform) * gl.uniform2f(sdr.InvTexSizeUniform, 1.0 / texture.image.width, 1.0 / texture.image.height);*/ for (int i = 0; i < text.Length; ++i) { char chr = text[i]; if (chr == '\n') { x = linestart; y += charsize.Y; } if (chr != ' ') { Vector2 charpos; switch (chr) { case '-': charpos = new Vector2((float)(0 * charsize.X), (float)(3 * charsize.Y)); break; case '/': charpos = new Vector2((float)(1 * charsize.X), (float)(3 * charsize.Y)); break; case ':': charpos = new Vector2((float)(2 * charsize.X), (float)(3 * charsize.Y)); break; case '>': charpos = new Vector2((float)(3 * charsize.X), (float)(3 * charsize.Y)); break; case '(': charpos = new Vector2((float)(4 * charsize.X), (float)(3 * charsize.Y)); break; case ')': charpos = new Vector2((float)(5 * charsize.X), (float)(3 * charsize.Y)); break; case '%': charpos = new Vector2((float)(6 * charsize.X), (float)(3 * charsize.Y)); break; case '.': charpos = new Vector2((float)(7 * charsize.X), (float)(3 * charsize.Y)); break; default: if (char.IsNumber(chr)) { charpos = new Vector2((float)(chr - '0') * charsize.X, (float)(2 * charsize.Y)); // Character is digit } else { charpos = new Vector2((float)(char.ToLower(chr) - 'a') * charsize.X, (float)(char.IsUpper(chr) ? 0 : 1) * charsize.Y); // Character is letter } break; } // Transform texture quad texture coordinates to select the letter Matrix3 texcoordtrans = Matrix3.Identity; //texcoordtrans *= Matrix3_CreateScale(charsize.X / texture.width, charsize.Y / texture.height); texcoordtrans *= GLTextFont.Matrix3_CreateScale(charsize.X / texture.width, (charsize.Y - 2.0f) / texture.height); texcoordtrans *= Matrix3_CreateTranslation((charpos.X - 0.5f) / texture.width, (charpos.Y - 0.5f) / texture.height); GL.UniformMatrix3(fontshader.defparams.textransform, false, ref texcoordtrans); /*// Save character bounds so that characters can be clamped to avoid bleeding over of neighboring characters * if(sdr.texboundsUniform) * gl.uniform1fv(sdr.texboundsUniform, [charpos[0] / texture.image.width, (charpos[0] + charsize[0]) / texture.image.width, * charpos[1] / texture.image.height, (charpos[1] + charsize[1]) / texture.image.height]);*/ // Transform texture quad vertices to position the letter Matrix4 trans = Matrix4.Identity; trans *= Matrix4.CreateScale(2.0f * charsize.X / backbufferSize.Width, (2.0f * charsize.Y - 4.0f) / backbufferSize.Height, 1.0f); trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (x + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (y + charsize.Y) / backbufferSize.Height, w); GL.UniformMatrix4(fontshader.defparams.worldviewproj, false, ref trans); meshquad.Draw(); } x += charsize.X; } }
public void Draw(Rectangle bounds, int argidx, Size backbufferSize, GLShader sdr, int colorUniform) { float x, y; this.bounds = bounds; Matrix4 trans = Matrix4.Identity; trans *= Matrix4.CreateScale(2.0f * bounds.Width / backbufferSize.Width, (2.0f * bounds.Height - 4.0f) / backbufferSize.Height, 1.0f); trans *= Matrix4.CreateTranslation(-1.0f + 2.0f * (bounds.Left + 0.5f) / backbufferSize.Width, 1.0f - 2.0f * (bounds.Bottom - 0.5f) / backbufferSize.Height, 0.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, BORDER_COLOR); meshBorders.Bind(sdr, null); meshBorders.Draw(); GL.Uniform4(colorUniform, CHECK_COLOR); meshCheck.Bind(sdr, null); y = 0.0f; //(2.0f * bounds.Height - 4.0f) / backbufferSize.Height; int xi = 0; foreach (bool isChecked in parameter.isChecked) { if (isChecked) { float halfwidth = parameter.strValues.Length <= MAX_NUM_PARAMS_SHOWING_VALUES?Common.fontTextSmall.MeasureString(parameter.strValues[xi]).X / 2.0f + 2.0f : 3.0f; x = (float)(xi + 1) / (float)(parameter.strValues.Length + 1); x *= 2.0f * bounds.Width / backbufferSize.Width; sdr.Bind(Matrix4.CreateScale(halfwidth / bounds.Width, 1.0f, 1.0f) * trans * Matrix4.CreateTranslation(x, y, 0.0f)); meshCheck.Draw(); } ++xi; } if (parameter.strValues.Length > MAX_NUM_PARAMS_SHOWING_VALUES) { GL.LineWidth(2.0f); sdr.Bind(trans); GL.Uniform4(colorUniform, TICK_COLOR); meshTick.Bind(sdr, null); for (int i = 0; i < parameter.strValues.Length; ++i) { //x = (float)(i + 1) / (float)(parameter.strValues.Length + 1); x = parameter.values[i] / 10.0f; sdr.Bind(trans * Matrix4.CreateTranslation(x * 2.0f * bounds.Width / backbufferSize.Width, 0.0f, 0.0f)); meshTick.Draw(); } } else { y = bounds.Bottom - Common.fontTextSmall.MeasureString(" ").Y + 2.0f; for (int i = 0; i < parameter.values.Length; ++i) { x = (float)(i + 1) / (float)(parameter.strValues.Length + 1); Common.fontTextSmall.DrawString(bounds.Left + x * bounds.Width - Common.fontTextSmall.MeasureString(parameter.strValues[i]).X / 2.0f, y, parameter.strValues[i], backbufferSize); } } GL.LineWidth(1.0f); Vector2 strsize = Common.fontText2.MeasureString(label); Common.fontText2.DrawString(bounds.X - strsize.X - 2, bounds.Y - 1, label, backbufferSize); this.labelBounds = new Rectangle((int)(bounds.X - strsize.X - 2), bounds.Y - 1, (int)strsize.X, (int)strsize.Y); }