mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 07:54:36 +00:00
Extract window position save/load functionality.
This commit is contained in:
parent
208755ad53
commit
31b6a88923
@ -203,6 +203,7 @@
|
|||||||
<ClCompile Include="..\..\src\NativeWindow.cpp" />
|
<ClCompile Include="..\..\src\NativeWindow.cpp" />
|
||||||
<ClCompile Include="..\..\src\ResolvService.cpp" />
|
<ClCompile Include="..\..\src\ResolvService.cpp" />
|
||||||
<ClCompile Include="..\..\src\RunQueue.cpp" />
|
<ClCompile Include="..\..\src\RunQueue.cpp" />
|
||||||
|
<ClCompile Include="..\..\src\WindowPosition.cpp" />
|
||||||
<ClCompile Include="..\..\src\winmain.cpp">
|
<ClCompile Include="..\..\src\winmain.cpp">
|
||||||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotSet</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotSet</EnableEnhancedInstructionSet>
|
||||||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotSet</EnableEnhancedInstructionSet>
|
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">NotSet</EnableEnhancedInstructionSet>
|
||||||
@ -326,6 +327,7 @@
|
|||||||
<ClInclude Include="..\..\src\ResolvService.hpp" />
|
<ClInclude Include="..\..\src\ResolvService.hpp" />
|
||||||
<ClInclude Include="..\..\src\RunQueue.hpp" />
|
<ClInclude Include="..\..\src\RunQueue.hpp" />
|
||||||
<ClInclude Include="..\..\src\stb_image.h" />
|
<ClInclude Include="..\..\src\stb_image.h" />
|
||||||
|
<ClInclude Include="..\..\src\WindowPosition.hpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Natvis Include="DebugVis.natvis" />
|
<Natvis Include="DebugVis.natvis" />
|
||||||
|
@ -339,6 +339,9 @@
|
|||||||
<ClCompile Include="..\..\src\RunQueue.cpp">
|
<ClCompile Include="..\..\src\RunQueue.cpp">
|
||||||
<Filter>src</Filter>
|
<Filter>src</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\WindowPosition.cpp">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\server\TracyEvent.hpp">
|
<ClInclude Include="..\..\..\server\TracyEvent.hpp">
|
||||||
@ -689,6 +692,9 @@
|
|||||||
<ClInclude Include="..\..\src\RunQueue.hpp">
|
<ClInclude Include="..\..\src\RunQueue.hpp">
|
||||||
<Filter>src</Filter>
|
<Filter>src</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\WindowPosition.hpp">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Natvis Include="DebugVis.natvis" />
|
<Natvis Include="DebugVis.natvis" />
|
||||||
|
48
profiler/src/WindowPosition.cpp
Normal file
48
profiler/src/WindowPosition.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "WindowPosition.hpp"
|
||||||
|
|
||||||
|
#include "../../server/TracyStorage.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
WindowPosition::WindowPosition()
|
||||||
|
: m_fn( tracy::GetSavePath( "window.position" ) )
|
||||||
|
{
|
||||||
|
Defaults();
|
||||||
|
|
||||||
|
FILE* f = fopen( m_fn.c_str(), "rb" );
|
||||||
|
if( f )
|
||||||
|
{
|
||||||
|
uint32_t data[5];
|
||||||
|
if( fread( data, 1, sizeof( data ), f ) == sizeof( data ) )
|
||||||
|
{
|
||||||
|
x = data[0];
|
||||||
|
y = data[1];
|
||||||
|
w = data[2];
|
||||||
|
h = data[3];
|
||||||
|
maximize = data[4];
|
||||||
|
}
|
||||||
|
fclose( f );
|
||||||
|
|
||||||
|
if( w <= 0 || h <= 0 ) Defaults();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowPosition::~WindowPosition()
|
||||||
|
{
|
||||||
|
FILE* f = fopen( m_fn.c_str(), "wb" );
|
||||||
|
if( !f ) return;
|
||||||
|
uint32_t data[5] = { uint32_t( x ), uint32_t( y ), uint32_t( w ), uint32_t( h ), uint32_t( maximize ) };
|
||||||
|
fwrite( data, 1, sizeof( data ), f );
|
||||||
|
fclose( f );
|
||||||
|
}
|
||||||
|
|
||||||
|
void WindowPosition::Defaults()
|
||||||
|
{
|
||||||
|
x = 200;
|
||||||
|
y = 200;
|
||||||
|
w = 1650;
|
||||||
|
h = 960;
|
||||||
|
maximize = 0;
|
||||||
|
}
|
20
profiler/src/WindowPosition.hpp
Normal file
20
profiler/src/WindowPosition.hpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef __WINDOWPOSITION_HPP__
|
||||||
|
#define __WINDOWPOSITION_HPP__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class WindowPosition
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowPosition();
|
||||||
|
~WindowPosition();
|
||||||
|
|
||||||
|
int x, y, w, h, maximize;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Defaults();
|
||||||
|
|
||||||
|
std::string m_fn;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -54,6 +54,8 @@
|
|||||||
#include "NativeWindow.hpp"
|
#include "NativeWindow.hpp"
|
||||||
#include "ResolvService.hpp"
|
#include "ResolvService.hpp"
|
||||||
#include "RunQueue.hpp"
|
#include "RunQueue.hpp"
|
||||||
|
#include "WindowPosition.hpp"
|
||||||
|
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description)
|
static void glfw_error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
@ -197,30 +199,7 @@ int main( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string winPosFile = tracy::GetSavePath( "window.position" );
|
WindowPosition winPos;
|
||||||
int x = 200, y = 200, w = 1650, h = 960, maximize = 0;
|
|
||||||
{
|
|
||||||
FILE* f = fopen( winPosFile.c_str(), "rb" );
|
|
||||||
if( f )
|
|
||||||
{
|
|
||||||
uint32_t data[5];
|
|
||||||
fread( data, 1, sizeof( data ), f );
|
|
||||||
fclose( f );
|
|
||||||
x = data[0];
|
|
||||||
y = data[1];
|
|
||||||
w = data[2];
|
|
||||||
h = data[3];
|
|
||||||
maximize = data[4];
|
|
||||||
}
|
|
||||||
if( w <= 0 || h <= 0 )
|
|
||||||
{
|
|
||||||
x = 200;
|
|
||||||
y = 200;
|
|
||||||
w = 1650;
|
|
||||||
h = 960;
|
|
||||||
maximize = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string connHistFile = tracy::GetSavePath( "connection.history" );
|
std::string connHistFile = tracy::GetSavePath( "connection.history" );
|
||||||
{
|
{
|
||||||
@ -291,7 +270,7 @@ int main( int argc, char** argv )
|
|||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
|
||||||
#endif
|
#endif
|
||||||
GLFWwindow* window = glfwCreateWindow( w, h, title, NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow( winPos.w, winPos.h, title, NULL, NULL);
|
||||||
if( !window ) return 1;
|
if( !window ) return 1;
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -301,9 +280,9 @@ int main( int argc, char** argv )
|
|||||||
free( icon.pixels );
|
free( icon.pixels );
|
||||||
}
|
}
|
||||||
|
|
||||||
glfwSetWindowPos( window, x, y );
|
glfwSetWindowPos( window, winPos.x, winPos.y );
|
||||||
#ifdef GLFW_MAXIMIZED
|
#ifdef GLFW_MAXIMIZED
|
||||||
if( maximize ) glfwMaximizeWindow( window );
|
if( winPos.maximize ) glfwMaximizeWindow( window );
|
||||||
#endif
|
#endif
|
||||||
s_glfwWindow = window;
|
s_glfwWindow = window;
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
@ -387,25 +366,16 @@ int main( int argc, char** argv )
|
|||||||
if( updateNotesThread.joinable() ) updateNotesThread.join();
|
if( updateNotesThread.joinable() ) updateNotesThread.join();
|
||||||
view.reset();
|
view.reset();
|
||||||
|
|
||||||
{
|
|
||||||
FILE* f = fopen( winPosFile.c_str(), "wb" );
|
|
||||||
if( f )
|
|
||||||
{
|
|
||||||
#ifdef GLFW_MAXIMIZED
|
#ifdef GLFW_MAXIMIZED
|
||||||
uint32_t maximized = glfwGetWindowAttrib( window, GLFW_MAXIMIZED );
|
uint32_t maximized = glfwGetWindowAttrib( window, GLFW_MAXIMIZED );
|
||||||
if( maximized ) glfwRestoreWindow( window );
|
if( maximized ) glfwRestoreWindow( window );
|
||||||
#else
|
#else
|
||||||
uint32_t maximized = 0;
|
uint32_t maximized = 0;
|
||||||
#endif
|
#endif
|
||||||
|
winPos.maximize = maximized;
|
||||||
|
|
||||||
glfwGetWindowPos( window, &x, &y );
|
glfwGetWindowPos( window, &winPos.x, &winPos.y );
|
||||||
glfwGetWindowSize( window, &w, &h );
|
glfwGetWindowSize( window, &winPos.w, &winPos.h );
|
||||||
|
|
||||||
uint32_t data[5] = { uint32_t( x ), uint32_t( y ), uint32_t( w ), uint32_t( h ), maximized };
|
|
||||||
fwrite( data, 1, sizeof( data ), f );
|
|
||||||
fclose( f );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
Loading…
Reference in New Issue
Block a user