A gui engine built on top of JMGraphics. Create more complex interactive apps with a user interface and event handler system.
Setting up a simple draw loop is similar to JMGraphics, but JMwindow is now used as the graphics engine/window instance. Create an instance of JMwindow and start the draw loop
JMwindow* jmw = new JMwindow(1920, 1080, "My Window")
while(jmw->window->windowOpen()){
jmw->beginDraw();
//draw stuff here
jmw->endDraw();
}
delete(jmw);
The "window" member is the JMGraphics instance and can be used to render custom graphics to the window.
To create user interface elements, a GuiElementHandler must be created and your gui elements can be added to it. The GuiElementHandler will handle rendering, events and destruction for all gui elements added to it. Gui elements have event instances that when triggered, are added to the windows event queue. Functions can be added to these events that are called after the event is triggered. To create a simple button in the middle of the window for example:
JMwindow* jmw = new JMwindow(1920, 1080, "My Window")
GuiElementHandler* myMenu = new GuiElementHandler(jmw);
Button* myButton = new Button(jmw->width() / 2.0f, jmw->height() / 2.0f, 100.0f, 40.0f, "My first button");
myButton->event_clicked->addListener([](JMeventDispatcher::Event* E){ std::cout << "Button clicked!" << std::endl; });
myMenu->addElement(myButton);
while(jmw->window->windowOpen()){
jmw->beginDraw();
myMenu->display();
jmw->endDraw();
}
delete(jmw);
Both this repository and the JMGraphics repository must be included in your project. https://github.com/Jasper99m/JMGraphics Adding them as git submodules is preferred. Once they are included, you can set up your CMakeLists.txt file to work with the CMake files in the libraries.
To set up your own CMakeLists.txt, you must add
add_subdirectory(JMgui)
add_subdirectory(JMGraphics)
target_link_libraries(YourProjectName
PUBLIC JMgui
)
And to copy assets to the build folder
add_custom_command(TARGET YourProjectName POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/JMGraphics/assimp-vc143-mt.dll $<TARGET_FILE_DIR:YourProjectName>
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/JMGraphics/shaders $<TARGET_FILE_DIR:YourProjectName>/JMGraphics/shaders
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/JMgui/fonts $<TARGET_FILE_DIR:YourProjectName>/JMgui/fonts
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/JMgui/textures $<TARGET_FILE_DIR:YourProjectName>/JMgui/textures
)
If you want your project to statically link MSVC in order to be run as a portable without installing anything, Put this before linking the JMGraphics library in your CMakeLists.txt.
if (MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
More detailed docs: https://jasper99m.github.io/JMgui/