Skip to content

Commit

Permalink
In-game widescreen toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Feb 6, 2023
1 parent 9acc208 commit 30c2d82
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 82 deletions.
2 changes: 2 additions & 0 deletions src/SDLU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ void SDLU_CreateRendererTexture()
SDL_PIXELFORMAT_RGB888,
SDL_TEXTUREACCESS_STREAMING,
640, 480);

SDL_RenderSetLogicalSize(g_renderer, 640, widescreen ? 360: 480);
}


Expand Down
50 changes: 34 additions & 16 deletions src/level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ enum
kTitleItemQuit,
};

struct {
struct TitleItemDef
{
const char* name;
MRGBColor color1;
MRGBColor color2;
MRect rect;
} titleItems[kTitleItems] = {
};

static const TitleItemDef k_titleItemDefs[kTitleItems] =
{
{ "\x03 Tutorial Mode", {204, 67,137}, {101, 74,207}, {155, 203, 207, 426} },
{ "\x03 One Player Game", { 35, 31,240}, { 81,237,252}, {225, 179, 281, 451} },
{ "\x03 Two Player Game", {212,194, 48}, {255,196, 56}, {297, 182, 352, 454} },
Expand All @@ -82,8 +86,6 @@ struct {
const int kCursorWidth = 32;
const int kCursorHeight = 32;

extern MBoolean useNewTitle;

#if USE_CURSOR_SPRITE
static void InsertCursor( MPoint mouseHere, SDL_Surface* scratch, SDL_Surface* surface )
{
Expand Down Expand Up @@ -124,6 +126,8 @@ static void GameStartMenuRepaint()

void GameStartMenu( void )
{
MBoolean useNewTitle = widescreen;

// NOTE: be wary of initializing variables here! This function can run top-to-bottom
// multiple times in a row, thanks to "redo". Put initializations after redo.
SDL_Surface* gameStartSurface;
Expand All @@ -144,14 +148,17 @@ void GameStartMenu( void )
SkittlesFontPtr smallFont = GetFont( picFont );
SkittlesFontPtr tinyFont = GetFont( picTinyFont );
SDL_Rect meterRect[2] = { { 30, 360, 110, 20 }, { 530, 360, 110, 20 } };
TitleItemDef titleItems[kTitleItems];
int titleGlow[kTitleItems];
int shouldAddBlob;
const int kTitleGlowOff = useNewTitle? 150: 192;
const bool secretCreditsItem = !useNewTitle;

const int kLeftSide = 0, kRightSide = 1, kGlow = 2, kCursor = 3;


redo:
memcpy(titleItems, k_titleItemDefs, sizeof(titleItems));

combo[0] = combo[1] = 0;
comboBright[0] = comboBright[1] = 0;
Expand Down Expand Up @@ -192,10 +199,13 @@ void GameStartMenu( void )

// make drawing surface
gameStartDrawSurface = SDLU_InitSurface( &backdropSDLRect, 32 );
if (!useNewTitle) {
if (!useNewTitle)
{
SDLU_BlitSurface(gameStartSurface, &gameStartSurface->clip_rect,
gameStartDrawSurface, &gameStartDrawSurface->clip_rect);
} else {
}
else
{
// Prepare new title screen
SDL_FillRect(gameStartDrawSurface, &gameStartDrawSurface->clip_rect, black);

Expand All @@ -212,13 +222,15 @@ void GameStartMenu( void )
int left = 225;
dPoint.h = left;
dPoint.v = 215;
for (int i = 0; i < kTitleItems; i++) {
for (int i = 0; i < kTitleItems; i++)
{
auto &item = titleItems[i];
item.rect.left = dPoint.h;
item.rect.top = dPoint.v - 6;
item.rect.bottom = dPoint.v + 16 + 6;
auto nameLength = strlen(item.name);
for (int charNo = 0; charNo < nameLength; charNo++) {
for (int charNo = 0; charNo < nameLength; charNo++)
{
char c = item.name[charNo];
float p = charNo / (float) (nameLength - 1);
int red = item.color1.red * (1.0f - p) + item.color2.red * p;
Expand Down Expand Up @@ -754,14 +766,7 @@ void InitGame( int player1, int player2 )

// In widescreen mode, move score/gray windows closer to the playfield
// so they fit in the cropped screen.
if (widescreen) {
for (int i = 0; i < 2; i++) {
grayMonitorRect[i].top = playerWindowRect[i].top - 32 - 4;
grayMonitorRect[i].bottom = playerWindowRect[i].top - 4;
scoreWindowRect[i].top = playerWindowRect[i].bottom + 4;
scoreWindowRect[i].bottom = playerWindowRect[i].bottom + 16 + 4;
}
}
ResetWidescreenLayout();

nextWindowVisible[0] = ( player1 == kAutoControl )? false: true;

Expand All @@ -782,6 +787,19 @@ void InitGame( int player1, int player2 )
credits = (player2 == kNobodyControl)? 1: 5;
}

void ResetWidescreenLayout()
{
int miniWindowOffset = widescreen ? 4 : 16;

for (int i = 0; i < 2; i++)
{
grayMonitorRect[i].top = playerWindowRect[i].top - 32 - miniWindowOffset;
grayMonitorRect[i].bottom = playerWindowRect[i].top - miniWindowOffset;
scoreWindowRect[i].top = playerWindowRect[i].bottom + miniWindowOffset;
scoreWindowRect[i].bottom = playerWindowRect[i].bottom + 16 + miniWindowOffset;
}
}

MBoolean InitCharacter( int player, int level )
{
const Character characterList[] = {
Expand Down
1 change: 1 addition & 0 deletions src/level.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// level.h

void InitGame( int player1, int player2 );
void ResetWidescreenLayout( );
MBoolean InitCharacter( int player, int level );
void PrepareStageGraphics( int type );
void BeginRound( MBoolean changeMusic );
Expand Down
10 changes: 2 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,15 @@ MBoolean needsRefresh = false;

static char candyCrisisResources[512];

MBoolean fullscreen = false;
MBoolean widescreen = false;
MBoolean useNewTitle = widescreen;
MBoolean fullscreen = true;
MBoolean widescreen = true;
MBoolean crispUpscaling = false;

int main(int argc, char *argv[])
{
Initialize( );

LoadPrefs( );
ParseCommandLine( argc, argv );

if ( widescreen )
useNewTitle = true;

ReserveMonitor( );
ShowTitle( );

Expand Down
Loading

0 comments on commit 30c2d82

Please sign in to comment.