Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Commit

Permalink
Build GUI using GTKMM.
Browse files Browse the repository at this point in the history
  • Loading branch information
aentinger committed May 7, 2024
1 parent 807c237 commit 05e0d83
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 63 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ if(GLUT_FOUND)
message ("GLUT_LIBRARIES: " ${GLUT_LIBRARIES})
endif()
#######################################################################################
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)
#######################################################################################
add_executable(${ROBOTEM_ROVNE_GUI_TARGET}
src/Node.cpp
src/main.cpp
src/Node.cpp
src/main.cpp
)
#######################################################################################
target_include_directories(${ROBOTEM_ROVNE_GUI_TARGET} PRIVATE
include
${mp_units_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIRS}
${GLUT_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS}
)
#######################################################################################
target_compile_features(${ROBOTEM_ROVNE_GUI_TARGET} PRIVATE cxx_std_20)
Expand All @@ -46,12 +50,12 @@ target_link_libraries(${ROBOTEM_ROVNE_GUI_TARGET}
${mp-units_LIBRARIES}
${OPENGL_LIBRARIES}
${GLUT_LIBRARIES}
${GTKMM_LIBRARIES}
)
#######################################################################################
ament_target_dependencies(${ROBOTEM_ROVNE_GUI_TARGET} rclcpp std_msgs)
#######################################################################################
install(TARGETS ${ROBOTEM_ROVNE_GUI_TARGET} DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
#######################################################################################
ament_package()
#######################################################################################
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ colcon build --packages-select robotem_rovne_gui
```bash
cd $COLCON_WS
. install/setup.bash
ros2 launch robotem_rovne_gui gui.py
ros2 run robotem_rovne_gui robotem_rovne_gui_node
```
10 changes: 3 additions & 7 deletions include/robotem_rovne_gui/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
* INCLUDE
**************************************************************************************/

#include <GL/freeglut.h>

#include <thread>
#include <memory>

#include <gtkmm.h>

#include <rclcpp/qos.hpp>
#include <rclcpp/rclcpp.hpp>

Expand Down Expand Up @@ -44,14 +43,11 @@ namespace t07
class Node : public rclcpp::Node
{
public:
Node();
Node(int & argc, char ** argv);
~Node();

private:
std::thread _gui_thread;

void init_glut();
void deinit_glut();
};

/**************************************************************************************
Expand Down
16 changes: 0 additions & 16 deletions launch/gui.py

This file was deleted.

47 changes: 14 additions & 33 deletions src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,53 +21,34 @@ namespace t07
* CTOR/DTOR
**************************************************************************************/

Node::Node()
Node::Node(int & argc, char ** argv)
: rclcpp::Node("robotem_rovne_gui_node")
, _gui_thread{}
{
init_glut();
_gui_thread = std::thread(
[this, &argc, &argv]()
{
auto app = Gtk::Application::create(argc, argv, "");

Gtk::Window window;
window.set_title("Robotem Rovne GUI");
window.set_default_size(320, 240);

return app->run(window);
});

RCLCPP_INFO(get_logger(), "%s init complete.", get_name());
}

Node::~Node()
{
deinit_glut();
_gui_thread.join();
RCLCPP_INFO(get_logger(), "%s shut down successfully.", get_name());
}

/**************************************************************************************
* PRIVATE MEMBER FUNCTIONS
**************************************************************************************/

void Node::init_glut()
{
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

glutInitWindowPosition(50, 50);
glutInitWindowSize(320, 240);

glutCreateWindow("Robotem Rovne GUI");

auto const glut_render = +[]()
{
/* Just clear the buffers for now. */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* Flip the buffers. */
glutSwapBuffers();
};

glutDisplayFunc(glut_render);
glutIdleFunc(glut_render);

_gui_thread = std::thread([this]() { glutMainLoop(); });
}

void Node::deinit_glut()
{
glutLeaveMainLoop();
_gui_thread.join();
}

/**************************************************************************************
* NAMESPACE
**************************************************************************************/
Expand Down
17 changes: 14 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
* MAIN
**************************************************************************************/

int main(int argc, char * argv[])
class GuiWindow : public Gtk::Window
{
public:
GuiWindow();
};

GuiWindow::GuiWindow()
{
set_title("Robotem Rovne GUI");
set_default_size(320, 240);
}

int main(int argc, char ** argv)
{
glutInit(&argc, argv);
rclcpp::init(argc, argv);

auto node = std::make_shared<t07::Node>();
auto node = std::make_shared<t07::Node>(argc, argv);

try
{
Expand Down

0 comments on commit 05e0d83

Please sign in to comment.