Пример #1
0
        protected override void BuildIconTexture(DrawArgs drawArgs)
        {
            base.BuildIconTexture(drawArgs);

            try
            {
                // if secondary icon enabled
                if (m_iconTexture2Show && m_iconTexture2Name.Trim() != String.Empty)
                {
                    if (m_iconTexture2 != null)
                    {
                        m_iconTexture2.ReferenceCount--;
                    }

                    m_iconTexture2 = (IconTexture)DrawArgs.Textures[m_iconTexture2Name];
                    if (m_iconTexture2 == null)
                    {
                        m_iconTexture2 = new IconTexture(drawArgs.device, m_iconTexture2Name);
                        DrawArgs.Textures.Add(m_iconTexture2Name, m_iconTexture2);
                    }

                    if (m_iconTexture2 != null)
                    {
                        m_iconTexture2.ReferenceCount++;
                    }
                }

                // if teritary icon enabled
                if (m_iconTexture3Show && m_iconTexture3Name.Trim() != String.Empty)
                {
                    if (m_iconTexture3 != null)
                    {
                        m_iconTexture3.ReferenceCount--;
                    }

                    m_iconTexture3 = (IconTexture)DrawArgs.Textures[m_iconTexture3Name];
                    if (m_iconTexture3 == null)
                    {
                        m_iconTexture3 = new IconTexture(drawArgs.device, m_iconTexture3Name);
                        DrawArgs.Textures.Add(m_iconTexture3Name, m_iconTexture3);
                    }

                    if (m_iconTexture3 != null)
                    {
                        m_iconTexture3.ReferenceCount++;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }

            m_newTexture = false;
        }
Пример #2
0
        public override void Dispose()
        {
            try
            {
                // call rol dispose to get all the children disposed first
                base.Dispose();

                // remove any textures no longer being used.
                if (DrawArgs.Textures != null)
                {
                    List <object> removeList = new List <object>();
                    foreach (object key in DrawArgs.Textures.Keys)
                    {
                        IconTexture iconTexture = (IconTexture)DrawArgs.Textures[key];
                        if (iconTexture.ReferenceCount <= 0)
                        {
                            removeList.Add(key);
                        }
                    }

                    foreach (object key in removeList)
                    {
                        IconTexture iconTexture = (IconTexture)DrawArgs.Textures[key];
                        DrawArgs.Textures.Remove(key);
                        iconTexture.Dispose();
                    }
                }

                if (m_sprite != null)
                {
                    m_sprite.Dispose();
                    m_sprite = null;
                }

                if (refreshTimer != null)
                {
                    refreshTimer.Stop();
                    refreshTimer.Dispose();
                    refreshTimer = null;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }
        }
Пример #3
0
        /// <summary>
        /// Draw the icon
        /// </summary>
        //[Obsolete]
        //protected virtual void Render(DrawArgs drawArgs, Icon icon, Vector3 projectedPoint)
        //{
        //    if (!icon.isInitialized)
        //        icon.Initialize(drawArgs);

        //    if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
        //        return;

        //    // Check icons for within "visual" range
        //    double distanceToIcon = Vector3.Length(icon.Position - drawArgs.WorldCamera.Position);
        //    if (distanceToIcon > icon.MaximumDisplayDistance)
        //        return;
        //    if (distanceToIcon < icon.MinimumDisplayDistance)
        //        return;

        //    //Respect icon set temporal extents
        //    if (TimeKeeper.CurrentTimeUtc < EarliestTime || TimeKeeper.CurrentTimeUtc > LatestTime)
        //        return;

        //    IconTexture iconTexture = GetTexture(icon);
        //    bool isMouseOver = icon == mouseOverIcon;

        //    //Show description for normal Icons at the bottom
        //    //of the page
        //    if (isMouseOver) // && !icon.IsKMLIcon)
        //    {
        //        // Mouse is over
        //        isMouseOver = true;

        //        if (icon.isSelectable)
        //            DrawArgs.MouseCursor = CursorType.Hand;

        //        string description = icon.Description;
        //        if (description == null)
        //            description = icon.ClickableActionURL;
        //        if (description != null)
        //        {
        //            // Render description field
        //            DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.WordBreak | DrawTextFormat.Bottom;
        //            int left = 10;
        //            if (World.Settings.showLayerManager)
        //                left += World.Settings.layerManagerWidth;
        //            Rectangle rect = Rectangle.FromLTRB(left, 10, drawArgs.screenWidth - 10, drawArgs.screenHeight - 10);

        //            // Draw outline
        //            drawArgs.defaultDrawingFont.DrawText(
        //                m_sprite, description,
        //                rect,
        //                format, 0xb0 << 24);

        //            rect.Offset(2, 0);
        //            drawArgs.defaultDrawingFont.DrawText(
        //                m_sprite, description,
        //                rect,
        //                format, 0xb0 << 24);

        //            rect.Offset(0, 2);
        //            drawArgs.defaultDrawingFont.DrawText(
        //                m_sprite, description,
        //                rect,
        //                format, 0xb0 << 24);

        //            rect.Offset(-2, 0);
        //            drawArgs.defaultDrawingFont.DrawText(
        //                m_sprite, description,
        //                rect,
        //                format, 0xb0 << 24);

        //            // Draw description
        //            rect.Offset(1, -1);
        //            drawArgs.defaultDrawingFont.DrawText(
        //                m_sprite, description,
        //                rect,
        //                format, descriptionColor);
        //        }
        //    }

        //    int color = isMouseOver ? hotColor : normalColor;
        //    if (iconTexture == null || isMouseOver || icon.NameAlwaysVisible)
        //    {
        //        // Render label
        //        if (icon.Name != null)
        //        {
        //            // Render name field
        //            const int labelWidth = 1000; // Dummy value needed for centering the text
        //            if (iconTexture == 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(m_sprite, icon.Name, rect, DrawTextFormat.Center, color);
        //            }
        //            else
        //            {
        //                // Adjust text to make room for icon
        //                int spacing = (int)(icon.Width * 0.3f);
        //                if (spacing > 10)
        //                    spacing = 10;
        //                int offsetForIcon = (icon.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(m_sprite, icon.Name, rect, DrawTextFormat.WordBreak, color);
        //            }
        //        }
        //    }

        //    if (iconTexture != null)
        //    {
        //        // Render icon
        //        float factor = 1;
        //        //Do Altitude depedent scaling for KMLIcons
        //        //if(icon.IsKMLIcon)
        //        //    if (drawArgs.WorldCamera.Altitude > MinIconZoomDistance)
        //        //        factor -= (float)((drawArgs.WorldCamera.Altitude - MinIconZoomDistance) / drawArgs.WorldCamera.Altitude);

        //        float xscale = factor * ((float)icon.Width / iconTexture.Width);
        //        float yscale = factor * ((float)icon.Height / iconTexture.Height);
        //        m_sprite.Transform = Matrix.Scaling(xscale, yscale, 0);

        //        if (icon.IsRotated)
        //            m_sprite.Transform *= Matrix.RotationZ((float)icon.Rotation.Radians - (float)drawArgs.WorldCamera.Heading.Radians);

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

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

        /// <summary>
        /// Retrieve an icon's texture
        /// </summary>
        protected IconTexture GetTexture(Icon icon)
        {
            object key = null;

            if (icon.Image == null)
            {
                key = icon.TextureFileName;
            }
            else
            {
                key = icon.Image;
            }
            if (key == null)
            {
                return(null);
            }

            IconTexture res = (IconTexture)DrawArgs.Textures[key];

            return(res);
        }
Пример #4
0
        /// <summary>
        /// Retrieve an icon's texture
        /// </summary>
        protected IconTexture GetTexture(Icon icon)
        {
            object key = null;

            if (icon.Image == null)
            {
                key = (icon.TextureFileName.ToLower().StartsWith("http://") ? icon.SaveFilePath : icon.TextureFileName);
            }
            else
            {
                key = icon.Image;
            }
            if (key == null)
            {
                return(null);
            }

            IconTexture res = (IconTexture)m_textures[key];

            return(res);
        }
Пример #5
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (!isOn)
            {
                return;
            }

            if (!isInitialized)
            {
                string textureFilePath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), @"Data\Icons\sol_wh.gif");

                m_pointTexture = new IconTexture(drawArgs.device, textureFilePath);

                // This could be off since the texture is scaled
                SelectionRectangle = new Rectangle(0, 0, m_pointTexture.Width, m_pointTexture.Height);

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

            isInitialized = true;
        }
Пример #6
0
        /// <summary>
        /// Draw the icon
        /// </summary>
        protected virtual void Render(DrawArgs drawArgs, Icon icon, Vector3 projectedPoint)
        {
            if (!icon.isInitialized)
            {
                icon.Initialize(drawArgs);
            }

            if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
            {
                return;
            }

            // Check icons for within "visual" range
            double distanceToIcon = Vector3.Length(icon.Position - drawArgs.WorldCamera.Position);

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

            IconTexture iconTexture = GetTexture(icon);
            bool        isMouseOver = icon == mouseOverIcon;

            if (isMouseOver)
            {
                // Mouse is over
                isMouseOver = true;

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

                string description = icon.Description;
                if (description == null)
                {
                    description = icon.ClickableActionURL;
                }
                if (description != null)
                {
                    // Render description field
                    DrawTextFormat format = DrawTextFormat.NoClip | DrawTextFormat.WordBreak | DrawTextFormat.Bottom;
                    int            left   = 10;
                    if (World.Settings.showLayerManager)
                    {
                        left += World.Settings.layerManagerWidth;
                    }
                    Rectangle rect = Rectangle.FromLTRB(left, 10, drawArgs.screenWidth - 10, drawArgs.screenHeight - 10);

                    // Draw outline
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    rect.Offset(2, 0);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    rect.Offset(0, 2);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    rect.Offset(-2, 0);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, 0xb0 << 24);

                    // Draw description
                    rect.Offset(1, -1);
                    drawArgs.defaultDrawingFont.DrawText(
                        m_sprite, description,
                        rect,
                        format, descriptionColor);
                }
            }

            int color = isMouseOver ? hotColor : normalColor;

            if (iconTexture == null || isMouseOver || icon.NameAlwaysVisible)
            {
                // Render label
                if (icon.Name != null)
                {
                    // Render name field
                    const int labelWidth = 1000;                     // Dummy value needed for centering the text
                    if (iconTexture == 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(m_sprite, icon.Name, rect, DrawTextFormat.Center, color);
                    }
                    else
                    {
                        // Adjust text to make room for icon
                        int spacing = (int)(icon.Width * 0.3f);
                        if (spacing > 10)
                        {
                            spacing = 10;
                        }
                        int offsetForIcon = (icon.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(m_sprite, icon.Name, rect, DrawTextFormat.WordBreak, color);
                    }
                }
            }

            if (iconTexture != null)
            {
                // Render icon
                float xscale = (float)icon.Width / iconTexture.Width;
                float yscale = (float)icon.Height / iconTexture.Height;
                m_sprite.Transform = Matrix.Scaling(xscale, yscale, 0);

                if (icon.IsRotated)
                {
                    m_sprite.Transform *= Matrix.RotationZ((float)icon.Rotation.Radians - (float)drawArgs.WorldCamera.Heading.Radians);
                }

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

                // Reset transform to prepare for text rendering later
                m_sprite.Transform = Matrix.Identity;
            }
        }
Пример #7
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (!isOn)
            {
                return;
            }

            if (m_sprite != null)
            {
                m_sprite.Dispose();
                m_sprite = null;
            }

            m_sprite = new Sprite(drawArgs.device);

            System.TimeSpan smallestRefreshInterval = System.TimeSpan.MaxValue;

            // Load all textures
            foreach (RenderableObject ro in m_children)
            {
                Icon icon = ro as Icon;
                if (icon == null)
                {
                    // Child is not an icon
                    if (ro.IsOn)
                    {
                        ro.Initialize(drawArgs);
                    }
                    continue;
                }

                if (icon.RefreshInterval.TotalMilliseconds != 0 && icon.RefreshInterval != TimeSpan.MaxValue && icon.RefreshInterval < smallestRefreshInterval)
                {
                    smallestRefreshInterval = icon.RefreshInterval;
                }

                // Child is an icon
                icon.Initialize(drawArgs);

                object      key         = null;
                IconTexture iconTexture = null;

                if (icon.TextureFileName != null && icon.TextureFileName.Length > 0)
                {
                    if (icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null)
                    {
                        //download it
                        try
                        {
                            WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName);
                            webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified;

                            System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath);
                            if (!saveFile.Directory.Exists)
                            {
                                saveFile.Directory.Create();
                            }

                            webDownload.DownloadFile(saveFile.FullName);
                        }
                        catch {}

                        iconTexture = (IconTexture)m_textures[icon.SaveFilePath];
                        if (iconTexture == null)
                        {
                            key         = icon.SaveFilePath;
                            iconTexture = new IconTexture(drawArgs.device, icon.SaveFilePath);
                        }
                    }
                    else
                    {
                        // Icon image from file
                        iconTexture = (IconTexture)m_textures[icon.TextureFileName];
                        if (iconTexture == null)
                        {
                            key         = icon.TextureFileName;
                            iconTexture = new IconTexture(drawArgs.device, icon.TextureFileName);
                        }
                    }
                }
                else
                {
                    // Icon image from bitmap
                    if (icon.Image != null)
                    {
                        iconTexture = (IconTexture)m_textures[icon.Image];
                        if (iconTexture == null)
                        {
                            // Create new texture from image
                            key         = icon.Image;
                            iconTexture = new IconTexture(drawArgs.device, icon.Image);
                        }
                    }
                }

                if (iconTexture == null)
                {
                    // No texture set
                    continue;
                }

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

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

            // Compute mouse over bounding boxes
            foreach (RenderableObject ro in m_children)
            {
                Icon icon = ro as Icon;
                if (icon == null)
                {
                    // Child is not an icon
                    continue;
                }

                if (GetTexture(icon) == null)
                {
                    // Label only
                    icon.SelectionRectangle = drawArgs.defaultDrawingFont.MeasureString(null, icon.Name, DrawTextFormat.None, 0);
                }
                else
                {
                    // Icon only
                    icon.SelectionRectangle = new Rectangle(0, 0, icon.Width, icon.Height);
                }

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

            if (refreshTimer == null && smallestRefreshInterval != TimeSpan.MaxValue)
            {
                refreshTimer          = new System.Timers.Timer(smallestRefreshInterval.TotalMilliseconds);
                refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(refreshTimer_Elapsed);
                refreshTimer.Start();
            }

            isInitialized = true;
        }
Пример #8
0
        private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (isUpdating)
            {
                return;
            }
            isUpdating = true;
            try
            {
                for (int i = 0; i < this.ChildObjects.Count; i++)
                {
                    RenderableObject ro = (RenderableObject)this.ChildObjects[i];
                    if (ro != null && ro.IsOn && ro is Icon)
                    {
                        Icon icon = (Icon)ro;

                        if (icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval)
                        {
                            continue;
                        }

                        object      key         = null;
                        IconTexture iconTexture = null;

                        if (icon.TextureFileName != null && icon.TextureFileName.Length > 0)
                        {
                            iconTexture = (IconTexture)DrawArgs.Textures[icon.TextureFileName];
                            if (iconTexture != null)
                            {
                                iconTexture.UpdateTexture(DrawArgs.Device, icon.TextureFileName);
                            }
                            else
                            {
                                key         = icon.TextureFileName;
                                iconTexture = new IconTexture(DrawArgs.Device, icon.TextureFileName);

                                iconTexture.ReferenceCount++;

                                // New texture, cache it
                                DrawArgs.Textures.Add(key, iconTexture);

                                // Use default dimensions if not set
                                if (icon.Width == 0)
                                {
                                    icon.Width = iconTexture.Width;
                                }
                                if (icon.Height == 0)
                                {
                                    icon.Height = iconTexture.Height;
                                }
                            }
                        }
                        else
                        {
                            // Icon image from bitmap
                            if (icon.Image != null)
                            {
                                iconTexture = (IconTexture)DrawArgs.Textures[icon.Image];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    DrawArgs.Textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.Image);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.Image);

                                    // New texture, cache it
                                    DrawArgs.Textures.Add(key, iconTexture);

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

                        icon.LastRefresh = System.DateTime.Now;
                    }
                }
            }
            catch { }
            finally
            {
                isUpdating = false;
            }
        }
Пример #9
0
        /// <summary>
        /// Builds the icon texture based on the saved texturefile name
        /// </summary>
        /// <param name="drawArgs"></param>
        protected virtual void BuildIconTexture(DrawArgs drawArgs)
        {
            try
            {
                object key = null;

                if (m_iconTexture != null)
                {
                    m_iconTexture.ReferenceCount--;
                }

                if ((TextureFileName != null) && (TextureFileName.Trim() != String.Empty))
                {
                    // Icon image from file
                    m_iconTexture = (IconTexture)DrawArgs.Textures[TextureFileName];
                    if (m_iconTexture == null)
                    {
                        key = TextureFileName;
                        m_iconTexture = new IconTexture(drawArgs.device, TextureFileName);
                    }
                }
                else
                {
                    // Icon image from bitmap
                    if (this.m_image != null)
                    {
                        m_iconTexture = (IconTexture)DrawArgs.Textures[this.m_image];
                        if (m_iconTexture == null)
                        {
                            // Create new texture from image
                            key = this.m_image;
                            m_iconTexture = new IconTexture(drawArgs.device, this.m_image);
                        }
                    }
                }

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

                    if (key != null)
                    {
                        // New texture, cache it
                        DrawArgs.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 mouse over bounding boxes
                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;

                }
                else
                {
                    this.XScale = 1.0f;
                    this.YScale = 1.0f;
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message.ToString());
            }

            m_newTexture = false;
        }
Пример #10
0
		private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
		{
			if(isUpdating)
				return;
			isUpdating = true;
			try
			{
				for(int i = 0; i < this.ChildObjects.Count; i++)
				{
					RenderableObject ro = (RenderableObject)this.ChildObjects[i];
					if(ro != null && ro.IsOn && ro is Icon)
					{
						Icon icon = (Icon)ro;

						if(icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval)
							continue;

						object key = null;
						IconTexture iconTexture = null;

						if(icon.TextureFileName != null && icon.TextureFileName.Length > 0)
						{
							if(icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null)
							{
								//download it
								try
								{
									WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName);
									webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified;
	
									System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath);
									if(!saveFile.Directory.Exists)
										saveFile.Directory.Create();

									webDownload.DownloadFile(saveFile.FullName);
								}
								catch{}
						
								iconTexture = (IconTexture)m_textures[icon.SaveFilePath];
								if(iconTexture != null)
								{
									IconTexture tempTexture = iconTexture;
									m_textures[icon.SaveFilePath] = new IconTexture( DrawArgs.Device, icon.SaveFilePath );
									tempTexture.Dispose();
								}
								else
								{
									key = icon.SaveFilePath;
									iconTexture = new IconTexture( DrawArgs.Device, icon.SaveFilePath );
									
									// New texture, cache it
									m_textures.Add(key, iconTexture);

									// Use default dimensions if not set
									if(icon.Width==0)
										icon.Width = iconTexture.Width;
									if(icon.Height==0)
										icon.Height = iconTexture.Height;
								}
								
							}
							else
							{
								// Icon image from file
								iconTexture = (IconTexture)m_textures[icon.TextureFileName];
								if(iconTexture != null)
								{
									IconTexture tempTexture = iconTexture;
									m_textures[icon.SaveFilePath] = new IconTexture( DrawArgs.Device, icon.TextureFileName );
									tempTexture.Dispose();
								}
								else
								{
									key = icon.SaveFilePath;
									iconTexture = new IconTexture( DrawArgs.Device, icon.TextureFileName );
									
									// New texture, cache it
									m_textures.Add(key, iconTexture);

									// Use default dimensions if not set
									if(icon.Width==0)
										icon.Width = iconTexture.Width;
									if(icon.Height==0)
										icon.Height = iconTexture.Height;
								}
							}
						}
						else
						{
							// Icon image from bitmap
							if(icon.Image != null)
							{
								iconTexture = (IconTexture)m_textures[icon.Image];
								if(iconTexture != null)
								{
									IconTexture tempTexture = iconTexture;
									m_textures[icon.SaveFilePath] = new IconTexture( DrawArgs.Device, icon.Image );
									tempTexture.Dispose();
								}
								else
								{
									key = icon.SaveFilePath;
									iconTexture = new IconTexture( DrawArgs.Device, icon.Image );
									
									// New texture, cache it
									m_textures.Add(key, iconTexture);

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

						icon.LastRefresh = System.DateTime.Now;
					}
				}
			}
			catch{}
			finally
			{
				isUpdating = false;
			}
		}
Пример #11
0
		public override void Initialize(DrawArgs drawArgs)
		{
			if(!isOn)
				return;

			if(m_sprite != null)
			{
				m_sprite.Dispose();
				m_sprite = null;
			}

			m_sprite = new Sprite(drawArgs.device);

			System.TimeSpan smallestRefreshInterval = System.TimeSpan.MaxValue;

			// Load all textures
			foreach(RenderableObject ro in m_children)
			{
				Icon icon = ro as Icon;
				if(icon==null)
				{
					// Child is not an icon
					if(ro.IsOn)
						ro.Initialize(drawArgs);
					continue;
				}

				if(icon.RefreshInterval.TotalMilliseconds != 0 && icon.RefreshInterval != TimeSpan.MaxValue && icon.RefreshInterval < smallestRefreshInterval)
					smallestRefreshInterval = icon.RefreshInterval;

				// Child is an icon
				icon.Initialize(drawArgs);

				object key = null;
				IconTexture iconTexture = null;

				if(icon.TextureFileName != null && icon.TextureFileName.Length > 0)
				{
					if(icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null)
					{
						//download it
						try
						{
							WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName);
							webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified;
	
							System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath);
							if(!saveFile.Directory.Exists)
								saveFile.Directory.Create();

							webDownload.DownloadFile(saveFile.FullName);
						}
						catch{}
						
						iconTexture = (IconTexture)m_textures[icon.SaveFilePath];
						if(iconTexture==null)
						{
							key = icon.SaveFilePath;
							iconTexture = new IconTexture( drawArgs.device, icon.SaveFilePath );
						}
					}
					else
					{
						// Icon image from file
						iconTexture = (IconTexture)m_textures[icon.TextureFileName];
						if(iconTexture==null)
						{
							key = icon.TextureFileName;
							iconTexture = new IconTexture( drawArgs.device, icon.TextureFileName );
						}
					}
				}
				else
				{
					// Icon image from bitmap
					if(icon.Image != null)
					{
						iconTexture = (IconTexture)m_textures[icon.Image];
						if(iconTexture==null)
						{
							// Create new texture from image
							key = icon.Image;
							iconTexture = new IconTexture( drawArgs.device, icon.Image);
						}
					}
				}

				if(iconTexture==null)
					// No texture set
					continue;

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

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

			// Compute mouse over bounding boxes
			foreach(RenderableObject ro in m_children)
			{
				Icon icon = ro as Icon;
				if(icon==null)
					// Child is not an icon
					continue;

				if(GetTexture(icon)==null)
				{
					// Label only 
					icon.SelectionRectangle = drawArgs.defaultDrawingFont.MeasureString(null, icon.Name, DrawTextFormat.None, 0);
				}
				else
				{
					// Icon only
					icon.SelectionRectangle = new Rectangle( 0,0,icon.Width, icon.Height );
				}

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

			if(refreshTimer == null && smallestRefreshInterval != TimeSpan.MaxValue)
			{
				refreshTimer = new System.Timers.Timer(smallestRefreshInterval.TotalMilliseconds);
				refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(refreshTimer_Elapsed);
				refreshTimer.Start();
			}

			isInitialized = true;
		}
Пример #12
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;

			m_imageName = Path.GetDirectoryName(Application.ExecutablePath) + @"\Plugins\Navigator\world.png";

			// Icon image from file
			m_iconTexture = (IconTexture)DrawArgs.Textures[m_imageName];
			if(m_iconTexture==null)
			{
				key = m_imageName;
				m_iconTexture = new IconTexture( drawArgs.device, m_imageName );
			}

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

				if(key!=null)
				{
					// New texture, cache it
					DrawArgs.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;
		}
Пример #13
0
		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 = (IconTexture)DrawArgs.Textures[m_imageName];
				if(m_iconTexture==null)
				{
					key = m_imageName;
					m_iconTexture = new IconTexture( drawArgs.device, m_imageName );
				}

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

					if(key!=null)
					{
						// New texture, cache it
						DrawArgs.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;
		}
Пример #14
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;

            /// TODO - Make this work the same way as Icons including fetch from URL
 
			// Icon image from file
            m_iconTexture = (IconTexture)DrawArgs.Textures[m_imageName];
			if(m_iconTexture==null)
			{
				key = m_imageName;
				m_iconTexture = new IconTexture( drawArgs.device, m_imageName );
			}

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

				if(key!=null)
				{
					// New texture, cache it
                    DrawArgs.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;
		}
Пример #15
0
		public override void Initialize(DrawArgs drawArgs)
		{
			if(!isOn)
				return;

			if(m_sprite != null)
			{
				m_sprite.Dispose();
				m_sprite = null;
			}
			if(m_groundStick != null)
			{
				m_groundStick.Dispose();
				m_groundStick = null;
			}

			m_sprite = new Sprite(drawArgs.device);
			m_groundStick = new Line(drawArgs.device);

			// Load all textures
			foreach(RenderableObject ro in m_children)
			{
				RIcon icon = ro as RIcon;
				if(icon==null)
				{
					// Child is not an icon
					if(ro.IsOn)
						ro.Initialize(drawArgs);
					continue;
				}

				// Child is an icon
				icon.Initialize(drawArgs);

				object key = null;
				IconTexture iconTexture = null;

				// Icon image from bitmap
				if(icon.Image != null)
				{
					iconTexture = (IconTexture)m_textures[icon.Image];
					if(iconTexture==null)
					{
						// Create new texture from image
						key = icon.Image;
						iconTexture = new IconTexture( drawArgs.device, icon.Image);
					}
				}

				if(iconTexture==null)
					// No texture set
					continue;

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

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

			// Compute mouse over bounding boxes
			foreach(RenderableObject ro in m_children)
			{
				RIcon icon = ro as RIcon;
				if(icon==null)
					// Child is not an icon
					continue;

				if(GetTexture(icon)==null)
				{
					// Label only 
					icon.SelectionRectangle = drawArgs.defaultDrawingFont.MeasureString(null, icon.Name, DrawTextFormat.None, 0);
				}
				else
				{
					// Icon only
					icon.SelectionRectangle = new Rectangle(0, 0, icon.Width, icon.Height);
				}

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

			isInitialized = true;
		}
Пример #16
0
        private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if(isUpdating)
                return;
            isUpdating = true;
            try
            {
                for(int i = 0; i < this.ChildObjects.Count; i++)
                {
                    RenderableObject ro = (RenderableObject)this.ChildObjects[i];
                    if(ro != null && ro.IsOn && ro is Icon)
                    {
                        Icon icon = (Icon)ro;

                        if(icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval)
                            continue;

                        object key = null;
                        IconTexture iconTexture = null;

                        if (icon.TextureFileName != null && icon.TextureFileName.Length > 0)
                        {
                            iconTexture = (IconTexture)DrawArgs.Textures[icon.TextureFileName];
                            if (iconTexture != null)
                            {
                                iconTexture.UpdateTexture(DrawArgs.Device, icon.TextureFileName);
                            }
                            else
                            {
                                key = icon.TextureFileName;
                                iconTexture = new IconTexture(DrawArgs.Device, icon.TextureFileName);

                                iconTexture.ReferenceCount++;

                                // New texture, cache it
                                DrawArgs.Textures.Add(key, iconTexture);

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

                        }
                        else
                        {
                            // Icon image from bitmap
                            if (icon.Image != null)
                            {
                                iconTexture = (IconTexture)DrawArgs.Textures[icon.Image];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    DrawArgs.Textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.Image);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.Image);

                                    // New texture, cache it
                                    DrawArgs.Textures.Add(key, iconTexture);

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

                        icon.LastRefresh = System.DateTime.Now;
                    }
                }
            }
            catch{}
            finally
            {
                isUpdating = false;
            }
        }
Пример #17
0
        private void refreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (isUpdating)
            {
                return;
            }
            isUpdating = true;
            try
            {
                for (int i = 0; i < this.ChildObjects.Count; i++)
                {
                    RenderableObject ro = (RenderableObject)this.ChildObjects[i];
                    if (ro != null && ro.IsOn && ro is Icon)
                    {
                        Icon icon = (Icon)ro;

                        if (icon.RefreshInterval == TimeSpan.MaxValue || icon.LastRefresh > System.DateTime.Now - icon.RefreshInterval)
                        {
                            continue;
                        }

                        object      key         = null;
                        IconTexture iconTexture = null;

                        if (icon.TextureFileName != null && icon.TextureFileName.Length > 0)
                        {
                            if (icon.TextureFileName.ToLower().StartsWith("http://") && icon.SaveFilePath != null)
                            {
                                //download it
                                try
                                {
                                    WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(icon.TextureFileName);
                                    webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified;

                                    System.IO.FileInfo saveFile = new System.IO.FileInfo(icon.SaveFilePath);
                                    if (!saveFile.Directory.Exists)
                                    {
                                        saveFile.Directory.Create();
                                    }

                                    webDownload.DownloadFile(saveFile.FullName);
                                }
                                catch {}

                                iconTexture = (IconTexture)m_textures[icon.SaveFilePath];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.SaveFilePath);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.SaveFilePath);

                                    // New texture, cache it
                                    m_textures.Add(key, iconTexture);

                                    // Use default dimensions if not set
                                    if (icon.Width == 0)
                                    {
                                        icon.Width = iconTexture.Width;
                                    }
                                    if (icon.Height == 0)
                                    {
                                        icon.Height = iconTexture.Height;
                                    }
                                }
                            }
                            else
                            {
                                // Icon image from file
                                iconTexture = (IconTexture)m_textures[icon.TextureFileName];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.TextureFileName);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.TextureFileName);

                                    // New texture, cache it
                                    m_textures.Add(key, iconTexture);

                                    // Use default dimensions if not set
                                    if (icon.Width == 0)
                                    {
                                        icon.Width = iconTexture.Width;
                                    }
                                    if (icon.Height == 0)
                                    {
                                        icon.Height = iconTexture.Height;
                                    }
                                }
                            }
                        }
                        else
                        {
                            // Icon image from bitmap
                            if (icon.Image != null)
                            {
                                iconTexture = (IconTexture)m_textures[icon.Image];
                                if (iconTexture != null)
                                {
                                    IconTexture tempTexture = iconTexture;
                                    m_textures[icon.SaveFilePath] = new IconTexture(DrawArgs.Device, icon.Image);
                                    tempTexture.Dispose();
                                }
                                else
                                {
                                    key         = icon.SaveFilePath;
                                    iconTexture = new IconTexture(DrawArgs.Device, icon.Image);

                                    // New texture, cache it
                                    m_textures.Add(key, iconTexture);

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

                        icon.LastRefresh = System.DateTime.Now;
                    }
                }
            }
            catch {}
            finally
            {
                isUpdating = false;
            }
        }
Пример #18
0
        public override void Initialize(DrawArgs drawArgs)
        {
            if (!isOn)
            {
                return;
            }

            System.TimeSpan smallestRefreshInterval = System.TimeSpan.MaxValue;

            if (!isInitialized)
            {
                if (m_sprite != null)
                {
                    m_sprite.Dispose();
                    m_sprite = null;
                }

                // init Icons layer
                m_sprite = new Sprite(drawArgs.device);

                string textureFilePath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), @"Data\Icons\sol_wh.gif");

                m_pointTexture = new IconTexture(drawArgs.device, textureFilePath);

                // if the device can't do point sprites don't use them
                if (drawArgs.device.DeviceCaps.MaxPointSize == 1)
                {
                    m_canUsePointSprites = false;
                }
                else
                {
                    m_canUsePointSprites = true;
                }
            }

            // figure out refresh period
            m_childrenRWLock.AcquireReaderLock(Timeout.Infinite);
            try
            {
                foreach (RenderableObject ro in m_children)
                {
                    Icon icon = ro as Icon;
                    if (icon != null)
                    {
                        if (icon.RefreshInterval.TotalMilliseconds != 0 && icon.RefreshInterval != TimeSpan.MaxValue && icon.RefreshInterval < smallestRefreshInterval)
                        {
                            smallestRefreshInterval = icon.RefreshInterval;
                        }
                    }
                }
            }
            finally
            {
                m_childrenRWLock.ReleaseReaderLock();
            }


            if (refreshTimer == null && smallestRefreshInterval != TimeSpan.MaxValue)
            {
                refreshTimer          = new System.Timers.Timer(smallestRefreshInterval.TotalMilliseconds);
                refreshTimer.Elapsed += new System.Timers.ElapsedEventHandler(refreshTimer_Elapsed);
                refreshTimer.Start();
            }

            isInitialized = true;
        }
Пример #19
0
        protected override void Render(DrawArgs drawArgs, Icon icon, Vector3 projectedPoint)
        {
            if (!icon.Initialized)
            {
                icon.Initialize(drawArgs);
                return;
            }
            if (!drawArgs.WorldCamera.ViewFrustum.ContainsPoint(icon.Position))
            {
                return;
            }

            // check whether in icon's visual range.
            float distanceToIcon = Vector3.Length(icon.Position - drawArgs.WorldCamera.Position);

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

            IconTexture iconTexture = this.GetTexture(icon);
            // check is mouse over.
            bool isMouseOver = (icon == this.mouseOverIcon);

            if (isMouseOver)
            {
                if (icon.IsSelectable)
                {
                    DrawArgs.MouseCursor = CursorType.Hand;
                }

                // get icon's description.
                string description = icon.Description;
                if (description == null)
                {
                    description = icon.ClickableActionURL;
                }

                if (description != null)
                {
                    // Render the description field.
                    DrawTextFormat descTextFormat = DrawTextFormat.NoClip;
                    descTextFormat |= DrawTextFormat.WordBreak;
                    descTextFormat |= DrawTextFormat.Bottom;

                    int left = 10;
                    //if (World.Settings.ShowLayerManager) {
                    //   left += World.Settings.LayerManagerWidth;
                    //}
                    Rectangle descRectangle = Rectangle.FromLTRB(left, 10, drawArgs.ScreenWidth - 10, drawArgs.ScreenHeight - 10);

                    // Draw outline
                    this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, description, ref descRectangle, descTextFormat);

                    // Draw description
                    drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, description, descRectangle, descTextFormat, descriptionColor);
                }
            }

            int color = isMouseOver ? hotColor : normalColor;
            // calculate scale
            double scale = (drawArgs.WorldCamera.WorldRadius + icon.Altitude) / (drawArgs.WorldCamera.WorldRadius + distanceToIcon);

            scale *= drawArgs.WorldCamera.TargetDistance / distanceToIcon;
            //
            // render name field.
            if (icon.Name != null)
            {
                Rectangle nameRectangle = drawArgs.DefaultDrawingFont.MeasureString(this.m_sprite, icon.Name, DrawTextFormat.Center, color);
                nameRectangle.X = (int)projectedPoint.X - (nameRectangle.Width >> 1);
                if (iconTexture == null)
                {
                    // by zzm start
                    nameRectangle.Y = (int)projectedPoint.Y - (drawArgs.DefaultDrawingFont.Description.Height >> 1);
                    // by zzm end
                    this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, icon.Name, ref nameRectangle, DrawTextFormat.Center);
                    drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, icon.Name, nameRectangle, DrawTextFormat.Center, color);
                }
                else
                {
                    // adjust text to make room for icon.
                    int spacing       = 10;
                    int offsetForIcon = (int)(icon.Height * scale) + spacing;
                    nameRectangle.Y = (int)projectedPoint.Y - offsetForIcon - (drawArgs.DefaultDrawingFont.Description.Height >> 1);
                    this.DrawOutline(drawArgs.DefaultDrawingFont, this.m_sprite, icon.Name, ref nameRectangle, DrawTextFormat.Center);
                    drawArgs.DefaultDrawingFont.DrawText(this.m_sprite, icon.Name, nameRectangle, DrawTextFormat.Center, color);
                }
            }

            if (iconTexture != null)
            {
                // render icon
                // get icon's current scale
                float xScale = (float)scale;                  //icon.Width / iconTexture.Width;
                float yScale = (float)scale;                  //icon.Height / iconTexture.Height;
                this.m_sprite.Transform  = Matrix.Scaling(xScale, yScale, 0);
                this.m_sprite.Transform *= Matrix.Translation(projectedPoint.X, projectedPoint.Y, 0);
                this.m_sprite.Draw(iconTexture.Texture, new Vector3(iconTexture.Width, iconTexture.Height, 0), Vector3.Empty, color);
                this.m_sprite.Transform = Matrix.Identity;
            }
        }
Пример #20
0
        public override void Initialize(DrawArgs drawArgs)
        {
            // get icon texture
            m_iconTexture = null;

            BuildIconTexture(drawArgs);

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

                if (m_groundStickVector == null)
                    m_groundStickVector = new Vector2[2];
            }

            m_isUpdated = false;
            Update(drawArgs);

            isInitialized = true;
        }