Gwen::Point DirectX9::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString & text ) { // If the font doesn't exist, or the font size should be changed if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 ) { FreeFont( pFont ); LoadFont( pFont ); } FontData* pFontData = ( FontData* ) pFont->data; Gwen::Point size; if ( text.empty() ) { RECT rct = {0, 0, 0, 0}; pFontData->pFont->DrawTextW( NULL, L"W", -1, &rct, DT_CALCRECT, 0 ); return Gwen::Point( 0, rct.bottom ); } RECT rct = {0, 0, 0, 0}; pFontData->pFont->DrawTextW( NULL, text.c_str(), -1, &rct, DT_CALCRECT | DT_LEFT | DT_TOP | DT_SINGLELINE, 0 ); for ( int i = text.length() - 1; i >= 0 && text[i] == L' '; i-- ) { rct.right += pFontData->iSpaceWidth; } return Gwen::Point( rct.right / Scale(), rct.bottom / Scale() ); }
Gwen::Point Chowdren::MeasureText( Gwen::Font* pFont, const Gwen::UnicodeString & text ) { FTSimpleLayout layout; layout.SetLineLength(10000); layout.SetFont(get_font(pFont->size)); FTBBox bbox = layout.BBox(text.c_str()); FTPoint size = bbox.Upper() - bbox.Lower(); return Gwen::Point((int)ceil(size.X()), (int)ceil(size.Y())); }
float dumpRecursive(CProfileIterator* profileIterator, Gwen::Controls::TreeNode* parentNode) { profileIterator->First(); if (profileIterator->Is_Done()) return 0.f; float accumulated_time=0,parent_time = profileIterator->Is_Root() ? CProfileManager::Get_Time_Since_Reset() : profileIterator->Get_Current_Parent_Total_Time(); int i; int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset(); //printf("Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->Get_Current_Parent_Name(), parent_time ); float totalTime = 0.f; int numChildren = 0; Gwen::UnicodeString txt; std::vector<Gwen::Controls::TreeNode*> nodes; for (i = 0; !profileIterator->Is_Done(); i++,profileIterator->Next()) { numChildren++; float current_total_time = profileIterator->Get_Current_Total_Time(); accumulated_time += current_total_time; double fraction = parent_time > SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f; Gwen::String name(profileIterator->Get_Current_Name()); Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name); txt = Gwen::Utility::Format(L"%s (%.2f %%) :: %.3f ms / frame (%d calls)",uname.c_str(), fraction,(current_total_time / (double)frames_since_reset),profileIterator->Get_Current_Total_Calls()); Gwen::Controls::TreeNode* childNode = (Gwen::Controls::TreeNode*)profileIterator->Get_Current_UserPointer(); if (!childNode) { childNode = parentNode->AddNode(L""); profileIterator->Set_Current_UserPointer(childNode); } childNode->SetText(txt); nodes.push_back(childNode); totalTime += current_total_time; //recurse into children } for (i=0;i<numChildren;i++) { profileIterator->Enter_Child(i); Gwen::Controls::TreeNode* curNode = nodes[i]; dumpRecursive(profileIterator, curNode); profileIterator->Enter_Parent(); } return accumulated_time; }
void DirectX9::RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString & text ) { Flush(); // If the font doesn't exist, or the font size should be changed if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 ) { FreeFont( pFont ); LoadFont( pFont ); } FontData* pFontData = ( FontData* ) pFont->data; Translate( pos.x, pos.y ); RECT ClipRect = { pos.x, pos.y, 0, 0 }; pFontData->pFont->DrawTextW( NULL, text.c_str(), -1, &ClipRect, DT_LEFT | DT_TOP | DT_NOCLIP | DT_SINGLELINE, m_Color ); }
void Chowdren::RenderText( Gwen::Font* pFont, Gwen::Point pos, const Gwen::UnicodeString & text ) { if (!init_font()) return; FTTextureFont* font = get_font(pFont->size); if (font) { Translate(pos.x, pos.y); FTTextureFont::color = m_Color; FTSimpleLayout layout; layout.SetLineLength(10000); layout.SetFont(font); layout.Render(text.c_str(), -1, FTPoint(pos.x, pos.y + font->Ascender())); } }
void GDIPlus::RenderText( gwen::Font* pFont, gwen::Point pos, const gwen::UnicodeString & text ) { Translate( pos.x, pos.y ); // If the font doesn't exist, or the font size should be changed if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 ) { FreeFont( pFont ); LoadFont( pFont ); } Gdiplus::StringFormat strFormat( Gdiplus::StringFormat::GenericDefault() ); Gdiplus::SolidBrush solidBrush( m_Colour ); Gdiplus::RectF r( pos.x, pos.y, 1000, 1000 ); Gdiplus::Font* pGDIFont = ( Gdiplus::Font* ) pFont->data; graphics->DrawString( text.c_str(), text.length() + 1, pGDIFont, r, &strFormat, &solidBrush ); }
gwen::Point GDIPlus::MeasureText( gwen::Font* pFont, const gwen::UnicodeString & text ) { gwen::Point p( 1, 1 ); if ( !pFont->data || fabs( pFont->realsize - pFont->size * Scale() ) > 2 ) { FreeFont( pFont ); LoadFont( pFont ); } Gdiplus::StringFormat strFormat( Gdiplus::StringFormat::GenericDefault() ); strFormat.SetFormatFlags( Gdiplus::StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); Gdiplus::SizeF size; Gdiplus::Graphics g( m_HWND ); Gdiplus::Font* pGDIFont = ( Gdiplus::Font* ) pFont->data; g.MeasureString( text.c_str(), -1, pGDIFont, Gdiplus::SizeF( 10000, 10000 ), &strFormat, &size ); return gwen::Point( size.Width + 1, size.Height + 1 ); }
bool Gwen::Platform::SetClipboardText( const Gwen::UnicodeString& str ) { if ( !OpenClipboard( NULL ) ) return false; EmptyClipboard(); // Create a buffer to hold the string size_t iDataSize = (str.length()+1) * sizeof(wchar_t); HGLOBAL clipbuffer = GlobalAlloc( GMEM_DDESHARE, iDataSize ); // Copy the string into the buffer wchar_t* buffer = (wchar_t*) GlobalLock( clipbuffer ); wcscpy( buffer, str.c_str() ); GlobalUnlock(clipbuffer); // Place it on the clipboard SetClipboardData( CF_UNICODETEXT, clipbuffer ); CloseClipboard(); return true; }
void UpdateText(CProfileIterator* profileIterator, bool idle) { static bool update=true; m_ctrl->SetBounds(0,0,this->GetInnerBounds().w,this->GetInnerBounds().h); // if (!update) // return; update=false; static int test = 1; test++; static double time_since_reset = 0.f; if (!idle) { time_since_reset = CProfileManager::Get_Time_Since_Reset(); } //Gwen::UnicodeString txt = Gwen::Utility::Format( L"FEM Settings %i fps", test ); { //recompute profiling data, and store profile strings char blockTime[128]; double totalTime = 0; int frames_since_reset = CProfileManager::Get_Frame_Count_Since_Reset(); profileIterator->First(); double parent_time = profileIterator->Is_Root() ? time_since_reset : profileIterator->Get_Current_Parent_Total_Time(); Gwen::Controls::TreeNode* curParent = m_node; double accumulated_time = dumpRecursive(profileIterator,m_node); const char* name = profileIterator->Get_Current_Parent_Name(); #ifdef _WIN32 Gwen::UnicodeString uname = Gwen::Utility::StringToUnicode(name); Gwen::UnicodeString txt = Gwen::Utility::Format( L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", uname.c_str(), parent_time , parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time); #else Gwen::UnicodeString txt = Gwen::Utility::Format( L"Profiling: %s total time: %.3f ms, unaccounted %.3f %% :: %.3f ms", name, parent_time , parent_time > SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time); #endif //sprintf(blockTime,"--- Profiling: %s (total running time: %.3f ms) ---", profileIterator->Get_Current_Parent_Name(), parent_time ); //displayProfileString(xOffset,yStart,blockTime); m_node->SetText(txt); //printf("%s (%.3f %%) :: %.3f ms\n", "Unaccounted:",); } static int counter=10; if (counter) { counter--; m_ctrl->ExpandAll(); } }