Пример #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
        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;
        }
Пример #5
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;
            }
        }
Пример #6
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;
        }