namespace FDK.メディア
{
/// <summary>
- /// DirectWrite を使った Direct2D1ビットマップ。
+ /// DirectWrite を使った Direct2D1ビットマップ。
/// </summary>
/// <remarks>
- /// 「表示文字列」メンバを設定/更新すれば、次回の描画時にビットマップが生成される。
+ /// 「表示文字列」メンバを設定/更新すれば、次回の描画時にビットマップが生成される。
/// </remarks>
public class 文字列画像 : FDK.Activity
{
/// <summary>
- /// このメンバを set すれば、次回の進行描画時に画像が更新される。
+ /// このメンバを set すれば、次回の進行描画時に画像が更新される。
/// </summary>
public string 表示文字列 { get; set; } = null;
+
public string フォント名 { get; set; } = "メイリオ";
+
public float フォントサイズpt { get; set; } = 20.0f;
+
public SharpDX.Direct2D1.InterpolationMode 補正モード { get; set; } = SharpDX.Direct2D1.InterpolationMode.Linear;
+
public SharpDX.RectangleF? 転送元矩形dpx { get; set; } = null;
+
public bool 加算合成 { get; set; } = false;
+
public SharpDX.Size2F レイアウトサイズdpx { get; set; } = new SharpDX.Size2F( -1f, -1f );
+
public bool 下詰め { get; set; } = false;
public 文字列画像()
{
}
+
public 文字列画像( string 文字列, float フォントサイズpt = 20.0f, string フォント名 = "メイリオ" )
+ : this()
{
this.表示文字列 = 文字列;
this.フォント名 = フォント名;
this.フォントサイズpt = フォントサイズpt;
}
+
protected override void Onデバイス依存リソースの作成( デバイスリソース dr )
{
- this.前回の表示文字列 = null;
+ this._前回の表示文字列 = null;
if( this.表示文字列.Nullでも空でもない() )
{
this.ビットマップを生成する( dr );
- this.前回の表示文字列 = this.表示文字列; // 最初の構築完了。
+ this._前回の表示文字列 = this.表示文字列; // 最初の構築完了。
}
}
+
protected override void Onデバイス依存リソースの解放( デバイスリソース dr )
{
- FDK.Utilities.解放する( ref this.黒ブラシ );
- FDK.Utilities.解放する( ref this.白ブラシ );
+ FDK.Utilities.解放する( ref this._黒ブラシ );
+ FDK.Utilities.解放する( ref this._白ブラシ );
FDK.Utilities.解放する( ref this.ビットマップレンダーターゲット );
- FDK.Utilities.解放する( ref this.テキストレイアウト );
- FDK.Utilities.解放する( ref this.テキストフォーマット );
+ FDK.Utilities.解放する( ref this._テキストレイアウト );
+ FDK.Utilities.解放する( ref this._テキストフォーマット );
}
+
public void 進行描画する(
デバイスリソース dr,
float 左位置dpx,
return;
// 表示文字列が変更されているなら、ここで表示ビットマップの再構築を行う。
- if( false == string.Equals( this.表示文字列, this.前回の表示文字列 ) )
+ if( false == string.Equals( this.表示文字列, this._前回の表示文字列 ) )
this.ビットマップを生成する( dr );
if( null == this.ビットマップレンダーターゲット )
} );
}
- protected string 前回の表示文字列 = null;
protected SharpDX.Direct2D1.BitmapRenderTarget ビットマップレンダーターゲット = null;
- protected SharpDX.DirectWrite.TextFormat テキストフォーマット = null;
- protected SharpDX.DirectWrite.TextLayout テキストレイアウト = null;
- protected SharpDX.Direct2D1.SolidColorBrush 白ブラシ = null;
- protected SharpDX.Direct2D1.SolidColorBrush 黒ブラシ = null;
protected void ビットマップを生成する( デバイスリソース dr )
{
- this.前回の表示文字列 = this.表示文字列;
+ this._前回の表示文字列 = this.表示文字列;
// テキストフォーマット/レイアウトを作成し、表示ビットマップのサイズを計算する。
- if( null == this.テキストフォーマット )
+ if( null == this._テキストフォーマット )
{
- this.テキストフォーマット = new SharpDX.DirectWrite.TextFormat( dr.DWriteFactory, this.フォント名, this.フォントサイズpt ) {
+ this._テキストフォーマット = new SharpDX.DirectWrite.TextFormat( dr.DWriteFactory, this.フォント名, this.フォントサイズpt ) {
TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading,
};
}
if( ( 0.0f >= this.レイアウトサイズdpx.Width ) || ( 0.0f >= this.レイアウトサイズdpx.Height ) )
- this.レイアウトサイズdpx = dr.設計画面サイズdpx;
+ this.レイアウトサイズdpx = new SharpDX.Size2F( dr.設計画面サイズdpx.Width, dr.設計画面サイズdpx.Height );
- this.テキストレイアウト?.Dispose();
- this.テキストレイアウト = new SharpDX.DirectWrite.TextLayout(
+ this._テキストレイアウト?.Dispose();
+ this._テキストレイアウト = new SharpDX.DirectWrite.TextLayout(
dr.DWriteFactory,
this.表示文字列,
- this.テキストフォーマット,
+ this._テキストフォーマット,
this.レイアウトサイズdpx.Width,
this.レイアウトサイズdpx.Height );
if( this.下詰め )
{
表示ビットマップのサイズdpx = new SharpDX.Size2F(
- this.テキストレイアウト.Metrics.WidthIncludingTrailingWhitespace,
+ this._テキストレイアウト.Metrics.WidthIncludingTrailingWhitespace,
this.レイアウトサイズdpx.Height ); // レイアウトの最大高
- 上マージン = this.レイアウトサイズdpx.Height - this.テキストレイアウト.Metrics.Height;
+ 上マージン = this.レイアウトサイズdpx.Height - this._テキストレイアウト.Metrics.Height;
}
else
{
表示ビットマップのサイズdpx = new SharpDX.Size2F(
- this.テキストレイアウト.Metrics.WidthIncludingTrailingWhitespace,
- this.テキストレイアウト.Metrics.Height );
+ this._テキストレイアウト.Metrics.WidthIncludingTrailingWhitespace,
+ this._テキストレイアウト.Metrics.Height );
}
// ビットマップレンダーターゲットを生成する。
表示ビットマップのサイズdpx );
// ブラシの作成がまだなら行う。
- if( null == this.白ブラシ )
- this.白ブラシ = new SharpDX.Direct2D1.SolidColorBrush( this.ビットマップレンダーターゲット, SharpDX.Color.LightGray );
- if( null == this.黒ブラシ )
- this.黒ブラシ = new SharpDX.Direct2D1.SolidColorBrush( this.ビットマップレンダーターゲット, SharpDX.Color.Black );
+ if( null == this._白ブラシ )
+ this._白ブラシ = new SharpDX.Direct2D1.SolidColorBrush( this.ビットマップレンダーターゲット, SharpDX.Color.LightGray );
+ if( null == this._黒ブラシ )
+ this._黒ブラシ = new SharpDX.Direct2D1.SolidColorBrush( this.ビットマップレンダーターゲット, SharpDX.Color.Black );
// ビットマップレンダーターゲットにテキストを描画する。
Utilities.D2DBatchDraw( this.ビットマップレンダーターゲット, () => {
this.ビットマップレンダーターゲット.DrawTextLayout( // ドロップシャドウ
new SharpDX.Vector2( 1.0f, 上マージン + 1.0f ),
- this.テキストレイアウト,
- this.黒ブラシ,
+ this._テキストレイアウト,
+ this._黒ブラシ,
SharpDX.Direct2D1.DrawTextOptions.Clip );
this.ビットマップレンダーターゲット.DrawTextLayout( // 本体
new SharpDX.Vector2( 0.0f, 上マージン ),
- this.テキストレイアウト,
- this.白ブラシ,
+ this._テキストレイアウト,
+ this._白ブラシ,
SharpDX.Direct2D1.DrawTextOptions.Clip );
} );
}
+
+ private string _前回の表示文字列 = null;
+
+ private SharpDX.DirectWrite.TextFormat _テキストフォーマット = null;
+
+ private SharpDX.DirectWrite.TextLayout _テキストレイアウト = null;
+
+ private SharpDX.Direct2D1.SolidColorBrush _白ブラシ = null;
+
+ private SharpDX.Direct2D1.SolidColorBrush _黒ブラシ = null;
}
}