-
Notifications
You must be signed in to change notification settings - Fork 0
Getting started
- You can simply install LibGui by using this in terminal.
git clone https://github.com/TechnologicalTurtle/LibGui.git- After that use CMake to build it for your IDE.
cmake -B [build directory]Note
If you want to build some stuff packed with LibGui, add flag:
-DLIBGUI_BUILD_CLIENT=ONTo build simple hello world program
-DLIBGUI_BUILD_EXAMPLES=ONTo build simple LibGui notepad example
- Open the project from [build directory] in your IDE.
- And that's all! Enjoy!
Note
This part assumes you have set up main.cpp, or used LIBGUI_BUILD_CLIENT option.
First you need to include LibGui.h header,
#include "include/LibGui.h"then in your main function initialize library using the LibGui::Init() function, this function returns pointer to app window, to get handle for this window plug it into LibGui::Window constructor with other properties like window name, and size. That should look like this:
LibGui::Window MyMainWindow(LibGui(), "window name", {600, 400});Now, you have to create the square, because square is an basic object without any special properties, the class that handles it is called LibGui::Object, now you can just use constructor with function LibGui::Shapes::Rectangle() to tell it to be square.
Your code should look like this:
// position | scale | color | shape of this object
LibGui::Object MyObject({300, 200}, {150, 150}, Color::Red, LibGui::Shapes::Rectangle());Now is time to render something, create an while loop using !MyWindow.ShouldClose(), once user clicks on [X] button, the function will return true, which will break the loop. In the loop, you should tell program where to render using function MyWindow.Draw(). Then render MyObject using MyObject.Render(). At the end, tell library to push changes by calling MyWindow.PushDraw();. The code will look like this:
while (!MyWindow.ShouldClose())
{
MyWindow.Draw();
MyObject.Render();
MyWindow.PushDraw();
}Now, after user closed our window, we'll tell LibGui to Terminate by calling LibGui::Terminate();
LibGui::Terminate();Our final code should look similar to this:
// include library header
#include "include/LibGui.h"
int main()
{
// initialize library and create main window
LibGui::Window MyWindow(LibGui::Init(), "My LibGui window", {600, 400});
// create our square
LibGui::Object MyObject({300, 200}, {150, 150}, Color::Red, LibGui::Shapes::Rectangle());
while (!MyWindow.ShouldClose())
{
// start drawing on our main window
MyWindow.Draw();
// render our square
MyObject.Render();
// push our changes
MyWindow.PushDraw();
}
// terminate libgui
LibGui::Terminate();
return 0;
}Features