OSDN Git Service

FDK.メディア.文字列テクスチャ クラスを SST.曲.タイトルテクスチャ へ移設。
authorくまかみ工房 <kumakamikoubou@gmail.com>
Fri, 7 Oct 2016 06:45:31 +0000 (15:45 +0900)
committerくまかみ工房 <kumakamikoubou@gmail.com>
Fri, 7 Oct 2016 06:45:31 +0000 (15:45 +0900)
FDK24/FDK24.csproj
FDK24/メディア/文字列テクスチャ.cs [deleted file]
StrokeStyleT/StrokeStyleT.csproj
StrokeStyleT/曲/Node.cs
StrokeStyleT/曲/タイトルテクスチャ.cs [new file with mode: 0644]

index ca8cd52..8f73771 100644 (file)
     <Compile Include="メディア\ビットマップ付きテクスチャ.cs" />
     <Compile Include="メディア\動画.cs" />
     <Compile Include="メディア\描画可能画像.cs" />
-    <Compile Include="メディア\文字列テクスチャ.cs" />
     <Compile Include="メディア\文字列画像.cs" />
     <Compile Include="メディア\画像.cs" />
     <Compile Include="メディア\矩形リスト.cs" />
diff --git a/FDK24/メディア/文字列テクスチャ.cs b/FDK24/メディア/文字列テクスチャ.cs
deleted file mode 100644 (file)
index 7174b9c..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-
-namespace FDK.メディア
-{
-       /// <summary>
-       /// DirectWrite を使って文字列を書き込めるテクスチャ。
-       /// </summary>
-       public class 文字列テクスチャ : テクスチャ
-       {
-               public string 表示文字列 { get; set; } = null;
-               public float フォントサイズpt { get; set; } = 20.0f;
-               public string フォント名 { get; set; } = "メイリオ";
-
-               public 文字列テクスチャ( string 初期文字列, float フォントサイズpt = 20.0f, string フォント名 = "メイリオ" ) : base( SharpDX.Size2.Zero )
-               {
-                       this.表示文字列 = 初期文字列 ?? "";
-                       this.フォントサイズpt = フォントサイズpt;
-                       this.フォント名 = フォント名;
-               }
-               protected override void Onデバイス依存リソースの作成( デバイスリソース dr )
-               {
-                       this.前回の表示文字列 = this.表示文字列;
-                       this.テクスチャとビットマップを作成する( dr );
-               }
-               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.テキストフォーマット );
-
-                       // テクスチャを解放する。
-                       base.Onデバイス依存リソースの解放( dr );
-               }
-               public new void 進行描画する( デバイスリソース dr, SharpDX.Matrix ワールド行列変換, SharpDX.RectangleF? 転送元矩形 = null )
-               {
-                       if( this.表示文字列.Nullまたは空である() )
-                               return;
-
-                       // 表示文字列が変更されているなら、ここで表示ビットマップの再構築を行う。
-                       if( false == string.Equals( this.表示文字列, this.前回の表示文字列 ) )
-                               this.テクスチャとビットマップを作成する( dr );
-
-                       // テクスチャを描画する。
-                       base.進行描画する( dr, ワールド行列変換, 転送元矩形 );
-               }
-
-               protected string 前回の表示文字列 = null;
-               protected SharpDX.DirectWrite.TextFormat テキストフォーマット = null;
-               protected SharpDX.DirectWrite.TextLayout テキストレイアウト = null;
-               protected SharpDX.Direct2D1.Bitmap1 ビットマップターゲット = null;
-               protected SharpDX.Direct2D1.SolidColorBrush 白ブラシ = null;
-               protected SharpDX.Direct2D1.SolidColorBrush 黒ブラシ = null;
-
-               protected void テクスチャとビットマップを作成する( デバイスリソース dr )
-               {
-                       this.前回の表示文字列 = this.表示文字列;
-
-                       // テクスチャとビットマップを解放する。
-                       this.Onデバイス依存リソースの解放( dr ); // base. じゃなくて this.
-
-                       if( this.表示文字列.Nullまたは空である() )
-                               return;
-
-                       #region " テキストフォーマット/レイアウトを作成し、表示ビットマップのサイズを計算し、ユーザ指定サイズdpx に格納する。"
-                       //----------------
-                       this.テキストフォーマット = new SharpDX.DirectWrite.TextFormat( dr.DWriteFactory, this.フォント名, this.フォントサイズpt ) {
-                               TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading,
-                       };
-
-                       var 最大サイズdpx = dr.設計画面サイズdpx;
-
-                       this.テキストレイアウト = new SharpDX.DirectWrite.TextLayout(
-                               dr.DWriteFactory,
-                               this.表示文字列.Nullまたは空である() ? " " : this.表示文字列,
-                               this.テキストフォーマット,
-                               最大サイズdpx.Width,
-                               最大サイズdpx.Height );
-
-                       this.ユーザ指定サイズdpx = new SharpDX.Size2(
-                               (int) ( this.テキストレイアウト.Metrics.WidthIncludingTrailingWhitespace + 0.5f ),
-                               (int) ( this.テキストレイアウト.Metrics.Height + 0.5f ) );
-                       //----------------
-                       #endregion
-
-                       // ユーザ指定サイズdpx に従って、テクスチャを作成する。
-                       base.Onデバイス依存リソースの作成( dr ); // this. じゃなくて base.
-
-                       #region " 作成したテクスチャとデータを共有するビットマップを作成する。"
-                       //----------------
-                       using( var dxgiSurface = this.Texture.QueryInterfaceOrNull<SharpDX.DXGI.Surface1>() )
-                       {
-                               var bmpProp = new SharpDX.Direct2D1.BitmapProperties1() {
-                                       PixelFormat = new SharpDX.Direct2D1.PixelFormat( dxgiSurface.Description.Format, SharpDX.Direct2D1.AlphaMode.Premultiplied ),
-                                       BitmapOptions = SharpDX.Direct2D1.BitmapOptions.Target | SharpDX.Direct2D1.BitmapOptions.CannotDraw,
-                               };
-                               this.ビットマップターゲット = new SharpDX.Direct2D1.Bitmap1( dr.D2DContext1, dxgiSurface, bmpProp );
-                       }
-                       //----------------
-                       #endregion
-                       #region " ビットマップに文字列を描画する。"
-                       //----------------
-                       using( var 旧ターゲット = dr.D2DContext1.Target )
-                       {
-                               try
-                               {
-                                       this.白ブラシ = new SharpDX.Direct2D1.SolidColorBrush( dr.D2DContext1, SharpDX.Color.LightGray );
-                                       this.黒ブラシ = new SharpDX.Direct2D1.SolidColorBrush( dr.D2DContext1, SharpDX.Color.Black );
-
-                                       dr.D2DContextの設定をリセットする( dr.D2DContext1 );
-                                       dr.D2DContext1.Target = this.ビットマップターゲット;
-
-                                       FDK.Utilities.D2DBatchDraw( dr.D2DContext1, () => {
-
-                                               dr.D2DContext1.Clear( SharpDX.Color.Transparent );
-
-                                               dr.D2DContext1.DrawTextLayout(    // ドロップシャドウ部
-                                                       new SharpDX.Vector2( 1.0f, 1.0f ),
-                                                       this.テキストレイアウト,
-                                                       黒ブラシ,
-                                                       SharpDX.Direct2D1.DrawTextOptions.Clip );
-
-                                               dr.D2DContext1.DrawTextLayout(    // 本体部
-                                                       new SharpDX.Vector2( 0.0f, 0.0f ),
-                                                       this.テキストレイアウト,
-                                                       白ブラシ,
-                                                       SharpDX.Direct2D1.DrawTextOptions.Clip );
-
-                                       } );
-                               }
-                               finally
-                               {
-                                       dr.D2DContext1.Target = 旧ターゲット;
-                               }
-                       }
-                       //----------------
-                       #endregion
-               }
-       }
-}
index 636f0b4..8ef9194 100644 (file)
@@ -88,6 +88,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="曲\タイトルテクスチャ.cs" />
     <Compile Include="ステージ\選曲\曲パネルビュー.cs" />
     <Compile Include="設定\Config.cs" />
     <Compile Include="SSTException.cs" />
index e91e343..6fffd7e 100644 (file)
@@ -74,7 +74,7 @@ namespace SST.曲
                protected override void On活性化( デバイスリソース dr )
                {
                        // タイトル部の文字画像を作成する。
-                       this.子リスト.Add( this.タイトル文画像 = new 文字列テクスチャ( this.タイトル, 30f ) );
+                       this.子リスト.Add( this.タイトル文画像 = new タイトルテクスチャ( this.タイトル ) );
                }
                protected override void On非活性化( デバイスリソース dr )
                {
@@ -110,7 +110,7 @@ namespace SST.曲
                                this.タイトル文画像.進行描画する( dr, ワールド変換行列 );
                }
 
-               protected FDK.メディア.文字列テクスチャ タイトル文画像 = null;
+               protected タイトルテクスチャ タイトル文画像 = null;
 
                protected static FDK.メディア.テクスチャ 既定の曲画像 = null;   // 全インスタンスで共有
        }
diff --git a/StrokeStyleT/曲/タイトルテクスチャ.cs b/StrokeStyleT/曲/タイトルテクスチャ.cs
new file mode 100644 (file)
index 0000000..211719d
--- /dev/null
@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using FDK.メディア;
+using FDK;     // string拡張メソッド用。
+
+namespace SST.曲
+{
+       public class タイトルテクスチャ : FDK.メディア.ビットマップ付きテクスチャ
+       {
+               public string 表示文字列 { get; set; } = null;
+
+               public タイトルテクスチャ( string 初期文字列 ) : base( new SharpDX.Size2( 1, 1 ) )
+               {
+                       this.表示文字列 = 初期文字列 ?? "(no title)";
+               }
+               protected override void Onデバイス依存リソースの作成( デバイスリソース dr )
+               {
+                       this.テクスチャを更新する( dr );
+               }
+               protected override void Onデバイス依存リソースの解放( デバイスリソース dr )
+               {
+                       // テキスト描画用リソースを解放する。
+                       FDK.Utilities.解放する( ref this.黒ブラシ );
+                       FDK.Utilities.解放する( ref this.白ブラシ );
+                       FDK.Utilities.解放する( ref this.テキストレイアウト );
+                       FDK.Utilities.解放する( ref this.テキストフォーマット );
+
+                       // ビットマップ付きテクスチャを解放する。
+                       base.Onデバイス依存リソースの解放( dr );
+               }
+               public new void 進行描画する( デバイスリソース dr, SharpDX.Matrix ワールド行列変換, SharpDX.RectangleF? 転送元矩形 = null )
+               {
+                       if( this.表示文字列.Nullまたは空である() )
+                               return;
+
+                       // 表示文字列が変更されているなら、ここで表示ビットマップの再構築を行う。
+                       if( false == string.Equals( this.表示文字列, this.前回の表示文字列 ) )
+                               this.テクスチャを更新する( dr );
+
+                       // テクスチャを描画する。
+                       base.進行描画する( dr, ワールド行列変換, 転送元矩形 );
+               }
+
+               protected float フォントサイズpt = 30.0f;
+               protected string フォント名 = "メイリオ";
+               protected string 前回の表示文字列 = null;
+               protected SharpDX.DirectWrite.TextFormat テキストフォーマット = null;
+               protected SharpDX.DirectWrite.TextLayout テキストレイアウト = null;
+               protected SharpDX.Direct2D1.SolidColorBrush 白ブラシ = null;
+               protected SharpDX.Direct2D1.SolidColorBrush 黒ブラシ = null;
+
+               /// <summary>
+               /// デバイス依存リソースの作成() から、または表示文字列が変更された場合に呼び出される。
+               /// </summary>
+               protected void テクスチャを更新する( デバイスリソース dr )
+               {
+                       this.前回の表示文字列 = this.表示文字列;
+
+                       // すべてのリソースを解放する。
+                       this.Onデバイス依存リソースの解放( dr ); // base. じゃなくて this.
+
+                       if( this.表示文字列.Nullまたは空である() )
+                               return;
+
+                       #region " テキストフォーマット/レイアウトを作成し、表示ビットマップのサイズを計算し、ユーザ指定サイズdpx に格納する。"
+                       //----------------
+                       this.テキストフォーマット = new SharpDX.DirectWrite.TextFormat( dr.DWriteFactory, this.フォント名, this.フォントサイズpt ) {
+                               TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading,
+                       };
+
+                       var 最大サイズdpx = dr.設計画面サイズdpx;
+                       this.テキストレイアウト = new SharpDX.DirectWrite.TextLayout(
+                               dr.DWriteFactory,
+                               this.表示文字列.Nullまたは空である() ? " " : this.表示文字列,
+                               this.テキストフォーマット,
+                               最大サイズdpx.Width,
+                               最大サイズdpx.Height );
+
+                       this.ユーザ指定サイズdpx = new SharpDX.Size2(
+                               (int) ( this.テキストレイアウト.Metrics.WidthIncludingTrailingWhitespace + 0.5f ),
+                               (int) ( this.テキストレイアウト.Metrics.Height + 0.5f ) );
+                       //----------------
+                       #endregion
+
+                       // ビットマップ付きテクスチャを作成する。(上で設定した ユーザ指定サイズdpx の大きさで作成される。)
+                       base.Onデバイス依存リソースの作成( dr );
+
+                       #region " ビットマップに文字列を描画する。"
+                       //----------------
+                       this.ビットマップへ描画する( dr, ( context, bitmap ) => {
+
+                               this.白ブラシ = new SharpDX.Direct2D1.SolidColorBrush( dr.D2DContext1, SharpDX.Color.LightGray );
+                               this.黒ブラシ = new SharpDX.Direct2D1.SolidColorBrush( dr.D2DContext1, SharpDX.Color.Black );
+
+                               dr.D2DContext1.Clear( SharpDX.Color.Transparent );
+
+                               dr.D2DContext1.DrawTextLayout(    // ドロップシャドウ部
+                                       new SharpDX.Vector2( 1.0f, 1.0f ),
+                                       this.テキストレイアウト,
+                                       this.黒ブラシ,
+                                       SharpDX.Direct2D1.DrawTextOptions.Clip );
+
+                               dr.D2DContext1.DrawTextLayout(    // 本体部
+                                       new SharpDX.Vector2( 0.0f, 0.0f ),
+                                       this.テキストレイアウト,
+                                       this.白ブラシ,
+                                       SharpDX.Direct2D1.DrawTextOptions.Clip );
+                       } );
+                       //----------------
+                       #endregion
+               }
+       }
+}