Fix status bar being on side in portriat
This commit is contained in:
parent
5dec89c683
commit
d4b1c382e1
|
@ -0,0 +1,6 @@
|
|||
#ifndef EBOOK_READER_CONFIG_H
|
||||
#define EBOOK_READER_CONFIG_H
|
||||
|
||||
extern bool configDarkMode;
|
||||
|
||||
#endif
|
|
@ -32,10 +32,14 @@ void SDL_ClearScreen(SDL_Renderer *renderer, SDL_Color colour);
|
|||
void SDL_DrawRect(SDL_Renderer *renderer, int x, int y, int w, int h, SDL_Color colour);
|
||||
void SDL_DrawCircle(SDL_Renderer *renderer, int x, int y, int r, SDL_Color colour);
|
||||
void SDL_DrawText(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char *text);
|
||||
void SDL_DrawRotatedText(SDL_Renderer *renderer, TTF_Font *font, double rotation, int x, int y, SDL_Color colour, const char *text);
|
||||
void SDL_DrawTextf(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char* text, ...);
|
||||
void SDL_LoadImage(SDL_Renderer *renderer, SDL_Texture **texture, char *path);
|
||||
void SDL_LoadImageBuf(SDL_Renderer *renderer, SDL_Texture **texture, void *mem, int size);
|
||||
void SDL_DrawImage(SDL_Renderer *renderer, SDL_Texture *texture, int x, int y);
|
||||
void SDL_DrawImageScale(SDL_Renderer *renderer, SDL_Texture *texture, int x, int y, int w, int h);
|
||||
void SDL_InvertSurfaceColor(SDL_Surface *surface);
|
||||
Uint32 SDL_GetPixel32(SDL_Surface *surface, int x, int y);
|
||||
void SDL_PutPixel32(SDL_Surface *surface, int x, int y, Uint32 pixel);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef NX_SHELL_FS_H
|
||||
#define NX_SHELL_FS_H
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
int FS_MakeDir(const char *path);
|
||||
int FS_RecursiveMakeDir(const char * dir);
|
||||
bool FS_FileExists(const char *path);
|
||||
bool FS_DirExists(const char *path);
|
||||
const char *FS_GetFileExt(const char *filename);
|
||||
char *FS_GetFileModifiedTime(const char *filename);
|
||||
u64 FS_GetFileSize(const char *filename);
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef EBOOK_READER_STATUS_BAR_H
|
||||
#define EBOOK_READER_STATUS_BAR_H
|
||||
|
||||
void StatusBar_DisplayTime(void);
|
||||
void StatusBar_DisplayTime(bool portriat);
|
||||
|
||||
#endif
|
|
@ -31,6 +31,73 @@ void SDL_DrawText(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Colo
|
|||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
void SDL_DrawRotatedText(SDL_Renderer *renderer, TTF_Font *font, double rotation, int x, int y, SDL_Color colour, const char *text) {
|
||||
SDL_Surface *surface = TTF_RenderText_Blended_Wrapped(font, text, colour, 1280);
|
||||
SDL_SetSurfaceAlphaMod(surface, colour.a);
|
||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
SDL_Rect position;
|
||||
position.x = x; position.y = y;
|
||||
SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h);
|
||||
SDL_Point center = {position.w / 2, position.h / 2};
|
||||
SDL_Rect crop = {0, 0, &position.w, &position.h}; // the crop is what part of the image we want to display.
|
||||
|
||||
SDL_SetRenderTarget(renderer, texture);
|
||||
//SDL_RenderCopyEx(RENDERER, texture, &crop, &position, rotation, ¢er, SDL_FLIP_NONE);
|
||||
SDL_RenderCopyEx(RENDERER, texture, NULL, &position, rotation, NULL, SDL_FLIP_NONE);
|
||||
SDL_SetRenderTarget(renderer, NULL);
|
||||
/*SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h);
|
||||
SDL_RenderCopy(renderer, texture, NULL, &position);*/
|
||||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
void SDL_InvertSurfaceColor(SDL_Surface *surface) {
|
||||
for(int x = 0; x < (*surface).w; x++) {
|
||||
for(int y = 0; y < (*surface).h; y++) {
|
||||
int r, g, b, a;
|
||||
Uint32 pixel = SDL_GetPixel32(&surface, x, y);
|
||||
SDL_GetRGBA(pixel, SDL_GetWindowPixelFormat(&WINDOW), &r, &g, &b, &a);
|
||||
SDL_Color color = SDL_MakeColour(255 - r, 255 - g, 255 - b, a);
|
||||
SDL_PutPixel32(&surface, x, y, pixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 SDL_GetPixel32(SDL_Surface *surface, int x, int y) {
|
||||
//Lock the surface.
|
||||
if(SDL_MUSTLOCK(surface)) {
|
||||
SDL_LockSurface(surface);
|
||||
}
|
||||
|
||||
//Convert the pixels to 32 bit
|
||||
Uint32 *pixels = (Uint32 *)surface->pixels;
|
||||
|
||||
//Get the requested pixel
|
||||
return pixels[ ( y * surface->w ) + x ];
|
||||
|
||||
//Unlock when we are done.
|
||||
if(SDL_MUSTLOCK(surface))
|
||||
SDL_UnlockSurface(surface);
|
||||
}
|
||||
|
||||
void SDL_PutPixel32(SDL_Surface *surface, int x, int y, Uint32 pixel) {
|
||||
//Lock the surface.
|
||||
if(SDL_MUSTLOCK(surface)) {
|
||||
SDL_LockSurface(surface);
|
||||
}
|
||||
|
||||
//Convert the pixels to 32 bit
|
||||
Uint32 *pixels = (Uint32 *)surface->pixels;
|
||||
|
||||
//Set the pixel
|
||||
pixels[ ( y * surface->w ) + x ] = pixel;
|
||||
|
||||
//Unlock when we are done.
|
||||
if(SDL_MUSTLOCK(surface))
|
||||
SDL_UnlockSurface(surface);
|
||||
}
|
||||
|
||||
void SDL_DrawTextf(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Color colour, const char* text, ...) {
|
||||
char buffer[256];
|
||||
va_list args;
|
||||
|
@ -48,7 +115,7 @@ void SDL_LoadImage(SDL_Renderer *renderer, SDL_Texture **texture, char *path) {
|
|||
SDL_SetColorKey(imageSurface, SDL_TRUE, colorkey);
|
||||
*texture = SDL_CreateTextureFromSurface(renderer, imageSurface);
|
||||
} else {
|
||||
printf("Failed to load image: %c", path);
|
||||
printf("Failed to load image: %s", path);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(imageSurface);
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <switch.h>
|
||||
|
||||
#include "fs.h"
|
||||
|
||||
int FS_MakeDir(const char *path)
|
||||
{
|
||||
if (!path)
|
||||
return -1;
|
||||
|
||||
return mkdir(path, 0777);
|
||||
}
|
||||
|
||||
int FS_RecursiveMakeDir(const char * dir)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[256];
|
||||
char *p = NULL;
|
||||
size_t len;
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s",dir);
|
||||
len = strlen(buf);
|
||||
|
||||
if (buf[len - 1] == '/')
|
||||
buf[len - 1] = 0;
|
||||
|
||||
for (p = buf + 1; *p; p++)
|
||||
{
|
||||
if (*p == '/')
|
||||
{
|
||||
*p = 0;
|
||||
|
||||
ret = FS_MakeDir(buf);
|
||||
|
||||
*p = '/';
|
||||
}
|
||||
|
||||
ret = FS_MakeDir(buf);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool FS_FileExists(const char *path)
|
||||
{
|
||||
FILE *temp = fopen(path, "r");
|
||||
|
||||
if (temp == NULL)
|
||||
return false;
|
||||
|
||||
fclose(temp);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FS_DirExists(const char *path)
|
||||
{
|
||||
struct stat info;
|
||||
|
||||
if (stat(path, &info) != 0)
|
||||
return false;
|
||||
else if (info.st_mode & S_IFDIR)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *FS_GetFileExt(const char *filename)
|
||||
{
|
||||
const char *dot = strrchr(filename, '.');
|
||||
|
||||
if (!dot || dot == filename)
|
||||
return "";
|
||||
|
||||
return dot + 1;
|
||||
}
|
||||
|
||||
char *FS_GetFileModifiedTime(const char *filename)
|
||||
{
|
||||
struct stat attr;
|
||||
stat(filename, &attr);
|
||||
|
||||
return ctime(&attr.st_mtime);
|
||||
}
|
||||
|
||||
u64 FS_GetFileSize(const char *filename)
|
||||
{
|
||||
struct stat st;
|
||||
stat(filename, &st);
|
||||
|
||||
return st.st_size;
|
||||
}
|
|
@ -16,6 +16,8 @@ extern "C" {
|
|||
#include "common.h"
|
||||
#include "textures.h"
|
||||
#include "MenuChooser.h"
|
||||
#include "fs.h"
|
||||
#include "config.h"
|
||||
}
|
||||
|
||||
SDL_Renderer* RENDERER;
|
||||
|
@ -23,7 +25,7 @@ SDL_Window* WINDOW;
|
|||
//SDL_Surface* WINDOW_SURFACE;
|
||||
SDL_Event EVENT;
|
||||
TTF_Font *ARIAL, *ARIAL_35, *ARIAL_30, *ARIAL_27, *ARIAL_25, *ARIAL_20, *ARIAL_15;
|
||||
|
||||
bool configDarkMode;
|
||||
bool run = true;
|
||||
|
||||
void Term_Services() {
|
||||
|
@ -127,6 +129,10 @@ void Init_Services() {
|
|||
}
|
||||
}
|
||||
std::cout << "Initalized Input" << std::endl;
|
||||
|
||||
FS_RecursiveMakeDir("/switch/eBookReader/books");
|
||||
|
||||
configDarkMode = false;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
#include "LandscapePageLayout.hpp"
|
||||
#include "common.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
//#include <libconfig.h>
|
||||
|
||||
extern "C" {
|
||||
#include "SDL_helper.h"
|
||||
#include "status_bar.h"
|
||||
//#include "config.h"
|
||||
#include "config.h"
|
||||
}
|
||||
|
||||
fz_context *ctx = NULL;
|
||||
|
@ -128,10 +129,11 @@ void BookReader::switch_page_layout() {
|
|||
}
|
||||
|
||||
void BookReader::draw() {
|
||||
/*if (config_dark_theme == true)
|
||||
SDL_ClearScreen(RENDERER, SDL_MakeColour(33, 39, 43, 255));
|
||||
else */
|
||||
if (configDarkMode == true) {
|
||||
SDL_ClearScreen(RENDERER, BLACK);
|
||||
} else {
|
||||
SDL_ClearScreen(RENDERER, WHITE);
|
||||
}
|
||||
|
||||
SDL_RenderClear(RENDERER);
|
||||
|
||||
|
@ -144,13 +146,21 @@ void BookReader::draw() {
|
|||
int title_width = 0, title_height = 0;
|
||||
TTF_SizeText(ARIAL_15, title, &title_width, &title_height);
|
||||
|
||||
//SDL_Color color = config_dark_theme ? STATUS_BAR_DARK : STATUS_BAR_LIGHT;
|
||||
SDL_Color color = STATUS_BAR_LIGHT;
|
||||
SDL_Color color = configDarkMode ? STATUS_BAR_DARK : STATUS_BAR_LIGHT;
|
||||
|
||||
SDL_DrawRect(RENDERER, 0, 0, 1280, 45, SDL_MakeColour(color.r, color.g, color.b , 180));
|
||||
SDL_DrawText(RENDERER, ARIAL_25, (1280 - title_width) / 2, (40 - title_height) / 2, WHITE, title);
|
||||
if (_currentPageLayout == BookPageLayoutPortrait) {
|
||||
SDL_DrawRect(RENDERER, 0, 0, 1280, 45, SDL_MakeColour(color.r, color.g, color.b , 180));
|
||||
SDL_DrawText(RENDERER, ARIAL_25, (1280 - title_width) / 2, (40 - title_height) / 2, WHITE, title);
|
||||
|
||||
StatusBar_DisplayTime();
|
||||
StatusBar_DisplayTime(false);
|
||||
} else if (_currentPageLayout == BookPageLayoutLandscape) {
|
||||
SDL_DrawRect(RENDERER, 1280 - 45, 0, 45, 720, SDL_MakeColour(color.r, color.g, color.b , 180));
|
||||
int x = (1280 - title_width) - ((40 - title_height) / 2);
|
||||
int y = (720 - title_height) / 2;
|
||||
SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, x, y, WHITE, title);
|
||||
|
||||
StatusBar_DisplayTime(true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
#include "PageLayout.hpp"
|
||||
#include "common.h"
|
||||
#include <algorithm>
|
||||
|
||||
extern "C" {
|
||||
#include "common.h"
|
||||
#include "config.h"
|
||||
#include "SDL_helper.h"
|
||||
}
|
||||
|
||||
PageLayout::PageLayout(fz_document *doc, int current_page):doc(doc),pdf(pdf_specifics(ctx, doc)),pages_count(fz_count_pages(ctx, doc)) {
|
||||
_current_page = std::min(std::max(0, current_page), pages_count - 1);
|
||||
|
||||
|
@ -83,7 +88,12 @@ void PageLayout::render_page_to_texture(int num, bool reset_zoom) {
|
|||
|
||||
fz_pixmap *pix = fz_new_pixmap_from_page_contents(ctx, page, fz_scale(zoom, zoom), fz_device_rgb(ctx), 0);
|
||||
SDL_Surface *image = SDL_CreateRGBSurfaceFrom(pix->samples, pix->w, pix->h, pix->n * 8, pix->w * pix->n, 0x000000FF, 0x0000FF00, 0x00FF0000, 0);
|
||||
/*if (configDarkMode) {
|
||||
SDL_InvertSurfaceColor(image);
|
||||
}*/
|
||||
|
||||
page_texture = SDL_CreateTextureFromSurface(RENDERER, image);
|
||||
//SDL_SetTextureColorMod(&page_texture, page_texture)
|
||||
|
||||
SDL_FreeSurface(image);
|
||||
fz_drop_pixmap(ctx, pix);
|
||||
|
|
|
@ -100,12 +100,20 @@ static void StatusBar_GetBatteryStatus(int x, int y)
|
|||
}
|
||||
}
|
||||
|
||||
void StatusBar_DisplayTime(void) {
|
||||
void StatusBar_DisplayTime(bool portriat) {
|
||||
int width = 0, height = 0;
|
||||
TTF_SizeText(ARIAL_25, Clock_GetCurrentTime(), &width, &height);
|
||||
|
||||
#ifdef EXPERIMENTAL
|
||||
//StatusBar_GetBatteryStatus(1260 - width - 44, (40 - height) / 2);
|
||||
#endif
|
||||
SDL_DrawText(RENDERER, ARIAL_25, 1260 - width, (40 - height) / 2, WHITE, Clock_GetCurrentTime());
|
||||
if (portriat) {
|
||||
int x = (1280 - width) + height; //- ((45 - height) / 2);
|
||||
int y = (720 - width) + 15;
|
||||
SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, x, y, WHITE, Clock_GetCurrentTime());
|
||||
|
||||
//SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, 1270 - width, (720 - height), WHITE, Clock_GetCurrentTime());
|
||||
} else {
|
||||
SDL_DrawText(RENDERER, ARIAL_25, 1260 - width, (40 - height) / 2, WHITE, Clock_GetCurrentTime());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue