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

Messages - Alpgh367

#1
Thank you so much for all your help!!!! Everything is working now!!   ;D ;D ;D
#2
I am not overly experienced in C++ but I have tried to fix the code you have mentioned, although I think I may have done so unsuccessfully. Here is more of my code:

Sidebar class (what I have attempted to fix)

#include "Sidebar.h"
#include "App.h"

Sidebar::Sidebar()
{
App app;
tgui::Button::Ptr button = tgui::Button::create("Home");
homeButton(button);
app.gui.add(button, "homeButton");
}

std::shared_ptr<tgui::Button> Sidebar::homeButton(std::shared_ptr<tgui::Button> button)
{
button->setPosition(600, 600);
button->setSize(200, 200);
button->setText("test");
button->setTextSize(20);
return button;
}


App class (I have publicly declared my gui object in the app header)
#include "App.h"
#include "Sidebar.h"

const sf::Time App::timePerFrame = sf::seconds(1.f / 60.f);

App::App()
{
mWindow.create(sf::VideoMode(1280, 720), "Study Buddy", sf::Style::Default);
gui.setWindow(mWindow);
}

void App::run()
{
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
while (mWindow.isOpen())
{
sf::Time elapsedTime = clock.restart();
timeSinceLastUpdate += elapsedTime;
while (timeSinceLastUpdate > timePerFrame)
{
timeSinceLastUpdate -= timePerFrame;

processEvents();
update(timePerFrame);
}

render();
}
}

void App::processEvents()
{
sf::Event event;

while (mWindow.pollEvent(event))
{
switch (event.type)
{
case sf::Event::KeyPressed:
handleUserInput(event.key.code, true);
break;

case sf::Event::KeyReleased:
handleUserInput(event.key.code, false);
break;

case sf::Event::Closed:
mWindow.close();
break;
}

gui.handleEvent(event);
}
}

void App::update(sf::Time elapsedTime)
{

}

void App::render()
{
mWindow.clear();
Sidebar s;
gui.draw();
mWindow.display();
}

void App::handleUserInput(sf::Keyboard::Key key, bool isPressed)
{
if (key == sf::Keyboard::Escape)
mWindow.close();
}


Unfortunately, I am still getting the rapidly flashing window with this code. Thanks for your help so far.
#3
I have managed to fix the Access Violation error but now when running the program the window rapidly flashes and the button is not rendered. Any fix to this would be great.
#4
Hi,
While trying to set the size and position of a button with TGUI I am receiving an access violation error. I am using Visual Studio 2015 community, I downloaded the precompiled library, and I am linking dynamically. This is the code that is causing the error:
#include "Sidebar.h"
#include "App.h"

std::shared_ptr<tgui::Button> Sidebar::homeButton()
{
tgui::Button::Ptr button = tgui::Button::create("Home");
button->setPosition(500, 200);
button->setSize(200, 200);
App app;
app.gui.add(button, "homeButton");

return button;
}


The code runs with no errors without the setPosition and setSize, leading me to believe that they are the ones causing the issue. Any help is highly appreciated, thanks!