public void HandleMouseInput(bool leftButtonPressed, bool rightButtonPressed, Point mouseLocation)
        {
            // We are hovering over the map.  Update its location.
            Point drawPoint = new Point();

            // The draw point should be on a grid line intersection, and should not be outside the bounds of the map.
            drawPoint.X = Math.Max(0, mouseLocation.X - (mouseLocation.X % MapView.CellDimension));
            drawPoint.X = Math.Min(drawPoint.X, ((XnaUITestGame)mapView.Game).Model.GetScenario().GetGameWorld().GetMap().GetWidth() * MapView.CellDimension - building.DrawBox.Width);

            drawPoint.Y = Math.Max(0, mouseLocation.Y - (mouseLocation.Y % MapView.CellDimension));
            drawPoint.Y = Math.Min(drawPoint.Y, ((XnaUITestGame)mapView.Game).Model.GetScenario().GetGameWorld().GetMap().GetHeight() * MapView.CellDimension - building.DrawBox.Height);

            building.DrawBox = new Rectangle(drawPoint.X, drawPoint.Y, building.DrawBox.Width, building.DrawBox.Height);
            if (!added)
            {
                mapView.AddChild(building);
                added = true;
            }

            // Check if the cells are taken.  If so, tint the drawing red, otherwise tint it green.
            // BUG: This only checks the upper left cell - we have to check all the cells.
            if (((XnaUITestGame)mapView.Game).Controller.CellsAreEmpty(building.DrawBox.X / MapView.CellDimension, building.DrawBox.Y / MapView.CellDimension, building.DrawBox.Width / MapView.CellDimension, building.DrawBox.Height / MapView.CellDimension))
            {
                building.Tint = new Color(0, 125, 0, 0);
            }
            else
            {
                building.Tint = new Color(125, 0, 0, 0);
            }
        }
 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;
         }
     }
 }