diff --git a/profiler/build/win32/Tracy.vcxproj b/profiler/build/win32/Tracy.vcxproj index 574567d5..fe713213 100644 --- a/profiler/build/win32/Tracy.vcxproj +++ b/profiler/build/win32/Tracy.vcxproj @@ -195,6 +195,7 @@ + @@ -311,6 +312,7 @@ + diff --git a/profiler/build/win32/Tracy.vcxproj.filters b/profiler/build/win32/Tracy.vcxproj.filters index 99039d6f..e256df08 100644 --- a/profiler/build/win32/Tracy.vcxproj.filters +++ b/profiler/build/win32/Tracy.vcxproj.filters @@ -333,6 +333,9 @@ src\imgui + + src + @@ -677,6 +680,9 @@ src\imgui + + src + diff --git a/profiler/src/Fonts.cpp b/profiler/src/Fonts.cpp new file mode 100644 index 00000000..7f802ca6 --- /dev/null +++ b/profiler/src/Fonts.cpp @@ -0,0 +1,50 @@ +#include +#include + +#include "Fonts.hpp" +#include "misc/freetype/imgui_freetype.h" +#include "imgui/imgui_impl_opengl3.h" +#include "../../server/IconsFontAwesome5.h" + +#include "font/DroidSans.hpp" +#include "font/FiraCodeRetina.hpp" +#include "font/FontAwesomeSolid.hpp" + +ImFont* s_bigFont; +ImFont* s_smallFont; +ImFont* s_fixedWidth; + +void LoadFonts( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont ) +{ + static const ImWchar rangesBasic[] = { + 0x0020, 0x00FF, // Basic Latin + Latin Supplement + 0x03BC, 0x03BC, // micro + 0x03C3, 0x03C3, // small sigma + 0x2013, 0x2013, // en dash + 0x2264, 0x2264, // less-than or equal to + 0, + }; + static const ImWchar rangesIcons[] = { + ICON_MIN_FA, ICON_MAX_FA, + 0 + }; + + ImGuiIO& io = ImGui::GetIO(); + + ImFontConfig configBasic; + configBasic.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting; + ImFontConfig configMerge; + configMerge.MergeMode = true; + configMerge.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting; + + io.Fonts->Clear(); + io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 15.0f * scale ), &configBasic, rangesBasic ); + io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 14.0f * scale ), &configMerge, rangesIcons ); + s_fixedWidth = cb_fixedWidth = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FiraCodeRetina_compressed_data, tracy::FiraCodeRetina_compressed_size, round( 15.0f * scale ), &configBasic ); + s_bigFont = cb_bigFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 21.0f * scale ), &configBasic ); + io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 20.0f * scale ), &configMerge, rangesIcons ); + s_smallFont = cb_smallFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 10.0f * scale ), &configBasic ); + + ImGui_ImplOpenGL3_DestroyFontsTexture(); + ImGui_ImplOpenGL3_CreateFontsTexture(); +} diff --git a/profiler/src/Fonts.hpp b/profiler/src/Fonts.hpp new file mode 100644 index 00000000..0603ef97 --- /dev/null +++ b/profiler/src/Fonts.hpp @@ -0,0 +1,12 @@ +#ifndef __FONTS_HPP__ +#define __FONTS_HPP__ + +struct ImFont; + +extern ImFont* s_bigFont; +extern ImFont* s_smallFont; +extern ImFont* s_fixedWidth; + +void LoadFonts( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont ); + +#endif diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 0493986d..de2a955a 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -48,14 +48,11 @@ #include "../../server/TracyVersion.hpp" #include "../../server/IconsFontAwesome5.h" -#include "misc/freetype/imgui_freetype.h" -#include "font/DroidSans.hpp" -#include "font/FiraCodeRetina.hpp" -#include "font/FontAwesomeSolid.hpp" #include "icon.hpp" -#include "ResolvService.hpp" -#include "NativeWindow.hpp" +#include "Fonts.hpp" #include "HttpRequest.hpp" +#include "NativeWindow.hpp" +#include "ResolvService.hpp" static void glfw_error_callback(int error, const char* description) { @@ -114,9 +111,6 @@ static std::unique_ptr broadcastListen; static std::mutex resolvLock; static tracy::unordered_flat_map resolvMap; static ResolvService resolv( port ); -static ImFont* bigFont; -static ImFont* smallFont; -static ImFont* fixedWidth; static char addr[1024] = { "127.0.0.1" }; static std::unordered_map connHistMap; static std::vector::const_iterator> connHistVec; @@ -144,41 +138,6 @@ void RunOnMainThread( std::function cb, bool forceDelay = false ) } } -static void LoadFonts( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont ) -{ - static const ImWchar rangesBasic[] = { - 0x0020, 0x00FF, // Basic Latin + Latin Supplement - 0x03BC, 0x03BC, // micro - 0x03C3, 0x03C3, // small sigma - 0x2013, 0x2013, // en dash - 0x2264, 0x2264, // less-than or equal to - 0, - }; - static const ImWchar rangesIcons[] = { - ICON_MIN_FA, ICON_MAX_FA, - 0 - }; - - ImGuiIO& io = ImGui::GetIO(); - - ImFontConfig configBasic; - configBasic.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting; - ImFontConfig configMerge; - configMerge.MergeMode = true; - configMerge.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_LightHinting; - - io.Fonts->Clear(); - io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 15.0f * scale ), &configBasic, rangesBasic ); - io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 14.0f * scale ), &configMerge, rangesIcons ); - fixedWidth = cb_fixedWidth = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FiraCodeRetina_compressed_data, tracy::FiraCodeRetina_compressed_size, round( 15.0f * scale ), &configBasic ); - bigFont = cb_bigFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 21.0f * scale ), &configBasic ); - io.Fonts->AddFontFromMemoryCompressedTTF( tracy::FontAwesomeSolid_compressed_data, tracy::FontAwesomeSolid_compressed_size, round( 20.0f * scale ), &configMerge, rangesIcons ); - smallFont = cb_smallFont = io.Fonts->AddFontFromMemoryCompressedTTF( tracy::DroidSans_compressed_data, tracy::DroidSans_compressed_size, round( 10.0f * scale ), &configBasic ); - - ImGui_ImplOpenGL3_DestroyFontsTexture(); - ImGui_ImplOpenGL3_CreateFontsTexture(); -} - static void SetupDPIScale( float scale, ImFont*& cb_fixedWidth, ImFont*& cb_bigFont, ImFont*& cb_smallFont ) { LoadFonts( scale, cb_fixedWidth, cb_bigFont, cb_smallFont ); @@ -399,16 +358,16 @@ int main( int argc, char** argv ) ImGui_ImplGlfw_InitForOpenGL( window, true ); ImGui_ImplOpenGL3_Init( "#version 150" ); - SetupDPIScale( dpiScale, fixedWidth, bigFont, smallFont ); + SetupDPIScale( dpiScale, s_fixedWidth, s_bigFont, s_smallFont ); if( initFileOpen ) { - view = std::make_unique( RunOnMainThread, *initFileOpen, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); + view = std::make_unique( RunOnMainThread, *initFileOpen, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); initFileOpen.reset(); } else if( connectTo ) { - view = std::make_unique( RunOnMainThread, connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); + view = std::make_unique( RunOnMainThread, connectTo, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } #ifndef TRACY_NO_FILESELECTOR @@ -631,7 +590,7 @@ static void DrawContents() ImGui::Begin( "Get started", nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse ); char buf[128]; sprintf( buf, "Tracy Profiler %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch ); - ImGui::PushFont( bigFont ); + ImGui::PushFont( s_bigFont ); tracy::TextCentered( buf ); ImGui::PopFont(); ImGui::SameLine( ImGui::GetWindowContentRegionMax().x - ImGui::CalcTextSize( ICON_FA_WRENCH ).x - ImGui::GetStyle().FramePadding.x * 2 ); @@ -642,7 +601,7 @@ static void DrawContents() bool keepOpenAbout = true; if( ImGui::BeginPopupModal( "About Tracy", &keepOpenAbout, ImGuiWindowFlags_AlwaysAutoResize ) ) { - ImGui::PushFont( bigFont ); + ImGui::PushFont( s_bigFont ); tracy::TextCentered( buf ); ImGui::PopFont(); ImGui::Spacing(); @@ -788,11 +747,11 @@ static void DrawContents() { std::string addrPart = std::string( addr, ptr ); uint16_t portPart = (uint16_t)atoi( ptr+1 ); - view = std::make_unique( RunOnMainThread, addrPart.c_str(), portPart, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); + view = std::make_unique( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } else { - view = std::make_unique( RunOnMainThread, addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); + view = std::make_unique( RunOnMainThread, addr, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } } ImGui::SameLine( 0, ImGui::GetTextLineHeight() * 2 ); @@ -813,7 +772,7 @@ static void DrawContents() loadThread = std::thread( [f] { try { - view = std::make_unique( RunOnMainThread, *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); + view = std::make_unique( RunOnMainThread, *f, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } catch( const tracy::UnsupportedVersion& e ) { @@ -843,7 +802,7 @@ static void DrawContents() if( badVer.state != tracy::BadVersionState::Ok ) { if( loadThread.joinable() ) { loadThread.join(); } - tracy::BadVersion( badVer, bigFont ); + tracy::BadVersion( badVer, s_bigFont ); } #endif @@ -946,7 +905,7 @@ static void DrawContents() } if( selected && !loadThread.joinable() ) { - view = std::make_unique( RunOnMainThread, v.second.address.c_str(), v.second.port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); + view = std::make_unique( RunOnMainThread, v.second.address.c_str(), v.second.port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } ImGui::NextColumn(); const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll; @@ -997,7 +956,7 @@ static void DrawContents() } else { - ImGui::PushFont( fixedWidth ); + ImGui::PushFont( s_fixedWidth ); ImGui::TextUnformatted( releaseNotes.c_str() ); ImGui::PopFont(); } @@ -1038,7 +997,7 @@ static void DrawContents() } if( ImGui::BeginPopupModal( "Loading trace...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) { - ImGui::PushFont( bigFont ); + ImGui::PushFont( s_bigFont ); tracy::TextCentered( ICON_FA_HOURGLASS_HALF ); ImGui::PopFont(); @@ -1115,7 +1074,7 @@ static void DrawContents() viewShutdown.store( ViewShutdown::False, std::memory_order_relaxed ); if( reconnect ) { - view = std::make_unique( RunOnMainThread, reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); + view = std::make_unique( RunOnMainThread, reconnectAddr.c_str(), reconnectPort, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } break; default: @@ -1124,7 +1083,7 @@ static void DrawContents() if( ImGui::BeginPopupModal( "Capture cleanup...", nullptr, ImGuiWindowFlags_AlwaysAutoResize ) ) { if( viewShutdown.load( std::memory_order_relaxed ) != ViewShutdown::True ) ImGui::CloseCurrentPopup(); - ImGui::PushFont( bigFont ); + ImGui::PushFont( s_bigFont ); tracy::TextCentered( ICON_FA_BROOM ); ImGui::PopFont(); animTime += ImGui::GetIO().DeltaTime;