1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-04 18:29:41 +01:00
VVVVVV/desktop_version/src/Graphics.h

359 lines
8.4 KiB
C
Raw Normal View History

2020-01-01 21:29:24 +01:00
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include <map>
2020-01-01 21:29:24 +01:00
#include <string>
#include <vector>
2020-01-01 21:29:24 +01:00
#include "GraphicsResources.h"
2020-01-01 21:29:24 +01:00
#include "GraphicsUtil.h"
#include "Maths.h"
#include "Textbox.h"
#include "TowerBG.h"
2020-01-01 21:29:24 +01:00
class Graphics
{
public:
void init(void);
void destroy(void);
2020-01-01 21:29:24 +01:00
void create_buffers(const SDL_PixelFormat* fmt);
void destroy_buffers(void);
GraphicsResources grphx;
2020-01-01 21:29:24 +01:00
int bfontlen(uint32_t ch);
int font_idx(uint32_t ch);
bool Makebfont(void);
2020-01-01 21:29:24 +01:00
void drawhuetile(int x, int y, int t);
void huetilesetcol(int t);
Uint32 bigchunkygetcol(int t);
2020-01-01 21:29:24 +01:00
void drawgravityline(int t);
2020-01-01 21:29:24 +01:00
bool MakeTileArray(void);
2020-01-01 21:29:24 +01:00
bool MakeSpriteArray(void);
2020-01-01 21:29:24 +01:00
bool maketelearray(void);
2020-01-01 21:29:24 +01:00
void drawcoloredtile(int x, int y, int t, int r, int g, int b);
2020-01-01 21:29:24 +01:00
void drawmenu(int cr, int cg, int cb, bool levelmenu = false);
2020-01-01 21:29:24 +01:00
void processfade(void);
void setfade(const int amount);
2020-01-01 21:29:24 +01:00
void drawfade(void);
2020-01-01 21:29:24 +01:00
void setwarprect(int a, int b, int c, int d);
2020-01-01 21:29:24 +01:00
void createtextboxreal(
const std::string& t,
int xp,
int yp,
int r,
int g,
int b,
bool flipme
);
void createtextbox(
const std::string& t,
int xp,
int yp,
int r,
int g,
int b
);
void createtextboxflipme(
const std::string& t,
int xp,
int yp,
int r,
int g,
int b
);
2020-01-01 21:29:24 +01:00
void textboxcenterx(void);
2020-01-01 21:29:24 +01:00
int textboxwidth(void);
2020-01-01 21:29:24 +01:00
void textboxmoveto(int xo);
2020-01-01 21:29:24 +01:00
void textboxcentery(void);
2020-01-01 21:29:24 +01:00
void textboxadjust(void);
2020-01-01 21:29:24 +01:00
void addline(const std::string& t);
2020-01-01 21:29:24 +01:00
void textboxtimer(int t);
2020-01-01 21:29:24 +01:00
void textboxremove(void);
2020-01-01 21:29:24 +01:00
void textboxremovefast(void);
2020-01-01 21:29:24 +01:00
void textboxactive(void);
2020-01-01 21:29:24 +01:00
void drawtextbox(int x, int y, int w, int h, int r, int g, int b);
2020-01-01 21:29:24 +01:00
void drawpixeltextbox(int x, int y, int w, int h, int r, int g, int b);
2020-01-01 21:29:24 +01:00
void drawcrewman(int x, int y, int t, bool act, bool noshift =false);
2020-01-01 21:29:24 +01:00
int crewcolour(const int t);
2020-01-01 21:29:24 +01:00
void cutscenebars(void);
void cutscenebarstimer(void);
void setbars(const int position);
2020-01-01 21:29:24 +01:00
void drawpartimage(int t, int xp, int yp, int wp, int hp);
2020-01-01 21:29:24 +01:00
void drawimage(int t, int xp, int yp, bool cent=false);
2020-01-01 21:29:24 +01:00
void drawimagecol(int t, int xp, int yp, bool cent= false);
2020-01-01 21:29:24 +01:00
void updatetextboxes(void);
void drawgui(void);
2020-01-01 21:29:24 +01:00
void drawsprite(int x, int y, int t, int r, int g, int b);
void drawsprite(int x, int y, int t, Uint32 c);
2020-01-01 21:29:24 +01:00
void printcrewname(int x, int y, int t);
2020-01-01 21:29:24 +01:00
void printcrewnamestatus(int x, int y, int t);
2020-01-01 21:29:24 +01:00
void printcrewnamedark(int x, int y, int t);
2020-01-01 21:29:24 +01:00
void map_tab(int opt, const std::string& text, bool selected = false);
void map_option(int opt, int num_opts, const std::string& text, bool selected = false);
void do_print(int x, int y, const std::string& text, int r, int g, int b, int a, int scale);
void Print(int _x, int _y, const std::string& _s, int r, int g, int b, bool cen = false);
2020-01-01 21:29:24 +01:00
void PrintAlpha(int _x, int _y, const std::string& _s, int r, int g, int b, int a, bool cen = false);
bool next_wrap(size_t* start, size_t* len, const char* str, int maxwidth);
bool next_wrap_s(char buffer[], size_t buffer_size, size_t* start, const char* str, int maxwidth);
void PrintWrap(int x, int y, const char* str, int r, int g, int b, bool cen, int linespacing, int maxwidth);
void bprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false);
2020-01-01 21:29:24 +01:00
void bprintalpha(int x, int y, const std::string& t, int r, int g, int b, int a, bool cen = false);
int len(const std::string& t);
void bigprint( int _x, int _y, const std::string& _s, int r, int g, int b, bool cen = false, int sc = 2 );
void bigbprint(int x, int y, const std::string& s, int r, int g, int b, bool cen = false, int sc = 2);
void drawspritesetcol(int x, int y, int t, int c);
2020-01-01 21:29:24 +01:00
void flashlight(void);
void screenshake(void);
void updatescreenshake(void);
int screenshake_x;
int screenshake_y;
2020-01-01 21:29:24 +01:00
void render(void);
void renderwithscreeneffects(void);
void renderfixedpre(void);
void renderfixedpost(void);
2020-01-01 21:29:24 +01:00
bool Hitest(SDL_Surface* surface1, point p1, SDL_Surface* surface2, point p2);
2020-01-01 21:29:24 +01:00
void drawentities(void);
2020-01-01 21:29:24 +01:00
void drawentity(const int i, const int yoff);
void drawtrophytext(void);
2020-01-01 21:29:24 +01:00
void bigrprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
void bigbrprint(int x, int y, const std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
2020-01-01 21:29:24 +01:00
void drawtele(int x, int y, int t, Uint32 c);
2020-01-01 21:29:24 +01:00
Uint32 getRGBA(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
Uint32 getRGB(Uint8 r, Uint8 g, Uint8 b);
2020-01-01 21:29:24 +01:00
Uint32 getRGB(Uint32 _col);
2020-01-01 21:29:24 +01:00
Uint32 RGBf(int r, int g, int b);
2020-01-01 21:29:24 +01:00
void setcolreal(Uint32 t);
2020-01-01 21:29:24 +01:00
void drawbackground(int t);
void updatebackground(int t);
#ifndef NO_CUSTOM_LEVELS
bool shouldrecoloroneway(const int tilenum, const bool mounted);
#endif
void drawtile3( int x, int y, int t, int off, int height_subtract = 0 );
void drawtile2( int x, int y, int t );
void drawtile( int x, int y, int t );
void drawtowertile( int x, int y, int t );
void drawtowertile3( int x, int y, int t, TowerBG& bg_obj );
2020-01-01 21:29:24 +01:00
void drawmap(void);
2020-01-01 21:29:24 +01:00
void drawforetile(int x, int y, int t);
2020-01-01 21:29:24 +01:00
void drawforetile2(int x, int y, int t);
2020-01-01 21:29:24 +01:00
void drawforetile3(int x, int y, int t, int off);
2020-01-01 21:29:24 +01:00
void drawrect(int x, int y, int w, int h, int r, int g, int b);
2020-01-01 21:29:24 +01:00
void drawtowermap(void);
2020-01-01 21:29:24 +01:00
void drawtowerspikes(void);
2020-01-01 21:29:24 +01:00
bool onscreen(int t);
bool reloadresources(void);
#ifndef NO_CUSTOM_LEVELS
bool tiles1_mounted;
bool tiles2_mounted;
bool minimap_mounted;
#endif
2020-01-01 21:29:24 +01:00
void menuoffrender(void);
2020-01-01 21:29:24 +01:00
void drawtowerbackground(const TowerBG& bg_obj);
void updatetowerbackground(TowerBG& bg_obj);
2020-01-01 21:29:24 +01:00
void setcol(int t);
void drawfinalmap(void);
2020-01-01 21:29:24 +01:00
colourTransform ct;
2020-01-01 21:29:24 +01:00
int rcol;
2020-01-01 21:29:24 +01:00
int m;
2020-01-01 21:29:24 +01:00
std::vector <SDL_Surface*> images;
2020-01-01 21:29:24 +01:00
std::vector <SDL_Surface*> tele;
std::vector <SDL_Surface*> tiles;
std::vector <SDL_Surface*> tiles2;
std::vector <SDL_Surface*> tiles3;
std::vector <SDL_Surface*> entcolours;
std::vector <SDL_Surface*> sprites;
std::vector <SDL_Surface*> flipsprites;
std::vector <SDL_Surface*> bfont;
std::vector <SDL_Surface*> flipbfont;
2020-01-01 21:29:24 +01:00
bool flipmode;
bool setflipmode;
bool notextoutline;
//buffer objects. //TODO refactor buffer objects
SDL_Surface* backBuffer;
SDL_Surface* menubuffer;
SDL_Surface* foregroundBuffer;
SDL_Surface* tempBuffer;
SDL_Surface* warpbuffer;
SDL_Surface* warpbuffer_lerp;
2020-01-01 21:29:24 +01:00
TowerBG towerbg;
TowerBG titlebg;
SDL_Rect tiles_rect;
SDL_Rect sprites_rect;
SDL_Rect line_rect;
SDL_Rect tele_rect;
SDL_Rect towerbuffer_rect;
2020-01-01 21:29:24 +01:00
SDL_Rect prect;
SDL_Rect footerrect;
SDL_Surface* footerbuffer;
2020-01-01 21:29:24 +01:00
int linestate, linedelay;
int backoffset;
bool backgrounddrawn, foregrounddrawn;
2020-01-01 21:29:24 +01:00
int menuoffset;
int oldmenuoffset;
bool resumegamemode;
2020-01-01 21:29:24 +01:00
SDL_Rect warprect;
2020-01-01 21:29:24 +01:00
int crewframe;
int crewframedelay;
2020-01-01 21:29:24 +01:00
int fademode;
int fadeamount;
int oldfadeamount;
int fadebars[15];
int ingame_fademode;
2020-01-01 21:29:24 +01:00
bool trinketcolset;
int trinketr, trinketg, trinketb;
2020-01-01 21:29:24 +01:00
std::vector <textboxclass> textboxes;
2020-01-01 21:29:24 +01:00
bool showcutscenebars;
int cutscenebarspos;
int oldcutscenebarspos;
2020-01-01 21:29:24 +01:00
static const int numstars = 50;
SDL_Rect stars[numstars];
int starsspeed[numstars];
2020-01-01 21:29:24 +01:00
static const int numbackboxes = 18;
int spcol, spcoldel;
SDL_Rect backboxes[numbackboxes];
int backboxvx[numbackboxes];
int backboxvy[numbackboxes];
float backboxint[numbackboxes];
2020-01-01 21:29:24 +01:00
int warpskip, warpfcol, warpbcol;
2020-01-01 21:29:24 +01:00
bool translucentroomname;
std::map<int, int> font_positions;
SDL_Surface* ghostbuffer;
float inline lerp(const float v0, const float v1)
{
return v0 + alpha * (v1 - v0);
}
float alpha;
Uint32 col_crewred;
Uint32 col_crewyellow;
Uint32 col_crewgreen;
Uint32 col_crewcyan;
Uint32 col_crewblue;
Uint32 col_crewpurple; //actually pink
Uint32 col_crewinactive;
Uint32 col_clock;
Uint32 col_trinket;
int col_tr;
int col_tg;
int col_tb;
void updatetitlecolours(void);
bool kludgeswnlinewidth;
Uint32 crewcolourreal(int t);
char error[128];
char error_title[128]; /* for SDL_ShowSimpleMessageBox */
2020-01-01 21:29:24 +01:00
};
#ifndef GRAPHICS_DEFINITION
Allow using help/graphics/music/game/key/map/obj everywhere This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and `obj` essentially static global objects that can be used everywhere. This is useful in case we ever need to add a new function in the future, so we don't have to bother with passing a new argument in which means we have to pass a new argument in to the function that calls that function which means having to pass a new argument into the function that calls THAT function, etc. which is a real headache when working on fan mods of the source code. Note that this changes NONE of the existing function signatures, it merely just makes those variables accessible everywhere in the same way `script` and `ed` are. Also note that some classes had to be initialized after the filesystem was initialized, but C++ would keep initializing them before the filesystem got initialized, because I *had* to put them at the top of `main.cpp`, or else they wouldn't be global variables. The only way to work around this was to use entityclass's initialization style (which I'm pretty sure entityclass of all things doesn't need to be initialized this way), where you actually initialize the class in an `init()` function, and so then you do `graphics.init()` after the filesystem initialization, AFTER doing `Graphics graphics` up at the top. I've had to do this for `graphics` (but only because its child GraphicsResources `grphx` needs to be initialized this way), `music`, and `game`. I don't think this will affect anything. Other than that, `help`, `key`, and `map` are still using the C++-intended method of having ClassName::ClassName() functions.
2020-01-29 08:35:03 +01:00
extern Graphics graphics;
#endif
Allow using help/graphics/music/game/key/map/obj everywhere This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and `obj` essentially static global objects that can be used everywhere. This is useful in case we ever need to add a new function in the future, so we don't have to bother with passing a new argument in which means we have to pass a new argument in to the function that calls that function which means having to pass a new argument into the function that calls THAT function, etc. which is a real headache when working on fan mods of the source code. Note that this changes NONE of the existing function signatures, it merely just makes those variables accessible everywhere in the same way `script` and `ed` are. Also note that some classes had to be initialized after the filesystem was initialized, but C++ would keep initializing them before the filesystem got initialized, because I *had* to put them at the top of `main.cpp`, or else they wouldn't be global variables. The only way to work around this was to use entityclass's initialization style (which I'm pretty sure entityclass of all things doesn't need to be initialized this way), where you actually initialize the class in an `init()` function, and so then you do `graphics.init()` after the filesystem initialization, AFTER doing `Graphics graphics` up at the top. I've had to do this for `graphics` (but only because its child GraphicsResources `grphx` needs to be initialized this way), `music`, and `game`. I don't think this will affect anything. Other than that, `help`, `key`, and `map` are still using the C++-intended method of having ClassName::ClassName() functions.
2020-01-29 08:35:03 +01:00
2020-01-01 21:29:24 +01:00
#endif /* GRAPHICS_H */