+++ /dev/null
-#include "stdafx.h"\r
-/*\r
-* Copyright (c) 2007-2010 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-\r
-#include <windows.h>\r
-#include <d3d9.h>\r
-#include <d3dx9.h>\r
-\r
-#include "../ComObject.h"\r
-#include "../Utilities.h"\r
-\r
-#include "Device.h"\r
-#include "Sprite9.h"\r
-#include "Font9.h"\r
-#include "Direct3D9Exception.h"\r
-\r
-#include <vcclr.h>\r
-\r
-using namespace System;\r
-using namespace System::Drawing;\r
-\r
-namespace SlimDX\r
-{\r
-namespace Direct3D9\r
-{\r
- Font::Font( Device^ device, int height, int width, FontWeight weight, int mipLevels, bool italic,\r
- CharacterSet charSet, Precision outputPrecision, FontQuality quality,\r
- PitchAndFamily pitchAndFamily, String^ faceName )\r
- {\r
- Build( device, height, width, weight, mipLevels, italic, charSet, outputPrecision, quality,\r
- pitchAndFamily, faceName );\r
- }\r
-\r
- Font::Font( Device^ device, System::Drawing::Font^ font )\r
- {\r
- Build( device, font->Height, 0, (font->Bold) ? FontWeight::Bold : FontWeight::Normal, 0, font->Italic, \r
- CharacterSet::Default, Precision::Default, FontQuality::Default, PitchAndFamily::Default, font->Name );\r
- }\r
-\r
- void Font::Build( Device^ device, int height, int width, FontWeight weight, int mipLevels, bool italic,\r
- CharacterSet charSet, Precision outputPrecision, FontQuality quality,\r
- PitchAndFamily pitchAndFamily, String^ faceName )\r
- {\r
- ID3DXFont* font;\r
- pin_ptr<const wchar_t> pinned_name = PtrToStringChars( faceName );\r
-\r
- HRESULT hr = D3DXCreateFont( device->InternalPointer, height, width, static_cast<UINT>( weight ), mipLevels, italic, static_cast<DWORD>( charSet ),\r
- static_cast<DWORD>( outputPrecision ), static_cast<DWORD>( quality ), static_cast<DWORD>( pitchAndFamily ), reinterpret_cast<LPCWSTR>( pinned_name ), &font );\r
-\r
- if( RECORD_D3D9( hr ).IsFailure )\r
- throw gcnew Direct3D9Exception( Result::Last );\r
-\r
- Construct(font);\r
- }\r
-\r
- int Font::DrawString( Sprite^ sprite, String^ text, System::Drawing::Rectangle rect, DrawTextFormat format, Color4 color )\r
- {\r
- return DrawString( sprite, text, rect, format, color.ToArgb() );\r
- }\r
-\r
- int Font::DrawString( Sprite^ sprite, String^ text, System::Drawing::Rectangle rect, DrawTextFormat format, int color )\r
- {\r
- ID3DXSprite* spritePtr = sprite != nullptr ? sprite->InternalPointer : NULL;\r
- pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );\r
- RECT nativeRect = { rect.Left, rect.Top, rect.Right, rect.Bottom };\r
-\r
- return InternalPointer->DrawTextW( spritePtr, reinterpret_cast<LPCWSTR>( pinned_text ), text->Length, &nativeRect, static_cast<DWORD>( format ), color );\r
- }\r
-\r
- int Font::DrawString( Sprite^ sprite, String^ text, int x, int y, Color4 color )\r
- {\r
- System::Drawing::Rectangle rect( x, y, 0, 0 );\r
- return DrawString( sprite, text, rect, DrawTextFormat::NoClip, color );\r
- }\r
-\r
- int Font::DrawString( Sprite^ sprite, String^ text, int x, int y, int color )\r
- {\r
- System::Drawing::Rectangle rect( x, y, 0, 0 );\r
- return DrawString( sprite, text, rect, DrawTextFormat::NoClip, color );\r
- }\r
-\r
- System::Drawing::Rectangle Font::MeasureString( Sprite^ sprite, String^ text, DrawTextFormat format )\r
- {\r
- System::Drawing::Rectangle rect;\r
- MeasureString( sprite, text, format, rect );\r
- return rect;\r
- }\r
-\r
- int Font::MeasureString( Sprite^ sprite, System::String^ text, DrawTextFormat format,\r
- System::Drawing::Rectangle% rectangle )\r
- {\r
- ID3DXSprite* spritePtr = sprite != nullptr ? sprite->InternalPointer : NULL;\r
- pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );\r
- RECT nativeRect = {rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom};\r
-\r
- int result = InternalPointer->DrawTextW( spritePtr, reinterpret_cast<LPCWSTR>( pinned_text ), text->Length, &nativeRect, \r
- static_cast<DWORD>(format) | DT_CALCRECT, 0 );\r
- \r
- rectangle = System::Drawing::Rectangle( nativeRect.left, nativeRect.top, \r
- nativeRect.right - nativeRect.left, nativeRect.bottom - nativeRect.top );\r
- return result;\r
- }\r
-\r
- Result Font::PreloadCharacters( int first, int last )\r
- {\r
- HRESULT hr = InternalPointer->PreloadCharacters( first, last );\r
- return RECORD_D3D9( hr );\r
- }\r
-\r
- Result Font::PreloadGlyphs( int first, int last )\r
- {\r
- HRESULT hr = InternalPointer->PreloadGlyphs( first, last );\r
- return RECORD_D3D9( hr );\r
- }\r
-\r
- Result Font::PreloadText( String^ text )\r
- {\r
- pin_ptr<const wchar_t> pinned_text = PtrToStringChars( text );\r
- HRESULT hr = InternalPointer->PreloadTextW( reinterpret_cast<LPCWSTR>( pinned_text ), text->Length );\r
- return RECORD_D3D9( hr );\r
- }\r
-\r
- Result Font::OnLostDevice()\r
- {\r
- HRESULT hr = InternalPointer->OnLostDevice();\r
- return RECORD_D3D9( hr );\r
- }\r
-\r
- Result Font::OnResetDevice()\r
- {\r
- HRESULT hr = InternalPointer->OnResetDevice();\r
- return RECORD_D3D9( hr );\r
- }\r
-\r
- FontDescription Font::Description::get()\r
- {\r
- D3DXFONT_DESC description;\r
- \r
- HRESULT hr = InternalPointer->GetDesc( &description );\r
- if( RECORD_D3D9( hr ).IsFailure )\r
- return FontDescription();\r
-\r
- FontDescription outDesc;\r
- outDesc.Height = description.Height;\r
- outDesc.Width = description.Width;\r
- outDesc.Weight = static_cast<FontWeight>( description.Weight );\r
- outDesc.MipLevels = description.MipLevels;\r
- outDesc.Italic = description.Italic > 0;\r
- outDesc.CharSet = static_cast<CharacterSet>( description.CharSet );\r
- outDesc.OutputPrecision = static_cast<Precision>( description.OutputPrecision );\r
- outDesc.Quality = static_cast<FontQuality>( description.Quality );\r
- outDesc.PitchAndFamily = static_cast<PitchAndFamily>( description.PitchAndFamily );\r
- outDesc.FaceName = gcnew String( description.FaceName );\r
-\r
- return outDesc;\r
- }\r
-\r
- IntPtr Font::DeviceContext::get()\r
- {\r
- return static_cast<IntPtr>( InternalPointer->GetDC() );\r
- }\r
-}\r
-}\r