summaryrefslogtreecommitdiff
path: root/source/screens/TextTestScreen.cs
blob: 2e772df3e3fe375ef3afc5bbac63cc6a3f8ffc28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Diagnostics;
using Celesteia.Game.Input;
using Celesteia.Resources;
using Celesteia.UI;
using Celesteia.UI.Elements;
using Celesteia.UI.Properties;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.Screens;

namespace Celesteia.Screens {
    public class TextTestScreen : GameScreen {
        private new GameInstance Game => (GameInstance) base.Game;
        public TextTestScreen(GameInstance game) : base(game) {}

        private IContainer Root;

        private Label topLeft;
        //private Label topCenter;
        //private Label topRight;
        //private Label middleLeft;
        //private Label middle;
        //private Label middleRight;
        //private Label bottomLeft;
        //private Label bottom;
        private Label bottomRight;

        private TextProperties properties;
        private float _fontSize = 24f;

        public override void LoadContent()
        {
            base.LoadContent();

            Root = new Container(Rect.ScreenFull);

            properties = new TextProperties().SetColor(Color.White).SetFont(ResourceManager.Fonts.GetFontType("Hobo")).SetText("Hello, world!");

            topLeft = new Label(new Rect(AbsoluteUnit.WithValue(50), AbsoluteUnit.WithValue(50), AbsoluteUnit.WithValue(100), AbsoluteUnit.WithValue(100)));
            Root.AddChild(topLeft);
            bottomRight = new Label(new Rect(AbsoluteUnit.WithValue(50), AbsoluteUnit.WithValue(150), AbsoluteUnit.WithValue(100), AbsoluteUnit.WithValue(100)));
            Root.AddChild(bottomRight);
        }

        public override void Update(GameTime gameTime) {
            _fontSize += MouseHelper.ScrollDelta;
            _fontSize = Math.Clamp(_fontSize, 1f, 100f);

            topLeft.SetTextProperties(properties.Clone().SetTextAlignment(TextAlignment.Top | TextAlignment.Left).SetFontSize(_fontSize));
            bottomRight.SetTextProperties(properties.Clone().SetTextAlignment(TextAlignment.Bottom | TextAlignment.Right).SetFontSize(_fontSize));
        }

        public override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            Game.SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp);
            
            Root.Draw(Game.SpriteBatch);

            Game.SpriteBatch.End();
        }

        public override void Dispose()
        {
            Debug.WriteLine("Unloading TextTestScreen content...");
            base.UnloadContent();
            Debug.WriteLine("Disposing TextTestScreen...");
            base.Dispose();
        }
    }
}