Classic modes: further text label rendering optimization.

MODELDEF parser: rewrote most of the parser logic. Now it picks actor model(s) based on Frame / FrameName properties.
This commit is contained in:
MaxED 2016-04-06 11:44:38 +00:00 committed by spherallic
parent bf9c3c8abe
commit 693f241202
9 changed files with 82 additions and 59 deletions

View File

@ -387,6 +387,21 @@ namespace CodeImp.DoomBuilder
// Clean up temp file
CleanTempFile(General.Map);
if(General.Map != null)
{
// Device reset may be needed...
if(General.Editing.Mode is ClassicMode)
{
General.Map.Graphics.Reset();
General.MainWindow.RedrawDisplay();
}
/*else if(General.Editing.Mode is VisualMode)
{
General.MainWindow.StopExclusiveMouseInput();
General.MainWindow.StartExclusiveMouseInput();
}*/
}
General.Plugins.OnMapSaveEnd(SavePurpose.Testing);
General.MainWindow.FocusDisplay();
if(General.Editing.Mode is ClassicMode) General.MainWindow.RedrawDisplay();

View File

@ -1533,7 +1533,6 @@ namespace CodeImp.DoomBuilder.Rendering
AlignX = TextAlignmentX.Center,
AlignY = TextAlignmentY.Middle,
Color = General.Colors.WaypointColor,
Backcolor = General.Colors.Background,
TransformCoords = true,
Rectangle = new RectangleF(waypoints[i].Position.x, waypoints[i].Position.y, 0.0f, 0.0f)
};
@ -1737,7 +1736,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.Device.SetRenderState(RenderState.FogEnable, false);
graphics.Shaders.Display2D.Texture1 = label.Texture;
SetWorldTransformation(false);
graphics.Shaders.Display2D.SetSettings(1f, 1f, 0f, 1f, true);
graphics.Shaders.Display2D.SetSettings(1f, 1f, 0f, 1f, false);
graphics.Device.SetStreamSource(0, label.VertexBuffer, 0, FlatVertex.Stride);
// Draw
@ -1770,7 +1769,7 @@ namespace CodeImp.DoomBuilder.Rendering
graphics.Device.SetRenderState(RenderState.TextureFactor, -1);
graphics.Device.SetRenderState(RenderState.FogEnable, false);
SetWorldTransformation(false);
graphics.Shaders.Display2D.SetSettings(1f, 1f, 0f, 1f, true);
graphics.Shaders.Display2D.SetSettings(1f, 1f, 0f, 1f, false);
// Begin drawing
graphics.Shaders.Display2D.Begin();

View File

@ -88,7 +88,7 @@ namespace CodeImp.DoomBuilder.Rendering
public TextAlignmentX AlignX { get { return alignx; } set { alignx = value; updateneeded = true; } }
public TextAlignmentY AlignY { get { return aligny; } set { aligny = value; updateneeded = true; } }
public PixelColor Color { get { return color; } set { if(!color.Equals(value)) { color = value; textureupdateneeded = true; } } }
public PixelColor Backcolor { get { return backcolor; } set { if(!backcolor.Equals(value)) { backcolor = value; textureupdateneeded = true; } } }
public PixelColor BackColor { get { return backcolor; } set { if(!backcolor.Equals(value)) { backcolor = value; textureupdateneeded = true; } } }
public bool DrawBackground { get { return drawbg; } set { if(drawbg != value) { drawbg = value; textureupdateneeded = true; } } } //mxd
internal Texture Texture { get { return texture; } } //mxd
internal VertexBuffer VertexBuffer { get { return textbuffer; } }
@ -109,7 +109,7 @@ namespace CodeImp.DoomBuilder.Rendering
this.font = General.Settings.TextLabelFont; //mxd
this.rect = new RectangleF(0f, 0f, 1f, 1f);
this.color = new PixelColor(255, 255, 255, 255);
this.backcolor = new PixelColor(255, 0, 0, 0);
this.backcolor = new PixelColor(128, 0, 0, 0);
this.alignx = TextAlignmentX.Center;
this.aligny = TextAlignmentY.Top;
this.textsize = new SizeF();
@ -119,10 +119,6 @@ namespace CodeImp.DoomBuilder.Rendering
// Register as resource
General.Map.Graphics.RegisterResource(this);
//mxd. Create the buffer
this.textbuffer = new VertexBuffer(General.Map.Graphics.Device, 4 * FlatVertex.Stride,
Usage.Dynamic | Usage.WriteOnly, VertexFormat.None, Pool.Default);
// We have no destructor
GC.SuppressFinalize(this);
}
@ -203,7 +199,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
// Create label image
Bitmap img = CreateLabelImage(text, font, color, backcolor, drawbg);
Bitmap img = CreateLabelImage(text, font, alignx, aligny, color, backcolor, drawbg);
textsize = img.Size;
// Create texture
@ -234,6 +230,13 @@ namespace CodeImp.DoomBuilder.Rendering
case TextAlignmentY.Bottom: beginy = absview.Y + absview.Height - textsize.Height; break;
}
//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);
}
//mxd. Lock the buffer
using(DataStream stream = textbuffer.Lock(0, 4 * FlatVertex.Stride, LockFlags.Discard | LockFlags.NoSystemLock))
{
@ -258,7 +261,7 @@ namespace CodeImp.DoomBuilder.Rendering
}
//mxd
private static Bitmap CreateLabelImage(string text, Font font, PixelColor color, PixelColor backcolor, bool drawbg)
private static Bitmap CreateLabelImage(string text, Font font, TextAlignmentX alignx, TextAlignmentY aligny, PixelColor color, PixelColor backcolor, bool drawbg)
{
PointF textorigin = new PointF(4, 3);
RectangleF textrect = new RectangleF(textorigin, General.Interface.MeasureString(text, font));
@ -266,7 +269,25 @@ namespace CodeImp.DoomBuilder.Rendering
textrect.Height = (float)Math.Round(textrect.Height);
RectangleF bgrect = new RectangleF(0, 0, textrect.Width + textorigin.X * 2, textrect.Height + textorigin.Y * 2);
Bitmap result = new Bitmap((int)bgrect.Width, (int)bgrect.Height);
// Make PO2 image, for speed and giggles...
RectangleF po2rect = new RectangleF(0, 0, General.NextPowerOf2((int)bgrect.Width), General.NextPowerOf2((int)bgrect.Height));
switch(alignx)
{
case TextAlignmentX.Center: bgrect.X = (po2rect.Width - bgrect.Width) / 2; break;
case TextAlignmentX.Right: bgrect.X = po2rect.Width - bgrect.Width; break;
}
switch(aligny)
{
case TextAlignmentY.Middle: bgrect.Y = (po2rect.Height - bgrect.Height) / 2; break;
case TextAlignmentY.Bottom: bgrect.Y = po2rect.Height - bgrect.Height; break;
}
textrect.X += bgrect.X;
textrect.Y += bgrect.Y;
Bitmap result = new Bitmap((int)po2rect.Width, (int)po2rect.Height);
using(Graphics g = Graphics.FromImage(result))
{
g.SmoothingMode = SmoothingMode.HighQuality;
@ -276,7 +297,7 @@ namespace CodeImp.DoomBuilder.Rendering
// Draw text
using(StringFormat sf = new StringFormat())
{
sf.FormatFlags = StringFormatFlags.NoWrap;
sf.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.NoWrap;
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
@ -319,21 +340,20 @@ namespace CodeImp.DoomBuilder.Rendering
using(SolidBrush brush = new SolidBrush(backcolor.ToColor()))
g.DrawString(text, font, brush, textrect, sf);
}
// Draw text with outline
// Draw plain text
else
{
RectangleF pathrect = textrect;
pathrect.Inflate(1, 3);
RectangleF plainbgrect = textrect;
if(text.Length > 1) plainbgrect.Inflate(6, 2);
GraphicsPath p = new GraphicsPath();
p.AddString(text, font.FontFamily, (int)font.Style, g.DpiY * font.Size / 72f, pathrect, sf);
RectangleF plaintextrect = textrect;
plaintextrect.Inflate(6, 4);
// Draw'n'fill text
using(Pen pen = new Pen(backcolor.ToColor(), 3))
g.DrawPath(pen, p);
using(SolidBrush brush = new SolidBrush(backcolor.ToColor()))
g.FillRectangle(brush, plainbgrect);
using(SolidBrush brush = new SolidBrush(color.ToColor()))
g.FillPath(brush, p);
g.DrawString(text, font, brush, plaintextrect, sf);
}
}
}

View File

@ -205,17 +205,20 @@ namespace CodeImp.DoomBuilder.Windows
// Constructor
internal MainForm()
{
// Fetch pointer
windowptr = base.Handle;
//mxd. Graphics
graphics = Graphics.FromHwndInternal(windowptr);
//mxd. Set DPI-aware icon size
using(Graphics g = this.CreateGraphics())
{
DPIScaler = new SizeF(g.DpiX / 96, g.DpiY / 96);
DPIScaler = new SizeF(graphics.DpiX / 96, graphics.DpiY / 96);
if(DPIScaler.Width != 1.0f || DPIScaler.Height != 1.0f)
{
ScaledIconSize.Width = (int)Math.Round(ScaledIconSize.Width * DPIScaler.Width);
ScaledIconSize.Height = (int)Math.Round(ScaledIconSize.Height * DPIScaler.Height);
}
}
// Setup controls
InitializeComponent();
@ -235,9 +238,6 @@ namespace CodeImp.DoomBuilder.Windows
labelcollapsedinfo.Text = "";
display.Dock = DockStyle.Fill;
// Fetch pointer
windowptr = base.Handle;
// Make array for view modes
viewmodesbuttons = new ToolStripButton[Renderer2D.NUM_VIEW_MODES];
viewmodesbuttons[(int)ViewMode.Normal] = buttonviewnormal;
@ -291,9 +291,6 @@ namespace CodeImp.DoomBuilder.Windows
//mxd. Hints
hintsPanel = new HintsPanel();
hintsDocker = new Docker("hints", "Help", hintsPanel);
//mxd. Graphics
graphics = Graphics.FromHwndInternal(windowptr);
}
#endregion
@ -2669,14 +2666,14 @@ namespace CodeImp.DoomBuilder.Windows
private string GetDisplayFilename(string filename)
{
// String doesnt fit?
if(GetStringWidth(filename) > MAX_RECENT_FILES_PIXELS)
if(MeasureString(filename, this.Font).Width > MAX_RECENT_FILES_PIXELS)
{
// Start chopping off characters
for(int i = filename.Length - 6; i >= 0; i--)
{
// Does it fit now?
string newname = filename.Substring(0, 3) + "..." + filename.Substring(filename.Length - i, i);
if(GetStringWidth(newname) <= MAX_RECENT_FILES_PIXELS) return newname;
if(MeasureString(newname, this.Font).Width <= MAX_RECENT_FILES_PIXELS) return newname;
}
// Cant find anything that fits (most unlikely!)
@ -2689,14 +2686,6 @@ namespace CodeImp.DoomBuilder.Windows
}
}
// This returns the width of a string
private float GetStringWidth(string str)
{
Graphics g = Graphics.FromHwndInternal(this.Handle);
SizeF strsize = g.MeasureString(str, this.Font);
return strsize.Width;
}
// Exit clicked
private void itemexit_Click(object sender, EventArgs e) { this.Close(); }

View File

@ -484,7 +484,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
l.AlignX = TextAlignmentX.Center;
l.AlignY = TextAlignmentY.Middle;
l.Color = General.Colors.InfoLine;
l.Backcolor = General.Colors.Background.WithAlpha(255);
l.BackColor = General.Colors.Background.WithAlpha(128);
larr[i] = l;
}
@ -519,7 +519,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
l.AlignX = TextAlignmentX.Center;
l.AlignY = TextAlignmentY.Middle;
l.Color = (linedef == highlighted ? General.Colors.Selection : General.Colors.Highlight);
l.Backcolor = General.Colors.Background.WithAlpha(255);
l.BackColor = General.Colors.Background.WithAlpha(192);
l.Text = (++index).ToString();
labels.Add(linedef, l);
}

View File

@ -160,7 +160,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
labelarray[i].AlignX = TextAlignmentX.Center;
labelarray[i].AlignY = TextAlignmentY.Middle;
labelarray[i].Color = c;
labelarray[i].Backcolor = General.Colors.Background.WithAlpha(255);
labelarray[i].BackColor = General.Colors.Background.WithAlpha(128);
}
labels.Add(s, labelarray);
}

View File

@ -954,7 +954,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
l.AlignX = TextAlignmentX.Center;
l.AlignY = TextAlignmentY.Middle;
l.Color = General.Colors.InfoLine;
l.Backcolor = General.Colors.Background.WithAlpha(255);
l.BackColor = General.Colors.Background.WithAlpha(128);
larr[i] = l;
}
@ -1000,8 +1000,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
l.Color = (thing == highlighted ? General.Colors.Selection : General.Colors.Highlight);
l.Backcolor = General.Colors.Background.WithAlpha(255);
l.DrawBackground = true;
l.BackColor = General.Colors.Background.WithAlpha(192);
l.Text = (++index).ToString();
labels.Add(thing, l);
}

View File

@ -85,7 +85,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
vertexnames[i].AlignX = TextAlignmentX.Center;
vertexnames[i].AlignY = TextAlignmentY.Middle;
vertexnames[i].Color = General.Colors.Highlight.WithAlpha(255);
vertexnames[i].Backcolor = General.Colors.Background.WithAlpha(255);
}
points = new List<DrawnVertex>();
overgroups = new List<int>();

View File

@ -103,12 +103,14 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Initialization
private void Initialize()
{
label = new TextLabel();
label.AlignX = TextAlignmentX.Center;
label.AlignY = TextAlignmentY.Middle;
label.Color = General.Colors.Highlight;
label.Backcolor = General.Colors.Background;
label.TransformCoords = true;
label = new TextLabel
{
AlignX = TextAlignmentX.Center,
AlignY = TextAlignmentY.Middle,
Color = General.Colors.Highlight,
BackColor = General.Colors.Background.WithAlpha(64),
TransformCoords = true,
};
}
// Disposer