Ejemplo n.º 1
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());
            }
        }
Ejemplo n.º 2
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;
            }
        }