Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions bimpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class Context
int GetWidth() const;

int GetHeight() const;

bool IsActive();
void KeepFrame();
void Wake();

~Context();

Expand All @@ -48,6 +52,7 @@ class Context
int m_height;
struct ImGuiContext* m_imgui;
std::mutex m_imgui_ctx_mutex;
bool is_active = false;
};


Expand Down Expand Up @@ -132,6 +137,13 @@ void Context::Init(int width, int height, const std::string& name)
io.MouseDown[button] = action == GLFW_PRESS;
}
});

glfwSetWindowFocusCallback(m_window, [](GLFWwindow* window, int focused)
{
Context* ctx = static_cast<Context*>(glfwGetWindowUserPointer(window));
ctx->is_active = focused;
});

}
}

Expand Down Expand Up @@ -170,6 +182,30 @@ void Context::NewFrame()
ImGui::NewFrame();
}

void Context::KeepFrame()
{
m_imgui_ctx_mutex.lock();
GImGui = m_imgui;
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

ImGui::Render();
glfwMakeContextCurrent(m_window);
glViewport(0, 0, m_width, m_height);
// glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapInterval(4);
glfwSwapBuffers(m_window);
// glfwPollEvents();
glfwWaitEvents();
m_imgui_ctx_mutex.unlock();
}

void Context::Wake()
{
glfwPostEmptyEvent();
}

void Context::Resize(int width, int height)
{
Expand All @@ -192,6 +228,11 @@ int Context::GetHeight() const
{
return m_height;
}

bool Context::IsActive()
{
return is_active;
}

struct Bool
{
Expand Down Expand Up @@ -410,6 +451,9 @@ PYBIND11_MODULE(_bimpy, m) {
.def("should_close", &Context::ShouldClose)
.def("width", &Context::GetWidth)
.def("height", &Context::GetHeight)
.def("is_active", &Context::IsActive)
.def("keep_frame", &Context::KeepFrame)
.def("wake", &Context::Wake)
.def("__enter__", &Context::NewFrame)
.def("__exit__", [](Context& self, py::object, py::object, py::object)
{
Expand Down Expand Up @@ -1044,6 +1088,7 @@ PYBIND11_MODULE(_bimpy, m) {
return result;
}, py::arg("label"), py::arg("v1"), py::arg("v2"), py::arg("v3"), py::arg("v4"), py::arg("v_speed") = 1.0f, py::arg("v_min"), py::arg("v_max"), py::arg("display_format") = "%.0f");


m.def("plot_lines", [](
const char* label,
const std::vector<float>& values,
Expand Down