2015-12-18 10:16:53 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using CodeImp.DoomBuilder.ZDoom;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Data
|
|
|
|
|
{
|
|
|
|
|
public class CameraTextureImage : ImageData
|
|
|
|
|
{
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
|
public CameraTextureImage(CameraTextureData data)
|
|
|
|
|
{
|
|
|
|
|
// Initialize
|
|
|
|
|
this.UseColorCorrection = false;
|
|
|
|
|
this.worldpanning = data.WorldPanning;
|
|
|
|
|
SetName(data.Name);
|
|
|
|
|
|
|
|
|
|
// Get width and height from image
|
|
|
|
|
this.width = data.Width;
|
|
|
|
|
this.height = data.Height;
|
|
|
|
|
scale.x = data.ScaleX;
|
|
|
|
|
scale.y = data.ScaleY;
|
|
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
|
|
// This loads the image
|
2019-12-29 02:54:12 +00:00
|
|
|
|
protected override LocalLoadResult LocalLoadImage()
|
2015-12-18 10:16:53 +00:00
|
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
|
Bitmap bitmap = new Bitmap(width, height);
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
|
int w = Math.Max(2, Math.Min(width, height) / 24); // line width
|
|
|
|
|
int o = w / 2; // line center offset
|
|
|
|
|
int l = w * 3; // line length
|
|
|
|
|
name = name.ToUpperInvariant();
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
|
using(Graphics g = Graphics.FromImage(bitmap))
|
|
|
|
|
{
|
|
|
|
|
// Fill bg
|
|
|
|
|
g.FillRectangle(Brushes.Black, 0, 0, width, height);
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
|
// Draw corners
|
|
|
|
|
Color color = General.Colors.BrightColors[General.Random(0, General.Colors.BrightColors.Length - 1)].ToColor();
|
|
|
|
|
using(var pen = new Pen(color, w))
|
|
|
|
|
{
|
|
|
|
|
g.DrawLines(pen, new[] { new Point(l, o), new Point(o, o), new Point(o, l) }); // TL
|
|
|
|
|
g.DrawLines(pen, new[] { new Point(width - l, o), new Point(width - o, o), new Point(width - o, l) }); // TR
|
|
|
|
|
g.DrawLines(pen, new[] { new Point(l, height - o), new Point(o, height - o), new Point(o, height - l) }); // BL
|
|
|
|
|
g.DrawLines(pen, new[] { new Point(width - l, height - o), new Point(width - o, height - o), new Point(width - o, height - l) }); // BR
|
|
|
|
|
}
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
|
// Calculate required font size
|
|
|
|
|
const string rec = "\u25CFREC";
|
|
|
|
|
float targetwidth = Math.Max(l * 2, 22);
|
|
|
|
|
SizeF fontsize = g.MeasureString(rec, General.MainWindow.Font);
|
|
|
|
|
float scaleratio = Math.Min(targetwidth / fontsize.Height, targetwidth / fontsize.Width);
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
|
// Draw "REC" text
|
|
|
|
|
using(Font font = new Font(General.MainWindow.Font.FontFamily, General.MainWindow.Font.Size * scaleratio))
|
|
|
|
|
{
|
|
|
|
|
using(var brush = new SolidBrush(Color.Red))
|
2015-12-18 10:16:53 +00:00
|
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
|
g.DrawString(rec, font, brush, new RectangleF(l / 2, l / 2 - w / 2, fontsize.Width * scaleratio, fontsize.Height * scaleratio));
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
2019-12-29 02:54:12 +00:00
|
|
|
|
}
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
|
// Calculate required font size
|
|
|
|
|
targetwidth = Math.Min(width, height);
|
|
|
|
|
targetwidth -= targetwidth / 6;
|
|
|
|
|
fontsize = g.MeasureString(name, General.MainWindow.Font);
|
|
|
|
|
scaleratio = Math.Min(targetwidth / fontsize.Height, targetwidth / fontsize.Width);
|
2015-12-18 10:16:53 +00:00
|
|
|
|
|
2019-12-29 02:54:12 +00:00
|
|
|
|
// Draw texture name
|
|
|
|
|
using(Font font = new Font(General.MainWindow.Font.FontFamily, General.MainWindow.Font.Size * scaleratio))
|
|
|
|
|
{
|
|
|
|
|
using(var brush = new SolidBrush(color))
|
2015-12-18 10:16:53 +00:00
|
|
|
|
{
|
2019-12-29 02:54:12 +00:00
|
|
|
|
StringFormat sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
|
|
|
|
|
g.DrawString(name, font, brush, new RectangleF(0, 0, width, height), sf);
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-29 02:54:12 +00:00
|
|
|
|
|
|
|
|
|
return new LocalLoadResult(bitmap);
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//mxd
|
|
|
|
|
protected override void SetName(string name)
|
|
|
|
|
{
|
|
|
|
|
if(!General.Map.Config.UseLongTextureNames)
|
|
|
|
|
{
|
|
|
|
|
if(name.Length > DataManager.CLASIC_IMAGE_NAME_LENGTH) name = name.Substring(0, DataManager.CLASIC_IMAGE_NAME_LENGTH);
|
|
|
|
|
name = name.ToUpperInvariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.SetName(name);
|
|
|
|
|
this.virtualname = "[CAMERA TEXTURES]" + Path.AltDirectorySeparatorChar + name;
|
2019-05-30 22:20:12 +00:00
|
|
|
|
|
|
|
|
|
ComputeNamesWidth(); // biwa
|
2015-12-18 10:16:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|