diff --git a/romfs/nop.png b/romfs/nop.png new file mode 100644 index 0000000..23e2741 Binary files /dev/null and b/romfs/nop.png differ diff --git a/source/Request.hpp b/source/JKanime.hpp similarity index 63% rename from source/Request.hpp rename to source/JKanime.hpp index 1aeba3c..9fa2716 100644 --- a/source/Request.hpp +++ b/source/JKanime.hpp @@ -1,107 +1,3 @@ -static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) -{ - ((std::string*)userp)->append((char*)contents, size * nmemb); - return size * nmemb; -} -size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { - size_t written = fwrite(ptr, size, nmemb, stream); - return written; -} - -int progress_func(void* ptr, double TotalToDownload, double NowDownloaded, - double TotalToUpload, double NowUploaded) -{ - - - // ensure that the file to be downloaded is not empty - // because that would cause a division by zero error later on - if (TotalToDownload <= 0.0) { - return 0; - } - - // how wide you want the progress meter to be - int totaldotz = 20; - double fractiondownloaded = NowDownloaded / TotalToDownload; - // part of the progressmeter that's already "full" - int dotz = round(fractiondownloaded * totaldotz); - - // create the "meter" - int ii = 0; - porcendown = fractiondownloaded * 100; - sizeestimated = TotalToDownload; - printf("%3.0f%% [", fractiondownloaded * 100); - // part that's full already - for (; ii < dotz; ii++) { - printf("="); - } - // remaining part (spaces) - for (; ii < 20; ii++) { - printf(" "); - } - // and back to line begin - do not forget the fflush to avoid output buffering problems! - printf("]\r"); - fflush(stdout); - // if you don't return 0, the transfer will be aborted - see the documentation - if (cancelcurl == 1) - { - return 1; - } - - return 0; - -} - -std::string gethtml(std::string enlace) -{ - - CURL *curl; - CURLcode res = CURLE_OK; - std::string Buffer; - - curl = curl_easy_init(); - if (curl) { - - curl_easy_setopt(curl, CURLOPT_URL, enlace.c_str()); - curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &Buffer); - res = curl_easy_perform(curl); - curl_easy_cleanup(curl); - if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));} - } - return Buffer; -} -void downloadfile(std::string enlace, std::string directorydown) -{ - - CURL *curl; - FILE *fp; - CURLcode res = CURLE_OK; - - curl = curl_easy_init(); - if (curl) { - - fp = fopen(directorydown.c_str(), "wb"); - curl_easy_setopt(curl, CURLOPT_URL, enlace.c_str()); - curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); - // Install the callback function - curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func); - res = curl_easy_perform(curl); - /* always cleanup */ - curl_easy_cleanup(curl); - fclose(fp); - if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));} - } -} int downloadjkanimevideo(void* data) { @@ -187,6 +83,7 @@ int downloadjkanimevideo(void* data) return 0; } + void onlinejkanimevideo(std::string onlineenlace) { #ifdef __SWITCH__ @@ -277,14 +174,20 @@ int ydistance = 448; void callimage() { #ifdef __SWITCH__ - std::string directorydownloadimage = "sdmc:/RipJKAnime/"; - directorydownloadimage.append(std::to_string(selectchapter)); + std::string temp = arrayimages[selectchapter]; + replace(temp,"https://cdn.jkanime.net/assets/images/animes/image/",""); + replace(temp,".jpg0", ""); + replace(temp,".jpg", ""); + + std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/"; + directorydownloadimage.append(temp); directorydownloadimage.append(".jpg"); #else std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/"; - directorydownloadimage.append(std::to_string(selectchapter)); + directorydownloadimage.append(temp); directorydownloadimage.append(".jpg"); #endif // SWITCH + printf("# %d imagen: %s \n",selectchapter,directorydownloadimage.c_str()); TPreview.loadFromFileCustom(directorydownloadimage.c_str(), sizeportraitx, sizeportraity); tempimage = directorydownloadimage; } @@ -292,16 +195,20 @@ void callimagesearch() { #ifdef __SWITCH__ - std::string directorydownloadimage = "sdmc:/RipJKAnime/s"; - directorydownloadimage.append(std::to_string(searchchapter)); + std::string temp = arraysearchimages[searchchapter]; + replace(temp,"https://cdn.jkanime.net/assets/images/animes/image/",""); + replace(temp,".jpg0", ""); + replace(temp,".jpg", ""); + std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/"; + directorydownloadimage.append(temp); directorydownloadimage.append(".jpg"); #else - std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/s"; - directorydownloadimage.append(std::to_string(searchchapter)); + std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/"; + directorydownloadimage.append(temp); directorydownloadimage.append(".jpg"); #endif // SWITCH - + TSearchPreview.loadFromFileCustom(directorydownloadimage.c_str(), sizeportraitx, sizeportraity); tempimage = directorydownloadimage; @@ -311,10 +218,7 @@ int refrescarpro(void* data) activatefirstimage = true; reloading = true; porcentajereload = 0; - int val1 = 1; - int val2; - int val3, val4; - int val0 = 0; + int val0 = 0, val1 = 1, val2, val3, val4; std::string temporal = ""; std::string content = gethtml("https://jkanime.net"); while (val0 != -1) { @@ -330,57 +234,39 @@ int refrescarpro(void* data) val4 = content.find('"', val3); std::string gpreview = content.substr(val3, val4 - val3); arrayimages.push_back(gpreview); + //std::cout << arraycount << ". " << gdrive << std::endl; temporal = temporal + gdrive + "\n"; temporal = temporal + gpreview + "\n"; + val1++; - } printf(temporal.c_str()); - - CURL *curl; - FILE *fp; - CURLcode res = CURLE_OK; - for (int x = 0; x < (int)arrayimages.size(); x++) { - curl = curl_easy_init(); - if (curl) { std::string tempima = arrayimages[x]; - std::cout << tempima << selectchapter << std::endl; + replace(tempima,"https://cdn.jkanime.net/assets/images/animes/image/",""); + replace(tempima,".jpg0", ""); + replace(tempima,".jpg", ""); #ifdef __SWITCH__ - std::string directorydownloadimage = "sdmc:/RipJKAnime/"; - directorydownloadimage.append(std::to_string(x)); + std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/"; + directorydownloadimage.append(tempima); directorydownloadimage.append(".jpg"); #else std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/" ; - directorydownloadimage.append(std::to_string(x)); + directorydownloadimage.append(tempima); directorydownloadimage.append(".jpg"); #endif // SWITCH - - fp = fopen(directorydownloadimage.c_str(), "wb"); - curl_easy_setopt(curl, CURLOPT_URL, tempima.c_str()); - curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); - res = curl_easy_perform(curl); - /* always cleanup */ - curl_easy_cleanup(curl); - fclose(fp); - if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));} - - } + printf("# %d imagen: %s \n",x,tempima.c_str()); + if(!isFileExist(directorydownloadimage.c_str())) + downloadfile(arrayimages[x],directorydownloadimage,false); + porcentajereload = ((x+1) * 100) / arrayimages.size(); } - reloading = false; preview = true; - return 0; } @@ -411,11 +297,6 @@ int searchjk(void* data) int val2; int val0 = 0; - - - - - while (val0 != -1) { val0 = content.find("portada-title", val1); if (val0 == -1) { break; } @@ -436,40 +317,21 @@ int searchjk(void* data) } for (int x = 0; x < (int)arraysearchimages.size(); x++) { - CURL *curl; - FILE *fp; - CURLcode res = CURLE_OK; - - - curl = curl_easy_init(); - if (curl) { std::string tempima = arraysearchimages[x]; - std::cout << tempima << selectchapter << std::endl; + replace(tempima,"https://cdn.jkanime.net/assets/images/animes/image/",""); + replace(tempima,".jpg0", ""); + replace(tempima,".jpg", ""); #ifdef __SWITCH__ - std::string directorydownloadimage = "sdmc:/RipJKAnime/s"; - directorydownloadimage.append(std::to_string(x)); + std::string directorydownloadimage = "sdmc:/switch/RipJKAnime_NX/DATA/"; + directorydownloadimage.append(tempima); directorydownloadimage.append(".jpg"); #else - std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/s"; - directorydownloadimage.append(std::to_string(x)); + std::string directorydownloadimage = "C:/respaldo2017/C++/test/Debug/RipJKAnime/"; + directorydownloadimage.append(tempima); directorydownloadimage.append(".jpg"); #endif // SWITCH - - fp = fopen(directorydownloadimage.c_str(), "wb"); - curl_easy_setopt(curl, CURLOPT_URL, tempima.c_str()); - curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); - res = curl_easy_perform(curl); - /* always cleanup */ - curl_easy_cleanup(curl); - fclose(fp); - if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));} - - } + if(!isFileExist(directorydownloadimage.c_str())) + downloadfile(arraysearchimages[x],directorydownloadimage,false); porcentajereload = ((x + 1) * 100) / arraysearchimages.size(); } @@ -574,4 +436,41 @@ std::string capit(std::string b) { } -}; \ No newline at end of file +}; + +bool isFavorite(std::string fav){ + static std::string limit = ""; + if (limit == fav){ + return gFAV; + } else limit = fav; + std::ifstream file(favoritosdirectory); + std::string str; + while (std::getline(file, str)) { + // std::cout << str << "\n"; + if (str.find("jkanime")) + {printf("-%s-- -%s--\n",fav.c_str(),str.c_str()); + if (fav == str){file.close(); return true;} + } + } +file.close(); +return false; +} +void delFavorite(int inst = -1){ + + std::string tmp=""; + if (inst > 0){//delete all if is -1 delFavorite(); + std::ifstream file(favoritosdirectory); + std::string str = ""; + + int index = 0; + while (std::getline(file, str)) { + if (inst != index){tmp += str+"\n";} + index++; + } + file.close(); + } + + std::ofstream outfile(favoritosdirectory); + outfile << tmp; + outfile.close(); +} \ No newline at end of file diff --git a/source/Networking.cpp b/source/Networking.cpp new file mode 100644 index 0000000..bd58396 --- /dev/null +++ b/source/Networking.cpp @@ -0,0 +1,165 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Networking.hpp" + +extern int porcendown; +extern int sizeestimated; +extern int cancelcurl; + +//Write file in mem to increase download speed on 3 or 5 times + +struct MemoryStruct +{ + char *memory; + size_t size; + int mode; +}; + +static size_t write_memory_callback(void *contents, size_t size, size_t nmemb, void *userdata) +{ + size_t realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)userdata; + + char *ptr = (char*)realloc(mem->memory, mem->size + realsize + 1); + + if (ptr == NULL) + { + printf("Failed to realloc mem"); + return 0; + } + + mem->memory = ptr; + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + + return realsize; +} + +static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) +{ + ((std::string*)userp)->append((char*)contents, size * nmemb); + return size * nmemb; +} +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { + size_t written = fwrite(ptr, size, nmemb, stream); + return written; +} + +int progress_func(void* ptr, double TotalToDownload, double NowDownloaded, + double TotalToUpload, double NowUploaded) +{ + + + // ensure that the file to be downloaded is not empty + // because that would cause a division by zero error later on + if (TotalToDownload <= 0.0) { + return 0; + } + + // how wide you want the progress meter to be + int totaldotz = 20; + double fractiondownloaded = NowDownloaded / TotalToDownload; + // part of the progressmeter that's already "full" + int dotz = round(fractiondownloaded * totaldotz); + + // create the "meter" + int ii = 0; + porcendown = fractiondownloaded * 100; + sizeestimated = TotalToDownload; + printf("%3.0f%% [", fractiondownloaded * 100); + // part that's full already + for (; ii < dotz; ii++) { + printf("="); + } + // remaining part (spaces) + for (; ii < 20; ii++) { + printf(" "); + } + // and back to line begin - do not forget the fflush to avoid output buffering problems! + printf("]\r"); + fflush(stdout); + // if you don't return 0, the transfer will be aborted - see the documentation + if (cancelcurl == 1) + { + return 1; + } + + return 0; + +} + +std::string gethtml(std::string enlace) +{ + + CURL *curl; + CURLcode res = CURLE_OK; + std::string Buffer; + + curl = curl_easy_init(); + if (curl) { + + curl_easy_setopt(curl, CURLOPT_URL, enlace.c_str()); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &Buffer); + res = curl_easy_perform(curl); + curl_easy_cleanup(curl); + if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));} + } + return Buffer; +} +void downloadfile(std::string enlace, std::string directorydown,bool progress) +{ + + CURL *curl; + FILE *fp = fopen(directorydown.c_str(), "wb");; + CURLcode res = CURLE_OK; + + curl = curl_easy_init(); + if (curl) { + if(fp){ + struct MemoryStruct chunk; + chunk.memory = (char*)malloc(1); + chunk.size = 0; + curl_easy_setopt(curl, CURLOPT_URL, enlace.c_str()); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_memory_callback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + // Install the callback function + if (progress){ + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_func); + } else { + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); + } + + res = curl_easy_perform(curl); + fwrite(chunk.memory, 1, chunk.size, fp);// write from mem to file + /* always cleanup */ + curl_easy_cleanup(curl); + free(chunk.memory); + } + fclose(fp); + if (res != CURLE_OK){printf("\n%s\n",curl_easy_strerror(res));} + } +} + + diff --git a/source/Networking.hpp b/source/Networking.hpp new file mode 100644 index 0000000..e799117 --- /dev/null +++ b/source/Networking.hpp @@ -0,0 +1,6 @@ +#include +#include +#include + +std::string gethtml(std::string enlace); +void downloadfile(std::string enlace, std::string directorydown,bool progress = true); \ No newline at end of file diff --git a/source/SDLWork.cpp b/source/SDLWork.cpp new file mode 100644 index 0000000..6223edd --- /dev/null +++ b/source/SDLWork.cpp @@ -0,0 +1,297 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "SDLWork.hpp" + +extern LTexture gTextTexture; +extern TTF_Font *gFont; +extern SDL_Renderer* gRenderer; +LTexture::LTexture() +{ + //Initialize + mTexture = NULL; + mWidth = 0; + mHeight = 0; +} + +LTexture::~LTexture() +{ + //Deallocate + free(); +} + +bool LTexture::loadFromFile(std::string path) +{ + //Get rid of preexisting texture + free(); + + //The final texture + SDL_Texture* newTexture = NULL; + + //Load image at specified path + SDL_Surface* loadedSurface = IMG_Load(path.c_str()); + if (loadedSurface == NULL) + { + printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError()); + } + else + { + //Color key image + SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF)); + + //Create texture from surface pixels + newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface); + if (newTexture == NULL) + { + printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError()); + } + else + { + //Get image dimensions + mWidth = loadedSurface->w; + mHeight = loadedSurface->h; + } + + //Get rid of old loaded surface + SDL_FreeSurface(loadedSurface); + } + + //Return success + mTexture = newTexture; + return mTexture != NULL; +} +bool LTexture::loadFromFileCustom(std::string path, int h, int w) +{ + //Get rid of preexisting texture + free(); + + //The final texture + SDL_Texture* newTexture = NULL; + + //Load image at specified path + SDL_Surface* loadedSurface = IMG_Load(path.c_str()); + if (loadedSurface == NULL) + { + printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError()); + if(std::string(IMG_GetError()) == "Unsupported image format") remove(path.c_str()); + } + else + { + //Color key image + SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF)); + + //Create texture from surface pixels + newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface); + if (newTexture == NULL) + { + printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError()); + } + else + { + //Get image dimensions + mWidth = w; + mHeight = h; + } + + //Get rid of old loaded surface + SDL_FreeSurface(loadedSurface); + } + + //Return success + mTexture = newTexture; + return mTexture != NULL; +} +bool LTexture::loadFromRenderedText(TTF_Font *fuente, std::string textureText, SDL_Color textColor) +{ + //Get rid of preexisting texture + free(); + + //Render text surface + SDL_Surface* textSurface = TTF_RenderText_Blended(fuente, textureText.c_str(), textColor); + + if (textSurface == NULL) + { + printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError()); + } + else + { + //Create texture from surface pixels + mTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface); + if (mTexture == NULL) + { + printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError()); + } + else + { + //Get image dimensions + mWidth = textSurface->w; + mHeight = textSurface->h; + } + + //Get rid of old surface + SDL_FreeSurface(textSurface); + } + + //Return success + return mTexture != NULL; +} +bool LTexture::loadFromRenderedTextWrap(TTF_Font *fuente, std::string textureText, SDL_Color textColor, Uint32 size) +{ + //Get rid of preexisting texture + free(); + + //Render text surface + SDL_Surface* textSurface = TTF_RenderUTF8_Blended_Wrapped(fuente, textureText.c_str(), textColor, size); + + if (textSurface == NULL) + { + printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError()); + } + else + { + //Create texture from surface pixels + mTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface); + if (mTexture == NULL) + { + printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError()); + } + else + { + //Get image dimensions + mWidth = textSurface->w; + mHeight = textSurface->h; + } + + //Get rid of old surface + SDL_FreeSurface(textSurface); + } + + //Return success + return mTexture != NULL; +} + +void LTexture::free() +{ + //Free texture if it exists + if (mTexture != NULL) + { + SDL_DestroyTexture(mTexture); + mTexture = NULL; + mWidth = 0; + mHeight = 0; + } +} + +void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue) +{ + //Modulate texture rgb + SDL_SetTextureColorMod(mTexture, red, green, blue); +} + +void LTexture::setBlendMode(SDL_BlendMode blending) +{ + //Set blending function + SDL_SetTextureBlendMode(mTexture, blending); +} + +void LTexture::setAlpha(Uint8 alpha) +{ + //Modulate texture alpha + SDL_SetTextureAlphaMod(mTexture, alpha); +} + +void LTexture::render(int x, int y, SDL_Rect* clip, double angle, SDL_Point* center, SDL_RendererFlip flip) +{ + //Set rendering space and render to screen + SDL_Rect renderQuad = { x, y, mWidth, mHeight }; + + //Set clip rendering dimensions + if (clip != NULL) + { + renderQuad.w = clip->w; + renderQuad.h = clip->h; + } + + //Render to screen + SDL_RenderCopyEx(gRenderer, mTexture, clip, &renderQuad, angle, center, flip); +} + +int LTexture::getWidth() +{ + return mWidth; +} + +int LTexture::getHeight() +{ + return mHeight; +} + +void DrawImageFile(SDL_Renderer* gRenderer,std::string path,int X, int Y,std::string Text){ + + SDL_Surface* DrawImg; + DrawImg = IMG_Load(path.c_str()); + int DW=0,DH=0; + if (DrawImg == NULL) + { + printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError()); + }else{ + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); + SDL_Texture* CLUST = SDL_CreateTextureFromSurface(gRenderer, DrawImg); + + SDL_Rect ImagetRect2 = {X, Y, DrawImg->w, DrawImg->h}; + SDL_RenderCopy(gRenderer, CLUST , NULL, &ImagetRect2); + SDL_DestroyTexture(CLUST); + DW=DrawImg->w; + DH=DrawImg->h; + } + + + if (Text.length()){ + SDL_Color textColor = { 50, 50, 50 }; + gTextTexture.loadFromRenderedText(gFont, Text.c_str(), textColor); + gTextTexture.render(X+DW+3, Y +(DH/3)); + } + SDL_FreeSurface(DrawImg); +} + +void DrawImageCover(SDL_Renderer* gRenderer,std::string path,int X, int Y,std::string Text,int scale){ + + SDL_Surface* DrawImg; + DrawImg = IMG_Load(path.c_str()); + int DW=0,DH=0; + if (DrawImg == NULL) + { + printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError()); + }else{ + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); + SDL_Texture* CLUST = SDL_CreateTextureFromSurface(gRenderer, DrawImg); + + int WS = (DrawImg->w * (scale * 1000 /DrawImg->h) /1000); + SDL_Rect ImagetRect2 = {X, Y, WS, scale}; + SDL_RenderCopy(gRenderer, CLUST , NULL, &ImagetRect2); + SDL_DestroyTexture(CLUST); + DW=DrawImg->w; + DH=DrawImg->h; + } + + + if (Text.length()){ + SDL_Color textColor = { 50, 50, 50 }; + gTextTexture.loadFromRenderedText(gFont, Text.c_str(), textColor); + gTextTexture.render(X+DW+3, Y +(DH/3)); + } + SDL_FreeSurface(DrawImg); +} diff --git a/source/SDLWork.hpp b/source/SDLWork.hpp index 61dd43f..e4f535a 100644 --- a/source/SDLWork.hpp +++ b/source/SDLWork.hpp @@ -44,272 +44,10 @@ class LTexture int mHeight; }; +void DrawImageCover(SDL_Renderer* gRenderer,std::string path,int X, int Y,std::string Text = "",int scale = 100); +void DrawImageFile(SDL_Renderer* gRenderer,std::string path,int X, int Y,std::string Text = ""); -//The window we'll be rendering to -SDL_Window* gWindow = NULL; -//The window renderer -SDL_Renderer* gRenderer = NULL; -#ifdef __SWITCH__ -HidsysNotificationLedPattern blinkLedPattern(u8 times); -void blinkLed(u8 times); -#endif // ___SWITCH___ -//Globally used font -TTF_Font *gFont = NULL; -TTF_Font* digifont = NULL; -TTF_Font *gFontcapit = NULL; -TTF_Font *gFont2 = NULL; -TTF_Font *gFont3 = NULL; -//Rendered texture -LTexture gTextTexture; -LTexture Farest; -LTexture Heart; -LTexture TChapters; -LTexture TPreview; -LTexture TSearchPreview; -LTexture::LTexture() -{ - //Initialize - mTexture = NULL; - mWidth = 0; - mHeight = 0; -} - -LTexture::~LTexture() -{ - //Deallocate - free(); -} - -bool LTexture::loadFromFile(std::string path) -{ - //Get rid of preexisting texture - free(); - - //The final texture - SDL_Texture* newTexture = NULL; - - //Load image at specified path - SDL_Surface* loadedSurface = IMG_Load(path.c_str()); - if (loadedSurface == NULL) - { - printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError()); - } - else - { - //Color key image - SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF)); - - //Create texture from surface pixels - newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface); - if (newTexture == NULL) - { - printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError()); - } - else - { - //Get image dimensions - mWidth = loadedSurface->w; - mHeight = loadedSurface->h; - } - - //Get rid of old loaded surface - SDL_FreeSurface(loadedSurface); - } - - //Return success - mTexture = newTexture; - return mTexture != NULL; -} -bool LTexture::loadFromFileCustom(std::string path, int h, int w) -{ - //Get rid of preexisting texture - free(); - - //The final texture - SDL_Texture* newTexture = NULL; - - //Load image at specified path - SDL_Surface* loadedSurface = IMG_Load(path.c_str()); - if (loadedSurface == NULL) - { - printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError()); - } - else - { - //Color key image - SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface->format, 0, 0xFF, 0xFF)); - - //Create texture from surface pixels - newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface); - if (newTexture == NULL) - { - printf("Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError()); - } - else - { - //Get image dimensions - mWidth = w; - mHeight = h; - } - - //Get rid of old loaded surface - SDL_FreeSurface(loadedSurface); - } - - //Return success - mTexture = newTexture; - return mTexture != NULL; -} -bool LTexture::loadFromRenderedText(TTF_Font *fuente, std::string textureText, SDL_Color textColor) -{ - //Get rid of preexisting texture - free(); - - //Render text surface - SDL_Surface* textSurface = TTF_RenderText_Blended(fuente, textureText.c_str(), textColor); - - if (textSurface == NULL) - { - printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError()); - } - else - { - //Create texture from surface pixels - mTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface); - if (mTexture == NULL) - { - printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError()); - } - else - { - //Get image dimensions - mWidth = textSurface->w; - mHeight = textSurface->h; - } - - //Get rid of old surface - SDL_FreeSurface(textSurface); - } - - //Return success - return mTexture != NULL; -} -bool LTexture::loadFromRenderedTextWrap(TTF_Font *fuente, std::string textureText, SDL_Color textColor, Uint32 size) -{ - //Get rid of preexisting texture - free(); - - //Render text surface - SDL_Surface* textSurface = TTF_RenderUTF8_Blended_Wrapped(fuente, textureText.c_str(), textColor, size); - - if (textSurface == NULL) - { - printf("Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError()); - } - else - { - //Create texture from surface pixels - mTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface); - if (mTexture == NULL) - { - printf("Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError()); - } - else - { - //Get image dimensions - mWidth = textSurface->w; - mHeight = textSurface->h; - } - - //Get rid of old surface - SDL_FreeSurface(textSurface); - } - - //Return success - return mTexture != NULL; -} - -void LTexture::free() -{ - //Free texture if it exists - if (mTexture != NULL) - { - SDL_DestroyTexture(mTexture); - mTexture = NULL; - mWidth = 0; - mHeight = 0; - } -} - -void LTexture::setColor(Uint8 red, Uint8 green, Uint8 blue) -{ - //Modulate texture rgb - SDL_SetTextureColorMod(mTexture, red, green, blue); -} - -void LTexture::setBlendMode(SDL_BlendMode blending) -{ - //Set blending function - SDL_SetTextureBlendMode(mTexture, blending); -} - -void LTexture::setAlpha(Uint8 alpha) -{ - //Modulate texture alpha - SDL_SetTextureAlphaMod(mTexture, alpha); -} - -void LTexture::render(int x, int y, SDL_Rect* clip, double angle, SDL_Point* center, SDL_RendererFlip flip) -{ - //Set rendering space and render to screen - SDL_Rect renderQuad = { x, y, mWidth, mHeight }; - - //Set clip rendering dimensions - if (clip != NULL) - { - renderQuad.w = clip->w; - renderQuad.h = clip->h; - } - - //Render to screen - SDL_RenderCopyEx(gRenderer, mTexture, clip, &renderQuad, angle, center, flip); -} - -int LTexture::getWidth() -{ - return mWidth; -} - -int LTexture::getHeight() -{ - return mHeight; -} - -void DrawImageFile(SDL_Renderer* gRenderer,std::string ImgPath,int X, int Y,std::string Text = ""){ - - SDL_Surface* DrawImg; - DrawImg = IMG_Load(ImgPath.c_str()); - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); - SDL_Texture* CLUST = SDL_CreateTextureFromSurface(gRenderer, DrawImg); -/* int XM = 695,YM = 75, WM = 260, HM = 280, - WS = (DrawImg->w * (HM * 1000 /DrawImg->h) /1000),HS = (DrawImg->h * (WM * 1000 /DrawImg->w) /1000), - WT = WS > WM ? WM : WS,HT = WS > WM ? HS : HM, - XT = XM + (WS < WM ? (WM - WS)/2 : 0),YT = YM + (WS > WM ? (HM - HS) : 0);// printf("print size: %dx%d\n",WS,HM); - SDL_Rect ImagetRect2 = {XT, YT, WT, HT}; -*/ - SDL_Rect ImagetRect2 = {X, Y, DrawImg->w, DrawImg->h}; - SDL_RenderCopy(gRenderer, CLUST , NULL, &ImagetRect2); - - - if (Text.length()){ - SDL_Color textColor = { 50, 50, 50 }; - gTextTexture.loadFromRenderedText(gFont, Text.c_str(), textColor); - gTextTexture.render(X+DrawImg->w+3, Y +(DrawImg->h/3)); - } - SDL_DestroyTexture(CLUST); - SDL_FreeSurface(DrawImg); -} diff --git a/source/main.cpp b/source/main.cpp index 6983ece..1783297 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -7,9 +7,7 @@ #define _CRT_SECURE_NO_WARNINGS #endif - //test - #include #include #include @@ -29,10 +27,11 @@ #include #include #include - - +#include "Networking.hpp" +#include "SDLWork.hpp" #ifdef __SWITCH__ #include + extern u32 __nx_applet_exit_mode; SwkbdTextCheckResult Keyboard_ValidateText(char *string, size_t size) { @@ -75,9 +74,7 @@ const char *Keyboard_GetText(const char *guide_text, const char *initial_text) { #endif - - -bool isFileExist(const char *file) +bool isFileExist(const char *file) { struct stat st = { 0 }; @@ -117,12 +114,13 @@ std::string searchtext = ""; std::string tempimage = ""; std::string txtyase = ""; +bool gFAV = false; bool AppletMode=false; bool isSXOS=false; bool hasStealth=false; #ifdef __SWITCH__ -std::string favoritosdirectory = "sdmc:/favoritos.txt"; +std::string favoritosdirectory = "sdmc:/switch/RipJKAnime_NX/favoritos.txt"; #else std::string favoritosdirectory = "C:/respaldo2017/C++/test/Debug/favoritos.txt"; #endif // SWITCH @@ -130,11 +128,34 @@ Mix_Music* gMusic = NULL; std::ofstream outfile; //Frees media and shuts down SDL void close(); +#ifdef __SWITCH__ +HidsysNotificationLedPattern blinkLedPattern(u8 times); +void blinkLed(u8 times); +#endif // ___SWITCH___ + //make some includes to clean alittle the main -#include "SDLWork.hpp" +//Globally used font +TTF_Font *gFont = NULL; +TTF_Font* digifont = NULL; +TTF_Font *gFontcapit = NULL; +TTF_Font *gFont2 = NULL; +TTF_Font *gFont3 = NULL; +//Rendered texture +LTexture gTextTexture; +LTexture Farest; +LTexture Heart; +LTexture TChapters; +LTexture TPreview; +LTexture TSearchPreview; +//The window we'll be rendering to +SDL_Window* gWindow = NULL; + +//The window renderer +SDL_Renderer* gRenderer = NULL; + #include "utils.hpp" -#include "Request.hpp" +#include "JKanime.hpp" //MAIN INT @@ -145,15 +166,16 @@ int main(int argc, char **argv) socketInitializeDefault(); //nxlinkStdio(); struct stat st = { 0 }; - - if (stat("sdmc:/RipJKAnime", &st) == -1) { - mkdir("sdmc:/RipJKAnime", 0777); + nxlinkStdio(); + printf("printf output now goes to nxlink server\n"); + mkdir("sdmc:/switch/RipJKAnime_NX", 0777); + mkdir("sdmc:/switch/RipJKAnime_NX/DATA", 0777); + if (stat("sdmc:/RipJKAnime", &st) != -1) { + fsdevDeleteDirectoryRecursively("sdmc:/RipJKAnime"); } -#endif - - AppletType at = appletGetAppletType(); if (at != AppletType_Application && at != AppletType_SystemApplication) {AppletMode=true;} +#endif // int val1 = 1; @@ -366,7 +388,7 @@ quit=1; switch (statenow) { case searchstate: - if (reloadingsearch == false) + if (!reloadingsearch) { TSearchPreview.free(); if (searchchapter < (int)arraysearch.size() - 1) @@ -384,7 +406,7 @@ quit=1; break; case programationstate: - if (reloading == false) + if (!reloading) { TPreview.free(); @@ -436,7 +458,7 @@ quit=1; switch (statenow) { case programationstate: - if (reloading == false) + if (!reloading) { TPreview.free(); if (selectchapter > 0) @@ -465,7 +487,7 @@ quit=1; break; case searchstate: - if (reloadingsearch == false) + if (!reloadingsearch) { TSearchPreview.free(); if (searchchapter > 0) @@ -501,7 +523,7 @@ quit=1; { case programationstate: - {if (reloading == false) + {if (!reloading&&arraychapter.size()>=1) { TChapters.free(); TChapters.loadFromFileCustom(tempimage, 550, 400); @@ -530,7 +552,7 @@ quit=1; case searchstate: { - if (reloadingsearch == false) + if (!reloadingsearch&&arraysearch.size()>=1) { TChapters.free(); TChapters.loadFromFileCustom(tempimage, 550, 400); @@ -617,7 +639,7 @@ quit=1; break; case searchstate: - if (reloadingsearch == false) + if (!reloadingsearch) { returnnow = toprogramation; @@ -648,11 +670,12 @@ quit=1; break; case chapterstate: {//AGREGAR A FAVORITOS - + if(!isFavorite(temporallink)){ outfile.open(favoritosdirectory, std::ios_base::app); // append instead of overwrite outfile << temporallink; outfile << "\n"; outfile.close(); + } txtyase = "(Ya se agregó)"; } @@ -665,7 +688,7 @@ quit=1; ofs.close(); - if (reloading == false) + if (!reloading) { arrayfavorites.clear(); statenow = favoritesstate; @@ -721,7 +744,7 @@ quit=1; switch (statenow) { case programationstate: - if (reloading == false) + if (!reloading) { arrayfavorites.clear(); statenow = favoritesstate; @@ -886,7 +909,7 @@ quit=1; switch (statenow) { case programationstate: - if (reloadingsearch == false) + if (!reloadingsearch) { searchchapter = 0; @@ -969,7 +992,7 @@ quit=1; { case programationstate: - {if (reloading == false) + {if (!reloading&&arraychapter.size()>=1) { TChapters.free(); TChapters.loadFromFileCustom(tempimage, 550, 400); @@ -998,7 +1021,7 @@ quit=1; case searchstate: { - if (reloadingsearch == false) + if (!reloadingsearch && arraysearch.size()>=1) { TChapters.free(); TChapters.loadFromFileCustom(tempimage, 550, 400); @@ -1025,7 +1048,7 @@ quit=1; case favoritesstate: { - + if ((int)arrayfavorites.size() >= 1 ){ TChapters.free(); TChapters.loadFromFileCustom(tempimage, 550, 400); statenow = chapterstate; @@ -1044,6 +1067,7 @@ quit=1; capmore = maxcapit; } std::cout << maxcapit << std::endl; + } } @@ -1135,44 +1159,21 @@ quit=1; switch (statenow) { case programationstate: - if (reloading == false) - { - arrayfavorites.clear(); - statenow = favoritesstate; - std::string temp; - std::ifstream infile; - - std::ifstream file(favoritosdirectory); - std::string str; - while (std::getline(file, str)) { - std::cout << str << "\n"; - if (str.find("jkanime")) - { - arrayfavorites.push_back(str); - } - } - file.close(); - - - } break; case downloadstate: - - break; case chapterstate: - break; case searchstate: - break; case favoritesstate: - - statenow = programationstate; + delFavorite(); + favchapter=0; + arrayfavorites.clear(); break; } @@ -1206,7 +1207,7 @@ quit=1; break; case searchstate: - if (reloadingsearch == false) + if (!reloadingsearch) { returnnow = toprogramation; @@ -1262,8 +1263,26 @@ quit=1; switch (statenow) { case programationstate: + if (!reloading) + { + arrayfavorites.clear(); + statenow = favoritesstate; + std::string temp; + std::ifstream infile; + + std::ifstream file(favoritosdirectory); + std::string str; + while (std::getline(file, str)) { + std::cout << str << "\n"; + if (str.find("jkanime")) + { + arrayfavorites.push_back(str); + } + } + file.close(); + } break; case downloadstate: @@ -1272,25 +1291,24 @@ quit=1; break; case chapterstate: {//AGREGAR A FAVORITOS - - outfile.open(favoritosdirectory, std::ios_base::app); // append instead of overwrite - outfile << temporallink; - outfile << "\n"; - outfile.close(); + if(!isFavorite(temporallink)){ + outfile.open(favoritosdirectory, std::ios_base::app); // append instead of overwrite + outfile << temporallink; + outfile << "\n"; + outfile.close(); txtyase = "(Ya se agregó)"; + } + gFAV = true; } break; case favoritesstate: - std::ofstream ofs(favoritosdirectory, std::ofstream::trunc); - - ofs << ""; - - ofs.close(); + delFavorite(favchapter); - if (reloading == false) + if (!reloading) { + favchapter--; arrayfavorites.clear(); statenow = favoritesstate; std::string temp; @@ -1321,7 +1339,7 @@ quit=1; switch (statenow) { case programationstate: - if (reloadingsearch == false) + if (!reloadingsearch) { #ifdef __SWITCH__ //blinkLed(1);//LED @@ -1334,7 +1352,7 @@ quit=1; returnnow = tosearch; char *buf = (char*)malloc(256); #ifdef __SWITCH__ - strcpy(buf, Keyboard_GetText("Buscar Anime (3 letras minimo.)", "")); + strcpy(buf, Keyboard_GetText("Buscar Anime (3 letras minimo.)", searchtext.c_str())); #endif // SWITCH @@ -1401,7 +1419,7 @@ quit=1; switch (statenow) { case programationstate: - if (reloading == false) + if (!reloading) { TPreview.free(); if (selectchapter > 0) @@ -1430,7 +1448,7 @@ quit=1; break; case searchstate: - if (reloadingsearch == false) + if (!reloadingsearch) { TSearchPreview.free(); if (searchchapter > 0) @@ -1465,7 +1483,7 @@ quit=1; switch (statenow) { case searchstate: - if (reloadingsearch == false) + if (!reloadingsearch) { TSearchPreview.free(); if (searchchapter < (int)arraysearch.size() - 1) @@ -1483,7 +1501,7 @@ quit=1; break; case programationstate: - if (reloading == false) + if (!reloading) { TPreview.free(); @@ -1639,18 +1657,20 @@ quit=1; gTextTexture.loadFromRenderedTextWrap(gFont, rese, textColor, 750); gTextTexture.render(posxbase, posybase + 65); + + gFAV = isFavorite(temporallink); + //Draw Footer Buttons int dist = 1120,posdist = 130; DrawImageFile(gRenderer,"romfs:/buttons/A.png",dist, 680,"Ver Online");dist -= posdist; DrawImageFile(gRenderer,"romfs:/buttons/B.png",dist, 680,"Atras");dist -= posdist; DrawImageFile(gRenderer,"romfs:/buttons/L.png",dist, 680,"AnimeFLV");dist -= posdist; - if(!txtyase.length()){ - DrawImageFile(gRenderer,"romfs:/buttons/Y.png",dist, 680,"Favorito");dist -= posdist; - }else { + if(gFAV){ DrawImageFile(gRenderer,"romfs:/buttons/FAV.png",dist, 680,"Favorito");dist -= posdist; + }else { + DrawImageFile(gRenderer,"romfs:/buttons/Y.png",dist, 680,"Favorito");dist -= posdist; } - DrawImageFile(gRenderer,"romfs:/buttons/MINUS.png",dist, 680,"Música");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/PLUS.png",dist, 680,"Salir");dist -= posdist; + } @@ -1658,7 +1678,7 @@ quit=1; case programationstate: - if (reloading == false) { + if (!reloading&&arraychapter.size()>=1) { {//Draw a rectagle to a nice view SDL_SetRenderDrawColor(gRenderer, 200, 200, 200, 105); SDL_Rect HeaderRect = {0,0, 620, 670}; @@ -1680,8 +1700,7 @@ quit=1; SDL_RenderFillRect(gRenderer, &HeaderRect);} gTextTexture.render(posxbase, posybase + (x * 22)); - gTextTexture.loadFromRenderedText(digifont, ">", { 0,0,0 }); - gTextTexture.render(posxbase-10, posybase + (x * 22)); + Heart.render(posxbase - 18, posybase + 3 + (x * 22)); } else { @@ -1715,9 +1734,7 @@ quit=1; DrawImageFile(gRenderer,"romfs:/buttons/A.png",dist, 680,"Aceptar");dist -= posdist; DrawImageFile(gRenderer,"romfs:/buttons/R.png",dist, 680,"Buscar");dist -= posdist; DrawImageFile(gRenderer,"romfs:/buttons/L.png",dist, 680,"AnimeFLV");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/ZR.png",dist, 680,"Favoritos");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/MINUS.png",dist, 680,"Música");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/PLUS.png",dist, 680,"Salir");dist -= posdist; + DrawImageFile(gRenderer,"romfs:/buttons/Y.png",dist, 680,"Favoritos");dist -= posdist; /*{ SDL_Rect fillRect = { 0, SCREEN_HEIGHT - 35, 1280, 25 }; SDL_SetRenderDrawColor(gRenderer, 255, 255, 255, 255); @@ -1750,112 +1767,121 @@ quit=1; } break; case searchstate: - if (reloadingsearch == false) { - {//Draw a rectagle to a nice view - SDL_SetRenderDrawColor(gRenderer, 100, 100, 100, 105); - SDL_Rect HeaderRect = {0,0, 620, 670}; - SDL_RenderFillRect(gRenderer, &HeaderRect);} + if (!reloadingsearch) { //Draw Header gTextTexture.loadFromRenderedText(gFont, "Busqueda", {100,0,0}); gTextTexture.render(SCREEN_WIDTH - gTextTexture.getWidth() - 30, 20); + if ((int)arraysearch.size() >= 1){ + + + {//Draw a rectagle to a nice view + SDL_SetRenderDrawColor(gRenderer, 100, 100, 100, 105); + SDL_Rect HeaderRect = {0,0, 620, 670}; + SDL_RenderFillRect(gRenderer, &HeaderRect);} - for (int x = 0; x < (int)arraysearch.size(); x++) { - std::string temptext = arraysearch[x]; - - replace(temptext, "https://jkanime.net/", ""); - replace(temptext, "/", " "); - replace(temptext, "-", " "); - mayus(temptext); - if (x == searchchapter) { - gTextTexture.loadFromRenderedText(digifont, temptext, { 255,255,255 }); - {SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 105); - SDL_Rect HeaderRect = {posxbase-2,posybase + (x * 22), 590, gTextTexture.getHeight()}; - SDL_RenderFillRect(gRenderer, &HeaderRect);} - gTextTexture.render(posxbase, posybase + (x * 22)); + for (int x = 0; x < (int)arraysearch.size(); x++) { + std::string temptext = arraysearch[x]; + + replace(temptext, "https://jkanime.net/", ""); + replace(temptext, "/", " "); + replace(temptext, "-", " "); + mayus(temptext); + if (x == searchchapter) { + gTextTexture.loadFromRenderedText(digifont, temptext, { 255,255,255 }); + {SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 105); + SDL_Rect HeaderRect = {posxbase-2,posybase + (x * 22), 590, gTextTexture.getHeight()}; + SDL_RenderFillRect(gRenderer, &HeaderRect);} + gTextTexture.render(posxbase, posybase + (x * 22)); + + Heart.render(posxbase - 18, posybase + 3 + (x * 22)); + } + else + { - gTextTexture.loadFromRenderedText(digifont, ">", { 0,0,0 }); - gTextTexture.render(posxbase-10, posybase + (x * 22)); - } - else - { + gTextTexture.loadFromRenderedText(digifont, temptext, textColor); + gTextTexture.render(posxbase, posybase + (x * 22)); - gTextTexture.loadFromRenderedText(digifont, temptext, textColor); - gTextTexture.render(posxbase, posybase + (x * 22)); + } } + - } - + if (activatefirstsearchimage == true) + { + TSearchPreview.free(); + callimagesearch(); + activatefirstsearchimage = false; + } + if (preview == true) + { + {int ajuX = -390, ajuY = -450; + SDL_Rect fillRect = { xdistance + 18 +ajuX, ydistance + 8 + ajuY, sizeportraity + 4, sizeportraitx + 4}; + SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 200); - if (activatefirstsearchimage == true) - { - - TSearchPreview.free(); - callimagesearch(); - activatefirstsearchimage = false; - } - if (preview == true) - { - {int ajuX = -390, ajuY = -450; - SDL_Rect fillRect = { xdistance + 18 +ajuX, ydistance + 8 + ajuY, sizeportraity + 4, sizeportraitx + 4}; - SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 200); + SDL_RenderFillRect(gRenderer, &fillRect); + TSearchPreview.render(posxbase + xdistance + ajuX, posybase + ydistance + ajuY);} + + } + }else DrawImageFile(gRenderer,"romfs:/nop.png",230, 355,""); - SDL_RenderFillRect(gRenderer, &fillRect); - TSearchPreview.render(posxbase + xdistance + ajuX, posybase + ydistance + ajuY);} - - } {//Draw footer buttons int dist = 1100,posdist = 160; DrawImageFile(gRenderer,"romfs:/buttons/A.png",dist, 680,"Aceptar");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/B.png",dist, 680,"Volver");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/MINUS.png",dist, 680,"Música");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/PLUS.png",dist, 680,"Salir");dist -= posdist;} + DrawImageFile(gRenderer,"romfs:/buttons/B.png",dist, 680,"Volver");dist -= posdist;} break; case favoritesstate: + //Draw Header + gTextTexture.loadFromRenderedText(gFont, "Favoritos", {100,0,0}); + gTextTexture.render(SCREEN_WIDTH - gTextTexture.getWidth() - 30, 20); + if ((int)arrayfavorites.size() >= 1 ){ + {//Draw a rectagle to a nice view SDL_SetRenderDrawColor(gRenderer, 150, 150, 150, 105); SDL_Rect HeaderRect = {0,0, 620, 670}; SDL_RenderFillRect(gRenderer, &HeaderRect);} - //Draw Header - gTextTexture.loadFromRenderedText(gFont, "Favoritos", {100,0,0}); - gTextTexture.render(SCREEN_WIDTH - gTextTexture.getWidth() - 30, 20); - for (int x = 0; x < (int)arrayfavorites.size(); x++) { - std::string temptext = arrayfavorites[x]; - - replace(temptext, "https://jkanime.net/", ""); - replace(temptext, "/", " "); - replace(temptext, "-", " "); - mayus(temptext); - if (x == favchapter) { - gTextTexture.loadFromRenderedText(digifont, temptext, { 255,255,255 }); - {SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 105); - SDL_Rect HeaderRect = {posxbase-2,posybase + (x * 22), 590, gTextTexture.getHeight()}; - SDL_RenderFillRect(gRenderer, &HeaderRect);} - gTextTexture.render(posxbase, posybase + (x * 22)); - gTextTexture.loadFromRenderedText(digifont, ">", { 0,0,0 }); - gTextTexture.render(posxbase-10, posybase + (x * 22)); - } - else - { + for (int x = 0; x < (int)arrayfavorites.size(); x++) { + std::string temptext = arrayfavorites[x]; - gTextTexture.loadFromRenderedText(digifont, temptext, textColor); - gTextTexture.render(posxbase, posybase + (x * 22)); + replace(temptext, "https://jkanime.net/", ""); + replace(temptext, "/", ""); + std::string machu ="sdmc:/switch/RipJKAnime_NX/DATA/"+temptext+".jpg"; + replace(temptext, "-", " "); + mayus(temptext); + if (x == favchapter) { + tempimage = machu; + gTextTexture.loadFromRenderedText(digifont, temptext, { 255,255,255 }); + {SDL_SetRenderDrawColor(gRenderer, 0, 0, 0, 105); + SDL_Rect HeaderRect = {posxbase-2,posybase + (x * 22), 590, gTextTexture.getHeight()}; + SDL_RenderFillRect(gRenderer, &HeaderRect);} + gTextTexture.render(posxbase, posybase + (x * 22)); + + int scroll = posybase + (x * 22); + DrawImageCover(gRenderer,tempimage,620,scroll > 570 ? 570 : scroll ,""); + Heart.render(posxbase - 18, posybase + 3 + (x * 22)); + } + else + { + gTextTexture.loadFromRenderedText(digifont, temptext, textColor); + gTextTexture.render(posxbase, posybase + (x * 22)); + + } } - - } - {//Draw footer buttons + {//Draw footer buttons int dist = 1100,posdist = 160; DrawImageFile(gRenderer,"romfs:/buttons/A.png",dist, 680,"Aceptar");dist -= posdist; DrawImageFile(gRenderer,"romfs:/buttons/B.png",dist, 680,"Volver");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/MINUS.png",dist, 680,"Música");dist -= posdist; - DrawImageFile(gRenderer,"romfs:/buttons/PLUS.png",dist, 680,"Salir");dist -= posdist;} + if ((int)arrayfavorites.size() >= 1){ + DrawImageFile(gRenderer,"romfs:/buttons/Y.png",dist, 680,"Borrar#"+std::to_string(favchapter+1));dist -= posdist; + DrawImageFile(gRenderer,"romfs:/buttons/ZR.png",dist, 680,"Limpiar");dist -= posdist; + }else DrawImageFile(gRenderer,"romfs:/nop.png",230, 355,""); + } break; case downloadstate: std::string temptext = urltodownload; @@ -1917,7 +1943,8 @@ quit=1; } - + DrawImageFile(gRenderer,"romfs:/buttons/PLUS.png",160, 680,"Salir"); + DrawImageFile(gRenderer,"romfs:/buttons/MINUS.png",10, 680,"Música"); //Update screen SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); SDL_SetRenderDrawBlendMode(gRenderer, SDL_BLENDMODE_BLEND);//enable alpha blend