Skip to content

Commit

Permalink
Added ability to have multiple screen sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
raz0red committed Jan 4, 2020
1 parent 798b59f commit 5d1b886
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 19 deletions.
28 changes: 26 additions & 2 deletions include/wii_resize_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,24 @@
extern "C" {
#endif

/**
* Represents a specific screen size
*/
typedef struct screen_size {
/** The width */
u16 w;
/** The height */
u16 h;
/** The name of the specific screen size (2x, etc.) */
const char* name;
} screen_size;

/**
* Information about the resize operation
*/
typedef struct resize_info {
float defaultX;
float defaultY;
const screen_size* sizes;
int size_count;
float currentX;
float currentY;
} resize_info;
Expand All @@ -51,6 +63,18 @@ typedef struct resize_info {
*/
void wii_resize_screen_gui(resize_info* rinfo);

/**
* Returns the index of the screen size corresponding to the specified width and
* height
*
* @param rinfo The resize info
* @param w The width
* @param h The height
* @return The index of the screen size corresponding to the specified width
* and height
*/
int wii_resize_screen_find_size(resize_info* rinfo, int w, int h);

/**
* Draws a border around the surface that is to be scaled.
*
Expand Down
70 changes: 53 additions & 17 deletions src/wii_resize_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,41 @@ static float aratio = 0.0f;
static float xinc = 0.0f;
/** The y increment */
static float yinc = 0.0f;
/** The screen size */
static resize_info* resizeinfo = NULL;
/** The current screen size index */
static int currsize = -1;
/** The current width */
float currentX = 0;
/** The current height */
float currentY = 0;


#define DELAY_FRAMES 6
#define DELAY_STEP 1
#define DELAY_MIN 0

/**
* Returns the index of the screen size corresponding to the specified width and
* height
*
* @param rinfo The resize info
* @param w The width
* @param h The height
* @return The index of the screen size corresponding to the specified width
* and height
*/
int wii_resize_screen_find_size(resize_info* rinfo, int w, int h) {
for (int i = 0; i < rinfo->size_count; i++) {
const screen_size* cur = &(rinfo->sizes[i]);
if (cur->w == w && cur->h == h) {
return i;
}
}

return -1;
}

/**
* Resets the aspect ratio
*
Expand Down Expand Up @@ -135,26 +165,23 @@ void wii_resize_render_callback() {

snprintf(buffer, sizeof(buffer), "%s :", gettextmsg("Plus/RTrigger"));
wii_gx_drawtext(0, y, fontsize, buffer, white, right);
wii_gx_drawtext(0, y, fontsize, gettextmsg("Reset to defaults"), white,
left);
y -= largespacing;

#if 0
snprintf(buffer, sizeof(buffer), " %s", gettextmsg("Toggle screen sizes"));
snprintf(buffer, sizeof(buffer), " %s",
gettextmsg(resizeinfo->size_count == 1 ? "Reset to defaults"
: "Toggle screen sizes"));
wii_gx_drawtext(0, y, fontsize, buffer, white, left);
y -= largespacing;

snprintf(buffer, sizeof(buffer), "%s :", gettextmsg("Screen size"));
wii_gx_drawtext(0, y, fontsize, buffer, white, right);
snprintf(buffer, sizeof(buffer), " %s",
gettextmsg(resizeinfo->rotated
? resizeinfo->emulator.getRotatedScreenSizeName(
currentX, currentY)
: resizeinfo->emulator.getScreenSizeName(
currentX, currentY)));

int curr_index =
wii_resize_screen_find_size(resizeinfo, currentX, currentY);
snprintf(
buffer, sizeof(buffer), " %s",
gettextmsg((curr_index == -1 ? "Custom"
: resizeinfo->sizes[curr_index].name)));
wii_gx_drawtext(0, y, fontsize, buffer, white, left);
y -= spacing;
#endif

snprintf(buffer, sizeof(buffer), "%s :", gettextmsg("Aspect ratio"));
wii_gx_drawtext(0, y, fontsize, buffer, white, right);
Expand All @@ -170,8 +197,12 @@ void wii_resize_render_callback() {
* @param rinfo Information for the resize operation
*/
void wii_resize_screen_gui(resize_info* rinfo) {
float currentX = rinfo->currentX;
float currentY = rinfo->currentY;

resizeinfo = rinfo;

currentX = rinfo->currentX;
currentY = rinfo->currentY;
currsize = wii_resize_screen_find_size(rinfo, currentX, currentY);

arlocked = TRUE;

Expand Down Expand Up @@ -318,8 +349,13 @@ void wii_resize_screen_gui(resize_info* rinfo) {
if ((down & (WPAD_BUTTON_PLUS | WPAD_CLASSIC_BUTTON_PLUS |
WPAD_CLASSIC_BUTTON_FULL_R)) ||
(gcDown & PAD_TRIGGER_R)) {
currentX = rinfo->defaultX;
currentY = rinfo->defaultY;
currsize++;
if (resizeinfo->size_count <= currsize) {
currsize = 0;
}
const screen_size* size = &(resizeinfo->sizes[currsize]);
currentX = size->w;
currentY = size->h;
reset_aspect_ratio(currentX, currentY);
}

Expand Down

0 comments on commit 5d1b886

Please sign in to comment.