2018-02-06 13:15:06 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2022-01-12 05:32:17 +13:00
|
|
|
|
Copyright (c) 2007-2022 ShareX Team
|
2018-02-06 13:15:06 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using Manina.Windows.Forms;
|
2018-03-01 11:52:11 +13:00
|
|
|
|
using ShareX.HelpersLib;
|
2018-02-06 13:15:06 +13:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX.ScreenCaptureLib
|
|
|
|
|
{
|
2020-01-16 23:51:14 +13:00
|
|
|
|
public class StickerImageListViewRenderer : ImageListView.ImageListViewRenderer
|
2018-02-06 13:15:06 +13:00
|
|
|
|
{
|
|
|
|
|
public override void InitializeGraphics(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
base.InitializeGraphics(g);
|
|
|
|
|
|
|
|
|
|
ItemDrawOrder = ItemDrawOrder.NormalSelectedHovered;
|
2018-02-06 19:49:08 +13:00
|
|
|
|
|
2020-01-16 23:51:14 +13:00
|
|
|
|
ImageListView.Colors.SelectedColor1 = ImageListView.Colors.HoverColor1 = ImageListView.Colors.UnFocusedColor1 = Color.FromArgb(252, 221, 132);
|
|
|
|
|
ImageListView.Colors.SelectedColor2 = ImageListView.Colors.HoverColor2 = ImageListView.Colors.UnFocusedColor2 = Color.Transparent;
|
|
|
|
|
|
2020-05-22 17:44:02 +12:00
|
|
|
|
if (ShareXResources.UseCustomTheme)
|
2020-01-16 23:51:14 +13:00
|
|
|
|
{
|
|
|
|
|
ImageListView.BackColor = ShareXResources.Theme.BackgroundColor;
|
|
|
|
|
ImageListView.Colors.BackColor = ShareXResources.Theme.LightBackgroundColor;
|
|
|
|
|
ImageListView.Colors.BorderColor = ShareXResources.Theme.BorderColor;
|
|
|
|
|
ImageListView.Colors.ForeColor = ShareXResources.Theme.TextColor;
|
|
|
|
|
ImageListView.Colors.SelectedForeColor = ShareXResources.Theme.TextColor;
|
|
|
|
|
ImageListView.Colors.UnFocusedForeColor = ShareXResources.Theme.TextColor;
|
|
|
|
|
}
|
2018-02-06 13:15:06 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
|
|
|
|
|
{
|
|
|
|
|
Clip = false;
|
|
|
|
|
|
|
|
|
|
Size itemPadding = new Size(4, 4);
|
|
|
|
|
Rectangle imageBounds = bounds;
|
|
|
|
|
|
|
|
|
|
string text = Path.GetFileNameWithoutExtension(item.Text);
|
|
|
|
|
Size szt = TextRenderer.MeasureText(text, ImageListView.Font);
|
2018-05-17 01:27:11 +12:00
|
|
|
|
int textWidth = szt.Width + (itemPadding.Width * 2);
|
2018-02-06 13:15:06 +13:00
|
|
|
|
|
|
|
|
|
if ((state & ItemState.Hovered) != ItemState.None && textWidth > bounds.Width)
|
|
|
|
|
{
|
2018-05-17 01:27:11 +12:00
|
|
|
|
bounds = new Rectangle(bounds.X + (bounds.Width / 2) - (textWidth / 2), bounds.Y, textWidth, bounds.Height);
|
2018-02-06 13:15:06 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Paint background
|
|
|
|
|
if (ImageListView.Enabled)
|
|
|
|
|
{
|
|
|
|
|
using (Brush bItemBack = new SolidBrush(ImageListView.Colors.BackColor))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(bItemBack, bounds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (Brush bItemBack = new SolidBrush(ImageListView.Colors.DisabledBackColor))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(bItemBack, bounds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((state & ItemState.Disabled) != ItemState.None) // Paint background Disabled
|
|
|
|
|
{
|
|
|
|
|
using (Brush bDisabled = new LinearGradientBrush(bounds.Offset(1), ImageListView.Colors.DisabledColor1, ImageListView.Colors.DisabledColor2, LinearGradientMode.Vertical))
|
|
|
|
|
{
|
2020-01-16 23:51:14 +13:00
|
|
|
|
g.FillRectangle(bDisabled, bounds);
|
2018-02-06 13:15:06 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) ||
|
|
|
|
|
(!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None))) // Paint background Selected
|
|
|
|
|
{
|
|
|
|
|
using (Brush bSelected = new LinearGradientBrush(bounds.Offset(1), ImageListView.Colors.SelectedColor1, ImageListView.Colors.SelectedColor2, LinearGradientMode.Vertical))
|
|
|
|
|
{
|
2020-01-16 23:51:14 +13:00
|
|
|
|
g.FillRectangle(bSelected, bounds);
|
2018-02-06 13:15:06 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) // Paint background unfocused
|
|
|
|
|
{
|
|
|
|
|
using (Brush bGray64 = new LinearGradientBrush(bounds.Offset(1), ImageListView.Colors.UnFocusedColor1, ImageListView.Colors.UnFocusedColor2, LinearGradientMode.Vertical))
|
|
|
|
|
{
|
2020-01-16 23:51:14 +13:00
|
|
|
|
g.FillRectangle(bGray64, bounds);
|
2018-02-06 13:15:06 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Paint background Hovered
|
|
|
|
|
if ((state & ItemState.Hovered) != ItemState.None)
|
|
|
|
|
{
|
|
|
|
|
using (Brush bHovered = new LinearGradientBrush(bounds.Offset(1), ImageListView.Colors.HoverColor1, ImageListView.Colors.HoverColor2, LinearGradientMode.Vertical))
|
|
|
|
|
{
|
2020-01-16 23:51:14 +13:00
|
|
|
|
g.FillRectangle(bHovered, bounds);
|
2018-02-06 13:15:06 +13:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw the image
|
|
|
|
|
Image img = item.GetCachedImage(CachedImageType.Thumbnail);
|
|
|
|
|
if (img != null)
|
|
|
|
|
{
|
|
|
|
|
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(imageBounds.Location + itemPadding, ImageListView.ThumbnailSize));
|
|
|
|
|
g.DrawImage(img, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw item text
|
|
|
|
|
Color foreColor = ImageListView.Colors.ForeColor;
|
|
|
|
|
if ((state & ItemState.Disabled) != ItemState.None)
|
|
|
|
|
{
|
|
|
|
|
foreColor = ImageListView.Colors.DisabledForeColor;
|
|
|
|
|
}
|
|
|
|
|
else if ((state & ItemState.Selected) != ItemState.None)
|
|
|
|
|
{
|
|
|
|
|
if (ImageListView.Focused)
|
|
|
|
|
{
|
|
|
|
|
foreColor = ImageListView.Colors.SelectedForeColor;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreColor = ImageListView.Colors.UnFocusedForeColor;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-17 01:27:11 +12:00
|
|
|
|
Rectangle rt = new Rectangle(bounds.Left, bounds.Top + (2 * itemPadding.Height) + ImageListView.ThumbnailSize.Height, bounds.Width, szt.Height);
|
2018-02-06 13:15:06 +13:00
|
|
|
|
TextFormatFlags flags;
|
|
|
|
|
|
|
|
|
|
if ((state & ItemState.Hovered) != ItemState.None)
|
|
|
|
|
{
|
|
|
|
|
flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.NoClipping;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
flags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | TextFormatFlags.WordEllipsis;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextRenderer.DrawText(g, text, ImageListView.Font, rt, foreColor, flags);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|