-------------------------------------------------------------------------------------- Description: Draws text into current render target. Arguments: font - Font to use string - NULL-terminated string to render rect - Rectangle to use in the render target format - Bitfield of TRI_DFS_... constants color - Color to use for rendering (alpha component is ignored) -------------------------------------
| 144 | // color - Color to use for rendering (alpha component is ignored) |
| 145 | // -------------------------------------------------------------------------------------- |
| 146 | void TriDebugTextRenderer::DrawText( Tr2RenderContext& renderContext, TriDebugFont font, const char* string, const Tr2Rect& rect, uint32_t format, const Vector4& vecColor ) |
| 147 | { |
| 148 | uint32_t color = Color( vecColor.x, vecColor.y, vecColor.z, vecColor.w ); |
| 149 | |
| 150 | if( !Tr2Renderer::IsResourceCreationAllowed() ) |
| 151 | { |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | #ifdef WIN32 |
| 156 | if( !m_dc ) |
| 157 | { |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | // Measure actual text size |
| 162 | HGDIOBJ oldFont = SelectObject( m_dc, m_dcFonts[font] ); |
| 163 | ON_BLOCK_EXIT( [&] { SelectObject( m_dc, oldFont ); } ); |
| 164 | RECT realRect = { rect.left, rect.top, rect.right, rect.bottom }; |
| 165 | ::DrawText( m_dc, string, -1, &realRect, format | DT_CALCRECT ); |
| 166 | RECT size = realRect; |
| 167 | OffsetRect( &size, -size.left, -size.top ); |
| 168 | unsigned width = size.right; |
| 169 | unsigned height = size.bottom; |
| 170 | if( width == 0 || height == 0 ) |
| 171 | { |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | if( width > m_bitmapWidth || height > m_bitmapHeight ) |
| 176 | { |
| 177 | DeleteObject( m_bitmap ); |
| 178 | m_bitmapData = nullptr; |
| 179 | m_bitmapWidth = max( width, m_bitmapWidth ); |
| 180 | m_bitmapHeight = max( height, m_bitmapHeight ); |
| 181 | HDC screenDC = GetDC( NULL ); |
| 182 | |
| 183 | BITMAPINFO info; |
| 184 | memset( &info, 0, sizeof( info ) ); |
| 185 | info.bmiHeader.biSize = sizeof( info ); |
| 186 | info.bmiHeader.biWidth = m_bitmapWidth; |
| 187 | info.bmiHeader.biHeight = -int( m_bitmapHeight ); |
| 188 | info.bmiHeader.biPlanes = 1; |
| 189 | info.bmiHeader.biBitCount = 32; |
| 190 | info.bmiHeader.biCompression = BI_RGB; |
| 191 | info.bmiHeader.biSizeImage = 0; |
| 192 | info.bmiHeader.biXPelsPerMeter = 0; |
| 193 | info.bmiHeader.biYPelsPerMeter = 0; |
| 194 | info.bmiHeader.biClrUsed = 0; |
| 195 | info.bmiHeader.biClrImportant = 0; |
| 196 | |
| 197 | m_bitmap = CreateDIBSection( screenDC, &info, DIB_RGB_COLORS, (void**)&m_bitmapData, nullptr, 0 ); |
| 198 | if( !m_bitmapData ) |
| 199 | { |
| 200 | DeleteObject( m_bitmap ); |
| 201 | m_bitmapWidth = 0; |
| 202 | m_bitmapHeight = 0; |
| 203 | m_bitmap = nullptr; |
nothing calls this directly
no test coverage detected