Zoom value added

This commit is contained in:
Pòsweg 2020-07-05 08:58:39 +02:00
parent 39f69ad7d7
commit 2852b6ed32
3 changed files with 21 additions and 3 deletions

3
.gitignore vendored
View File

@ -93,4 +93,5 @@ tags
# End of https://www.toptal.com/developers/gitignore/api/vim,c,linux
main
build
build/
assets2/

View File

@ -2,7 +2,7 @@
int gridHelper(SDL_Rect* rect, int index, SDL_Rect screen, int zoom, int page){
rect->y = 0;
rect->x = screen.w/20 * index;
rect->x = screen.w/10 * index * zoom / 10;
//printf("index %i -- x = %i | y = %i | w = %i | h = %i\n", index, rect->x, rect->y, rect->w, rect->h);
}

View File

@ -75,6 +75,9 @@ int main(int argc, char* args[]) {
SDL_Rect thumbs_container = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
SDL_Rect thumbs_rect = {40, 40, 40, 40};
int min_zoom = 1, max_zoom = 100;
int zoom = 25;
for(int i = 0; i < nfiles; i++){
gridHelper(&thumbs_rect, i, thumbs_container, 1, 0);
@ -89,6 +92,20 @@ int main(int argc, char* args[]) {
if(e.type == SDL_QUIT){
quit = true;
}
if(e.type == SDL_MOUSEWHEEL){
if(e.wheel.y > 0){ // scroll up
if(zoom < max_zoom){
zoom++;
printf("zoom = %i\n", zoom);
}
}
else if(e.wheel.y < 0){ // scroll down
if(zoom > min_zoom){
zoom--;
printf("zoom = %i\n", zoom);
}
}
}
}
if(currentKeyStates[SDL_SCANCODE_ESCAPE]){
return 0;
@ -101,7 +118,7 @@ int main(int argc, char* args[]) {
//thumbs_rect.x = 0;
//thumbs_rect.y = 0;
for(int i = 0; i < nfiles; i++){
gridHelper(&thumbs_rect, i, thumbs_container, 1, 0);
gridHelper(&thumbs_rect, i, thumbs_container, zoom, 0);
SDL_RenderCopy(renderer, thumbs[i], NULL, &thumbs_rect);
}