Пример #1
0
        private IImage GetImageFromSkinFolder(string imageName)
        {
            try
            {
                string   skinFolderPath = _skinFolderPath + "\\" + _skinName + "\\" + _subDataPrefix;
                string[] files          = null;
                if (Directory.Exists(skinFolderPath))
                {
                    files = Directory.GetFiles(skinFolderPath, imageName + ".*");
                }
                if (files != null && files.Length > 0)
                {
                    IImage img;
                    _imagingFactory.CreateImageFromFile(files[0], out img);
                    return(img);
                }
                else
                {
                    skinFolderPath = _skinFolderPath + "\\" + _skinName;
                    files          = Directory.GetFiles(skinFolderPath, imageName + ".*");
                    if (files.Length > 0)
                    {
                        IImage img;
                        _imagingFactory.CreateImageFromFile(files[0], out img);
                        return(img);
                    }
                }
            }
            catch (Exception)
            {
            }

            return(null);
        }
Пример #2
0
        protected void ChangeImage()
        {
            if (this._picture != null)
            {
                this._picture = null;
            }
            try
            {
                IImagingFactory factory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
                factory.CreateImageFromFile(this.Image, out this._picture);
                this.thumb = null;
            }
            catch
            {
                return;
            }

            this.Refresh();
        }
Пример #3
0
        /// <summary>
        /// This event occurs when specific parts of the task ListView are to be drawn.
        /// </summary>
        /// <param name="hdc"></param>
        /// <param name="item"></param>
        /// <param name="subitem"></param>
        /// <param name="selected"></param>
        /// <param name="rect"></param>
        void Handler_DrawEvent(IntPtr hdc, int item, int subitem, bool selected, RectangleF rect)
        {
            var task = (TaskItem)lsvTasks.Items[item].Tag;

            using (var graphics = Graphics.FromHdc(hdc))
            {
                switch (subitem)
                {
                case -1:
                    // This is the prepaint event for the entire item.

                    if (selected)
                    {
                        if (Theming.ListSelectionRectangleImage != null)
                        {
                            // Draw the selection rectangle image, since we have one.
                            graphics.DrawImageAlphaChannel(Theming.ListSelectionRectangleImage, new Rectangle((int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1));
                        }
                        else if (Theming.ListSelectionRectangleColor.HasValue)
                        {
                            using (var bg = new SolidBrush(Theming.ListSelectionRectangleColor.Value))
                            {
                                // Draw the selection rectangle solid color, since we have that, but no image.
                                graphics.FillRectangle(bg, (int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1);
                            }
                        }
                    }
                    else     // not selected
                    {
                        if (Theming.ListItemBackgroundImage != null)
                        {
                            // Draw the deselected rectangle image, since we have one.
                            graphics.DrawImageAlphaChannel(Theming.ListItemBackgroundImage, new Rectangle((int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1));
                        }
                        else if (Theming.ListItemBackgroundColor.HasValue)
                        {
                            using (var bg = new SolidBrush(Theming.ListItemBackgroundColor.Value))
                            {
                                // Draw the deselected rectangle solid color, since we have that, but no image.
                                graphics.FillRectangle(bg, (int)rect.X, (int)rect.Y + 1, (int)rect.Width, (int)rect.Height - 1);
                            }
                        }
                    }
                    break;

                case 0:
                    // The first item is the application icon.

                    try
                    {
                        // If we're using Start menu icons, then try to get the one for the current task.
                        var customIcon = _usingStartIcons ? StartIconMgmt.GetCustomIconPathForExe(task.ExePath) : null;
                        if (customIcon != null && File.Exists(customIcon))
                        {
                            // Retrieve it.
                            IImage img;
                            ImgFactory.CreateImageFromFile(customIcon, out img);
                            ImageInfo info;
                            img.GetImageInfo(out info);
                            var imgSize = new Size((int)info.Width, (int)info.Height);

                            // Draw it.
                            graphics.DrawImageAlphaChannel(img, Misc.CalculateCenteredScaledDestRect(rect, imgSize, false));
                        }
                        else
                        {
                            // Get the icon from the EXE itself.
                            var icon = ExeIconMgmt.GetIconForExe(task.ExePath, true);
                            if (icon != null)
                            {
                                if (icon.Height <= rect.Height && icon.Width <= rect.Width)
                                {
                                    // If the icon is smaller or equal to the size of the space we have for it, just draw it directly, in the center.
                                    graphics.DrawIcon(icon, (int)rect.Width / 2 - icon.Width / 2 + (int)rect.X, (int)rect.Height / 2 - icon.Height / 2 + (int)rect.Y);
                                }
                                else
                                {
                                    // The icon is too big, so we have to resize it. Since there is no method provided to draw resized icons, we need a bitmap instead.

                                    // Get the bitmap representation of the icon.
                                    var bmp = ExeIconMgmt.GetBitmapFromIcon(icon, true);
                                    // Draw the bitmap, resizing it (and keeping the aspect ratio).
                                    graphics.DrawImage(bmp, Misc.CalculateCenteredScaledDestRect(rect, bmp.Size, false), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
                                    bmp.Dispose();
                                }
                            }
                            else
                            {
                                // Draw the generic application icon.
                                graphics.DrawImageAlphaChannel(NoIconImage, Misc.CalculateCenteredScaledDestRect(rect, NoIconImageSize, false));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            "An error has occurred. ArkSwitch will try to continue. Please report this!" +
                            Environment.NewLine + "Error: " + ex.Message);
                    }
                    break;

                case 1:
                    // The second item is the task title and memory info.

                    // Generate the strings, determine their sizes, etc...
                    var infoString     = Path.GetFileName(task.ExePath);
                    var nameStringSize = graphics.MeasureString(task.Title, TaskListMainFont);
                    var infoStringSize = graphics.MeasureString(infoString, TaskListSubFont);
                    var combinedHeight = nameStringSize.Height + infoStringSize.Height + 1;
                    var y         = rect.Height / 2 - combinedHeight / 2 + rect.Y;
                    var titleRect = new RectangleF(rect.X + 2, y, rect.Width - 2, nameStringSize.Height);
                    var infoRect  = new RectangleF(rect.X + 2, y + nameStringSize.Height + 1, rect.Width - 2, infoStringSize.Height);

                    // Draw the strings.
                    using (var brushPrimary = new SolidBrush(selected ? Theming.ListTextColorPrimarySelected : Theming.ListTextColorPrimary))
                        using (var brushSecondary = new SolidBrush(selected ? Theming.ListTextColorSecondarySelected : Theming.ListTextColorSecondary))
                        {
                            graphics.DrawString(task.Title, TaskListMainFont, brushPrimary, titleRect, TaskListStringFormat);
                            graphics.DrawString(infoString, TaskListSubFont, brushSecondary, infoRect, TaskListStringFormat);
                        }

                    break;

                case 2:
                    // The third item is the X icon.

                    var modRect  = new Rectangle((int)rect.X + 2, (int)rect.Y + 2, (int)rect.Width - 4, (int)rect.Height - 4);
                    var xImg     = selected ? Theming.XSelectedImage : Theming.XDeselectedImage;
                    var xImgSize = selected ? Theming.XSelectedImageSize : Theming.XDeselectedImageSize;
                    graphics.DrawImageAlphaChannel(xImg, Misc.CalculateCenteredScaledDestRect(modRect, xImgSize, true));
                    break;
                }
            }
        }
Пример #4
0
        protected override List <NativeItemData> BuildNativeControlItems()
        {
            var retVal = new List <NativeItemData>(Items.Count);

            if (Items != null)
            {
                for (int i = 0; i < Items.Count; i++)
                {
                    IImagingFactory newImagingFactory = ImagingFactory.GetImaging();

                    IImage newIImage;

                    if (Items[i].IsAvatarLoaded)
                    {
                        newImagingFactory.CreateImageFromFile(Items[i].Avatar, out newIImage);
                    }
                    else
                    {
                        newIImage = MasterForm.SkinManager.GetImage("AvatarStub");
                    }

                    NativeItemData newNativeItemData = new KineticListView <WallPostListViewItem> .NativeItemData
                    {
                        PrimaryText   = Items[i].UserName,
                        SecondaryText = Items[i].Status,
                        TertiaryText  = Items[i].StatusChangeDate,

                        PrimaryImage = newIImage,

                        InfoLeftIndents = new int[2],
                        InfoTopIndents  = new int[1]
                    };

                    retVal.Add(newNativeItemData);
                }
            }

            #region старая версия
            //if (Items != null)
            //{
            //    for (int i = 0; i < Items.Count; i++)
            //    {
            //        IImagingFactory iImagingFactory = ImagingFactory.GetImaging();

            //        //Привязка аватарки пользователя, если она еще не загружена, выводится заглушка
            //        IImage primaryImage;
            //        if (Items[i].IsAvatarLoaded)
            //            iImagingFactory.CreateImageFromFile(Items[i].Avatar, out primaryImage);
            //        else
            //            primaryImage = MasterForm.SkinManager.GetImage("AvatarStub");

            //        //Значек подарка или online
            //        /*
            //        IImage secondaryImage;
            //        if (Items[i].IsBirthday)
            //            secondaryImage = MasterForm.SkinManager.GetImage("Birthday");
            //        else if (Items[i].StatusOnline)
            //            secondaryImage = MasterForm.SkinManager.GetImage("Online");
            //        else secondaryImage = null;
            //        */

            //        //Статус пользователя
            //        string status = Items[i].Status;
            //        NativeItemData data = new NativeItemData
            //        {
            //            PrimaryText = Items[i].Name,
            //            SecondaryText = status,
            //            Tag = Items[i].Name,
            //            PrimaryImage = primaryImage,
            //            //SecondaryImage = secondaryImage,
            //            InfoLeftIndents = new int[2],
            //            InfoTopIndents = new int[1]
            //        };
            //        retVal.Add(data);
            //    }
            //}
            #endregion

            return(retVal);
        }