- fix bug on OSG with trackLights (by IcyStar)

- fix bug on scrolllist (by IcyStar)

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6873 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: d4e4e09f3d09b1754f257ab2ec527f753df28c09
Former-commit-id: 6be51bad80ce3894f03b857da3c03832c327db3f
This commit is contained in:
torcs-ng 2020-03-29 14:10:55 +00:00
parent 75f612b90d
commit 2b705431d4
2 changed files with 51 additions and 85 deletions

View file

@ -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;
}

View file

@ -32,6 +32,8 @@ public:
int index;
osg::ref_ptr<osg::Geode> node;
osg::ref_ptr<osg::Texture2D> textures[3];
Light(): index() { }
void setState(int index);
};
typedef std::vector<Light> 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<osg::Texture2D>
SDTrackLights::Internal::loadLightTexture(char const *filename)
{
@ -207,12 +220,7 @@ SDTrackLights::Internal::addLight(const osg::ref_ptr<osg::Group> &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);
}