Example #1
0
		public void DrawControlsAnchoredTogether()
		{
			var centerButton = new Button(ButtonDrawArea, "Click Me");
			var rnd = Randomizer.Current;
			centerButton.Clicked +=
				() => centerButton.TopLeft = new Vector2D(rnd.Get(0.3f, 0.6f), rnd.Get(0.3f, 0.6f));
			new Button(ButtonDrawArea) // button left of center button
			{
				RightMargin = new Margin(centerButton, Edge.Left, 0.01f),
				TopMargin = new Margin(centerButton, Edge.Top, 0.0f)
			};
			new Button(ButtonDrawArea) // button right of center button
			{
				LeftMargin = new Margin(centerButton, Edge.Right, 0.01f),
				TopMargin = new Margin(centerButton, Edge.Top, 0.0f)
			};
			new Button(ButtonDrawArea) // button above center button
			{
				BottomMargin = new Margin(centerButton, Edge.Top, 0.01f),
				LeftMargin = new Margin(centerButton, Edge.Left, 0.0f)
			};
			new Button(ButtonDrawArea) // button below center button
			{
				TopMargin = new Margin(centerButton, Edge.Bottom, 0.01f),
				LeftMargin = new Margin(centerButton, Edge.Left, 0.0f)
			};
			centerButton.Click();
		}
Example #2
0
		public void SetUp()
		{
			anchoring = new AnchoringState();
			control = new Button(new Rectangle(0.1f, 0.2f, 0.3f, 0.4f));
			landscapeControl = new Button(new Rectangle(0.0f, 0.0f, 0.6f, 0.5f));
			portraitControl = new Button(new Rectangle(0.0f, 0.0f, 0.4f, 0.5f));
		}
Example #3
0
		public void SetUp()
		{
			button = new Button(Center, "Click Me");
			InitializeMouse();
			InitializeTouch();
			AdvanceTimeAndUpdateEntities();
		}
Example #4
0
		public void ChangeToInteractiveButton(UIEditorScene uiEditorScene)
		{
			if (uiEditorScene == null)
				return; //ncrunch: no coverage 
			for (int i = 0; i < uiEditorScene.SelectedEntity2DList.Count; i++)
			{
				var selectedEntity2D = uiEditorScene.SelectedEntity2DList[i];
				if (selectedEntity2D == null ||
					(selectedEntity2D.GetType() != typeof(Button) &&
						selectedEntity2D.GetType() != typeof(InteractiveButton)))
					return;
				var index = uiEditorScene.Scene.Controls.IndexOf(selectedEntity2D);
				var selectedIndex = uiEditorScene.SelectedEntity2DList.IndexOf(selectedEntity2D);
				uiEditorScene.Scene.Remove(selectedEntity2D);
				uiEditorScene.SelectedEntity2DList.RemoveAt(i);
				var renderLayer = selectedEntity2D.RenderLayer;
				var anchorState = selectedEntity2D.Get<AnchoringState>();
				var controlName = (selectedEntity2D as Control).Name;
				if (IsInteractiveButton)
					selectedEntity2D = new InteractiveButton(selectedEntity2D.Get<Theme>(),
						selectedEntity2D.DrawArea, ((Button)selectedEntity2D).Text);
				else
					selectedEntity2D = new Button(selectedEntity2D.Get<Theme>(), selectedEntity2D.DrawArea,
						((Button)selectedEntity2D).Text);
				selectedEntity2D.RenderLayer = renderLayer;
				selectedEntity2D.Set(anchorState);
				(selectedEntity2D as Control).Name = controlName;
				uiEditorScene.Scene.Controls.Insert(index, selectedEntity2D);
				uiEditorScene.SelectedEntity2DList.Insert(selectedIndex, selectedEntity2D);
			}
		}
Example #5
0
 private void AddHowToPlay()
 {
     var howToButton = new Button(menuTheme,
         Rectangle.FromCenter(0.5f, ScreenSpace.Current.Top + 0.32f, 0.3f, 0.08f), "How To Play");
     howToButton.Clicked += ShowHowToPlaySubMenu;
     howToButton.RenderLayer = (int)AsteroidsRenderLayer.UserInterface;
     Add(howToButton);
 }
Example #6
0
 private void AddHighscores()
 {
     var highscoreButton = new Button(menuTheme,
         Rectangle.FromCenter(0.5f, ScreenSpace.Current.Top + 0.4f, 0.3f, 0.08f), "Highscores");
     highscoreButton.Clicked += ShowHighScoresSubMenu;
     highscoreButton.RenderLayer = (int)AsteroidsRenderLayer.UserInterface;
     Add(highscoreButton);
 }
Example #7
0
		public void CreateNewControlsWithIDNames()
		{
			var button1 = new Button(new Theme(), new Rectangle());
			Assert.AreEqual("Button1", button1.Name);
			var button2 = new Button(new Theme(), new Rectangle());
			Assert.AreEqual("Button2", button2.Name);
			var picture1 = new Picture(new Theme(), new Material(Color.Red, ShaderFlags.Position2DColored),
				new Rectangle());
			Assert.AreEqual("Picture1", picture1.Name);
		}
Example #8
0
		public void AddControlAfterRemovingOne()
		{
			var button1 = new Button(new Theme(), new Rectangle());
			Assert.AreEqual("Button1", button1.Name);
			var button2 = new Button(new Theme(), new Rectangle());
			Assert.AreEqual("Button2", button2.Name);
			button1.IsActive = false;
			var button3 = new Button(new Theme(), new Rectangle());
			Assert.AreEqual("Button1", button3.Name);
		}
Example #9
0
        private static string CreateMethodToButtonClickEventString(Button button)
        {
            string controlName = button.Name;
            var    methodsToButtonClickAssignmentString = "";

            methodsToButtonClickAssignmentString += "			var "+ controlName +
                                                    " = scene.Controls.FirstOrDefault(control => ((Control)control).Name == " + '"' +
                                                    controlName + '"' + ");\n";
            methodsToButtonClickAssignmentString += "			"+ controlName + ".Clicked = () => " +
                                                    controlName + "Clicked();\n";
            return(methodsToButtonClickAssignmentString);
        }
Example #10
0
		public void Test()
		{
			var centerButton = new Button(ButtonDrawArea, "Click Me");
			var rnd = Randomizer.Current;
			centerButton.Clicked +=
				() => centerButton.TopLeft = new Vector2D(rnd.Get(0.3f, 0.6f), rnd.Get(0.3f, 0.6f));
			new Button(ButtonDrawArea) // button above center button
			{
				BottomMargin = new Margin(centerButton, Edge.Top, 0.01f),
				RightMargin = new Margin(centerButton, Edge.Right, 0.05f)
			};
			centerButton.Click();
		}
		public void AchorControlsVerticalControls()
		{
			var controlList = createfilledControlList();
			controlList[0].DrawArea = new Rectangle(0, -1.5f, 1, 1);
			controlList[1].DrawArea = new Rectangle(0, -0.5f, 1, 1);
			controlList[2].DrawArea = new Rectangle(0, 1.5f, 1, 1);
			var anchoredControl = new Button(Rectangle.One);
			ControlAnchorer.AnchorSelectedControls(anchoredControl, controlList);
			Assert.AreEqual(new Vector2D(0, -1.5f), controlList[0].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(0, -0.5f), controlList[1].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(0, 1.5f), controlList[2].DrawArea.TopLeft);
			anchoredControl.DrawArea = new Rectangle(0, 0.5f, 1, 1);
			AdvanceTimeAndUpdateEntities();
			Assert.AreEqual(new Vector2D(0, -1), controlList[0].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(0, 0), controlList[1].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(0, 2f), controlList[2].DrawArea.TopLeft);
		}
		public void HorizontalControls()
		{
			var controlList = createfilledControlList();
			controlList[0].DrawArea = new Rectangle(-2.5f, 0, 1, 1);
			controlList[1].DrawArea = new Rectangle(-0.5f, 0, 1, 1);
			controlList[2].DrawArea = new Rectangle(2.5f, 0, 1, 1);
			var anchoredControl = new Button(Rectangle.One);
			ControlAnchorer.AnchorSelectedControls(anchoredControl, controlList);
			Assert.AreEqual(new Vector2D(-2.5f,0), controlList[0].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(-0.5f, 0), controlList[1].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(2.5f, 0), controlList[2].DrawArea.TopLeft);
			anchoredControl.DrawArea = new Rectangle(0.5f, 0, 1, 1);
			AdvanceTimeAndUpdateEntities();
			Assert.AreEqual(new Vector2D(-2, 0), controlList[0].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(0, 0), controlList[1].DrawArea.TopLeft);
			Assert.AreEqual(new Vector2D(3f, 0), controlList[2].DrawArea.TopLeft);
		}
Example #13
0
 public void AddControlToScene(Control control, UIEditorScene scene)
 {
     Control newControl = null;
     if (control.GetType() == typeof(Picture))
         newControl = new Picture(control.Get<Theme>(), control.Get<Material>(), control.DrawArea);
     else if (control.GetType() == typeof(Label))
     {
         newControl = new Label(control.Get<Theme>(), control.DrawArea, (control as Label).Text);
         newControl.Set(control.Get<Material>());
     }
     else if (control.GetType() == typeof(Button))
         newControl = new Button(control.Get<Theme>(), control.DrawArea, (control as Button).Text);
     else if (control.GetType() == typeof(Slider))
         newControl = new Slider(control.Get<Theme>(), control.DrawArea);
     newControl.AddTag(control.GetTags()[0]);
     newControl.RenderLayer = control.RenderLayer;
     scene.Scene.Add(newControl);
 }
Example #14
0
		public void AddButton(MenuButton code, float width, float ratio)
		{
			var material = new Material(ShaderFlags.Position2DTextured, code + "Button");
			var theme = new Theme
			{
				Button = material,
				ButtonMouseover =
					new Material(ShaderFlags.Position2DTextured, code + "Button")
					{
						DefaultColor = DefaultColors.HoverButton
					},
				ButtonPressed = material,
				Font = ContentLoader.Load<Font>("Verdana12"),
			};
			buttonTop += 0.1f;
			var button = new Button(theme, new Rectangle(0.4f, buttonTop, width, width / ratio));
			button.RenderLayer = 9000;
			button.IsVisible = false;
			button.Clicked += () => OnButtonClicked(code);
			Add(button);
		}
Example #15
0
		public void AddControlToScene(Control control)
		{
			Control newControl = null;
			if (control.GetType() == typeof(Picture))
				newControl = new Picture(control.Get<Theme>(), control.Get<Material>(), control.DrawArea);
			else if (control.GetType() == typeof(Label))
			{
				newControl = new Label(control.Get<Theme>(), control.DrawArea, (control as Label).Text);
				newControl.Set(control.Get<BlendMode>());
				newControl.Set(control.Get<Material>());
			}
			else if (control.GetType() == typeof(Button))
				newControl = new Button(control.Get<Theme>(), control.DrawArea, (control as Button).Text);
			else if (control.GetType() == typeof(InteractiveButton))
				newControl = new InteractiveButton(control.Get<Theme>(), control.DrawArea,
					(control as Button).Text);
			else if (control.GetType() == typeof(Slider))
				newControl = new Slider(control.Get<Theme>(), control.DrawArea);
			newControl.RenderLayer = control.RenderLayer;
			if (!newControl.Contains<AnchoringState>())
				newControl.Add(new AnchoringState()); //ncrunch: no coverage
			CheckIfAnyMaterialIsCorrupt(newControl);
			Scene.Add(newControl);
		}
Example #16
0
 public void RenderOneButtonEnablingAndDisablingAnother()
 {
     var button2 = new Button(Rectangle.FromCenter(0.5f, 0.3f, 0.2f, 0.1f));
     button2.Clicked += () => button.IsEnabled = !button.IsEnabled;
 }
Example #17
0
		private static Button AddNewButtonToList(Vector2D position, UIEditorScene uiEditorScene)
		{
			var newButton = new Button(new Theme(), Rectangle.FromCenter(position, new Size(0.2f, 0.1f)),
				"Default Button");
			uiEditorScene.Scene.Add(newButton);
			SetDefaultButtonName(newButton, uiEditorScene);
			return newButton;
		}
Example #18
0
		public void SetAndGetMargins()
		{
			var button = new Button(Rectangle.One)
			{
				LeftMargin = new Margin(Edge.Left, 1),
				RightMargin = new Margin(Edge.Right, 2),
				TopMargin = new Margin(Edge.Top, 3),
				BottomMargin = new Margin(Edge.Bottom, 4)
			};
			Assert.AreEqual(new Margin(Edge.Left, 1), button.LeftMargin);
			Assert.AreEqual(new Margin(Edge.Right, 2), button.RightMargin);
			Assert.AreEqual(new Margin(Edge.Top, 3), button.TopMargin);
			Assert.AreEqual(new Margin(Edge.Bottom, 4), button.BottomMargin);
		}
Example #19
0
		private static Stream SaveSceneWithAButton()
		{
			var scene = new Scene();
			var button = new Button(new Theme(), Rectangle.One, "Hello");
			button.RenderLayer = 5;
			scene.Controls.Add(button);
			var data = BinaryDataExtensions.SaveToMemoryStream(scene);
			data.Seek(0, SeekOrigin.Begin);
			return data;
		}
Example #20
0
		private void CreateNewButtons()
		{
			for (int i = 0; i < 5; i++)
			{
				var button = new Button(Rectangle.One, i.ToString());
				button.AddTag(i.ToString());
				button.RenderLayer = i;
				uiEditorScene.Scene.Add(button);
				uiEditorScene.UIImagesInList.Add(i.ToString());
			}
		}
Example #21
0
		public void AddControlToScene(Control control, Scene scene)
		{
			Control newControl = null;
			if (control.GetType() == typeof(Picture))
				newControl = new Picture((control as Picture).Theme, control.Material, control.DrawArea);
			else if (control.GetType() == typeof(Label))
			{
				newControl = new Label((control as Picture).Theme, control.DrawArea, (control as Label).Text);
				newControl.Set(control.Get<BlendMode>());
				newControl.Set(control.Material);
			}
			else if (control.GetType() == typeof(Button))
				newControl = new Button((control as Picture).Theme, control.DrawArea, (control as Button).Text);
			else if (control.GetType() == typeof(InteractiveButton))
				newControl = new InteractiveButton((control as Picture).Theme, control.DrawArea,
					(control as Button).Text);
			else if (control.GetType() == typeof(Slider))
				newControl = new Slider((control as Picture).Theme, control.DrawArea);
			newControl.Name = control.Name;
			if (newControl.Name == null && newControl.GetTags()[0] != null)
				newControl.Name = newControl.GetTags()[0];
			newControl.RenderLayer = control.RenderLayer;
			if (!control.Contains<AnchoringState>())
				newControl.Set(new AnchoringState()); //ncrunch: no coverage
			else
				newControl.Set(control.Get<AnchoringState>());
			scene.Add(newControl);
		}
		public void CreateBoundingBoxOfRoatatedControls()
		{
			uiEditor.Scene.Clear();
			var control = new Button(new Rectangle(0.0f, 0.0f, 0.4f, 0.2f));
			control.Rotation = 45;
			uiEditor.Scene.Controls.Add(control);
			uiEditor.Scene.Controls.Add(new Button(new Rectangle(0.8f, 0.8f, 0.2f, 0.2f)));
			uiEditor.SelectedEntity2DList.Clear();
			uiEditor.SelectedEntity2DList.Add(uiEditor.Scene.Controls[0]);
			uiEditor.SelectedEntity2DList.Add(uiEditor.Scene.Controls[1]);
			Rectangle rect =
				uiEditor.UiEditorScene.controlTransformer.CalculateBoundingBox(uiEditor.SelectedEntity2DList);
			Assert.AreNotEqual(rect.Center, Vector2D.Half);
		}
Example #23
0
		private void CreateIcons()
		{
			for (int index = 0; index < NumberOfItems; index++)
			{
				icons[index] = new Button(GetIconTheme((ItemType)index),
					Rectangle.FromCenter(0.39f + index * 0.08f, ScreenSpace.Current.Top + 0.04f, 0.07f, 0.08f));
				int itemIndex = index;
				icons[index].Clicked += () => SelectItemIfSufficientFunds(itemIndex);
				icons[index].RenderLayer = (int)RenderLayers.Icons;
				Add(icons[index]);
			}
		}
Example #24
0
 private void AddStartButton()
 {
     var startButton = new Button(menuTheme,
         Rectangle.FromCenter(0.5f, ScreenSpace.Current.Top + 0.24f, 0.3f, 0.08f), "Start Game");
     startButton.Clicked += TryInvokeGameStart;
     startButton.RenderLayer = (int)AsteroidsRenderLayer.UserInterface;
     Add(startButton);
 }
Example #25
0
 private void AddBackButton()
 {
     var backButton = new Button(menuTheme,
         Rectangle.FromCenter(0.5f, ScreenSpace.Current.Bottom - 0.1f, 0.3f, 0.08f), "Back");
     backButton.RenderLayer = renderLayer + 1;
     backButton.Clicked += () =>
     {
         Hide();
         parent.Show();
     };
     Add(backButton);
 }
Example #26
0
 private void ChangeToInteractiveButton()
 {
     if (SelectedEntity2D == null || uiEditorScene == null ||
         (SelectedEntity2D.GetType() != typeof(Button) &&
             SelectedEntity2D.GetType() != typeof(InteractiveButton)))
         return;
     uiEditorScene.Scene.Remove(SelectedEntity2D);
     var renderLayer = SelectedEntity2D.RenderLayer;
     var controlName = SelectedEntity2D.GetTags()[0];
     if (isInteractiveButton)
         SelectedEntity2D = new InteractiveButton(SelectedEntity2D.Get<Theme>(),
             SelectedEntity2D.DrawArea, ((Button)SelectedEntity2D).Text);
     else
         SelectedEntity2D = new Button(SelectedEntity2D.Get<Theme>(), SelectedEntity2D.DrawArea,
             ((Button)SelectedEntity2D).Text);
     SelectedEntity2D.RenderLayer = renderLayer;
     SelectedEntity2D.AddTag(controlName);
     uiEditorScene.Scene.Add(SelectedEntity2D);
 }
Example #27
0
 private void AddQuitButton()
 {
     var quitButton = new Button(menuTheme,
         Rectangle.FromCenter(0.5f, ScreenSpace.Current.Top + 0.48f, 0.3f, 0.08f), "Quit Game");
     quitButton.Clicked += TryInvokeQuit;
     quitButton.RenderLayer = (int)AsteroidsRenderLayer.UserInterface;
     Add(quitButton);
 }
Example #28
0
		public void ClickingFullscreenIconShouldNotCreateInputEvents()
		{
			var button = new Button(Rectangle.One);
			button.Start<ReportMouseState>();
		}
Example #29
0
 private static void ChangeButton(Button button, UIControl uiControl)
 {
     button.Size = new Size(uiControl.EntityWidth, uiControl.EntityHeight);
     button.Text = uiControl.contentText;
 }
Example #30
0
		private static string CreateMethodToButtonClickEventString(Button button)
		{
			string controlName = button.Name;
			var methodsToButtonClickAssignmentString = "";
			methodsToButtonClickAssignmentString += "			var " + controlName +
				" = scene.Controls.FirstOrDefault(control => ((Control)control).Name == " + '"' +
				controlName + '"' + ");\n";
			methodsToButtonClickAssignmentString += "			" + controlName + ".Clicked = () => " +
				controlName + "Clicked();\n";
			return methodsToButtonClickAssignmentString;
		}
Example #31
0
		private static void SetDefaultButtonName(Button newButton, UIEditorScene uiEditorScene)
		{
			uiEditorScene.UIImagesInList.Add(newButton.Name);
			if (uiEditorScene.UIImagesInList[0] == null)
				uiEditorScene.UIImagesInList[0] = newButton.Name;
		}