Skip to content

Commit

Permalink
allow glfw to be spawned (eventually) by sofapython3 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredroy authored Nov 8, 2023
1 parent 3a99785 commit e281b6d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
1 change: 1 addition & 0 deletions SofaGLFW/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(SOFAGLFW_SOURCE_DIR src/SofaGLFW)

set(HEADER_FILES
${SOFAGLFW_SOURCE_DIR}/config.h.in
${SOFAGLFW_SOURCE_DIR}/init.h
${SOFAGLFW_SOURCE_DIR}/SofaGLFWWindow.h
${SOFAGLFW_SOURCE_DIR}/SofaGLFWBaseGUI.h
${SOFAGLFW_SOURCE_DIR}/BaseGUIEngine.h
Expand Down
10 changes: 9 additions & 1 deletion SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, boo
}
else
{
glfwWindow = glfwCreateWindow(width, height, title, nullptr, m_firstWindow);
glfwWindow = glfwCreateWindow(width > 0 ? width : 100, height > 0 ? height : 100, title, nullptr, m_firstWindow);
}

setWindowIcon(glfwWindow);
Expand Down Expand Up @@ -226,6 +226,14 @@ bool SofaGLFWBaseGUI::createWindow(int width, int height, const char* title, boo
}
}

void SofaGLFWBaseGUI::resizeWindow(int width, int height)
{
if (hasWindow())
{
glfwSetWindowSize(m_firstWindow, width, height);
}
}

void SofaGLFWBaseGUI::destroyWindow()
{
}
Expand Down
2 changes: 2 additions & 0 deletions SofaGLFW/src/SofaGLFW/SofaGLFWBaseGUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class SOFAGLFW_API SofaGLFWBaseGUI
int getWindowHeight() const { return m_windowHeight; }
void setWindowHeight(int height) { m_windowHeight = height; }

void resizeWindow(int width, int height);

GLFWmonitor* getCurrentMonitor(GLFWwindow *window);

bool isFullScreen(GLFWwindow* glfwWindow = nullptr) const;
Expand Down
8 changes: 7 additions & 1 deletion SofaGLFW/src/SofaGLFW/SofaGLFWGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ void SofaGLFWGUI::setScene(sofa::simulation::NodeSPtr groot, const char* filenam
std::string strFilename;
if (filename)
strFilename = filename;

m_baseGUI.setSimulation(groot, strFilename);

m_baseGUI.createWindow(m_baseGUI.getWindowWidth(), m_baseGUI.getWindowHeight(), std::string("SofaGLFW - " + strFilename).c_str(), m_bCreateWithFullScreen);
Expand All @@ -78,6 +77,10 @@ void SofaGLFWGUI::setViewerResolution(int width, int height)
{
m_baseGUI.setWindowWidth(width);
m_baseGUI.setWindowHeight(height);

//if already spawned, apply
m_baseGUI.resizeWindow(width, height);

}

void SofaGLFWGUI::setViewerConfiguration(sofa::component::setting::ViewerSetting* viewerConf)
Expand Down Expand Up @@ -117,6 +120,9 @@ sofa::gui::common::BaseGUI* SofaGLFWGUI::CreateGUI(const char* name, sofa::simul
{
return nullptr;
}

gui->setScene(groot, filename);

return gui;
}

Expand Down
29 changes: 29 additions & 0 deletions SofaGLFW/src/SofaGLFW/init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/******************************************************************************
* SOFA, Simulation Open-Framework Architecture *
* (c) 2006 INRIA, USTL, UJF, CNRS, MGH *
* *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************
* Authors: The SOFA Team and external contributors (see Authors.txt) *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#pragma once

#include <SofaGLFW/config.h>

namespace sofaglfw
{
SOFAGLFW_API void init();
} // namespace sofaglfw
7 changes: 6 additions & 1 deletion SofaGLFW/src/SofaGLFW/initSofaGLFW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
#include <SofaGLFW/config.h>
#include <SofaGLFW/init.h>

#include <sofa/simulation/Node.h>

Expand Down Expand Up @@ -78,4 +78,9 @@ const char* getModuleComponentList()
return "";
}

void init()
{
initExternalModule();
}

} // namespace sofaglfw

0 comments on commit e281b6d

Please sign in to comment.