A control which draws glyphed text.
Changing the text, font or width will cause many string allocations. The label automatically sets it's size to that of its text when the text, justification or font changes.
Inheritance: Control
示例#1
0
        public StatisticGraph(Control parent, SpriteFont font, Statistic statistic, TimeSpan accessInterval)
            : base(parent)
        {
            if (statistic == null)
                throw new ArgumentNullException("statistic");

            if (accessInterval == TimeSpan.Zero)
                accessInterval = TimeSpan.FromMilliseconds(16);

            Strata = new ControlStrata() { Layer = Layer.Overlay };
            _tracker = new StatisticTracker(statistic, accessInterval);
            _graph = new Graph(Device, (int)(15f / (float)accessInterval.TotalSeconds)); //(byte)MathHelper.Clamp(15f / (float)accessInterval.TotalSeconds, 15, 15 * 60));
            _label = new Label(this, font) {
                Text = statistic.Name,
                Justification = Justification.Centre
            };
            _label.SetPoint(Points.TopLeft, 2, 2);
            _label.SetPoint(Points.TopRight, -2, 2);

            _value = new Label(this, font) {
                Text = "0",
                Justification = Justification.Centre
            };
            _value.SetPoint(Points.BottomLeft, 2, -2);
            _value.SetPoint(Points.BottomRight, -2, -2);

            _texture = new Texture2D(Device, 1, 1);
            _texture.SetData<Color>(new Color[] { new Color(0, 0, 0, 0.8f) });

            SetSize(200, 120);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextMultiButton"/> class.
        /// </summary>
        /// <param name="parent">This controls parent control.</param>
        /// <param name="font">The font.</param>
        /// <param name="options">The options.</param>
        /// <param name="focusScope">The focus scope.</param>
        public TextMultiButton(Control parent, SpriteFont font, string[] options)
            : base(parent)
        {
            if (options == null)
                throw new ArgumentNullException("options");
            if (options.Length == 0)
                throw new ArgumentException("There must be at least one option.", "options");

            this.Colour = Color.White;
            this.Highlight = Color.CornflowerBlue;
            this.options = options;
            this.OptionsCount = options.Length;

            this.leftArrow = new Label(this, font);
            this.leftArrow.Text = "<";
            this.leftArrow.SetPoint(Points.TopLeft, 0, 0);
            this.rightArrow = new Label(this, font);
            this.rightArrow.Text = ">";
            this.rightArrow.SetPoint(Points.TopRight, 0, 0);

            this.centreText = new Label(this, font);
            this.centreText.Justification = Justification.Centre;
            this.centreText.SetPoint(Points.TopLeft, leftArrow.Area.Width, 0);
            this.centreText.SetPoint(Points.TopRight, -rightArrow.Area.Width, 0);
            this.centreText.Text = options[0];

            ControlEventHandler recalcSize = delegate(Control c)
            {
                Vector2 maxSize = Vector2.Zero;
                for (int i = 0; i < options.Length; i++)
                {
                    var size = font.MeasureString(options[i]);
                    maxSize.X = Math.Max(maxSize.X, size.X);
                    maxSize.Y = Math.Max(maxSize.Y, size.Y);
                }
                arrowSize = (int)font.MeasureString("<").X;
                maxSize.X += arrowSize * 2;
                SetSize((int)maxSize.X, (int)maxSize.Y);
                leftArrow.SetSize(arrowSize, font.LineSpacing);
                rightArrow.SetSize(arrowSize, font.LineSpacing);
            };

            ControlEventHandler highlight = delegate(Control c)
            {
                (c as Label).Colour = (c.IsFocused || c.IsWarm) ? Highlight : Colour;
            };

            leftArrow.WarmChanged += highlight;
            rightArrow.WarmChanged += highlight;
            recalcSize(this);

            SelectionChanged += delegate(Control c)
            {
                centreText.Text = this[SelectedOption];
            };

            BindGestures();
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextButton"/> class.
        /// </summary>
        /// <param name="parent">This controls parent control.</param>
        /// <param name="font">The font to use to draw this buttons text value.</param>
        /// <param name="text">The text.</param>
        public TextButton(Control parent, SpriteFont font, string text)
            : base(parent)
        {
            if (text == null)
                throw new ArgumentNullException("text");

            Label = new Label(this, font);
            Justification = Justification.Centre;
            Label.Text = text;
            Colour = Color.White;
            Highlight = Color.CornflowerBlue;

            SetSize((int)Label.TextSize.X, (int)Label.TextSize.Y);
            Label.SetPoint(Points.TopLeft, Int2D.Zero);
            Label.SetPoint(Points.TopRight, Int2D.Zero);
        }
示例#4
0
        public TestScreen(string name, IKernel kernel)
        {
            Name = name;
            Game = kernel.Get<TestGame>();

            content = kernel.Get<ContentManager>();
            content.RootDirectory = "Content";

            UI = kernel.Get<UserInterface>();
            UI.Root.Gestures.Bind((gesture, time, device) => Manager.Pop(), new KeyReleased(Keys.Escape));

            actor = Game.Player;
            UI.Actors.Add(actor);

            var title = new Label(UI.Root, content.Load<SpriteFont>("Consolas"));
            title.Text = Name;
            title.Justification = Justification.Centre;
            title.SetPoint(Points.Top, Int2D.Zero);
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandConsole"/> class.
        /// </summary>
        /// <param name="font"></param>
        /// <param name="parent">The parent.</param>
        /// <param name="assemblies">The assemblies containing commands and options to add to this <see cref="CommandConsole"/> instance.</param>
        /// <param name="game"></param>
        public CommandConsole(Game game, SpriteFont font, Control parent, params Assembly[] assemblies)
            : base(parent)
        {
            _engine = new CommandEngine(assemblies);
            _writer = new ConsoleWriter(this);

            PresentationParameters pp = game.GraphicsDevice.PresentationParameters;
            SetSize(0, pp.BackBufferHeight / 3);
            SetPoint(Points.Top, 0, 5);
            SetPoint(Points.Left, 5, 0);
            SetPoint(Points.Right, -5, 0);
            Strata = new ControlStrata() { Layer = Layer.Overlay, Offset = 100 };
            FocusPriority = int.MaxValue;
            LikesHavingFocus = false;
            IsVisible = false;
            RespectSafeArea = true;
            ToggleKey = Keys.Oem8;

            //var font = Content.Load<SpriteFont>(game, "Consolas");
            //skin = Content.Load<Skin>(game, "Console");
            //skin.BackgroundColour = new Color(1f, 1f, 1f, 0.8f);
            _background = new Texture2D(game.GraphicsDevice, 1, 1);
            _background.SetData(new Color[] { Color.Black });

            _textBox = new TextBox(this, game, font, "Command Console", "Enter your command");
            _textBox.SetPoint(Points.Bottom, 0, -3);
            _textBox.SetPoint(Points.Left, 3, 0);
            _textBox.SetPoint(Points.Right, -3, 0);
            _textBox.FocusPriority = 1;
            _textBox.FocusedChanged += c => { if (c.IsFocused) _textBox.BeginTyping(PlayerIndex.One); };
            _textBox.IgnoredCharacters.Add('`');

            _log = new TextLog(this, font, (int)(3 * Area.Height / (float)font.LineSpacing));
            _log.SetPoint(Points.TopLeft, 3, 3);
            _log.SetPoint(Points.TopRight, -3, 3);
            _log.SetPoint(Points.Bottom, 0, 0, _textBox, Points.Top);
            _log.WriteLine("Hello world");

            _tabCompletion = new Label(this, font);
            _tabCompletion.SetSize(300, 0);
            _tabCompletion.SetPoint(Points.TopLeft, 3, 6, this, Points.BottomLeft);

            _infoBox = new Label(this, font);
            _infoBox.SetPoint(Points.TopRight, -3, 6, this, Points.BottomRight);

            AreaChanged += c => _infoBox.SetSize(Math.Max(0, c.Area.Width - 311), 0);

            _commandStack = new CommandStack(_textBox, Gestures);

            BindGestures();

            Gestures.BlockedDevices.Add(typeof(KeyboardDevice));
        }
示例#6
0
 public StatisticText(StatisticTextLog log, Statistic statistic, TimeSpan accessInterval, SpriteFont font)
     : base(statistic, accessInterval)
 {
     label = new Label(log, font);
     label.Text = statistic.Name + ": " + string.Format(statistic.Format, statistic.Value);
 }