#pragma once
#include <SDL2/SDL.h>
#include "loader.h"
#include "tween.h"
/*
Copyright (c) 2013-2021 Devine Lu Linvega
2018 web port by rezmason
2021 C89 port by rezmason
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE.
*/
/*
Every image onscreen is positioned and scaled
relative to some rectangular region, which in turn
is positioned and scaled relative to the window dimensions.
Stage manages these regions' screen coordinates, along with the
images inside them, including loading and unloading the lazy ones.
Stage also manages the regions' tinting, fading and "camera motion".
*/
/*
A region can scale its image content in one of four ways:
CONTAIN - preserve the image proportions, scaling it to fit inside the region
COVER - preserve the image proportions, scaling it so the region fits inside it, and then cropping it
STRETCH — match the image dimensions exactly to the region's, disregarding proportion
STRETCH_NODE — like STRETCH, except the region is posiitoned and scaled relative to the node region, rather than the window
*/
typedef enum {
LAYOUTMODE_CONTAIN,
LAYOUTMODE_COVER,
LAYOUTMODE_STRETCH,
LAYOUTMODE_STRETCH_NODE
} LayoutMode;
/* SDL_Rect is all integers, but Stage's layout math is done in floating point */
typedef struct {
double x, y, w, h;
} RegionRect;
typedef enum {
BILLBOARD_NODE,
BILLBOARD_LAST_NODE_FADE,
BILLBOARD_VIGNETTE,
BILLBOARD_MENU_BLACK,
BILLBOARD_MENU_CREDIT1,
BILLBOARD_MENU_CREDIT2,
BILLBOARD_MENU_CREDIT3,
BILLBOARD_MENU_CREDIT4,
BILLBOARD_MENU_LOGO,
BILLBOARD_MENU_CONTROLS,
BILLBOARD_ENTENTE_SCREEN,
BILLBOARD_CLOCK,
BILLBOARD_CLOCK_SHADOW,
BILLBOARD_PROGRESS_PANE,
BILLBOARD_HUD_FUSE,
BILLBOARD_HUD_FUSE_ALERT,
BILLBOARD_HUD_AUDIO,
BILLBOARD_HUD_CLOCK,
BILLBOARD_HUD_CLOCK_ALERT,
BILLBOARD_HUD_SAVE,
BILLBOARD_HUD_SEAL_1,
BILLBOARD_HUD_SEAL_2,
BILLBOARD_HUD_SEAL_ALERT,
BILLBOARD_HUD_STEP_FORWARD,
BILLBOARD_HUD_STEP_LEFT,
BILLBOARD_HUD_STEP_RIGHT,
BILLBOARD_SPLASH_TOP,
BILLBOARD_SPLASH_LEFT,
BILLBOARD_SPLASH_RIGHT,
TRIGGER_ACTION,
TRIGGER_MOVE_FORWARD,
TRIGGER_MOVE_LEFT,
TRIGGER_MOVE_RIGHT,
NumberOfRegions
} RegionName;
/*
Each region contains all the data needed to reconstruct it,
from the multiple intermediate steps that can be independently invalidated.
*/
typedef struct {
short int line;
RegionRect layout;
LayoutMode layoutMode;
RegionRect bounds;
RegionRect contentRect;
Tween alphaTween;
Image *image;
SDL_Rect dest;
} Region;
extern Region regions[];
void Stage_Init();
void Stage_Quit();
void Stage_SetImage(RegionName name, Image *image);
void Stage_SwapImages(RegionName name1, RegionName name2);
void Stage_Fade(RegionName name, double startAlpha, double endAlpha, double duration, double delay, void (*onComplete)());
void Stage_StopFade(RegionName name, int complete);
void Stage_SetAlpha(RegionName name, double alpha);
void Stage_Tint(SDL_Color color, double duration, double delay);
void Stage_StopTint();
void Stage_Nudge(double x, double y, double duration);
void Stage_Update(double totalTime, double deltaTime);
void Stage_Resize(int windowW, int windowH);
void Stage_Render(SDL_Renderer *renderer);
int Stage_HitTest(RegionName name, int x, int y);
int Stage_PointNearBorder(int x, int y, int locus);