OSDN Git Service

#36897 [DTXC] MIDIインポート機能の呼び出し口を、ファイルメニュー内にも配置。
[dtxmania/dtxmania.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d10 / Font10.cpp
1 #include "stdafx.h"\r
2 /*\r
3 * Copyright (c) 2007-2010 SlimDX Group\r
4\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy\r
6 * of this software and associated documentation files (the "Software"), to deal\r
7 * in the Software without restriction, including without limitation the rights\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
9 * copies of the Software, and to permit persons to whom the Software is\r
10 * furnished to do so, subject to the following conditions:\r
11\r
12 * The above copyright notice and this permission notice shall be included in\r
13 * all copies or substantial portions of the Software.\r
14\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
21 * THE SOFTWARE.\r
22 */\r
23 \r
24 #include <d3dx10.h>\r
25 #include <vcclr.h>\r
26 \r
27 #include "Direct3D10Exception.h"\r
28 \r
29 #include "Device10.h"\r
30 #include "Font10.h"\r
31 #include "FontDescription10.h"\r
32 #include "Sprite10.h"\r
33 \r
34 using namespace System;\r
35 \r
36 namespace SlimDX\r
37 {\r
38 namespace Direct3D10\r
39 {\r
40         Font::Font( Device^ device, FontDescription description )\r
41         {\r
42                 Construct( Build( device, description.Height, description.Width, description.Weight, description.MipLevels, description.IsItalic, description.CharacterSet, description.Precision, description.Quality, description.PitchAndFamily, description.FaceName ) );\r
43         }\r
44 \r
45         Font::Font( Device^ device, int height, String^ faceName )\r
46         {\r
47                 Construct( Build( device, height, 0, FontWeight::Normal, 1, false, FontCharacterSet::Default, FontPrecision::Default, FontQuality::Default, FontPitchAndFamily::Default, faceName ) );\r
48         }\r
49 \r
50         Font::Font( Device^ device, int height, int width, FontWeight weight, int mipLevels, bool isItalic, FontCharacterSet characterSet, FontPrecision precision, FontQuality quality, FontPitchAndFamily pitchAndFamily, String^ faceName )\r
51         {\r
52                 Construct( Build( device, height, width, weight, mipLevels, isItalic, characterSet, precision, quality, pitchAndFamily, faceName ) );\r
53         }\r
54 \r
55         ID3DX10Font* Font::Build( Device^ device, int height, int width, FontWeight weight, int mipLevels, bool isItalic, FontCharacterSet characterSet, FontPrecision precision, FontQuality quality, FontPitchAndFamily pitchAndFamily, String^ faceName )\r
56         {\r
57                 ID3DX10Font* font = 0;\r
58                 pin_ptr<const wchar_t> pinned_name = PtrToStringChars( faceName ); \r
59                 if( RECORD_D3D10( D3DX10CreateFont( device->InternalPointer, height, width, static_cast<UINT>( weight ), mipLevels, isItalic, static_cast<UINT>( characterSet ), static_cast<UINT>( precision ), static_cast< UINT>( quality ), static_cast<UINT>( pitchAndFamily ), pinned_name, &font ) ).IsFailure )\r
60                         throw gcnew Direct3D10Exception( Result::Last );\r
61 \r
62                 return font;\r
63         }\r
64         \r
65         FontDescription Font::Description::get()\r
66         {\r
67                 D3DX10_FONT_DESC nativeDescription;\r
68                 if( RECORD_D3D10( InternalPointer->GetDesc( &nativeDescription ) ).IsFailure )\r
69                         return FontDescription();\r
70                         \r
71                 return FontDescription( nativeDescription );\r
72         }\r
73 \r
74         int Font::Draw( Sprite^ sprite, String^ text, Drawing::Rectangle rect, FontDrawFlags flags, Color4 color )\r
75         {\r
76                 ID3DX10Sprite* nativeSprite = sprite == nullptr ? 0 : sprite->InternalPointer;\r
77                 pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );\r
78                 RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };\r
79 \r
80                 int result = InternalPointer->DrawTextW( nativeSprite, pinned_text, text->Length, &nativeRect,\r
81                         static_cast<DWORD>( flags ), color.ToUnmanaged() );\r
82                 \r
83                 return result;\r
84         }\r
85 \r
86         Drawing::Rectangle Font::Measure( Sprite^ sprite, String^ text, Drawing::Rectangle rect, FontDrawFlags flags )\r
87         {\r
88                 ID3DX10Sprite* nativeSprite = sprite == nullptr ? 0 : sprite->InternalPointer;\r
89                 pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );\r
90                 RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };\r
91                 InternalPointer->DrawTextW( nativeSprite, pinned_text, text->Length, &nativeRect, static_cast<DWORD>( flags ) | DT_CALCRECT, 0xFFFFFFFF );\r
92                 \r
93                 return Drawing::Rectangle( nativeRect.left, nativeRect.top, nativeRect.right - nativeRect.left, nativeRect.bottom - nativeRect.top );\r
94         }\r
95 \r
96         Result Font::PreloadCharacters( int first, int last )\r
97         {\r
98                 return RECORD_D3D10( InternalPointer->PreloadCharacters( first, last ) );\r
99         }\r
100 \r
101         Result Font::PreloadGlyphs( int first, int last )\r
102         {\r
103                 return RECORD_D3D10( InternalPointer->PreloadGlyphs( first, last ) );\r
104         }\r
105 \r
106         Result Font::PreloadText( String^ text )\r
107         {\r
108                 pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );\r
109                 return RECORD_D3D10( InternalPointer->PreloadText( pinned_text, text->Length ) );\r
110         }\r
111 }\r
112 }\r