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

#1
I was trying to change the font of some listbox items, and (after tinkering and trying stuff) figured out that if I add a widget to a panel, the font I set to the widget gets reset, or rather, gets set to the panel's font.

Is this expected behaviour?

And if so, how do I change a font of a widget that I plan to add to a panel without changing the panel's font?

I'll try changing the font AFTER I add it to the panel. See where it takes me.
EDIT: No dice. I tried getting a pointer to a button I added to a panel after I added it and changing its font, and it didn't work.
#2
I have multiple game states, each with their buttons and stuff.

So far, I've created a single tgui object, and pass a pointer around, everytime I enter a game state, I create the buttons and add to the gui, and everytime I quit a game state, I do gui->removeAllWidgets(), and clear everything.

But it just ocurred to me (years later than it should), that maybe I should create a gui object for each game state, and create and load the buttons on the constructor of each game state, so switching between game states should be faster, because everything is already created.

Is that ok? Having multiple tgui objects? Also, if I continue my current scheme (lots of code to change if swith), can I expect any problems?
#3
Help requests / Clickable pictures.
22 November 2015, 20:48:12
Hey. I'm trying to set up clickable pictures. I searched the forums a bit, and tried to figure out how to do it, but it's not working.

This doesn't work:

   tgui::Picture::Ptr robot_face = std::make_shared<tgui::Picture>();
   robot_pic->connect("clicked", &Equip_Screen::select_robot, this);

If I make it a button, tho, it works

   tgui::Button::Ptr robot_face = theme->load("Button");
   robot_face->connect("pressed", &Equip_Screen::select_robot, this);

Assume that the positions and textures were set, I cut them out so the code is minimal.

What is wrong?
#4
Hello. I set up some code like this:

tgui::ListBox::Ptr list_box_ptr = gui->get("List Box");

And I'm getting an error which reads "no conversion from tgui::Widget to tgui::ListBox exists"

But if I change the code to:

tgui::Widget::Ptr list_box_ptr = gui->get("List Box");

I lose the member functions available to tgui::ListBox.

How do I retrieve a pointer to a listbox (or any other widget) using get? Do I have to cast it into the right type of pointer each time?

Another thing, how do I work with tabs? There's nothing about them in the tutorials.

Is there some sample code anywhere, with basic usage of each widget? That would ease the use of the library a lot. I want to set up some tabs and listboxes...
#5
So. I'm trying to make a button do something. I've got a this button created inside a member function of my "main_menu" class. I'm trying to make the button call another member function of "main_menu" class, and I'm not having much success. The commented line is the offending one, and I've tried different arguments on that connect function with no success.

If you don't mind me saying, the tutorials could be a little clearer and explain stuff a little more in detail.

Lemme provide some minimal code:

#include "Main_Menu.h"

Quotevoid Main_Menu::start(tgui::Gui *gui, sf::RenderWindow *window)
{
   auto theme = std::make_shared<tgui::Theme>("Black.txt");
   
   tgui::Picture::Ptr main_menu_pic = std::make_shared<tgui::Picture>("splash.jpg");
   
   tgui::Button::Ptr new_game_button = theme->load("Button");
   new_game_button->setText("New Game");
   new_game_button->setPosition(1000, 200);
   new_game_button->setSize(100, 70);
   //new_game_button->connect("bpressed", &Main_Menu::button_pressed, this);

   gui->add(main_menu_pic);
   gui->add(new_game_button);

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

         gui->handleEvent(event);
      }

      window->clear();
      gui->draw();
      window->display();
   }
}

void Main_Menu::button_pressed()
{
   std::cout << "Button pressed" << std::endl;
}
#6
Hi. I'm trying to put some buttons on screen. I'm getting an unhandled exception:

"Unhandled exception at 0x72EE2B2B (sfml-system-d-2.dll) in blue.exe: 0xC0000005: Access violation reading location 0x00000238."

Bellow is my code. The offending line is "new_game_button->setText("New Game");" But if I delete this line, the next line that uses the new_game_button pointer gives me the same exception. If I just create the button and don't modify it, just call gui.add(new_game_button), it crashes during runtime.

int main()
{
sf::RenderWindow window(sf::VideoMode(1280, 720), "SFML works!");

tgui::Gui gui(window);
gui.setFont("DejaVuSans.ttf");

tgui::Button::Ptr new_game_button;
new_game_button->setText("New Game");
new_game_button->setPosition(1000, 200);
new_game_button->setSize(50, 50);
gui.add(new_game_button);

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

window.clear();
gui.draw();
window.display();
}
return 0;
}
#7
Help requests / About using tgui and game states
02 October 2015, 19:09:02
Hello.

I'm begginer programmer, this might be more of a programming question than tgui specific, but please bear with me a bit.

What would be the best way to use tgui and game states?

My plan was to create a Game_State_Manager class, a Game_State class and specific Game_State derived classes, like Battle_Menu, Options, Inventory, etc.

The Game_State objects would be contained (and managed) by the Game_State_Manager class.

My idea was to pass a pointer of the tgui::Gui gui object created on the main() function to the Game_State_Manager, all the way to the derived classes. And in each derived class I would add the widegts necessary to the gui object. Upon exiting each game state, I would remove all the widgets from the gui object and add the ones from the next game state.

But I stumbled upon the widget declaration

tgui::Button::Ptr new_game_button(gui);

gui there is not a pointer, it's asking me for the actual object.

If I pass the object by copy, instead of using a pointer, then the gui object who is actually being asked to draw stuff (the one on the main function) won't actually receive the widgets, and thus won't draw anything.

I tried passing a reference instead of a pointer, but the compiler is not letting me store the reference in a variable inside Game_State_Manager, for some reason, it complains that I have to initialize references in the constructor initialization list (I have to confess I don't know what it's talking about :) )

I hope I was sufficiently clear, and I would like suggestions on how to proceed with the game states

I also would lke some clarification on what happens here: "tgui::Button::Ptr new_game_button(gui);" I checked the documentation, and it's a typedef for a sharedptr for a Button. Ok, but why does it need that gui parameter? Can anybody explain what's happening in a more detailed fashion?