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;
|
|
|
|
|
|
|
|
|
|
var iw = bmp.Width;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
else if(ih > h)
|
|
|
|
|
{
|
|
|
|
|
iw = (int)Math.Floor(w * (iw / (float)ih));
|
|
|
|
|
ih = h;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 12:39:09 +00:00
|
|
|
|
int ix = (iw < w ? x + (w - iw) / 2 : x);
|
|
|
|
|
int iy = (ih < h ? y + (h - ih) / 2 : y);
|
2016-12-22 15:04:40 +00:00
|
|
|
|
|
|
|
|
|
// Pick colors and brushes
|
2016-12-23 12:39:09 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
Color topselected = Color.FromArgb(255, 151, 67, 37);
|
|
|
|
|
Color bottomselected = Color.FromArgb(255, 83, 20, 1);
|
|
|
|
|
selectedbgbrush = new LinearGradientBrush(new Point(x - 2, y - 3), new Point(x - 2, y + h + 4 + SystemFonts.MessageBoxFont.Height), topselected, bottomselected);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 12:39:09 +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
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(selectedbgbrush, x - 13, y - 2, w + 26, h + 4 + SystemFonts.MessageBoxFont.Height);
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2016-12-22 15:04:40 +00:00
|
|
|
|
g.DrawRectangle(selection, x - 1, y - 1, w + 1, h + 1);
|
|
|
|
|
g.DrawRectangle(selection, x - 2, y - 2, w + 3, h + 3);
|
2016-12-23 12:39:09 +00:00
|
|
|
|
|
|
|
|
|
// Image name bg
|
|
|
|
|
g.FillRectangle(selectionbrush, x - 2, y + h + 2, w + 4, SystemFonts.MessageBoxFont.Height);
|
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
|
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
|
g.DrawRectangle(frame, x - 1, y - 1, w + 1, h + 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
|
|
|
|
|
float textureNameX = classicview ? (x + w / 2 - g.MeasureString(TextureName, SystemFonts.MessageBoxFont).Width / 2) : (x - 2);
|
|
|
|
|
g.DrawString(TextureName, SystemFonts.MessageBoxFont, (selected ? selectiontextbrush : fgbrush), textureNameX, y + h + 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)
|
|
|
|
|
{
|
|
|
|
|
string imagesize = Math.Abs(icon.ScaledWidth) + "x" + Math.Abs(icon.ScaledHeight);
|
|
|
|
|
SizeF textsize = g.MeasureString(imagesize, SystemFonts.MessageBoxFont);
|
|
|
|
|
textsize.Width += 2;
|
2016-12-23 12:39:09 +00:00
|
|
|
|
textsize.Height -= 3;
|
2009-05-05 12:24:00 +00:00
|
|
|
|
|
2016-12-22 15:04:40 +00:00
|
|
|
|
// Draw bg
|
2016-12-23 12:39:09 +00:00
|
|
|
|
if(selected)
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(selectionbrush, x, y, textsize.Width, textsize.Height);
|
|
|
|
|
}
|
|
|
|
|
else
|
2016-12-22 15:04:40 +00:00
|
|
|
|
{
|
2016-12-23 12:39:09 +00:00
|
|
|
|
using(Brush bg = new SolidBrush(Color.FromArgb(192, bgcolor)))
|
|
|
|
|
{
|
|
|
|
|
g.FillRectangle(bg, x, y, textsize.Width, textsize.Height);
|
|
|
|
|
}
|
2016-12-22 15:04:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-23 12:39:09 +00:00
|
|
|
|
g.DrawString(imagesize, SystemFonts.MessageBoxFont, (selected ? selectiontextbrush : fgbrush), x, y - 1);
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|