New SDL helper load image method, doesn't crash.
Also moved images around and added button images.
2
Makefile
|
@ -63,7 +63,7 @@ CFLAGS := -g -std=c++17 -Wall -O2 -ffunction-sections \
|
|||
|
||||
CFLAGS += -D__SWITCH__ $(INCLUDE) `sdl2-config --cflags`
|
||||
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -DDEBUG=1 #-DEXPERIMENTAL=1
|
||||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -DDEBUG=1 -DEXPERIMENTAL=1
|
||||
|
||||
ASFLAGS := -g $(ARCH)
|
||||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
|
|
@ -36,7 +36,8 @@ void SDL_DrawCircle(SDL_Renderer *renderer, int x, int y, int r, SDL_Color colou
|
|||
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_LoadImage(SDL_Renderer *renderer, SDL_Texture **texture, char *path);
|
||||
void SDL_LoadImage(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);
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
extern SDL_Texture *battery_20, *battery_20_charging, *battery_30, *battery_30_charging, *battery_50, *battery_50_charging, \
|
||||
*battery_60, *battery_60_charging, *battery_80, *battery_80_charging, *battery_90, *battery_90_charging, \
|
||||
*battery_full, *battery_full_charging, *battery_low, *battery_unknown, *error, *warning;
|
||||
*battery_full, *battery_full_charging, *battery_low, *battery_unknown, *error, *warning, *button_a, *button_b, \
|
||||
*button_x, *button_y, *button_down, *button_up, *button_left, *button_right, *button_lb, *button_rb, *button_lt, \
|
||||
*button_rt, *button_minus, *button_plus, *button_capture, *button_home;
|
||||
|
||||
void Textures_Load(void);
|
||||
void Textures_Free(void);
|
||||
|
|
Before Width: | Height: | Size: 393 B After Width: | Height: | Size: 393 B |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 395 B After Width: | Height: | Size: 395 B |
Before Width: | Height: | Size: 515 B After Width: | Height: | Size: 515 B |
Before Width: | Height: | Size: 263 B After Width: | Height: | Size: 263 B |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 263 B After Width: | Height: | Size: 263 B |
Before Width: | Height: | Size: 560 B After Width: | Height: | Size: 560 B |
Before Width: | Height: | Size: 264 B After Width: | Height: | Size: 264 B |
Before Width: | Height: | Size: 578 B After Width: | Height: | Size: 578 B |
Before Width: | Height: | Size: 263 B After Width: | Height: | Size: 263 B |
Before Width: | Height: | Size: 556 B After Width: | Height: | Size: 556 B |
Before Width: | Height: | Size: 263 B After Width: | Height: | Size: 263 B |
Before Width: | Height: | Size: 534 B After Width: | Height: | Size: 534 B |
Before Width: | Height: | Size: 407 B After Width: | Height: | Size: 407 B |
Before Width: | Height: | Size: 551 B After Width: | Height: | Size: 551 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 3.5 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 356 B |
After Width: | Height: | Size: 764 B |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.0 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 4.5 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 437 B After Width: | Height: | Size: 437 B |
Before Width: | Height: | Size: 447 B After Width: | Height: | Size: 447 B |
|
@ -1,5 +1,6 @@
|
|||
#include "common.h"
|
||||
#include "SDL_helper.h"
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
void SDL_ClearScreen(SDL_Renderer *renderer, SDL_Color colour) {
|
||||
SDL_SetRenderDrawColor(renderer, colour.r, colour.g, colour.b, colour.a);
|
||||
|
@ -41,14 +42,11 @@ void SDL_DrawRotatedText(SDL_Renderer *renderer, TTF_Font *font, double rotation
|
|||
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_Rect crop = {0, 0, &position.w, &position.h};
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -61,18 +59,21 @@ void SDL_DrawTextf(SDL_Renderer *renderer, TTF_Font *font, int x, int y, SDL_Col
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
void SDL_LoadImage(SDL_Renderer *renderer, SDL_Texture **texture, char *path) {
|
||||
SDL_Surface *imageSurface = IMG_Load(path);
|
||||
void SDL_LoadImage(SDL_Texture **texture, char *path) {
|
||||
SDL_Surface *image = NULL;
|
||||
|
||||
if (imageSurface) {
|
||||
Uint32 colorkey = SDL_MapRGB(imageSurface->format, 0, 0, 0);
|
||||
SDL_SetColorKey(imageSurface, SDL_TRUE, colorkey);
|
||||
*texture = SDL_CreateTextureFromSurface(renderer, imageSurface);
|
||||
} else {
|
||||
printf("Failed to load image: %s", path);
|
||||
image = IMG_Load(path);
|
||||
if (!image) {
|
||||
//DEBUG_LOG("IMG_Load failed: %s\n", IMG_GetError());
|
||||
printf("IMG_Load failed: %s\n", IMG_GetError());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_FreeSurface(imageSurface);
|
||||
|
||||
SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGBA8888, 0);
|
||||
*texture = SDL_CreateTextureFromSurface(RENDERER, image);
|
||||
SDL_FreeSurface(image);
|
||||
image = NULL;
|
||||
}
|
||||
|
||||
void SDL_DrawImage(SDL_Renderer *renderer, SDL_Texture *texture, int x, int y) {
|
||||
|
|
|
@ -22,7 +22,6 @@ extern "C" {
|
|||
|
||||
SDL_Renderer* RENDERER;
|
||||
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;
|
||||
|
|
|
@ -17,8 +17,8 @@ extern "C" {
|
|||
using namespace std;
|
||||
namespace fs = filesystem;
|
||||
|
||||
template <typename T> bool contains(std::list<T> & listOfElements, const T & element) {
|
||||
auto it = std::find(listOfElements.begin(), listOfElements.end(), element);
|
||||
template <typename T> bool contains(list<T> & listOfElements, const T & element) {
|
||||
auto it = find(listOfElements.begin(), listOfElements.end(), element);
|
||||
return it != listOfElements.end();
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ void Menu_StartChoosing() {
|
|||
}
|
||||
|
||||
SDL_DrawText(RENDERER, ARIAL_25, windowX - 123, windowY - 45, textColor, "\"B\" - Exit");
|
||||
SDL_DrawText(RENDERER, ARIAL_25, windowX - 200, windowY - 35 * 2, textColor, "\"-\" - Switch theme");
|
||||
SDL_DrawText(RENDERER, ARIAL_25, windowX - 200, windowY - 80, textColor, "\"-\" - Switch theme");
|
||||
|
||||
int choosingIndex = 0;
|
||||
for (const auto & entry : fs::directory_iterator(path)) {
|
||||
|
@ -144,11 +144,11 @@ void Menu_StartChoosing() {
|
|||
|
||||
#ifdef EXPERIMENTAL
|
||||
if (contains(warnedExtentions, extention)) {
|
||||
//SDL_DrawImage(RENDERER, warning, 5, 10 + (40 * choosingIndex));
|
||||
SDL_DrawImage(RENDERER, warning, 25, 18 + (40 * choosingIndex));
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DrawText(RENDERER, ARIAL_25, 50, 20 + (40 * choosingIndex), textColor, entry.path().filename().c_str());
|
||||
SDL_DrawText(RENDERER, ARIAL_25, 70, 20 + (40 * choosingIndex), textColor, entry.path().filename().c_str());
|
||||
|
||||
if (isWarningOnScreen) {
|
||||
if (!configDarkMode) { // Display a dimmed background if on light mode
|
||||
|
|
|
@ -88,12 +88,12 @@ static void StatusBar_GetBatteryStatus(int x, int y) {
|
|||
}
|
||||
|
||||
snprintf(buf, 5, "%d%%", percent);
|
||||
TTF_SizeText(ARIAL_15, buf, &width, NULL);
|
||||
SDL_DrawText(RENDERER, ARIAL_15, (x - width - 10), y, WHITE, buf);
|
||||
TTF_SizeText(ARIAL_20, buf, &width, NULL);
|
||||
SDL_DrawText(RENDERER, ARIAL_20, (x + width + 5), y, WHITE, buf);
|
||||
} else {
|
||||
snprintf(buf, 5, "%d%%", percent);
|
||||
TTF_SizeText(ARIAL_15, buf, &width, NULL);
|
||||
SDL_DrawText(RENDERER, ARIAL_15, (x - width - 10), y, WHITE, buf);
|
||||
TTF_SizeText(ARIAL_20, buf, &width, NULL);
|
||||
SDL_DrawText(RENDERER, ARIAL_20, (x + width + 5), y, WHITE, buf);
|
||||
SDL_DrawImage(RENDERER, battery_unknown, x, 1);
|
||||
}
|
||||
}
|
||||
|
@ -104,9 +104,6 @@ void StatusBar_DisplayTime(bool portriat) {
|
|||
int helpWidth, helpHeight;
|
||||
TTF_SizeText(ARIAL_20, "\"+\" - Help", &helpWidth, &helpHeight);
|
||||
|
||||
#ifdef EXPERIMENTAL
|
||||
//StatusBar_GetBatteryStatus(1260 - width - 44, (40 - height) / 2);
|
||||
#endif
|
||||
if (portriat) {
|
||||
int timeX = (1280 - timeWidth) + timeHeight;
|
||||
int timeY = (720 - timeWidth) + 15;
|
||||
|
@ -121,5 +118,11 @@ void StatusBar_DisplayTime(bool portriat) {
|
|||
SDL_DrawText(RENDERER, ARIAL_25, 1260 - timeWidth, (40 - timeHeight) / 2, WHITE, Clock_GetCurrentTime());
|
||||
|
||||
SDL_DrawText(RENDERER, ARIAL_20, 1260 - helpWidth - timeWidth - 25, (40 - helpHeight) / 2, WHITE, "\"+\" - Help");
|
||||
}
|
||||
|
||||
StatusBar_GetBatteryStatus(1260 - (timeWidth + helpWidth) - 110, (40 - timeHeight) / 2 + 15); // 34 is height of battery img
|
||||
}
|
||||
|
||||
#ifdef EXPERIMENTAL
|
||||
|
||||
#endif
|
||||
}
|
|
@ -4,71 +4,35 @@
|
|||
|
||||
SDL_Texture *battery_20, *battery_20_charging, *battery_30, *battery_30_charging, *battery_50, *battery_50_charging, \
|
||||
*battery_60, *battery_60_charging, *battery_80, *battery_80_charging, *battery_90, *battery_90_charging, \
|
||||
*battery_full, *battery_full_charging, *battery_low, *battery_unknown, *error, *warning;
|
||||
*battery_full, *battery_full_charging, *battery_low, *battery_unknown, *error, *warning, *button_a, *button_b, \
|
||||
*button_x, *button_y, *button_down, *button_up, *button_left, *button_right, *button_lb, *button_rb, *button_lt, \
|
||||
*button_rt, *button_minus, *button_plus, *button_capture, *button_home;
|
||||
|
||||
void Textures_Load(void) {
|
||||
/*SDL_LoadImage(RENDERER, &battery_20, "romfs:/resources/images/battery_20.png");
|
||||
SDL_LoadImage(RENDERER, &battery_20_charging, "romfs:/resources/images/battery_20_charging.png");
|
||||
SDL_LoadImage(RENDERER, &battery_30, "romfs:/resources/images/battery_30.png");
|
||||
SDL_LoadImage(RENDERER, &battery_30_charging, "romfs:/resources/images/battery_30_charging.png");
|
||||
SDL_LoadImage(RENDERER, &battery_50, "romfs:/resources/images/battery_50.png");
|
||||
SDL_LoadImage(RENDERER, &battery_50_charging, "romfs:/resources/images/battery_50_charging.png");
|
||||
SDL_LoadImage(RENDERER, &battery_60, "romfs:/resources/images/battery_60.png");
|
||||
SDL_LoadImage(RENDERER, &battery_60_charging, "romfs:/resources/images/battery_60_charging.png");
|
||||
SDL_LoadImage(RENDERER, &battery_80, "romfs:/resources/images/battery_80.png");
|
||||
SDL_LoadImage(RENDERER, &battery_80_charging, "romfs:/resources/images/battery_80_charging.png");
|
||||
SDL_LoadImage(RENDERER, &battery_90, "romfs:/resources/images/battery_90.png");
|
||||
SDL_LoadImage(RENDERER, &battery_90_charging, "romfs:/resources/images/battery_90_charging.png");
|
||||
SDL_LoadImage(RENDERER, &battery_full, "romfs:/resources/images/battery_full.png");
|
||||
SDL_LoadImage(RENDERER, &battery_full_charging, "romfs:/resources/images/battery_full_charging.png");
|
||||
SDL_LoadImage(RENDERER, &battery_low, "romfs:/resources/images/battery_low.png");
|
||||
SDL_LoadImage(RENDERER, &battery_unknown, "romfs:/resources/images/battery_unknown.png");*/
|
||||
//SDL_LoadImage(RENDERER, &error, "romfs:/resources/images/error.png");
|
||||
|
||||
fprintf(stderr, "LOADING WARNING\n");
|
||||
SDL_Surface *imageSurface = IMG_Load("romfs:/resources/images/warning.png");
|
||||
fprintf(stderr, "LOADED WARNING\n");
|
||||
|
||||
if (RENDERER) {
|
||||
if (imageSurface) {
|
||||
fprintf(stderr, "CREATING TEXTURE\n");
|
||||
warning = SDL_CreateTextureFromSurface(RENDERER, imageSurface);
|
||||
fprintf(stderr, "CREATED TEXTURE\n");
|
||||
|
||||
if (warning == NULL) {
|
||||
fprintf(stderr, "CreateTextureFromSurface failed: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
} else {
|
||||
fprintf(stderr, "Loaded \"romfs:/resources/images/warning.png\"\n");
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Failed to load image: \"romfs:/resources/images/warning.png\"\n");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Something wrong with RENDERER");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(imageSurface);
|
||||
|
||||
|
||||
/*if (imageSurface) {
|
||||
Uint32 colorkey = SDL_MapRGB(imageSurface->format, 0, 0, 0);
|
||||
SDL_SetColorKey(imageSurface, SDL_TRUE, colorkey);
|
||||
warning = SDL_CreateTextureFromSurface(RENDERER, imageSurface);
|
||||
} else {
|
||||
printf("Failed to load image: %c", "romfs:/resources/images/warning.png");
|
||||
}
|
||||
|
||||
SDL_FreeSurface(imageSurface);*/
|
||||
//SDL_LoadImage(RENDERER, &warning, "romfs:/resources/images/warning.png");
|
||||
SDL_LoadImage(&battery_20, "romfs:/resources/images/battery/battery_20.png");
|
||||
SDL_LoadImage(&battery_20_charging, "romfs:/resources/images/battery/battery_20_charging.png");
|
||||
SDL_LoadImage(&battery_30, "romfs:/resources/images/battery/battery_30.png");
|
||||
SDL_LoadImage(&battery_30_charging, "romfs:/resources/images/battery/battery/battery_30_charging.png");
|
||||
SDL_LoadImage(&battery_50, "romfs:/resources/images/battery/battery_50.png");
|
||||
SDL_LoadImage(&battery_50_charging, "romfs:/resources/images/battery/battery_50_charging.png");
|
||||
SDL_LoadImage(&battery_60, "romfs:/resources/images/battery/battery_60.png");
|
||||
SDL_LoadImage(&battery_60_charging, "romfs:/resources/images/battery/battery_60_charging.png");
|
||||
SDL_LoadImage(&battery_80, "romfs:/resources/images/battery/battery_80.png");
|
||||
SDL_LoadImage(&battery_80_charging, "romfs:/resources/images/battery/battery_80_charging.png");
|
||||
SDL_LoadImage(&battery_90, "romfs:/resources/images/battery/battery_90.png");
|
||||
SDL_LoadImage(&battery_90_charging, "romfs:/resources/images/battery/battery_90_charging.png");
|
||||
SDL_LoadImage(&battery_full, "romfs:/resources/images/battery/battery_full.png");
|
||||
SDL_LoadImage(&battery_full_charging, "romfs:/resources/images/battery/battery_full_charging.png");
|
||||
SDL_LoadImage(&battery_low, "romfs:/resources/images/battery/battery_low.png");
|
||||
SDL_LoadImage(&battery_unknown, "romfs:/resources/images/battery/battery_unknown.png");
|
||||
SDL_LoadImage(&error, "romfs:/resources/images/info/error.png");
|
||||
SDL_LoadImage(&warning, "romfs:/resources/images/info/warning.png");
|
||||
}
|
||||
|
||||
void Textures_Free(void) {
|
||||
SDL_DestroyTexture(warning);
|
||||
//SDL_DestroyTexture(error);
|
||||
/*SDL_DestroyTexture(battery_unknown);
|
||||
SDL_DestroyTexture(error);
|
||||
SDL_DestroyTexture(battery_unknown);
|
||||
SDL_DestroyTexture(battery_low);
|
||||
SDL_DestroyTexture(battery_full_charging);
|
||||
SDL_DestroyTexture(battery_full);
|
||||
|
@ -82,5 +46,5 @@ void Textures_Free(void) {
|
|||
SDL_DestroyTexture(battery_30_charging);
|
||||
SDL_DestroyTexture(battery_30);
|
||||
SDL_DestroyTexture(battery_20_charging);
|
||||
SDL_DestroyTexture(battery_20);*/
|
||||
SDL_DestroyTexture(battery_20);
|
||||
}
|