BtBool BtStrCompare( const BtChar* pString1, const BtChar* pString2 ) { BtU32 maxString = MtMax( BtStrLength( pString1 ), BtStrLength( pString2 ) ); if( BtMemory::Compare( (void*)pString1, (void*)pString2, maxString ) == BtTrue ) { return BtTrue; } return BtFalse; }
// virtual MtVector2 RsFontWin32GL::GetDimension( const BtChar* szText ) { MtVector2 v2LastPosition = MtVector2( 0, 0 ); // Set the start position MtVector2 v2Position = MtVector2( 0, 0 ); // Cache the string length BtU32 length = BtStrLength(szText); // Loop through the string for( BtU32 nCharacterIndex=0; nCharacterIndex<length; nCharacterIndex++ ) { // Cache each character BtUChar Character = szText[nCharacterIndex]; if( Character == '\n' ) { // Cache the font character LBaFontChar& fontChar = m_pFileData->m_characters['A']; v2Position.x = 0; v2Position.y += fontChar.m_fHeight * 1.50f; continue; } // Cache the font character LBaFontChar& fontChar = m_pFileData->m_characters[Character]; // Set the dimension from the width and height of the texture MtVector2 v2Dimension = MtVector2( fontChar.m_fWidth, fontChar.m_fHeight ); // Increment the last position v2LastPosition.x = MtMax( v2LastPosition.x, v2Position.x + v2Dimension.x ); v2LastPosition.y = MtMax( v2LastPosition.y, v2Position.y + v2Dimension.y ); // Increment the position v2Position.x += fontChar.m_nXAdvance; } MtVector2 v2Dimension = v2LastPosition; return v2Dimension; }
void HlDebug::Render() { if( !ApConfig::IsDebug() ) { return; } BtU32 numItems = m_items.GetNumItems(); MtVector2 v2Position( 0, 0 ); MtVector2 v2Dimension( 0, 0 ); for( BtU32 i=0; i<numItems; i++ ) { HlItem &item = m_items[i]; if( !IsHidden(item) ) { RsColour textColour = RsColour::WhiteColour(); if( item.m_isReadOnly ) { textColour = RsColour( 0.7f, 0.7f, 0.7f, 1.0f ); } BtChar text[2048]; sprintf( text, "" ); for(BtU32 j = 0; j < GetNumParents(&item) * 4; j++) { sprintf( text + strlen(text), " "); } if(item.m_type == HlDebugEnum ) { BtU32 current = *item.m_pEnum; sprintf( text + strlen(text), "%s ", item.m_name ); BtU32 index = 0; BtChar *pStr = item.m_pEnumString; while( pStr ) { BtChar temp[32]; BtStrCopy( temp, 32, pStr, BtStrLength( pStr ) ); BtChar *eol = BtStrStr(temp, ";"); if( eol ) { *eol = 0; pStr = BtStrStr(pStr, ";") + 1; } else { pStr = 0; } if(current == index) { sprintf(text + strlen(text), "%s", temp); } ++index; } } else if(item.m_type == HlDebugSave ) { sprintf(text + strlen(text), "Save"); } else if( item.m_type == HlDebugNode ) { sprintf( text + strlen(text), "%s", item.m_name); if( item.m_isCollapsed ) { sprintf( text + strlen(text), "+" ); } else { sprintf(text + strlen(text), "-" ); } } else if( item.m_type == HlDebugFloat ) { BtFloat value = *item.m_pFloat; // Do the conversion if( item.m_unitsSystem == HLDebugKnots ) { value = MtMetersPerSecondToKnots( value ); sprintf(text + strlen(text), "%s %.2fKnts", item.m_name, value); } else { sprintf( text + strlen(text), "%s %.2f", item.m_name, value ); } } else if( item.m_type == HlDebugInteger ) { sprintf( text + strlen(text), "%s %d", item.m_name, *item.m_pInteger ); } else if(item.m_type == HlDebugBool ) { if( *item.m_pBool ) { sprintf(text + strlen(text), "%s True", item.m_name ); } else { sprintf(text + strlen(text), "%s False", item.m_name ); } } else if( item.m_type == HlDebugVector ) { sprintf(text + strlen(text), "%s %.2f %.2f %.2f", item.m_name, item.m_pVector->x, item.m_pVector->y, item.m_pVector->z ); } else if( item.m_type == HlDebugColour ) { sprintf(text + strlen(text), "%s %.2f %.2f %.2f", item.m_name, item.m_pColour->Red(), item.m_pColour->Green(), item.m_pColour->Blue() ); } else if( item.m_type == HlDebugFPS ) { sprintf( text + strlen(text), "FPS %.2f", RsUtil::GetFPS() ); } if( DebugIndex == i ) { sprintf( text + strlen(text), "*" ); } MtVector2 v2FontDimension = HlFont::GetDimension( text ); v2Dimension.x = MtMax( v2Dimension.x, v2Position.x + v2FontDimension.x + 15.0f ); v2Dimension.y = MtMax( v2Dimension.y, v2Position.y + v2FontDimension.y + 15.0f ); HlFont::Render(v2Position, text, textColour, MaxSortOrders - 1); v2Position.y += 15.0f; } } // Display the list of archives BtLinkedList<BaArchiveNode> archives = BaArchive::GetArchives(); BaArchiveNode *pCurrent = archives.pHead(); while( pCurrent ) { BtChar text[2048]; sprintf(text, pCurrent->m_pArchive->GetFilename()); MtVector2 v2FontDimension = HlFont::GetDimension(text); v2Dimension.x = MtMax(v2Dimension.x, v2Position.x + v2FontDimension.x + 30.0f); v2Dimension.y = MtMax(v2Dimension.y, v2Position.y + v2FontDimension.y + 30.0f); HlFont::Render(v2Position, text, RsColour(0.7f, 0.7f, 0.7f, 1.0f), MaxSortOrders - 1); v2Position.y += 15.0f; pCurrent = pCurrent->pNext(); } HlDraw::RenderQuad( MtVector2( 0, 0 ), v2Dimension, RsColour( 0.1f, 0.1f, 0.1f, 1.0f ), MaxSortOrders-1 ); }
// virtual MtVector2 RsFontWin32GL::Render( const MtVector2& v2StartPosition, const MtVector2& v2Scale, const RsColour &colour, const BtChar* szText, BtU32 sortOrder ) { const BtU32 MaxFontLength = 256; MtVector2 v2LastPosition = MtVector2( 0, 0 ); // Cache the impl RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance(); // Cache the render target RsRenderTarget *pRenderTarget = RsRenderTarget::GetCurrent(); // Cache the camera RsCamera camera = pRenderTarget->GetCamera(); // Cache the display width and height BtFloat Width = (BtFloat)camera.GetViewport().m_width; BtFloat Height = (BtFloat)camera.GetViewport().m_height; // Cache the display width and height BtFloat fScaleWidth = 1.0f / Width; BtFloat fScaleHeight = 1.0f / Height; // Allocate vertex RsVertex3 *pStartVertex = pImpl->StartVertex(); // Set the start vertex RsVertex3 *pVertex = pStartVertex; // Cache the texture RsTextureWinGL* pTexture = (RsTextureWinGL*) m_pTextures[ 0 ]; // Set the start position MtVector2 v2Position = v2StartPosition; // Cache the string length BtU32 length = strlen(szText); // Cache the texture width and height BtFloat TextureWidth = 1.0f / (BtFloat) pTexture->GetWidth(); BtFloat TextureHeight = 1.0f / (BtFloat) pTexture->GetHeight(); BtU32 currentVertex = 0; // Loop through the string for( BtU32 nCharacterIndex=0; nCharacterIndex<length; nCharacterIndex++ ) { // Cache each character BtUChar Character = szText[nCharacterIndex]; if( Character == '\n' ) { // Cache the font character LBaFontChar& fontChar = m_pFileData->m_characters['A']; v2Position.x = v2StartPosition.x; v2Position.y += fontChar.m_fHeight * 1.50f * v2Scale.y; continue; } // Cache the font character LBaFontChar& fontChar = m_pFileData->m_characters[Character]; // Set the dimension from the width and height of the texture MtVector2 v2Dimension = MtVector2( fontChar.m_fWidth, fontChar.m_fHeight ); // Calculate the positions BtFloat fX0 = v2Position.x; BtFloat fX1 = fX0 + ( v2Dimension.x * v2Scale.x ); BtFloat fY0 = v2Position.y + ( fontChar.m_nYOffset * v2Scale.y ); BtFloat fY1 = fY0 + ( v2Dimension.y * v2Scale.y ); RsVertex3 *pQuad = pVertex; // Copy these into vertex pVertex->m_v3Position = MtVector3(fX0, fY0, 0.1f ); pVertex->m_v2UV = MtVector2( fontChar.m_U0 , fontChar.m_V0 ); ++pVertex; pVertex->m_v3Position = MtVector3(fX0, fY1, 0.1f ); pVertex->m_v2UV = MtVector2( fontChar.m_U0, fontChar.m_V1 + 1 ); ++pVertex; pVertex->m_v3Position = MtVector3(fX1, fY0, 0.1f ); pVertex->m_v2UV = MtVector2( fontChar.m_U1 + 1, fontChar.m_V0 ); ++pVertex; pVertex->m_v3Position = MtVector3(fX0, fY1, 0.1f ); pVertex->m_v2UV = MtVector2( fontChar.m_U0 , fontChar.m_V1 + 1 ); ++pVertex; pVertex->m_v3Position = MtVector3(fX1, fY1, 0.1f ); pVertex->m_v2UV = MtVector2( fontChar.m_U1 + 1, fontChar.m_V1 + 1 ); ++pVertex; pVertex->m_v3Position = MtVector3(fX1, fY0, 0.1f ); pVertex->m_v2UV = MtVector2( fontChar.m_U1 + 1, fontChar.m_V0 ); ++pVertex; // Scale the position to local screen space -1 to 1 for( BtU32 i=0; i<6; i++ ) { // Set the colour pQuad[ i ].m_colour = colour.asWord(); // Scale the uvs pQuad[ i ].m_v2UV.x *= TextureWidth; pQuad[ i ].m_v2UV.y *= TextureHeight; // Flip the y pQuad[ i ].m_v3Position.y = Height - pQuad[ i ].m_v3Position.y; pQuad[ i ].m_v3Position.x -= 0.5f; pQuad[ i ].m_v3Position.y -= 0.5f; // Scale from 0..width to 0..1 pQuad[ i ].m_v3Position.x *= fScaleWidth; pQuad[ i ].m_v3Position.y *= fScaleHeight; // Scale from 0..1 to 0..2 pQuad[ i ].m_v3Position.x *= 2.0f; pQuad[ i ].m_v3Position.y *= 2.0f; // Translate from 0..2 to -1..1 pQuad[ i ].m_v3Position.x -= 1.0f; pQuad[ i ].m_v3Position.y -= 1.0f; } // Render the 6 new vertex // Increment the last position v2LastPosition.x = MtMax( v2LastPosition.x, v2Position.x + v2Dimension.x ); v2LastPosition.y = MtMax( v2LastPosition.y, v2Position.y + v2Dimension.y ); // Increment the position v2Position.x += ( fontChar.m_nXAdvance * v2Scale.x ); currentVertex += 6; } // Setup the primitive RsPrimitiveWinGL *pPrimitive = pImpl->AddPrimitive(); pPrimitive->m_primitiveType = GL_TRIANGLES; pPrimitive->m_numVertex = currentVertex; pPrimitive->m_nStartVertex = pImpl->GetCurrentVertex(); // End the current vertex pImpl->EndVertex( currentVertex ); // Make a new font renderable RsFontRenderable *pFontRenderable = pImpl->AddFont(); pFontRenderable->m_pFont = this; pFontRenderable->m_pVertex = pStartVertex; pFontRenderable->m_primitive = pPrimitive; // Validate the shader BtAssert( pFontRenderable->m_pShader != BtNull ); // Add the font to the renderable list RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent(); pCurrentRenderTarget->Add( sortOrder, pFontRenderable ); // Calculate the dimension MtVector2 v2Dimension = v2LastPosition - v2StartPosition; // Return the dimension return v2Dimension; }
// virtual void RsFlashWinGL::Render( const MtVector2& v2StartPosition, BtU32 sortOrder ) { MtVector2 v2Dimension( 0, 0 ); RsTexture *pTexture = BtNull; cJSON *pFames = cJSON_GetObjectItem( m_pJSON, "frames" ); cJSON *pCommands = cJSON_GetArrayItem( pFames, m_currentFrame ); if( pCommands == BtNull ) { m_currentFrameTime = 0; m_currentFrame = 0; pCommands = cJSON_GetArrayItem( pFames, m_currentFrame ); } RsColour colour( 1.0f, 1.0f, 1.0f, 1.0f ); BtU32 numCommands = cJSON_GetArraySize( pCommands ); for( BtU32 command=0; command<numCommands; command=command + 2 ) { // Cache the command cJSON *pCommand = cJSON_GetArrayItem( pCommands, command ); BtChar *pCommandString = pCommand->valuestring; // Cache the object cJSON *pObject = cJSON_GetArrayItem( pCommands, command + 1 ); if( BtStrCompare( pCommandString, "frameInfo" ) ) { cJSON *pFrameIndex = cJSON_GetObjectItem( pObject, "frameIndex" ); BtU32 frameIndex = pFrameIndex->valueint; (void)frameIndex; int a=0; a++; } else if( BtStrCompare( pCommandString, "texture" ) ) { cJSON *pTextureIndex = cJSON_GetObjectItem( pObject, "textureIndex" ); // Get the texture index BtU32 textureIndex = pTextureIndex->valueint - 1; pTexture = m_pFileData->m_pTextures[textureIndex]; colour = RsColour( 1.0f, 1.0f, 1.0f, 1.0f ); } else if( BtStrCompare( pCommandString, "colour" ) ) { // Get the colour object cJSON *pColour = cJSON_GetObjectItem( pObject, "colourArray" ); cJSON *pR = cJSON_GetArrayItem( pColour, 0 ); BtFloat r = (BtFloat)pR->valuedouble; cJSON *pG = cJSON_GetArrayItem( pColour, 1 ); BtFloat g = (BtFloat)pG->valuedouble; cJSON *pB = cJSON_GetArrayItem( pColour, 2 ); BtFloat b = (BtFloat) pB->valuedouble; colour = RsColour( r, g, b, 1.0f ); } else if( BtStrCompare( pCommandString, "vertex" ) ) { // Get the vertex object cJSON *pVertex = cJSON_GetObjectItem( pObject, "vertex" ); // Cache the number of vertex BtU32 numVertex = cJSON_GetArraySize( pVertex ); // Extract the vertex MtVector2 coords[4]; for( BtU32 vertexIndex=0; vertexIndex<numVertex; vertexIndex++ ) { // Cache each set of coordinates cJSON *pCoordinates = cJSON_GetArrayItem( pVertex, vertexIndex ); cJSON *pX = cJSON_GetObjectItem( pCoordinates, "positionx" ); cJSON *pY = cJSON_GetObjectItem( pCoordinates, "positiony" ); coords[vertexIndex].x = (BtFloat)pX->valueint / 20; coords[vertexIndex].y = (BtFloat)pY->valueint / 20; } { // Cache the impl RsImplWinGL *pImpl = (RsImplWinGL*)RsImpl::pInstance(); // Cache the render target RsRenderTarget *pRenderTarget = RsRenderTarget::GetCurrent(); // Cache the camera RsCamera camera = pRenderTarget->GetCamera(); // Cache the display width and height BtFloat Width = (BtFloat)camera.GetViewport().m_width; BtFloat Height = (BtFloat)camera.GetViewport().m_height; // Cache the display width and height BtFloat textureWidth = (BtFloat)pTexture->GetWidth(); BtFloat textureHeight = (BtFloat)pTexture->GetHeight(); // Cache the display width and height BtFloat fScaleWidth = 1.0f / Width; BtFloat fScaleHeight = 1.0f / Height; // Allocate vertex RsVertex3 *pStartVertex = pImpl->StartVertex(); // Set the start vertex RsVertex3 *pVertex = pStartVertex; RsVertex3 *pQuad = pVertex; BtFloat minU = 1.0f / textureWidth; BtFloat minV = 1.0f / textureHeight; BtFloat maxU = 1.0f - minU; BtFloat maxV = 1.0f - minV; /* coords[0].y = Height - coords[0].y; coords[1].y = Height - coords[1].y; coords[2].y = Height - coords[2].y; coords[3].y = Height - coords[3].y; */ // Copy these into vertex pVertex->m_v3Position = MtVector3(coords[0].x, coords[0].y, 0.1f ); pVertex->m_v2UV = MtVector2( minU, minV ); ++pVertex; pVertex->m_v3Position = MtVector3(coords[1].x, coords[1].y, 0.1f ); pVertex->m_v2UV = MtVector2( maxU, minV ); ++pVertex; pVertex->m_v3Position = MtVector3(coords[2].x, coords[2].y, 0.1f ); pVertex->m_v2UV = MtVector2( minU, maxV ); ++pVertex; pVertex->m_v3Position = MtVector3(coords[3].x, coords[3].y, 0.1f ); pVertex->m_v2UV = MtVector2( maxU, maxV ); ++pVertex; v2Dimension.x = MtMax( v2Dimension.x, coords[1].x - coords[0].x ); v2Dimension.y = MtMax( v2Dimension.y, coords[2].y - coords[0].y ); // Scale the position to local screen space -1 to 1 for( BtU32 i=0; i<4; i++ ) { // Set the colour pQuad[ i ].m_colour = colour.asARGB(); // Use the start position pQuad[ i ].m_v3Position.x += v2StartPosition.x; pQuad[ i ].m_v3Position.y += v2StartPosition.y; // Flip the y pQuad[ i ].m_v3Position.y = Height - pQuad[ i ].m_v3Position.y; pQuad[ i ].m_v3Position.x -= 0.5f; pQuad[ i ].m_v3Position.y -= 0.5f; // Scale from 0..width to 0..1 pQuad[ i ].m_v3Position.x *= fScaleWidth; pQuad[ i ].m_v3Position.y *= fScaleHeight; // Scale from 0..1 to 0..2 pQuad[ i ].m_v3Position.x *= 2.0f; pQuad[ i ].m_v3Position.y *= 2.0f; // Translate from 0..2 to -1..1 pQuad[ i ].m_v3Position.x -= 1.0f; pQuad[ i ].m_v3Position.y -= 1.0f; } // Setup the primitive RsPrimitiveWinGL *primitive = pImpl->AddPrimitive(); primitive->m_primitiveType = GL_TRIANGLE_STRIP; primitive->m_numVertex = 4; primitive->m_nStartVertex = pImpl->GetCurrentVertex(); // End the current vertex pImpl->EndVertex( 4 ); // Make a new font renderable RsTextureRenderable *pTextureRenderable = pImpl->AddTexture(); pTextureRenderable->m_pTexture = (RsTextureWinGL*)pTexture; pTextureRenderable->m_pVertex = pStartVertex; pTextureRenderable->m_primitive = primitive; // Validate the shader BtAssert( pTextureRenderable->m_pShader != BtNull ); // Add the font to the renderable list RsRenderTargetWinGL *pCurrentRenderTarget = (RsRenderTargetWinGL*)RsRenderTarget::GetCurrent(); pCurrentRenderTarget->Add( sortOrder, pTextureRenderable ); } } } (void)v2Dimension; int a=0; a++; }