Finished grid layout
This commit is contained in:
parent
2852b6ed32
commit
ef90d94569
2
src/fs.c
2
src/fs.c
|
@ -43,7 +43,7 @@ char **listFiles(char *path){
|
|||
// plus the \0 character having in mind the size of each character
|
||||
strings[i] = malloc((strlen(ep->d_name) + strlen(path) + 1) * sizeof(char));
|
||||
//strcpy(strings[i],path);
|
||||
strcpy(strings[i],"assets/");
|
||||
strcpy(strings[i],path);
|
||||
strcat(strings[i],ep->d_name);
|
||||
i++; // if not inside it will give size error since it counts . and ..
|
||||
if(i == nfiles) return strings;
|
||||
|
|
19
src/grid.c
19
src/grid.c
|
@ -1,8 +1,21 @@
|
|||
#include "grid.h"
|
||||
|
||||
int gridHelper(SDL_Rect* rect, int index, SDL_Rect screen, int zoom, int page){
|
||||
rect->y = 0;
|
||||
rect->x = screen.w/10 * index * zoom / 10;
|
||||
#define MARGIN 20
|
||||
#define MIN_PADDING 10
|
||||
|
||||
//printf("index %i -- x = %i | y = %i | w = %i | h = %i\n", index, rect->x, rect->y, rect->w, rect->h);
|
||||
int x_amount = (screen.w - MARGIN * 2) / (MIN_PADDING + rect->w);
|
||||
//int padding = ((screen.w - (MARGIN * 2) - (rect->w * x_amount)) / (x_amount-1));
|
||||
//
|
||||
int x_offset = ((screen.w - MARGIN * 2) / x_amount);
|
||||
int y_offset = ((screen.w - MARGIN * 2) / x_amount);
|
||||
|
||||
int center = (x_offset - rect->w) / 2;
|
||||
|
||||
screen.w = 200;
|
||||
|
||||
rect->w = 40 + zoom;
|
||||
rect->h = 40 + zoom;
|
||||
rect->y = MARGIN + (y_offset * (index / x_amount)) + center;
|
||||
rect->x = MARGIN + (x_offset * (index - (x_amount * (index / x_amount)))) + center;
|
||||
}
|
||||
|
|
18
src/main.c
18
src/main.c
|
@ -51,8 +51,8 @@ int main(int argc, char* args[]) {
|
|||
/* Init of the game */
|
||||
|
||||
// Get image file names and their count
|
||||
char ** imageNames = listFiles("assets/");
|
||||
int nfiles = countFiles("assets/");
|
||||
char ** imageNames = listFiles("assets2/");
|
||||
int nfiles = countFiles("assets2/");
|
||||
|
||||
// Allocate space for the images
|
||||
SDL_Texture **thumbs = (SDL_Texture **) malloc(sizeof(SDL_Texture *) * nfiles);
|
||||
|
@ -66,14 +66,14 @@ int main(int argc, char* args[]) {
|
|||
fprintf(stderr, "Error on loading image at path \"%s\".\n", imageNames[i]);
|
||||
}
|
||||
else{
|
||||
fprintf(stderr, "Loaded image on at path \"%s\".\n", imageNames[i]);
|
||||
//fprintf(stderr, "Loaded image on at path \"%s\".\n", imageNames[i]);
|
||||
}
|
||||
|
||||
free(imageNames[i]);
|
||||
imageNames[i] = NULL;
|
||||
}
|
||||
|
||||
SDL_Rect thumbs_container = {0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
|
||||
SDL_Rect thumbs_container = {0, 0, SCREEN_WIDTH/3*2, SCREEN_HEIGHT};
|
||||
SDL_Rect thumbs_rect = {40, 40, 40, 40};
|
||||
int min_zoom = 1, max_zoom = 100;
|
||||
int zoom = 25;
|
||||
|
@ -81,8 +81,7 @@ int main(int argc, char* args[]) {
|
|||
|
||||
for(int i = 0; i < nfiles; i++){
|
||||
gridHelper(&thumbs_rect, i, thumbs_container, 1, 0);
|
||||
printf("index %i -- x = %i | y = %i | w = %i | h = %i\n",
|
||||
i, thumbs_rect.x, thumbs_rect.y, thumbs_rect.w, thumbs_rect.h);
|
||||
//printf("index %3i -- x = %5i | y = %4i | w = %3i | h = %3i\n",i, thumbs_rect.x, thumbs_rect.y, thumbs_rect.w, thumbs_rect.h);
|
||||
}
|
||||
|
||||
bool quit = false;
|
||||
|
@ -94,15 +93,13 @@ int main(int argc, char* args[]) {
|
|||
}
|
||||
if(e.type == SDL_MOUSEWHEEL){
|
||||
if(e.wheel.y > 0){ // scroll up
|
||||
if(zoom < max_zoom){
|
||||
if(zoom < max_zoom && currentKeyStates[SDL_SCANCODE_LCTRL]){
|
||||
zoom++;
|
||||
printf("zoom = %i\n", zoom);
|
||||
}
|
||||
}
|
||||
else if(e.wheel.y < 0){ // scroll down
|
||||
if(zoom > min_zoom){
|
||||
if(zoom > min_zoom && currentKeyStates[SDL_SCANCODE_LCTRL]){
|
||||
zoom--;
|
||||
printf("zoom = %i\n", zoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -138,5 +135,6 @@ int main(int argc, char* args[]) {
|
|||
renderer = NULL;
|
||||
|
||||
SDL_Quit();
|
||||
IMG_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue