2016-12-22 15:04:40 +00:00
|
|
|
|
#region ================== Namespaces
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
2017-01-09 04:47:58 +00:00
|
|
|
|
using System.Drawing.Drawing2D;
|
2017-02-08 16:36:40 +00:00
|
|
|
|
using System.Text;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
#region ================== mxd. ImageBrowserItemType
|
|
|
|
|
|
|
|
|
|
internal enum ImageBrowserItemType
|
2009-04-19 18:07:22 +00:00
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
// Values order is used when sorting ImageBrowserItems!
|
|
|
|
|
FOLDER_UP,
|
|
|
|
|
FOLDER,
|
|
|
|
|
IMAGE,
|
|
|
|
|
}
|
2014-11-25 11:52:01 +00:00
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
#endregion
|
2014-11-25 11:52:01 +00:00
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
internal class ImageBrowserItem : IComparable<ImageBrowserItem>
|
|
|
|
|
{
|
2009-04-19 18:07:22 +00:00
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
protected ImageData icon;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
private bool imageloaded;
|
2016-12-22 15:04:40 +00:00
|
|
|
|
private bool showfullname;
|
|
|
|
|
protected ImageBrowserItemType itemtype;
|
|
|
|
|
private string tooltip;
|
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
private static Brush bgbrush, fgbrush_used, fgbrush_unused, selectedbgbrush, selectionbrush, selectiontextbrush, bgbrush_alpha;
|
|
|
|
|
private static Color bgcolor;
|
|
|
|
|
private static Pen selection, frame_used, frame_unused;
|
|
|
|
|
private static StringBuilder size_builder;
|
|
|
|
|
private static Font pixelSizeFont;
|
|
|
|
|
|
2020-04-05 13:15:34 +00:00
|
|
|
|
private static readonly Font messageBoxFont = SystemFonts.MessageBoxFont;
|
2020-04-05 15:40:14 +00:00
|
|
|
|
private static readonly int messageBoxFontHeight = messageBoxFont.Height;
|
2020-04-05 13:15:34 +00:00
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
#endregion
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
2020-04-05 13:15:34 +00:00
|
|
|
|
#region ================== Properties
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
2020-04-05 13:15:34 +00:00
|
|
|
|
public ImageData Icon { get { return icon; } }
|
2016-12-22 15:04:40 +00:00
|
|
|
|
public ImageBrowserItemType ItemType { get { return itemtype; } }
|
2016-12-23 12:39:09 +00:00
|
|
|
|
public virtual bool IsPreviewLoaded { get { return icon.IsPreviewLoaded; } }
|
2017-04-03 17:40:51 +00:00
|
|
|
|
public bool ShowFullName { set { showfullname = value; } get { return showfullname && (!(icon is PK3FileImage) || !((PK3FileImage)icon).IsBadForLongTextureNames); } }
|
|
|
|
|
public virtual string TextureName { get { return (ShowFullName ? icon.Name : icon.ShortName); } }
|
2019-05-30 22:20:12 +00:00
|
|
|
|
public virtual int TextureNameWidth { get { return ShowFullName ? icon.NameWidth : icon.ShortNameWidth; } } // biwa
|
2016-12-22 15:04:40 +00:00
|
|
|
|
public string ToolTip { get { return tooltip; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
#region ================== Constructor
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
|
|
// Constructors
|
2016-12-22 15:04:40 +00:00
|
|
|
|
protected ImageBrowserItem() { } //mxd. Needed for inheritance...
|
|
|
|
|
public ImageBrowserItem(ImageData icon, string tooltip, bool showfullname)
|
2009-04-19 18:07:22 +00:00
|
|
|
|
{
|
|
|
|
|
// Initialize
|
2016-12-22 15:04:40 +00:00
|
|
|
|
this.icon = icon;
|
|
|
|
|
this.itemtype = ImageBrowserItemType.IMAGE; //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
|
this.showfullname = showfullname; //mxd
|
2016-12-22 15:04:40 +00:00
|
|
|
|
this.imageloaded = icon.IsPreviewLoaded; //mxd
|
|
|
|
|
this.tooltip = tooltip; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
|
#endregion
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
|
#region ================== Methods
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
|
|
internal bool CheckRedrawNeeded()
|
2009-04-19 18:07:22 +00:00
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
if(icon.IsPreviewLoaded != imageloaded)
|
|
|
|
|
{
|
|
|
|
|
imageloaded = icon.IsPreviewLoaded;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
internal static void SetBrushes(bool classicview, int x, int y, int w, int h)
|
|
|
|
|
{
|
|
|
|
|
if (size_builder == null)
|
|
|
|
|
{
|
|
|
|
|
size_builder = new StringBuilder(11); // 11 for 2 parens + 1 'x' + 4 * 2 numbers
|
|
|
|
|
}
|
2017-02-01 17:10:22 +00:00
|
|
|
|
// Pick colors and brushes
|
2017-02-08 16:36:40 +00:00
|
|
|
|
if (General.Settings.BlackBrowsers)
|
|
|
|
|
{
|
|
|
|
|
bgcolor = Color.Black;
|
|
|
|
|
bgbrush = Brushes.Black;
|
|
|
|
|
fgbrush_used = Brushes.Orange;
|
|
|
|
|
fgbrush_unused = Brushes.White;
|
2017-01-09 04:47:58 +00:00
|
|
|
|
|
|
|
|
|
if (!classicview)
|
|
|
|
|
{
|
|
|
|
|
selectedbgbrush = Brushes.Gray;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-08 16:36:40 +00:00
|
|
|
|
// FIXME - ano - okay this is a bit off
|
2017-02-08 16:58:13 +00:00
|
|
|
|
// [ZZ] this is not "a bit" off. this is completely off. especially when items have different sizes.
|
|
|
|
|
// moved to item drawing.
|
2017-01-09 04:47:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
frame_used = Pens.Orange;
|
|
|
|
|
frame_unused = Pens.Gray;
|
|
|
|
|
selection = Pens.Red;
|
|
|
|
|
selectionbrush = Brushes.Red;
|
|
|
|
|
selectiontextbrush = Brushes.White;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bgcolor = SystemColors.Window;
|
|
|
|
|
bgbrush = SystemBrushes.Window;
|
|
|
|
|
fgbrush_used = SystemBrushes.HotTrack;
|
|
|
|
|
fgbrush_unused = SystemBrushes.ControlText;
|
2017-01-09 04:47:58 +00:00
|
|
|
|
|
|
|
|
|
if (!classicview)
|
|
|
|
|
{
|
|
|
|
|
selectedbgbrush = SystemBrushes.Highlight;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-08 16:58:13 +00:00
|
|
|
|
selectedbgbrush = null;
|
2017-01-09 04:47:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
frame_used = SystemPens.HotTrack;
|
|
|
|
|
frame_unused = SystemPens.ActiveBorder;
|
|
|
|
|
selection = SystemPens.HotTrack;
|
|
|
|
|
selectionbrush = SystemBrushes.HotTrack;
|
|
|
|
|
selectiontextbrush = SystemBrushes.Window;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bgbrush_alpha = new SolidBrush(Color.FromArgb(192, bgcolor));
|
|
|
|
|
|
|
|
|
|
if (General.Settings.TextureSizesBelow)
|
|
|
|
|
{
|
2020-04-05 13:15:34 +00:00
|
|
|
|
pixelSizeFont = new Font(messageBoxFont.FontFamily, messageBoxFont.Size * 0.8f, FontStyle.Regular);
|
2017-02-08 16:36:40 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-04-05 13:15:34 +00:00
|
|
|
|
pixelSizeFont = messageBoxFont;
|
2017-02-08 16:36:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void Draw(Graphics g, Image bmp, int x, int y, int w, int h, bool selected, bool used, bool classicview)
|
|
|
|
|
{
|
|
|
|
|
if(bmp == null) return;
|
|
|
|
|
|
2020-04-05 15:40:14 +00:00
|
|
|
|
int fontH = 4 + messageBoxFontHeight;
|
2017-02-08 16:36:40 +00:00
|
|
|
|
int h2 = h;
|
2017-02-08 17:21:17 +00:00
|
|
|
|
if (General.Settings.ShowTextureSizes && General.Settings.TextureSizesBelow && ItemType == ImageBrowserItemType.IMAGE)
|
2017-02-08 16:36:40 +00:00
|
|
|
|
h2 -= fontH;
|
|
|
|
|
|
|
|
|
|
var iw = bmp.Width;
|
|
|
|
|
var ih = bmp.Height;
|
|
|
|
|
|
|
|
|
|
if(iw > w && iw >= ih)
|
|
|
|
|
{
|
|
|
|
|
ih = (int)Math.Floor(h * (ih / (float)iw));
|
|
|
|
|
iw = w;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
}
|
2017-02-08 16:36:40 +00:00
|
|
|
|
else if(ih > h2)
|
|
|
|
|
{
|
|
|
|
|
iw = (int)Math.Floor(w * (iw / (float)ih));
|
|
|
|
|
ih = h2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ix = (iw < w ? x + (w - iw) / 2 : x);
|
|
|
|
|
int iy = (ih < h2 ? y + (h2 - ih) / 2 : y);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
// Item bg
|
2020-04-05 15:40:14 +00:00
|
|
|
|
g.FillRectangle(bgbrush, x - 2, y - 2, w + 3, h + 8 + messageBoxFontHeight);
|
2014-12-03 09:06:05 +00:00
|
|
|
|
|
2017-01-09 04:47:58 +00:00
|
|
|
|
// Selected image bg
|
|
|
|
|
if (selected)
|
|
|
|
|
{
|
|
|
|
|
if (!classicview)
|
|
|
|
|
{
|
2020-04-05 15:40:14 +00:00
|
|
|
|
g.FillRectangle(selectedbgbrush, x - 2, y - 2, w + 4, h + 2 + messageBoxFontHeight);
|
2017-01-09 04:47:58 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-08 16:58:13 +00:00
|
|
|
|
// calculate selectedbgbrush here. once.
|
|
|
|
|
Color topselected = Color.FromArgb(255, 37, 67, 151);
|
|
|
|
|
Color bottomselected = Color.FromArgb(255, 1, 20, 83);
|
|
|
|
|
selectedbgbrush = new LinearGradientBrush(new Point(x - 2, y - 3), new Point(x - 2, y + h + fontH), topselected, bottomselected);
|
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
g.FillRectangle(selectedbgbrush, x - 13, y - 2, w + 26, h + fontH);
|
2017-01-09 04:47:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-12 21:05:01 +00:00
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
// Image
|
|
|
|
|
g.DrawImage(bmp, ix, iy, iw, ih);
|
|
|
|
|
|
|
|
|
|
// Frame
|
2017-01-09 04:47:58 +00:00
|
|
|
|
if(selected && !classicview)
|
2014-12-03 09:06:05 +00:00
|
|
|
|
{
|
2017-02-01 17:10:22 +00:00
|
|
|
|
g.DrawRectangle(selection, x - 1, y - 1, w + 1, h2 + 1);
|
|
|
|
|
g.DrawRectangle(selection, x - 2, y - 2, w + 3, h2 + 3);
|
2016-12-23 12:39:09 +00:00
|
|
|
|
|
|
|
|
|
// Image name bg
|
2020-04-05 15:40:14 +00:00
|
|
|
|
g.FillRectangle(selectionbrush, x - 2, y + h2 + 2, w + 4, messageBoxFontHeight + (General.Settings.TextureSizesBelow ? fontH : 0));
|
2016-12-22 15:04:40 +00:00
|
|
|
|
}
|
2017-01-09 04:47:58 +00:00
|
|
|
|
else if (!classicview)
|
2016-12-22 15:04:40 +00:00
|
|
|
|
{
|
2017-02-08 16:36:40 +00:00
|
|
|
|
g.DrawRectangle(used ? frame_used : frame_unused , x - 1, y - 1, w + 1, h2 + 1);
|
2014-12-03 09:06:05 +00:00
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
2017-01-09 04:47:58 +00:00
|
|
|
|
// Image name
|
2017-02-08 16:58:13 +00:00
|
|
|
|
float textureNameX = classicview ? (x + (float)w / 2 - TextureNameWidth / 2) : (x - 2);
|
2020-04-05 13:15:34 +00:00
|
|
|
|
g.DrawString(TextureName, messageBoxFont, (selected ? selectiontextbrush : (used ? fgbrush_used : fgbrush_unused)), textureNameX, y + h2 + 1);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
// Image size
|
|
|
|
|
if(General.Settings.ShowTextureSizes && icon.IsPreviewLoaded && itemtype == ImageBrowserItemType.IMAGE)
|
|
|
|
|
{
|
2017-02-01 17:10:22 +00:00
|
|
|
|
if (!General.Settings.TextureSizesBelow)
|
|
|
|
|
{
|
2017-02-08 16:36:40 +00:00
|
|
|
|
//string imagesize = Math.Abs(icon.ScaledWidth) + "x" + Math.Abs(icon.ScaledHeight);
|
|
|
|
|
//ano - let's do this with a stringbuilder instead
|
|
|
|
|
size_builder.Length = 0;
|
|
|
|
|
size_builder.Append(Math.Abs(icon.ScaledWidth));
|
|
|
|
|
size_builder.Append('x');
|
|
|
|
|
size_builder.Append(Math.Abs(icon.ScaledHeight));
|
|
|
|
|
|
|
|
|
|
string imagesize = size_builder.ToString();
|
|
|
|
|
SizeF textsize = g.MeasureString(imagesize, pixelSizeFont);
|
2017-02-01 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
textsize.Width += 2;
|
|
|
|
|
textsize.Height -= 3;
|
|
|
|
|
|
|
|
|
|
// Draw bg
|
|
|
|
|
if (selected)
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(selectionbrush, x, y, textsize.Width, textsize.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-08 16:36:40 +00:00
|
|
|
|
g.FillRectangle(bgbrush_alpha, x, y, textsize.Width, textsize.Height);
|
2017-02-01 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
g.DrawString(imagesize, pixelSizeFont, (selected ? selectiontextbrush : (used ? fgbrush_used : fgbrush_unused)), x, y - 1);
|
2017-02-01 17:10:22 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-08 16:36:40 +00:00
|
|
|
|
//string imagesize = "(" + Math.Abs(icon.ScaledWidth) + "x" + Math.Abs(icon.ScaledHeight) + ")";
|
|
|
|
|
//ano - let's do this with a stringbuilder instead
|
|
|
|
|
size_builder.Length = 0;
|
|
|
|
|
size_builder.Append("(");
|
|
|
|
|
size_builder.Append(Math.Abs(icon.ScaledWidth));
|
|
|
|
|
size_builder.Append('x');
|
|
|
|
|
size_builder.Append(Math.Abs(icon.ScaledHeight));
|
|
|
|
|
size_builder.Append(")");
|
|
|
|
|
|
|
|
|
|
string imagesize = size_builder.ToString();
|
2017-02-01 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
// [ZZ] we can't draw it with the regular font: it blends in with the texture name.
|
2017-02-08 16:36:40 +00:00
|
|
|
|
SolidBrush brush = new SolidBrush(((SolidBrush)(selected ? selectiontextbrush : (used ? fgbrush_used : fgbrush_unused))).Color);
|
2017-02-01 17:10:22 +00:00
|
|
|
|
brush.Color = Color.FromArgb((int)(brush.Color.A/* * 0.75f*/), brush.Color.R, brush.Color.G, brush.Color.B);
|
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
SizeF textsize = g.MeasureString(imagesize, pixelSizeFont);
|
2017-02-01 17:10:22 +00:00
|
|
|
|
|
|
|
|
|
float szx = classicview ? (x + (float)w / 2 - textsize.Width / 2) : x;
|
|
|
|
|
float szy = (float)y + h;
|
|
|
|
|
|
2017-02-08 16:36:40 +00:00
|
|
|
|
g.DrawString(imagesize, pixelSizeFont, brush, szx, szy);
|
2017-02-01 17:10:22 +00:00
|
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 12:24:00 +00:00
|
|
|
|
// Comparer
|
|
|
|
|
public int CompareTo(ImageBrowserItem other)
|
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
if(itemtype != other.itemtype) return ((int)itemtype).CompareTo((int)other.itemtype);
|
|
|
|
|
return this.TextureName.ToUpperInvariant().CompareTo(other.TextureName.ToUpperInvariant());
|
2009-05-05 12:24:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|