Greetings All...
I have been trying to get a SpinButton to adjust another value, but I can't seem to make it send the Callback. Is there anything I missing?
Here is some code I made from the "Full example" with most things removed.
There are a few modifications...
-I used a <tgui.h> file to select the libs required for debug/release. It may changed back on another computer.
-Added "spinButton->setCallbackId(1);" so it should function.
-Added some text for displaying "CallBack Count" and X and Y just for testing.
-I kept the menu so if the "Save" or "Load" were selected, it will increase the "CallBack Count". "Quit" it too quick to see.
-I changed "if(callback.id == 1)" to do nothing important so a click from the SpinButton doesn't Quit the program, it should only increment the "CallBack Count", however it doesn't.
That's where I ran into the issue and haven't figured out how to solve yet.
I hope that provides enough information.
Ezk.
I have been trying to get a SpinButton to adjust another value, but I can't seem to make it send the Callback. Is there anything I missing?
Here is some code I made from the "Full example" with most things removed.
Code Select
//#include <TGUI/TGUI.hpp>
#include <tgui.h>
#include <string>
#include <sstream>
#define THEME_CONFIG_FILE "../../widgets/Black.conf"
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI window");
tgui::Gui gui(window);
tgui::setResourcePath("../../../TGUI-0.6/examples/FullExample");
if (gui.setGlobalFont("../../fonts/DejaVuSans.ttf") == false)
return 1;
unsigned int callback_count = 0;
//control
int current_mouse_x = 0;
int current_mouse_y = 0;
//fonts
sf::Font font;
font.loadFromFile("arial.ttf");
sf::Font fixedfont;
fixedfont.loadFromFile("courbd.ttf");
tgui::Picture::Ptr picture(gui);
picture->load("../Linux.jpg");
tgui::MenuBar::Ptr menu(gui);
menu->load(THEME_CONFIG_FILE);
menu->setSize(window.getSize().x, 20);
menu->addMenu("File");
menu->addMenuItem("File", "Load");
menu->addMenuItem("File", "Save");
menu->addMenuItem("File", "Exit");
menu->bindCallback(tgui::MenuBar::MenuItemClicked);
menu->setCallbackId(2);
tgui::SpinButton::Ptr spinButton(gui);
spinButton->load(THEME_CONFIG_FILE);
spinButton->setCallbackId(1);
spinButton->setPosition(100, 80);
spinButton->setVerticalScroll(false);
spinButton->setSize(40, 20);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
//exits
if ((event.type == sf::Event::Closed) ||
((event.type == sf::Event::KeyPressed) && (event.key.code == sf::Keyboard::Escape))
|| (event.type == sf::Event::Closed))
window.close();
if(event.type == sf::Event::MouseMoved)
{
current_mouse_x = event.mouseMove.x;//keep track of mouse current position
current_mouse_y = event.mouseMove.y;
}
gui.handleEvent(event);
}
tgui::Callback callback;
while (gui.pollCallback(callback))
{
if (callback.id == 1)sf::sleep(sf::seconds(0.016f));//spinbutton, does nothing important
if (callback.id == 2)
{
if (callback.text == "Exit")
window.close();
}
callback_count++;
}
window.clear();
gui.draw();
//test text
std::stringstream info_conv;
info_conv << "CallBack Count: " << callback_count <<
//"\nchecked " << (int)checkbox->Checked <<
//"\nunchecked " << (int)checkbox->Unchecked <<
"\nX: " << current_mouse_x << "\nY: " << current_mouse_y;
sf::Text info_text;
info_text.setFont(font);
info_text.setCharacterSize(18);
info_text.setPosition(240.0f, 70.0f);
info_text.setString(info_conv.str());
window.draw(info_text);
window.display();
sf::sleep(sf::seconds(0.016f));
}
return 0;
}
There are a few modifications...
-I used a <tgui.h> file to select the libs required for debug/release. It may changed back on another computer.
-Added "spinButton->setCallbackId(1);" so it should function.
-Added some text for displaying "CallBack Count" and X and Y just for testing.
-I kept the menu so if the "Save" or "Load" were selected, it will increase the "CallBack Count". "Quit" it too quick to see.
-I changed "if(callback.id == 1)" to do nothing important so a click from the SpinButton doesn't Quit the program, it should only increment the "CallBack Count", however it doesn't.
That's where I ran into the issue and haven't figured out how to solve yet.
I hope that provides enough information.
Ezk.