Exemplo n.º 1
0
        public void Initialize()
        {
            ResourceManagerInitializer initializer = new ResourceManagerInitializer();

            data      = initializer.DataModel;
            resources = initializer.Manager;
            uiManager = (UserInterfaceResourceManager)resources.UserInterface;
        }
Exemplo n.º 2
0
        protected override void OnSceneStart()
        {
            var resources = new AgateResourceManager("ResourceTester.yaml");

            resources.InitializeContainer(this);

            sprite.StartAnimation();
        }
Exemplo n.º 3
0
        public void CreateGui()
        {
            resources = new AgateResourceManager("UserInterface/MenuScroll.yaml");
            facet     = new Facet();

            resources.InitializeContainer(facet);

            Input.Handlers.Add(facet.InterfaceRoot);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            using (new AgateWinForms(args)
                   .AssetPath("Assets")
                   .Initialize())
                using (new DisplayWindowBuilder(args)
                       .BackbufferSize(500, 400)
                       .Build())
                {
                    // Load the resource file and initialize the resource manager.
                    var resourceLoader  = new ResourceDataLoader();
                    var resourceManager = new AgateResourceManager(resourceLoader.Load("resources.yaml"));

                    // Create the object which will hold the UI.
                    var facet = new MyFacet();

                    resourceManager.InitializeContainer(facet);

                    // If the user hits escape or the B button on a game controller,
                    // exit the program.
                    facet.MainMenu.MenuCancel += (sender, e) => { AgateApp.IsAlive = false; };

                    // Attach a handler to each menu item if the user
                    // hits enter, the A button on a game controller, or
                    // clicks it with the mouse.
                    facet.StartItem.PressAccept += (sender, e) =>
                    {
                        facet.StartLabel.Text = "Thanks for starting the game!";
                    };

                    facet.QuitItem.PressAccept += (sender, e) =>
                    {
                        AgateApp.IsAlive = false;
                    };

                    // Install the user interface so that it captures input.
                    Input.Handlers.Add(facet.InterfaceRoot);

                    // Run the game loop
                    while (AgateApp.IsAlive)
                    {
                        // Update the UI outside a BeginFrame..EndFrame section.
                        facet.InterfaceRoot.OnUpdate(AgateApp.ApplicationClock.Elapsed, true);

                        Display.BeginFrame();
                        Display.Clear(Color.Gray);

                        // Draw the UI as the last thing before Display.EndFrame.
                        facet.InterfaceRoot.Draw();

                        Display.EndFrame();
                        AgateApp.KeepAlive();
                    }
                }
        }
Exemplo n.º 5
0
        private void btnLoadSprite_Click(object sender, EventArgs e)
        {
            if (openFile.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Sprite spTest   = null;
            string filename = openFile.FileName;

            try
            {
                spTest = new Sprite(filename,
                                    int.Parse(txtWidth.Text), int.Parse(txtHeight.Text));
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.GetType().Name);
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }

            if (spTest != null)
            {
                SetSprite(spTest);
            }
            else
            {
                // since loading the sprite from the file failed, try it as a resource file.
                AgateResourceManager resources = new AgateResourceManager(filename);

                AgateApp.Assets = new FileSystemProvider
                                      (System.IO.Path.GetDirectoryName(filename));

                if (resources.Sprites.ToArray().Length == 1)
                {
                    var sprites = resources.Sprites.ToArray();

                    Sprite sp = (Sprite)resources.Display.GetSprite(resources.Sprites.First());

                    SetSprite(sp);
                }
                else
                {
                    frmChooseSprite frm = new frmChooseSprite();

                    if (frm.ShowDialog(this, resources) == DialogResult.OK)
                    {
                        Sprite sp = (Sprite)resources.Display.GetSprite(frm.SelectedSprite);

                        SetSprite(sp);
                    }
                }
            }
        }
Exemplo n.º 6
0
        public DialogResult ShowDialog(IWin32Window owner, AgateResourceManager resources)
        {
            this.resources = resources;

            lstSprites.Items.Clear();

            foreach (var sprite in resources.Sprites)
            {
                lstSprites.Items.Add(sprite);
            }

            return(ShowDialog(owner));
        }
        public void CreateGui()
        {
            resources = new AgateResourceManager("UserInterface/NonWrappingLayout.yaml");
            facet     = new Facet();

            resources.UserInterface.InitializeFacet(facet);

            facet.menu_1.SelectedItemChanged += (sender, args) =>
            {
                var pt = facet.label_1.ClientToScreen(Point.Zero);

                facet.label_1.Text = $"Client Rect: {pt.X},{pt.Y},{facet.label_1.Width},{facet.label_1.Height}";
            };

            Input.Handlers.Add(facet.InterfaceRoot);
        }
Exemplo n.º 8
0
        public void Initialize()
        {
            var fakeFileProvider = new FakeReadFileProvider();

            fakeFileProvider.Add("resources.yaml", FacetSource);

            var resourceManager = new AgateResourceManager(
                new ResourceDataLoader(fakeFileProvider).Load("resources.yaml"));

            FacetName = resourceManager.Data.Facets.First().Key;

            resourceManager.InitializeContainer(this);

            Adapter = InterfaceRoot.Renderer.Adapter;

            InitializeTest();
        }
Exemplo n.º 9
0
        private void OnResourcesChanged()
        {
            if (resourceManager != null)
            {
                resourceManager.Dispose();
            }

            lstSprites.Items.Clear();

            if (resources != null)
            {
                resourceManager = new AgateResourceManager(resources);
            }
            else
            {
                lstSprites.Enabled = false;
                return;
            }

            lstSprites.Enabled = true;
            lstSprites.Items.AddRange(resourceManager.Sprites.ToArray());
        }
Exemplo n.º 10
0
        public void InitializeWindow(int width, int height)
        {
            string yaml = $@"
themes:
    default:
        window:
            box:
                padding: {WindowPadding}
                margin: {WindowMargin}
            border:
                size: {WindowBorder}
        panel:
            box:
                padding: {PanelPadding}
                margin: {PanelMargin}
            border:
                size: {PanelBorder}
        label:
            box:
                padding: {LabelPadding}
                margin: {LabelMargin}
            border:
                size: {LabelBorder}

facets:
    main: 
    -   name: window
        type: window
        position: {WindowPosition.X} {WindowPosition.Y}
        size: {width} {height}
        children:
        -   name: container_1
            type: panel
            children:
            -   name: label_1
                type: label
                text: hello
            -   name: label_2
                type: label
                text: hello, world
            -   name: label_3
                type: label
                text: hello your face
        -   name: container_2
            type: panel
            children:
            -   name: label_4
                type: label
                text: dogs are the best
            -   name: label_5
                type: label
                text: cats suck
";

            var fileProvider = new FakeReadFileProvider();

            fileProvider.Add("resources.yaml", yaml);

            var resourceDataModel = new ResourceDataLoader(fileProvider)
                                    .Load("resources.yaml");

            Resources = new AgateResourceManager(resourceDataModel);

            Facet = new TestFacet();
            Resources.UserInterface.InitializeFacet(Facet);

            LayoutEngine = Facet.InterfaceRoot.LayoutEngine;
            Adapter      = Facet.InterfaceRoot.Renderer.Adapter;

            LayoutEngine.UpdateLayout(Facet.InterfaceRoot);
        }
Exemplo n.º 11
0
        public void Run(string[] args)
        {
            using (var window = new DisplayWindowBuilder(args)
                                .BackbufferSize(800, 600)
                                .QuitOnClose()
                                .Build())
            {
                var resources = new AgateResourceManager("UserInterface/FontAlignment.yaml");
                resources.InitializeContainer(this);

                var fonts = new List <IFont> {
                    Font.AgateSans, Font.AgateSerif, Font.AgateMono,
                };

                Input.Unhandled.KeyDown += Keyboard_KeyDown;

                int[] numbers = new int[] { 0, 0, 1, 11, 22, 33, 44, 99, 100, 111, 222, 333, 444, 555, 666, 777, 888, 999 };

                while (AgateApp.IsAlive)
                {
                    IFont f = fonts[fontIndex];

                    Display.BeginFrame();
                    Display.Clear(Color.Black);

                    var firstLineFont   = fonts.First();
                    var firstLineHeight = firstLineFont.FontHeight;

                    Display.Primitives.FillRect(Color.DarkSlateGray, new Rectangle(0, firstLineHeight, 300, 600));
                    Display.Primitives.FillRect(Color.DarkBlue, new Rectangle(300, firstLineHeight, 300, 600));

                    firstLineFont.DisplayAlignment = OriginAlignment.TopLeft;
                    firstLineFont.Color            = Color.White;
                    firstLineFont.DrawText(0, 0, "Press space to cycle fonts.");

                    f.Color            = Color.White;
                    f.DisplayAlignment = OriginAlignment.TopLeft;
                    f.DrawText(0, firstLineHeight, "Left-aligned numbers");

                    for (int i = 1; i < numbers.Length; i++)
                    {
                        f.DrawText(0, firstLineHeight + i * f.FontHeight, numbers[i].ToString());
                    }

                    f.DisplayAlignment = OriginAlignment.TopRight;
                    f.DrawText(600, firstLineHeight, "Right-aligned numbers");

                    for (int i = 1; i < numbers.Length; i++)
                    {
                        f.DrawText(600.0, firstLineHeight + i * f.FontHeight, numbers[i].ToString());
                    }

                    Display.EndFrame();
                    AgateApp.KeepAlive();

                    if (fontIndex >= fonts.Count)
                    {
                        fontIndex = 0;
                    }
                }
            }
        }
Exemplo n.º 12
0
        public DialogResult ShowDialog(IWin32Window parent, AgateResourceManager resources)
        {
            this.resources = resources;

            return(ShowDialog(parent));
        }