public bool PerformRMBAction(MouseEventArgs e)
        {
            int      closestIconDistanceSquared = int.MaxValue;
            JHU_Icon closestIcon = null;
            DrawArgs drawArgs    = JHU_Globals.getInstance().WorldWindow.DrawArgs;

            foreach (RenderableObject ro in m_children)
            {
                // If renderable object can handle the selection
                if (!ro.IsOn)
                {
                    continue;
                }
                if (!ro.isSelectable)
                {
                    continue;
                }

                JHU_Icon icon = ro as JHU_Icon;

                // if its a JHU_Icon check to see if we're on top
                if (icon != null)
                {
                    // don't check if we aren't even in view
                    if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
                    {
                        // check if inside current icon's selection rectangle
                        Vector3 projectedPoint = drawArgs.WorldCamera.Project(icon.Position);

                        int dx = e.X - (int)projectedPoint.X;
                        int dy = e.Y - (int)projectedPoint.Y;

                        if (icon.SelectionRectangle.Contains(dx, dy))
                        {
                            // Mouse is over, check whether this icon is closest
                            int distanceSquared = dx * dx + dy * dy;
                            if (distanceSquared < closestIconDistanceSquared)
                            {
                                closestIconDistanceSquared = distanceSquared;
                                closestIcon = icon;
                            }
                        }
                    }
                }
            }

            // if no other object has handled the selection let the closest icon try
            if (closestIcon != null)
            {
                if (closestIcon.PerformRMBAction(e))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
		/// <summary>
		/// Adds an icon to this layer. Deprecated.
		/// </summary>
		public void AddIcon(JHU_Icon icon)
		{
			this.Add(icon);
		}
Exemple #3
0
		public override void Render(DrawArgs drawArgs)
		{
			if(!isOn)
				return;

			if(!isInitialized)
				this.Initialize(drawArgs);

			if(m_needToInitChildren)
				this.InitializeChildren(drawArgs);

			int closestIconDistanceSquared = int.MaxValue;
			JHU_Icon closestIcon = null;

			// Begin sprite rendering
			try
			{
				m_sprite.Begin(SpriteFlags.AlphaBlend);

				if (m_mouseOver)
				{
					// For each ro
					foreach(RenderableObject ro in m_children)
					{
						if(!ro.IsOn)
							continue;

						// most objects should be icons
						JHU_Icon icon = ro as JHU_Icon;

						// if its not an icon call its render
						if(icon==null)
						{
							ro.Render(drawArgs);
						}
							// else its an icon - render here to batch up the sprite renders
						else
						{
							// don't bother if we aren't even in view
							if(drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
							{

                                Vector3 translationVector = new Vector3(
                                (float)(icon.Position.X - drawArgs.WorldCamera.ReferenceCenter.X),
                                (float)(icon.Position.Y - drawArgs.WorldCamera.ReferenceCenter.Y),
                                (float)(icon.Position.Z - drawArgs.WorldCamera.ReferenceCenter.Z));

								// check if inside current icon's selection rectangle
                                Vector3 projectedPoint = drawArgs.WorldCamera.Project(translationVector);

								int dx = DrawArgs.LastMousePosition.X - (int)projectedPoint.X;
								int dy = DrawArgs.LastMousePosition.Y - (int)projectedPoint.Y;

								if( icon.SelectionRectangle.Contains( dx, dy ) )
								{
									// Mouse is over, check whether this icon is closest
									int distanceSquared = dx*dx + dy*dy;
									if(distanceSquared < closestIconDistanceSquared)
									{
										closestIconDistanceSquared = distanceSquared;
										closestIcon = icon;
									}
								}

								// render the icon if it wasn't the last mouseover
								if(icon != mouseOverIcon)
									icon.FastRender(drawArgs, m_sprite, projectedPoint);
							}

							// Update here or it doesn't update when the icon is out of view
							icon.UpdateHookForm();
						}
					}

					// Render the mouse over icon last (on top)
					if(mouseOverIcon != null)
					{
						mouseOverIcon.MouseOverRender(drawArgs, m_sprite, drawArgs.WorldCamera.Project(mouseOverIcon.Position));
					}

					// set new mouseover icon
					mouseOverIcon = closestIcon;
				}
				else
				{
					// For each ro
					foreach(RenderableObject ro in m_children)
					{
						if(!ro.IsOn)
							continue;

						// most objects should be icons
						JHU_Icon icon = ro as JHU_Icon;

						// if its not an icon call its render
						if(icon==null)
						{
							ro.Render(drawArgs);
						}
							// else its an icon - render here to batch up the sprite renders
						else
						{
							// don't bother if we aren't even in view
							if(drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
							{
								icon.FastRender(drawArgs, m_sprite, drawArgs.WorldCamera.Project(icon.Position));
							}

							// Update here or it doesn't update when the icon is out of view
							icon.UpdateHookForm();
						}
					}
				}
			}
			catch(Exception ex)
			{
				System.Console.WriteLine(ex.Message.ToString());			
			}
			finally
			{
				m_sprite.End();
			}
		}
 /// <summary>
 /// Adds an icon to this layer. Deprecated.
 /// </summary>
 public void AddIcon(JHU_Icon icon)
 {
     this.Add(icon);
 }
        public override void Render(DrawArgs drawArgs)
        {
            if (!isOn)
            {
                return;
            }

            if (!isInitialized)
            {
                this.Initialize(drawArgs);
            }

            if (m_needToInitChildren)
            {
                this.InitializeChildren(drawArgs);
            }

            int      closestIconDistanceSquared = int.MaxValue;
            JHU_Icon closestIcon = null;

            // Begin sprite rendering
            try
            {
                m_sprite.Begin(SpriteFlags.AlphaBlend);

                if (m_mouseOver)
                {
                    // For each ro
                    foreach (RenderableObject ro in m_children)
                    {
                        if (!ro.IsOn)
                        {
                            continue;
                        }

                        // most objects should be icons
                        JHU_Icon icon = ro as JHU_Icon;

                        // if its not an icon call its render
                        if (icon == null)
                        {
                            ro.Render(drawArgs);
                        }
                        // else its an icon - render here to batch up the sprite renders
                        else
                        {
                            // don't bother if we aren't even in view
                            if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
                            {
                                Vector3 translationVector = new Vector3(
                                    (float)(icon.Position.X - drawArgs.WorldCamera.ReferenceCenter.X),
                                    (float)(icon.Position.Y - drawArgs.WorldCamera.ReferenceCenter.Y),
                                    (float)(icon.Position.Z - drawArgs.WorldCamera.ReferenceCenter.Z));

                                // check if inside current icon's selection rectangle
                                Vector3 projectedPoint = drawArgs.WorldCamera.Project(translationVector);

                                int dx = DrawArgs.LastMousePosition.X - (int)projectedPoint.X;
                                int dy = DrawArgs.LastMousePosition.Y - (int)projectedPoint.Y;

                                if (icon.SelectionRectangle.Contains(dx, dy))
                                {
                                    // Mouse is over, check whether this icon is closest
                                    int distanceSquared = dx * dx + dy * dy;
                                    if (distanceSquared < closestIconDistanceSquared)
                                    {
                                        closestIconDistanceSquared = distanceSquared;
                                        closestIcon = icon;
                                    }
                                }

                                // render the icon if it wasn't the last mouseover
                                if (icon != mouseOverIcon)
                                {
                                    icon.FastRender(drawArgs, m_sprite, projectedPoint);
                                }
                            }

                            // Update here or it doesn't update when the icon is out of view
                            icon.UpdateHookForm();
                        }
                    }

                    // Render the mouse over icon last (on top)
                    if (mouseOverIcon != null)
                    {
                        mouseOverIcon.MouseOverRender(drawArgs, m_sprite, drawArgs.WorldCamera.Project(mouseOverIcon.Position));
                    }

                    // set new mouseover icon
                    mouseOverIcon = closestIcon;
                }
                else
                {
                    // For each ro
                    foreach (RenderableObject ro in m_children)
                    {
                        if (!ro.IsOn)
                        {
                            continue;
                        }

                        // most objects should be icons
                        JHU_Icon icon = ro as JHU_Icon;

                        // if its not an icon call its render
                        if (icon == null)
                        {
                            ro.Render(drawArgs);
                        }
                        // else its an icon - render here to batch up the sprite renders
                        else
                        {
                            // don't bother if we aren't even in view
                            if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
                            {
                                icon.FastRender(drawArgs, m_sprite, drawArgs.WorldCamera.Project(icon.Position));
                            }

                            // Update here or it doesn't update when the icon is out of view
                            icon.UpdateHookForm();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
            finally
            {
                m_sprite.End();
            }
        }
        public override bool PerformSelectionAction(DrawArgs drawArgs)
        {
            int      closestIconDistanceSquared = int.MaxValue;
            JHU_Icon closestIcon = null;

            foreach (RenderableObject ro in m_children)
            {
                // If renderable object can handle the selection
                if (!ro.IsOn)
                {
                    continue;
                }
                if (!ro.isSelectable)
                {
                    continue;
                }

                JHU_Icon icon = ro as JHU_Icon;

                // if its not an icon just perform the action else do the selection on the closest icon
                if (icon == null)
                {
                    if (ro.PerformSelectionAction(drawArgs))
                    {
                        return(true);
                    }
                }
                else
                {
                    // don't check if we aren't even in view
                    if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
                    {
                        // check if inside current icon's selection rectangle
                        Vector3 projectedPoint = drawArgs.WorldCamera.Project(icon.Position);

                        int dx = DrawArgs.LastMousePosition.X - (int)projectedPoint.X;
                        int dy = DrawArgs.LastMousePosition.Y - (int)projectedPoint.Y;

                        if (icon.SelectionRectangle.Contains(dx, dy))
                        {
                            // Mouse is over, check whether this icon is closest
                            int distanceSquared = dx * dx + dy * dy;
                            if (distanceSquared < closestIconDistanceSquared)
                            {
                                closestIconDistanceSquared = distanceSquared;
                                closestIcon = icon;
                            }
                        }
                    }
                }
            }

            // if no other object has handled the selection let the closest icon try
            if (closestIcon != null)
            {
                if (closestIcon.PerformSelectionAction(drawArgs))
                {
                    return(true);
                }
            }

            return(false);
        }