2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
using SlimDX;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
2009-05-05 12:24:00 +00:00
|
|
|
internal class ImageBrowserItem : ListViewItem, IComparable<ImageBrowserItem>
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
#region ================== Constants
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
internal const int MAX_NAME_LENGTH = 14; //mxd
|
2014-11-25 11:52:01 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#region ================== Variables
|
|
|
|
|
2011-12-02 22:18:55 +00:00
|
|
|
// Display image and text
|
2014-12-03 23:15:26 +00:00
|
|
|
public readonly ImageData Icon;
|
2014-12-03 09:06:05 +00:00
|
|
|
private string imagesize; //mxd
|
|
|
|
private bool showfullname; //mxd
|
2014-05-19 13:33:38 +00:00
|
|
|
private static readonly StringFormat format = new StringFormat { Alignment = StringAlignment.Center }; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Group
|
|
|
|
private ListViewGroup listgroup;
|
|
|
|
|
|
|
|
// Image cache
|
|
|
|
private bool imageloaded;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public ListViewGroup ListGroup { get { return listgroup; } set { listgroup = value; } }
|
|
|
|
public bool IsPreviewLoaded { get { return imageloaded; } }
|
2014-12-03 09:06:05 +00:00
|
|
|
public bool ShowFullName { set { showfullname = value; UpdateName(); } }
|
2014-12-03 23:15:26 +00:00
|
|
|
public string TextureName { get { return showfullname ? Icon.Name : Icon.ShortName; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructors
|
2014-12-03 09:06:05 +00:00
|
|
|
public ImageBrowserItem(ImageData icon, object tag, bool showfullname)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
2014-12-03 23:15:26 +00:00
|
|
|
this.Icon = icon;
|
2009-04-19 18:07:22 +00:00
|
|
|
this.Tag = tag;
|
2014-12-03 09:06:05 +00:00
|
|
|
this.showfullname = showfullname; //mxd
|
|
|
|
UpdateName(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This checks if a redraw is needed
|
|
|
|
public bool CheckRedrawNeeded()
|
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
UpdateName(); //mxd. Update texture size if needed
|
2014-12-03 23:15:26 +00:00
|
|
|
return (Icon.IsPreviewLoaded != imageloaded);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This draws the images
|
|
|
|
public void Draw(Graphics g, Rectangle bounds)
|
|
|
|
{
|
|
|
|
Brush forecolor;
|
|
|
|
Brush backcolor;
|
2013-06-17 14:09:29 +00:00
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Remember if the preview is loaded
|
2014-12-03 23:15:26 +00:00
|
|
|
imageloaded = Icon.IsPreviewLoaded;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Drawing settings
|
|
|
|
g.CompositingQuality = CompositingQuality.HighSpeed;
|
|
|
|
g.InterpolationMode = InterpolationMode.NearestNeighbor;
|
|
|
|
g.SmoothingMode = SmoothingMode.HighSpeed;
|
|
|
|
g.PixelOffsetMode = PixelOffsetMode.None;
|
|
|
|
|
|
|
|
// Determine coordinates
|
2014-12-03 09:06:05 +00:00
|
|
|
SizeF textsize = g.MeasureString(Text, this.ListView.Font, bounds.Width * 2);
|
2009-04-19 18:07:22 +00:00
|
|
|
Rectangle imagerect = new Rectangle(bounds.Left + ((bounds.Width - General.Map.Data.Previews.MaxImageWidth) >> 1),
|
|
|
|
bounds.Top + ((bounds.Height - General.Map.Data.Previews.MaxImageHeight - (int)textsize.Height) >> 1),
|
|
|
|
General.Map.Data.Previews.MaxImageWidth, General.Map.Data.Previews.MaxImageHeight);
|
2014-05-19 13:33:38 +00:00
|
|
|
PointF textpos = new PointF(bounds.Left + (bounds.Width * 0.5f), bounds.Bottom - textsize.Height - 2);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Determine colors
|
|
|
|
if(this.Selected)
|
|
|
|
{
|
|
|
|
// Highlighted
|
|
|
|
backcolor = new LinearGradientBrush(new Point(0, bounds.Top - 1), new Point(0, bounds.Bottom + 1),
|
|
|
|
AdjustedColor(SystemColors.Highlight, 0.2f),
|
|
|
|
AdjustedColor(SystemColors.Highlight, -0.1f));
|
2015-09-12 21:05:01 +00:00
|
|
|
forecolor = new SolidBrush(SystemColors.HighlightText);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Normal
|
|
|
|
backcolor = new SolidBrush(base.ListView.BackColor);
|
|
|
|
forecolor = new SolidBrush(base.ListView.ForeColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw!
|
|
|
|
g.FillRectangle(backcolor, bounds);
|
2014-12-03 23:15:26 +00:00
|
|
|
Icon.DrawPreview(g, imagerect.Location);
|
2014-12-03 09:06:05 +00:00
|
|
|
g.DrawString(Text, this.ListView.Font, forecolor, textpos, format);
|
|
|
|
|
2015-09-12 21:05:01 +00:00
|
|
|
//mxd. Dispose brushes
|
|
|
|
backcolor.Dispose();
|
|
|
|
forecolor.Dispose();
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd. Draw size label?
|
2015-09-16 12:10:43 +00:00
|
|
|
if(General.Settings.ShowTextureSizes && !string.IsNullOrEmpty(imagesize))
|
2014-12-03 09:06:05 +00:00
|
|
|
{
|
|
|
|
// Setup
|
2016-07-02 22:27:20 +00:00
|
|
|
using(Font sizefont = new Font(this.ListView.Font.FontFamily, this.ListView.Font.SizeInPoints - 1))
|
2015-05-27 10:34:25 +00:00
|
|
|
{
|
2016-07-02 22:27:20 +00:00
|
|
|
textsize = g.MeasureString(imagesize, sizefont, bounds.Width * 2);
|
|
|
|
textpos = new PointF(bounds.Left + textsize.Width / 2, bounds.Top + 1);
|
|
|
|
imagerect = new Rectangle(bounds.Left + 1, bounds.Top + 1, (int)textsize.Width, (int)textsize.Height);
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
using(SolidBrush labelbg = new SolidBrush(Color.FromArgb(196, base.ListView.ForeColor)))
|
|
|
|
{
|
|
|
|
g.FillRectangle(labelbg, imagerect);
|
|
|
|
}
|
|
|
|
using(SolidBrush labelcolor = new SolidBrush(base.ListView.BackColor))
|
|
|
|
{
|
|
|
|
g.DrawString(imagesize, sizefont, labelcolor, textpos, format);
|
|
|
|
}
|
2015-05-27 10:34:25 +00:00
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This brightens or darkens a color
|
2014-05-20 09:09:28 +00:00
|
|
|
private static Color AdjustedColor(Color c, float amount)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
Color4 cc = new Color4(c);
|
|
|
|
|
|
|
|
// Adjust color
|
|
|
|
cc.Red = Saturate((cc.Red * (1f + amount)) + (amount * 0.5f));
|
|
|
|
cc.Green = Saturate((cc.Green * (1f + amount)) + (amount * 0.5f));
|
|
|
|
cc.Blue = Saturate((cc.Blue * (1f + amount)) + (amount * 0.5f));
|
|
|
|
|
|
|
|
// Return result
|
|
|
|
return Color.FromArgb(cc.ToArgb());
|
|
|
|
}
|
|
|
|
|
|
|
|
// This clamps a value between 0 and 1
|
2014-03-05 09:21:28 +00:00
|
|
|
private static float Saturate(float v)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
if(v < 0f) return 0f; else if(v > 1f) return 1f; else return v;
|
|
|
|
}
|
2009-05-05 12:24:00 +00:00
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd
|
|
|
|
private void UpdateName()
|
|
|
|
{
|
2014-12-03 23:15:26 +00:00
|
|
|
Text = (showfullname ? Icon.DisplayName : Icon.ShortName);
|
|
|
|
if(General.Settings.ShowTextureSizes && Icon.IsPreviewLoaded)
|
Fixed, Texture previews: texture size labels were displaying incorrect size or no size at all when showing TEXTURES textures with negative scale.
Fixed, Visual mode, UDMF: when several wall parts were selected, only one could be dragged with the mouse.
Fixed, Visual mode, Auto-align textures, UDMF: TEXTURES scale is now taken into account when aligning textures.
Fixed, Visual mode, Auto-align textures (Y), UDMF: nearest height matching is now applied to non-wrapped middle backsides.
Cosmetic changes in ZDoom_ACS.cfg.
2015-01-27 11:40:25 +00:00
|
|
|
imagesize = Math.Abs(Icon.ScaledWidth) + "x" + Math.Abs(Icon.ScaledHeight);
|
2014-12-03 09:06:05 +00:00
|
|
|
}
|
|
|
|
|
2009-05-05 12:24:00 +00:00
|
|
|
// Comparer
|
|
|
|
public int CompareTo(ImageBrowserItem other)
|
|
|
|
{
|
2014-05-19 13:33:38 +00:00
|
|
|
return this.Text.ToUpperInvariant().CompareTo(other.Text.ToUpperInvariant());
|
2009-05-05 12:24:00 +00:00
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|