// Updates the text to be displayed. void SampleFpsTextRenderer::Update(DX::StepTimer const& timer) { // Update display text. uint32 fps = timer.GetFramesPerSecond(); m_text = (fps > 0) ? std::to_wstring(fps) + L" FPS" : L" - FPS"; ComPtr<IDWriteTextLayout> textLayout; DX::ThrowIfFailed( m_deviceResources->GetDWriteFactory()->CreateTextLayout( m_text.c_str(), (uint32) m_text.length(), m_textFormat.Get(), 240.0f, // Max width of the input text. 50.0f, // Max height of the input text. &textLayout ) ); DX::ThrowIfFailed( textLayout.As(&m_textLayout) ); DX::ThrowIfFailed( m_textLayout->GetMetrics(&m_textMetrics) ); }
// 更新要显示的文本。 void SampleFpsTextRenderer::Update(DX::StepTimer const& timer) { // 更新显示文本。 uint32 fps = timer.GetFramesPerSecond(); m_text = (fps > 0) ? std::to_wstring(fps) + L" FPS" : L" - FPS"; DX::ThrowIfFailed( m_deviceResources->GetDWriteFactory()->CreateTextLayout( m_text.c_str(), (uint32) m_text.length(), m_textFormat.Get(), 240.0f, // 输入文本的最大宽度。 50.0f, // 输入文本的最大高度。 &m_textLayout ) ); DX::ThrowIfFailed( m_textLayout->GetMetrics(&m_textMetrics) ); }