Fix image index underflow when navigating past boundaries
This commit is contained in:
28
viewer.cpp
28
viewer.cpp
@@ -153,6 +153,18 @@ struct App {
|
||||
|
||||
LoadImageList(curFile);
|
||||
}
|
||||
void Prev()
|
||||
{
|
||||
this->imageIndex--;
|
||||
if(this->imageIndex >= this->filenames.size())
|
||||
this->imageIndex=this->filenames.size()-1;
|
||||
}
|
||||
void Next()
|
||||
{
|
||||
this->imageIndex++;
|
||||
if(this->imageIndex >= this->filenames.size())
|
||||
this->imageIndex=0;
|
||||
}
|
||||
bool Update() {
|
||||
if(!window || !renderer) return false;
|
||||
SDL_Event evt;
|
||||
@@ -188,22 +200,28 @@ struct App {
|
||||
break;
|
||||
case SDL_SCANCODE_PAGEUP:
|
||||
{
|
||||
SetNewImage(this->imageIndex-20);
|
||||
for(size_t i = 0; i < 20; i++)
|
||||
Prev();
|
||||
SetNewImage(this->imageIndex);
|
||||
}
|
||||
break;
|
||||
case SDL_SCANCODE_PAGEDOWN:
|
||||
{
|
||||
SetNewImage(this->imageIndex+20);
|
||||
for(size_t i = 0; i < 20; i++)
|
||||
Next();
|
||||
SetNewImage(this->imageIndex);
|
||||
}
|
||||
break;
|
||||
case SDL_SCANCODE_LEFT:
|
||||
{
|
||||
SetNewImage(this->imageIndex-1);
|
||||
Prev();
|
||||
SetNewImage(this->imageIndex);
|
||||
}
|
||||
break;
|
||||
case SDL_SCANCODE_RIGHT:
|
||||
{
|
||||
SetNewImage(this->imageIndex+1);
|
||||
Next();
|
||||
SetNewImage(this->imageIndex);
|
||||
}
|
||||
break;
|
||||
case SDL_SCANCODE_F:
|
||||
@@ -218,6 +236,8 @@ struct App {
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user