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;
|
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-01-08 22:04:55 +00:00
|
|
|
|
private int namewidth;
|
|
|
|
|
private int shortnamewidth;
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
public ImageData Icon { get { return icon; } }
|
|
|
|
|
public ImageBrowserItemType ItemType { get { return itemtype; } }
|
2016-12-23 12:39:09 +00:00
|
|
|
|
public virtual bool IsPreviewLoaded { get { return icon.IsPreviewLoaded; } }
|
2016-12-22 15:04:40 +00:00
|
|
|
|
public bool ShowFullName { set { showfullname = value; } }
|
|
|
|
|
public virtual string TextureName { get { return (showfullname ? icon.Name : icon.ShortName); } }
|
2017-01-08 22:04:55 +00:00
|
|
|
|
public virtual int TextureNameWidth { get { return (showfullname ? namewidth : shortnamewidth); } }
|
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
|
2017-01-08 22:04:55 +00:00
|
|
|
|
|
|
|
|
|
//mxd. Calculate names width
|
|
|
|
|
this.namewidth = (int)Math.Ceiling(General.Interface.MeasureString(icon.Name, SystemFonts.MessageBoxFont, 10000, StringFormat.GenericTypographic).Width);
|
|
|
|
|
this.shortnamewidth = (int)Math.Ceiling(General.Interface.MeasureString(icon.ShortName, SystemFonts.MessageBoxFont, 10000, StringFormat.GenericTypographic).Width);
|
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-01-09 04:47:58 +00:00
|
|
|
|
internal void Draw(Graphics g, Image bmp, int x, int y, int w, int h, bool selected, bool used, bool classicview)
|
2009-04-19 18:07:22 +00:00
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
if(bmp == null) return;
|
|
|
|
|
|
2017-02-01 17:10:22 +00:00
|
|
|
|
int font = 4 + SystemFonts.MessageBoxFont.Height;
|
|
|
|
|
int h2 = h;
|
|
|
|
|
if (General.Settings.TextureSizesBelow && ItemType == ImageBrowserItemType.IMAGE)
|
|
|
|
|
h2 -= font;
|
|
|
|
|
|
|
|
|
|
var iw = bmp.Width;
|
2016-12-22 15:04:40 +00:00
|
|
|
|
var ih = bmp.Height;
|
|
|
|
|
|
|
|
|
|
if(iw > w && iw >= ih)
|
2009-04-19 18:07:22 +00:00
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
ih = (int)Math.Floor(h * (ih / (float)iw));
|
|
|
|
|
iw = w;
|
|
|
|
|
}
|
2017-02-01 17:10:22 +00:00
|
|
|
|
else if(ih > h2)
|
2016-12-22 15:04:40 +00:00
|
|
|
|
{
|
|
|
|
|
iw = (int)Math.Floor(w * (iw / (float)ih));
|
2017-02-01 17:10:22 +00:00
|
|
|
|
ih = h2;
|
2016-12-22 15:04:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-01 17:10:22 +00:00
|
|
|
|
int ix = (iw < w ? x + (w - iw) / 2 : x);
|
|
|
|
|
int iy = (ih < h2 ? y + (h2 - ih) / 2 : y);
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
2017-02-01 17:10:22 +00:00
|
|
|
|
// Pick colors and brushes
|
|
|
|
|
Brush bgbrush, fgbrush, selectedbgbrush, selectionbrush, selectiontextbrush;
|
2016-12-22 15:04:40 +00:00
|
|
|
|
Color bgcolor;
|
2016-12-23 12:39:09 +00:00
|
|
|
|
Pen selection, frame;
|
2016-12-22 15:04:40 +00:00
|
|
|
|
if(General.Settings.BlackBrowsers)
|
|
|
|
|
{
|
|
|
|
|
bgcolor = Color.Black;
|
|
|
|
|
bgbrush = Brushes.Black;
|
2016-12-23 12:39:09 +00:00
|
|
|
|
fgbrush = (used ? Brushes.Orange : Brushes.White);
|
2017-01-09 04:47:58 +00:00
|
|
|
|
|
|
|
|
|
if (!classicview)
|
|
|
|
|
{
|
|
|
|
|
selectedbgbrush = Brushes.Gray;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
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 + 4 + SystemFonts.MessageBoxFont.Height), topselected, bottomselected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
frame = (used ? Pens.Orange : Pens.Gray);
|
2016-12-22 15:04:40 +00:00
|
|
|
|
selection = Pens.Red;
|
|
|
|
|
selectionbrush = Brushes.Red;
|
2016-12-23 12:39:09 +00:00
|
|
|
|
selectiontextbrush = Brushes.White;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
bgcolor = SystemColors.Window;
|
|
|
|
|
bgbrush = SystemBrushes.Window;
|
2016-12-23 12:39:09 +00:00
|
|
|
|
fgbrush = (used ? SystemBrushes.HotTrack : SystemBrushes.ControlText);
|
2017-01-09 04:47:58 +00:00
|
|
|
|
|
|
|
|
|
if (!classicview)
|
|
|
|
|
{
|
|
|
|
|
selectedbgbrush = SystemBrushes.Highlight;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-01-15 01:39:39 +00:00
|
|
|
|
Color topselected = Color.FromArgb(255, 37, 67, 151);
|
|
|
|
|
Color bottomselected = Color.FromArgb(255, 1, 20, 83);
|
2017-01-09 04:47:58 +00:00
|
|
|
|
selectedbgbrush = new LinearGradientBrush(new Point(x - 2, y - 3), new Point(x - 2, y + h + 4 + SystemFonts.MessageBoxFont.Height), topselected, bottomselected);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-15 01:39:39 +00:00
|
|
|
|
frame = (used ? SystemPens.HotTrack : SystemPens.ActiveBorder);
|
2016-12-22 15:04:40 +00:00
|
|
|
|
selection = SystemPens.HotTrack;
|
|
|
|
|
selectionbrush = SystemBrushes.HotTrack;
|
2016-12-23 12:39:09 +00:00
|
|
|
|
selectiontextbrush = SystemBrushes.Window;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
// Item bg
|
2016-12-23 12:39:09 +00:00
|
|
|
|
g.FillRectangle(bgbrush, x - 2, y - 2, w + 3, h + 8 + SystemFonts.MessageBoxFont.Height);
|
2014-12-03 09:06:05 +00:00
|
|
|
|
|
2017-01-09 04:47:58 +00:00
|
|
|
|
// Selected image bg
|
|
|
|
|
if (selected)
|
|
|
|
|
{
|
|
|
|
|
if (!classicview)
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(selectedbgbrush, x - 2, y - 2, w + 4, h + 2 + SystemFonts.MessageBoxFont.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-02-01 17:10:22 +00:00
|
|
|
|
g.FillRectangle(selectedbgbrush, x - 13, y - 2, w + 26, h + font);
|
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
|
2017-02-01 17:10:22 +00:00
|
|
|
|
g.FillRectangle(selectionbrush, x - 2, y + h2 + 2, w + 4, SystemFonts.MessageBoxFont.Height + (General.Settings.TextureSizesBelow ? font : 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-01 17:10:22 +00:00
|
|
|
|
g.DrawRectangle(frame, 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-01 17:10:22 +00:00
|
|
|
|
float textureNameX = classicview ? (x + (float)w / 2 - g.MeasureString(TextureName, SystemFonts.MessageBoxFont).Width / 2) : (x - 2);
|
|
|
|
|
g.DrawString(TextureName, SystemFonts.MessageBoxFont, (selected ? selectiontextbrush : fgbrush), 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)
|
|
|
|
|
{
|
|
|
|
|
string imagesize = Math.Abs(icon.ScaledWidth) + "x" + Math.Abs(icon.ScaledHeight);
|
|
|
|
|
SizeF textsize = g.MeasureString(imagesize, SystemFonts.MessageBoxFont);
|
|
|
|
|
|
|
|
|
|
textsize.Width += 2;
|
|
|
|
|
textsize.Height -= 3;
|
|
|
|
|
|
|
|
|
|
// Draw bg
|
|
|
|
|
if (selected)
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(selectionbrush, x, y, textsize.Width, textsize.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (Brush bg = new SolidBrush(Color.FromArgb(192, bgcolor)))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(bg, x, y, textsize.Width, textsize.Height);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g.DrawString(imagesize, SystemFonts.MessageBoxFont, (selected ? selectiontextbrush : fgbrush), x, y - 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string imagesize = "(" + Math.Abs(icon.ScaledWidth) + "x" + Math.Abs(icon.ScaledHeight) + ")";
|
|
|
|
|
|
|
|
|
|
// [ZZ] we can't draw it with the regular font: it blends in with the texture name.
|
|
|
|
|
SolidBrush brush = new SolidBrush(((SolidBrush)(selected ? selectiontextbrush : fgbrush)).Color);
|
|
|
|
|
brush.Color = Color.FromArgb((int)(brush.Color.A/* * 0.75f*/), brush.Color.R, brush.Color.G, brush.Color.B);
|
|
|
|
|
|
|
|
|
|
Font f = new Font(SystemFonts.MessageBoxFont.FontFamily, SystemFonts.MessageBoxFont.Size * 0.8f, FontStyle.Regular);
|
|
|
|
|
SizeF textsize = g.MeasureString(imagesize, f);
|
|
|
|
|
|
|
|
|
|
float szx = classicview ? (x + (float)w / 2 - textsize.Width / 2) : x;
|
|
|
|
|
float szy = (float)y + h;
|
|
|
|
|
|
|
|
|
|
g.DrawString(imagesize, f, brush, szx, szy);
|
|
|
|
|
}
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|