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.


Messages - desocupado

Pages: [1]
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
Help requests / Doubt about creating tgui objects.
« on: 16 May 2017, 22:56:15 »
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 / Re: Clickable pictures.
« on: 22 November 2015, 22:57:37 »
Sigh.

It was just that. Really sorry about that, it's the second time I make a silly mistake like this today.

Could you tell me if I'm right about something tho, in this line:

robot_face->connect("clicked", &Equip_Screen::select_robot, this, i);

The value of "i" is set at the time the line executes. So if I do something like this:

int i = 1;
robot_face->connect("clicked", &Equip_Screen::select_robot, this, i);
i = 2;

wait for button press

When the button is pressed, the select_robot function is going to be called with the value of 1 as argument, correct?

And if I do

robot_face->connect("clicked", &Equip_Screen::select_robot, this, std::ref(i));

Then it'll store a reference to i, and use it's value?

4
Help requests / Clickable pictures.
« on: 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?

5
Help requests / Re: Help with gui::get(), list boxes and tabs
« on: 21 November 2015, 23:49:14 »
Well, thanks for the answers! :)

I hope you don't mind if I have more questions tho.

For example, is there a way to make all tabs the same, fixed width, regardless of the text width?

6
Help requests / Help with gui::get(), list boxes and tabs
« on: 21 November 2015, 18:43:18 »
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...

7
Quote
This is not possible. You wouldn't be able to access the return value even if the function would return something since the function is called internally and there is nowhere in your code where you would get the return. If a function need to "return" something then give it a reference parameter and pass it with std::ref.
void f(int& x) { x = 5; }
int i = 0;
button->connect("pressed", f, std::ref(i));
// i is 0 here but will become 5 once the callback is triggered

I tried using "&i" and it didn't work, but when I wrote "std::ref(i)" thinks worked properly. Why is that? Shouldn't it be the same thing?

8
Changing from "bpressed" to pressed solved the issue. Thanks.

About what could be clearer, well, I made that mistake because I didn't know exactly what that parameter meant.
Explaining what a signal is and where it goes when you click the function would go a long way.

Another thing that I wondered about, is what is the scope of the function that is called by the button, once it's connected. I assumed it's the same scope as where the button was created, am I right?

Also, what if the function has a return type? Let's say return type int. How could I catch that int when the function returns?

Sorry if those questions are a bit (or a lot) amateurish, but I guess we all have to start somewhere.

9
Help requests / Using signals and the ->connect member function.
« on: 16 October 2015, 21:05:21 »
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"

Quote
void 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;
}

10
Help requests / Re: Unhandled exception on using Button::Ptr
« on: 10 October 2015, 16:20:17 »
Derp. Such a silly mistake. Well, sorry for that, and thanks for your time and attention.

11
Help requests / Re: Unhandled exception on using Button::Ptr
« on: 10 October 2015, 15:49:25 »
I did. Everything is set up correctly. tgui-d.lib for the debug mode and tgui.lib for the release mode. Same for the sfml files. I'm linking dynamically, I'm using VS2015, and I downloaded the precompiled libraries for VS2015 32-bit.

12
Help requests / Unhandled exception on using Button::Ptr
« on: 10 October 2015, 06:21:12 »
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.

Code: [Select]
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;
}

13
Help requests / Re: Problem loading font
« on: 10 October 2015, 05:39:35 »
I'm having this exact same problem, but I don't understand the solution. Can anybody explain to me what he did?

This line here:

gui.setFont("TGUI/fonts/DejaVuSans.ttf");

Gives me an unhandled exception. I'm using the latest SFML and the latest TGUI, win7, VS2015.

EDIT: Nevermind, I updated the Visual Studio and forgot to change the TGUI version. Downloaded the proper files and it's working now. Sorry about that.

14
Help requests / Re: About using tgui and game states
« on: 02 October 2015, 19:57:21 »
Thank you very much! :D

I'll start using the 0.7 version.

15
Help requests / About using tgui and game states
« on: 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?

Pages: [1]