From 89ca01014689852dd04bd5e50f969de3426dd999 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 18 Nov 2021 22:22:11 +0100 Subject: [PATCH] Add scale setup callback infrastructure. --- profiler/src/main.cpp | 19 ++++++++++++------- server/TracyView.cpp | 6 ++++-- server/TracyView.hpp | 8 +++++--- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index d075e2e6..ceaed73b 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -191,6 +191,11 @@ static void SetupDPIScale( float scale, ImFont*& fixedWidth, ImFont*& bigFont, I style.ScaleAllSizes( scale ); } +static void SetupScaleCallback( float scale, ImFont*& fixedWidth, ImFont*& bigFont, ImFont*& smallFont ) +{ + SetupDPIScale( scale * dpiScale, fixedWidth, bigFont, smallFont ); +} + int main( int argc, char** argv ) { sprintf( title, "Tracy Profiler %i.%i.%i", tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch ); @@ -354,7 +359,7 @@ int main( int argc, char** argv ) auto f = std::unique_ptr( tracy::FileRead::Open( argv[1] ) ); if( f ) { - view = std::make_unique( RunOnMainThread, *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); + view = std::make_unique( RunOnMainThread, *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } } else @@ -380,7 +385,7 @@ int main( int argc, char** argv ) } if( connectTo ) { - view = std::make_unique( RunOnMainThread, connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); + view = std::make_unique( RunOnMainThread, connectTo, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } glfwShowWindow( window ); @@ -747,11 +752,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 ); + view = std::make_unique( RunOnMainThread, addrPart.c_str(), portPart, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } else { - view = std::make_unique( RunOnMainThread, addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); + view = std::make_unique( RunOnMainThread, addr, port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } } ImGui::SameLine( 0, ImGui::GetFontSize() * 2 ); @@ -771,7 +776,7 @@ static void DrawContents() loadThread = std::thread( [f] { try { - view = std::make_unique( RunOnMainThread, *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative ); + view = std::make_unique( RunOnMainThread, *f, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } catch( const tracy::UnsupportedVersion& e ) { @@ -894,7 +899,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 ); + view = std::make_unique( RunOnMainThread, v.second.address.c_str(), v.second.port, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } ImGui::NextColumn(); const auto acttime = ( v.second.activeTime + ( time - v.second.time ) / 1000 ) * 1000000000ll; @@ -1063,7 +1068,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 ); + view = std::make_unique( RunOnMainThread, reconnectAddr.c_str(), reconnectPort, fixedWidth, smallFont, bigFont, SetWindowTitleCallback, GetMainWindowNative, SetupScaleCallback ); } break; default: diff --git a/server/TracyView.cpp b/server/TracyView.cpp index e4aa791d..633e5f09 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -134,7 +134,7 @@ enum { MinFrameSize = 5 }; static View* s_instance = nullptr; -View::View( void(*cbMainThread)(std::function), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb ) +View::View( void(*cbMainThread)(std::function), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb, SetScaleCallback sscb ) : m_worker( addr, port ) , m_staticView( false ) , m_viewMode( ViewMode::LastFrames ) @@ -149,6 +149,7 @@ View::View( void(*cbMainThread)(std::function), const char* addr, uint16 , m_fixedFont( fixedWidth ) , m_stcb( stcb ) , m_gwcb( gwcb ) + , m_sscb( sscb ) , m_userData() , m_cbMainThread( cbMainThread ) { @@ -159,7 +160,7 @@ View::View( void(*cbMainThread)(std::function), const char* addr, uint16 InitTextEditor( fixedWidth ); } -View::View( void(*cbMainThread)(std::function), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb ) +View::View( void(*cbMainThread)(std::function), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, GetWindowCallback gwcb, SetScaleCallback sscb ) : m_worker( f ) , m_filename( f.GetFilename() ) , m_staticView( true ) @@ -171,6 +172,7 @@ View::View( void(*cbMainThread)(std::function), FileRead& f, ImFont* fix , m_fixedFont( fixedWidth ) , m_stcb( stcb ) , m_gwcb( gwcb ) + , m_sscb( sscb ) , m_userData( m_worker.GetCaptureProgram().c_str(), m_worker.GetCaptureTime() ) , m_cbMainThread( cbMainThread ) { diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 5b8b3fb6..f4b02af7 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -90,10 +90,11 @@ public: using SetTitleCallback = void(*)( const char* ); using GetWindowCallback = void*(*)(); + using SetScaleCallback = void(*)( float, ImFont*&, ImFont*&, ImFont*& ); - View( void(*cbMainThread)(std::function), ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr ) : View( cbMainThread, "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb, gwcb ) {} - View( void(*cbMainThread)(std::function), const char* addr, uint16_t port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr ); - View( void(*cbMainThread)(std::function), FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr ); + View( void(*cbMainThread)(std::function), ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr ) : View( cbMainThread, "127.0.0.1", 8086, fixedWidth, smallFont, bigFont, stcb, gwcb, sscb ) {} + View( void(*cbMainThread)(std::function), const char* addr, uint16_t port, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr ); + View( void(*cbMainThread)(std::function), FileRead& f, ImFont* fixedWidth = nullptr, ImFont* smallFont = nullptr, ImFont* bigFont = nullptr, SetTitleCallback stcb = nullptr, GetWindowCallback gwcb = nullptr, SetScaleCallback sscb = nullptr ); ~View(); static bool Draw(); @@ -479,6 +480,7 @@ private: SetTitleCallback m_stcb; bool m_titleSet = false; GetWindowCallback m_gwcb; + SetScaleCallback m_sscb; float m_notificationTime = 0; std::string m_notificationText;