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;
|
2016-03-30 23:25:03 +00:00
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
using System.Drawing.Imaging;
|
|
|
|
using System.Drawing.Text;
|
|
|
|
using System.IO;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Drawing;
|
|
|
|
using SlimDX.Direct3D9;
|
|
|
|
using SlimDX;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
2016-03-30 23:25:03 +00:00
|
|
|
using Font = System.Drawing.Font;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Rendering
|
|
|
|
{
|
2016-04-25 14:48:39 +00:00
|
|
|
public interface ITextLabel //mxd. Methods and properties required to render a textlabel
|
|
|
|
{
|
|
|
|
// Required to render text label
|
|
|
|
bool SkipRendering { get; }
|
|
|
|
Texture Texture { get; }
|
|
|
|
VertexBuffer VertexBuffer { get; }
|
|
|
|
|
|
|
|
// Access/setup
|
|
|
|
Font Font { get; }
|
|
|
|
string Text { get; set; }
|
|
|
|
PixelColor Color { get; set; }
|
|
|
|
PixelColor BackColor { get; set; }
|
|
|
|
|
|
|
|
void Update(float translatex, float translatey, float scalex, float scaley);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TextLabel : IDisposable, ID3DResource, ITextLabel
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// The text is stored as a polygon in a vertex buffer
|
|
|
|
private VertexBuffer textbuffer;
|
2016-03-30 23:25:03 +00:00
|
|
|
private Texture texture;
|
|
|
|
private Font font; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Text settings
|
|
|
|
private string text;
|
2016-04-19 20:40:42 +00:00
|
|
|
private Vector2D location; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
private bool transformcoords;
|
|
|
|
private PixelColor color;
|
|
|
|
private PixelColor backcolor;
|
|
|
|
private TextAlignmentX alignx;
|
|
|
|
private TextAlignmentY aligny;
|
2016-04-19 20:40:42 +00:00
|
|
|
private bool drawbg; //mxd
|
|
|
|
|
|
|
|
//mxd. Label image settings...
|
2016-03-30 23:25:03 +00:00
|
|
|
private SizeF textsize;
|
2016-04-17 22:52:03 +00:00
|
|
|
private Size texturesize;
|
2016-04-19 20:40:42 +00:00
|
|
|
private RectangleF textrect;
|
|
|
|
private RectangleF bgrect;
|
|
|
|
private PointF textorigin;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This keeps track if changes were made
|
|
|
|
private bool updateneeded;
|
2016-03-30 23:25:03 +00:00
|
|
|
private bool textureupdateneeded; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
private float lasttranslatex = float.MinValue;
|
|
|
|
private float lasttranslatey;
|
|
|
|
private float lastscalex;
|
|
|
|
private float lastscaley;
|
Sectors, Linedefs, Things modes: optimized text label rendering.
Fixed, Things mode: in some cases selection labels were not updated after editing a thing.
Fixed, Things mode: selection labels were positioned incorrectly on things with FixedSize setting.
Fixed, Sectors mode: fixed a crash when selecting self-referencing sector when selection labels were enabled.
Fixed, Visual mode: in some cases Auto-align texture actions were not working when "use long texture names" Map Options setting was enabled.
Fixed, MD2/MD3 loader: available animation frames upper bound check was performed incorrectly, which would cause a crash in some very special cases.
Fixed, Game configurations: most Hexen/ZDoom teleport actions use TeleportDests as teleport targets, not MapSpots.
2016-04-05 22:24:36 +00:00
|
|
|
|
|
|
|
//mxd. Rendering
|
|
|
|
private bool skiprendering;
|
2016-05-19 21:44:39 +00:00
|
|
|
|
|
|
|
//mxd. Compatibility
|
|
|
|
private float scale;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Disposing
|
2014-02-21 14:42:12 +00:00
|
|
|
private bool isdisposed;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
// Properties
|
2016-04-19 20:40:42 +00:00
|
|
|
public Vector2D Location { get { return location; } set { location = value; updateneeded = true; } } //mxd
|
|
|
|
public string Text { get { return text; } set { if(text != value) { text = value; textsize = Size.Empty; textureupdateneeded = true; } } }
|
2016-07-02 22:27:20 +00:00
|
|
|
public Font Font { get { return font; } set { font.Dispose(); font = value; textsize = Size.Empty; textureupdateneeded = true; } } //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
public bool TransformCoords { get { return transformcoords; } set { transformcoords = value; updateneeded = true; } }
|
2016-04-04 22:20:49 +00:00
|
|
|
public SizeF TextSize { get { if(textureupdateneeded) Update(General.Map.Renderer2D.TranslateX, General.Map.Renderer2D.TranslateY, General.Map.Renderer2D.Scale, -General.Map.Renderer2D.Scale); return textsize; } }
|
2009-04-19 18:07:22 +00:00
|
|
|
public TextAlignmentX AlignX { get { return alignx; } set { alignx = value; updateneeded = true; } }
|
|
|
|
public TextAlignmentY AlignY { get { return aligny; } set { aligny = value; updateneeded = true; } }
|
2016-03-30 23:25:03 +00:00
|
|
|
public PixelColor Color { get { return color; } set { if(!color.Equals(value)) { color = value; textureupdateneeded = true; } } }
|
2016-04-06 11:44:38 +00:00
|
|
|
public PixelColor BackColor { get { return backcolor; } set { if(!backcolor.Equals(value)) { backcolor = value; textureupdateneeded = true; } } }
|
2016-03-30 23:25:03 +00:00
|
|
|
public bool DrawBackground { get { return drawbg; } set { if(drawbg != value) { drawbg = value; textureupdateneeded = true; } } } //mxd
|
2016-04-25 14:48:39 +00:00
|
|
|
public Texture Texture { get { return texture; } } //mxd
|
|
|
|
public VertexBuffer VertexBuffer { get { return textbuffer; } }
|
|
|
|
public bool SkipRendering { get { return skiprendering; } } //mxd
|
2016-05-19 21:44:39 +00:00
|
|
|
|
|
|
|
//mxd. Compatibility settings
|
|
|
|
[Obsolete("Backcolor property is deprecated, please use BackColor property instead.")]
|
|
|
|
public PixelColor Backcolor { get { return BackColor; } set { BackColor = value.WithAlpha(128); } }
|
|
|
|
|
|
|
|
[Obsolete("Scale property is deprecated, please assign the font directly using Font property instead.")]
|
|
|
|
public float Scale
|
|
|
|
{
|
|
|
|
get { return scale; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
scale = value;
|
2016-07-02 22:27:20 +00:00
|
|
|
font.Dispose();
|
2016-05-19 21:44:39 +00:00
|
|
|
font = new Font(new FontFamily(General.Settings.TextLabelFontName), (float)Math.Round(scale * 0.75f), (General.Settings.TextLabelFontBold ? FontStyle.Bold : FontStyle.Regular));
|
|
|
|
textsize = Size.Empty;
|
|
|
|
textureupdateneeded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Obsolete("Rectangle property is deprecated, please use Location property instead.")]
|
|
|
|
public RectangleF Rectangle { get { return new RectangleF(location.x, location.y, 0f, 0f); } set { location = new Vector2D(value.X, value.Y); updateneeded = true; } }
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Disposing
|
|
|
|
public bool IsDisposed { get { return isdisposed; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
2016-03-30 23:25:03 +00:00
|
|
|
public TextLabel()
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.text = "";
|
2016-07-02 22:27:20 +00:00
|
|
|
this.font = new Font(new FontFamily(General.Settings.TextLabelFontName), General.Settings.TextLabelFontSize, (General.Settings.TextLabelFontBold ? FontStyle.Bold : FontStyle.Regular)); //General.Settings.TextLabelFont; //mxd
|
2016-04-19 20:40:42 +00:00
|
|
|
this.location = new Vector2D(); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
this.color = new PixelColor(255, 255, 255, 255);
|
2016-04-06 11:44:38 +00:00
|
|
|
this.backcolor = new PixelColor(128, 0, 0, 0);
|
2013-09-13 14:54:43 +00:00
|
|
|
this.alignx = TextAlignmentX.Center;
|
2009-04-19 18:07:22 +00:00
|
|
|
this.aligny = TextAlignmentY.Top;
|
2016-04-19 20:40:42 +00:00
|
|
|
this.textsize = SizeF.Empty; //mxd
|
|
|
|
this.texturesize = Size.Empty; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
this.updateneeded = true;
|
2016-03-30 23:25:03 +00:00
|
|
|
this.textureupdateneeded = true; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Register as resource
|
|
|
|
General.Map.Graphics.RegisterResource(this);
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
2016-05-19 21:44:39 +00:00
|
|
|
//mxd. Compatibility constructor...
|
|
|
|
[Obsolete("TextLabel(int capacity) is deprecated, please use TextLabel() instead.")]
|
|
|
|
public TextLabel(int unused)
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
this.text = "";
|
2016-07-02 22:27:20 +00:00
|
|
|
this.font = new Font(new FontFamily(General.Settings.TextLabelFontName), General.Settings.TextLabelFontSize, (General.Settings.TextLabelFontBold ? FontStyle.Bold : FontStyle.Regular)); // General.Settings.TextLabelFont;
|
2016-05-19 21:44:39 +00:00
|
|
|
this.location = new Vector2D();
|
|
|
|
this.color = new PixelColor(255, 255, 255, 255);
|
|
|
|
this.backcolor = new PixelColor(128, 0, 0, 0);
|
|
|
|
this.alignx = TextAlignmentX.Center;
|
|
|
|
this.aligny = TextAlignmentY.Top;
|
|
|
|
this.textsize = SizeF.Empty;
|
|
|
|
this.texturesize = Size.Empty;
|
|
|
|
this.updateneeded = true;
|
|
|
|
this.textureupdateneeded = true;
|
|
|
|
|
|
|
|
// Register as resource
|
|
|
|
General.Map.Graphics.RegisterResource(this);
|
|
|
|
|
|
|
|
// We have no destructor
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Diposer
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
UnloadResource();
|
2016-07-02 22:27:20 +00:00
|
|
|
font.Dispose();
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Unregister resource
|
|
|
|
General.Map.Graphics.UnregisterResource(this);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
isdisposed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
|
|
// This updates the text if needed
|
2016-04-25 14:48:39 +00:00
|
|
|
public void Update(float translatex, float translatey, float scalex, float scaley)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Check if transformation changed and needs to be updated
|
2016-03-30 23:25:03 +00:00
|
|
|
if(transformcoords && (translatex != lasttranslatex || translatey != lasttranslatey ||
|
|
|
|
scalex != lastscalex || scaley != lastscaley))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-03-30 23:25:03 +00:00
|
|
|
lasttranslatex = translatex; //mxd
|
|
|
|
lasttranslatey = translatey; //mxd
|
|
|
|
lastscalex = scalex; //mxd
|
|
|
|
lastscaley = scaley; //mxd
|
|
|
|
updateneeded = true;
|
|
|
|
}
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Update if needed
|
2016-03-30 23:25:03 +00:00
|
|
|
if(updateneeded || textureupdateneeded)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Only build when there are any vertices
|
|
|
|
if(text.Length > 0)
|
|
|
|
{
|
|
|
|
// Transform?
|
2016-04-19 20:40:42 +00:00
|
|
|
Vector2D abspos = (transformcoords ? location.GetTransformed(translatex, translatey, scalex, scaley) : location);
|
|
|
|
|
|
|
|
// Update text and texture sizes
|
|
|
|
if(textsize.IsEmpty || texturesize.IsEmpty)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-04-19 20:40:42 +00:00
|
|
|
textorigin = new PointF(4, 3);
|
|
|
|
textrect = new RectangleF(textorigin, General.Interface.MeasureString(text, font));
|
|
|
|
textrect.Width = (float)Math.Round(textrect.Width);
|
|
|
|
textrect.Height = (float)Math.Round(textrect.Height);
|
|
|
|
bgrect = new RectangleF(0, 0, textrect.Width + textorigin.X * 2, textrect.Height + textorigin.Y * 2);
|
|
|
|
|
|
|
|
// Store calculated text size...
|
|
|
|
textsize = new SizeF(textrect.Width + textorigin.X * 2, textrect.Height + textorigin.Y * 2);
|
|
|
|
|
|
|
|
// Make PO2 image, for speed and giggles...
|
|
|
|
texturesize = new Size(General.NextPowerOf2((int)textsize.Width), General.NextPowerOf2((int)textsize.Height));
|
|
|
|
|
|
|
|
switch(alignx)
|
|
|
|
{
|
|
|
|
case TextAlignmentX.Center: bgrect.X = (texturesize.Width - bgrect.Width) / 2; break;
|
|
|
|
case TextAlignmentX.Right: bgrect.X = texturesize.Width - bgrect.Width; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(aligny)
|
|
|
|
{
|
|
|
|
case TextAlignmentY.Middle: bgrect.Y = (texturesize.Height - bgrect.Height) / 2; break;
|
|
|
|
case TextAlignmentY.Bottom: bgrect.Y = texturesize.Height - bgrect.Height; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
textrect.X += bgrect.X;
|
|
|
|
textrect.Y += bgrect.Y;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2016-04-19 20:40:42 +00:00
|
|
|
|
|
|
|
// Align the text horizontally
|
|
|
|
float beginx = 0;
|
|
|
|
switch(alignx)
|
|
|
|
{
|
|
|
|
case TextAlignmentX.Left: beginx = abspos.x; break;
|
|
|
|
case TextAlignmentX.Center: beginx = abspos.x - texturesize.Width * 0.5f; break;
|
|
|
|
case TextAlignmentX.Right: beginx = abspos.x - texturesize.Width; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Align the text vertically
|
|
|
|
float beginy = 0;
|
|
|
|
switch(aligny)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-04-19 20:40:42 +00:00
|
|
|
case TextAlignmentY.Top: beginy = abspos.y; break;
|
|
|
|
case TextAlignmentY.Middle: beginy = abspos.y - texturesize.Height * 0.5f; break;
|
|
|
|
case TextAlignmentY.Bottom: beginy = abspos.y - texturesize.Height; break;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
Sectors, Linedefs, Things modes: optimized text label rendering.
Fixed, Things mode: in some cases selection labels were not updated after editing a thing.
Fixed, Things mode: selection labels were positioned incorrectly on things with FixedSize setting.
Fixed, Sectors mode: fixed a crash when selecting self-referencing sector when selection labels were enabled.
Fixed, Visual mode: in some cases Auto-align texture actions were not working when "use long texture names" Map Options setting was enabled.
Fixed, MD2/MD3 loader: available animation frames upper bound check was performed incorrectly, which would cause a crash in some very special cases.
Fixed, Game configurations: most Hexen/ZDoom teleport actions use TeleportDests as teleport targets, not MapSpots.
2016-04-05 22:24:36 +00:00
|
|
|
//mxd. Skip when not on screen...
|
2016-04-19 20:40:42 +00:00
|
|
|
RectangleF abssize = new RectangleF(beginx, beginy, texturesize.Width, texturesize.Height);
|
Sectors, Linedefs, Things modes: optimized text label rendering.
Fixed, Things mode: in some cases selection labels were not updated after editing a thing.
Fixed, Things mode: selection labels were positioned incorrectly on things with FixedSize setting.
Fixed, Sectors mode: fixed a crash when selecting self-referencing sector when selection labels were enabled.
Fixed, Visual mode: in some cases Auto-align texture actions were not working when "use long texture names" Map Options setting was enabled.
Fixed, MD2/MD3 loader: available animation frames upper bound check was performed incorrectly, which would cause a crash in some very special cases.
Fixed, Game configurations: most Hexen/ZDoom teleport actions use TeleportDests as teleport targets, not MapSpots.
2016-04-05 22:24:36 +00:00
|
|
|
Size windowsize = General.Map.Graphics.RenderTarget.ClientSize;
|
|
|
|
skiprendering = (abssize.Right < 0.1f) || (abssize.Left > windowsize.Width) || (abssize.Bottom < 0.1f) || (abssize.Top > windowsize.Height);
|
|
|
|
if(skiprendering) return;
|
|
|
|
|
|
|
|
//mxd. Update texture if needed
|
|
|
|
if(textureupdateneeded)
|
|
|
|
{
|
|
|
|
// Get rid of old texture
|
|
|
|
if(texture != null)
|
|
|
|
{
|
|
|
|
texture.Dispose();
|
|
|
|
texture = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create label image
|
2016-04-19 20:40:42 +00:00
|
|
|
Bitmap img = CreateLabelImage(text, font, color, backcolor, drawbg, textrect, bgrect, texturesize, textorigin);
|
|
|
|
//texturesize = img.Size;
|
Sectors, Linedefs, Things modes: optimized text label rendering.
Fixed, Things mode: in some cases selection labels were not updated after editing a thing.
Fixed, Things mode: selection labels were positioned incorrectly on things with FixedSize setting.
Fixed, Sectors mode: fixed a crash when selecting self-referencing sector when selection labels were enabled.
Fixed, Visual mode: in some cases Auto-align texture actions were not working when "use long texture names" Map Options setting was enabled.
Fixed, MD2/MD3 loader: available animation frames upper bound check was performed incorrectly, which would cause a crash in some very special cases.
Fixed, Game configurations: most Hexen/ZDoom teleport actions use TeleportDests as teleport targets, not MapSpots.
2016-04-05 22:24:36 +00:00
|
|
|
|
|
|
|
// Create texture
|
|
|
|
MemoryStream memstream = new MemoryStream((img.Size.Width * img.Size.Height * 4) + 4096);
|
|
|
|
img.Save(memstream, ImageFormat.Bmp);
|
|
|
|
memstream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
texture = Texture.FromStream(General.Map.Graphics.Device, memstream, (int)memstream.Length,
|
|
|
|
img.Size.Width, img.Size.Height, 1, Usage.None, Format.Unknown,
|
|
|
|
Pool.Managed, General.Map.Graphics.PostFilter, General.Map.Graphics.MipGenerateFilter, 0);
|
|
|
|
}
|
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
//mxd. Create the buffer
|
|
|
|
if(textbuffer == null || textbuffer.Disposed)
|
|
|
|
{
|
|
|
|
textbuffer = new VertexBuffer(General.Map.Graphics.Device, 4 * FlatVertex.Stride,
|
|
|
|
Usage.Dynamic | Usage.WriteOnly, VertexFormat.None, Pool.Default);
|
|
|
|
}
|
|
|
|
|
2016-03-30 23:25:03 +00:00
|
|
|
//mxd. Lock the buffer
|
|
|
|
using(DataStream stream = textbuffer.Lock(0, 4 * FlatVertex.Stride, LockFlags.Discard | LockFlags.NoSystemLock))
|
|
|
|
{
|
2016-04-17 22:52:03 +00:00
|
|
|
FlatQuad quad = new FlatQuad(PrimitiveType.TriangleStrip, beginx, beginy, beginx + texturesize.Width, beginy + texturesize.Height);
|
2016-03-30 23:25:03 +00:00
|
|
|
stream.WriteRange(quad.Vertices);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Done filling the vertex buffer
|
|
|
|
textbuffer.Unlock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// No faces in polygon
|
2016-04-19 20:40:42 +00:00
|
|
|
textsize = SizeF.Empty; //mxd
|
|
|
|
texturesize = Size.Empty; //mxd
|
Sectors, Linedefs, Things modes: optimized text label rendering.
Fixed, Things mode: in some cases selection labels were not updated after editing a thing.
Fixed, Things mode: selection labels were positioned incorrectly on things with FixedSize setting.
Fixed, Sectors mode: fixed a crash when selecting self-referencing sector when selection labels were enabled.
Fixed, Visual mode: in some cases Auto-align texture actions were not working when "use long texture names" Map Options setting was enabled.
Fixed, MD2/MD3 loader: available animation frames upper bound check was performed incorrectly, which would cause a crash in some very special cases.
Fixed, Game configurations: most Hexen/ZDoom teleport actions use TeleportDests as teleport targets, not MapSpots.
2016-04-05 22:24:36 +00:00
|
|
|
skiprendering = true; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Text updated
|
|
|
|
updateneeded = false;
|
2016-03-30 23:25:03 +00:00
|
|
|
textureupdateneeded = false; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2016-03-30 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//mxd
|
2016-04-19 20:40:42 +00:00
|
|
|
private static Bitmap CreateLabelImage(string text, Font font, PixelColor color, PixelColor backcolor, bool drawbg, RectangleF textrect, RectangleF bgrect, Size texturesize, PointF textorigin)
|
2016-03-30 23:25:03 +00:00
|
|
|
{
|
2016-04-19 20:40:42 +00:00
|
|
|
Bitmap result = new Bitmap(texturesize.Width, texturesize.Height);
|
2016-03-30 23:25:03 +00:00
|
|
|
using(Graphics g = Graphics.FromImage(result))
|
|
|
|
{
|
|
|
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
|
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
|
|
g.CompositingQuality = CompositingQuality.HighQuality;
|
|
|
|
|
|
|
|
// Draw text
|
|
|
|
using(StringFormat sf = new StringFormat())
|
|
|
|
{
|
2016-04-06 11:44:38 +00:00
|
|
|
sf.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap;
|
2016-03-30 23:25:03 +00:00
|
|
|
sf.Alignment = StringAlignment.Center;
|
|
|
|
sf.LineAlignment = StringAlignment.Center;
|
|
|
|
|
|
|
|
// Draw text with BG
|
|
|
|
if(drawbg)
|
|
|
|
{
|
|
|
|
GraphicsPath p = new GraphicsPath();
|
|
|
|
float radius = textorigin.X;
|
|
|
|
const float outlinewidth = 1;
|
|
|
|
|
|
|
|
RectangleF pathrect = bgrect;
|
|
|
|
pathrect.Width -= 1;
|
|
|
|
pathrect.Height -= 1;
|
|
|
|
|
|
|
|
// Left line
|
|
|
|
p.AddLine(pathrect.Left, pathrect.Bottom - radius + outlinewidth, pathrect.Left, pathrect.Top + radius);
|
|
|
|
p.AddArc(pathrect.Left, pathrect.Top, radius, radius, 180, 90);
|
|
|
|
|
|
|
|
// Top line
|
|
|
|
p.AddLine(pathrect.Left + radius, pathrect.Top, pathrect.Right - radius, pathrect.Top);
|
|
|
|
p.AddArc(pathrect.Right - radius, pathrect.Top, radius, radius, 270, 90);
|
|
|
|
|
|
|
|
// Right line
|
|
|
|
p.AddLine(pathrect.Right, pathrect.Top + radius, pathrect.Right, pathrect.Bottom - radius);
|
|
|
|
p.AddArc(pathrect.Right - radius, pathrect.Bottom - radius, radius, radius, 0, 90);
|
|
|
|
|
|
|
|
// Bottom line
|
|
|
|
p.AddLine(pathrect.Left + radius, pathrect.Bottom, pathrect.Left + radius, pathrect.Bottom);
|
|
|
|
p.AddArc(pathrect.Left, pathrect.Bottom - radius, radius, radius, 90, 90);
|
|
|
|
|
|
|
|
// Fill'n'draw bg
|
|
|
|
using(SolidBrush brush = new SolidBrush(color.ToColor()))
|
|
|
|
g.FillPath(brush, p);
|
|
|
|
|
|
|
|
using(Pen pen = new Pen(backcolor.ToColor(), outlinewidth))
|
|
|
|
g.DrawPath(pen, p);
|
|
|
|
|
|
|
|
// Draw text
|
2016-04-04 22:20:49 +00:00
|
|
|
textrect.Inflate(4, 2);
|
2016-03-30 23:25:03 +00:00
|
|
|
using(SolidBrush brush = new SolidBrush(backcolor.ToColor()))
|
|
|
|
g.DrawString(text, font, brush, textrect, sf);
|
|
|
|
}
|
2016-04-06 11:44:38 +00:00
|
|
|
// Draw plain text
|
2016-03-30 23:25:03 +00:00
|
|
|
else
|
|
|
|
{
|
2016-04-06 11:44:38 +00:00
|
|
|
RectangleF plainbgrect = textrect;
|
|
|
|
if(text.Length > 1) plainbgrect.Inflate(6, 2);
|
2016-03-30 23:25:03 +00:00
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
RectangleF plaintextrect = textrect;
|
|
|
|
plaintextrect.Inflate(6, 4);
|
2016-03-30 23:25:03 +00:00
|
|
|
|
2016-04-06 11:44:38 +00:00
|
|
|
using(SolidBrush brush = new SolidBrush(backcolor.ToColor()))
|
|
|
|
g.FillRectangle(brush, plainbgrect);
|
2016-03-30 23:25:03 +00:00
|
|
|
|
|
|
|
using(SolidBrush brush = new SolidBrush(color.ToColor()))
|
2016-04-06 11:44:38 +00:00
|
|
|
g.DrawString(text, font, brush, plaintextrect, sf);
|
2016-03-30 23:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This unloads the resources
|
|
|
|
public void UnloadResource()
|
|
|
|
{
|
|
|
|
// Clean up
|
2016-03-30 23:25:03 +00:00
|
|
|
if(textbuffer != null)
|
|
|
|
{
|
|
|
|
textbuffer.Dispose();
|
|
|
|
textbuffer = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(texture != null) //mxd
|
|
|
|
{
|
|
|
|
texture.Dispose();
|
|
|
|
texture = null;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Need to update before we can render
|
|
|
|
updateneeded = true;
|
2016-03-30 23:25:03 +00:00
|
|
|
textureupdateneeded = true; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This (re)loads the resources
|
2016-03-30 23:25:03 +00:00
|
|
|
public void ReloadResource() { }
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|