예제 #1
0
        public override void Draw(MicroWorld.Graphics.Renderer renderer)
        {
            if (texture0cw == null) return;
            if (!CanDraw()) return;
            Resistor p = parent as Resistor;
            Components.Logics.ResistorLogics l = (Components.Logics.ResistorLogics)parent.Logics;

            String pr = "Ω";
            double tr = p.Resistance;
            if (tr > 1000000)//m
            {
                pr = "m" + pr;
                tr /= 1000000;
            }
            else if (tr > 1000)
            {
                pr = "k" + pr;
                tr /= 1000;
            }
            tr = Math.Round(tr, 1);
            if (parent.ComponentRotation == Component.Rotation.cw0)
                pr = tr.ToString() + " " + pr;
            else
            {
                String t = tr.ToString();
                for (int i = 2; i < t.Length; i += 4)
                    t = t.Insert(i, "\r\n");
                pr = t + "\r\n" + pr;
            }
            var a = font.MeasureString(pr);

            switch (parent.ComponentRotation)
            {
                case Component.Rotation.cw0:
                    renderer.Draw(texture0cw,
                        new Rectangle((int)Position.X, (int)Position.Y,
                            (int)GetSizeRotated(parent.ComponentRotation).X, (int)GetSizeRotated(parent.ComponentRotation).Y), null,
                            Color.White);
                    //text
                    renderer.DrawString(font, pr, Position + (GetSizeRotated(parent.ComponentRotation) - a) / 2, Color.White, MicroWorld.Graphics.Renderer.TextAlignment.Center);
                    break;
                case Component.Rotation.cw90:
                    renderer.Draw(texture90cw,
                        new Rectangle((int)Position.X, (int)Position.Y,
                            (int)GetSizeRotated(parent.ComponentRotation).X, (int)GetSizeRotated(parent.ComponentRotation).Y), null,
                            Color.White);
                    //text
                    renderer.DrawString(font, pr, Position + (GetSizeRotated(parent.ComponentRotation) - a) / 2, Color.White, MicroWorld.Graphics.Renderer.TextAlignment.Center);
                    break;
                case Component.Rotation.cw180:
                    break;
                case Component.Rotation.cw270:
                    break;
                default:
                    break;
            }

            //renderer.DrawStringLeft(MicroWorld.Graphics.GUI.Elements.TextBox.defaultFont, ((Resistor)parent).Resistance.ToString(),
            //    Position, Color.White);
        }