Trouble syncing scrollbar and knob widgets
« on: 14 December 2015, 02:31:30 »
I have 8 knobs and 8 scrollbars in my project but i keep running into issues when i try to sync them.

Working:
Default/Inverted Mode: Knob operates Scrollbar
Inverted Mode: Knob operates Scrollbar
Not working:
Default Mode: Scrollbar operates Knob


How can i correctly sync changes between them?


Interesting bits of code:

Code: [Select]
const int vertical_control_separator = 100;

tgui::Scrollbar::Ptr scrollbar(gui);
scrollbar->load(THEME_CONFIG_FILE);
scrollbar->setVerticalScroll(true);
scrollbar->setPosition(20, 20);
scrollbar->setSize(18, 256);
scrollbar->setMaximum(127);
scrollbar->setLowValue(8);

tgui::Knob::Ptr knob(gui);
knob->load("data/widgets/Knob/Knob.conf");
knob->setPosition(55, 235);
knob->setSize(40, 40);
knob->setStartRotation(127);
knob->setValue(0);
knob->setEndRotation(-128);

Code: [Select]
/* Callback handling*/
#define Knob_CALLBACK_ID 10
#define KnobScroll_CALLBACK_ID 20

bool invert_Knob_SYNC=false;

knob->bindCallback(tgui::Knob::ValueChanged);
knob->setCallbackId(Knob_CALLBACK_ID +1);

syncbox->bindCallback(tgui::Checkbox::Checked);
syncbox->bindCallback(tgui::Checkbox::Unchecked);
syncbox->setCallbackId(Knob_CALLBACK_ID + 9);

scrollbar->bindCallback(tgui::Scrollbar::ValueChanged);
scrollbar->setCallbackId(KnobScroll_CALLBACK_ID + 1);

Code: [Select]
int value;

switch(callback.id)
{
// Knobs
case Knob_CALLBACK_ID + 1:
{
value=knob->getValue();

if (invert_Knob_SYNC == true) scrollbar->setValue(value / 3); // works but sync is flipped
else scrollbar->setValue((128 - 8) - (value / 3)); // default ( offset fixed)
break;
}
Code: [Select]
case Knob_CALLBACK_ID + 9:
{
invert_Knob_SYNC = !invert_Knob_SYNC;
break;
}
Code: [Select]
case KnobScroll_CALLBACK_ID + 1:
{
value = scrollbar->getValue();

if (invert_Knob_SYNC == true) knob8->setValue(value * 3); // works but sync is flipped
//else knob->setValue(? ); // broken
break;
}

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Trouble syncing scrollbar and knob widgets
« Reply #1 on: 14 December 2015, 10:09:25 »
Knob also has a minimum and maximum, the start and end rotation only tell something about where the min and max are graphically, the value goes in the range of min to max which is 0 to 360 by default.

If you add this:
knob->setMaximum(128-8);
then your scrollbar and knob will have the exact same value range.

The "scrollbar->setValue(( 128 - 8 ) - (value / 3));" code that you had would e.g. become
scrollbar->setValue((128 - 8) - value);
after this change.

I don't have the time now to give the correct formula, but like this it shouldn't be too hard to find it yourself.

Re: Trouble syncing scrollbar and knob widgets
« Reply #2 on: 14 December 2015, 11:09:03 »
Fixed. a quick question though: is it possible to change the color of a widget like SFML can do on sprites?

I.e: sprite.setColor(sf::Color(0, 255, 0)); // green

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Trouble syncing scrollbar and knob widgets
« Reply #3 on: 14 December 2015, 13:29:06 »
No you can only set the opacity. If I were to add a setColor function to widgets I would also have to define what should happen with colored widgets as opposed to textured widgets. Before there was a setOpacity function there was a setTransparency function which had several issues, when I once tried adding a setColor function back then it made those issues even bigger making it practically impossible. I guess most of these problems will have been solved if I implemented it similar to setOpacity though, so maybe I could give it another try. But it won't happen anywhere soon.

Re: Trouble syncing scrollbar and knob widgets
« Reply #4 on: 19 December 2015, 04:24:09 »
I see.

There is a minor glitch with the knobs; the first time they are clicked, they jump to what seems to be a random point above half of the maximum value set.

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Trouble syncing scrollbar and knob widgets
« Reply #5 on: 19 December 2015, 12:45:53 »
I can't reproduce it here. Could you show the lines where you create the knob? Maybe the problem is specific to the minimum, maximum, start rotation and end rotation that you are using.

Re: Trouble syncing scrollbar and knob widgets
« Reply #6 on: 19 December 2015, 16:10:27 »
Code: [Select]
tgui::Knob::Ptr knob1(gui);
knob1->load("data/widgets/Knob/Knob.conf");
knob1->setPosition(55, 235);
knob1->setSize(40, 40);
knob1->setStartRotation(127);
knob1->setValue(0);
knob1->setEndRotation(-128);
knob1->setMinimum(0);
knob1->setMaximum(127);

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Trouble syncing scrollbar and knob widgets
« Reply #7 on: 19 December 2015, 16:14:28 »
I still can't reproduce it with that code. Can you put your code in a single file and send it to me so that I can run the identical code?
Does it matter where you click on the knob?

Re: Trouble syncing scrollbar and knob widgets
« Reply #8 on: 19 December 2015, 16:48:13 »
Ah, found a reliable way to trigger it; It happens when clicking on the area not specified, i.e:



Most of the time it sets the knob to near/at maximum level

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Trouble syncing scrollbar and knob widgets
« Reply #9 on: 19 December 2015, 16:53:06 »
That's actually intended behaviour, it sets the value to the closest possible location.

Re: Trouble syncing scrollbar and knob widgets
« Reply #10 on: 19 December 2015, 17:26:43 »
I see. But it only works towards maximum, i would have expected it to work both ways

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Trouble syncing scrollbar and knob widgets
« Reply #11 on: 19 December 2015, 17:32:21 »
It should work both ways. The code that you last showed had the invalid area on the left side. When I click just above the middle it goes up, if you click right below the middle it goes down. It still works as intended when I set the rotations to 0 and 180.

So if it is only going to the maximum then you could still show your code and then I can check why it goes wrong in that situation (if I can reproduce it here).

Re: Trouble syncing scrollbar and knob widgets
« Reply #12 on: 19 December 2015, 21:41:03 »
it's pretty long, added it as attachment.

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Trouble syncing scrollbar and knob widgets
« Reply #13 on: 19 December 2015, 21:49:45 »
It is still working here, but I noticed that my invalid area is on the left side, while in your screenshots it seems to be at the bottom. So the only thing that I can still think of that can be the issue is a difference in the config file. Could you also send the Knob.conf and the images so that I can test with them?

Re: Trouble syncing scrollbar and knob widgets
« Reply #14 on: 19 December 2015, 22:41:03 »
\/