Skip to content

Commit

Permalink
Begin implementing image viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
joel16 committed May 26, 2018
1 parent ea73686 commit e3b61f6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
6 changes: 6 additions & 0 deletions include/menus/menu_gallery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef NX_SHELL_MENU_GALLERY_H
#define NX_SHELL_MENU_GALLERY_H

void Gallery_DisplayImage(char *path);

#endif
19 changes: 9 additions & 10 deletions source/dirbrowse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "common.h"
#include "dirbrowse.h"
#include "fs.h"
#include "menu_gallery.h"
#include "SDL_helper.h"
#include "textures.h"
#include "utils.h"
Expand Down Expand Up @@ -157,9 +158,9 @@ void Dirbrowse_DisplayFiles(void)
strncpy(buf, file->name, sizeof(buf));
buf[sizeof(buf) - 1] = '\0';

if (strncmp(file->name, "..", 2) == 0)
SDL_DrawText(Roboto, 170, 160 + (73 * printed), BLACK, "Parent folder");
else if (!file->isDir)
/*if (strncmp(file->name, "..", 2) == 0)
SDL_DrawText(Roboto, 170, 160 + (73 * printed), BLACK, "Parent folder");*/
if (!file->isDir)
{
Utils_GetSizeString(size, FS_GetFileSize(path));
int width = 0;
Expand Down Expand Up @@ -224,14 +225,12 @@ void Dirbrowse_OpenFile(void)
Dirbrowse_SaveLastDirectory();

Dirbrowse_PopulateFiles(true);
Dirbrowse_DisplayFiles();
//Dirbrowse_DisplayFiles();
}
}
/*else if ((strncasecmp(file->ext, "png", 3) == 0) || (strncasecmp(file->ext, "jpg", 3) == 0) ||
(strncasecmp(file->ext, "gif", 3) == 0) || (strncasecmp(file->ext, "bmp", 3) == 0) ||
(strncasecmp(file->ext, "tga", 3) == 0))
else if ((strncasecmp(file->ext, "png", 3) == 0) || (strncasecmp(file->ext, "jpg", 3) == 0))
Gallery_DisplayImage(path);
else if (Music_GetMusicFileType(path) != 0)
/*else if (Music_GetMusicFileType(path) != 0)
Music_Player(path);
else if (strncasecmp(file->ext, "txt", 3) == 0)
TextViewer_DisplayText(path);
Expand Down Expand Up @@ -270,7 +269,6 @@ int Dirbrowse_Navigate(int dir)
}

slash[0] = 0; // Terminate working directory
Dirbrowse_SaveLastDirectory();
}

// Normal folder
Expand All @@ -280,8 +278,9 @@ int Dirbrowse_Navigate(int dir)
strcpy(cwd + strlen(cwd), file->name);
cwd[strlen(cwd) + 1] = 0;
cwd[strlen(cwd)] = '/';
Dirbrowse_SaveLastDirectory();
}

Dirbrowse_SaveLastDirectory();

return 0; // Return success
}
31 changes: 31 additions & 0 deletions source/menus/menu_gallery.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <switch.h>

#include "common.h"
#include "menu_gallery.h"
#include "SDL_helper.h"

void Gallery_DisplayImage(char *path)
{
SDL_Texture *image = NULL;
SDL_LoadImage(RENDERER, &image, path);

int width = 0, height = 0;
SDL_QueryTexture(image, NULL, NULL, &width, &height);

while(appletMainLoop())
{
SDL_ClearScreen(RENDERER, SDL_MakeColour(33, 39, 43));
SDL_RenderClear(RENDERER);
SDL_DrawImage(RENDERER, image, (1280 - width) / 2, (720 - height) / 2, width, height);
SDL_RenderPresent(RENDERER);

hidScanInput();
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);

if (kDown & KEY_B)
break;
}

SDL_DestroyTexture(image);
MENU_DEFAULT_STATE = MENU_STATE_HOME;
}

0 comments on commit e3b61f6

Please sign in to comment.