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(); } } }
public ResourceFileDataSource(string resourceName) { _dataLoader = new ResourceDataLoader(); _resourceName = resourceName; }
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); }