Button prompt images

* Show button prompt images instead of text
* Unsupported files show yellow triangles to the left of them
* Change from Arial to Roboto font
This commit is contained in:
SeanOMik 2019-09-23 21:11:56 -05:00
parent b5af2c2829
commit 88ccf7b1d9
33 changed files with 164 additions and 90 deletions

View File

@ -46,7 +46,7 @@ ROMFS := romfs
VERSION_MAJOR := 0
VERSION_MINOR := 2
VERSION_MICRO := 1
VERSION_MICRO := 2
APP_TITLE := eBookReader
APP_AUTHOR := SeanOMik
@ -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)

View File

@ -8,6 +8,6 @@
extern SDL_Window *WINDOW;
//extern SDL_Surface *WINDOW_SURFACE;
extern SDL_Renderer *RENDERER;
extern TTF_Font *ARIAL, *ARIAL_35, *ARIAL_30, *ARIAL_27, *ARIAL_25, *ARIAL_20, *ARIAL_15;
extern TTF_Font *ROBOTO_35, *ROBOTO_30, *ROBOTO_27, *ROBOTO_25, *ROBOTO_20, *ROBOTO_15;
#endif

View File

@ -36,11 +36,12 @@ 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_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_DrawButtonPrompt(SDL_Renderer *renderer, SDL_Texture *texture, TTF_Font *font, SDL_Color textColor, const char* text, int x, int y, int imageW, int imageH, int imageDistance, int yTextOffset);
void SDL_DrawHorizonalAlignedImageText (SDL_Renderer *renderer, SDL_Texture *texture, TTF_Font *font, SDL_Color textColor, const char* text, int x, int y, int imageW, int imageH, int imageDistance, int yTextOffset);
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);

View File

@ -6,8 +6,8 @@
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, *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;
*button_x, *button_y, *button_dpad_up_down, *button_dpad_left_right, *button_lb, *button_rb, *button_lt, \
*button_rt, *button_minus, *button_plus, *left_stick_up_down, *right_stick_up_down;
void Textures_Load(void);
void Textures_Free(void);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -88,3 +88,20 @@ void SDL_DrawImageScale(SDL_Renderer *renderer, SDL_Texture *texture, int x, int
position.x = x; position.y = y; position.w = w; position.h = h;
SDL_RenderCopy(renderer, texture, NULL, &position);
}
void SDL_DrawButtonPrompt(SDL_Renderer *renderer, SDL_Texture *texture, TTF_Font *font, SDL_Color textColor, const char* text, int x, int y, int imageW, int imageH, int imageDistance, int yTextOffset) {
int textWidth, textHeight;
TTF_SizeText(ROBOTO_20, text, &textWidth, &textHeight);
int imageX = x;
int imageY = y - imageH;
SDL_DrawImageScale(RENDERER, texture, imageX, imageY, imageW, imageH);
int textX = x + imageDistance + imageW;
int textY = y - (imageH * 0.85) - yTextOffset; // 0.85 was retreived from trail and error when trying to center the text with the image.
SDL_DrawText(RENDERER, ROBOTO_20, textX, textY, textColor, text);
}
void SDL_DrawHorizonalAlignedImageText (SDL_Renderer *renderer, SDL_Texture *texture, TTF_Font *font, SDL_Color textColor, const char* text, int x, int y, int imageW, int imageH, int imageDistance, int yTextOffset) {
SDL_DrawButtonPrompt(renderer, texture, font, textColor, text, x, y, imageW, imageH, imageDistance, yTextOffset);
}

View File

@ -23,7 +23,7 @@ extern "C" {
SDL_Renderer* RENDERER;
SDL_Window* WINDOW;
SDL_Event EVENT;
TTF_Font *ARIAL, *ARIAL_35, *ARIAL_30, *ARIAL_27, *ARIAL_25, *ARIAL_20, *ARIAL_15;
TTF_Font *ROBOTO_35, *ROBOTO_30, *ROBOTO_27, *ROBOTO_25, *ROBOTO_20, *ROBOTO_15;
bool configDarkMode;
bool run = true;
@ -32,13 +32,12 @@ void Term_Services() {
run = false;
timeExit();
TTF_CloseFont(ARIAL_35);
TTF_CloseFont(ARIAL_30);
TTF_CloseFont(ARIAL_27);
TTF_CloseFont(ARIAL_25);
TTF_CloseFont(ARIAL_20);
TTF_CloseFont(ARIAL_15);
TTF_CloseFont(ARIAL);
TTF_CloseFont(ROBOTO_35);
TTF_CloseFont(ROBOTO_30);
TTF_CloseFont(ROBOTO_27);
TTF_CloseFont(ROBOTO_25);
TTF_CloseFont(ROBOTO_20);
TTF_CloseFont(ROBOTO_15);
TTF_Quit();
Textures_Free();
@ -96,19 +95,16 @@ void Init_Services() {
}
std::cout << "Initalized TTF" << std::endl;
#ifdef EXPERIMENTAL
std::cout << "Loading Textures" << std::endl;
Textures_Load();
#endif
Textures_Load();
std::cout << "Loaded Textures" << std::endl;
ARIAL_35 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 35);
ARIAL_30 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 30);
ARIAL_27 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 27);
ARIAL_25 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 25);
ARIAL_20 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 20);
ARIAL_15 = TTF_OpenFont("romfs:/resources/font/arial.ttf", 15);
ARIAL = TTF_OpenFont("romfs:/resources/font/arial.ttf", 20);
if (!ARIAL_35 || !ARIAL_25 || !ARIAL_15 || !ARIAL) {
ROBOTO_35 = TTF_OpenFont("romfs:/resources/font/Roboto-Light.ttf", 35);
ROBOTO_30 = TTF_OpenFont("romfs:/resources/font/Roboto-Light.ttf", 30);
ROBOTO_27 = TTF_OpenFont("romfs:/resources/font/Roboto-Light.ttf", 27);
ROBOTO_25 = TTF_OpenFont("romfs:/resources/font/Roboto-Light.ttf", 25);
ROBOTO_20 = TTF_OpenFont("romfs:/resources/font/Roboto-Light.ttf", 20);
ROBOTO_15 = TTF_OpenFont("romfs:/resources/font/Roboto-Light.ttf", 15);
if (!ROBOTO_35 || !ROBOTO_25 || !ROBOTO_15) {
std::cout << "Failure to retrieve fonts" << std::endl;
Term_Services();
}
@ -131,7 +127,9 @@ void Init_Services() {
int main(int argc, char *argv[]) {
Init_Services();
Menu_StartChoosing();
if (run) {
Menu_StartChoosing();
}
Term_Services();
return 0;

View File

@ -22,7 +22,7 @@ template <typename T> bool contains(list<T> & listOfElements, const T & element)
return it != listOfElements.end();
}
extern TTF_Font *ARIAL, *ARIAL_35, *ARIAL_25, *ARIAL_15;
extern TTF_Font *ROBOTO_35, *ROBOTO_25, *ROBOTO_15;
void Menu_StartChoosing() {
int choosenIndex = 0;
@ -129,8 +129,13 @@ void Menu_StartChoosing() {
configDarkMode = !configDarkMode;
}
SDL_DrawText(RENDERER, ARIAL_25, windowX - 123, windowY - 45, textColor, "\"B\" - Exit");
SDL_DrawText(RENDERER, ARIAL_25, windowX - 200, windowY - 80, textColor, "\"-\" - Switch theme");
int exitWidth = 0;
TTF_SizeText(ROBOTO_20, "Exit", &exitWidth, NULL);
SDL_DrawButtonPrompt(RENDERER, button_b, ROBOTO_20, textColor, "Exit", windowX - exitWidth - 50, windowY - 10, 35, 35, 5, 0);
int themeWidth = 0;
TTF_SizeText(ROBOTO_20, "Switch Theme", &themeWidth, NULL);
SDL_DrawButtonPrompt(RENDERER, button_minus, ROBOTO_20, textColor, "Switch Theme", windowX - themeWidth - 50, windowY - 40, 35, 35, 5, 0);
int choosingIndex = 0;
for (const auto & entry : fs::directory_iterator(path)) {
@ -142,13 +147,11 @@ void Menu_StartChoosing() {
SDL_DrawRect(RENDERER, 15, 15 + (40 * choosingIndex), 1265, 40, configDarkMode ? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
}
#ifdef EXPERIMENTAL
if (contains(warnedExtentions, extention)) {
SDL_DrawImage(RENDERER, warning, 25, 18 + (40 * choosingIndex));
}
#endif
if (contains(warnedExtentions, extention)) {
SDL_DrawImage(RENDERER, warning, 25, 18 + (40 * choosingIndex));
}
SDL_DrawText(RENDERER, ARIAL_25, 70, 20 + (40 * choosingIndex), textColor, entry.path().filename().c_str());
SDL_DrawText(RENDERER, ROBOTO_25, 70, 20 + (40 * choosingIndex), textColor, entry.path().filename().c_str());
if (isWarningOnScreen) {
if (!configDarkMode) { // Display a dimmed background if on light mode
@ -156,10 +159,10 @@ void Menu_StartChoosing() {
}
SDL_DrawRect(RENDERER, (windowX - warningWidth) / 2, (windowY - warningHeight) / 2, warningWidth, warningHeight, configDarkMode ? HINT_COLOUR_DARK : HINT_COLOUR_LIGHT);
SDL_DrawText(RENDERER, ARIAL_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 15, textColor, "This file is not yet fully supported, and may");
SDL_DrawText(RENDERER, ARIAL_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 50, textColor, "cause a system, or app crash.");
SDL_DrawText(RENDERER, ARIAL_20, (windowX - warningWidth) / 2 + warningWidth - 250, (windowY - warningHeight) / 2 + warningHeight - 30, textColor, "\"A\" - Read");
SDL_DrawText(RENDERER, ARIAL_20, (windowX - warningWidth) / 2 + warningWidth - 125, (windowY - warningHeight) / 2 + warningHeight - 30, textColor, "\"B\" - Cancel.");
SDL_DrawText(RENDERER, ROBOTO_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 15, textColor, "This file is not yet fully supported, and may");
SDL_DrawText(RENDERER, ROBOTO_30, (windowX - warningWidth) / 2 + 15, (windowY - warningHeight) / 2 + 50, textColor, "cause a system, or app crash.");
SDL_DrawText(RENDERER, ROBOTO_20, (windowX - warningWidth) / 2 + warningWidth - 250, (windowY - warningHeight) / 2 + warningHeight - 30, textColor, "\"A\" - Read");
SDL_DrawText(RENDERER, ROBOTO_20, (windowX - warningWidth) / 2 + warningWidth - 125, (windowY - warningHeight) / 2 + warningHeight - 30, textColor, "\"B\" - Cancel.");
}
choosingIndex++;

View File

@ -1,7 +1,6 @@
#include "BookReader.hpp"
#include "PageLayout.hpp"
#include "LandscapePageLayout.hpp"
#include "common.h"
#include <algorithm>
#include <iostream>
#include <libconfig.h>
@ -10,6 +9,8 @@ extern "C" {
#include "SDL_helper.h"
#include "status_bar.h"
#include "config.h"
#include "textures.h"
#include "common.h"
}
fz_context *ctx = NULL;
@ -147,6 +148,7 @@ void BookReader::draw(bool drawHelp) {
if (drawHelp) { // Help menu
int helpWidth = 680;
int helpHeight = 365;
helpHeight -= 38; // Removed due to removing the skip forward page button prompt.
if (!configDarkMode) { // Display a dimmed background if on light mode
SDL_DrawRect(RENDERER, 0, 0, 1280, 720, SDL_MakeColour(50, 50, 50, 150));
@ -154,39 +156,39 @@ void BookReader::draw(bool drawHelp) {
SDL_DrawRect(RENDERER, (windowX - helpWidth) / 2, (windowY - helpHeight) / 2, helpWidth, helpHeight, configDarkMode ? HINT_COLOUR_DARK : HINT_COLOUR_LIGHT);
// These already have margin added to them
int textX = (windowX - helpWidth) / 2 + 20;
int textY = (windowY - helpHeight) / 2 + 75;
SDL_DrawText(RENDERER, ARIAL_30, textX, (windowY - helpHeight) / 2 + 10, configDarkMode ? WHITE : BLACK, "Help Menu:");
int textY = (windowY - helpHeight) / 2 + 87;
SDL_Color textColor = configDarkMode ? WHITE : BLACK;
SDL_DrawText(RENDERER, ROBOTO_30, textX, (windowY - helpHeight) / 2 + 10, textColor, "Help Menu:");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY, configDarkMode ? WHITE : BLACK, "\"B\" - Stop reading / Close help menu.");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35, configDarkMode ? WHITE : BLACK, "\"-\" - Switch to dark/light theme.");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 2, configDarkMode ? WHITE : BLACK, "\"Right Stick Up/Down\" - Zoom in/out.");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 3, configDarkMode ? WHITE : BLACK, "\"Left Stick Up/Down\" - Page up/down.");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 4, configDarkMode ? WHITE : BLACK, "\"Y\" - Rotate page.");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 5, configDarkMode ? WHITE : BLACK, "\"X\" - Keep status bar on.");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 6, configDarkMode ? WHITE : BLACK, "\"Left/Right DPad\" - Next/previous page.");
SDL_DrawText(RENDERER, ARIAL_25, textX, textY + 35 * 7, configDarkMode ? WHITE : BLACK, "\"Left/Right Bumper\" - Skip forward/backward 10 pages.");
SDL_DrawButtonPrompt(RENDERER, button_b, ROBOTO_25, textColor, "Stop reading / Close help menu.", textX, textY, 35, 35, 5, 0);
SDL_DrawButtonPrompt(RENDERER, button_minus, ROBOTO_25, textColor, "Switch to dark/light theme.", textX, textY + 38, 35, 35, 5, 0);
SDL_DrawButtonPrompt(RENDERER, right_stick_up_down, ROBOTO_25, textColor, "Zoom in/out.", textX, textY + 38 * 2, 35, 35, 5, 0);
SDL_DrawButtonPrompt(RENDERER, left_stick_up_down, ROBOTO_25, textColor, "Page up/down.", textX, textY + 38 * 3, 35, 35, 5, 0);
SDL_DrawButtonPrompt(RENDERER, button_y, ROBOTO_25, textColor, "Rotate page.", textX, textY + 38 * 4, 35, 35, 5, 0);
SDL_DrawButtonPrompt(RENDERER, button_x, ROBOTO_25, textColor, "Keep status bar on.", textX, textY + 38 * 5, 35, 35, 5, 0);
SDL_DrawButtonPrompt(RENDERER, button_dpad_left_right, ROBOTO_25, textColor, "Next/previous page.", textX, textY + 38 * 6, 35, 35, 5, 0);
//SDL_DrawButtonPrompt(RENDERER, button_dpad_up_down, ROBOTO_25, textColor, "Skip forward/backward 10 pages.", textX, textY + 38 * 7, 35, 35, 5, 0);
}
if (permStatusBar || --status_bar_visible_counter > 0) {
char *title = layout->info();
int title_width = 0, title_height = 0;
TTF_SizeText(ARIAL_15, title, &title_width, &title_height);
TTF_SizeText(ROBOTO_15, title, &title_width, &title_height);
SDL_Color color = configDarkMode ? STATUS_BAR_DARK : STATUS_BAR_LIGHT;
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);
SDL_DrawText(RENDERER, ROBOTO_25, (1280 - title_width) / 2, (40 - title_height) / 2, WHITE, title);
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);
SDL_DrawRotatedText(RENDERER, ROBOTO_25, (double) 90, x, y, WHITE, title);
StatusBar_DisplayTime(true);
}

View File

@ -41,88 +41,103 @@ static void StatusBar_GetBatteryStatus(int x, int y) {
state = 0;
if (R_SUCCEEDED(psmGetBatteryChargePercentage(&percent))) {
SDL_Texture *batteryImage;
if (percent < 20) {
SDL_DrawImage(RENDERER, battery_low, x, 3);
//SDL_DrawImage(RENDERER, battery_low, x, 3);
batteryImage = battery_low;
} else if ((percent >= 20) && (percent < 30)) {
if (state != 0) {
SDL_DrawImage(RENDERER, battery_20_charging, x, 3);
//SDL_DrawImage(RENDERER, battery_20_charging, x, 3);
batteryImage = battery_20_charging;
} else {
SDL_DrawImage(RENDERER, battery_20, x, 3);
//SDL_DrawImage(RENDERER, battery_20, x, 3);
batteryImage = battery_20;
}
} else if ((percent >= 30) && (percent < 50)) {
if (state != 0) {
SDL_DrawImage(RENDERER, battery_50_charging, x, 3);
//SDL_DrawImage(RENDERER, battery_50_charging, x, 3);
batteryImage = battery_50_charging;
} else {
SDL_DrawImage(RENDERER, battery_50, x, 3);
//SDL_DrawImage(RENDERER, battery_50, x, 3);
batteryImage = battery_50;
}
} else if ((percent >= 50) && (percent < 60)) {
if (state != 0) {
SDL_DrawImage(RENDERER, battery_50_charging, x, 3);
//SDL_DrawImage(RENDERER, battery_50_charging, x, 3);
batteryImage = battery_50_charging;
} else {
SDL_DrawImage(RENDERER, battery_50, x, 3);
//SDL_DrawImage(RENDERER, battery_50, x, 3);
batteryImage = battery_50;
}
} else if ((percent >= 60) && (percent < 80)) {
if (state != 0) {
SDL_DrawImage(RENDERER, battery_60_charging, x, 3);
//SDL_DrawImage(RENDERER, battery_60_charging, x, 3);
batteryImage = battery_60_charging;
} else {
SDL_DrawImage(RENDERER, battery_60, x, 3);
//SDL_DrawImage(RENDERER, battery_60, x, 3);
batteryImage = battery_60;
}
} else if ((percent >= 80) && (percent < 90)) {
if (state != 0) {
SDL_DrawImage(RENDERER, battery_80_charging, x, 3);
//SDL_DrawImage(RENDERER, battery_80_charging, x, 3);
batteryImage = battery_80_charging;
} else {
SDL_DrawImage(RENDERER, battery_80, x, 3);
//SDL_DrawImage(RENDERER, battery_80, x, 3);
batteryImage = battery_80;
}
} else if ((percent >= 90) && (percent < 100)) {
if (state != 0) {
SDL_DrawImage(RENDERER, battery_90_charging, x, 3);
//SDL_DrawImage(RENDERER, battery_90_charging, x, 3);
batteryImage = battery_90_charging;
} else {
SDL_DrawImage(RENDERER, battery_90, x, 3);
//SDL_DrawImage(RENDERER, battery_90, x, 3);
batteryImage = battery_90;
}
} else if (percent == 100) {
if (state != 0) {
SDL_DrawImage(RENDERER, battery_full_charging, x, 3);
//SDL_DrawImage(RENDERER, battery_full_charging, x, 3);
batteryImage = battery_full_charging;
} else {
SDL_DrawImage(RENDERER, battery_full, x, 3);
//SDL_DrawImage(RENDERER, battery_full, x, 3);
batteryImage = battery_full;
}
}
snprintf(buf, 5, "%d%%", percent);
TTF_SizeText(ARIAL_20, buf, &width, NULL);
SDL_DrawText(RENDERER, ARIAL_20, (x + width + 5), y, WHITE, buf);
TTF_SizeText(ROBOTO_20, buf, &width, NULL);
SDL_DrawHorizonalAlignedImageText(RENDERER, batteryImage, ROBOTO_20, WHITE, buf, (x + width + 5), y, 34, 34, -2, -7);
//SDL_DrawText(RENDERER, ROBOTO_20, (x + width + 5), y, WHITE, buf);
} else {
snprintf(buf, 5, "%d%%", percent);
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);
TTF_SizeText(ROBOTO_20, buf, &width, NULL);
SDL_DrawHorizonalAlignedImageText(RENDERER, battery_unknown, ROBOTO_20, WHITE, buf, x, y, 34, 34, -2, -7);
/*SDL_DrawText(RENDERER, ROBOTO_20, (x + width + 5), y, WHITE, buf);
SDL_DrawImage(RENDERER, battery_unknown, x, 1);*/
}
}
void StatusBar_DisplayTime(bool portriat) {
int timeWidth = 0, timeHeight = 0;
TTF_SizeText(ARIAL_25, Clock_GetCurrentTime(), &timeWidth, &timeHeight);
TTF_SizeText(ROBOTO_25, Clock_GetCurrentTime(), &timeWidth, &timeHeight);
int helpWidth, helpHeight;
TTF_SizeText(ARIAL_20, "\"+\" - Help", &helpWidth, &helpHeight);
TTF_SizeText(ROBOTO_20, "\"+\" - Help", &helpWidth, &helpHeight);
if (portriat) {
int timeX = (1280 - timeWidth) + timeHeight;
int timeY = (720 - timeWidth) + 15;
SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, timeX, timeY, WHITE, Clock_GetCurrentTime());
SDL_DrawRotatedText(RENDERER, ROBOTO_25, (double) 90, timeX, timeY, WHITE, Clock_GetCurrentTime());
int helpX = (1280 - helpWidth) + 21;
int helpY = (720 - helpHeight) - (720 - timeY) - 75;
SDL_DrawRotatedText(RENDERER, ARIAL_20, (double) 90, helpX, helpY, WHITE, "\"+\" - Help");
SDL_DrawRotatedText(RENDERER, ROBOTO_20, (double) 90, helpX, helpY, WHITE, "\"+\" - Help");
//SDL_DrawRotatedText(RENDERER, ARIAL_25, (double) 90, 1270 - width, (720 - height), WHITE, Clock_GetCurrentTime());
//SDL_DrawRotatedText(RENDERER, ROBOTO_25, (double) 90, 1270 - width, (720 - height), WHITE, Clock_GetCurrentTime());
} else {
SDL_DrawText(RENDERER, ARIAL_25, 1260 - timeWidth, (40 - timeHeight) / 2, WHITE, Clock_GetCurrentTime());
SDL_DrawText(RENDERER, ROBOTO_25, 1260 - timeWidth, (40 - timeHeight) / 2, WHITE, Clock_GetCurrentTime());
SDL_DrawText(RENDERER, ARIAL_20, 1260 - helpWidth - timeWidth - 25, (40 - helpHeight) / 2, WHITE, "\"+\" - Help");
SDL_DrawText(RENDERER, ROBOTO_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
StatusBar_GetBatteryStatus(1260 - (timeWidth + helpWidth) - 110, (40 - timeHeight) / 2 + 34); // 34 is height of battery img
}
#ifdef EXPERIMENTAL
#endif
}

View File

@ -5,14 +5,15 @@
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, *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;
*button_x, *button_y, *button_dpad_up_down, *button_dpad_left_right, *button_lb, *button_rb, *button_lt, \
*button_rt, *button_minus, *button_plus, *left_stick_up_down, *right_stick_up_down;
void Textures_Load(void) {
// Battery images
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_30_charging, "romfs:/resources/images/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");
@ -25,13 +26,50 @@ void Textures_Load(void) {
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");
// Info images
SDL_LoadImage(&error, "romfs:/resources/images/info/error.png");
SDL_LoadImage(&warning, "romfs:/resources/images/info/warning.png");
// Button images
SDL_LoadImage(&button_a, "romfs:/resources/images/control/Switch_A.png");
SDL_LoadImage(&button_b, "romfs:/resources/images/control/Switch_B.png");
SDL_LoadImage(&button_x, "romfs:/resources/images/control/Switch_X.png");
SDL_LoadImage(&button_y, "romfs:/resources/images/control/Switch_Y.png");
SDL_LoadImage(&button_dpad_up_down, "romfs:/resources/images/control/Switch_Dpad_Up_down.png");
SDL_LoadImage(&button_dpad_left_right, "romfs:/resources/images/control/Switch_Dpad_Left_right.png");
SDL_LoadImage(&button_lb, "romfs:/resources/images/control/Switch_LB.png");
SDL_LoadImage(&button_rb, "romfs:/resources/images/control/Switch_RB.png");
SDL_LoadImage(&button_lt, "romfs:/resources/images/control/Switch_LT.png");
SDL_LoadImage(&button_rt, "romfs:/resources/images/control/Switch_RT.png");
SDL_LoadImage(&button_minus, "romfs:/resources/images/control/Switch_Minus.png");
SDL_LoadImage(&button_plus, "romfs:/resources/images/control/Switch_Plus.png");
SDL_LoadImage(&left_stick_up_down, "romfs:/resources/images/control/Switch_Left_Stick_up_down.png");
SDL_LoadImage(&right_stick_up_down, "romfs:/resources/images/control/Switch_Right_Stick_up_down.png");
}
void Textures_Free(void) {
// Button images
SDL_DestroyTexture(button_a);
SDL_DestroyTexture(button_b);
SDL_DestroyTexture(button_x);
SDL_DestroyTexture(button_y);
SDL_DestroyTexture(button_dpad_up_down);
SDL_DestroyTexture(button_dpad_left_right);
SDL_DestroyTexture(button_lb);
SDL_DestroyTexture(button_rb);
SDL_DestroyTexture(button_lt);
SDL_DestroyTexture(button_rt);
SDL_DestroyTexture(button_minus);
SDL_DestroyTexture(button_plus);
SDL_DestroyTexture(left_stick_up_down);
SDL_DestroyTexture(right_stick_up_down);
// Info images
SDL_DestroyTexture(warning);
SDL_DestroyTexture(error);
// Battery images
SDL_DestroyTexture(battery_unknown);
SDL_DestroyTexture(battery_low);
SDL_DestroyTexture(battery_full_charging);