Re-wrote Ruler to reduce number of memory allocations.
@@ -127,19 +127,22 @@ class App
// Ruler object //
//////////////////
- static Pose demoRuler = new Pose(0, 0, .5f, Quat.Identity);
+ static Pose rulerPose = new Pose(0, 0, .5f, Quat.Identity);
+ static string[] rulerLabels = { "0", "5", "10", "15", "20", "25" };
static void RulerWindow()
{
- UI.HandleBegin("Ruler", ref demoRuler, new Bounds(new Vec3(31,4,1)*U.cm), true);
+ UI.HandleBegin("Ruler", ref rulerPose, new Bounds(new Vec3(31,4,1)*U.cm), true);
Color32 color = Color.HSV(.6f, 0.5f, 1);
Text.Add("Centimeters", Matrix.TS(new Vec3(14.5f, -1.5f, -.6f)*U.cm, .3f), TextAlign.BottomLeft);
for (int d = 0; d <= 60; d+=1)
{
float x = d/2.0f;
- float size = d%2==0?1f:0.15f;
+ float size = d%2==0?.5f:0.15f;
+ if (d%10 == 0 && d/2 != 30) {
+ size = 1;
+ Text.Add(rulerLabels[d/10], Matrix.TS(new Vec3(15-x-0.1f, 2-size, -.6f) * U.cm, .2f), TextAlign.BottomLeft);
+ }
Lines.Add(new Vec3(15-x, 1.8f, -.6f)*U.cm, new Vec3(15-x,1.8f-size, -.6f)*U.cm, color, U.mm*0.5f);
- if (d%2==0 && d/2 != 30)
- Text.Add((d/2).ToString(), Matrix.TS(new Vec3(15-x-0.1f,2-size, -.6f)*U.cm, .2f), TextAlign.BottomLeft);
}
UI.HandleEnd();
}
