Skip to content

Commit f87bdce

Browse files
committed
rg_display: Added rg_display_get_width/height
1 parent e8c2a51 commit f87bdce

File tree

8 files changed

+49
-31
lines changed

8 files changed

+49
-31
lines changed

components/retro-go/drivers/display/sdl2.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static void lcd_init(void)
99
{
1010
window = SDL_CreateWindow("Retro-Go", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, RG_SCREEN_WIDTH, RG_SCREEN_HEIGHT, 0);
1111
surface = SDL_GetWindowSurface(window);
12-
canvas = SDL_CreateRGBSurfaceWithFormat(0, display.screen.width, display.screen.height, 16, SDL_PIXELFORMAT_RGB565);
12+
canvas = SDL_CreateRGBSurfaceWithFormat(0, RG_SCREEN_WIDTH, RG_SCREEN_HEIGHT, 16, SDL_PIXELFORMAT_RGB565);
1313
}
1414

1515
static void lcd_deinit(void)

components/retro-go/rg_display.c

+26-14
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static inline void write_update(const rg_surface_t *update)
211211
// for both virtual keyboard and info labels. Maybe make it configurable later...
212212
}
213213

214-
if (lines_updated > display.screen.height * 0.80f)
214+
if (lines_updated > draw_height * 0.80f)
215215
counters.fullFrames++;
216216
else
217217
counters.partFrames++;
@@ -220,23 +220,25 @@ static inline void write_update(const rg_surface_t *update)
220220

221221
static void update_viewport_scaling(void)
222222
{
223+
int screen_width = display.screen.width;
224+
int screen_height = display.screen.height;
223225
int src_width = display.source.width;
224226
int src_height = display.source.height;
225227
int new_width = src_width;
226228
int new_height = src_height;
227229

228230
if (config.scaling == RG_DISPLAY_SCALING_FULL)
229231
{
230-
new_width = display.screen.width;
231-
new_height = display.screen.height;
232+
new_width = screen_width;
233+
new_height = screen_height;
232234
}
233235
else if (config.scaling == RG_DISPLAY_SCALING_FIT)
234236
{
235-
new_width = FLOAT_TO_INT(display.screen.height * ((float)src_width / src_height));
236-
new_height = display.screen.height;
237-
if (new_width > display.screen.width) {
238-
new_width = display.screen.width;
239-
new_height = FLOAT_TO_INT(display.screen.width * ((float)src_height / src_width));
237+
new_width = FLOAT_TO_INT(screen_height * ((float)src_width / src_height));
238+
new_height = screen_height;
239+
if (new_width > screen_width) {
240+
new_width = screen_width;
241+
new_height = FLOAT_TO_INT(screen_width * ((float)src_height / src_width));
240242
}
241243
}
242244
else if (config.scaling == RG_DISPLAY_SCALING_ZOOM)
@@ -249,8 +251,8 @@ static void update_viewport_scaling(void)
249251
new_width &= ~1;
250252
new_height &= ~1;
251253

252-
display.viewport.left = (display.screen.width - new_width) / 2;
253-
display.viewport.top = (display.screen.height - new_height) / 2;
254+
display.viewport.left = (screen_width - new_width) / 2;
255+
display.viewport.top = (screen_height - new_height) / 2;
254256
display.viewport.width = new_width;
255257
display.viewport.height = new_height;
256258

@@ -264,9 +266,9 @@ static void update_viewport_scaling(void)
264266

265267
memset(screen_line_checksum, 0, sizeof(screen_line_checksum));
266268

267-
for (int x = 0; x < display.screen.width; ++x)
269+
for (int x = 0; x < screen_width; ++x)
268270
map_viewport_to_source_x[x] = FLOAT_TO_INT(x * display.viewport.step_x);
269-
for (int y = 0; y < display.screen.height; ++y)
271+
for (int y = 0; y < screen_height; ++y)
270272
map_viewport_to_source_y[y] = FLOAT_TO_INT(y * display.viewport.step_y);
271273

272274
RG_LOGI("%dx%d@%.3f => %dx%d@%.3f left:%d top:%d step_x:%.2f step_y:%.2f", src_width, src_height,
@@ -283,9 +285,9 @@ static bool load_border_file(const char *filename)
283285

284286
if (filename && (border = rg_surface_load_image_file(filename, 0)))
285287
{
286-
if (border->width != display.screen.width || border->height != display.screen.height)
288+
if (border->width != rg_display_get_width() || border->height != rg_display_get_height())
287289
{
288-
rg_surface_t *resized = rg_surface_resize(border, display.screen.width, display.screen.height);
290+
rg_surface_t *resized = rg_surface_resize(border, rg_display_get_width(), rg_display_get_height());
289291
if (resized)
290292
{
291293
rg_surface_free(border);
@@ -348,6 +350,16 @@ rg_display_counters_t rg_display_get_counters(void)
348350
return counters;
349351
}
350352

353+
int rg_display_get_width(void)
354+
{
355+
return display.screen.width;
356+
}
357+
358+
int rg_display_get_height(void)
359+
{
360+
return display.screen.height;
361+
}
362+
351363
void rg_display_set_scaling(display_scaling_t scaling)
352364
{
353365
config.scaling = RG_MIN(RG_MAX(0, scaling), RG_DISPLAY_SCALING_COUNT - 1);

components/retro-go/rg_display.h

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ void rg_display_submit(const rg_surface_t *update, uint32_t flags);
111111

112112
rg_display_counters_t rg_display_get_counters(void);
113113
const rg_display_t *rg_display_get_info(void);
114+
int rg_display_get_width(void);
115+
int rg_display_get_height(void);
114116

115117
void rg_display_set_scaling(display_scaling_t scaling);
116118
display_scaling_t rg_display_get_scaling(void);

components/retro-go/rg_gui.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ static struct
1616
uint16_t *screen_buffer, *draw_buffer;
1717
size_t draw_buffer_size;
1818
int screen_width, screen_height;
19+
int screen_safezone; // rg_rect_t
1920
struct
2021
{
2122
const rg_font_t *font;
@@ -102,8 +103,13 @@ static int get_vertical_position(int y_pos, int height)
102103

103104
void rg_gui_init(void)
104105
{
105-
gui.screen_width = rg_display_get_info()->screen.width;
106-
gui.screen_height = rg_display_get_info()->screen.height;
106+
gui.screen_width = rg_display_get_width();
107+
gui.screen_height = rg_display_get_height();
108+
#ifdef RG_SCREEN_HAS_ROUND_CORNERS
109+
gui.screen_safezone = 20;
110+
#else
111+
gui.screen_safezone = 0;
112+
#endif
107113
gui.draw_buffer = get_draw_buffer(gui.screen_width, 18, C_BLACK);
108114
rg_gui_set_language_id(rg_settings_get_number(NS_GLOBAL, SETTING_LANGUAGE, RG_LANG_EN));
109115
rg_gui_set_font(rg_settings_get_number(NS_GLOBAL, SETTING_FONTTYPE, RG_FONT_VERA_12));
@@ -534,15 +540,11 @@ void rg_gui_draw_icons(void)
534540
int bar_height = txt.height;
535541
int icon_height = RG_MAX(8, bar_height - 4);
536542
int icon_top = RG_MAX(0, (bar_height - icon_height - 1) / 2);
537-
int right = 0;
543+
int right = gui.screen_safezone;
538544

539545
if (battery.present)
540546
{
541-
#ifdef RG_SCREEN_HAS_ROUND_CORNERS
542-
right += 42; // This is to shift the battery icon a bit on the left
543-
#else
544-
right += 22; // Regular rectangle screen
545-
#endif
547+
right += 22;
546548

547549
int width = 16;
548550
int height = icon_height;
@@ -600,8 +602,9 @@ void rg_gui_draw_icons(void)
600602

601603
void rg_gui_draw_hourglass(void)
602604
{
603-
rg_display_write_rect((gui.screen_width / 2) - (image_hourglass.width / 2),
604-
(gui.screen_height / 2) - (image_hourglass.height / 2),
605+
rg_display_write_rect(
606+
get_horizontal_position(RG_GUI_CENTER, image_hourglass.width),
607+
get_vertical_position(RG_GUI_CENTER, image_hourglass.height),
605608
image_hourglass.width,
606609
image_hourglass.height,
607610
image_hourglass.width * 2,
@@ -633,6 +636,7 @@ void rg_gui_draw_status_bars(void)
633636
else
634637
snprintf(footer, max_len, "Retro-Go %s", app->version);
635638

639+
// FIXME: Respect gui.safezone (draw black background full screen_width, but pad the text if needed)
636640
rg_gui_draw_text(0, RG_GUI_TOP, gui.screen_width, header, C_WHITE, C_BLACK, 0);
637641
rg_gui_draw_text(0, RG_GUI_BOTTOM, gui.screen_width, footer, C_WHITE, C_BLACK, 0);
638642

components/retro-go/rg_system.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ bool rg_emu_save_state(uint8_t slot)
12941294
{
12951295
// Save succeeded, let's take a pretty screenshot for the launcher!
12961296
char *filename = rg_emu_get_path(RG_PATH_SCREENSHOT + slot, app.romPath);
1297-
rg_emu_screenshot(filename, rg_display_get_info()->screen.width / 2, 0);
1297+
rg_emu_screenshot(filename, rg_display_get_width() / 2, 0);
12981298
free(filename);
12991299
emu_update_save_slot(slot);
13001300
}

components/retro-go/targets/mrgc-gbm/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#define RG_SCREEN_HEIGHT 240
2323
#define RG_SCREEN_ROTATE 0
2424
#define RG_SCREEN_MARGIN_TOP 38
25+
#define RG_SCREEN_MARGIN_BOTTOM 0
2526
#define RG_SCREEN_MARGIN_LEFT 0
2627
#define RG_SCREEN_MARGIN_RIGHT 0
2728
#define RG_SCREEN_INIT() \

launcher/main/gui.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ void gui_init(bool cold_boot)
3838
.start_screen = rg_settings_get_number(NS_APP, SETTING_START_SCREEN, START_SCREEN_AUTO),
3939
.show_preview = rg_settings_get_number(NS_APP, SETTING_SHOW_PREVIEW, PREVIEW_MODE_SAVE_COVER),
4040
.scroll_mode = rg_settings_get_number(NS_APP, SETTING_SCROLL_MODE, SCROLL_MODE_CENTER),
41-
.width = rg_display_get_info()->screen.width,
42-
.height = rg_display_get_info()->screen.height,
41+
.width = rg_display_get_width(),
42+
.height = rg_display_get_height(),
4343
};
4444
// Auto: Show carousel on cold boot, browser on warm boot (after cleanly exiting an emulator)
4545
gui.browse = gui.start_screen == START_SCREEN_BROWSER || (gui.start_screen == START_SCREEN_AUTO && !cold_boot);

prboom-go/main/main.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,8 @@ void app_main()
544544
app = rg_system_init(AUDIO_SAMPLE_RATE, &handlers, NULL);
545545
rg_system_set_tick_rate(TICRATE);
546546

547-
const rg_display_t *display = rg_display_get_info();
548-
SCREENWIDTH = RG_MIN(display->screen.width, MAX_SCREENWIDTH);
549-
SCREENHEIGHT = RG_MIN(display->screen.height, MAX_SCREENHEIGHT);
547+
SCREENWIDTH = RG_MIN(rg_display_get_width(), MAX_SCREENWIDTH);
548+
SCREENHEIGHT = RG_MIN(rg_display_get_height(), MAX_SCREENHEIGHT);
550549

551550
update = rg_surface_create(SCREENWIDTH, SCREENHEIGHT, RG_PIXEL_PAL565_BE, MEM_FAST);
552551

0 commit comments

Comments
 (0)