addOnValueChangedEventHandler() not working?

Captain_Deathbeard

17-07-2007 01:27:31

TrackBar::addOnValueChangedEventHandler does not seem to work, when I change a value on the slider the callback is not called. Unless its activated a different way?

kungfoomasta

17-07-2007 01:50:10

Looks like I forgot to fire this event. :(

I have added the fixes to my code. For a temporary fix, replace these functions:


bool TrackBar::onMouseButtonDown(MouseEventArgs& e)
{
if(!mEnabled) return e.handled;

bool fireOnValueChangedEvent = false;

if( e.button == MB_Left )
{
if(mLayout == QGUI_TRACKBAR_HORIZONTAL)
{
// if mouse cursor simulating dragging more than 50% towards the next right position..
if(e.position.x > (mCurrentSliderPos.x))
{
if(mCurrentPos < mNumRegions)
{
// move slider one region length to the right
mCurrentSliderPos.x += (mRegionLength);
++mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
else if(e.position.x < (mCurrentSliderPos.x))
{
if(mCurrentPos > 0)
{
// move slider one region length to the right
mCurrentSliderPos.x -= (mRegionLength);
--mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
}
else if(mLayout == QGUI_TRACKBAR_VERTICAL)
{
// if mouse cursor simulating dragging more than 50% towards the next right position..
if(e.position.y > (mCurrentSliderPos.y))
{
if(mCurrentPos > 0)
{
// move slider one region length down
mCurrentSliderPos.y += (mRegionLength);
--mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
else if(e.position.y < (mCurrentSliderPos.y))
{
if(mCurrentPos < mNumRegions)
{
// move slider one region length up
mCurrentSliderPos.y -= (mRegionLength);
++mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
}
}

if(fireOnValueChangedEvent)
{
WidgetEventArgs e(this);
e.handled = false;
onValueChanged(e);
}

return Label::onMouseButtonDown(e);
}



void TrackBar::setTickPosition(unsigned int Tick)
{
if( (Tick < 0) || (static_cast<int>(Tick) > mNumRegions) ) return;

mCurrentPos = Tick;

if(mLayout == QGUI_TRACKBAR_HORIZONTAL)
{
mCurrentSliderPos.x = mPixelInitialSliderLeft + (mCurrentPos * mRegionLength);
}
else if(mLayout == QGUI_TRACKBAR_VERTICAL)
{
mCurrentSliderPos.y = mPixelInitialSliderBot - (mCurrentPos * mRegionLength);
}
mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);

WidgetEventArgs e(this);
e.handled = false;
onValueChanged(e);
}



bool TrackBar::slide(const EventArgs& e)
{
if(!mEnabled) return e.handled;

bool fireOnValueChangedEvent = false;

// determine if slider was moved toward or away from current position
Ogre::Vector2 newPos = MouseCursor::getSingleton().getPixelPosition();
if(mLayout == QGUI_TRACKBAR_HORIZONTAL)
{
// if mouse cursor simulating dragging more than 50% towards the next right position..
if(newPos.x > (mCurrentSliderPos.x + (mRegionLength / 2)))
{
if(mCurrentPos < mNumRegions)
{
// move slider one region length to the right
mCurrentSliderPos.x += (mRegionLength);
++mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
else if(newPos.x < (mCurrentSliderPos.x - (mRegionLength / 2)))
{
if(mCurrentPos > 0)
{
// move slider one region length to the right
mCurrentSliderPos.x -= (mRegionLength);
--mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
}
else if(mLayout == QGUI_TRACKBAR_VERTICAL)
{
// if mouse cursor simulating dragging more than 50% towards the next right position..
if(newPos.y > (mCurrentSliderPos.y + (mRegionLength / 2)))
{
if(mCurrentPos > 0)
{
// move slider one region length down
mCurrentSliderPos.y += (mRegionLength);
--mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
else if(newPos.y < (mCurrentSliderPos.y - (mRegionLength / 2)))
{
if(mCurrentPos < mNumRegions)
{
// move slider one region length up
mCurrentSliderPos.y -= (mRegionLength);
++mCurrentPos;

mSliderButton->setPosition(mCurrentSliderPos.x,mCurrentSliderPos.y,QGUI_GMM_PIXELS);
fireOnValueChangedEvent = true;
}
}
}

if(fireOnValueChangedEvent)
{
WidgetEventArgs e(this);
e.handled = false;
onValueChanged(e);
}

return true;
}


I haven't tested this code, but basically if the TrackBar Button changes position, I call onValueChanged. Let me know if there are any other problems.

Thanks for pointing this out! :)

Captain_Deathbeard

17-07-2007 03:34:14

it works great, thanks!