public override void Update(GameTime gameTime)
        {
            MouseState mouseState = Mouse.GetState();
            Point mousePoint = new Point(mouseState.X, mouseState.Y);
            XnaUIComponent currentUIOn = GetTarget(mousePoint);

            // Fire all events for mouse down, mouse up, and clicks
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                if (leftMouseDownTarget == null)
                {
                    leftMouseDownTarget = GetTarget(mousePoint);
                    XnaMouseEventArgs e = new XnaMouseEventArgs();
                    e.Target = leftMouseDownTarget;
                    e.ClickLocation = mousePoint;
                    e.Handled = false;
                    e.Bubbled = false;
                    e.ButtonPressed = MouseButton.Left;
                    e.SingleTarget = true;
                    e.time = System.Environment.TickCount;
                    frame.MouseDown(e);
                }
            }
            else
            {
                if (leftMouseDownTarget != null)
                {
                    XnaUIComponent leftMouseUpTarget = currentUIOn;
                    XnaUIComponent commonAncestor = getCommonAncestor(leftMouseDownTarget, leftMouseUpTarget);
                    if (commonAncestor != null)
                    {
                        XnaMouseEventArgs mouseUpEventArgs = new XnaMouseEventArgs();
                        mouseUpEventArgs.Target = commonAncestor;
                        mouseUpEventArgs.ClickLocation = mousePoint;
                        mouseUpEventArgs.Handled = false;
                        mouseUpEventArgs.Bubbled = false;
                        mouseUpEventArgs.ButtonPressed = MouseButton.Left;
                        mouseUpEventArgs.SingleTarget = (leftMouseDownTarget == leftMouseUpTarget);
                        mouseUpEventArgs.time = System.Environment.TickCount;
                        frame.MouseUp(mouseUpEventArgs);

                        XnaMouseEventArgs e = new XnaMouseEventArgs();
                        e.Target = commonAncestor;
                        e.ClickLocation = mousePoint;
                        e.Handled = false;
                        e.Bubbled = false;
                        e.ButtonPressed = MouseButton.Left;
                        e.SingleTarget = (leftMouseDownTarget == leftMouseUpTarget);
                        e.time = System.Environment.TickCount;
                        frame.Click(e);
                    }
                    // Reset the state.
                    leftMouseDownTarget = null;
                }
            }

            if (mouseState.RightButton == ButtonState.Pressed)
            {
                if (rightMouseDownTarget == null)
                {
                    rightMouseDownTarget = currentUIOn;
                    XnaMouseEventArgs e = new XnaMouseEventArgs();
                    e.Target = rightMouseDownTarget;
                    e.ClickLocation = mousePoint;
                    e.Handled = false;
                    e.Bubbled = false;
                    e.ButtonPressed = MouseButton.Right;
                    e.SingleTarget = true;
                    e.time = System.Environment.TickCount;
                    frame.MouseDown(e);
                }
            }
            else
            {
                if (rightMouseDownTarget != null)
                {
                    XnaUIComponent rightMouseUpTarget = GetTarget(mousePoint);
                    XnaUIComponent commonAncestor = getCommonAncestor(rightMouseDownTarget, rightMouseUpTarget);

                    if (commonAncestor != null)
                    {
                        XnaMouseEventArgs mouseUpEventArgs = new XnaMouseEventArgs();
                        mouseUpEventArgs.Target = commonAncestor;
                        mouseUpEventArgs.ClickLocation = mousePoint;
                        mouseUpEventArgs.Handled = false;
                        mouseUpEventArgs.Bubbled = false;
                        mouseUpEventArgs.ButtonPressed = MouseButton.Left;
                        mouseUpEventArgs.SingleTarget = (rightMouseDownTarget == rightMouseUpTarget);
                        mouseUpEventArgs.time = System.Environment.TickCount;
                        frame.MouseUp(mouseUpEventArgs);

                        XnaMouseEventArgs e = new XnaMouseEventArgs();
                        e.Target = commonAncestor;
                        e.ClickLocation = mousePoint;
                        e.Handled = false;
                        e.Bubbled = false;
                        e.ButtonPressed = MouseButton.Right;
                        e.SingleTarget = (rightMouseDownTarget == rightMouseUpTarget);
                        e.time = System.Environment.TickCount;
                        frame.Click(e);
                    }
                    // Reset the state.
                    rightMouseDownTarget = null;
                }
            }

            // Handle mouse enter and exit events.
            if (mouseHoverTarget != currentUIOn)
            {
                // Base case : First time entering.
                if (mouseHoverTarget == null)
                {
                    XnaUIComponent current = currentUIOn;
                    Stack<XnaUIComponent> stack = new Stack<XnaUIComponent>();
                    while (current != null)
                    {
                        stack.Push(current);
                        current = current.Parent;
                    }
                    while (stack.Count > 0)
                    {
                        current = stack.Pop();
                        current.MouseEnter();
                    }
                }
                else
                {
                    // Mouse has moved
                    XnaUIComponent current = mouseHoverTarget;
                    XnaUIComponent ancestor = getCommonAncestor(currentUIOn, mouseHoverTarget);
                    while (current != ancestor)
                    {
                        current.MouseLeave();
                        current = current.Parent;
                    }
                    current = currentUIOn;
                    Stack<XnaUIComponent> stack = new Stack<XnaUIComponent>();
                    while (current != ancestor)
                    {
                        stack.Push(current);
                        current = current.Parent;
                    }
                    while (stack.Count > 0)
                    {
                        current = stack.Pop();
                        current.MouseEnter();
                    }
                }
                mouseHoverTarget = currentUIOn;
            }
            base.Update(gameTime);
        }
        internal void MouseUp(XnaMouseEventArgs e)
        {
            if (!e.Handled)
            {
                if (OnMouseUp != null)
                {
                    OnMouseUp(this, e);
                }
                if (e.Target != this)
                {
                    XnaUIComponent nextTarget = e.Target;
                    while (nextTarget.Parent != this)
                    {
                        nextTarget = nextTarget.Parent;
                    }
                    Point currentPoint = e.ClickLocation;
                    Point offsetPoint = new Point(currentPoint.X, currentPoint.Y);
                    offsetPoint.X -= ScrollX;
                    offsetPoint.X -= nextTarget.drawBox.X;
                    offsetPoint.Y -= ScrollY;
                    offsetPoint.Y -= nextTarget.drawBox.Y;
                    e.ClickLocation = offsetPoint;
                    nextTarget.MouseUp(e);

                    // Repair event
                    e.ClickLocation = currentPoint;
                }
                e.Bubbled = true;
                if (!e.Handled && (OnMouseUp != null))
                {
                    OnMouseUp(this, e);
                }
            }
        }
 public void handleClick(object sender, XnaMouseEventArgs agrs)
 {
     ((XnaUITestGame)Game).Controller.TellSelectedBuildingToBuild();
 }
 private void getAttacked(Object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled && e.ButtonPressed == MouseButton.Right)
     {
         ((XnaUITestGame)Game).Controller.TellSelectedUnitsToAttack(building);
         e.Handled = true;
     }
 }
 /// <summary>
 /// Trigger function in the event of selected unit is told to harvest
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tellSelectedUnitsToHarvestAt(object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled && e.ButtonPressed == MouseButton.Right)
     {
         PointF gamePoint = new PointF((float)(e.ClickLocation.X + ScrollX) / (float)cellDimension, (float)(e.ClickLocation.Y + ScrollY) / (float)cellDimension);
         ((XnaUITestGame)Game).Controller.TellSelectedUnitsToHarvest(gamePoint);
         e.Handled = true;
     }
 }
 private void selectUnit(Object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled)
     {
         List<ModelComponent> entities = new List<ModelComponent>();
         entities.Add(unit);
         ((XnaUITestGame)Game).Controller.SelectEntities(entities);
         e.Handled = true;
     }
 }
 private void placeBuilding(Object sender, XnaMouseEventArgs e)
 {
     if (building.Tint.Equals(new Color(0, 125, 0, 0)))
     {
         mapView.RemoveChild(building);
         building.OnClick -= placeBuilding;
         Point drawPoint = new Point();
         drawPoint.X = building.DrawBox.X / MapView.CellDimension;
         drawPoint.Y = building.DrawBox.Y / MapView.CellDimension;
         ((XnaUITestGame)mapView.Game).Controller.TellSelectedUnitsToBuildAt(buildingType, drawPoint);
         changeLeftClickStrategy();
     }
 }
 /// <summary>
 /// Trigger action when stop button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void handleStopButtonClick(object sender, XnaMouseEventArgs e)
 {
     //System.Console.Out.WriteLine("STOP BUTTON IS CLICKED!");
     if (e.Bubbled && !e.Handled)
     {
         e.Handled = true;
         ((XnaUITestGame)Game).Controller.OnSelectUnitToStop();
     }
 }
 /// <summary>
 /// Event/Trigger funciton when unit produce button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void handleUnitProduceButtonClick(object sender, XnaMouseEventArgs e)
 {
     if (Math.Abs(e.time) - lastClick > MSECONDS_PER_CLICK)
     {
         ((XnaUITestGame)Game).Controller.TellSelectedBuildingToBuild();
         e.Handled = true;
         lastClick = e.time;
     }
 }
 /// <summary>
 /// Event/Trigger function when buildingbutton is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void handleBuildingButtonClick(Object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled)
     {
         string buildingType = uiToBuildingType[sender] as string;
         ((XnaUITestGame)Game).Controller.OnSelectBuildingToBuild(buildingType);
         workerPanel.Visible = true;
         buildPanel.Visible = false;
         e.Handled = true;
     }
 }
 /// <summary>
 /// Trigger move command when move button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void handleMoveButtonClick(object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled)
     {
         //System.Console.Out.WriteLine("Move button is clicked!");
         e.Handled = true;
     }
 }
 private void handleBuildButtonClick(Object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled)
     {
         mainPanel.Visible = false;
         workerPanel.Visible = false;
         buildPanel.Visible = true;
         e.Handled = true;
     }
 }
 /// <summary>
 /// Trigger action when stop button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void handleStopButtonClick(object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled)
     {
         e.Handled = true;
         ((XnaUITestGame)Game).Controller.OnSelectUnitToStop();
     }
 }
 /// <summary>
 /// Trigger move command when move button is clicked
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void handleMoveButtonClick(object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled)
     {
         e.Handled = true;
     }
 }
 // Harvest Button
 private void handleHarvestButtonClick(object sender, XnaMouseEventArgs e)
 {
     if (e.Bubbled && !e.Handled)
     {
         e.Handled = true;
         // TODO: Change this to reflect the mouseclick location where the unit needs to move and harvest
         ((XnaUITestGame)Game).Controller.OnSelectedUnitsToHarvest();
     }
 }
        public override void Update(GameTime gameTime)
        {
            MouseState     mouseState  = Mouse.GetState();
            Point          mousePoint  = new Point(mouseState.X, mouseState.Y);
            XnaUIComponent currentUIOn = GetTarget(mousePoint);

            // Fire all events for mouse down, mouse up, and clicks
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                if (leftMouseDownTarget == null)
                {
                    leftMouseDownTarget = GetTarget(mousePoint);
                    XnaMouseEventArgs e = new XnaMouseEventArgs();
                    e.Target        = leftMouseDownTarget;
                    e.ClickLocation = mousePoint;
                    e.Handled       = false;
                    e.Bubbled       = false;
                    e.ButtonPressed = MouseButton.Left;
                    e.SingleTarget  = true;
                    e.time          = System.Environment.TickCount;
                    frame.MouseDown(e);
                }
            }
            else
            {
                if (leftMouseDownTarget != null)
                {
                    XnaUIComponent leftMouseUpTarget = currentUIOn;
                    XnaUIComponent commonAncestor    = getCommonAncestor(leftMouseDownTarget, leftMouseUpTarget);
                    if (commonAncestor != null)
                    {
                        XnaMouseEventArgs mouseUpEventArgs = new XnaMouseEventArgs();
                        mouseUpEventArgs.Target        = commonAncestor;
                        mouseUpEventArgs.ClickLocation = mousePoint;
                        mouseUpEventArgs.Handled       = false;
                        mouseUpEventArgs.Bubbled       = false;
                        mouseUpEventArgs.ButtonPressed = MouseButton.Left;
                        mouseUpEventArgs.SingleTarget  = (leftMouseDownTarget == leftMouseUpTarget);
                        mouseUpEventArgs.time          = System.Environment.TickCount;
                        frame.MouseUp(mouseUpEventArgs);

                        XnaMouseEventArgs e = new XnaMouseEventArgs();
                        e.Target        = commonAncestor;
                        e.ClickLocation = mousePoint;
                        e.Handled       = false;
                        e.Bubbled       = false;
                        e.ButtonPressed = MouseButton.Left;
                        e.SingleTarget  = (leftMouseDownTarget == leftMouseUpTarget);
                        e.time          = System.Environment.TickCount;
                        frame.Click(e);
                    }
                    // Reset the state.
                    leftMouseDownTarget = null;
                }
            }

            if (mouseState.RightButton == ButtonState.Pressed)
            {
                if (rightMouseDownTarget == null)
                {
                    rightMouseDownTarget = currentUIOn;
                    XnaMouseEventArgs e = new XnaMouseEventArgs();
                    e.Target        = rightMouseDownTarget;
                    e.ClickLocation = mousePoint;
                    e.Handled       = false;
                    e.Bubbled       = false;
                    e.ButtonPressed = MouseButton.Right;
                    e.SingleTarget  = true;
                    e.time          = System.Environment.TickCount;
                    frame.MouseDown(e);
                }
            }
            else
            {
                if (rightMouseDownTarget != null)
                {
                    XnaUIComponent rightMouseUpTarget = GetTarget(mousePoint);
                    XnaUIComponent commonAncestor     = getCommonAncestor(rightMouseDownTarget, rightMouseUpTarget);

                    if (commonAncestor != null)
                    {
                        XnaMouseEventArgs mouseUpEventArgs = new XnaMouseEventArgs();
                        mouseUpEventArgs.Target        = commonAncestor;
                        mouseUpEventArgs.ClickLocation = mousePoint;
                        mouseUpEventArgs.Handled       = false;
                        mouseUpEventArgs.Bubbled       = false;
                        mouseUpEventArgs.ButtonPressed = MouseButton.Left;
                        mouseUpEventArgs.SingleTarget  = (rightMouseDownTarget == rightMouseUpTarget);
                        mouseUpEventArgs.time          = System.Environment.TickCount;
                        frame.MouseUp(mouseUpEventArgs);

                        XnaMouseEventArgs e = new XnaMouseEventArgs();
                        e.Target        = commonAncestor;
                        e.ClickLocation = mousePoint;
                        e.Handled       = false;
                        e.Bubbled       = false;
                        e.ButtonPressed = MouseButton.Right;
                        e.SingleTarget  = (rightMouseDownTarget == rightMouseUpTarget);
                        e.time          = System.Environment.TickCount;
                        frame.Click(e);
                    }
                    // Reset the state.
                    rightMouseDownTarget = null;
                }
            }

            // Handle mouse enter and exit events.
            if (mouseHoverTarget != currentUIOn)
            {
                // Base case : First time entering.
                if (mouseHoverTarget == null)
                {
                    XnaUIComponent         current = currentUIOn;
                    Stack <XnaUIComponent> stack   = new Stack <XnaUIComponent>();
                    while (current != null)
                    {
                        stack.Push(current);
                        current = current.Parent;
                    }
                    while (stack.Count > 0)
                    {
                        current = stack.Pop();
                        current.MouseEnter();
                    }
                }
                else
                {
                    // Mouse has moved
                    XnaUIComponent current  = mouseHoverTarget;
                    XnaUIComponent ancestor = getCommonAncestor(currentUIOn, mouseHoverTarget);
                    while (current != ancestor)
                    {
                        current.MouseLeave();
                        current = current.Parent;
                    }
                    current = currentUIOn;
                    Stack <XnaUIComponent> stack = new Stack <XnaUIComponent>();
                    while (current != ancestor)
                    {
                        stack.Push(current);
                        current = current.Parent;
                    }
                    while (stack.Count > 0)
                    {
                        current = stack.Pop();
                        current.MouseEnter();
                    }
                }
                mouseHoverTarget = currentUIOn;
            }
            base.Update(gameTime);
        }