#include "localconsts.h"
class Image;
class ImageCollection;
class ImageVertexes;
class MapLayer;
struct SDL_Surface;
static const int defaultScreenWidth = 800;
static const int defaultScreenHeight = 600;
int MSDL_gfxBlitRGBA(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
/**
* 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The
* topology is as follows:
*
*
* !-----!-----------------!-----!
* ! 0 ! 1 ! 2 !
* !-----!-----------------!-----!
* ! 3 ! 4 ! 5 !
* !-----!-----------------!-----!
* ! 6 ! 7 ! 8 !
* !-----!-----------------!-----!
*
*
* Sections 0, 2, 6 and 8 will remain as is. 1, 3, 4, 5 and 7 will be
* repeated to fit the size of the widget.
*/
class ImageRect final
{
public:
ImageRect()
{
for (int f = 0; f < 9; f ++)
grid[f] = nullptr;
}
A_DELETE_COPY(ImageRect)
enum ImagePosition
{
UPPER_LEFT = 0,
UPPER_CENTER = 1,
UPPER_RIGHT = 2,
LEFT = 3,
CENTER = 4,
RIGHT = 5,
LOWER_LEFT = 6,
LOWER_CENTER = 7,
LOWER_RIGHT = 8
};
Image *grid[9];
};
/**
* A central point of control for graphics.
*/
class Graphics : public gcn::SDLGraphics
{
public:
/**
* Constructor.
*/
Graphics();
A_DELETE_COPY(Graphics)
/**
* Destructor.
*/
virtual ~Graphics();
/**
* Sets whether vertical refresh syncing is enabled. Takes effect after
* the next call to setVideoMode(). Only implemented on MacOS for now.
*/
void setSync(const bool sync);
bool getSync() const A_WARN_UNUSED
{ return mSync; }
/**
* Try to create a window with the given settings.
*/
virtual bool setVideoMode(const int w, const int h, const int bpp,
const bool fs, const bool hwaccel,
const bool resize, const bool noFrame);
/**
* Set fullscreen mode.
*/
bool setFullscreen(const bool fs);
/**
* Resize the window to the specified size.
*/
bool resizeScreen(const int width, const int height);
/**
* Blits an image onto the screen.
*
* @return true
if the image was blitted properly
* false
otherwise.
*/
bool drawImage(const Image *image, int x, int y);
/**
* Draws a resclaled version of the image
*/
virtual bool drawRescaledImage(const Image *const image, int srcX,
int srcY, int dstX, int dstY,
const int width, const int height,
const int desiredWidth,
const int desiredHeight,
const bool useColor = false) = 0;
virtual void drawImagePattern(const Image *const image,
const int x, const int y,
const int w, const int h) = 0;
/**
* Draw a pattern based on a rescaled version of the given image...
*/
virtual void drawRescaledImagePattern(const Image *const image,
const int x, const int y,
const int w, const int h,
const int scaledWidth,
const int scaledHeight) = 0;
/**
* Draws a rectangle using images. 4 corner images, 4 side images and 1
* image for the inside.
*/
void drawImageRect(const int x, const int y, const int w, const int h,
const Image *const topLeft,
const Image *const topRight,
const Image *const bottomLeft,
const Image *const bottomRight,
const Image *const top,
const Image *const right,
const Image *const bottom,
const Image *const left,
const Image *const center);
/**
* Draws a rectangle using images. 4 corner images, 4 side images and 1
* image for the inside.
*/
void drawImageRect(int x, int y, int w, int h,
const ImageRect &imgRect);
bool calcImageRect(ImageVertexes *const vert,
const int x, const int y,
const int w, const int h,
const Image *const topLeft,
const Image *const topRight,
const Image *const bottomLeft,
const Image *const bottomRight,
const Image *const top,
const Image *const right,
const Image *const bottom,
const Image *const left,
const Image *const center);
virtual void calcImagePattern(ImageVertexes *const vert,
const Image *const image,
const int x, const int y,
const int w, const int h) const = 0;
virtual void calcImagePattern(ImageCollection *const vert,
const Image *const image,
const int x, const int y,
const int w, const int h) const = 0;
virtual void calcTile(ImageVertexes *const vert,
const Image *const image,
int x, int y) const = 0;
virtual void calcTileSDL(ImageVertexes *const vert A_UNUSED,
int x A_UNUSED, int y A_UNUSED) const
{
}
virtual void drawTile(const ImageVertexes *const vert) = 0;
virtual void drawTile(const ImageCollection *const vertCol) = 0;
virtual void calcTile(ImageCollection *const vertCol,
const Image *const image,
int x, int y) = 0;
virtual bool calcWindow(ImageCollection *const vertCol,
const int x, const int y,
const int w, const int h,
const ImageRect &imgRect) = 0;
/**
* Draws a rectangle using images. 4 corner images, 4 side images and 1
* image for the inside.
*/
inline void drawImageRect(const gcn::Rectangle &area,
const ImageRect &imgRect)
{ drawImageRect(area.x, area.y, area.width, area.height, imgRect); }
virtual void fillRectangle(const gcn::Rectangle& rectangle)
override = 0;
/**
* Updates the screen. This is done by either copying the buffer to the
* screen or swapping pages.
*/
virtual void updateScreen() = 0;
/**
* Returns the width of the screen.
*/
int getWidth() const A_WARN_UNUSED;
/**
* Returns the height of the screen.
*/
int getHeight() const A_WARN_UNUSED;
/**
* Takes a screenshot and returns it as SDL surface.
*/
virtual SDL_Surface *getScreenshot() A_WARN_UNUSED = 0;
virtual void prepareScreenshot()
{ }
int getMemoryUsage() const A_WARN_UNUSED;
virtual bool drawNet(const int x1, const int y1,
const int x2, const int y2,
const int width, const int height);
const gcn::Font *getFont() const A_WARN_UNUSED
{ return mFont; }
gcn::ClipRectangle &getTopClip() A_WARN_UNUSED
{ return mClipStack.top(); }
void setRedraw(const bool n)
{ mRedraw = n; }
bool getRedraw() const A_WARN_UNUSED
{ return mRedraw; }
void setSecure(const bool n)
{ mSecure = n; }
bool getSecure() const A_WARN_UNUSED
{ return mSecure; }
int getBpp() const A_WARN_UNUSED
{ return mBpp; }
bool getFullScreen() const A_WARN_UNUSED
{ return mFullscreen; }
bool getHWAccel() const A_WARN_UNUSED
{ return mHWAccel; }
bool getDoubleBuffer() const A_WARN_UNUSED
{ return mDoubleBuffer; }
int getOpenGL() const A_WARN_UNUSED
{ return mOpenGL; }
void setNoFrame(const bool n)
{ mNoFrame = n; }
const std::string &getName() const A_WARN_UNUSED
{ return mName; }
virtual void initArrays()
{ }
void setColor(const gcn::Color &color)
{
mColor = color;
mColor2 = color;
mAlpha = (color.a != 255);
}
void setColor2(const gcn::Color &color)
{ mColor2 = color; }
void setColorAll(const gcn::Color &color, const gcn::Color &color2)
{
mColor = color;
mColor2 = color2;
mAlpha = (color.a != 255);
}
const gcn::Color &getColor2() const
{ return mColor2; }
#ifdef DEBUG_DRAW_CALLS
virtual unsigned int getDrawCalls() const
{ return 0; }
#endif
#ifdef DEBUG_BIND_TEXTURE
virtual unsigned int getBinds() const
{ return 0; }
#endif
int mWidth;
int mHeight;
protected:
/**
* Blits an image onto the screen.
*
* @return true
if the image was blitted properly
* false
otherwise.
*/
virtual bool drawImage2(const Image *const image,
int srcX, int srcY,
int dstX, int dstY,
const int width, const int height,
const bool useColor) = 0;
void setMainFlags(int w, int h, int bpp, bool fs,
bool hwaccel, bool resize, bool noFrame);
int getOpenGLFlags() const A_WARN_UNUSED;
int getSoftwareFlags() const A_WARN_UNUSED;
bool setOpenGLMode();
void updateMemoryInfo();
bool videoInfo();
int mBpp;
bool mFullscreen;
bool mHWAccel;
bool mRedraw;
bool mDoubleBuffer;
SDL_Rect mRect;
bool mSecure;
int mOpenGL;
bool mEnableResize;
bool mNoFrame;
std::string mName;
int mStartFreeMem;
bool mSync;
gcn::Color mColor2;
};
extern Graphics *mainGraphics;
#endif // GRAPHICS_H