Ejemplo n.º 1
0
        // Callback from VolumeDetector
        public void AudioChanged(DeviceInfo info)
        {
            // Windows7 sometimes triggers callback when volume hasn't changed.
            if (lastInfo != null)
            {
                if (info.Muted == lastInfo.Muted && info.Volume == lastInfo.Volume )
                    return;
            }
            lastInfo = info;

            try
            {
                this.Opacity = settings.Opacity + _Opacity;
                if (this.Visible == false)
                    this.Visible = true; // throw in preview

                // Manually draw the image to get the transparency
                string image = ResolveImage(info, settings, BasePath);
                System.Drawing.Image actualImage = System.Drawing.Image.FromFile(image);
                ImageAttributes attr = new ImageAttributes();
                Rectangle dstRect = new Rectangle(0, 0, actualImage.Width, actualImage.Height);
                CreateGraphics().DrawImage(actualImage, dstRect, 0, 0, actualImage.Width, actualImage.Height,
                    GraphicsUnit.Pixel, attr);

                System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(WaitAndHide));
                lastMove = System.DateTime.Now;
                t.Start();
            }
            catch (ObjectDisposedException)
            {
                // In preview we recieved a callback from an item that we cannot
                // access
                return;
            }
        }
Ejemplo n.º 2
0
        // Resolve the image that the device info corresponds to
        private string ResolveImage(DeviceInfo info, DisplaySettings settings, string basePath)
        {
            if (info.Muted)
                return basePath + settings.Images[0].ImageName;

            int images = settings.Images.Count;
            images--; // take into account the mute item

            double interval = (double)1 / (double)images;
            double estimatedItem = info.Volume / interval;
            int imageNumber = System.Convert.ToInt32(System.Math.Round(estimatedItem));
            return basePath + settings.Images[System.Math.Min(images, imageNumber + 1)].ImageName;
        }