Skip to content

Commit

Permalink
style
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Jul 23, 2024
1 parent 43a25a1 commit 7a82374
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 27 deletions.
13 changes: 3 additions & 10 deletions library/src/interactor_impl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include "camera.h"

#include "imgui_impl_vtk.h"

namespace f3d::detail
{
class interactor_impl::internals
Expand All @@ -51,16 +53,7 @@ class interactor_impl::internals
// in order to be able to interact while animating
this->VTKInteractor->RemoveObservers(vtkCommand::TimerEvent);

vtkNew<vtkCallbackCommand> renderCallback;
renderCallback->SetClientData(this->Window.GetRenderWindow());
renderCallback->SetCallback(
[](vtkObject*, unsigned long, void* clientData, void* callData)
{
vtkRenderWindow* renWin = static_cast<vtkRenderWindow*>(clientData);
// calling Frame() here instead of Render() refresh only the UI
renWin->Frame();
});
this->VTKInteractor->AddObserver(vtkCommand::MouseMoveEvent, renderCallback);
ImGui_ImplVTK_AddObservers(this->VTKInteractor);

vtkNew<vtkCallbackCommand> keyPressCallback;
keyPressCallback->SetClientData(this);
Expand Down
Binary file added resources/Inter-Regular.ttf
Binary file not shown.
58 changes: 58 additions & 0 deletions vtkext/private/module/imgui_impl_vtk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <vtkOpenGLVertexArrayObject.h>
#include <vtkShader.h>
#include <vtkShaderProgram.h>
#include <vtkCallbackCommand.h>
#include <vtkRenderWindowInteractor.h>
#include <vtk_glew.h>

#include "vtkF3DImguiFS.h"
Expand Down Expand Up @@ -216,6 +218,62 @@ void ImGui_ImplVTK_NewFrame()
io.DisplaySize = ImVec2((float)size[0], (float)size[1]);
}

void ImGui_ImplVTK_AddObservers(vtkRenderWindowInteractor* interactor)
{
vtkNew<vtkCallbackCommand> mouseMoveCB;
mouseMoveCB->SetClientData(interactor);
mouseMoveCB->PassiveObserverOn();
mouseMoveCB->SetCallback(
[](vtkObject*, unsigned long, void* clientData, void* callData)
{
vtkRenderWindowInteractor* that = static_cast<vtkRenderWindowInteractor*>(clientData);

int sz[2];
int p[2];
that->GetEventPosition(p);
that->GetSize(sz);
ImGuiIO& io = ImGui::GetIO();
std::cout << p[0] << " " << p[1] << std::endl;
io.AddMousePosEvent(static_cast<float>(p[0]), static_cast<float>(sz[1] - p[1] - 1));

// calling Frame() here instead of Render() refresh only the UI
that->GetRenderWindow()->Frame();
});
interactor->AddObserver(vtkCommand::MouseMoveEvent, mouseMoveCB);

vtkNew<vtkCallbackCommand> mouseleftpressCB;
mouseleftpressCB->SetClientData(interactor);
mouseleftpressCB->PassiveObserverOn();
mouseleftpressCB->SetCallback(
[](vtkObject*, unsigned long, void* clientData, void* callData)
{
vtkRenderWindowInteractor* that = static_cast<vtkRenderWindowInteractor*>(clientData);

ImGuiIO& io = ImGui::GetIO();
io.AddMouseButtonEvent(ImGuiMouseButton_Left, true);

// calling Frame() here instead of Render() refresh only the UI
that->GetRenderWindow()->Frame();
});
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, mouseleftpressCB);

vtkNew<vtkCallbackCommand> mouseleftreleaseCB;
mouseleftreleaseCB->SetClientData(interactor);
mouseleftreleaseCB->PassiveObserverOn();
mouseleftreleaseCB->SetCallback(
[](vtkObject*, unsigned long, void* clientData, void* callData)
{
vtkRenderWindowInteractor* that = static_cast<vtkRenderWindowInteractor*>(clientData);

ImGuiIO& io = ImGui::GetIO();
io.AddMouseButtonEvent(ImGuiMouseButton_Left, false);

// calling Frame() here instead of Render() refresh only the UI
that->GetRenderWindow()->Frame();
});
interactor->AddObserver(vtkCommand::LeftButtonReleaseEvent, mouseleftreleaseCB, 1.f);
}

//-----------------------------------------------------------------------------

#endif // #ifndef IMGUI_DISABLE
3 changes: 3 additions & 0 deletions vtkext/private/module/imgui_impl_vtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
#ifndef IMGUI_DISABLE

class vtkOpenGLRenderWindow;
class vtkRenderWindowInteractor;

IMGUI_IMPL_API bool ImGui_ImplVTK_Init(vtkOpenGLRenderWindow* renWin);
IMGUI_IMPL_API void ImGui_ImplVTK_Shutdown();
IMGUI_IMPL_API void ImGui_ImplVTK_NewFrame();
IMGUI_IMPL_API void ImGui_ImplVTK_RenderDrawData(ImDrawData* draw_data);

IMGUI_IMPL_API void ImGui_ImplVTK_AddObservers(vtkRenderWindowInteractor* renWin);

#endif // #ifndef IMGUI_DISABLE
79 changes: 62 additions & 17 deletions vtkext/private/module/vtkF3DUIRenderWindow.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "vtkF3DUIRenderWindow.h"

#include "vtkF3DRenderer.h"
#include "vtkRendererCollection.h"

#include <vtkObjectFactory.h>

#include "imgui.h"
Expand Down Expand Up @@ -39,6 +42,16 @@ void vtkF3DUIRenderWindow::OpenGLInitContext()
ImGuiIO& io = ImGui::GetIO();
IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");

io.Fonts->Clear();
io.Fonts->AddFontFromFileTTF("/home/michael/dev/f3d/resources/Inter-Regular.ttf", 16);
io.Fonts->Build();

ImGuiStyle* style = &ImGui::GetStyle();
style->GrabRounding = 4.0f;
style->WindowRounding = 8.f;
style->WindowBorderSize = 0.f;
style->WindowPadding = ImVec2(10, 10);

// Setup backend capabilities flags
io.BackendPlatformUserData = nullptr;
io.BackendPlatformName = io.BackendRendererName = "imgui_impl_vtk";
Expand All @@ -52,8 +65,6 @@ void vtkF3DUIRenderWindow::OpenGLInitContext()

void vtkF3DUIRenderWindow::BlitDisplayFramebuffersToHardware()
{
std::cout << "blit!\n";

this->Superclass::BlitDisplayFramebuffersToHardware();

ImGuiIO& io = ImGui::GetIO();
Expand All @@ -66,21 +77,55 @@ void vtkF3DUIRenderWindow::BlitDisplayFramebuffersToHardware()
#endif
ImGui::NewFrame();

ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(ImVec2(300, 300));

bool opened = true;
ImGui::Begin("Cheatsheet !", &opened);

if (ImGui::Button("Enable Grid", ImVec2(280, 20)))
{
std::cout << "click!" << std::endl;
}

if (ImGui::Button("Enable Depth Peeling", ImVec2(280, 20)))
{
std::cout << "click!" << std::endl;
}
int marginLeft = 20;
int marginTB = 30;
ImGui::SetNextWindowPos(ImVec2(marginLeft, marginTB));
ImGui::SetNextWindowSize(ImVec2(300, this->Size[1] - 2 * marginTB - 1));

ImGui::Begin("Cheatsheet", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize);

vtkF3DRenderer* ren = vtkF3DRenderer::SafeDownCast(this->Renderers->GetFirstRenderer());

auto b = [](bool v) { return v ? "ON" : "OFF"; };

ImGui::Button("test");

ImGui::SeparatorText("Options");
ImGui::Text("W: Cycle animation [%s]", "N/A");
ImGui::Text("P: Translucency support [%s]", b(true));
ImGui::Text("Q: Ambient occlusion [%s]", b(true));
ImGui::Text("A: Anti-aliasing [%s]", b(true));
ImGui::Text("T: Tone mapping [%s]", b(true));
ImGui::Text("E: Edge visibility [%s]", b(true));
ImGui::Text("X: Axis [%s]", b(true));
ImGui::Text("G: Grid [%s]", b(true));
ImGui::Text("N: File name [%s]", b(true));
ImGui::Text("M: Metadata [%s]", b(true));
ImGui::Text("Z: FPS Timer [%s]", b(true));
ImGui::Text("U: Blur background [%s]", b(true));
ImGui::Text("K: Trackball interaction [%s]", b(true));
ImGui::Text("F: HDRI ambient lighting [%s]", b(true));
ImGui::Text("J: HDRI skybox [%s]", b(true));
ImGui::Text("L: Light (increase, shift+L: decrease) [%.2f]", 1.f);

ImGui::SeparatorText("Hotkeys");
ImGui::Text("H: Cheat sheet");
ImGui::Text("?: Print scene descr to terminal");
ImGui::Text("ESC : Quit ");
ImGui::Text("SPACE: Play animation if any");
ImGui::Text("LEFT : Previous file ");
ImGui::Text("RIGHT: Next file ");
ImGui::Text("UP : Reload current file ");
ImGui::Text("DOWN : Add files from dir of current file");
ImGui::Text("ENTER: Reset camera to initial parameters");
ImGui::Text("Drop : Load dropped file, folder or HDRI");

ImGui::SeparatorText("Camera");
ImGui::Text("1: Front View camera");
ImGui::Text("3: Right View camera");
ImGui::Text("5: Toggle Orthographic Projection [%s]", b(false));
ImGui::Text("7: Top View camera");
ImGui::Text("9: Isometric View camera");

ImGui::End();

Expand Down

0 comments on commit 7a82374

Please sign in to comment.