Capture ImGui mouse state.

This commit is contained in:
Bartosz Taudul 2020-08-01 12:02:11 +02:00
parent 39197b9ff8
commit 6836014caa
3 changed files with 33 additions and 4 deletions

View File

@ -36,6 +36,7 @@
#include "../../server/TracyBadVersion.hpp" #include "../../server/TracyBadVersion.hpp"
#include "../../server/TracyFileRead.hpp" #include "../../server/TracyFileRead.hpp"
#include "../../server/TracyImGui.hpp" #include "../../server/TracyImGui.hpp"
#include "../../server/TracyMouse.hpp"
#include "../../server/TracyPrint.hpp" #include "../../server/TracyPrint.hpp"
#include "../../server/TracyStorage.hpp" #include "../../server/TracyStorage.hpp"
#include "../../server/TracyView.hpp" #include "../../server/TracyView.hpp"
@ -434,6 +435,7 @@ static void DrawContents()
ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame(); ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame(); ImGui::NewFrame();
tracy::MouseFrame();
if( !view ) if( !view )
{ {

View File

@ -1,26 +1,51 @@
#include "TracyMouse.hpp" #include "TracyMouse.hpp"
#include "../imgui/imgui_internal.h"
namespace tracy namespace tracy
{ {
static constexpr int MouseButtons = IM_ARRAYSIZE( ImGuiContext::IO.MouseDown );
struct Mouse
{
bool mouseDown[MouseButtons];
bool mouseClicked[MouseButtons];
bool mouseDragging[MouseButtons];
ImVec2 mouseDragDelta[MouseButtons];
};
static Mouse s_mouse;
void MouseFrame()
{
for( int i=0; i<MouseButtons; i++ )
{
s_mouse.mouseDown[i] = ImGui::IsMouseDown( i );
s_mouse.mouseClicked[i] = ImGui::IsMouseClicked( i );
s_mouse.mouseDragging[i] = ImGui::IsMouseDragging( i, 0 );
s_mouse.mouseDragDelta[i] = ImGui::GetMouseDragDelta( i, 0 );
}
}
bool IsMouseDown( ImGuiMouseButton button ) bool IsMouseDown( ImGuiMouseButton button )
{ {
return ImGui::IsMouseDown( button ); return s_mouse.mouseDown[button];
} }
bool IsMouseClicked( ImGuiMouseButton button ) bool IsMouseClicked( ImGuiMouseButton button )
{ {
return ImGui::IsMouseClicked( button ); return s_mouse.mouseClicked[button];
} }
bool IsMouseDragging( ImGuiMouseButton button, float lock_threshold ) bool IsMouseDragging( ImGuiMouseButton button, float lock_threshold )
{ {
return ImGui::IsMouseDragging( button, lock_threshold ); return s_mouse.mouseDragging[button];
} }
ImVec2 GetMouseDragDelta( ImGuiMouseButton button, float lock_threshold ) ImVec2 GetMouseDragDelta( ImGuiMouseButton button, float lock_threshold )
{ {
return ImGui::GetMouseDragDelta( button, lock_threshold ); return s_mouse.mouseDragDelta[button];
} }
} }

View File

@ -6,6 +6,8 @@
namespace tracy namespace tracy
{ {
void MouseFrame();
bool IsMouseDown( ImGuiMouseButton button ); bool IsMouseDown( ImGuiMouseButton button );
bool IsMouseClicked( ImGuiMouseButton button ); bool IsMouseClicked( ImGuiMouseButton button );
bool IsMouseDragging( ImGuiMouseButton button, float lock_threshold = -1.f ); bool IsMouseDragging( ImGuiMouseButton button, float lock_threshold = -1.f );