Merge branch 'master' of git://github.com/beedee/OpenRA
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Windows.Forms;
|
||||
using Ijw.DirectX;
|
||||
using OpenRa.FileFormats;
|
||||
using OpenRa.Support;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace OpenRa.Graphics
|
||||
{
|
||||
@@ -20,7 +21,11 @@ namespace OpenRa.Graphics
|
||||
public Texture PaletteTexture;
|
||||
|
||||
readonly SpriteHelper sh;
|
||||
readonly FontHelper fhDebug, fhTitle;
|
||||
readonly Font fDebug, fTitle;
|
||||
|
||||
Sheet textSheet;
|
||||
SpriteRenderer rgbaRenderer;
|
||||
Sprite textSprite;
|
||||
|
||||
public Renderer(Control host, Size resolution, bool windowed)
|
||||
{
|
||||
@@ -37,9 +42,29 @@ namespace OpenRa.Graphics
|
||||
WorldSpriteShader = new Shader(device, FileSystem.Open("chrome-shp.fx"));
|
||||
WorldSpriteShader.Quality = ShaderQuality.High;
|
||||
|
||||
sh = new SpriteHelper(device);
|
||||
fhDebug = new FontHelper(device, "Tahoma", 10, false);
|
||||
fhTitle = new FontHelper(device, "Tahoma", 10, true);
|
||||
//sh = new SpriteHelper(device);
|
||||
fDebug = new Font("Tahoma", 10, FontStyle.Regular);
|
||||
fTitle = new Font("Tahoma", 10, FontStyle.Bold);
|
||||
textSheet = new Sheet(this, new Size(256, 256));
|
||||
rgbaRenderer = new SpriteRenderer(this, true, RgbaSpriteShader);
|
||||
textSprite = new Sprite(textSheet, new Rectangle(0, 0, 256, 256), TextureChannel.Alpha);
|
||||
}
|
||||
|
||||
Bitmap RenderTextToBitmap(string s, Font f, Color c)
|
||||
{
|
||||
Bitmap b = new Bitmap(256, 256);
|
||||
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
|
||||
g.DrawString(s, f, new SolidBrush(c), 0, 0);
|
||||
g.Flush();
|
||||
g.Dispose();
|
||||
return b;
|
||||
}
|
||||
|
||||
int2 GetTextSize(string s, Font f)
|
||||
{
|
||||
Bitmap b = new Bitmap(1,1);
|
||||
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);
|
||||
return new int2(g.MeasureString(s, f).ToSize());
|
||||
}
|
||||
|
||||
public GraphicsDevice Device { get { return device; } }
|
||||
@@ -96,26 +121,26 @@ namespace OpenRa.Graphics
|
||||
|
||||
public void DrawText(string text, int2 pos, Color c)
|
||||
{
|
||||
sh.Begin();
|
||||
fhDebug.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
|
||||
sh.End();
|
||||
Bitmap b = RenderTextToBitmap(text, fDebug, c);
|
||||
textSheet.Texture.SetData(b);
|
||||
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome");
|
||||
}
|
||||
|
||||
public void DrawText2(string text, int2 pos, Color c)
|
||||
{
|
||||
sh.Begin();
|
||||
fhTitle.Draw(sh, text, pos.X, pos.Y, c.ToArgb());
|
||||
sh.End();
|
||||
Bitmap b = RenderTextToBitmap(text, fTitle, c);
|
||||
textSheet.Texture.SetData(b);
|
||||
rgbaRenderer.DrawSprite(textSprite, pos.ToFloat2(), "chrome");
|
||||
}
|
||||
|
||||
public int2 MeasureText(string text)
|
||||
{
|
||||
return new int2(fhDebug.MeasureText(sh, text));
|
||||
return GetTextSize(text, fDebug);
|
||||
}
|
||||
|
||||
public int2 MeasureText2(string text)
|
||||
{
|
||||
return new int2(fhTitle.MeasureText(sh, text));
|
||||
return GetTextSize(text, fTitle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</StartupObject>
|
||||
<ApplicationIcon>OpenRA.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;SANITY_CHECKS</DefineConstants>
|
||||
@@ -44,13 +44,13 @@
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<UseVSHostingProcess>false</UseVSHostingProcess>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -25,10 +25,9 @@ Global
|
||||
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Debug|Any CPU.Build.0 = Debug|x86
|
||||
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{230F65CE-A6DE-4235-8B38-13A3D606C7F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
||||
Reference in New Issue
Block a user