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 - Jimmyee

#1
Hello. I was trying to compile this code:

#include <TGUI/TGUI.hpp>

int main()
{
    // Create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "Window");
    tgui::Gui gui(window);

    // Load the font (you should check the return value to make sure that it is loaded)
    gui.setGlobalFont("fonts/DejaVuSans.ttf");

    tgui::Button::Ptr button(gui, "btnTileset");
    button->load("widgets/Button/BabyBlue");
    button->setText("Tileset");
    button->setSize(80, 20);
    button->setPosition(4, 4);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

            // Pass the event to all the widgets (if there would be widgets)
            gui.handleEvent(event);
        }

        window.clear();

        // Draw all created widgets
        gui.draw();

        window.display();
    }

    return EXIT_SUCCESS;
}


The "widgets" and "fonts" folders are in the same folder as the app is. What might be the problem?
This is TGUI v0.6 of course.
#2
Help requests / Child window and controls
27 July 2013, 23:35:54
How can I add controls to a child window and handle them? It seems different than it is done in the main GUI window...
#3
Help requests / Problem with TGUI basics
13 July 2013, 20:44:20
Hello. I'm Jimmyee.
I just downloaded TGUI 0.5 and I am trying to compile my game using tgui::window. Seems like everything works fine but nothing is being drawn. There is just a white screen.
I use tdm-gcc-4.7.1-2.

This is my code:

void Game::init()
{
    int fps = v_conv::to_int(config["FPS"]);
    std::string fullscreen = config["Fullscreen"];

    if(fullscreen == "yes")
        window.create(sf::VideoMode(800, 600), "Lucyferian", sf::Style::Close | sf::Style::Titlebar | sf::Style::Fullscreen);
    else
        window.create(sf::VideoMode(800, 600), "Lucyferian", sf::Style::Close | sf::Style::Titlebar);
    window.setVerticalSyncEnabled(true);
    window.setFramerateLimit(fps);

    window.globalFont.loadFromFile("DejaVuSans.ttf");

    gfxLoader = std::shared_ptr<GFXLoader>(new GFXLoader("gfx/"));

    sgui.setTexture(gfxLoader->dir["gui/"].tex[0]);
    sgui.setPosition(0.0f, 0.0f);

    tileset[0].load(gfxLoader, 1);
    tileset[1].load(gfxLoader, 1);
}

Game::Game()
: config("config.ini")
, state(State::Run)
, minimap(false)
{
    init();
}

void Game::handleEvents()
{
    sf::Event event;
    while(window.pollEvent(event))
    {
        handleEvent(event);
        window.handleEvent(event);
    }

    realTimeKeyboardInput();

    tgui::Callback callback;
    while (window.getCallback(callback))
    {
        // here tgui events are handled
    }
}

void Game::draw()
{
    window.clear(sf::Color(0, 0, 0, 255));

    if(map.get())
    {
        window.draw(*map);
        if(minimap)
        {
            sf::RectangleShape rectangle(sf::Vector2f(240, 180));
            rectangle.setFillColor(sf::Color::Black);
            rectangle.setOutlineThickness(1);
            rectangle.setOutlineColor(sf::Color::White);
            rectangle.setPosition(440, 0);
            window.draw(rectangle);

            sf::View transformed_map(sf::FloatRect(0, 0, 800, 600));
            transformed_map.setCenter(((21/2)*32) - 16, ((16/2)*32) + 16);
            transformed_map.setViewport(sf::FloatRect(0.55f, 0, 0.3f, 0.3f));
            transformed_map.zoom(1.5);
            window.setView(transformed_map);
            window.draw(*map.get());
            window.setView(window.getDefaultView());
        }

        if(tileset[1].enabled)
        {
            tileset[1].draw(window);
        }
    }

    window.drawGUI();
    window.display();
}

void Game::run()
{
    MapFile mf("data/maps/testmap.map");
    map = std::shared_ptr<MapRender>(new MapRender(mf, (*this)));
    me = std::shared_ptr<Character>(new Character(*this, 0, 0));
    me->x = map->mapFile.width/2;
    me->y = map->mapFile.height/2;
    me->speed = 4;
    map->addObject(me);
    printf("Player speed: %i\n", me->speed);

    map->update();

    sf::Clock clock;
    while(this->window.isOpen())
    {
        handleEvents();
        sf::Time elapsed = clock.restart();
        process(elapsed);
        draw();
        sf::sleep(sf::milliseconds(5));
    }
}


I can't find the problem but maybe you will. Thanks in advance.