Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - MattDA

#1
Hi again. I am trying to make a basic set up with headers to test my new build using the raylib backend. I have app class that holds the backend object (tgui::RAYLIB::gui). All the logic is nearly the same as the working example. I get no errors and everything loads. I can see that the container of the gui has 2 elements, (canvas and menubar) but I can't get them to draw. What am I doing wrong?
main.cpp
//#include <iostream>
//#include "raylib.h"
//#include <filesystem>


//namespace fs = std::filesystem;

//#include <SFML/Graphics.hpp>
#include <iostream>
//#include <UI.h>
//#include <TGUI/TGUI.hpp>
//#include <TGUI/Backend/raylib.hpp>
#include "Game.h"


int main()
{

    Game game;
    //float ar = (1080.0 / 1920.0) * 1.25;
    game.init(900, 600);

    game.runFixed();

    return 0;
}
game.cpp
#ifndef GAME_H
#define GAME_H
#include <iostream>
//#include <filesystem>
//#include <unordered_map>
//#include <string>
//#include <cassert> // for assert()
//#include "raylib.h"
//#include "raymath.h"

#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/raylib.hpp>

//#include "VecUtil.h"
//#include "MapMan.h"
//#include "AssetMan.h"
//#include "GameObjects.hpp"

#include "AppUI.h"

class Game
{
public:

    Game();
    ~Game();
    void init(int,int);
    void runFixed();
private:

    ui::App m_ui;
};
#endif

Game.cpp
#include "Game.h"

Game::Game()
{

    std::cout << "Game Created" << std::endl;
   
    //m_ui = nullptr;
}
Game::~Game(){CloseWindow();}

void Game::init(int screenWidth,int screenHeight)
{
    SetTraceLogLevel(LOG_WARNING);
    std::cout << "Game Initializing" << std::endl;
    InitWindow(screenWidth, screenHeight, "Raylib is the master");

    SetTargetFPS(60);
    m_ui.init();

    tgui::RAYLIB::Gui* ui = m_ui.getUI();
    if (ui == nullptr)
        std::cout << "UI is null" << std::endl;

   
}

void Game::runFixed()
{

    while (!WindowShouldClose())    // Detect window close button or ESC key
    {

        auto ui = m_ui.getUI();
        ui->handleEvents();

        int pressedChar = GetCharPressed();
        while (pressedChar)
        {
            ui->handleCharPressed(pressedChar);
            pressedChar = GetCharPressed();
        }

        int pressedKey = GetKeyPressed();
        while (pressedKey)
        {
            ui->handleKeyPressed(pressedKey);
            pressedKey = GetKeyPressed();
        }
       
       BeginDrawing();
       
            ClearBackground({40, 60, 40, 255});
            DrawCircle(200, 120, 50, Color{100,10,10,255});
            m_ui.draw();
           
       EndDrawing();
     
       // ui.mainLoop();

    }
}


AppUI.h
#ifndef HEADER_APP_UI
#define HEADER_APP_UI



#pragma once

#include <iostream>
#include <unordered_map>
#include <map>
#include <string>
#include <filesystem>

//#include "raylib.h"
//#include "rlgl.h"
#include <TGUI/TGUI.hpp>
#include <TGUI/Backend/raylib.hpp>

//#include "VecUtil.h"
//#include "AssetMan.h"


namespace ui
{
    namespace fs = std::filesystem;

class App
{
public:
        App();
~App();
void init();
tgui::RAYLIB::Gui* getUI();
void draw();
void update();

private:


tgui::RAYLIB::Gui m_ui;
};


}


#endif // header guard



AppUI.cpp
#include "AppUI.h"

ui::App::App(){

}

ui::App::~App()
{

}

void ui::App::init()
{

    std::cout << "Initializing App User Interface." << std::endl;
try {
tgui::Theme blackTheme{ "../../themes/Black.txt" };

tgui::CanvasRaylib::Ptr MainCanvas = tgui::CanvasRaylib::create({ "100%", "100%" });

m_ui.add(MainCanvas, "main_canvas");


tgui::MenuBar::Ptr MainMenuBar = tgui::MenuBar::create();
MainMenuBar->setRenderer(blackTheme.getRenderer("MenuBar"));

MainMenuBar->setHeight(22.f);
MainMenuBar->setPosition("1%", "1%");
MainMenuBar->addMenu("File");
MainMenuBar->addMenuItem("New");
MainMenuBar->addMenuItem("Load");
MainMenuBar->addMenuItem("Save");
MainMenuBar->addMenuItem("Exit");

MainMenuBar->addMenu("Window");
MainMenuBar->addMenuItem("Map Object Tree");//Show a tree view of the map in a child window
MainMenuBar->addMenuItem("Object Properties");//Show Properties of an object

MainMenuBar->addMenu("Help");
MainMenuBar->addMenuItem("About");
MainMenuBar->setVisible(true);

m_ui.add(MainMenuBar, "main_menu_bar");


//MainMenuBar->connectMenuItem({ "File", "New" }, &UI::createWizard, this);
}
catch (const tgui::Exception& e)
{
std::cerr << "TGUI Exception: " << e.what() << std::endl;
exit(1);
}


}
tgui::RAYLIB::Gui* ui::App::getUI()
{
   
    return &m_ui;
}

void ui::App::draw()
{
auto MainCanvas = m_ui.get<tgui::CanvasRaylib>("main_canvas");
BeginTextureMode(MainCanvas->getTextureTarget());

m_ui.draw();
EndTextureMode();

}


void ui::App::update()
{
    //m_screenSize.x = static_cast<float>(GetScreenWidth());
    //m_screenSize.y = static_cast<float>(GetScreenHeight());
}


#2
Hello. I am trying to install the latest tgui for use with Raylib. In cmake gui cmake can not find the bin dir because it does not exist in my raylib 5 build.In the "selecting a back end" docs, "lib/cmake/raylib/raylib-config.cmake must exists." This directory does not exist in any of my raylib builds or the pre built package. I can see the raylib-config.cmake in another folder but when I tried so set that as raylibs path cmake gui considered it but rejected the file.   


Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
CMake Error at cmake/Dependencies.cmake:600 (find_package):
  Could not find a package configuration file provided by "raylib" with any
  of the following names:

    raylibConfig.cmake
    raylib-config.cmake

  Add the installation prefix of "raylib" to CMAKE_PREFIX_PATH or set
  "raylib_DIR" to a directory containing one of the above files.  If "raylib"
  provides a separate development package or SDK, be sure it has been
  installed.
Call Stack (most recent call first):
  src/Backend/CMakeLists.txt:204 (tgui_add_dependency_raylib)
  src/CMakeLists.txt:312 (include)


Configuring incomplete, errors occurred!

				
#3
Help requests / Tree View Tutorials?
17 January 2023, 02:13:21
Hi. I was trying to create a tree view but I am not sure how it works. It takes an array of strings as an Item but each string of that array creates a deeper indent.
so for example, a string array like {"Object", "SubObject", "SubObject2"}
ends up looking like this.
Object
     SubObject
          SubObject2

But what I want is something like this.
Object
     SubObject
     SubObject2
I see on the main tgui page the screenshots show a proper tree view example. Are those examples available?
#4
Help requests / Texture for RangeSlider
12 October 2020, 02:43:11
Hello. I am trying to make a display child window that has all of the TGUI widgets. The widgets are using a modified version of black.txt. The texture atlas is my own custom drawn png. The issue I am having is with RangeSlider. There does not seem to be a way to load textures for the space between the two thumbs.

RangeSlider is inherited from Slider, but the object properties (that we set in a theme file or setters) are not available.
In other words I can not set the RangeSlider to display textures (available to Sliders) and the color values in the RangeSlider renderer.


RangeSlider {


/*
TextureTrack      = "GUI.png" Part(245, 45, 26, 26) Middle(6, 6, 14, 14);
    //TextureTrackHover = "GUI.png" Part(297, 45, 26, 26) Middle(2, 2, 22, 22);
    TextureThumb      = "GUI.png" Part(350, 45, 26, 26) Middle(2, 2, 22, 22) Smooth;
TextureThumbHover = "GUI.png" Part(375, 45, 26, 26) Middle(2, 2, 22, 22) Smooth;
//SelectedTrack     = "GUI.png" Part(297, 45, 26, 26) Middle(2, 2, 22, 22);
*/

SelectedTrackColor = rgb(190, 0, 0, 100);
SelectedTrackColorHover = rgb(0,190, 0, 100);
}