diff --git a/src/libs/tgfclient/guiscrollist.cpp b/src/libs/tgfclient/guiscrollist.cpp index a6d41d137..34065a7b0 100644 --- a/src/libs/tgfclient/guiscrollist.cpp +++ b/src/libs/tgfclient/guiscrollist.cpp @@ -60,6 +60,28 @@ gfuiScroll(tScrollBarInfo *sinfo) } } +static void +gfuiScrollListUpdateScroll(tGfuiScrollList *scrollist, int showElt = -1, int elemBeforeAfter = 0) +{ + if (showElt >= 0) { + showElt = MIN(showElt, scrollist->nbElts); + elemBeforeAfter = MIN(elemBeforeAfter, (scrollist->nbElts-1)/2); + elemBeforeAfter = MAX(elemBeforeAfter, 0); + scrollist->firstVisible = MIN( + scrollist->firstVisible, + showElt - scrollist->nbVisible + 1 + elemBeforeAfter ); + scrollist->firstVisible = MAX( + scrollist->firstVisible, + scrollist->selectedElt - elemBeforeAfter ); + } + + scrollist->firstVisible = MIN(scrollist->firstVisible, scrollist->nbElts - scrollist->nbVisible); + scrollist->firstVisible = MAX(scrollist->firstVisible, 0); + + GfuiScrollBarPosSet(GfuiScreen, scrollist->scrollBar, 0, MAX(scrollist->nbElts - scrollist->nbVisible, 0), + scrollist->nbVisible, scrollist->firstVisible); +} + void gfuiScrollListNextElt (tGfuiObject *object) { @@ -75,16 +97,7 @@ gfuiScrollListNextElt (tGfuiObject *object) if (scrollist->onSelect) { scrollist->onSelect(scrollist->userDataOnSelect); } - if (scrollist->selectedElt == scrollist->firstVisible + scrollist->nbVisible) { - /* Scroll down */ - if (scrollist->firstVisible + scrollist->nbVisible < scrollist->nbElts) { - scrollist->firstVisible++; - if (scrollist->scrollBar) { - GfuiScrollBarPosSet(GfuiScreen, scrollist->scrollBar, 0, MAX(scrollist->nbElts - scrollist->nbVisible, 0), - scrollist->nbVisible, scrollist->firstVisible); - } - } - } + gfuiScrollListUpdateScroll(scrollist, scrollist->selectedElt); } void @@ -102,16 +115,7 @@ gfuiScrollListPrevElt (tGfuiObject *object) if (scrollist->onSelect) { scrollist->onSelect(scrollist->userDataOnSelect); } - if (scrollist->selectedElt < scrollist->firstVisible) { - /* Scroll down */ - if (scrollist->firstVisible > 0) { - scrollist->firstVisible--; - if (scrollist->scrollBar) { - GfuiScrollBarPosSet(GfuiScreen, scrollist->scrollBar, 0, MAX(scrollist->nbElts - scrollist->nbVisible, 0), - scrollist->nbVisible, scrollist->firstVisible); - } - } - } + gfuiScrollListUpdateScroll(scrollist, scrollist->selectedElt); } @@ -276,6 +280,7 @@ GfuiScrollListSetSelectedElement(void *scr, int id, unsigned int selectElement) if (scrollist->onSelect) scrollist->onSelect(scrollist->userDataOnSelect); + gfuiScrollListUpdateScroll(scrollist, scrollist->selectedElt); return true; } @@ -451,6 +456,7 @@ GfuiScrollListExtractSelectedElement(void *scr, int id, void **userData) *userData = elt->userData; free(elt); + gfuiScrollListUpdateScroll(scrollist, scrollist->selectedElt); return name; } @@ -486,6 +492,7 @@ GfuiScrollListExtractElement(void *scr, int id, int index, void **userData) *userData = elt->userData; free(elt); + gfuiScrollListUpdateScroll(scrollist); return name; } @@ -505,6 +512,7 @@ GfuiScrollListClear(void *scr, int id) scrollist->nbElts = 0; scrollist->selectedElt = -1; + gfuiScrollListUpdateScroll(scrollist); } /** Insert an element in a scroll list. @@ -535,9 +543,7 @@ GfuiScrollListInsertElement(void *scr, int id, const char *element, int index, v gfuiScrollListInsElt(scrollist, elt, index); scrollist->nbElts++; - if (scrollist->scrollBar) - GfuiScrollBarPosSet(scr, scrollist->scrollBar, 0, MAX(scrollist->nbElts - scrollist->nbVisible, 0), - scrollist->nbVisible, scrollist->firstVisible); + gfuiScrollListUpdateScroll(scrollist, scrollist->nbElts - 1); return 0; } @@ -565,15 +571,7 @@ GfuiScrollListShowElement(void *scr, int id, int index) else if (index >= scrollist->nbElts) index = scrollist->nbElts - 1; - int oldFirstVisible = scrollist->firstVisible; - if (index < scrollist->firstVisible) - scrollist->firstVisible = index; - else if (index >= scrollist->firstVisible + scrollist->nbVisible) - scrollist->firstVisible = index - scrollist->nbVisible + 1; - - if (scrollist->firstVisible != oldFirstVisible && scrollist->scrollBar) - GfuiScrollBarPosSet(scr, scrollist->scrollBar, 0, MAX(scrollist->nbElts - scrollist->nbVisible, 0), - scrollist->nbVisible, scrollist->firstVisible); + gfuiScrollListUpdateScroll(scrollist, index); } void @@ -735,26 +733,7 @@ GfuiScrollListMoveSelectedElement(void *scr, int id, int delta) gfuiScrollListInsElt(scrollist, elt, newPos); scrollist->selectedElt = newPos; - - if (scrollist->selectedElt == scrollist->firstVisible + scrollist->nbVisible) { - /* Scroll down */ - if (scrollist->firstVisible + scrollist->nbVisible < scrollist->nbElts) { - scrollist->firstVisible++; - if (scrollist->scrollBar) { - GfuiScrollBarPosSet(GfuiScreen, scrollist->scrollBar, 0, MAX(scrollist->nbElts - scrollist->nbVisible, 0), - scrollist->nbVisible, scrollist->firstVisible); - } - } - } else if (scrollist->selectedElt < scrollist->firstVisible) { - /* Scroll down */ - if (scrollist->firstVisible > 0) { - scrollist->firstVisible--; - if (scrollist->scrollBar) { - GfuiScrollBarPosSet(GfuiScreen, scrollist->scrollBar, 0, MAX(scrollist->nbElts - scrollist->nbVisible, 0), - scrollist->nbVisible, scrollist->firstVisible); - } - } - } + gfuiScrollListUpdateScroll(scrollist, scrollist->selectedElt, abs(delta)); return 0; } diff --git a/src/modules/graphic/osggraph/Scenery/OsgTrackLight.cpp b/src/modules/graphic/osggraph/Scenery/OsgTrackLight.cpp index 4f49b7464..5a5a4d1c1 100644 --- a/src/modules/graphic/osggraph/Scenery/OsgTrackLight.cpp +++ b/src/modules/graphic/osggraph/Scenery/OsgTrackLight.cpp @@ -32,6 +32,8 @@ public: int index; osg::ref_ptr node; osg::ref_ptr textures[3]; + Light(): index() { } + void setState(int index); }; typedef std::vector LightList; @@ -64,6 +66,17 @@ public: void update(double currentTime, double totTime, int raceType); }; +void SDTrackLights::Internal::Light::setState(int index) +{ + osg::StateSet *stateSet = new osg::StateSet; + stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); + stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON); + stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); + stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); + stateSet->setTextureAttributeAndModes(0, textures[index], osg::StateAttribute::ON); + node->setStateSet(stateSet); +} + osg::ref_ptr SDTrackLights::Internal::loadLightTexture(char const *filename) { @@ -207,12 +220,7 @@ SDTrackLights::Internal::addLight(const osg::ref_ptr &group, tGraphi new_light->node = new osg::Geode; new_light->node->addDrawable(geometry); - osg::StateSet *stateSet = new_light->node->getOrCreateStateSet(); - stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); - stateSet->setMode(GL_CULL_FACE, osg::StateAttribute::ON); - stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); - stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); - stateSet->setTextureAttributeAndModes(0, new_light->textures[0], osg::StateAttribute::ON); + new_light->setState(0); group->addChild( new_light->node ); } @@ -232,58 +240,37 @@ SDTrackLights::Internal::update(double currentTime, double totTime, int raceType current_index = -1; onoff = !active && raceType != RM_TYPE_RACE; - if( current_index != onoff_red_index || onoff != onoff_red ) { onoff_red_index = current_index; onoff_red = onoff; - for(LightList::iterator i = red.begin(); i != red.end(); ++i) - { - int index = onoff || (current_index >= 0 && current_index < i->index) ? 1 : 0; - i->node->getOrCreateStateSet()->setTextureAttributeAndModes( - 0, i->textures[index], osg::StateAttribute::ON ); - } + i->setState(onoff || (current_index >= 0 && current_index < i->index) ? 1 : 0); } onoff = active && raceType != RM_TYPE_RACE; - if( onoff_green != onoff ) { onoff_green = onoff; - for(LightList::iterator i = green.begin(); i != green.end(); ++i) - { - i->node->getOrCreateStateSet()->setTextureAttributeAndModes( - 0, i->textures[onoff ? 1 : 0], osg::StateAttribute::ON ); - } + i->setState(onoff ? 1 : 0); } onoff = active && ( raceType != RM_TYPE_RACE || currentTime < 30.0f ); - if( onoff_green_st != onoff ) { onoff_green_st = onoff; - for(LightList::iterator i = green_st.begin(); i != green_st.end(); ++i) - { - i->node->getOrCreateStateSet()->setTextureAttributeAndModes( - 0, i->textures[onoff ? 1 : 0], osg::StateAttribute::ON ); - } + i->setState(onoff ? 1 : 0); } onoff = false; - if( onoff_yellow != onoff || ( onoff && phase != onoff_phase ) ) { onoff_yellow = onoff; - + int index = !onoff ? 0 : (phase ? 2 : 1); for(LightList::iterator i = yellow.begin(); i != yellow.end(); ++i) - { - int index = !onoff ? 0 : (phase ? 2 : 1); - i->node->getOrCreateStateSet()->setTextureAttributeAndModes( - 0, i->textures[index], osg::StateAttribute::ON ); - } + i->setState(index); } onoff_phase = phase; @@ -312,5 +299,5 @@ void SDTrackLights::build(tTrack *track) void SDTrackLights::update(double currentTime, double totTime, int raceType) { - internal->update(currentTime, totTime, raceType); + if (internal) internal->update(currentTime, totTime, raceType); }