(empty log message)
@@ -1,58 +0,0 @@ | ||
1 | -using System.Reflection; | |
2 | -using System.Runtime.CompilerServices; | |
3 | - | |
4 | -// | |
5 | -// アセンブリに関する一般情報は以下の | |
6 | -// 属性セットを通して制御されます。アセンブリに関連付けられている | |
7 | -// 情報を変更するには、これらの属性値を変更してください。 | |
8 | -// | |
9 | -[assembly: AssemblyTitle("NeoFT DirectDraw")] | |
10 | -[assembly: AssemblyDescription("NeoFreeTrain DirectDraw library")] | |
11 | -[assembly: AssemblyConfiguration("")] | |
12 | -[assembly: AssemblyCompany("c477")] | |
13 | -[assembly: AssemblyProduct("NeoFT")] | |
14 | -[assembly: AssemblyCopyright("(C)Copyright by c477 & K.Kawaguchi, 2004")] | |
15 | -[assembly: AssemblyTrademark("")] | |
16 | -[assembly: AssemblyCulture("")] | |
17 | - | |
18 | -// | |
19 | -// アセンブリのバージョン情報は、以下の 4 つの属性で構成されます : | |
20 | -// | |
21 | -// Major Version | |
22 | -// Minor Version | |
23 | -// Build Number | |
24 | -// Revision | |
25 | -// | |
26 | -// 下にあるように、'*' を使って、すべての値を指定するか、 | |
27 | -// ビルドおよびリビジョン番号を既定値にすることができます。 | |
28 | - | |
29 | -[assembly: AssemblyVersion("1.0.*")] | |
30 | - | |
31 | -// | |
32 | -// アセンブリに署名するには、使用するキーを指定しなければなりません。 | |
33 | -// アセンブリ署名に関する詳細については、Microsoft .NET Framework ドキュメントを参照してください。 | |
34 | -// | |
35 | -// 下記の属性を使って、署名に使うキーを制御します。 | |
36 | -// | |
37 | -// メモ : | |
38 | -// (*) キーが指定されないと、アセンブリは署名されません。 | |
39 | -// (*) KeyName は、コンピュータにインストールされている | |
40 | -// 暗号サービス プロバイダ (CSP) のキーを表します。KeyFile は、 | |
41 | -// キーを含むファイルです。 | |
42 | -// (*) KeyFile および KeyName の値が共に指定されている場合は、 | |
43 | -// 以下の処理が行われます : | |
44 | -// (1) KeyName が CSP に見つかった場合、そのキーが使われます。 | |
45 | -// (2) KeyName が存在せず、KeyFile が存在する場合、 | |
46 | -// KeyFile にあるキーが CSP にインストールされ、使われます。 | |
47 | -// (*) KeyFile を作成するには、sn.exe (厳密な名前) ユーティリティを使ってください。 | |
48 | -// KeyFile を指定するとき、KeyFile の場所は、 | |
49 | -// プロジェクト出力 ディレクトリへの相対パスでなければなりません。 | |
50 | -// パスは、%Project Directory%\obj\<configuration> です。たとえば、KeyFile がプロジェクト ディレクトリにある場合、 | |
51 | -// AssemblyKeyFile 属性を | |
52 | -// [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] として指定します。 | |
53 | -// (*) 遅延署名は高度なオプションです。 | |
54 | -// 詳細については Microsoft .NET Framework ドキュメントを参照してください。 | |
55 | -// | |
56 | -[assembly: AssemblyDelaySign(false)] | |
57 | -[assembly: AssemblyKeyFile("")] | |
58 | -[assembly: AssemblyKeyName("")] |
@@ -1,154 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Drawing; | |
3 | -using System.Collections; | |
4 | -using nft.framework.drawing; | |
5 | -using DxVBLib; | |
6 | - | |
7 | -namespace nft.drawing.ddraw7 | |
8 | -{ | |
9 | - internal class Util | |
10 | - { | |
11 | - public const int OPAQUE_KEY = 0x01000000; | |
12 | - | |
13 | - internal static RECT toRECT( Rectangle srcRect ) | |
14 | - { | |
15 | - RECT r = new RECT(); | |
16 | - r.Left = srcRect.Left; | |
17 | - r.Top = srcRect.Top; | |
18 | - r.Right = srcRect.Right; | |
19 | - r.Bottom= srcRect.Bottom; | |
20 | - return r; | |
21 | - } | |
22 | - internal static RECT toRECT( int x1, int y1, int x2, int y2 ) { | |
23 | - RECT r = new RECT(); | |
24 | - r.Left = x1; | |
25 | - r.Top = y1; | |
26 | - r.Right = x2; | |
27 | - r.Bottom= y2; | |
28 | - return r; | |
29 | - } | |
30 | - internal static RECT toRECT( Point pt, Size sz ) { | |
31 | - RECT r = new RECT(); | |
32 | - r.Left = pt.X; | |
33 | - r.Top = pt.Y; | |
34 | - r.Right = pt.X+sz.Width; | |
35 | - r.Bottom= pt.Y+sz.Height; | |
36 | - return r; | |
37 | - } | |
38 | - internal static Rectangle toRectangle( RECT r ) { | |
39 | - return new Rectangle( r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top ); | |
40 | - } | |
41 | - | |
42 | - /// <summary> | |
43 | - /// Compute the intersection of two RECTs. | |
44 | - /// </summary> | |
45 | - internal static RECT intersect( RECT a, RECT b ) { | |
46 | - RECT r = new RECT(); | |
47 | - r.Left = Math.Max( a.Left, b.Left ); | |
48 | - r.Top = Math.Max( a.Top, b.Top ); | |
49 | - r.Right = Math.Min( a.Right, b.Right ); | |
50 | - r.Bottom = Math.Min( a.Bottom, b.Bottom ); | |
51 | - return r; | |
52 | - } | |
53 | - | |
54 | - /// <summary> | |
55 | - /// Clip two rectangles by the clipping region. | |
56 | - /// | |
57 | - /// </summary> | |
58 | - internal static void clip( ref RECT dst, ref RECT src, RECT clip ) { | |
59 | - int t; | |
60 | - | |
61 | - // compute new dst.Left | |
62 | - t = Math.Max( dst.Left, clip.Left ); | |
63 | - src.Left += (t-dst.Left); | |
64 | - dst.Left = t; // dst.Left += (t-dst.Left) | |
65 | - | |
66 | - t = Math.Max( dst.Top, clip.Top ); | |
67 | - src.Top += (t-dst.Top); | |
68 | - dst.Top = t; | |
69 | - | |
70 | - t = Math.Min( dst.Right, clip.Right ); | |
71 | - src.Right += (t-dst.Right); | |
72 | - dst.Right = t; | |
73 | - | |
74 | - t = Math.Min( dst.Bottom, clip.Bottom ); | |
75 | - src.Bottom += (t-dst.Bottom); | |
76 | - dst.Bottom = t; | |
77 | - } | |
78 | - | |
79 | - /// <summary> | |
80 | - /// Clipping in a vflip mode. | |
81 | - /// | |
82 | - /// In this mode, clipping is done as: | |
83 | - /// | |
84 | - /// ###--- ------ | |
85 | - /// ###--- => ###--- | |
86 | - /// ------ ###--- | |
87 | - /// </summary> | |
88 | - /// <param name="dst"></param> | |
89 | - /// <param name="src"></param> | |
90 | - /// <param name="clip"></param> | |
91 | - internal static void clipVflip( ref RECT dst, ref RECT src, RECT clip ) { | |
92 | - int t; | |
93 | - | |
94 | - // compute new dst.Left | |
95 | - t = Math.Max( dst.Left, clip.Left ); | |
96 | - src.Left += (t-dst.Left); | |
97 | - dst.Left = t; // dst.Left += (t-dst.Left) | |
98 | - | |
99 | - t = Math.Max( dst.Top, clip.Top ); | |
100 | - src.Bottom -= (t-dst.Top); // different than the clip method | |
101 | - dst.Top = t; | |
102 | - | |
103 | - t = Math.Min( dst.Right, clip.Right ); | |
104 | - src.Right += (t-dst.Right); | |
105 | - dst.Right = t; | |
106 | - | |
107 | - t = Math.Min( dst.Bottom, clip.Bottom ); | |
108 | - src.Top -= (t-dst.Bottom); // different than the clip method | |
109 | - dst.Bottom = t; | |
110 | - } | |
111 | - | |
112 | - internal static void PrepareDesc(ref DrawingDesc desc, DD7Surface dstSurf, ref DDSURFACEDESC2 dstSD, ref RECT dstRegion, | |
113 | - DD7Surface srcSurf, ref DDSURFACEDESC2 srcSD, ref RECT srcRegion, Scaler scale ) { | |
114 | - | |
115 | - double zoomCount = scale.Scale(1.0); | |
116 | - int skip; | |
117 | - if( zoomCount > 0 ) { | |
118 | - skip = 0; | |
119 | - desc.Stretch = (int)zoomCount-1; | |
120 | - desc.ColumnSteps = srcRegion.Right-srcRegion.Left; | |
121 | - desc.RowSteps = srcRegion.Bottom-srcRegion.Top; | |
122 | - //dstRegion.Width *= 1+zoomCount; | |
123 | - //dstRegion.Height *= 1+zoomCount; | |
124 | - } | |
125 | - else { | |
126 | - desc.Stretch = 0; | |
127 | - skip = 1-(int)(1.0/zoomCount); | |
128 | - //dstRegion.Width /= 1-zoomCount; | |
129 | - //dstRegion.Height /= 1-zoomCount; | |
130 | - desc.ColumnSteps = dstRegion.Right-dstRegion.Left; | |
131 | - desc.RowSteps = dstRegion.Bottom-dstRegion.Top; | |
132 | - } | |
133 | - PreparePixelBuffer(ref desc.Dest, dstSurf, dstSD, ref dstRegion, 0 ); | |
134 | - PreparePixelBuffer(ref desc.Src, srcSurf, srcSD, ref srcRegion, skip ); | |
135 | - } | |
136 | - | |
137 | - internal static void PreparePixelBuffer(ref PixelBuffer pb, DD7Surface surface, DDSURFACEDESC2 ddsd, ref RECT region, int skip ) { | |
138 | - if(surface.ColorKey == Color.Empty) | |
139 | - pb.ColorKey = OPAQUE_KEY; | |
140 | - else | |
141 | - pb.ColorKey = (int)surface.colorKeyValue; | |
142 | - pb.Mode = surface.PixelColorMode; | |
143 | - pb.RowPitch = ddsd.lPitch; | |
144 | - pb.PixelPitch = (ddsd.ddpfPixelFormat.lRGBBitCount+1)>>3; | |
145 | - pb.PixelMask = ddsd.ddpfPixelFormat.lRBitMask|ddsd.ddpfPixelFormat.lGBitMask|ddsd.ddpfPixelFormat.lBBitMask; | |
146 | - pb.lpOffset = ddsd.lpSurface + region.Left*pb.PixelPitch + region.Top*pb.RowPitch; | |
147 | - if(skip>0) { | |
148 | - pb.PixelPitch *= (1+skip); | |
149 | - pb.RowPitch *= (1+skip); | |
150 | - } | |
151 | - //pb.LowPadding = ?; | |
152 | - } | |
153 | - } | |
154 | -} |
@@ -1,138 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Collections; | |
3 | -using System.ComponentModel; | |
4 | -using System.Drawing; | |
5 | -using System.Data; | |
6 | -using System.Diagnostics; | |
7 | -using System.Windows.Forms; | |
8 | -using DxVBLib; | |
9 | -using nft.framework.drawing; | |
10 | - | |
11 | -namespace nft.drawing.ddraw7 | |
12 | -{ | |
13 | - /// <summary> | |
14 | - /// DD7Control の概要の説明です。 | |
15 | - /// </summary> | |
16 | - public class DD7Control : DrawableControl | |
17 | - { | |
18 | - /// <summary> | |
19 | - /// 必要なデザイナ変数です。 | |
20 | - /// </summary> | |
21 | - private System.ComponentModel.Container components = null; | |
22 | - private WindowedDDraw7 winDDraw7; | |
23 | - | |
24 | - public DD7Control() | |
25 | - { | |
26 | - // この呼び出しは、Windows.Forms フォーム デザイナで必要です。 | |
27 | - InitializeComponent(); | |
28 | - | |
29 | - } | |
30 | - | |
31 | - protected override void OnLoad(EventArgs e) { | |
32 | - base.OnLoad (e); | |
33 | - winDDraw7 = new WindowedDDraw7(this); | |
34 | - } | |
35 | - | |
36 | - public override ISurfaceOld Surface { get { return winDDraw7.PrimarySurface; } } | |
37 | - | |
38 | - /// <summary> | |
39 | - /// 使用されているリソースに後処理を実行します。 | |
40 | - /// </summary> | |
41 | - protected override void Dispose( bool disposing ) | |
42 | - { | |
43 | - if(winDDraw7!=null) | |
44 | - winDDraw7.Dispose(); | |
45 | - if( disposing ) | |
46 | - { | |
47 | - if(components != null) | |
48 | - { | |
49 | - components.Dispose(); | |
50 | - } | |
51 | - } | |
52 | - base.Dispose( disposing ); | |
53 | - } | |
54 | - | |
55 | - #region コンポーネント デザイナで生成されたコード | |
56 | - /// <summary> | |
57 | - /// デザイナ サポートに必要なメソッドです。このメソッドの内容を | |
58 | - /// コード エディタで変更しないでください。 | |
59 | - /// </summary> | |
60 | - private void InitializeComponent() | |
61 | - { | |
62 | - components = new System.ComponentModel.Container(); | |
63 | - } | |
64 | - #endregion | |
65 | - } | |
66 | - | |
67 | - /// <summary> | |
68 | - /// DirectDraw with the primary surface to the window of | |
69 | - /// the specified control. | |
70 | - /// </summary> | |
71 | - /// <remarks>this class is originaly implemented by K.Kawaguchi</remarks> | |
72 | - class WindowedDDraw7 : DDraw7 { | |
73 | - private PrimarySurface primary; | |
74 | - public DD7Surface PrimarySurface { get { return primary; } } | |
75 | - | |
76 | - public WindowedDDraw7( Control control ) { | |
77 | - DDSURFACEDESC2 sd= new DDSURFACEDESC2(); | |
78 | - sd.lFlags = CONST_DDSURFACEDESCFLAGS.DDSD_CAPS; | |
79 | - sd.ddsCaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_PRIMARYSURFACE; | |
80 | - primary = new PrimarySurface(handle.CreateSurface(ref sd), control); | |
81 | - // attach window clipper | |
82 | - DirectDrawClipper cp = handle.CreateClipper(0); | |
83 | - cp.SetHWnd( control.Handle.ToInt32() ); | |
84 | - primary.NativeSurface.SetClipper(cp); | |
85 | - } | |
86 | - | |
87 | - public override void Dispose() { | |
88 | - primary.Dispose(); | |
89 | - primary=null; | |
90 | - } | |
91 | - | |
92 | - private void control_BoundsChanged(object sender, EventArgs e) { | |
93 | - Control c = sender as Control; | |
94 | - Point p = c.PointToScreen(new Point(0)); | |
95 | - primary.ClipRect = new Rectangle(p,c.Size); | |
96 | - } | |
97 | - | |
98 | - } | |
99 | - class PrimarySurface : DD7Surface { | |
100 | - private Control control; | |
101 | - | |
102 | - public PrimarySurface(DirectDrawSurface7 surface, Control c) : base(surface){ | |
103 | - this.control = c; | |
104 | - } | |
105 | - | |
106 | - protected Rectangle controlBorder(){ | |
107 | - Point p = control.PointToScreen(new Point(0)); | |
108 | - Debug.WriteLine(new Rectangle(p,control.Size)); | |
109 | - return new Rectangle(p,control.Size); | |
110 | - } | |
111 | - | |
112 | - public override RECT ClipRECT { | |
113 | - get { | |
114 | - return Util.toRECT(controlBorder()); | |
115 | - } | |
116 | - set { | |
117 | - // invalid operation | |
118 | - base.ClipRECT = value; | |
119 | - } | |
120 | - } | |
121 | - | |
122 | - public override Rectangle ClipRect { | |
123 | - get { | |
124 | - return controlBorder(); | |
125 | - } | |
126 | - set { | |
127 | - // invalid operation | |
128 | - base.ClipRect = value; | |
129 | - } | |
130 | - } | |
131 | - | |
132 | - public override void Dispose() { | |
133 | - base.Dispose (); | |
134 | - control = null; | |
135 | - } | |
136 | - | |
137 | - } | |
138 | -} |
@@ -1,912 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Runtime.InteropServices; | |
3 | -using System.Drawing; | |
4 | -using System.Drawing.Imaging; | |
5 | -using System.Diagnostics; | |
6 | -using DxVBLib; | |
7 | -using nft.framework.drawing; | |
8 | - | |
9 | -namespace nft.drawing.ddraw7 | |
10 | -{ | |
11 | - | |
12 | - #region Intersecter | |
13 | - class IntersectDrawer : ISurfaceDrawer{ | |
14 | - public void Blt(ref DrawingDesc desc ){ | |
15 | - /* | |
16 | - int mask; | |
17 | - switch(desc.Dest.Mode){ | |
18 | - case PixelColorMode.RGB16Bit565: | |
19 | - mask = 0xf7de; | |
20 | - break; | |
21 | - case PixelColorMode.RGB16Bit555: | |
22 | - mask = 0x7bde; | |
23 | - break; | |
24 | - default: | |
25 | - mask = 0xfefefe; | |
26 | - break; | |
27 | - } | |
28 | - */ | |
29 | - if(desc.Stretch>0) | |
30 | - BltIntersectStretch(ref desc); | |
31 | - else | |
32 | - BltIntersect(ref desc); | |
33 | - } | |
34 | - | |
35 | - private static unsafe void BltIntersect(ref DrawingDesc desc){ | |
36 | - Int32 colKey = desc.Src.ColorKey; | |
37 | - Int32 colKey2 = desc.Dest.ColorKey; | |
38 | - Int32 pixMask = desc.Src.PixelMask; | |
39 | - Int32 pixNegMask = ~pixMask; | |
40 | - int lpSrc = desc.Src.lpOffset; | |
41 | - int lpDst = desc.Dest.lpOffset; | |
42 | - int y = 0; | |
43 | - while(++y<= desc.RowSteps) { | |
44 | - // | |
45 | - // Alpha-blend the pixels in the current row. | |
46 | - // | |
47 | - int x = 0; | |
48 | - int lpSrc2 = lpSrc; | |
49 | - int lpDst2 = lpDst; | |
50 | - while ( ++x<= desc.ColumnSteps ) { | |
51 | - // Read in the next source pixel. | |
52 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
53 | - vSrc &= pixMask; | |
54 | - // If the source pixel is not black ... | |
55 | - if ( vSrc != colKey ) { | |
56 | - // ... read in the next target pixel. | |
57 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
58 | - if( ( vDst & pixMask ) != colKey2 ){ | |
59 | - // Write the destination pixel. | |
60 | - *(( Int32* )lpDst2) = (vDst&pixNegMask)|vSrc; | |
61 | - } | |
62 | - } | |
63 | - // Proceed to the next pixel. | |
64 | - lpDst2 += desc.Dest.PixelPitch; | |
65 | - lpSrc2 += desc.Src.PixelPitch; | |
66 | - } | |
67 | - // Proceed to the next line. | |
68 | - lpDst += desc.Dest.RowPitch; | |
69 | - lpSrc += desc.Src.RowPitch; | |
70 | - }; | |
71 | - } | |
72 | - | |
73 | - private static readonly int[] patternArray = { | |
74 | - (1<<1)+(1<<3),//1 | |
75 | - (1<<2)+(1<<5)+(1<<8),//2 | |
76 | - (1<<3)+(1<<7)+(1<<11)+(1<<15),//3 | |
77 | - (1<<4)+(1<<9)+(1<<14)+(1<<19)+(1<<24)//4 | |
78 | - }; | |
79 | - private static unsafe void BltIntersectStretch(ref DrawingDesc desc){ | |
80 | - Int32 colKey = desc.Src.ColorKey; | |
81 | - Int32 colKey2 = desc.Dest.ColorKey; | |
82 | - Int32 pixMask = desc.Src.PixelMask; | |
83 | - Int32 pixNegMask = ~pixMask; | |
84 | - int n = Math.Min(desc.Stretch,4); | |
85 | - int pattern = patternArray[n-1]; | |
86 | - n++; | |
87 | - int dstColPitch = desc.Dest.PixelPitch*n; | |
88 | - int dstRowPitch = desc.Dest.RowPitch*n; | |
89 | - int dstPadding = desc.Dest.RowPitch-dstColPitch; | |
90 | - n*=n; | |
91 | - int lpSrc = desc.Src.lpOffset; | |
92 | - int lpDst = desc.Dest.lpOffset; | |
93 | - int y = 0; | |
94 | - while(++y<= desc.RowSteps) { | |
95 | - // | |
96 | - // Alpha-blend the pixels in the current row. | |
97 | - // | |
98 | - int x = 0; | |
99 | - int lpSrc2 = lpSrc; | |
100 | - int lpDst2 = lpDst; | |
101 | - while ( ++x<= desc.ColumnSteps ) { | |
102 | - // Read in the next source pixel. | |
103 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
104 | - vSrc &= pixMask; | |
105 | - // If the source pixel is not black ... | |
106 | - if ( vSrc != colKey ) { | |
107 | - int lpDst3 = lpDst2; | |
108 | - int c = n; | |
109 | - int p = pattern; | |
110 | - while(c-->0){ | |
111 | - // ... read in the next target pixel. | |
112 | - Int32 vDst = *(( Int32*)lpDst3 ); | |
113 | - if(( vDst & pixMask ) != colKey2 ) { | |
114 | - // Write the destination pixel. | |
115 | - *(( Int32* )lpDst3) = (vDst&pixNegMask)|vSrc; | |
116 | - } | |
117 | - lpDst3+=desc.Dest.PixelPitch; | |
118 | - lpDst3+=dstPadding*(p&1); | |
119 | - p>>=1; | |
120 | - } | |
121 | - } | |
122 | - // Proceed to the next pixel. | |
123 | - lpDst2 += dstColPitch; | |
124 | - lpSrc2 += desc.Src.PixelPitch; | |
125 | - } | |
126 | - // Proceed to the next line. | |
127 | - lpDst += dstRowPitch; | |
128 | - lpSrc += desc.Src.RowPitch; | |
129 | - }; } | |
130 | - } | |
131 | - | |
132 | - #endregion | |
133 | - | |
134 | - #region HalfAlpha | |
135 | - class HalfAlphaDrawer : ISurfaceDrawer{ | |
136 | - public void Blt(ref DrawingDesc desc ){ | |
137 | - int mask; | |
138 | - switch(desc.Dest.Mode){ | |
139 | - case PixelColorMode.RGB16Bit565: | |
140 | - mask = 0xf7de; | |
141 | - break; | |
142 | - case PixelColorMode.RGB16Bit555: | |
143 | - mask = 0x7bde; | |
144 | - break; | |
145 | - default: | |
146 | - mask = 0xfefefe; | |
147 | - break; | |
148 | - } | |
149 | - if(desc.Stretch>0) | |
150 | - BltStretch(ref desc, mask); | |
151 | - else | |
152 | - Blt(ref desc, mask); | |
153 | - } | |
154 | - | |
155 | - private static unsafe void Blt(ref DrawingDesc desc, int mask){ | |
156 | - Int32 colKey = desc.Src.ColorKey; | |
157 | - Int32 pixMask = desc.Src.PixelMask; | |
158 | - Int32 pixNegMask = ~pixMask; | |
159 | - int lpSrc = desc.Src.lpOffset; | |
160 | - int lpDst = desc.Dest.lpOffset; | |
161 | - int y = 0; | |
162 | - while(++y<= desc.RowSteps) { | |
163 | - // | |
164 | - // Alpha-blend the pixels in the current row. | |
165 | - // | |
166 | - int x = 0; | |
167 | - int lpSrc2 = lpSrc; | |
168 | - int lpDst2 = lpDst; | |
169 | - while ( ++x<= desc.ColumnSteps ) { | |
170 | - // Read in the next source pixel. | |
171 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
172 | - // If the source pixel is not black ... | |
173 | - if ( ( vSrc & pixMask ) != colKey ) { | |
174 | - // ... read in the next target pixel. | |
175 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
176 | - | |
177 | - // Calculate the destination pixel. | |
178 | - vSrc = ( ( vDst & mask ) + ( vSrc & mask ))>> 1; | |
179 | - // Write the destination pixel. | |
180 | - *(( Int32* )lpDst2) = (vDst&pixNegMask)|vSrc; | |
181 | - } | |
182 | - // Proceed to the next pixel. | |
183 | - lpDst2 += desc.Dest.PixelPitch; | |
184 | - lpSrc2 += desc.Src.PixelPitch; | |
185 | - } | |
186 | - // Proceed to the next line. | |
187 | - lpDst += desc.Dest.RowPitch; | |
188 | - lpSrc += desc.Src.RowPitch; | |
189 | - }; | |
190 | - } | |
191 | - | |
192 | - private static readonly int[] patternArray = { | |
193 | - (1<<1)+(1<<3),//1 | |
194 | - (1<<2)+(1<<5)+(1<<8),//2 | |
195 | - (1<<3)+(1<<7)+(1<<11)+(1<<15),//3 | |
196 | - (1<<4)+(1<<9)+(1<<14)+(1<<19)+(1<<24)//4 | |
197 | - }; | |
198 | - private static unsafe void BltStretch(ref DrawingDesc desc, int mask){ | |
199 | - Int32 colKey = desc.Src.ColorKey; | |
200 | - Int32 pixMask = desc.Src.PixelMask; | |
201 | - Int32 pixNegMask = ~pixMask; | |
202 | - int n = Math.Min(desc.Stretch,4); | |
203 | - int pattern = patternArray[n-1]; | |
204 | - n++; | |
205 | - int dstColPitch = desc.Dest.PixelPitch*n; | |
206 | - int dstRowPitch = desc.Dest.RowPitch*n; | |
207 | - int dstPadding = desc.Dest.RowPitch-dstColPitch; | |
208 | - n*=n; | |
209 | - int lpSrc = desc.Src.lpOffset; | |
210 | - int lpDst = desc.Dest.lpOffset; | |
211 | - int y = 0; | |
212 | - while(++y<= desc.RowSteps) { | |
213 | - // | |
214 | - // Alpha-blend the pixels in the current row. | |
215 | - // | |
216 | - int x = 0; | |
217 | - int lpSrc2 = lpSrc; | |
218 | - int lpDst2 = lpDst; | |
219 | - while ( ++x<= desc.ColumnSteps ) { | |
220 | - // Read in the next source pixel. | |
221 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
222 | - // If the source pixel is not black ... | |
223 | - if ( ( vSrc & pixMask ) != colKey ) { | |
224 | - int lpDst3 = lpDst2; | |
225 | - int c = n; | |
226 | - int p = pattern; | |
227 | - vSrc &= mask; | |
228 | - while(c-->0){ | |
229 | - // ... read in the next target pixel. | |
230 | - Int32 vDst = *(( Int32*)lpDst3 ); | |
231 | - // Calculate the destination pixel. | |
232 | - Int32 vTmp = ( ( vDst & mask ) + vSrc)>> 1; | |
233 | - // Write the destination pixel. | |
234 | - *(( Int32* )lpDst3) = (vDst&pixNegMask)|vTmp; | |
235 | - lpDst3+=desc.Dest.PixelPitch; | |
236 | - lpDst3+=dstPadding*(p&1); | |
237 | - p>>=1; | |
238 | - } | |
239 | - } | |
240 | - // Proceed to the next pixel. | |
241 | - lpDst2 += dstColPitch; | |
242 | - lpSrc2 += desc.Src.PixelPitch; | |
243 | - } | |
244 | - // Proceed to the next line. | |
245 | - lpDst += dstRowPitch; | |
246 | - lpSrc += desc.Src.RowPitch; | |
247 | - }; } | |
248 | - } | |
249 | - | |
250 | - #endregion | |
251 | - | |
252 | - #region SelectBrighter | |
253 | - class SelectBrighterDrawer : ISurfaceDrawer{ | |
254 | - public void Blt(ref DrawingDesc desc ){ | |
255 | - int mask; | |
256 | - int depth; | |
257 | - switch(desc.Dest.Mode){ | |
258 | - case PixelColorMode.RGB16Bit565: | |
259 | - mask = 0xf7de; | |
260 | - depth = 5; | |
261 | - break; | |
262 | - case PixelColorMode.RGB16Bit555: | |
263 | - mask = 0x7bde; | |
264 | - depth = 5; | |
265 | - break; | |
266 | - default: | |
267 | - mask = 0xfefefe; | |
268 | - depth = 8; | |
269 | - break; | |
270 | - } | |
271 | - if(desc.Stretch>0) | |
272 | - BltStretch(ref desc, mask, depth); | |
273 | - else | |
274 | - Blt(ref desc, mask,depth); | |
275 | - } | |
276 | - | |
277 | - private static unsafe void Blt(ref DrawingDesc desc, int mask, int depth){ | |
278 | - Int32 channelMask = (1<<depth)-1; | |
279 | - Int32 colKey = desc.Src.ColorKey; | |
280 | - Int32 pixMask = desc.Src.PixelMask; | |
281 | - Int32 pixNegMask = ~pixMask; | |
282 | - Int32 flg = (~mask)&(pixMask<<1); | |
283 | - int lpSrc = desc.Src.lpOffset; | |
284 | - int lpDst = desc.Dest.lpOffset; | |
285 | - int y = 0; | |
286 | - while(++y<= desc.RowSteps) { | |
287 | - // | |
288 | - // Alpha-blend the pixels in the current row. | |
289 | - // | |
290 | - int x = 0; | |
291 | - int lpSrc2 = lpSrc; | |
292 | - int lpDst2 = lpDst; | |
293 | - while ( ++x<= desc.ColumnSteps ) { | |
294 | - // Read in the next source pixel. | |
295 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
296 | - // If the source pixel is not black ... | |
297 | - if ( ( vSrc & pixMask ) != colKey ) { | |
298 | - vSrc &= mask; | |
299 | - // ... read in the next target pixel. | |
300 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
301 | - Int32 vDst2 = vDst&mask; | |
302 | - // Calculate the destination pixel. | |
303 | - Int32 work = vDst2|flg; | |
304 | - work -= vSrc; | |
305 | - work &= flg; | |
306 | - work *= channelMask; | |
307 | - work >>= depth; | |
308 | - | |
309 | - vSrc = (vDst2&work) + (vSrc&~work); | |
310 | - // Write the destination pixel. | |
311 | - *(( Int32* )lpDst2) = (vDst&pixNegMask)|vSrc; | |
312 | - } | |
313 | - // Proceed to the next pixel. | |
314 | - lpDst2 += desc.Dest.PixelPitch; | |
315 | - lpSrc2 += desc.Src.PixelPitch; | |
316 | - } | |
317 | - // Proceed to the next line. | |
318 | - lpDst += desc.Dest.RowPitch; | |
319 | - lpSrc += desc.Src.RowPitch; | |
320 | - }; | |
321 | - } | |
322 | - | |
323 | - private static readonly int[] patternArray = { | |
324 | - (1<<1)+(1<<3),//1 | |
325 | - (1<<2)+(1<<5)+(1<<8),//2 | |
326 | - (1<<3)+(1<<7)+(1<<11)+(1<<15),//3 | |
327 | - (1<<4)+(1<<9)+(1<<14)+(1<<19)+(1<<24)//4 | |
328 | - }; | |
329 | - private static unsafe void BltStretch(ref DrawingDesc desc, int mask, int depth){ | |
330 | - Int32 channelMask = (1<<depth)-1; | |
331 | - Int32 colKey = desc.Src.ColorKey; | |
332 | - Int32 pixMask = desc.Src.PixelMask; | |
333 | - Int32 pixNegMask = ~pixMask; | |
334 | - Int32 flg = (~mask)&(pixMask<<1); | |
335 | - int n = Math.Min(desc.Stretch,4); | |
336 | - int pattern = patternArray[n-1]; | |
337 | - n++; | |
338 | - int dstColPitch = desc.Dest.PixelPitch*n; | |
339 | - int dstRowPitch = desc.Dest.RowPitch*n; | |
340 | - int dstPadding = desc.Dest.RowPitch-dstColPitch; | |
341 | - n*=n; | |
342 | - int lpSrc = desc.Src.lpOffset; | |
343 | - int lpDst = desc.Dest.lpOffset; | |
344 | - int y = 0; | |
345 | - while(++y<= desc.RowSteps) { | |
346 | - // | |
347 | - // Alpha-blend the pixels in the current row. | |
348 | - // | |
349 | - int x = 0; | |
350 | - int lpSrc2 = lpSrc; | |
351 | - int lpDst2 = lpDst; | |
352 | - while ( ++x<= desc.ColumnSteps ) { | |
353 | - // Read in the next source pixel. | |
354 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
355 | - // If the source pixel is not black ... | |
356 | - if ( ( vSrc & pixMask ) != colKey ) { | |
357 | - int lpDst3 = lpDst2; | |
358 | - int c = n; | |
359 | - int p = pattern; | |
360 | - vSrc &= mask; | |
361 | - while(c-->0){ | |
362 | - // ... read in the next target pixel. | |
363 | - Int32 vDst = *(( Int32*)lpDst3 ); | |
364 | - Int32 vDst2 = vDst&mask; | |
365 | - // Calculate the destination pixel. | |
366 | - Int32 work = vDst2|flg; | |
367 | - work -= vSrc; | |
368 | - work &= flg; | |
369 | - work *= channelMask; | |
370 | - work >>= depth; | |
371 | - | |
372 | - work = (vDst2&work) + (vSrc&~work); | |
373 | - // Write the destination pixel. | |
374 | - *(( Int32* )lpDst3) = (vDst&pixNegMask)|work; | |
375 | - lpDst3+=desc.Dest.PixelPitch; | |
376 | - lpDst3+=dstPadding*(p&1); | |
377 | - p>>=1; | |
378 | - } | |
379 | - } | |
380 | - // Proceed to the next pixel. | |
381 | - lpDst2 += dstColPitch; | |
382 | - lpSrc2 += desc.Src.PixelPitch; | |
383 | - } | |
384 | - // Proceed to the next line. | |
385 | - lpDst += dstRowPitch; | |
386 | - lpSrc += desc.Src.RowPitch; | |
387 | - }; } | |
388 | - } | |
389 | - | |
390 | - #endregion | |
391 | - | |
392 | - #region ColorBurn | |
393 | - class ColorBurnDrawer : ISurfaceDrawer{ | |
394 | - protected float apply; | |
395 | - protected Color color; | |
396 | - protected PixelColorMode prev = PixelColorMode.Unknown; | |
397 | - protected Int32[] masks = new Int32[4]; | |
398 | - | |
399 | - public ColorBurnDrawer(Color col, float apply){ | |
400 | - this.apply = apply; | |
401 | - this.color = col; | |
402 | - } | |
403 | - | |
404 | - public ColorBurnDrawer() : this(Color.Black,0.5f){ | |
405 | - } | |
406 | - | |
407 | - public float Apply { | |
408 | - get{ return apply; } | |
409 | - set{ apply = value; prev = PixelColorMode.Unknown; } | |
410 | - } | |
411 | - | |
412 | - public Color BurnColor { | |
413 | - get{ return color; } | |
414 | - set{ color = value; prev = PixelColorMode.Unknown; } | |
415 | - } | |
416 | - | |
417 | - public void Blt(ref DrawingDesc desc ){ | |
418 | - if(prev != desc.Dest.Mode){ | |
419 | - prev = desc.Dest.Mode; | |
420 | - int v = (int)(255*apply)&255; | |
421 | - int R = (int)(color.R*apply); | |
422 | - int G = (int)(color.G*apply); | |
423 | - int B = (int)(color.B*apply); | |
424 | - switch(desc.Dest.Mode){ | |
425 | - case PixelColorMode.RGB16Bit565: | |
426 | - masks[0] = 0xf7de; | |
427 | - masks[1] = (v&0xf8)<<3; | |
428 | - v = (v&0xf0)>>3; | |
429 | - masks[1] |= (v<<11) + v; | |
430 | - masks[2] = (G&0xfc)<<3; | |
431 | - masks[2] |=(R&0xf8)<<8; | |
432 | - masks[2] |=(B>>3); | |
433 | - masks[3] = 5; | |
434 | - break; | |
435 | - case PixelColorMode.RGB16Bit555: | |
436 | - masks[0] = 0x7bde; | |
437 | - v = (v&0xf0)>>3; | |
438 | - masks[1] = v + (v<<5)+ (v<<10); | |
439 | - masks[2] = (R&0xf8)<<8; | |
440 | - masks[2] |= (G&0xf8)<<2; | |
441 | - masks[2] |= (B>>3); | |
442 | - masks[3] = 5; | |
443 | - break; | |
444 | - default: | |
445 | - masks[0] = 0xfefefe; | |
446 | - masks[1] = v + (v<<8) + (v<<16); | |
447 | - masks[1] &= masks[0]; | |
448 | - masks[2] = (R<<16)|(G<<8)|B; | |
449 | - masks[3] = 8; | |
450 | - break; | |
451 | - } | |
452 | - } | |
453 | - if(desc.Stretch>0) | |
454 | - BltStretch(ref desc , ref masks); | |
455 | - else | |
456 | - Blt(ref desc, ref masks); | |
457 | - } | |
458 | - | |
459 | - private static unsafe void Blt(ref DrawingDesc desc, ref Int32[] masks){ | |
460 | - Int32 channelMask = (1<<masks[3])-1; | |
461 | - Int32 colKey = desc.Src.ColorKey; | |
462 | - Int32 pixMask = desc.Src.PixelMask; | |
463 | - Int32 pixNegMask = ~pixMask; | |
464 | - Int32 flg = (~masks[0])&(pixMask<<1); | |
465 | - int lpSrc = desc.Src.lpOffset; | |
466 | - int lpDst = desc.Dest.lpOffset; | |
467 | - int y = 0; | |
468 | - while(++y<= desc.RowSteps) { | |
469 | - // | |
470 | - // Alpha-blend the pixels in the current row. | |
471 | - // | |
472 | - int x = 0; | |
473 | - int lpSrc2 = lpSrc; | |
474 | - int lpDst2 = lpDst; | |
475 | - while ( ++x<= desc.ColumnSteps ) { | |
476 | - // Read in the next source pixel. | |
477 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
478 | - // If the source pixel is not black ... | |
479 | - if ( ( vSrc & pixMask ) != colKey ) { | |
480 | - // ... read in the next target pixel. | |
481 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
482 | - | |
483 | - // Calculate the destination pixel. | |
484 | - vSrc &= masks[0]; | |
485 | - vSrc -= masks[1]; | |
486 | - Int32 work = vSrc&flg; | |
487 | - work *= channelMask; | |
488 | - work >>= masks[3]; | |
489 | - | |
490 | - vSrc &= ~work; | |
491 | - vSrc += masks[2]; | |
492 | - // Write the destination pixel. | |
493 | - *(( Int32* )lpDst2) = (vDst&pixNegMask)|(vSrc&pixMask); | |
494 | - } | |
495 | - // Proceed to the next pixel. | |
496 | - lpDst2 += desc.Dest.PixelPitch; | |
497 | - lpSrc2 += desc.Src.PixelPitch; | |
498 | - } | |
499 | - // Proceed to the next line. | |
500 | - lpDst += desc.Dest.RowPitch; | |
501 | - lpSrc += desc.Src.RowPitch; | |
502 | - }; | |
503 | - } | |
504 | - | |
505 | - private static readonly int[] patternArray = { | |
506 | - (1<<1)+(1<<3),//1 | |
507 | - (1<<2)+(1<<5)+(1<<8),//2 | |
508 | - (1<<3)+(1<<7)+(1<<11)+(1<<15),//3 | |
509 | - (1<<4)+(1<<9)+(1<<14)+(1<<19)+(1<<24)//4 | |
510 | - }; | |
511 | - private static unsafe void BltStretch(ref DrawingDesc desc, ref Int32[] masks){ | |
512 | - Int32 channelMask = (1<<masks[3])-1; | |
513 | - Int32 colKey = desc.Src.ColorKey; | |
514 | - Int32 pixMask = desc.Src.PixelMask; | |
515 | - Int32 pixNegMask = ~pixMask; | |
516 | - Int32 flg = (~masks[0])&(pixMask<<1); | |
517 | - int n = Math.Min(desc.Stretch,4); | |
518 | - int pattern = patternArray[n-1]; | |
519 | - n++; | |
520 | - int dstColPitch = desc.Dest.PixelPitch*n; | |
521 | - int dstRowPitch = desc.Dest.RowPitch*n; | |
522 | - int dstPadding = desc.Dest.RowPitch-dstColPitch; | |
523 | - n*=n; | |
524 | - int lpSrc = desc.Src.lpOffset; | |
525 | - int lpDst = desc.Dest.lpOffset; | |
526 | - int y = 0; | |
527 | - while(++y<= desc.RowSteps) { | |
528 | - // | |
529 | - // Alpha-blend the pixels in the current row. | |
530 | - // | |
531 | - int x = 0; | |
532 | - int lpSrc2 = lpSrc; | |
533 | - int lpDst2 = lpDst; | |
534 | - while ( ++x<= desc.ColumnSteps ) { | |
535 | - // Read in the next source pixel. | |
536 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
537 | - // If the source pixel is not black ... | |
538 | - if ( ( vSrc & pixMask ) != colKey ) { | |
539 | - int lpDst3 = lpDst2; | |
540 | - int c = n; | |
541 | - int p = pattern; | |
542 | - // Calculate the destination pixel. | |
543 | - vSrc &= masks[0]; | |
544 | - vSrc -= masks[1]; | |
545 | - Int32 work = vSrc&flg; | |
546 | - work *= channelMask; | |
547 | - work >>= masks[3]; | |
548 | - | |
549 | - vSrc &= ~work; | |
550 | - vSrc += masks[2]; | |
551 | - while(c-->0){ | |
552 | - // ... read in the next target pixel. | |
553 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
554 | - // Write the destination pixel. | |
555 | - *(( Int32* )lpDst3) = (vDst&pixNegMask)|(vSrc&pixMask); | |
556 | - lpDst3+=desc.Dest.PixelPitch; | |
557 | - lpDst3+=dstPadding*(p&1); | |
558 | - p>>=1; | |
559 | - } | |
560 | - } | |
561 | - // Proceed to the next pixel. | |
562 | - lpDst2 += dstColPitch; | |
563 | - lpSrc2 += desc.Src.PixelPitch; | |
564 | - } | |
565 | - // Proceed to the next line. | |
566 | - lpDst += dstRowPitch; | |
567 | - lpSrc += desc.Src.RowPitch; | |
568 | - }; } | |
569 | - } | |
570 | - | |
571 | - #endregion | |
572 | - | |
573 | - #region MonoColor | |
574 | - class MonoColorDrawer : ISurfaceDrawer{ | |
575 | - protected Color color; | |
576 | - protected PixelColorMode prev = PixelColorMode.Unknown; | |
577 | - protected Int32[] masks = new Int32[6]; | |
578 | - protected long workval; | |
579 | - protected long workmask; | |
580 | - | |
581 | - public MonoColorDrawer(Color col){ | |
582 | - this.color = col; | |
583 | - } | |
584 | - | |
585 | - public MonoColorDrawer() : this(Color.White){ | |
586 | - } | |
587 | - | |
588 | - public Color DrawColor { | |
589 | - get{ return color; } | |
590 | - set{ color = value; prev = PixelColorMode.Unknown; } | |
591 | - } | |
592 | - | |
593 | - public void Blt(ref DrawingDesc desc ){ | |
594 | - if(prev != desc.Dest.Mode){ | |
595 | - prev = desc.Dest.Mode; | |
596 | - | |
597 | - switch(desc.Dest.Mode){ | |
598 | - case PixelColorMode.RGB16Bit565: | |
599 | - masks[0] = 0xe7dc; | |
600 | - masks[1] = 11; | |
601 | - masks[2] = 6; | |
602 | - masks[3] = 0x1f; | |
603 | - masks[4] = 5; | |
604 | - workval = ((long)color.G<<20)+(color.R<<8)+(color.B>>3); | |
605 | - workmask = 0xf80f81f; | |
606 | - workval&=workmask; | |
607 | - break; | |
608 | - case PixelColorMode.RGB16Bit555: | |
609 | - masks[0] = 0x73dc; | |
610 | - masks[1] = 10; | |
611 | - masks[2] = 5; | |
612 | - masks[3] = 0x1f; | |
613 | - masks[4] = 5; | |
614 | - workval = ((long)color.G<<17)+(color.R<<7)+(color.B>>3); | |
615 | - workmask = 0x1f07c1f; | |
616 | - workval&=workmask; | |
617 | - break; | |
618 | - default: | |
619 | - masks[0] = 0xfcfefc; | |
620 | - masks[1] = 16; | |
621 | - masks[2] = 8; | |
622 | - masks[3] = 0xff; | |
623 | - masks[4] = 8; | |
624 | - workval = ((long)color.G<<32)+(color.R<<16)+(color.B); | |
625 | - workmask = 0xff00ff00ff; | |
626 | - break; | |
627 | - } | |
628 | - } | |
629 | - //Debug.WriteLine(" v: " + workval.ToString("X")); | |
630 | - if(desc.Stretch>0) | |
631 | - BltStretch(ref desc , ref masks, workval, workmask); | |
632 | - else | |
633 | - Blt(ref desc, ref masks, workval, workmask); | |
634 | - } | |
635 | - | |
636 | - private static unsafe void Blt(ref DrawingDesc desc, ref Int32[] masks, long val, long mask){ | |
637 | - Int32 colKey = desc.Src.ColorKey; | |
638 | - Int32 pixMask = desc.Src.PixelMask; | |
639 | - Int32 pixNegMask = ~pixMask; | |
640 | - int shift = (masks[1]<<1) - masks[4]; | |
641 | - int lpSrc = desc.Src.lpOffset; | |
642 | - int lpDst = desc.Dest.lpOffset; | |
643 | - int y = 0; | |
644 | - while(++y<= desc.RowSteps) { | |
645 | - // | |
646 | - // Alpha-blend the pixels in the current row. | |
647 | - // | |
648 | - int x = 0; | |
649 | - int lpSrc2 = lpSrc; | |
650 | - int lpDst2 = lpDst; | |
651 | - while ( ++x<= desc.ColumnSteps ) { | |
652 | - // Read in the next source pixel. | |
653 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
654 | - // If the source pixel is not black ... | |
655 | - if ( ( vSrc & pixMask ) != colKey ) { | |
656 | - // ... read in the next target pixel. | |
657 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
658 | - // Calculate the destination pixel. | |
659 | - vSrc &= masks[0]; | |
660 | - Int32 work = vSrc + (vSrc>>masks[1]); | |
661 | - work >>=1; | |
662 | - work &= masks[3]; | |
663 | - work += vSrc>>masks[2]; | |
664 | - work >>=1; | |
665 | - work &= masks[3]; | |
666 | - //vSrc = 0x010101 * work; | |
667 | - long v = val * work; | |
668 | - v >>= masks[4]; | |
669 | - v &= mask; | |
670 | - vSrc = (int)v + (int)(v>>shift); | |
671 | - vSrc &= pixMask; | |
672 | - // Write the destination pixel. | |
673 | - *(( Int32* )lpDst2) = (vDst&pixNegMask)|vSrc; | |
674 | - } | |
675 | - // Proceed to the next pixel. | |
676 | - lpDst2 += desc.Dest.PixelPitch; | |
677 | - lpSrc2 += desc.Src.PixelPitch; | |
678 | - } | |
679 | - // Proceed to the next line. | |
680 | - lpDst += desc.Dest.RowPitch; | |
681 | - lpSrc += desc.Src.RowPitch; | |
682 | - }; | |
683 | - } | |
684 | - | |
685 | - private static readonly int[] patternArray = { | |
686 | - (1<<1)+(1<<3),//1 | |
687 | - (1<<2)+(1<<5)+(1<<8),//2 | |
688 | - (1<<3)+(1<<7)+(1<<11)+(1<<15),//3 | |
689 | - (1<<4)+(1<<9)+(1<<14)+(1<<19)+(1<<24)//4 | |
690 | - }; | |
691 | - private static unsafe void BltStretch(ref DrawingDesc desc, ref Int32[] masks, long val, long mask){ | |
692 | - Int32 colKey = desc.Src.ColorKey; | |
693 | - Int32 pixMask = desc.Src.PixelMask; | |
694 | - Int32 pixNegMask = ~pixMask; | |
695 | - int shift = (masks[1]<<1)-masks[4]; | |
696 | - int n = Math.Min(desc.Stretch,4); | |
697 | - int pattern = patternArray[n-1]; | |
698 | - n++; | |
699 | - int dstColPitch = desc.Dest.PixelPitch*n; | |
700 | - int dstRowPitch = desc.Dest.RowPitch*n; | |
701 | - int dstPadding = desc.Dest.RowPitch-dstColPitch; | |
702 | - n*=n; | |
703 | - int lpSrc = desc.Src.lpOffset; | |
704 | - int lpDst = desc.Dest.lpOffset; | |
705 | - int y = 0; | |
706 | - while(++y<= desc.RowSteps) { | |
707 | - // | |
708 | - // Alpha-blend the pixels in the current row. | |
709 | - // | |
710 | - int x = 0; | |
711 | - int lpSrc2 = lpSrc; | |
712 | - int lpDst2 = lpDst; | |
713 | - while ( ++x<= desc.ColumnSteps ) { | |
714 | - // Read in the next source pixel. | |
715 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
716 | - // If the source pixel is not black ... | |
717 | - if ( ( vSrc & pixMask ) != colKey ) { | |
718 | - int lpDst3 = lpDst2; | |
719 | - int c = n; | |
720 | - int p = pattern; | |
721 | - // Calculate the destination pixel. | |
722 | - vSrc &= masks[0]; | |
723 | - Int32 work = vSrc + (vSrc>>masks[1]); | |
724 | - work >>=1; | |
725 | - work &= masks[3]; | |
726 | - work += vSrc>>masks[2]; | |
727 | - work >>=1; | |
728 | - work &= masks[3]; | |
729 | - //vSrc = 0x010101 * work; | |
730 | - long v = val * work; | |
731 | - v >>= masks[4]; | |
732 | - v &= mask; | |
733 | - vSrc = (int)v + (int)(v>>shift); | |
734 | - vSrc &= pixMask; | |
735 | - while(c-->0){ | |
736 | - // ... read in the next target pixel. | |
737 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
738 | - // Write the destination pixel. | |
739 | - *(( Int32* )lpDst3) = (vDst&pixNegMask)|vSrc; | |
740 | - lpDst3+=desc.Dest.PixelPitch; | |
741 | - lpDst3+=dstPadding*(p&1); | |
742 | - p>>=1; | |
743 | - } | |
744 | - } | |
745 | - // Proceed to the next pixel. | |
746 | - lpDst2 += dstColPitch; | |
747 | - lpSrc2 += desc.Src.PixelPitch; | |
748 | - } | |
749 | - // Proceed to the next line. | |
750 | - lpDst += dstRowPitch; | |
751 | - lpSrc += desc.Src.RowPitch; | |
752 | - }; } | |
753 | - } | |
754 | - | |
755 | - #endregion | |
756 | - | |
757 | - | |
758 | - #region PixelFilterWrapper | |
759 | - class PixelFilterDrawer : ISurfaceDrawer{ | |
760 | - protected IPixelFilter filter; | |
761 | - | |
762 | - public PixelFilterDrawer(IPixelFilter filter){ | |
763 | - this.filter = filter; | |
764 | - } | |
765 | - | |
766 | - public IPixelFilter PixelFilter { | |
767 | - get{ return filter; } | |
768 | - set{ filter = (value==null)?new NullFilter():filter; } | |
769 | - } | |
770 | - | |
771 | - public void Blt(ref DrawingDesc desc ){ | |
772 | - filter.Begin(desc.Dest.Mode,desc.Dest.ColorKey); | |
773 | - if(desc.Stretch>0) | |
774 | - BltStretch(ref desc , filter); | |
775 | - else | |
776 | - Blt(ref desc, filter); | |
777 | - filter.End(); | |
778 | - } | |
779 | - | |
780 | - private static unsafe void Blt(ref DrawingDesc desc, IPixelFilter filter){ | |
781 | - Int32 colKey = desc.Src.ColorKey; | |
782 | - Int32 pixMask = desc.Src.PixelMask; | |
783 | - Int32 pixNegMask = ~pixMask; | |
784 | - int lpSrc = desc.Src.lpOffset; | |
785 | - int lpDst = desc.Dest.lpOffset; | |
786 | - int y = 0; | |
787 | - while(++y<= desc.RowSteps) { | |
788 | - // | |
789 | - // Alpha-blend the pixels in the current row. | |
790 | - // | |
791 | - int x = 0; | |
792 | - int lpSrc2 = lpSrc; | |
793 | - int lpDst2 = lpDst; | |
794 | - while ( ++x<= desc.ColumnSteps ) { | |
795 | - // Read in the next source pixel. | |
796 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
797 | - // If the source pixel is not black ... | |
798 | - if ( ( vSrc & pixMask ) != colKey ) { | |
799 | - // ... read in the next target pixel. | |
800 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
801 | - | |
802 | - // Calculate the destination pixel. | |
803 | - vSrc = filter.Convert(vDst,vSrc); | |
804 | - // Write the destination pixel. | |
805 | - *(( Int32* )lpDst2) = (vDst&pixNegMask)|vSrc; | |
806 | - } | |
807 | - // Proceed to the next pixel. | |
808 | - lpDst2 += desc.Dest.PixelPitch; | |
809 | - lpSrc2 += desc.Src.PixelPitch; | |
810 | - } | |
811 | - // Proceed to the next line. | |
812 | - lpDst += desc.Dest.RowPitch; | |
813 | - lpSrc += desc.Src.RowPitch; | |
814 | - }; | |
815 | - } | |
816 | - | |
817 | - private static readonly int[] patternArray = { | |
818 | - (1<<1)+(1<<3),//1 | |
819 | - (1<<2)+(1<<5)+(1<<8),//2 | |
820 | - (1<<3)+(1<<7)+(1<<11)+(1<<15),//3 | |
821 | - (1<<4)+(1<<9)+(1<<14)+(1<<19)+(1<<24)//4 | |
822 | - }; | |
823 | - private static unsafe void BltStretch(ref DrawingDesc desc, IPixelFilter filter){ | |
824 | - Int32 colKey = desc.Src.ColorKey; | |
825 | - Int32 pixMask = desc.Src.PixelMask; | |
826 | - Int32 pixNegMask = ~pixMask; | |
827 | - int n = Math.Min(desc.Stretch,4); | |
828 | - int pattern = patternArray[n-1]; | |
829 | - n++; | |
830 | - int dstColPitch = desc.Dest.PixelPitch*n; | |
831 | - int dstRowPitch = desc.Dest.RowPitch*n; | |
832 | - int dstPadding = desc.Dest.RowPitch-dstColPitch; | |
833 | - n*=n; | |
834 | - int lpSrc = desc.Src.lpOffset; | |
835 | - int lpDst = desc.Dest.lpOffset; | |
836 | - int y = 0; | |
837 | - while(++y<= desc.RowSteps) { | |
838 | - // | |
839 | - // Alpha-blend the pixels in the current row. | |
840 | - // | |
841 | - int x = 0; | |
842 | - int lpSrc2 = lpSrc; | |
843 | - int lpDst2 = lpDst; | |
844 | - while ( ++x<= desc.ColumnSteps ) { | |
845 | - // Read in the next source pixel. | |
846 | - Int32 vSrc = *(( Int32*)lpSrc2 ); | |
847 | - // If the source pixel is not black ... | |
848 | - if ( ( vSrc & pixMask ) != colKey ) { | |
849 | - int lpDst3 = lpDst2; | |
850 | - int c = n; | |
851 | - int p = pattern; | |
852 | - // Calculate the destination pixel. | |
853 | - while(c-->0){ | |
854 | - // ... read in the next target pixel. | |
855 | - Int32 vDst = *(( Int32*)lpDst2 ); | |
856 | - // Write the destination pixel. | |
857 | - *(( Int32* )lpDst3) = (vDst&pixNegMask)|filter.Convert(vDst,vSrc); | |
858 | - lpDst3+=desc.Dest.PixelPitch; | |
859 | - lpDst3+=dstPadding*(p&1); | |
860 | - p>>=1; | |
861 | - } | |
862 | - } | |
863 | - // Proceed to the next pixel. | |
864 | - lpDst2 += dstColPitch; | |
865 | - lpSrc2 += desc.Src.PixelPitch; | |
866 | - } | |
867 | - // Proceed to the next line. | |
868 | - lpDst += dstRowPitch; | |
869 | - lpSrc += desc.Src.RowPitch; | |
870 | - }; | |
871 | - } | |
872 | - | |
873 | - class NullFilter : IPixelFilter { | |
874 | - public void Begin(PixelColorMode mode, Int32 colorKey){} | |
875 | - | |
876 | - public Int32 Convert(Int32 dest, Int32 source){ return source; } | |
877 | - | |
878 | - public void End(){} | |
879 | - } | |
880 | - } | |
881 | - | |
882 | - #endregion | |
883 | - | |
884 | - /* | |
885 | - class AlphaPixelFilter : IPixelFilter { | |
886 | - /// <summary> | |
887 | - /// フィルター作業開始直前に呼ばれる | |
888 | - /// </summary> | |
889 | - /// <param name="mode">カラーモード</param> | |
890 | - /// <param name="colorKey">透明色</param> | |
891 | - public void Begin(PixelColorMode mode, Int32 colorKey) { | |
892 | - } | |
893 | - | |
894 | - /// <summary> | |
895 | - /// 与えられたカラーを変換する | |
896 | - /// 16bitモードでは、一度に2pixel分のデータが与えられる | |
897 | - /// </summary> | |
898 | - /// <param name="source">変換前の色値</param> | |
899 | - /// <returns></returns> | |
900 | - public Int32 Convert(Int32 dest, Int32 source) { | |
901 | - return ( ( dest & 0xfefefe ) + ( source & 0xfefefe ))>> 1; | |
902 | - } | |
903 | - | |
904 | - /// <summary> | |
905 | - /// フィルター作業終了事に呼ばれる | |
906 | - /// </summary> | |
907 | - public void End() { | |
908 | - } | |
909 | - } | |
910 | - } | |
911 | - */ | |
912 | -} |
@@ -1,183 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.IO; | |
3 | -using System.Drawing; | |
4 | -using nft.framework.drawing; | |
5 | -using System.Diagnostics; | |
6 | - | |
7 | -namespace nft.drawing.ddraw7 | |
8 | -{ | |
9 | - /// <summary> | |
10 | - /// SimpleTexture の概要の説明です。 | |
11 | - /// </summary> | |
12 | - public class DD7StaticTexture : IStaticTexture | |
13 | - { | |
14 | - protected DD7Surface surface; | |
15 | - protected bool surfaceOwner; | |
16 | - protected IPixelFilter filter; | |
17 | - protected Rectangle srcRegion; | |
18 | - protected Point drawOffset; | |
19 | - protected ImageRef imgRef; | |
20 | - | |
21 | - public DD7StaticTexture(DD7Surface source, Rectangle region, Point offset, bool surfaceOwner) { | |
22 | - this.surface = source as DD7Surface; | |
23 | - this.srcRegion = new Rectangle(0, 0, source.Size.Width, source.Size.Height); | |
24 | - this.srcRegion.Intersect(region); | |
25 | - this.surfaceOwner = surfaceOwner; | |
26 | - this.drawOffset = offset; | |
27 | - } | |
28 | - | |
29 | - public DD7StaticTexture(ImageRef image, Rectangle region, Point offset) { | |
30 | - this.surface = null; // create on demand | |
31 | - this.imgRef = image; | |
32 | - this.srcRegion = region; | |
33 | - this.surfaceOwner = true; | |
34 | - this.drawOffset = offset; | |
35 | - } | |
36 | - | |
37 | - #region ITexture メンバ | |
38 | - | |
39 | - public Rectangle Boundary { get { return new Rectangle(drawOffset,srcRegion.Size); } } | |
40 | - | |
41 | - public bool HitTest(Point pos) { | |
42 | - if(Boundary.Contains(pos)) { | |
43 | - int x = pos.X-drawOffset.X; | |
44 | - int y = pos.Y-drawOffset.Y; | |
45 | - return Source.HitTest(x, y); | |
46 | - } | |
47 | - else | |
48 | - return false; | |
49 | - } | |
50 | - | |
51 | - #endregion | |
52 | - | |
53 | - protected DrawParams Adjust(DrawParams orig){ | |
54 | - DrawParams dp = orig.Clone(); | |
55 | - dp.Location.X += drawOffset.X; | |
56 | - dp.Location.Y += drawOffset.Y; | |
57 | - if (dp.SoruceClip.Equals(Rectangle.Empty)) { | |
58 | - dp.SoruceClip = srcRegion; | |
59 | - } else { | |
60 | - dp.SoruceClip.Intersect(srcRegion); | |
61 | - } | |
62 | - return dp; | |
63 | - } | |
64 | - | |
65 | - #region IDrawable メンバ | |
66 | - public void Draw(DrawParams drawparam) { | |
67 | - DrawParams dp = Adjust(drawparam); | |
68 | - if (filter != null) | |
69 | - dp.Destination.BitBlt(Source, dp, filter); | |
70 | - else | |
71 | - dp.Destination.BitBlt(Source, dp); | |
72 | - } | |
73 | - | |
74 | - public void DrawEx(DrawParams drawparam, IPixelFilter f) { | |
75 | - DrawParams dp = Adjust(drawparam); | |
76 | - if (filter != null) { | |
77 | - CompositFilter cf = new CompositFilter(filter, f); | |
78 | - dp.Destination.BitBlt(Source, dp, cf); | |
79 | - } else | |
80 | - dp.Destination.BitBlt(Source, dp, f); | |
81 | - } | |
82 | - | |
83 | - public void DrawEx(DrawParams drawparam, ISurfaceDrawer drawer) { | |
84 | - DrawParams dp = Adjust(drawparam); | |
85 | - dp.Destination.BitBlt(Source, dp, drawer); | |
86 | - } | |
87 | - /* | |
88 | - [Obsolete] | |
89 | - public void Draw(ISurface dest, System.Drawing.Point location, Scaler scale, int frame) { | |
90 | - Point pt = new Point(location.X+drawOffset.X,location.Y+drawOffset.Y); | |
91 | - if(filter!=null) | |
92 | - dest.BitBlt(pt, Source, srcRegion, scale, filter); | |
93 | - else | |
94 | - dest.BitBlt(pt, Source, srcRegion, scale); | |
95 | - } | |
96 | - [Obsolete] | |
97 | - public void DrawEx(ISurface dest, System.Drawing.Point location, Scaler scale, IPixelFilter f, int frame) { | |
98 | - Point pt = new Point(location.X+drawOffset.X,location.Y+drawOffset.Y); | |
99 | - if(filter!=null) { | |
100 | - CompositFilter cf = new CompositFilter(filter,f); | |
101 | - dest.BitBlt(pt, Source, srcRegion, scale, cf); | |
102 | - } | |
103 | - else | |
104 | - dest.BitBlt(pt, Source, srcRegion, scale, f); | |
105 | - } | |
106 | - [Obsolete] | |
107 | - public void DrawEx(ISurface dest, System.Drawing.Point location, Scaler scale, ISurfaceDrawer drawer, int frame) { | |
108 | - Point pt = new Point(location.X+drawOffset.X,location.Y+drawOffset.Y); | |
109 | - dest.BitBlt(pt, Source, srcRegion, scale, drawer); | |
110 | - } | |
111 | - */ | |
112 | - public IPixelFilter Filter { | |
113 | - get { return filter; } | |
114 | - set { filter = value; } | |
115 | - } | |
116 | - #endregion | |
117 | - | |
118 | - #region IDisposable メンバ | |
119 | - | |
120 | - public void Dispose() { | |
121 | - Dispose(true); | |
122 | - GC.SuppressFinalize(this); | |
123 | - } | |
124 | - | |
125 | - protected void Dispose(bool disposing) { | |
126 | - if (surface != null) { | |
127 | - if (disposing) { | |
128 | - if(surfaceOwner) | |
129 | - surface.Dispose(); | |
130 | - surface = null; | |
131 | - } | |
132 | - } | |
133 | - } | |
134 | - | |
135 | - ~DD7StaticTexture() { | |
136 | - Dispose(false); | |
137 | - } | |
138 | - #endregion | |
139 | - | |
140 | - #region ISimpleTexture メンバ | |
141 | - // Becare!! If the source surface is refered from other objects, | |
142 | - // ColorKey setting will affects all those objects. | |
143 | - public Color ColorKey { | |
144 | - get { return Source.ColorKey; } | |
145 | - set { Source.ColorKey = value; } | |
146 | - } | |
147 | - | |
148 | - public void PickColorKeyFromSource( int x, int y ){ | |
149 | - x += srcRegion.X; | |
150 | - y += srcRegion.Y; | |
151 | - if(srcRegion.Contains(x,y)){ | |
152 | - PixelColorMode mode = Source.PixelColorMode; | |
153 | - ColorKey = PixelFormatUtil.ToColor(surface.GetPixel(x,y), mode); | |
154 | - } | |
155 | - else | |
156 | - ColorKey = Color.Empty; | |
157 | - } | |
158 | - | |
159 | - public Point DrawOffset { get { return drawOffset; } } | |
160 | - | |
161 | - public Bitmap CreateBitamap() { | |
162 | - throw new NotImplementedException(); | |
163 | - } | |
164 | - #endregion | |
165 | - | |
166 | - //public Rectangle SourceRegion { get { return srcRegion; } } | |
167 | - | |
168 | - internal ISurfaceOld Source { | |
169 | - get { | |
170 | - if (surface == null || surface.IsSurfaceLost) { | |
171 | - if (imgRef != null) { | |
172 | - IGraphicManagerOld gm = DD7GraphicManager.TheInstance; | |
173 | - surface = (DD7Surface)gm.CreateSurfaceFromBitmap(imgRef.AddRef(),srcRegion); | |
174 | - imgRef.ReleaseRef(); | |
175 | - } else { | |
176 | - throw new IOException("DirectDraw surface is lost."); | |
177 | - } | |
178 | - } | |
179 | - return surface; | |
180 | - } | |
181 | - } | |
182 | - } | |
183 | -} |
@@ -1,120 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Diagnostics; | |
3 | -using System.Drawing; | |
4 | -using System.Xml; | |
5 | -using nft.framework.drawing; | |
6 | -//using DxVBLib; | |
7 | - | |
8 | -namespace nft.drawing.ddraw7 | |
9 | -{ | |
10 | - /// <summary> | |
11 | - /// Draw an image in the picture as-is. | |
12 | - /// </summary> | |
13 | - [Serializable] | |
14 | - public class DD7Sprite : ISprite { | |
15 | - protected ITextureOld texture; | |
16 | - //protected IPixelFilter filter; | |
17 | - protected Point location; | |
18 | - protected object tag; | |
19 | - | |
20 | - internal protected DD7Sprite(ITextureOld texture){ | |
21 | - this.texture = texture; | |
22 | - location = new Point(0,0); | |
23 | - tag = null; | |
24 | - } | |
25 | - | |
26 | - #region ISprite メンバ | |
27 | - | |
28 | - public bool HitTest(Point loc) { | |
29 | - Point pt = new Point(loc.X - location.X, loc.Y - location.Y); | |
30 | - return texture.HitTest(pt); | |
31 | - } | |
32 | - | |
33 | - public ITextureOld Texture { | |
34 | - get { return texture; } | |
35 | - set { | |
36 | - Debug.Assert(value!=null); | |
37 | - texture = value; | |
38 | - } | |
39 | - } | |
40 | - | |
41 | - public Point Location { | |
42 | - get { return location; } | |
43 | - set { location = value; } | |
44 | - } | |
45 | - | |
46 | - | |
47 | - public object Tag { | |
48 | - get { return tag; } | |
49 | - set { tag = value; } | |
50 | - } | |
51 | - | |
52 | - /* | |
53 | - public IPixelFilter Filter { | |
54 | - get { return filter; } | |
55 | - set { filter = value; } | |
56 | - } | |
57 | - */ | |
58 | - | |
59 | - #endregion | |
60 | - | |
61 | - protected DrawParams Adjust(DrawParams orig) { | |
62 | - DrawParams dp = orig.Clone(); | |
63 | - dp.Location.X += location.X; | |
64 | - dp.Location.Y += location.Y; | |
65 | - return dp; | |
66 | - } | |
67 | - | |
68 | - #region IDrawable メンバ | |
69 | - public void Draw(DrawParams drawparam) { | |
70 | - DrawParams dp = Adjust(drawparam); | |
71 | - /* | |
72 | - if(filter!=null) | |
73 | - texture.DrawEx(dest, pt, scale, filter, frame); | |
74 | - else | |
75 | - */ | |
76 | - texture.Draw(dp); | |
77 | - } | |
78 | - | |
79 | - public void DrawEx(DrawParams drawparam, ISurfaceDrawer drawer) { | |
80 | - DrawParams dp = Adjust(drawparam); | |
81 | - texture.DrawEx(dp, drawer); | |
82 | - } | |
83 | - | |
84 | - public void DrawEx(DrawParams drawparam, IPixelFilter f) { | |
85 | - DrawParams dp = Adjust(drawparam); | |
86 | - texture.DrawEx(dp, f); | |
87 | - } | |
88 | - /* | |
89 | - [Obsolete] | |
90 | - public void Draw(ISurface dest, Point pos, Scaler scale, int frame) { | |
91 | - Point pt = new Point(pos.X + location.X, pos.Y + location.Y); | |
92 | - texture.Draw(dest, pt, scale, frame); | |
93 | - } | |
94 | - | |
95 | - [Obsolete] | |
96 | - public void DrawEx(ISurface dest, Point pos, Scaler scale, ISurfaceDrawer drawer, int frame) { | |
97 | - Point pt = new Point(pos.X+location.X,pos.Y+location.Y); | |
98 | - texture.DrawEx(dest, pt, scale, drawer, frame); | |
99 | - } | |
100 | - | |
101 | - [Obsolete] | |
102 | - public void DrawEx(ISurface dest, Point pos, Scaler scale, IPixelFilter f, int frame) { | |
103 | - Point pt = new Point(pos.X+location.X,pos.Y+location.Y); | |
104 | - texture.DrawEx(dest, pt, scale, f, frame); | |
105 | - } | |
106 | - */ | |
107 | - #endregion | |
108 | - | |
109 | - #region IDisposable メンバ | |
110 | - | |
111 | - public void Dispose() { | |
112 | - if(texture!=null){ | |
113 | - texture.Dispose(); | |
114 | - texture=null; | |
115 | - } | |
116 | - } | |
117 | - | |
118 | - #endregion | |
119 | - } | |
120 | -} |
@@ -1,391 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Runtime.InteropServices; | |
3 | -using System.Drawing; | |
4 | -using System.Drawing.Imaging; | |
5 | -using System.Diagnostics; | |
6 | -using DxVBLib; | |
7 | -//using DirectDrawAlphaBlendLib; | |
8 | -using nft.framework.drawing; | |
9 | - | |
10 | -namespace nft.drawing.ddraw7 | |
11 | -{ | |
12 | - /// <summary> | |
13 | - /// DD7Surface の概要の説明です。 | |
14 | - /// </summary> | |
15 | - /// <remarks>this class is originaly implemented by K.Kawaguchi</remarks> | |
16 | - public class DD7Surface : ISurfaceOld | |
17 | - { | |
18 | - protected DirectDrawSurface7 surface; | |
19 | - protected Color colorKey; | |
20 | - internal protected UInt32 colorKeyValue; | |
21 | - protected PixelColorMode colorMode; | |
22 | - protected Size surfaceSize; | |
23 | - | |
24 | - /// <summary> | |
25 | - /// Clipping rect. Even if the client doesn't set any clipping, | |
26 | - /// this is initialized to (0,0)-(size) | |
27 | - /// </summary> | |
28 | - protected RECT clip; | |
29 | - | |
30 | - public DD7Surface(DirectDrawSurface7 surface) | |
31 | - { | |
32 | - this.surface = surface; | |
33 | - this.colorKey = Color.Empty; | |
34 | - this.colorKeyValue = 0; | |
35 | - // compute the size of this surface | |
36 | - DDSURFACEDESC2 desc = new DDSURFACEDESC2(); | |
37 | - surface.GetSurfaceDesc( ref desc ); | |
38 | - this.surfaceSize = new Size( desc.lWidth, desc.lHeight ); | |
39 | - this.colorMode = DD7GraphicManager.GetPixelColorMode(surface); | |
40 | - ResetClipRect(); | |
41 | - | |
42 | - } | |
43 | - | |
44 | - ~DD7Surface() { | |
45 | - Dispose(false); | |
46 | - } | |
47 | - | |
48 | - #region クラス独自メソッド | |
49 | - static internal protected DirectDrawSurface7 ToNativeSurface(ISurfaceOld surface){ | |
50 | - DirectDrawSurface7 s; | |
51 | - try{ | |
52 | - s = ((DD7Surface)surface).NativeSurface; | |
53 | - }catch(InvalidCastException){ | |
54 | - DD7GraphicManager gm = DD7GraphicManager.TheInstance; | |
55 | - Bitmap bmp = surface.CreateBitmap(PixelColorMode.RGB24Bit); | |
56 | - DD7Surface temp = (DD7Surface)gm.CreateSurfaceFromBitmap(bmp); | |
57 | - s = temp.NativeSurface; | |
58 | - } | |
59 | - return s; | |
60 | - } | |
61 | - | |
62 | - /// <summary> | |
63 | - /// Returns true if the given exception is thrown because of | |
64 | - /// a lost surface. | |
65 | - /// </summary> | |
66 | - public static bool isSurfaceLostException( COMException e ) { | |
67 | - return (uint)e.ErrorCode == (uint)0x887601C2; | |
68 | - } | |
69 | - | |
70 | - public bool IsSurfaceLost { | |
71 | - get { return surface.isLost()!=0; } | |
72 | - } | |
73 | - | |
74 | - public DirectDrawSurface7 NativeSurface { get { return surface; } } | |
75 | - | |
76 | - public virtual Rectangle ClipRect { | |
77 | - get { | |
78 | - return Util.toRectangle(clip); | |
79 | - } | |
80 | - set { | |
81 | - // clipping rectangle must also clip things to fit inside the surface. | |
82 | - // otherwise blitting won't work. | |
83 | - value.Intersect( new Rectangle( 0,0, surfaceSize.Width, surfaceSize.Height ) ); | |
84 | - clip = Util.toRECT(value); | |
85 | - } | |
86 | - } | |
87 | - | |
88 | - public virtual RECT ClipRECT { | |
89 | - get { | |
90 | - return clip; | |
91 | - } | |
92 | - set { | |
93 | - ClipRect = Util.toRectangle(value); | |
94 | - } | |
95 | - } | |
96 | - | |
97 | - /// <summary> | |
98 | - /// Removes the clipping rect by re-initializing it | |
99 | - /// to the default size. | |
100 | - /// </summary> | |
101 | - public virtual void ResetClipRect() { | |
102 | - clip = Util.toRECT( new Point(0,0), surfaceSize ); | |
103 | - } | |
104 | - | |
105 | - public virtual void DxBlt(Rectangle dstRegion, DirectDrawSurface7 source, Rectangle srcRegion, CONST_DDBLTFLAGS addFlags){ | |
106 | - CONST_DDBLTFLAGS flag; | |
107 | - flag = CONST_DDBLTFLAGS.DDBLT_WAIT|addFlags; | |
108 | - | |
109 | - RECT dst = Util.toRECT(dstRegion); | |
110 | - RECT src = Util.toRECT(srcRegion); | |
111 | - //Util.clip( ref dst, ref src, clip ); | |
112 | - | |
113 | - surface.Blt( ref dst, source, ref src, flag ); | |
114 | - } | |
115 | - | |
116 | - public Color ColorKey { | |
117 | - set { | |
118 | - if(value == Color.Empty ) | |
119 | - RemoveColorKey(); | |
120 | - else | |
121 | - SetColorKey(value); | |
122 | - } | |
123 | - get { return colorKey; } | |
124 | - } | |
125 | - | |
126 | - protected void SetColorKey(Color c){ | |
127 | - colorKey = c; | |
128 | - colorKeyValue = PixelFormatUtil.ValueOf(c,colorMode); | |
129 | - DDCOLORKEY key = new DDCOLORKEY(); | |
130 | - key.high = key.low = (int)colorKeyValue; | |
131 | - surface.SetColorKey( CONST_DDCKEYFLAGS.DDCKEY_SRCBLT, ref key ); | |
132 | - } | |
133 | - | |
134 | - protected void RemoveColorKey(){ | |
135 | - unsafe { | |
136 | - colorKeyValue = 0; | |
137 | - colorKey = Color.Empty; | |
138 | - surface.SetColorKey( CONST_DDCKEYFLAGS.DDCKEY_DESTBLT, ref *(DDCOLORKEY*)new IntPtr(0)); | |
139 | - } | |
140 | - } | |
141 | - | |
142 | - internal protected int GetPixel(int x, int y) { | |
143 | - DDSURFACEDESC2 ddsd = new DDSURFACEDESC2(); | |
144 | - | |
145 | - // ロックしてポインタを得ます | |
146 | - ddsd.lSize = Marshal.SizeOf(ddsd); | |
147 | - RECT rect = new RECT(); | |
148 | - rect.Left = rect.Right = x; | |
149 | - rect.Top = rect.Bottom =y; | |
150 | - CONST_DDLOCKFLAGS flag = | |
151 | - CONST_DDLOCKFLAGS.DDLOCK_WAIT| | |
152 | - CONST_DDLOCKFLAGS.DDLOCK_NOSYSLOCK| | |
153 | - CONST_DDLOCKFLAGS.DDLOCK_READONLY; | |
154 | - surface.Lock(ref rect, ref ddsd, flag, 0); | |
155 | - int c = surface.GetLockedPixel(x,y); | |
156 | - surface.Unlock(ref rect); | |
157 | - | |
158 | - return c; | |
159 | - } | |
160 | - | |
161 | - #endregion | |
162 | - | |
163 | - #region ISurface メンバ | |
164 | - public Size Size { get { return surfaceSize; } } | |
165 | - | |
166 | - public PixelColorMode PixelColorMode { get { return colorMode; } } | |
167 | - | |
168 | - public void BitBlt(ISurfaceOld source, DrawParams dp) { | |
169 | - DirectDrawSurface7 ssrc = ToNativeSurface(source); | |
170 | - Size sz = dp.Scaler.Scale(dp.SoruceClip.Size); | |
171 | - Rectangle dst = new Rectangle(dp.Location, sz); | |
172 | - CONST_DDBLTFLAGS f = (source.ColorKey == Color.Empty) ? 0 : CONST_DDBLTFLAGS.DDBLT_KEYSRC; | |
173 | - DxBlt(dst, ssrc, dp.SoruceClip, f); | |
174 | - } | |
175 | - | |
176 | - public void BitBlt(ISurfaceOld source, DrawParams dp, IPixelFilter filter) { | |
177 | - DirectDrawSurface7 ssrc = ToNativeSurface(source); | |
178 | - Size sz = dp.Scaler.Scale(dp.SoruceClip.Size); | |
179 | - Rectangle dst = new Rectangle(dp.Location, sz); | |
180 | - // TODO: how to apply filter? | |
181 | - CONST_DDBLTFLAGS f = (source.ColorKey == Color.Empty) ? 0 : CONST_DDBLTFLAGS.DDBLT_KEYSRC; | |
182 | - DxBlt(dst, ssrc, dp.SoruceClip, f); | |
183 | - } | |
184 | - | |
185 | - public void BitBlt(ISurfaceOld source, DrawParams dp, ISurfaceDrawer drawer) { | |
186 | - if (!(source is DD7Surface)) | |
187 | - BitBlt(source, dp); | |
188 | - else { | |
189 | - DD7Surface srcSurf = source as DD7Surface; | |
190 | - DDSURFACEDESC2 srcSD = new DDSURFACEDESC2(); | |
191 | - DDSURFACEDESC2 dstSD = new DDSURFACEDESC2(); | |
192 | - srcSD.lSize = Marshal.SizeOf(srcSD); | |
193 | - dstSD.lSize = Marshal.SizeOf(dstSD); | |
194 | - // ロックしてポインタを得ます | |
195 | - CONST_DDLOCKFLAGS write = CONST_DDLOCKFLAGS.DDLOCK_WAIT | CONST_DDLOCKFLAGS.DDLOCK_WRITEONLY; | |
196 | - CONST_DDLOCKFLAGS read = CONST_DDLOCKFLAGS.DDLOCK_WAIT | CONST_DDLOCKFLAGS.DDLOCK_READONLY | CONST_DDLOCKFLAGS.DDLOCK_NOSYSLOCK; | |
197 | - RECT srcRec = Util.toRECT(dp.SoruceClip); | |
198 | - RECT dstRec = Util.toRECT(dp.Location, dp.Scaler.Scale(dp.SoruceClip.Size)); | |
199 | - Util.clip(ref dstRec, ref srcRec, this.ClipRECT); | |
200 | - NativeSurface.Lock(ref dstRec, ref dstSD, write, 0); | |
201 | - srcSurf.NativeSurface.Lock(ref srcRec, ref srcSD, read, 0); | |
202 | - DrawingDesc desc = new DrawingDesc(); | |
203 | - Util.PrepareDesc(ref desc, this, ref dstSD, ref dstRec, srcSurf, ref srcSD, ref srcRec, dp.Scaler); | |
204 | - drawer.Blt(ref desc); | |
205 | - NativeSurface.Unlock(ref srcRec); | |
206 | - srcSurf.NativeSurface.Unlock(ref dstRec); | |
207 | - } | |
208 | - } | |
209 | - | |
210 | -/* | |
211 | - private static AlphaBlender alpha = new AlphaBlenderClass(); | |
212 | - | |
213 | - public void BitBltAlpha(Point destpos, ISurface source, Rectangle region, int zoom) { | |
214 | - DirectDrawSurface7 ssrc = ToNativeSurface(source); | |
215 | - Size sz = ZoomUtil.Scale(region.Size, zoom); | |
216 | - Rectangle dst = new Rectangle(destpos, sz); | |
217 | - CONST_DDBLTFLAGS f = (source.ColorKey == Color.Empty) ? 0 : CONST_DDBLTFLAGS.DDBLT_KEYSRC; | |
218 | - RECT src = Util.toRECT(region); | |
219 | - alpha.bltAlphaFast(surface, ssrc, | |
220 | - dst.Left, dst.Top, | |
221 | - src.Left, src.Top, src.Right, src.Bottom, | |
222 | - (int)PixelFormatUtil.ValueOf(source.ColorKey, source.PixelColorMode)); | |
223 | - } | |
224 | -*/ | |
225 | - | |
226 | - [Obsolete] | |
227 | - public void BitBlt(Point destpos, ISurfaceOld source, Rectangle region, Scaler scale) { | |
228 | - DirectDrawSurface7 ssrc = ToNativeSurface(source); | |
229 | - Size sz = scale.Scale(region.Size); | |
230 | - Rectangle dst = new Rectangle(destpos,sz); | |
231 | - CONST_DDBLTFLAGS f = (source.ColorKey==Color.Empty)?0:CONST_DDBLTFLAGS.DDBLT_KEYSRC; | |
232 | - DxBlt(dst,ssrc,region,f); | |
233 | - } | |
234 | - [Obsolete] | |
235 | - public void BitBlt(Point destpos, ISurfaceOld source, Rectangle region, Scaler scale, IPixelFilter filter) { | |
236 | - DirectDrawSurface7 ssrc = ToNativeSurface(source); | |
237 | - Size sz = scale.Scale(region.Size); | |
238 | - Rectangle dst = new Rectangle(destpos, sz); | |
239 | - // TODO: how to apply filter? | |
240 | - CONST_DDBLTFLAGS f = (source.ColorKey == Color.Empty) ? 0 : CONST_DDBLTFLAGS.DDBLT_KEYSRC; | |
241 | - DxBlt(dst, ssrc, region, f); | |
242 | - } | |
243 | - [Obsolete] | |
244 | - public void BitBlt(Point destpos, ISurfaceOld source, Rectangle region, Scaler scale, ISurfaceDrawer drawer) { | |
245 | - if(!(source is DD7Surface)) | |
246 | - BitBlt(destpos, source, region, scale); | |
247 | - else { | |
248 | - DD7Surface srcSurf = source as DD7Surface; | |
249 | - DDSURFACEDESC2 srcSD = new DDSURFACEDESC2(); | |
250 | - DDSURFACEDESC2 dstSD = new DDSURFACEDESC2(); | |
251 | - srcSD.lSize = Marshal.SizeOf(srcSD); | |
252 | - dstSD.lSize = Marshal.SizeOf(dstSD); | |
253 | - // ロックしてポインタを得ます | |
254 | - CONST_DDLOCKFLAGS write = CONST_DDLOCKFLAGS.DDLOCK_WAIT|CONST_DDLOCKFLAGS.DDLOCK_WRITEONLY; | |
255 | - CONST_DDLOCKFLAGS read = CONST_DDLOCKFLAGS.DDLOCK_WAIT|CONST_DDLOCKFLAGS.DDLOCK_READONLY|CONST_DDLOCKFLAGS.DDLOCK_NOSYSLOCK; | |
256 | - RECT srcRec = Util.toRECT(region); | |
257 | - RECT dstRec = Util.toRECT(destpos, scale.Scale(region.Size)); | |
258 | - Util.clip(ref dstRec, ref srcRec, this.ClipRECT); | |
259 | - NativeSurface.Lock(ref dstRec, ref dstSD, write, 0); | |
260 | - srcSurf.NativeSurface.Lock(ref srcRec, ref srcSD, read, 0); | |
261 | - DrawingDesc desc = new DrawingDesc(); | |
262 | - Util.PrepareDesc(ref desc, this, ref dstSD, ref dstRec, srcSurf, ref srcSD, ref srcRec, scale); | |
263 | - drawer.Blt(ref desc); | |
264 | - NativeSurface.Unlock(ref srcRec); | |
265 | - srcSurf.NativeSurface.Unlock(ref dstRec); | |
266 | - } | |
267 | - } | |
268 | - | |
269 | - public void Clear(Color fill) { | |
270 | - surface.BltColorFill( ref clip, (int)PixelFormatUtil.ValueOf(fill,colorMode) ); | |
271 | - } | |
272 | - | |
273 | - public void Clear(Rectangle region, Color fill) { | |
274 | - RECT r = Util.intersect( Util.toRECT(region), clip ); | |
275 | - surface.BltColorFill( ref r, (int)PixelFormatUtil.ValueOf(fill,colorMode) ); | |
276 | - } | |
277 | - | |
278 | - public bool HitTest(int x, int y) { | |
279 | - return (GetPixel(x,y)&0xffffff)!=colorKeyValue; | |
280 | - } | |
281 | - | |
282 | - /// <summary> | |
283 | - /// Makes the bitmap of this surface. | |
284 | - /// The caller needs to dispose the bitmap. | |
285 | - /// </summary> | |
286 | - public Bitmap CreateBitmap(PixelColorMode mode) { | |
287 | - PixelFormat pf = PixelFormatUtil.ToPixelFormat(mode); | |
288 | - Bitmap bmp; | |
289 | - if(pf==PixelFormat.Undefined) | |
290 | - bmp = new Bitmap( surfaceSize.Width, surfaceSize.Height); | |
291 | - else | |
292 | - bmp = new Bitmap( surfaceSize.Width, surfaceSize.Height, pf ); | |
293 | - using( GDIGraphics src = new GDIGraphics(surface) ) { | |
294 | - using( Graphics dst = Graphics.FromImage(bmp) ) { | |
295 | - IntPtr dstHDC = dst.GetHdc(); | |
296 | - IntPtr srcHDC = src.graphics.GetHdc(); | |
297 | - BitBlt( dstHDC, 0, 0, surfaceSize.Width, surfaceSize.Height, srcHDC, 0, 0, 0x00CC0020 ); | |
298 | - dst.ReleaseHdc(dstHDC); | |
299 | - src.graphics.ReleaseHdc(srcHDC); | |
300 | - } | |
301 | - } | |
302 | - return bmp; | |
303 | - } | |
304 | - | |
305 | - #endregion | |
306 | - | |
307 | - protected DrawParams Adjust(DrawParams orig) { | |
308 | - if (orig.SoruceClip.Equals(Rectangle.Empty)) { | |
309 | - DrawParams dp = orig.Clone(); | |
310 | - dp.SoruceClip = new Rectangle(new Point(), Size); | |
311 | - return dp; | |
312 | - } else { | |
313 | - return orig; | |
314 | - } | |
315 | - } | |
316 | - | |
317 | - #region IDrawable メンバ | |
318 | - | |
319 | - public void DrawEx(DrawParams dp, IPixelFilter filter) { | |
320 | - dp.Destination.BitBlt(this, Adjust(dp), filter); | |
321 | - } | |
322 | - | |
323 | - public void DrawEx(DrawParams dp, ISurfaceDrawer drawer) { | |
324 | - dp.Destination.BitBlt(this, Adjust(dp), drawer); | |
325 | - } | |
326 | - | |
327 | - public void Draw(DrawParams dp) { | |
328 | - dp.Destination.BitBlt(this, Adjust(dp)); | |
329 | - } | |
330 | - #endregion | |
331 | - | |
332 | - #region IDisposable メンバ | |
333 | - | |
334 | - public virtual void Dispose() { | |
335 | - Dispose(true); | |
336 | - GC.SuppressFinalize(this); | |
337 | - } | |
338 | - | |
339 | - protected void Dispose(Boolean disposing) { | |
340 | - if (surface==null) | |
341 | - return; | |
342 | - // Unmanaged cleanup code here | |
343 | - if (disposing) { | |
344 | - System.Runtime.InteropServices.Marshal.ReleaseComObject(surface); | |
345 | - surface = null; | |
346 | - // Managed cleanup code here, while managed refs | |
347 | - // still valid | |
348 | - } | |
349 | - } | |
350 | - #endregion | |
351 | - | |
352 | - [DllImport("gdi32.dll")] | |
353 | - protected static extern bool BitBlt( | |
354 | - IntPtr hdcDest, | |
355 | - int nXDest, | |
356 | - int nYDest, | |
357 | - int nWidth, | |
358 | - int nHeight, | |
359 | - IntPtr hdcSrc, | |
360 | - int nXSrc, | |
361 | - int nYSrc, | |
362 | - long dwRop | |
363 | - ); | |
364 | - | |
365 | - } | |
366 | - | |
367 | - #region GDIGraphics class | |
368 | - /// <summary> | |
369 | - /// Wraps a Surface object and provides GDI+ functionality | |
370 | - /// via the graphics property. | |
371 | - /// </summary> | |
372 | - /// <remarks>this class is originaly implemented by K.Kawaguchi</remarks> | |
373 | - public sealed class GDIGraphics : IDisposable { | |
374 | - public readonly Graphics graphics; | |
375 | - | |
376 | - private readonly DirectDrawSurface7 surface; | |
377 | - private readonly int hdc; | |
378 | - | |
379 | - public GDIGraphics( DirectDrawSurface7 _surface ) { | |
380 | - this.surface = _surface; | |
381 | - this.hdc = surface.GetDC(); | |
382 | - graphics = Graphics.FromHdc( new IntPtr(hdc) ); | |
383 | - } | |
384 | - | |
385 | - public void Dispose() { | |
386 | - graphics.Dispose(); | |
387 | - surface.ReleaseDC(hdc); | |
388 | - } | |
389 | - } | |
390 | - #endregion | |
391 | -} |
@@ -1,295 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Drawing; | |
3 | -using System.Runtime.InteropServices; | |
4 | -using System.Windows.Forms; | |
5 | -using System.Diagnostics; | |
6 | -using System.Xml; | |
7 | -using DxVBLib; | |
8 | -using nft.framework; | |
9 | -using nft.framework.drawing; | |
10 | - | |
11 | -namespace nft.drawing.ddraw7 | |
12 | -{ | |
13 | - /// <summary> | |
14 | - /// DirectDraw root class. | |
15 | - /// </summary> | |
16 | - /// <remarks>Some part of these methods are originaly implemented by K.Kawaguchi</remarks> | |
17 | - public class DD7GraphicManager : IDisposable, IGraphicManagerOld | |
18 | - { | |
19 | - static protected DD7GraphicManager theInstance; | |
20 | - static internal protected DD7GraphicManager TheInstance { get { return theInstance; } } | |
21 | - | |
22 | - private WindowedDDraw7 ddraw; | |
23 | - private readonly string name; | |
24 | - private readonly string description; | |
25 | - | |
26 | - static protected CONST_DDSURFACECAPSFLAGS ToDDConstant(SurfaceAlloc place){ | |
27 | - CONST_DDSURFACECAPSFLAGS memoryPlace; | |
28 | - switch(place) { | |
29 | - case SurfaceAlloc.SystemMem: | |
30 | - memoryPlace = CONST_DDSURFACECAPSFLAGS.DDSCAPS_SYSTEMMEMORY; | |
31 | - break; | |
32 | - case SurfaceAlloc.VideoMem: | |
33 | - memoryPlace = CONST_DDSURFACECAPSFLAGS.DDSCAPS_VIDEOMEMORY; | |
34 | - break; | |
35 | - default: | |
36 | - memoryPlace = 0; | |
37 | - break; | |
38 | - } | |
39 | - return memoryPlace; | |
40 | - } | |
41 | - | |
42 | - public DD7GraphicManager( XmlNode node ){ | |
43 | - XmlAttribute a = node.Attributes["name"]; | |
44 | - if(a!=null) | |
45 | - name = a.Value; | |
46 | - else | |
47 | - name = "DirectDraw7 Graphics"; | |
48 | - XmlNode n = node.SelectSingleNode("description"); | |
49 | - if(n!=null) | |
50 | - description = n.InnerText; | |
51 | - else | |
52 | - description = "Microsoft DirectDraw(DirectX7) Graphic Manager"; | |
53 | - ddraw = new WindowedDDraw7(new UserControl()); | |
54 | - if(theInstance!=null) | |
55 | - theInstance.Dispose(); | |
56 | - theInstance = this; | |
57 | - } | |
58 | - | |
59 | - /// <summary> | |
60 | - /// System.Drawing.Imaging.PixelFormatに適した値をDDSURFACEDESC2.ddpfPixelFormatに設定 | |
61 | - /// </summary> | |
62 | - /// <param name="ddsd"></param> | |
63 | - /// <param name="format"></param> | |
64 | - /// <returns>formatが未対応の場合false</returns> | |
65 | - internal protected static bool SetPixelFormat(ref DDSURFACEDESC2 ddsd, PixelColorMode format){ | |
66 | - ddsd.ddpfPixelFormat.lSize = Marshal.SizeOf(ddsd.ddpfPixelFormat); | |
67 | - ddsd.ddpfPixelFormat.lFlags = CONST_DDPIXELFORMATFLAGS.DDPF_RGB; | |
68 | - | |
69 | - switch(format){ | |
70 | - case PixelColorMode.RGB32Bit: | |
71 | - ddsd.ddpfPixelFormat.lRGBBitCount = 32; | |
72 | - ddsd.ddpfPixelFormat.lRBitMask = 0x00FF0000; | |
73 | - ddsd.ddpfPixelFormat.lGBitMask = 0x0000FF00; | |
74 | - ddsd.ddpfPixelFormat.lBBitMask = 0x000000FF; | |
75 | - break; | |
76 | - case PixelColorMode.RGB24Bit: | |
77 | - ddsd.ddpfPixelFormat.lRGBBitCount = 24; | |
78 | - ddsd.ddpfPixelFormat.lRBitMask = 0x00FF0000; | |
79 | - ddsd.ddpfPixelFormat.lGBitMask = 0x0000FF00; | |
80 | - ddsd.ddpfPixelFormat.lBBitMask = 0x000000FF; | |
81 | - break; | |
82 | - case PixelColorMode.RGB16Bit565: | |
83 | - ddsd.ddpfPixelFormat.lRGBBitCount = 16; | |
84 | - ddsd.ddpfPixelFormat.lRBitMask = 0x0000F800; | |
85 | - ddsd.ddpfPixelFormat.lGBitMask = 0x000007E0; | |
86 | - ddsd.ddpfPixelFormat.lBBitMask = 0x0000001F; | |
87 | - break; | |
88 | - case PixelColorMode.RGB16Bit555: | |
89 | - ddsd.ddpfPixelFormat.lRGBBitCount = 16; | |
90 | - ddsd.ddpfPixelFormat.lRBitMask = 0x00007C00; | |
91 | - ddsd.ddpfPixelFormat.lGBitMask = 0x000003E0; | |
92 | - ddsd.ddpfPixelFormat.lBBitMask = 0x0000001F; | |
93 | - break; | |
94 | - default: | |
95 | - // format not supported. | |
96 | - return false; | |
97 | - } | |
98 | - return true; | |
99 | - } | |
100 | - | |
101 | - internal protected static PixelColorMode GetPixelColorMode(DirectDrawSurface7 surface) { | |
102 | - DDSURFACEDESC2 ddsd = new DDSURFACEDESC2(); | |
103 | - surface.GetSurfaceDesc(ref ddsd); | |
104 | - int bitcount = ddsd.ddpfPixelFormat.lRGBBitCount; | |
105 | - switch( bitcount ){ | |
106 | - case 32: | |
107 | - return PixelColorMode.RGB32Bit; | |
108 | - case 24: | |
109 | - return PixelColorMode.RGB24Bit; | |
110 | - case 16: | |
111 | - if(ddsd.ddpfPixelFormat.lBBitMask == 0x1f){ | |
112 | - if ( (ddsd.ddpfPixelFormat.lRBitMask == 0x7d) && | |
113 | - (ddsd.ddpfPixelFormat.lGBitMask == 0x3e0) ) { | |
114 | - return PixelColorMode.RGB16Bit555; | |
115 | - } | |
116 | - if ( (ddsd.ddpfPixelFormat.lRBitMask == 0xf800) && | |
117 | - (ddsd.ddpfPixelFormat.lGBitMask == 0x7e0) ) { | |
118 | - return PixelColorMode.RGB16Bit565; | |
119 | - } | |
120 | - } | |
121 | - break; | |
122 | - } | |
123 | - return PixelColorMode.Unknown; | |
124 | - } | |
125 | - | |
126 | - #region IGraphicManager メンバ | |
127 | - public PixelColorMode CurrentColorMode { | |
128 | - get{ | |
129 | - return GetPixelColorMode(ddraw.PrimarySurface.NativeSurface); | |
130 | - } | |
131 | - } | |
132 | - | |
133 | - public int TotalVideoMemory { | |
134 | - get { | |
135 | - DDSCAPS2 ddcaps = new DDSCAPS2(); | |
136 | - ddcaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_VIDEOMEMORY; | |
137 | - return ddraw.Handle.GetAvailableTotalMem(ref ddcaps); | |
138 | - } | |
139 | - } | |
140 | - | |
141 | - public int AvailableVideoMemory { | |
142 | - get { | |
143 | - DDSCAPS2 ddcaps = new DDSCAPS2(); | |
144 | - ddcaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_VIDEOMEMORY; | |
145 | - return ddraw.Handle.GetFreeMem(ref ddcaps); | |
146 | - } | |
147 | - } | |
148 | - | |
149 | - public ISprite CreateSprite( ITextureOld texture ) { | |
150 | - return new DD7Sprite(texture); | |
151 | - } | |
152 | - | |
153 | - public IStaticTexture CreateStaticTexture(ImageRef imageRef, Rectangle region, Point offset) { | |
154 | - return new DD7StaticTexture(imageRef,new Rectangle(0,0,region.Width,region.Height),offset); | |
155 | - } | |
156 | - | |
157 | - public IStaticTexture CreateStaticTexture(Image image, Point offset) { | |
158 | - DD7Surface s = (DD7Surface)CreateSurfaceFromBitmap(image); | |
159 | - Rectangle region = new Rectangle(0, 0, image.Width, image.Height); | |
160 | - return new DD7StaticTexture(s, region, offset, true); | |
161 | - } | |
162 | - | |
163 | - public IStaticTexture CreateStaticTexture(ISurfaceOld source, Rectangle region, Point offset, bool copyBits) { | |
164 | - if (source is DD7Surface && !copyBits) { | |
165 | - return new DD7StaticTexture((DD7Surface)source, region, offset, false); | |
166 | - } else { | |
167 | - DD7Surface s = (DD7Surface)DD7GraphicManager.TheInstance.CreateOffscreenSurface(region.Size); | |
168 | - s.BitBlt(new Point(0, 0), source, region, Scaler.Default); | |
169 | - region = new Rectangle(0, 0, source.Size.Width, source.Size.Height); | |
170 | - return new DD7StaticTexture(s, region, offset, true); | |
171 | - } | |
172 | - } | |
173 | - | |
174 | - public ISurfaceOld CreateOffscreenSurface(Size size) { | |
175 | - //Debug.Assert(size.Height>0 && size.Width>0,"invalid size"); | |
176 | - DDSURFACEDESC2 sd = new DDSURFACEDESC2(); | |
177 | - sd.lSize = Marshal.SizeOf(sd); | |
178 | - sd.lFlags = CONST_DDSURFACEDESCFLAGS.DDSD_CAPS | | |
179 | - CONST_DDSURFACEDESCFLAGS.DDSD_WIDTH | | |
180 | - CONST_DDSURFACEDESCFLAGS.DDSD_HEIGHT; | |
181 | - if(SetPixelFormat(ref sd, CurrentColorMode )) | |
182 | - sd.lFlags |= CONST_DDSURFACEDESCFLAGS.DDSD_PIXELFORMAT; | |
183 | - sd.ddsCaps.lCaps = CONST_DDSURFACECAPSFLAGS.DDSCAPS_OFFSCREENPLAIN|ToDDConstant(SurfaceAlloc.SystemMem); | |
184 | - sd.lHeight = size.Height; | |
185 | - sd.lWidth = size.Width; | |
186 | - try { | |
187 | - return new DD7Surface(ddraw.Handle.CreateSurface( ref sd )); | |
188 | - } | |
189 | - catch(Exception e) { | |
190 | - //for safe | |
191 | - Debug.WriteLine(string.Format("{0}:({1}x{2})",e.Message,size.Width,size.Height)); | |
192 | - sd.ddsCaps.lCaps |= CONST_DDSURFACECAPSFLAGS.DDSCAPS_SYSTEMMEMORY; | |
193 | - return new DD7Surface(ddraw.Handle.CreateSurface( ref sd )); | |
194 | - } | |
195 | - } | |
196 | - | |
197 | - public ISurfaceOld CreateSurfaceFromBitmap(Image source) { | |
198 | - Rectangle r = new Rectangle(0,0,source.Width,source.Height); | |
199 | - return CreateSurfaceFromBitmap(source, r); | |
200 | - } | |
201 | - | |
202 | - public ISurfaceOld CreateSurfaceFromBitmap(Image source, Rectangle region) { | |
203 | - | |
204 | - DD7Surface s = (DD7Surface)CreateOffscreenSurface(region.Size); | |
205 | - using(GDIGraphics g=new GDIGraphics(s.NativeSurface)) { | |
206 | - g.graphics.FillRectangle(new SolidBrush(Color.Black), region); | |
207 | - // without the size parameter, it doesn't work well with non-standard DPIs. | |
208 | - Rectangle dst = new Rectangle(0,0,region.Width,region.Height); | |
209 | - g.graphics.DrawImage( source, dst, region, GraphicsUnit.Pixel); | |
210 | - } | |
211 | - return s; | |
212 | - } | |
213 | - | |
214 | - public DrawableControl CreateDrawableControl() { | |
215 | - return new DD7Control(); | |
216 | - } | |
217 | - #endregion | |
218 | - | |
219 | - #region ISurfaceDrawer factories | |
220 | - private IntersectDrawer drawerIntersect = new IntersectDrawer(); | |
221 | - private HalfAlphaDrawer drawerAlpha = new HalfAlphaDrawer(); | |
222 | - private SelectBrighterDrawer drawerBrighter = new SelectBrighterDrawer(); | |
223 | - /// <summary> | |
224 | - /// create intersect drawer | |
225 | - /// draws only when both source and destination pixel is not transpalent | |
226 | - /// this drawer must be necessary for drawing perspective scenes | |
227 | - /// </summary> | |
228 | - /// <returns></returns> | |
229 | - public ISurfaceDrawer GetIntersectDrawer(){ | |
230 | - return drawerIntersect; | |
231 | - } | |
232 | - /// <summary> | |
233 | - /// create 50% alpha blend drawer | |
234 | - /// </summary> | |
235 | - /// <returns></returns> | |
236 | - public ISurfaceDrawer GetHalfAlphaDrawer(){ | |
237 | - return drawerAlpha; | |
238 | - } | |
239 | - /// <summary> | |
240 | - /// create brighter drawer | |
241 | - /// draws only when source pixel is brighter than destination | |
242 | - /// this drawer is used for red sunset and morning haze | |
243 | - /// </summary> | |
244 | - /// <returns></returns> | |
245 | - public ISurfaceDrawer GetBrighterDrawer(){ | |
246 | - return drawerBrighter; | |
247 | - } | |
248 | - /// <summary> | |
249 | - /// create color burn drawer | |
250 | - /// this drawer is used for red sunset and morning haze | |
251 | - /// </summary> | |
252 | - /// <param name="c"></param> | |
253 | - /// <param name="apply"></param> | |
254 | - /// <returns></returns> | |
255 | - public ISurfaceDrawer GetColorBurnDrawer(Color c, float apply){ | |
256 | - return new ColorBurnDrawer(c,apply); | |
257 | - } | |
258 | - /// <summary> | |
259 | - /// create mono color drawer | |
260 | - /// draws gray-scaled image with specified color | |
261 | - /// this drawer is used for setting highlihgt some sprites. | |
262 | - /// </summary> | |
263 | - /// <param name="c"></param> | |
264 | - /// <returns></returns> | |
265 | - public ISurfaceDrawer GetMonoColorDrawer(Color c){ | |
266 | - return new MonoColorDrawer(c); | |
267 | - } | |
268 | - #endregion | |
269 | - | |
270 | - #region IDisposable メンバ | |
271 | - | |
272 | - public void Dispose() { | |
273 | - ddraw.Dispose(); | |
274 | - } | |
275 | - | |
276 | - #endregion | |
277 | - | |
278 | - #region IGlobalModule メンバ | |
279 | - | |
280 | - public string Description { get { return description; } } | |
281 | - | |
282 | - public string Name { get { return name; } } | |
283 | - | |
284 | - public Type RegistType { | |
285 | - get { | |
286 | - Type t = this.GetType().GetInterface("IGraphicManagerOld"); | |
287 | - Debug.Assert((t!=null)&&(null!=this as IGraphicManagerOld)); | |
288 | - return t; | |
289 | - } | |
290 | - } | |
291 | - | |
292 | - #endregion | |
293 | - } | |
294 | - | |
295 | -} |
@@ -1,31 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Diagnostics; | |
3 | -using DxVBLib; | |
4 | - | |
5 | -namespace nft.drawing.ddraw7 | |
6 | -{ | |
7 | - /// <summary> | |
8 | - /// DDraw7 の概要の説明です。 | |
9 | - /// </summary> | |
10 | - /// <remarks>this class is originaly implemented by K.Kawaguchi</remarks> | |
11 | - public class DDraw7 : IDisposable | |
12 | - { | |
13 | - protected DirectDraw7 handle; | |
14 | - | |
15 | - public DDraw7() { | |
16 | - // initialize DirectDraw | |
17 | - DirectX7 dxc = new DirectX7Class(); | |
18 | - handle = dxc.DirectDrawCreate(""); | |
19 | - | |
20 | - handle.SetCooperativeLevel( 0, CONST_DDSCLFLAGS.DDSCL_NORMAL ); // window mode | |
21 | - } | |
22 | - | |
23 | - public virtual void Dispose() { | |
24 | - handle=null; | |
25 | - } | |
26 | - | |
27 | - internal DirectDraw7 Handle { get { return handle; } } | |
28 | - } | |
29 | - | |
30 | - | |
31 | -} |
@@ -94,7 +94,6 @@ | ||
94 | 94 | </item> |
95 | 95 | <item mid="HELP" caption="ヘルプ(&H)"> |
96 | 96 | <item mid="DEBUG|XNAFORMTEST" caption="XNAコントロールテスト"/> |
97 | - <item mid="DEBUG|GDITEST" caption="GDI描画ユーティリティテスト"/> | |
98 | 97 | <item mid="DEBUG|TABLEFORMTEST" caption="テーブルレイアウトのテスト"/> |
99 | 98 | <item mid="DEBUG|TERRAINTEST" caption="地形データ確認"/> |
100 | 99 | <item mid="DEBUG|DOCKTEST" caption="DockWindowコントロールテスト"/> |
@@ -204,12 +203,6 @@ | ||
204 | 203 | <command type="ModelessForm" menupath="HELP\DEBUG|TERRAINTEST" /> |
205 | 204 | </contribution> |
206 | 205 | |
207 | - <contribution type="Command" id="C_TestGDIDrawForm"> | |
208 | - <name>GDI描画クラスの機能テスト</name> | |
209 | - <class name="nft.debug.TestGDIDrawingForm"/> | |
210 | - <command type="ModelessForm" menupath="HELP\DEBUG|GDITEST" /> | |
211 | - </contribution> | |
212 | - | |
213 | 206 | <contribution type="Command" id="C_TestTableLayout"> |
214 | 207 | <name>テーブルレイアウトのテスト</name> |
215 | 208 | <class name="nft.debug.TableForm"/> |
@@ -142,6 +142,17 @@ | ||
142 | 142 | private Vector3 pos; |
143 | 143 | protected TerrainTemplate template; |
144 | 144 | |
145 | + internal TerrainPlate() { | |
146 | + } | |
147 | + | |
148 | + internal void Init(UInt32 id, TerrainTemplate templ){ | |
149 | + this._id = id; | |
150 | + this.template = templ; | |
151 | + this.filter = null; | |
152 | + this.pos = Vector3.Zero; | |
153 | + this._tag = null; | |
154 | + } | |
155 | + | |
145 | 156 | public TerrainPlate(UInt32 id, TerrainTemplate templ) |
146 | 157 | { |
147 | 158 | this._id = id; |
@@ -160,6 +171,7 @@ | ||
160 | 171 | #region I3DObject implementation |
161 | 172 | public UInt32 ID { |
162 | 173 | get { return _id; } |
174 | + set { _id = value; } | |
163 | 175 | } |
164 | 176 | |
165 | 177 | public object Tag { |
@@ -125,9 +125,12 @@ | ||
125 | 125 | throw new NotImplementedException(); |
126 | 126 | } |
127 | 127 | |
128 | + private TerrainPlate stock = new TerrainPlate(); | |
128 | 129 | public ITerrainPlate CreateTerrainPlate(UInt32 id, ITerrainPlateTemplate template) |
129 | 130 | { |
130 | - return new TerrainPlate(id, (TerrainTemplate)template); | |
131 | + //return new TerrainPlate(id, (TerrainTemplate)template); | |
132 | + stock.Init(id, (TerrainTemplate)template); | |
133 | + return stock; | |
131 | 134 | } |
132 | 135 | |
133 | 136 | public ICubicStructure CreateStructure(UInt32 id, ResourceKey rkey, ITexture texture, Point3D size3d) { |
@@ -44,6 +44,7 @@ | ||
44 | 44 | #region I3DObject implementation |
45 | 45 | public UInt32 ID { |
46 | 46 | get { return _id; } |
47 | + set { _id = value; } | |
47 | 48 | } |
48 | 49 | |
49 | 50 | public object Tag |
@@ -8,11 +8,14 @@ | ||
8 | 8 | using nft.framework.drawing; |
9 | 9 | using System.Diagnostics; |
10 | 10 | using Geocon = nft.core.geometry.GeometricConstants; |
11 | +using nft.core.game; | |
11 | 12 | |
12 | 13 | namespace nft.impl.view |
13 | 14 | { |
14 | 15 | public class SceneBuilder : IEnumerable<I3DObject> |
15 | 16 | { |
17 | + public delegate void TerrainPlateModifier(ITerrainPlate plate, ITerrainMap map, int x, int y, TerrainPieceTemplate.TerrainPolygonSet tpset); | |
18 | + | |
16 | 19 | CoordinationUtil cdUtil = null; |
17 | 20 | Scaler scaler; |
18 | 21 | InterCardinalDirection upperDir; |
@@ -17,7 +17,7 @@ | ||
17 | 17 | { |
18 | 18 | public enum Dir4SN : int { NE = 0, NW, SE, SW }; |
19 | 19 | /// <summary> |
20 | - /// TestFormDDraw の概要の説明です。 | |
20 | + /// TestTerrainForm の概要の説明です。 | |
21 | 21 | /// </summary> |
22 | 22 | public class TestTerrainForm : System.Windows.Forms.Form { |
23 | 23 |
@@ -1,12 +1,29 @@ | ||
1 | -XNA空間での座標軸 NeoFTのゲーム空間 | |
2 | -x y z y z x | |
3 | - \|/ yは上が正、x,zは奥が正 \|/ zは上が正、x,yは奥が正 | |
1 | +・前景と背景に分かれた3Dオブジェクト(線路など用) | |
2 | +・選択UIの基本、ステータス表示の基本 | |
3 | +・MRT昼夜同時描画/HitTest用マップ | |
4 | 4 | |
5 | +◎開発メモ | |
5 | 6 | ビルドしてobjからbinへのファイルコピー時にNFT.Framework.dllがロックする問題の暫定対処に |
6 | 7 | \NeoFT\framework\AssemblyInfo.cs |
7 | 8 | \NeoFT\core\AssemblyInfo.cs |
9 | + | |
8 | 10 | の29行目"AssemblyVersion"をコメントアウトした。最終リリースではコメント外すべき。 |
9 | 11 | |
12 | +■線路・道路の基本パターン | |
13 | +斜めは1:1対角線(45゚)と1:2(30゚)および2:1(60゚)対角線の3種類 | |
14 | +1:1線の太さは、TTDX式『1/√2』ではなく、A列車式改『√2』とする | |
15 | +※TTDX式 A列車式 A列車式改『√2』 | |
16 | + ∠|/ □ /□/ | |
17 | +∠|/ □ /□/ | |
18 | +TTDXはマス目の辺の中点を通るが、A列車は対角頂点を通る。 | |
19 | +A列車式『改』と銘打つのは斜めに繋がるマスとマスの間も補間するため。 | |
20 | + | |
21 | +■3D座標空間 | |
22 | +XNA空間での座標軸 NeoFTのゲーム空間 | |
23 | +x y z y z x | |
24 | + \|/ yは上が正、x,zは奥が正 \|/ zは上が正、x,yは奥が正 | |
25 | + | |
26 | + | |
10 | 27 | 北 東 後 |
11 | 28 | × 左◇右 |
12 | 29 | 西 南 前 |
@@ -1,77 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.IO; | |
3 | -using System.Collections.Generic; | |
4 | -using System.ComponentModel; | |
5 | -using System.Data; | |
6 | -using System.Drawing; | |
7 | -using System.Text; | |
8 | -using System.Windows.Forms; | |
9 | -using nft.framework.drawing; | |
10 | -using nft.framework; | |
11 | -using System.Diagnostics; | |
12 | - | |
13 | -namespace nft.debug { | |
14 | - public partial class TestGDIDrawingForm : Form { | |
15 | - protected ISurfaceOld bg; | |
16 | - protected ISurfaceOld buffer; | |
17 | - protected ISprite cursor; | |
18 | - protected IGraphicManagerOld graphic { get { return GlobalModules.GraphicManagerOld; } } | |
19 | - | |
20 | - public TestGDIDrawingForm() { | |
21 | - InitializeComponent(); | |
22 | - drawable.Canvas.Paint += new PaintEventHandler(Canvas_Paint); | |
23 | - drawable.Canvas.MouseMove += new MouseEventHandler(TestGDIDrawingForm_MouseMove); | |
24 | - prepareDrawing(); | |
25 | - Test t = new Test(new Point(123, 456)); | |
26 | - Point[] p = t.V; | |
27 | - p[0] = new Point(789,111); | |
28 | - p[1].X = 999; | |
29 | - Debug.WriteLine(t.V[0]); | |
30 | - Debug.WriteLine(t.V[1]); | |
31 | - } | |
32 | - | |
33 | - void Canvas_Paint(object sender, PaintEventArgs e) { | |
34 | - drawSceneImage(); | |
35 | - } | |
36 | - | |
37 | - private void prepareDrawing() { | |
38 | - string path = Path.Combine(Directories.AppBaseDir, @"res\grid_sample.gif"); | |
39 | - bg = graphic.CreateSurfaceFromBitmap(new Bitmap(path)); | |
40 | - buffer = graphic.CreateOffscreenSurface(drawable.Canvas.Size); | |
41 | - //drawable.Canvas.MouseMove += new MouseEventHandler(drawableControl1_MouseMove); | |
42 | - QuaterViewRect rect = new QuaterViewRect(16, 32, 16, 64, 32); | |
43 | - ITextureOld tex = PrimitiveTextrueFactory.CreateCellBoundsTexture(rect, this.Font, "テスト", Color.Green); | |
44 | - cursor = GlobalModules.GraphicManagerOld.CreateSprite(tex); | |
45 | - } | |
46 | - | |
47 | - private void drawSceneImage() { | |
48 | - if (bg != null) { | |
49 | - DrawParams param = new DrawParams(drawable.ScreenSurface, drawable.PointToScreen(new Point(0))); | |
50 | - bg.Draw(param); | |
51 | - drawable.ScreenSurface.ColorKey = Color.FromArgb(0x00, 0x72, 0xbc); | |
52 | - Point pt = MousePosition; | |
53 | - pt.X -= 24; | |
54 | - pt.Y -= 24; | |
55 | - param.Location = pt; | |
56 | - cursor.Draw(param); | |
57 | - //drawable.Surface. | |
58 | - } | |
59 | - } | |
60 | - | |
61 | - private void TestGDIDrawingForm_MouseMove(object sender, MouseEventArgs e) { | |
62 | - drawSceneImage(); | |
63 | - } | |
64 | - | |
65 | - } | |
66 | - | |
67 | - class Test { | |
68 | - private Point[] v; | |
69 | - public Test(Point p) { | |
70 | - v = new Point[]{ p, new Point(0,0)}; | |
71 | - } | |
72 | - | |
73 | - public Point[] V { | |
74 | - get { return (Point[])v.Clone(); } | |
75 | - } | |
76 | - } | |
77 | -} |
@@ -1,472 +0,0 @@ | ||
1 | - | |
2 | -using System; | |
3 | -using System.IO; | |
4 | -using System.Drawing; | |
5 | -using System.Collections; | |
6 | -using System.ComponentModel; | |
7 | -using System.Windows.Forms; | |
8 | -using nft.framework; | |
9 | -using nft.util; | |
10 | -using nft.ui; | |
11 | -using nft.framework.drawing; | |
12 | - | |
13 | -namespace nft.debug.ddraw | |
14 | -{ | |
15 | - /// <summary> | |
16 | - /// TestFormDDraw の概要の説明です。 | |
17 | - /// </summary> | |
18 | - public class TestFormDDraw : System.Windows.Forms.Form | |
19 | - { | |
20 | - private System.Windows.Forms.TabControl tabControl1; | |
21 | - private System.Windows.Forms.TabPage tabPage3; | |
22 | - private System.Windows.Forms.Label label1; | |
23 | - private System.Windows.Forms.Label l_t1; | |
24 | - private System.Windows.Forms.Label l_t2; | |
25 | - private System.Windows.Forms.Label l_t3; | |
26 | - private System.Windows.Forms.Label label5; | |
27 | - private System.Windows.Forms.Label label6; | |
28 | - private System.Windows.Forms.Label label7; | |
29 | - private System.Windows.Forms.Button btn_go; | |
30 | - private System.Windows.Forms.ComboBox combo_filter; | |
31 | - private System.Windows.Forms.ComboBox combo_zoom; | |
32 | - private System.Windows.Forms.Label label2; | |
33 | - private System.Windows.Forms.Label label3; | |
34 | - private bool calced; | |
35 | - private nft.framework.drawing.DrawablePanel drawable; | |
36 | - /// <summary> | |
37 | - /// 必要なデザイナ変数です。 | |
38 | - /// </summary> | |
39 | - private System.ComponentModel.Container components = null; | |
40 | - | |
41 | - public TestFormDDraw() | |
42 | - { | |
43 | - // | |
44 | - // Windows フォーム デザイナ サポートに必要です。 | |
45 | - // | |
46 | - InitializeComponent(); | |
47 | - combo_filter.SelectedIndex = 0; | |
48 | - combo_filter.Items.Add(graphic.GetHalfAlphaDrawer()); | |
49 | - combo_filter.Items.Add(graphic.GetIntersectDrawer()); | |
50 | - combo_filter.Items.Add(graphic.GetBrighterDrawer()); | |
51 | - combo_filter.Items.Add(graphic.GetColorBurnDrawer(Color.OrangeRed,0.5f)); | |
52 | - combo_filter.Items.Add(graphic.GetMonoColorDrawer(Color.LightBlue)); | |
53 | - combo_zoom.SelectedIndex = 2; | |
54 | - prepareDrawing(); | |
55 | - } | |
56 | - | |
57 | - protected IGraphicManagerOld graphic { get { return GlobalModules.GraphicManagerOld; } } | |
58 | - protected ISprite[] sprite; | |
59 | - protected ISurfaceOld spsrc; | |
60 | - protected ISurfaceOld bg; | |
61 | - protected ISurfaceOld buffer; | |
62 | - protected ISurfaceDrawer currentDrawer; | |
63 | - | |
64 | - private void prepareDrawing(){ | |
65 | - string path = Path.Combine(Directories.AppBaseDir,@"res\SpriteSamples.bmp"); | |
66 | - sprite = new ISprite[3]; | |
67 | - Rectangle r = new Rectangle(0,0,32,32); | |
68 | - using(Image bmp = Bitmap.FromFile(path)){ | |
69 | - spsrc = graphic.CreateSurfaceFromBitmap(bmp); | |
70 | - for(int i=0; i<3; i++){ | |
71 | - IStaticTexture t = graphic.CreateStaticTexture(spsrc,r,new Point(0),true); | |
72 | - t.PickColorKeyFromSource(0,31); | |
73 | - sprite[i] = graphic.CreateSprite(t); | |
74 | - r.X += 32; | |
75 | - } | |
76 | - } | |
77 | - path = Path.Combine(Directories.AppBaseDir,@"res\SceneSample.bmp"); | |
78 | - bg = graphic.CreateSurfaceFromBitmap(new Bitmap(path)); | |
79 | - buffer = graphic.CreateOffscreenSurface(drawable.Canvas.Size); | |
80 | - drawable.Canvas.MouseMove+=new MouseEventHandler(drawableControl1_MouseMove); | |
81 | - } | |
82 | - | |
83 | - /// <summary> | |
84 | - /// 使用されているリソースに後処理を実行します。 | |
85 | - /// </summary> | |
86 | - protected override void Dispose( bool disposing ) | |
87 | - { | |
88 | - if( disposing ) | |
89 | - { | |
90 | - if(components != null) | |
91 | - { | |
92 | - components.Dispose(); | |
93 | - } | |
94 | - if (spsrc != null) { | |
95 | - spsrc.Dispose(); | |
96 | - spsrc = null; | |
97 | - } | |
98 | - if (bg != null) { | |
99 | - bg.Dispose(); | |
100 | - bg = null; | |
101 | - } | |
102 | - if (buffer != null) { | |
103 | - buffer.Dispose(); | |
104 | - buffer = null; | |
105 | - } | |
106 | - } | |
107 | - base.Dispose( disposing ); | |
108 | - } | |
109 | - | |
110 | - #region Windows フォーム デザイナで生成されたコード | |
111 | - /// <summary> | |
112 | - /// デザイナ サポートに必要なメソッドです。このメソッドの内容を | |
113 | - /// コード エディタで変更しないでください。 | |
114 | - /// </summary> | |
115 | - private void InitializeComponent() | |
116 | - { | |
117 | - this.tabControl1 = new System.Windows.Forms.TabControl(); | |
118 | - this.tabPage3 = new System.Windows.Forms.TabPage(); | |
119 | - this.drawable = new nft.framework.drawing.DrawablePanel(); | |
120 | - this.combo_filter = new System.Windows.Forms.ComboBox(); | |
121 | - this.btn_go = new System.Windows.Forms.Button(); | |
122 | - this.label5 = new System.Windows.Forms.Label(); | |
123 | - this.l_t1 = new System.Windows.Forms.Label(); | |
124 | - this.l_t2 = new System.Windows.Forms.Label(); | |
125 | - this.l_t3 = new System.Windows.Forms.Label(); | |
126 | - this.label6 = new System.Windows.Forms.Label(); | |
127 | - this.label7 = new System.Windows.Forms.Label(); | |
128 | - this.combo_zoom = new System.Windows.Forms.ComboBox(); | |
129 | - this.label2 = new System.Windows.Forms.Label(); | |
130 | - this.label3 = new System.Windows.Forms.Label(); | |
131 | - this.label1 = new System.Windows.Forms.Label(); | |
132 | - this.tabControl1.SuspendLayout(); | |
133 | - this.tabPage3.SuspendLayout(); | |
134 | - this.SuspendLayout(); | |
135 | - // | |
136 | - // tabControl1 | |
137 | - // | |
138 | - this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | |
139 | - | System.Windows.Forms.AnchorStyles.Left) | |
140 | - | System.Windows.Forms.AnchorStyles.Right))); | |
141 | - this.tabControl1.Controls.Add(this.tabPage3); | |
142 | - this.tabControl1.ItemSize = new System.Drawing.Size(53, 17); | |
143 | - this.tabControl1.Location = new System.Drawing.Point(0, 0); | |
144 | - this.tabControl1.Name = "tabControl1"; | |
145 | - this.tabControl1.SelectedIndex = 0; | |
146 | - this.tabControl1.Size = new System.Drawing.Size(408, 392); | |
147 | - this.tabControl1.TabIndex = 1; | |
148 | - // | |
149 | - // tabPage3 | |
150 | - // | |
151 | - this.tabPage3.Controls.Add(this.drawable); | |
152 | - this.tabPage3.Controls.Add(this.combo_filter); | |
153 | - this.tabPage3.Controls.Add(this.btn_go); | |
154 | - this.tabPage3.Controls.Add(this.label5); | |
155 | - this.tabPage3.Controls.Add(this.l_t1); | |
156 | - this.tabPage3.Controls.Add(this.l_t2); | |
157 | - this.tabPage3.Controls.Add(this.l_t3); | |
158 | - this.tabPage3.Controls.Add(this.label6); | |
159 | - this.tabPage3.Controls.Add(this.label7); | |
160 | - this.tabPage3.Controls.Add(this.combo_zoom); | |
161 | - this.tabPage3.Controls.Add(this.label2); | |
162 | - this.tabPage3.Controls.Add(this.label3); | |
163 | - this.tabPage3.Location = new System.Drawing.Point(4, 21); | |
164 | - this.tabPage3.Name = "tabPage3"; | |
165 | - this.tabPage3.Size = new System.Drawing.Size(400, 367); | |
166 | - this.tabPage3.TabIndex = 2; | |
167 | - this.tabPage3.Text = "NewLib"; | |
168 | - // | |
169 | - // drawable | |
170 | - // | |
171 | - this.drawable.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | |
172 | - | System.Windows.Forms.AnchorStyles.Left) | |
173 | - | System.Windows.Forms.AnchorStyles.Right))); | |
174 | - this.drawable.BackColor = System.Drawing.SystemColors.Window; | |
175 | - this.drawable.Location = new System.Drawing.Point(0, 64); | |
176 | - this.drawable.Name = "drawable"; | |
177 | - this.drawable.Size = new System.Drawing.Size(400, 304); | |
178 | - this.drawable.TabIndex = 5; | |
179 | - // | |
180 | - // combo_filter | |
181 | - // | |
182 | - this.combo_filter.Items.AddRange(new object[] { | |
183 | - "Normal"}); | |
184 | - this.combo_filter.Location = new System.Drawing.Point(40, 8); | |
185 | - this.combo_filter.Name = "combo_filter"; | |
186 | - this.combo_filter.Size = new System.Drawing.Size(176, 20); | |
187 | - this.combo_filter.TabIndex = 4; | |
188 | - this.combo_filter.Text = "comboBox1"; | |
189 | - this.combo_filter.SelectedIndexChanged += new System.EventHandler(this.combo_filter_SelectedIndexChanged); | |
190 | - // | |
191 | - // btn_go | |
192 | - // | |
193 | - this.btn_go.Location = new System.Drawing.Point(352, 5); | |
194 | - this.btn_go.Name = "btn_go"; | |
195 | - this.btn_go.Size = new System.Drawing.Size(40, 24); | |
196 | - this.btn_go.TabIndex = 3; | |
197 | - this.btn_go.Text = "GO!"; | |
198 | - this.btn_go.Click += new System.EventHandler(this.btn_go_Click); | |
199 | - // | |
200 | - // label5 | |
201 | - // | |
202 | - this.label5.Location = new System.Drawing.Point(96, 40); | |
203 | - this.label5.Name = "label5"; | |
204 | - this.label5.Size = new System.Drawing.Size(24, 16); | |
205 | - this.label5.TabIndex = 2; | |
206 | - this.label5.Text = "T1:"; | |
207 | - this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |
208 | - // | |
209 | - // l_t1 | |
210 | - // | |
211 | - this.l_t1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; | |
212 | - this.l_t1.Location = new System.Drawing.Point(120, 40); | |
213 | - this.l_t1.Name = "l_t1"; | |
214 | - this.l_t1.Size = new System.Drawing.Size(64, 16); | |
215 | - this.l_t1.TabIndex = 1; | |
216 | - this.l_t1.Text = "--"; | |
217 | - this.l_t1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; | |
218 | - // | |
219 | - // l_t2 | |
220 | - // | |
221 | - this.l_t2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; | |
222 | - this.l_t2.Location = new System.Drawing.Point(224, 40); | |
223 | - this.l_t2.Name = "l_t2"; | |
224 | - this.l_t2.Size = new System.Drawing.Size(64, 16); | |
225 | - this.l_t2.TabIndex = 1; | |
226 | - this.l_t2.Text = "--"; | |
227 | - this.l_t2.TextAlign = System.Drawing.ContentAlignment.MiddleRight; | |
228 | - // | |
229 | - // l_t3 | |
230 | - // | |
231 | - this.l_t3.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; | |
232 | - this.l_t3.Location = new System.Drawing.Point(328, 40); | |
233 | - this.l_t3.Name = "l_t3"; | |
234 | - this.l_t3.Size = new System.Drawing.Size(64, 16); | |
235 | - this.l_t3.TabIndex = 1; | |
236 | - this.l_t3.Text = "--"; | |
237 | - this.l_t3.TextAlign = System.Drawing.ContentAlignment.MiddleRight; | |
238 | - // | |
239 | - // label6 | |
240 | - // | |
241 | - this.label6.Location = new System.Drawing.Point(200, 40); | |
242 | - this.label6.Name = "label6"; | |
243 | - this.label6.Size = new System.Drawing.Size(24, 16); | |
244 | - this.label6.TabIndex = 2; | |
245 | - this.label6.Text = "T2:"; | |
246 | - this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |
247 | - // | |
248 | - // label7 | |
249 | - // | |
250 | - this.label7.Location = new System.Drawing.Point(304, 40); | |
251 | - this.label7.Name = "label7"; | |
252 | - this.label7.Size = new System.Drawing.Size(24, 16); | |
253 | - this.label7.TabIndex = 2; | |
254 | - this.label7.Text = "T3:"; | |
255 | - this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |
256 | - // | |
257 | - // combo_zoom | |
258 | - // | |
259 | - this.combo_zoom.Items.AddRange(new object[] { | |
260 | - "x2", | |
261 | - "x1", | |
262 | - "x0.5", | |
263 | - "x0.25"}); | |
264 | - this.combo_zoom.Location = new System.Drawing.Point(272, 8); | |
265 | - this.combo_zoom.Name = "combo_zoom"; | |
266 | - this.combo_zoom.Size = new System.Drawing.Size(64, 20); | |
267 | - this.combo_zoom.TabIndex = 4; | |
268 | - this.combo_zoom.Text = "comboBox1"; | |
269 | - this.combo_zoom.SelectedIndexChanged += new System.EventHandler(this.combo_filter_SelectedIndexChanged); | |
270 | - // | |
271 | - // label2 | |
272 | - // | |
273 | - this.label2.Location = new System.Drawing.Point(0, 8); | |
274 | - this.label2.Name = "label2"; | |
275 | - this.label2.Size = new System.Drawing.Size(40, 24); | |
276 | - this.label2.TabIndex = 2; | |
277 | - this.label2.Text = "Filter:"; | |
278 | - this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |
279 | - // | |
280 | - // label3 | |
281 | - // | |
282 | - this.label3.Location = new System.Drawing.Point(232, 8); | |
283 | - this.label3.Name = "label3"; | |
284 | - this.label3.Size = new System.Drawing.Size(40, 24); | |
285 | - this.label3.TabIndex = 2; | |
286 | - this.label3.Text = "Zoom:"; | |
287 | - this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; | |
288 | - // | |
289 | - // label1 | |
290 | - // | |
291 | - this.label1.BackColor = System.Drawing.Color.Transparent; | |
292 | - this.label1.Dock = System.Windows.Forms.DockStyle.Fill; | |
293 | - this.label1.Location = new System.Drawing.Point(0, 0); | |
294 | - this.label1.Name = "label1"; | |
295 | - this.label1.TabIndex = 0; | |
296 | - this.label1.Text = "DrawableControl"; | |
297 | - // | |
298 | - // TestFormDDraw | |
299 | - // | |
300 | - this.AutoScaleBaseSize = new System.Drawing.Size(5, 12); | |
301 | - this.ClientSize = new System.Drawing.Size(408, 389); | |
302 | - this.Controls.Add(this.tabControl1); | |
303 | - this.Name = "TestFormDDraw"; | |
304 | - this.Text = "TestFormDDraw"; | |
305 | - this.tabControl1.ResumeLayout(false); | |
306 | - this.tabPage3.ResumeLayout(false); | |
307 | - this.ResumeLayout(false); | |
308 | - | |
309 | - } | |
310 | - #endregion | |
311 | - | |
312 | - private void drawableControl1_MouseMove(object sender, MouseEventArgs e) { | |
313 | - if(calced) return; | |
314 | - drawSceneImage(); | |
315 | - ISprite sp = sprite[2]; | |
316 | - int n = combo_zoom.SelectedIndex-2; | |
317 | - Scaler scaler = Scaler.Get((ZoomScale)n); | |
318 | - Size sz = scaler.Scale(sp.Texture.Boundary.Size); | |
319 | - Point pt = new Point(e.X-sz.Width*3/4, e.Y-sz.Height*3/4); | |
320 | - pt = ((Control)sender).PointToScreen(pt); | |
321 | - DrawParams param = new DrawParams(drawable.ScreenSurface, pt, scaler); | |
322 | - switch(combo_filter.SelectedIndex ){ | |
323 | - case 0: // Normal | |
324 | - sp.Draw(param); | |
325 | - break; | |
326 | -// case 1: // HalfAlpha | |
327 | -// sp.DrawEx(drawable.Surface, pt, zoom, currentDrawer, 0); | |
328 | -// break; | |
329 | - case -1: // nothing selected | |
330 | - break; | |
331 | - default: // Normal | |
332 | - currentDrawer = combo_filter.SelectedItem as ISurfaceDrawer; | |
333 | - sp.DrawEx(param, currentDrawer); | |
334 | - break; | |
335 | - } | |
336 | - } | |
337 | - | |
338 | - private void combo_filter_SelectedIndexChanged(object sender, System.EventArgs e) { | |
339 | - const string def = "--"; | |
340 | - l_t1.Text = def; | |
341 | - l_t2.Text = def; | |
342 | - l_t3.Text = def; | |
343 | - calced = false; | |
344 | - drawSceneImage(); | |
345 | - } | |
346 | - | |
347 | - private void drawSceneImage(){ | |
348 | - if(bg!=null) { | |
349 | - DrawParams param = new DrawParams(drawable.ScreenSurface, drawable.PointToScreen(new Point(0))); | |
350 | - bg.Draw(param); | |
351 | - drawable.ScreenSurface.ColorKey = Color.FromArgb(0x00,0x72,0xbc); | |
352 | - } | |
353 | - } | |
354 | - | |
355 | -// NFT.DirectDraw描画スピードテスト | |
356 | -// ■ノーマル: | |
357 | -// x2: 186,199,197 | |
358 | -// x1: 071,073,074 | |
359 | -// xH: 074,074,077 | |
360 | -// xQ: 070,070,070 | |
361 | -// ■AlphaBlenderClass(比較用): | |
362 | -// x1: 100,123,116 | |
363 | - private void btn_go_Click(object sender, System.EventArgs e) { | |
364 | - calced = true; | |
365 | - switch(combo_filter.SelectedIndex ){ | |
366 | - case 0: // Normal | |
367 | - doTestNormal(); | |
368 | - break; | |
369 | -// case 1: // HalfAlpha | |
370 | -// doTestDrawer(currentDrawer); | |
371 | -// break; | |
372 | - case -1: // nothing selected | |
373 | - break; | |
374 | - default: // Normal | |
375 | - currentDrawer = combo_filter.SelectedItem as ISurfaceDrawer; | |
376 | - doTestDrawer(currentDrawer); | |
377 | - break; | |
378 | - } | |
379 | - } | |
380 | - | |
381 | - private void doTestNormal(){ | |
382 | - Label[] labels = new Label[] { l_t1,l_t2,l_t3 }; | |
383 | - int width = drawable.Canvas.Width; | |
384 | - int height = drawable.Canvas.Height; | |
385 | - int zs = 3-combo_zoom.SelectedIndex; | |
386 | - Scaler scale = Scaler.Get((ZoomScale)zs); | |
387 | - for(int i=0; i<3; i++ ){ | |
388 | - int x=0,y=0; | |
389 | - DateTime start = DateTime.Now; | |
390 | - for(int n=0; n<100; n++){ | |
391 | - int m = 255-n; | |
392 | - buffer.Clear(Rectangle.Empty, Color.FromArgb(m,m,m)); | |
393 | - y = 0; | |
394 | - while(y<height){ | |
395 | - x = 0; | |
396 | - while(x<width) { | |
397 | - DrawParams p1 = new DrawParams(buffer, new Point(x, y), scale); | |
398 | - sprite[i].Draw(p1); | |
399 | - x+=16; | |
400 | - } | |
401 | - y+=16; | |
402 | - } | |
403 | - DrawParams p2 = new DrawParams(drawable.ScreenSurface, drawable.Canvas.PointToScreen(new Point(0, 0))); | |
404 | - buffer.Draw(p2); | |
405 | - } | |
406 | - TimeSpan span = DateTime.Now - start; | |
407 | - labels[i].Text = string.Format("{0} ns", (int)(span.TotalMilliseconds*10000/(x*y))); | |
408 | - } | |
409 | - } | |
410 | - | |
411 | - private void doTestDrawer(ISurfaceDrawer drawer){ | |
412 | - Label[] labels = new Label[] { l_t1,l_t2,l_t3 }; | |
413 | - int width = drawable.Canvas.Width; | |
414 | - int height = drawable.Canvas.Height; | |
415 | - int zs = 3-combo_zoom.SelectedIndex; | |
416 | - Scaler scale = Scaler.Get((ZoomScale)zs); | |
417 | - for (int i = 0; i < 3; i++) { | |
418 | - int x=0,y=0; | |
419 | - DateTime start = DateTime.Now; | |
420 | - for(int n=0; n<100; n++){ | |
421 | - int m = 255-n; | |
422 | - buffer.Clear(Rectangle.Empty, Color.FromArgb(m,m,m)); | |
423 | - y = 0; | |
424 | - while(y<height){ | |
425 | - x = 0; | |
426 | - while(x<width) { | |
427 | - DrawParams p1 = new DrawParams(buffer, new Point(x, y), scale); | |
428 | - sprite[i].DrawEx(p1, drawer); | |
429 | - x+=16; | |
430 | - } | |
431 | - y+=16; | |
432 | - } | |
433 | - DrawParams p2 = new DrawParams(drawable.ScreenSurface, drawable.Canvas.PointToScreen(new Point(0, 0))); | |
434 | - buffer.Draw(p2); | |
435 | - } | |
436 | - TimeSpan span = DateTime.Now - start; | |
437 | - labels[i].Text = string.Format("{0} ns", (int)(span.TotalMilliseconds*10000/(x*y))); | |
438 | - } | |
439 | - } | |
440 | - | |
441 | - private void doTestFilter(IPixelFilter pf){ | |
442 | - Label[] labels = new Label[] { l_t1,l_t2,l_t3 }; | |
443 | - int width = drawable.Canvas.Width; | |
444 | - int height = drawable.Canvas.Height; | |
445 | - int zs = 3-combo_zoom.SelectedIndex; | |
446 | - Scaler scale = Scaler.Get((ZoomScale)zs); | |
447 | - for (int i = 0; i < 3; i++) { | |
448 | - int x=0,y=0; | |
449 | - DateTime start = DateTime.Now; | |
450 | - for(int n=0; n<100; n++){ | |
451 | - int m = 255-n; | |
452 | - buffer.Clear(Rectangle.Empty, Color.FromArgb(m,m,m)); | |
453 | - y = 0; | |
454 | - while(y<height){ | |
455 | - x = 0; | |
456 | - while(x<width) { | |
457 | - DrawParams p1 = new DrawParams(buffer, new Point(x, y), scale); | |
458 | - sprite[i].DrawEx(p1, pf); | |
459 | - x+=16; | |
460 | - } | |
461 | - y+=16; | |
462 | - } | |
463 | - DrawParams p2 = new DrawParams(drawable.ScreenSurface, drawable.Canvas.PointToScreen(new Point(0,0))); | |
464 | - buffer.Draw(p2); | |
465 | - } | |
466 | - TimeSpan span = DateTime.Now - start; | |
467 | - labels[i].Text = string.Format("{0} ns", (int)(span.TotalMilliseconds*10000/(x*y))); | |
468 | - } | |
469 | - } | |
470 | - | |
471 | - } | |
472 | -} |
@@ -1,54 +0,0 @@ | ||
1 | -namespace nft.debug { | |
2 | - partial class TestGDIDrawingForm { | |
3 | - /// <summary> | |
4 | - /// Required designer variable. | |
5 | - /// </summary> | |
6 | - private System.ComponentModel.IContainer components = null; | |
7 | - | |
8 | - /// <summary> | |
9 | - /// Clean up any resources being used. | |
10 | - /// </summary> | |
11 | - /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> | |
12 | - protected override void Dispose(bool disposing) { | |
13 | - if (disposing && (components != null)) { | |
14 | - components.Dispose(); | |
15 | - } | |
16 | - base.Dispose(disposing); | |
17 | - } | |
18 | - | |
19 | - #region Windows Form Designer generated code | |
20 | - | |
21 | - /// <summary> | |
22 | - /// Required method for Designer support - do not modify | |
23 | - /// the contents of this method with the code editor. | |
24 | - /// </summary> | |
25 | - private void InitializeComponent() { | |
26 | - this.drawable = new nft.framework.drawing.DrawablePanel(); | |
27 | - this.SuspendLayout(); | |
28 | - // | |
29 | - // drawable | |
30 | - // | |
31 | - this.drawable.BackColor = System.Drawing.SystemColors.Window; | |
32 | - this.drawable.Dock = System.Windows.Forms.DockStyle.Fill; | |
33 | - this.drawable.Location = new System.Drawing.Point(0, 0); | |
34 | - this.drawable.Name = "drawable"; | |
35 | - this.drawable.Size = new System.Drawing.Size(255, 255); | |
36 | - this.drawable.TabIndex = 0; | |
37 | - // | |
38 | - // TestGDIDrawingForm | |
39 | - // | |
40 | - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); | |
41 | - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; | |
42 | - this.ClientSize = new System.Drawing.Size(255, 255); | |
43 | - this.Controls.Add(this.drawable); | |
44 | - this.Name = "TestGDIDrawingForm"; | |
45 | - this.Text = "TestGDI Drawing"; | |
46 | - this.ResumeLayout(false); | |
47 | - | |
48 | - } | |
49 | - | |
50 | - #endregion | |
51 | - | |
52 | - private nft.framework.drawing.DrawablePanel drawable; | |
53 | - } | |
54 | -} | |
\ No newline at end of file |
@@ -1,306 +0,0 @@ | ||
1 | -using System; | |
2 | -using System.Collections; | |
3 | -using System.ComponentModel; | |
4 | -using System.Drawing; | |
5 | -using System.Data; | |
6 | -using System.Windows.Forms; | |
7 | -using nft.ui.mainframe; | |
8 | -using System.Drawing.Drawing2D; | |
9 | -using System.Diagnostics; | |
10 | - | |
11 | -namespace nft.framework.drawing | |
12 | -{ | |
13 | - /// <summary> | |
14 | - /// 有効なDrawableControl をラップしたユーザーコントロール。 | |
15 | - /// a UserControl which wraps valid DrawableControl. | |
16 | - /// </summary> | |
17 | - [Obsolete] | |
18 | - public class DrawablePanel : System.Windows.Forms.UserControl, IView | |
19 | - { | |
20 | - protected static readonly IViewDrawer nullDrawer = new NullDrawer(); | |
21 | - /// <summary> | |
22 | - /// 必要なデザイナ変数です。 | |
23 | - /// </summary> | |
24 | - private System.ComponentModel.Container components = null; | |
25 | - | |
26 | - private DrawableControl canvas; | |
27 | - private IViewDrawer drawer = nullDrawer; | |
28 | - private Region dirtyRegion = null; | |
29 | - | |
30 | - public DrawablePanel() | |
31 | - { | |
32 | - // この呼び出しは、Windows.Forms フォーム デザイナで必要です。 | |
33 | - InitializeComponent(); | |
34 | - InitializeCanvas(); | |
35 | - } | |
36 | - | |
37 | - /// <summary> | |
38 | - /// 使用されているリソースに後処理を実行します。 | |
39 | - /// </summary> | |
40 | - protected override void Dispose( bool disposing ) | |
41 | - { | |
42 | - if( disposing ) | |
43 | - { | |
44 | - if(components != null) | |
45 | - { | |
46 | - components.Dispose(); | |
47 | - } | |
48 | - if (drawer != null) { | |
49 | - drawer.Dispose(); | |
50 | - } | |
51 | - } | |
52 | - base.Dispose( disposing ); | |
53 | - } | |
54 | - | |
55 | - /// <summary> | |
56 | - /// a DrawableControl wrapped by this panel | |
57 | - /// </summary> | |
58 | - public DrawableControl Canvas { get { return canvas; } } | |
59 | - | |
60 | - /// <summary> | |
61 | - /// Primary surface (Short cut to this.Canvas.Surface ) | |
62 | - /// </summary> | |
63 | - public ISurfaceOld ScreenSurface { get { return canvas.Surface; } } | |
64 | - | |
65 | - /// <summary> | |
66 | - /// ViewDrawer can be null because you can draw directory | |
67 | - /// by accessing this.Surface | |
68 | - /// </summary> | |
69 | - public IViewDrawer ViewDrawer { | |
70 | - get { return (drawer == nullDrawer) ? null : drawer; } | |
71 | - set { | |
72 | - if (drawer != nullDrawer) { | |
73 | - if (drawer == value) return; | |
74 | - drawer.Dispose(); | |
75 | - } | |
76 | - Point newPos; | |
77 | - if (value != null) { | |
78 | - drawer = value; | |
79 | - drawer.Attach(this); | |
80 | - canvas.AutoScroll = true; | |
81 | - Size sz = drawer.ContentSize; | |
82 | - newPos = new Point(sz.Width >> 1, sz.Height >> 1); | |
83 | - } else { | |
84 | - drawer = nullDrawer; | |
85 | - canvas.AutoScroll = false; | |
86 | - newPos = new Point(); | |
87 | - } | |
88 | - SetScrollSizeForDrawer(); | |
89 | - ViewPosition = newPos; | |
90 | - Invalidate(); | |
91 | - } | |
92 | - } | |
93 | - | |
94 | - protected virtual void SetScrollSizeForDrawer(){ | |
95 | - canvas.AutoScrollMinSize = drawer.ContentSize; | |
96 | - Size sz = drawer.ScrollUnit; | |
97 | - if (sz.Height > 0) { | |
98 | - canvas.VerticalScroll.SmallChange = sz.Height; | |
99 | - } | |
100 | - if (sz.Width > 0) { | |
101 | - canvas.HorizontalScroll.SmallChange = sz.Width; | |
102 | - } | |
103 | - } | |
104 | - | |
105 | - /// <summary> | |
106 | - /// topleft position of visible area in the view content | |
107 | - /// </summary> | |
108 | - public Point ViewPosition { | |
109 | - get { | |
110 | - // Be aware that AutoScrollPosition returns negative coordination. | |
111 | - Point pt = Canvas.AutoScrollPosition; | |
112 | - // To avoid complexity, returns positive coordination. | |
113 | - return new Point(-pt.X, -pt.Y); | |
114 | - } | |
115 | - set { | |
116 | - Size sz = drawer.ContentSize - ClientSize; | |
117 | - Point pt = ViewPosition; | |
118 | - int nx = Math.Max(0, Math.Min(sz.Width, value.X)); | |
119 | - int ny = Math.Max(0, Math.Min(sz.Height, value.Y)); | |
120 | - if (pt.X != nx || pt.Y != ny) { | |
121 | - pt.X = nx; | |
122 | - pt.Y = ny; | |
123 | - // Be aware that we must set positive coordination for AutoScrollPosition, | |
124 | - // even though it returns negative coordination. | |
125 | - Canvas.AutoScrollPosition = pt; | |
126 | - Invalidate(); | |
127 | - } | |
128 | - } | |
129 | - } | |
130 | - | |
131 | - /// <summary> | |
132 | - /// returns visible client rectangle of drawable control by screen coordination | |
133 | - /// </summary> | |
134 | - public Rectangle DrawableScreenRect { | |
135 | - get { | |
136 | - Rectangle rect = canvas.ClientRectangle; | |
137 | - rect.Location = canvas.PointToScreen(rect.Location); | |
138 | - return rect; | |
139 | - } | |
140 | - } | |
141 | - | |
142 | - #region IView メンバ | |
143 | - public Rectangle VisibleSourceRect { | |
144 | - get { | |
145 | - Rectangle cl = canvas.ClientRectangle; | |
146 | - Size sz = drawer.ContentSize; | |
147 | - cl.Location = ViewPosition; | |
148 | - Rectangle rt = new Rectangle(cl.X, cl.Y, | |
149 | - Math.Min(sz.Width, cl.Width), Math.Min(sz.Height, cl.Height)); | |
150 | - return rt; | |
151 | - } | |
152 | - } | |
153 | - | |
154 | - public void NotifyUpdate(Region srcUpdated, bool callbackImmediately) { | |
155 | - if (callbackImmediately) { | |
156 | - using (Graphics g = CreateGraphics()) { | |
157 | - drawer.Draw(g, this, DrawableScreenRect, srcUpdated); | |
158 | - } | |
159 | - } else if (srcUpdated == null) { | |
160 | - Rectangle rt = canvas.Bounds; | |
161 | - Invalidate(rt); | |
162 | - } else { | |
163 | - using (Graphics g = CreateGraphics()) { | |
164 | - Point pt = canvas.PointToScreen(ViewPosition); | |
165 | - pt = PointToClient(pt); | |
166 | - Region rgn = new Region(VisibleSourceRect); | |
167 | - Debug.Write("※update:" + rgn.GetBounds(g)); | |
168 | - rgn.Intersect(srcUpdated); | |
169 | - Matrix mtrx = new Matrix(); | |
170 | - mtrx.Translate(pt.X, pt.Y); | |
171 | - rgn.Transform(mtrx); | |
172 | - Debug.WriteLine(", translate:" + rgn.GetBounds(g)); | |
173 | - if (dirtyRegion != null) { | |
174 | - dirtyRegion.Union(rgn); | |
175 | - } else { | |
176 | - dirtyRegion = rgn; | |
177 | - } | |
178 | - Invalidate(rgn); | |
179 | - } | |
180 | - } | |
181 | - } | |
182 | - | |
183 | - public void NotifyContentSizeChanged(Point newPos) { | |
184 | - Size sz = canvas.AutoScrollMinSize; | |
185 | - Point pt = canvas.AutoScrollPosition; | |
186 | - SetScrollSizeForDrawer(); | |
187 | - ViewPosition = newPos; | |
188 | - Invalidate(); | |
189 | - } | |
190 | - | |
191 | - #endregion | |
192 | - | |
193 | - #region コンポーネント デザイナで生成されたコード | |
194 | - /// <summary> | |
195 | - /// デザイナ サポートに必要なメソッドです。このメソッドの内容を | |
196 | - /// コード エディタで変更しないでください。 | |
197 | - /// </summary> | |
198 | - private void InitializeComponent() | |
199 | - { | |
200 | - this.SuspendLayout(); | |
201 | - // | |
202 | - // DrawablePanel | |
203 | - // | |
204 | - this.BackColor = System.Drawing.SystemColors.Window; | |
205 | - this.Name = "DrawablePanel"; | |
206 | - this.Size = new System.Drawing.Size(88, 88); | |
207 | - this.ResumeLayout(false); | |
208 | - | |
209 | - } | |
210 | - #endregion | |
211 | - private void InitializeCanvas() { | |
212 | - this.SuspendLayout(); | |
213 | - try{ | |
214 | - this.canvas = GlobalModules.GraphicManagerOld.CreateDrawableControl(); | |
215 | - // | |
216 | - // canvas | |
217 | - // | |
218 | - this.canvas.Dock = System.Windows.Forms.DockStyle.Fill; | |
219 | - this.canvas.Location = new System.Drawing.Point(0, 0); | |
220 | - this.canvas.Name = "canvas"; | |
221 | - this.canvas.TabIndex = 0; | |
222 | - this.canvas.BackColor = Color.Transparent; // Transparent can cause repaint wrapper panel. | |
223 | - //this.canvas.Paint += new System.Windows.Forms.PaintEventHandler(this.DrawablePanel_Paint); | |
224 | - // | |
225 | - // DrawablePanel | |
226 | - // | |
227 | - this.Controls.Add(this.canvas); | |
228 | - }catch { | |
229 | - } | |
230 | - this.ResumeLayout(false); | |
231 | - } | |
232 | - #region Control override | |
233 | - protected override void OnPaintBackground(PaintEventArgs pevent) { | |
234 | - if (drawer == nullDrawer) { | |
235 | - base.OnPaintBackground(pevent); | |
236 | - } else { | |
237 | - // if client size is larger than content size, fill margin. | |
238 | - Size sz = drawer.ContentSize; | |
239 | - Point pt = ViewPosition; | |
240 | - int cw = sz.Width + pt.X; | |
241 | - int ch = sz.Height + pt.Y; | |
242 | - Size sz2 = ClientSize; | |
243 | - Brush br = null; | |
244 | - if (sz2.Width > cw) { | |
245 | - cw = Math.Max(cw,0); | |
246 | - br = new SolidBrush(BackColor); | |
247 | - int w2 = sz2.Width - cw; | |
248 | - pevent.Graphics.FillRectangle(br, cw, 0, w2, sz2.Height); | |
249 | - sz2.Width -= w2; | |
250 | - } | |
251 | - if (sz2.Height > ch) { | |
252 | - ch = Math.Max(ch, 0); | |
253 | - if (br == null) { | |
254 | - br = new SolidBrush(BackColor); | |
255 | - } | |
256 | - pevent.Graphics.FillRectangle(br, 0, ch, sz2.Width, sz2.Height-ch); | |
257 | - } | |
258 | - if (br != null) { | |
259 | - br.Dispose(); | |
260 | - } | |
261 | - } | |
262 | - } | |
263 | - | |
264 | - protected override void OnPaint(PaintEventArgs pe) { | |
265 | - if (drawer != nullDrawer) { | |
266 | - Rectangle rect = Rectangle.Round(pe.Graphics.ClipBounds); | |
267 | - rect.Intersect(canvas.Bounds); | |
268 | - rect.Location = canvas.PointToScreen(rect.Location); | |
269 | - if (dirtyRegion != null) { | |
270 | - drawer.Draw(pe.Graphics, this, rect, dirtyRegion); | |
271 | - dirtyRegion.Dispose(); | |
272 | - dirtyRegion = null; | |
273 | - } else { | |
274 | - Region rgn = new Region(VisibleSourceRect); | |
275 | - drawer.Draw(pe.Graphics, this, rect, rgn); | |
276 | - rgn.Dispose(); | |
277 | - } | |
278 | - } | |
279 | - base.OnPaint(pe); | |
280 | - } | |
281 | - #endregion | |
282 | - #region NullDrawer class | |
283 | - class NullDrawer : IViewDrawer { | |
284 | - public void Attach(IView view) { | |
285 | - } | |
286 | - | |
287 | - public void Detach(IView view) { | |
288 | - } | |
289 | - | |
290 | - public void Draw(Graphics g, IView owner, Rectangle destArea, Region requestSrc) { | |
291 | - } | |
292 | - | |
293 | - public Size ContentSize { | |
294 | - get { return new Size(); } | |
295 | - } | |
296 | - | |
297 | - public Size ScrollUnit { | |
298 | - get { return new Size(); } | |
299 | - } | |
300 | - | |
301 | - public void Dispose() { | |
302 | - } | |
303 | - } | |
304 | - #endregion | |
305 | - } | |
306 | -} |
@@ -65,10 +65,13 @@ | ||
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - public interface I3DObject : IDisposable | |
68 | + /// <summary> | |
69 | + /// Instance Recycle(Reuse) is recommended for Memory saving purpos. | |
70 | + /// </summary> | |
71 | + public interface I3DObject //: IDisposable | |
69 | 72 | { |
70 | - UInt32 ID { get; } | |
71 | - object Tag { get; set; } | |
73 | + UInt32 ID { get; set; } | |
74 | + //object Tag { get; set; } | |
72 | 75 | IEffectFilter Effect { get; set; } |
73 | 76 | } |
74 | 77 |