public void Initialize(DrawArgs drawArgs)
        {
            // Initialize fonts
            if (m_drawingFont == null)
            {
                System.Drawing.Font localHeaderFont = new System.Drawing.Font("Arial", 12.0f, FontStyle.Italic | FontStyle.Bold);
                m_drawingFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, localHeaderFont);

                System.Drawing.Font wingdings = new System.Drawing.Font("Wingdings", 12.0f);
                m_wingdingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, wingdings);

                System.Drawing.Font worldwinddings = new System.Drawing.Font("World Wind dings", 12.0f);
                m_worldwinddingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, worldwinddings);
            }

            // Initialize icon if any
            if (m_imageName.Trim() != string.Empty)
            {
                object key = null;

                // Icon image from file
                m_iconTexture = (JHU_IconTexture)m_textures[m_imageName];
                if (m_iconTexture == null)
                {
                    key           = m_imageName;
                    m_iconTexture = new JHU_IconTexture(drawArgs.device, JHU_Globals.getInstance().BasePath + @"\Data\Icons\Interface\" + m_imageName);
                }

                if (m_iconTexture != null)
                {
                    m_iconTexture.ReferenceCount++;

                    if (key != null)
                    {
                        // New texture, cache it
                        m_textures.Add(key, m_iconTexture);
                    }

                    if (m_size.Width == 0)
                    {
                        m_size.Width = m_iconTexture.Width;
                    }

                    if (m_size.Height == 0)
                    {
                        m_size.Height = m_iconTexture.Height;
                    }

                    this.XScale = (float)m_size.Width / m_iconTexture.Width;
                    this.YScale = (float)m_size.Height / m_iconTexture.Height;
                }

                if (m_sprite == null)
                {
                    m_sprite = new Sprite(drawArgs.device);
                }
            }

            m_isInitialized = true;
        }
Example #2
0
        /// <summary>
        /// Initializes the button by loading the texture, creating the sprite and figure out the scaling.
        ///
        /// Called on the GUI thread.
        /// </summary>
        /// <param name="drawArgs">The drawing arguments passed from the WW GUI thread.</param>
        public void Initialize(DrawArgs drawArgs)
        {
            object key = null;

            // Icon image from file
            m_iconTexture = (JHU_IconTexture)m_textures[m_imageName];
            if (m_iconTexture == null)
            {
                key           = m_imageName;
                m_iconTexture = new JHU_IconTexture(drawArgs.device, JHU_Globals.getInstance().BasePath + @"\Data\Icons\Interface\" + m_imageName);
            }

            if (m_iconTexture != null)
            {
                m_iconTexture.ReferenceCount++;

                if (key != null)
                {
                    // New texture, cache it
                    m_textures.Add(key, m_iconTexture);
                }

                if (m_size.Width == 0)
                {
                    m_size.Width = m_iconTexture.Width;
                }

                if (m_size.Height == 0)
                {
                    m_size.Height = m_iconTexture.Height;
                }

                this.XScale = (float)m_size.Width / m_iconTexture.Width;
                this.YScale = (float)m_size.Height / m_iconTexture.Height;
            }

            if (m_sprite == null)
            {
                m_sprite = new Sprite(drawArgs.device);
            }

            if (m_crossHairs == null)
            {
                m_crossHairs = new Line(drawArgs.device);
            }

            m_isInitialized = true;
        }
Example #3
0
		public override void Initialize(DrawArgs drawArgs)
		{
			UpdatePosition(drawArgs);

			// get the icon texture
			object key = null;
			m_iconTexture = null;
			if(TextureFileName.Trim() != String.Empty)
			{
				// Icon image from file
				m_iconTexture = (JHU_IconTexture)m_textures[TextureFileName];
				if(m_iconTexture==null)
				{
					key = TextureFileName;
					m_iconTexture = new JHU_IconTexture( drawArgs.device, TextureFileName );
				}

				// if secondary icon enabled
				if (m_iconTexture2Show && m_iconTexture2Name.Trim() != String.Empty)
				{
					m_iconTexture2 = (JHU_IconTexture)m_textures[m_iconTexture2Name];
					if (m_iconTexture2 == null)
					{
						m_iconTexture2 = new JHU_IconTexture( drawArgs.device, m_iconTexture2Name );
						m_textures.Add(m_iconTexture2Name, m_iconTexture2);
					}

					m_iconTexture2.ReferenceCount++;
				}

				// if teritary icon enabled
				if (m_iconTexture3Show && m_iconTexture3Name.Trim() != String.Empty)
				{
					m_iconTexture3 = (JHU_IconTexture)m_textures[m_iconTexture3Name];
					if (m_iconTexture3 == null)
					{
						m_iconTexture3 = new JHU_IconTexture( drawArgs.device, m_iconTexture3Name );
						m_textures.Add(m_iconTexture3Name, m_iconTexture3);
					}

					m_iconTexture3.ReferenceCount++;
				}
			}
			else
			{
				// Icon image from bitmap
				if(this.Image != null)
				{
					m_iconTexture = (JHU_IconTexture)m_textures[this.Image];
					if(m_iconTexture==null)
					{
						// Create new texture from image
						key = this.Image;
						m_iconTexture = new JHU_IconTexture( drawArgs.device, this.Image);
					}

				}
			}

			if(m_iconTexture!=null)
			{
				m_iconTexture.ReferenceCount++;

				if(key!=null)
				{
					// New texture, cache it
					m_textures.Add(key, m_iconTexture);
				}

				// Use default dimensions if not set
				if(this.Width==0)
					this.Width = m_iconTexture.Width;
				if(this.Height==0)
					this.Height = m_iconTexture.Height;
			}

			// Compute selection rectangle
			if(m_iconTexture == null)
			{
				// Label only 
				this.SelectionRectangle = drawArgs.defaultDrawingFont.MeasureString(null, this.Name, DrawTextFormat.None, 0);
			}
			else
			{
				// Icon only
				this.SelectionRectangle = new Rectangle( 0, 0, this.Width, this.Height );
			}

			// Center the box at (0,0)
			this.SelectionRectangle.Offset(-this.SelectionRectangle.Width/2, -this.SelectionRectangle.Height/2 );

			if (m_iconTexture != null)
			{
				this.XScale = (float)this.Width / m_iconTexture.Width;
				this.YScale = (float)this.Height / m_iconTexture.Height;

				// TODO - note: right now we assume any secondary icons scale the same as the primary
			}
			else
			{
				this.XScale = 1.0f;
				this.YScale = 1.0f;
			}

			if (m_groundStick == null)
				m_groundStick = new Line(drawArgs.device);

			isInitialized = true;
		}
		/// <summary>
		/// Initializes the button by loading the texture, creating the sprite and figure out the scaling.
		/// 
		/// Called on the GUI thread.
		/// </summary>
		/// <param name="drawArgs">The drawing arguments passed from the WW GUI thread.</param>
		public void Initialize (DrawArgs drawArgs)
		{
			object key = null;

			// Icon image from file
			m_iconTexture = (JHU_IconTexture)m_textures[m_imageName];
			if(m_iconTexture==null)
			{
				key = m_imageName;
				m_iconTexture = new JHU_IconTexture( drawArgs.device, JHU_Globals.getInstance().BasePath + @"\Data\Icons\Interface\" + m_imageName );
			}

			if(m_iconTexture!=null)
			{
				m_iconTexture.ReferenceCount++;

				if(key!=null)
				{
					// New texture, cache it
					m_textures.Add(key, m_iconTexture);
				}

				if (m_size.Width == 0)
					m_size.Width = m_iconTexture.Width;

				if (m_size.Height == 0)
					m_size.Height = m_iconTexture.Height;

				this.XScale = (float)m_size.Width / m_iconTexture.Width;
				this.YScale = (float)m_size.Height / m_iconTexture.Height;
			}

			if (m_sprite == null)
				m_sprite = new Sprite(drawArgs.device);

			m_isInitialized = true;
		}
		public void Initialize (DrawArgs drawArgs)
		{
			// Initialize fonts
			if (m_drawingFont == null)
			{
				System.Drawing.Font localHeaderFont = new System.Drawing.Font("Arial", 12.0f, FontStyle.Italic | FontStyle.Bold);
				m_drawingFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, localHeaderFont);

				System.Drawing.Font wingdings = new System.Drawing.Font("Wingdings", 12.0f);
				m_wingdingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, wingdings);

				System.Drawing.Font worldwinddings = new System.Drawing.Font("World Wind dings", 12.0f);
				m_worldwinddingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, worldwinddings);
			}

			// Initialize icon if any
			if (m_imageName.Trim() != string.Empty)
			{
				object key = null;

				// Icon image from file
				m_iconTexture = (JHU_IconTexture)m_textures[m_imageName];
				if(m_iconTexture==null)
				{
					key = m_imageName;
					m_iconTexture = new JHU_IconTexture( drawArgs.device, JHU_Globals.getInstance().BasePath + @"\Data\Icons\Interface\" + m_imageName );
				}

				if(m_iconTexture!=null)
				{
					m_iconTexture.ReferenceCount++;

					if(key!=null)
					{
						// New texture, cache it
						m_textures.Add(key, m_iconTexture);
					}

					if (m_size.Width == 0)
						m_size.Width = m_iconTexture.Width;

					if (m_size.Height == 0)
						m_size.Height = m_iconTexture.Height;

					this.XScale = (float)m_size.Width / m_iconTexture.Width;
					this.YScale = (float)m_size.Height / m_iconTexture.Height;
				}

				if (m_sprite == null)
					m_sprite = new Sprite(drawArgs.device);
			}

			m_isInitialized = true;
		}
Example #6
0
        /// <summary>
        /// Draw the icon
        /// </summary>
        public void MouseOverRender(DrawArgs drawArgs, Sprite sprite, Vector3 projectedPoint)
        {
            JHU_IconTexture iconTexture = this.GetTexture();

            if (this.isSelectable)
            {
                DrawArgs.MouseCursor = CursorType.Hand;
            }

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

            if ((!this.m_isUpdated) || (drawArgs.WorldCamera.Altitude < 300000))
            {
                this.UpdatePosition(drawArgs);
            }

            // set description to icon descrption
            m_globals.GeneralInfoLabel.Text  = GeneralInfo();
            m_globals.DetailedInfoLabel.Text = DetailedInfo();
            m_globals.DescriptionLabel.Text  = DescriptionInfo();


            if (iconTexture == null)
            {
                // Render label
                if (this.Name != null)
                {
                    // Center over target as we have no bitmap
                    Rectangle rect = new Rectangle(
                        (int)projectedPoint.X - (labelWidth >> 1),
                        (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1)),
                        labelWidth,
                        drawArgs.screenHeight);

                    drawArgs.defaultDrawingFont.DrawText(sprite, this.Name, rect, DrawTextFormat.Center, hotColor);
                }
            }
            else
            {
                // Render label
                if (this.Name != null)
                {
                    // Adjust text to make room for icon
                    int spacing = (int)(this.Width * 0.3f);
                    if (spacing > 10)
                    {
                        spacing = 10;
                    }
                    int offsetForIcon = (this.Width >> 1) + spacing;

                    Rectangle rect = new Rectangle(
                        (int)projectedPoint.X + offsetForIcon,
                        (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1)),
                        labelWidth,
                        drawArgs.screenHeight);

                    drawArgs.defaultDrawingFont.DrawText(sprite, this.Name, rect, DrawTextFormat.WordBreak, hotColor);
                }

                // Render icon
                sprite.Transform = Matrix.Scaling(this.XScale, this.YScale, 0);

                if (m_isRotated)
                {
                    sprite.Transform *= Matrix.RotationZ((float)m_rotation.Radians - (float)drawArgs.WorldCamera.Heading.Radians);
                }

                sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0);
                sprite.Draw(iconTexture.Texture,
                            new Vector3(iconTexture.Width >> 1, iconTexture.Height >> 1, 0),
                            Vector3.Empty,
                            hotColor);

                if (m_iconTexture2Show)
                {
                    sprite.Draw(m_iconTexture2.Texture,
                                new Vector3(m_iconTexture2.Width >> 1, m_iconTexture2.Height >> 1, 0),
                                Vector3.Empty,
                                hotColor);
                }

                if (m_iconTexture3Show)
                {
                    sprite.Draw(m_iconTexture3.Texture,
                                new Vector3(m_iconTexture3.Width >> 1, m_iconTexture3.Height >> 1, 0),
                                Vector3.Empty,
                                hotColor);
                }

                // Reset transform to prepare for text rendering later
                sprite.Transform = Matrix.Identity;
            }
            if (m_drawGroundStick)
            {
                Vector2[] groundStick = new Vector2[2];

                Vector3 projectedGroundPoint = drawArgs.WorldCamera.Project(m_groundPoint);

                m_groundStick.Begin();
                groundStick[0].X = projectedPoint.X;
                groundStick[0].Y = projectedPoint.Y;
                groundStick[1].X = projectedGroundPoint.X;
                groundStick[1].Y = projectedGroundPoint.Y;
                m_groundStick.Draw(groundStick, m_groundStickColor);
                m_groundStick.End();
            }
        }
Example #7
0
        /// <summary>
        /// Draw the icon
        /// </summary>
        public void FastRender(DrawArgs drawArgs, Sprite sprite, Vector3 projectedPoint)
        {
            // Check icons for within "visual" range
            float distanceToIcon = Vector3.Length(this.Position - drawArgs.WorldCamera.Position);

            if (distanceToIcon > this.MaximumDisplayDistance)
            {
                return;
            }
            if (distanceToIcon < this.MinimumDisplayDistance)
            {
                return;
            }

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

            if ((!this.m_isUpdated) || (drawArgs.WorldCamera.Altitude < 300000))
            {
                this.UpdatePosition(drawArgs);
            }

            JHU_IconTexture iconTexture = this.GetTexture();

            if (iconTexture == null)
            {
                // Render label
                if (this.Name != null)
                {
                    // Center over target as we have no bitmap
                    Rectangle rect = new Rectangle(
                        (int)projectedPoint.X - (labelWidth >> 1),
                        (int)(projectedPoint.Y - (drawArgs.defaultDrawingFont.Description.Height >> 1)),
                        labelWidth,
                        drawArgs.screenHeight);

                    drawArgs.defaultDrawingFont.DrawText(sprite, this.Name, rect, DrawTextFormat.Center, normalColor);
                }
            }
            else
            {
                // Render icon
                sprite.Transform = Matrix.Scaling(this.XScale, this.YScale, 0);

                if (m_isRotated)
                {
                    sprite.Transform *= Matrix.RotationZ((float)m_rotation.Radians - (float)drawArgs.WorldCamera.Heading.Radians);
                }

                sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0);

                sprite.Draw(iconTexture.Texture,
                            new Vector3(iconTexture.Width >> 1, iconTexture.Height >> 1, 0),
                            Vector3.Empty,
                            normalColor);

                if (m_iconTexture2Show)
                {
                    sprite.Draw(m_iconTexture2.Texture,
                                new Vector3(m_iconTexture2.Width >> 1, m_iconTexture2.Height >> 1, 0),
                                Vector3.Empty,
                                normalColor);
                }

                if (m_iconTexture3Show)
                {
                    sprite.Draw(m_iconTexture3.Texture,
                                new Vector3(m_iconTexture3.Width >> 1, m_iconTexture3.Height >> 1, 0),
                                Vector3.Empty,
                                normalColor);
                }

                // Reset transform to prepare for text rendering later
                sprite.Transform = Matrix.Identity;
            }

            if (m_drawGroundStick)
            {
                Vector2[] groundStick = new Vector2[2];
                Angle     testAngle   = new Angle();
                testAngle.Degrees = 45.0;

                Vector3 projectedGroundPoint = drawArgs.WorldCamera.Project(m_groundPoint);

                m_groundStick.Begin();
                groundStick[0].X = projectedPoint.X;
                groundStick[0].Y = projectedPoint.Y;
                groundStick[1].X = projectedGroundPoint.X;
                groundStick[1].Y = projectedGroundPoint.Y;

                m_groundStick.Draw(groundStick, m_groundStickColor);
                m_groundStick.End();
            }
        }
Example #8
0
        public override void Initialize(DrawArgs drawArgs)
        {
            UpdatePosition(drawArgs);

            // get the icon texture
            object key = null;

            m_iconTexture = null;
            if (TextureFileName.Trim() != String.Empty)
            {
                // Icon image from file
                m_iconTexture = (JHU_IconTexture)m_textures[TextureFileName];
                if (m_iconTexture == null)
                {
                    key           = TextureFileName;
                    m_iconTexture = new JHU_IconTexture(drawArgs.device, TextureFileName);
                }

                // if secondary icon enabled
                if (m_iconTexture2Show && m_iconTexture2Name.Trim() != String.Empty)
                {
                    m_iconTexture2 = (JHU_IconTexture)m_textures[m_iconTexture2Name];
                    if (m_iconTexture2 == null)
                    {
                        m_iconTexture2 = new JHU_IconTexture(drawArgs.device, m_iconTexture2Name);
                        m_textures.Add(m_iconTexture2Name, m_iconTexture2);
                    }

                    m_iconTexture2.ReferenceCount++;
                }

                // if teritary icon enabled
                if (m_iconTexture3Show && m_iconTexture3Name.Trim() != String.Empty)
                {
                    m_iconTexture3 = (JHU_IconTexture)m_textures[m_iconTexture3Name];
                    if (m_iconTexture3 == null)
                    {
                        m_iconTexture3 = new JHU_IconTexture(drawArgs.device, m_iconTexture3Name);
                        m_textures.Add(m_iconTexture3Name, m_iconTexture3);
                    }

                    m_iconTexture3.ReferenceCount++;
                }
            }
            else
            {
                // Icon image from bitmap
                if (this.Image != null)
                {
                    m_iconTexture = (JHU_IconTexture)m_textures[this.Image];
                    if (m_iconTexture == null)
                    {
                        // Create new texture from image
                        key           = this.Image;
                        m_iconTexture = new JHU_IconTexture(drawArgs.device, this.Image);
                    }
                }
            }

            if (m_iconTexture != null)
            {
                m_iconTexture.ReferenceCount++;

                if (key != null)
                {
                    // New texture, cache it
                    m_textures.Add(key, m_iconTexture);
                }

                // Use default dimensions if not set
                if (this.Width == 0)
                {
                    this.Width = m_iconTexture.Width;
                }
                if (this.Height == 0)
                {
                    this.Height = m_iconTexture.Height;
                }
            }

            // Compute selection rectangle
            if (m_iconTexture == null)
            {
                // Label only
                this.SelectionRectangle = drawArgs.defaultDrawingFont.MeasureString(null, this.Name, DrawTextFormat.None, 0);
            }
            else
            {
                // Icon only
                this.SelectionRectangle = new Rectangle(0, 0, this.Width, this.Height);
            }

            // Center the box at (0,0)
            this.SelectionRectangle.Offset(-this.SelectionRectangle.Width / 2, -this.SelectionRectangle.Height / 2);

            if (m_iconTexture != null)
            {
                this.XScale = (float)this.Width / m_iconTexture.Width;
                this.YScale = (float)this.Height / m_iconTexture.Height;

                // TODO - note: right now we assume any secondary icons scale the same as the primary
            }
            else
            {
                this.XScale = 1.0f;
                this.YScale = 1.0f;
            }

            if (m_groundStick == null)
            {
                m_groundStick = new Line(drawArgs.device);
            }

            isInitialized = true;
        }