private void onResize(Object sender, UISizeChangedEventArgs e) { // Update the position of the scrollbar. HPBar hpBar = getHPBar(); if (hpBar != null) { int hpBarHeight = hpBar.DrawBox.Height; int hpBarMargin = 3; int pictureBoxDimension = e.DrawBox.Height - hpBarHeight - 3 * hpBarMargin; hpBar.DrawBox = new Rectangle(hpBar.DrawBox.X, e.DrawBox.Height - hpBarHeight - hpBarMargin, e.DrawBox.Width - (2 * hpBar.DrawBox.X), hpBarHeight); // Get picturebox TestUIComponent pictureBox = null; foreach (XnaUIComponent component in GetChildren()) { if (component is TestUIComponent) { pictureBox = (TestUIComponent)component; break; } } if (pictureBox != null) { pictureBox.DrawBox = new Rectangle((e.DrawBox.Width - pictureBoxDimension) / 2, 3, pictureBoxDimension, pictureBoxDimension); } } }
public void CancelProgress() { if (started) { mapView.RemoveChild(dragBox); dragBox = null; } started = false; }
public void HandleMouseInput(bool leftButtonPressed, bool rightButtonPressed, Point mouseLocation) { if (started) { if (leftButtonPressed) { Rectangle newDragBox; newDragBox.X = Math.Min(mouseDownLocation.X, mouseLocation.X); newDragBox.Y = Math.Min(mouseDownLocation.Y, mouseLocation.Y); newDragBox.Width = Math.Abs(mouseDownLocation.X - mouseLocation.X); newDragBox.Height = Math.Abs(mouseDownLocation.Y - mouseLocation.Y); dragBox.DrawBox = newDragBox; } else { mapView.RemoveChild(dragBox); List<ModelComponent> selectedEntities = new List<ModelComponent>(); foreach (XnaUIComponent child in mapView.GetChildren()) { if (overlapsDragBox(child)) { if (child is UnitUI) { selectedEntities.Add(((UnitUI)child).Unit); } else if (child is BuildingUI) { selectedEntities.Add(((BuildingUI)child).Building); } } } ((XnaUITestGame)mapView.Game).Controller.SelectEntities(selectedEntities); started = false; } } else { if (leftButtonPressed) { started = true; dragBox = new TestUIComponent(mapView.Game, new Color(0, 125, 0, 0)); dragBox.DrawBox = new Rectangle(mouseLocation.X, mouseLocation.Y, 0, 0); mapView.AddChild(dragBox); mouseDownLocation = mouseLocation; } } }
public void HandleMouseInput(bool leftButtonPressed, bool rightButtonPressed, Point mouseLocation) { if (started) { if (leftButtonPressed) { Rectangle newDragBox; newDragBox.X = Math.Min(mouseDownLocation.X, mouseLocation.X); newDragBox.Y = Math.Min(mouseDownLocation.Y, mouseLocation.Y); newDragBox.Width = Math.Abs(mouseDownLocation.X - mouseLocation.X); newDragBox.Height = Math.Abs(mouseDownLocation.Y - mouseLocation.Y); dragBox.DrawBox = newDragBox; } else { mapView.RemoveChild(dragBox); List <ModelComponent> selectedEntities = new List <ModelComponent>(); foreach (XnaUIComponent child in mapView.GetChildren()) { if (overlapsDragBox(child)) { if (child is UnitUI) { selectedEntities.Add(((UnitUI)child).Unit); } else if (child is BuildingUI) { selectedEntities.Add(((BuildingUI)child).Building); } } } ((XnaUITestGame)mapView.Game).Controller.SelectEntities(selectedEntities); started = false; } } else { if (leftButtonPressed) { started = true; dragBox = new TestUIComponent(mapView.Game, new Color(0, 125, 0, 0)); dragBox.DrawBox = new Rectangle(mouseLocation.X, mouseLocation.Y, 0, 0); mapView.AddChild(dragBox); mouseDownLocation = mouseLocation; } } }