Skip to content

Commit

Permalink
Fix GS and Tweaks crashing when using AdobeBlank
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemiii91 committed Jun 23, 2024
1 parent 8d876c6 commit 39826ba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
14 changes: 10 additions & 4 deletions src/common/theme/render/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ SDL_Surface *theme_batterySurfaceWithBg(int percentage, SDL_Surface *background)
// Battery percentage text
char buffer[5];
sprintf(buffer, "%d%%", percentage);
SDL_Surface *text = TTF_RenderUTF8_Blended(font, buffer, style->color);
SDL_SetAlpha(text, 0, SDL_ALPHA_TRANSPARENT); /* important */

// Battery icon
ThemeImages icon_request = _getBatteryRequest(percentage);
SDL_Surface *icon = resource_getSurface(icon_request);

SDL_Surface *image = NULL;
SDL_Surface *text = TTF_RenderUTF8_Blended(font, buffer, style->color);

if (!text) {
text = SDL_CreateRGBSurface(0, 1, 1, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
}

SDL_SetAlpha(text, 0, SDL_ALPHA_TRANSPARENT); /* important */

if (icon->w > 640)
visible = false;

Expand All @@ -70,7 +77,7 @@ SDL_Surface *theme_batterySurfaceWithBg(int percentage, SDL_Surface *background)
if (img_height < 48)
img_height = 48;

SDL_Surface *image = SDL_CreateRGBSurface(0, img_width, img_height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
image = SDL_CreateRGBSurface(0, img_width, img_height, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);

SDL_Rect rect_icon = {0, (img_height - icon->h) / 2};
SDL_Rect rect_text = {0, (img_height - text->h) / 2 + offsetY};
Expand Down Expand Up @@ -109,7 +116,6 @@ SDL_Surface *theme_batterySurfaceWithBg(int percentage, SDL_Surface *background)

icon = SDL_ConvertSurface(icon, image->format, 0);
SDL_SetAlpha(icon, 0, SDL_ALPHA_TRANSPARENT); /* important */

SDL_BlitSurface(icon, NULL, image, &rect_icon);

if (visible)
Expand Down
22 changes: 14 additions & 8 deletions src/common/theme/render/footer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,21 @@ void theme_renderFooterStatus(SDL_Surface *screen, int current_num,
SDL_Surface *total =
TTF_RenderUTF8_Blended(font_hint, total_str, theme()->total.color);

SDL_Rect total_rect = {620 - total->w, 449 - total->h / 2};
SDL_Rect current_rect = {total_rect.x - current->w, 449 - current->h / 2};
old_status_width = total->w + current->w;

SDL_BlitSurface(total, NULL, screen, &total_rect);
SDL_BlitSurface(current, NULL, screen, &current_rect);
if (total) {
SDL_Rect current_rect = {0, 0};
SDL_Rect total_rect = {620 - total->w, 449 - total->h / 2};

SDL_BlitSurface(total, NULL, screen, &total_rect);
if (current) {
current_rect.x = total_rect.x - current->w;
current_rect.y = 449 - current->h / 2;
old_status_width = total->w + current->w;
SDL_BlitSurface(current, NULL, screen, &current_rect);
SDL_FreeSurface(current);
}

SDL_FreeSurface(current);
SDL_FreeSurface(total);
SDL_FreeSurface(total);
}
}

void theme_renderListFooter(SDL_Surface *screen, int current_num, int total_num,
Expand Down
13 changes: 9 additions & 4 deletions src/common/theme/render/textbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ SDL_Surface *theme_textboxSurface(const char *message, TTF_Font *font,
token = strtok(s, delim);
while (token != NULL) {
lines[line_count] = TTF_RenderUTF8_Blended(font, token, fg);
SDL_SetAlpha(lines[line_count], 0, 0); /* important */
if (lines[line_count]->w > line_width)
line_width = lines[line_count]->w;
line_count++;
if (lines[line_count]) {
SDL_SetAlpha(lines[line_count], 0, 0); /* important */
if (lines[line_count]->w > line_width)
line_width = lines[line_count]->w;
line_count++;
}
token = strtok(NULL, delim);
}

Expand All @@ -40,6 +42,9 @@ SDL_Surface *theme_textboxSurface(const char *message, TTF_Font *font,

int i;
for (i = 0; i < line_count; i++) {
if (!lines[i]) {
continue;
}
if (align == ALIGN_CENTER)
line_rect.x = (line_width - lines[i]->w) / 2;
else if (align == ALIGN_RIGHT)
Expand Down
2 changes: 1 addition & 1 deletion src/gameSwitcher/gameSwitcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ SDL_Surface *loadRomScreen(int index)

// Show artwork
if (!exists(currPicture))
sprintf(currPicture, game->romImagePath);
sprintf(currPicture, game->romImagePath);

if (exists(currPicture)) {
strcpy(game->romImagePath, currPicture);
Expand Down

0 comments on commit 39826ba

Please sign in to comment.