| 1 |
/* |
| 2 |
* The Mana World |
| 3 |
* Copyright (C) 2004 The Mana World Development Team |
| 4 |
* |
| 5 |
* This file is part of The Mana World. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef GRAPHICS_H |
| 23 |
#define GRAPHICS_H |
| 24 |
|
| 25 |
#include <guichan/sdl/sdlgraphics.hpp> |
| 26 |
|
| 27 |
class Image; |
| 28 |
class ImageRect; |
| 29 |
|
| 30 |
struct SDL_Surface; |
| 31 |
|
| 32 |
static const int defaultScreenWidth = 800; |
| 33 |
static const int defaultScreenHeight = 600; |
| 34 |
|
| 35 |
/** |
| 36 |
* 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The |
| 37 |
* topology is as follows: |
| 38 |
* |
| 39 |
* <pre> |
| 40 |
* !-----!-----------------!-----! |
| 41 |
* ! 0 ! 1 ! 2 ! |
| 42 |
* !-----!-----------------!-----! |
| 43 |
* ! 3 ! 4 ! 5 ! |
| 44 |
* !-----!-----------------!-----! |
| 45 |
* ! 6 ! 7 ! 8 ! |
| 46 |
* !-----!-----------------!-----! |
| 47 |
* </pre> |
| 48 |
* |
| 49 |
* Sections 0, 2, 6 and 8 will remain as is. 1, 3, 4, 5 and 7 will be |
| 50 |
* repeated to fit the size of the widget. |
| 51 |
*/ |
| 52 |
struct ImageRect |
| 53 |
{ |
| 54 |
enum ImagePosition |
| 55 |
{ |
| 56 |
UPPER_LEFT = 0, |
| 57 |
UPPER_CENTER = 1, |
| 58 |
UPPER_RIGHT = 2, |
| 59 |
LEFT = 3, |
| 60 |
CENTER = 4, |
| 61 |
RIGHT = 5, |
| 62 |
LOWER_LEFT = 6, |
| 63 |
LOWER_CENTER = 7, |
| 64 |
LOWER_RIGHT = 8 |
| 65 |
}; |
| 66 |
|
| 67 |
Image *grid[9]; |
| 68 |
}; |
| 69 |
|
| 70 |
/** |
| 71 |
* A central point of control for graphics. |
| 72 |
*/ |
| 73 |
class Graphics : public gcn::SDLGraphics |
| 74 |
{ |
| 75 |
public: |
| 76 |
/** |
| 77 |
* Constructor. |
| 78 |
*/ |
| 79 |
Graphics(); |
| 80 |
|
| 81 |
/** |
| 82 |
* Destructor. |
| 83 |
*/ |
| 84 |
virtual ~Graphics(); |
| 85 |
|
| 86 |
/** |
| 87 |
* Try to create a window with the given settings. |
| 88 |
*/ |
| 89 |
virtual bool setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel); |
| 90 |
|
| 91 |
/** |
| 92 |
* Set fullscreen mode. |
| 93 |
*/ |
| 94 |
bool setFullscreen(bool fs); |
| 95 |
|
| 96 |
/** |
| 97 |
* Blits an image onto the screen. |
| 98 |
* |
| 99 |
* @return <code>true</code> if the image was blitted properly |
| 100 |
* <code>false</code> otherwise. |
| 101 |
*/ |
| 102 |
bool drawImage(Image *image, int x, int y); |
| 103 |
|
| 104 |
/** |
| 105 |
* Overrides with our own drawing method. |
| 106 |
*/ |
| 107 |
void drawImage(gcn::Image const *image, int srcX, int srcY, |
| 108 |
int dstX, int dstY, int width, int height); |
| 109 |
|
| 110 |
/** |
| 111 |
* Draws a resclaled version of the image |
| 112 |
*/ |
| 113 |
bool drawRescaledImage(Image *image, int srcX, int srcY, |
| 114 |
int dstX, int dstY, |
| 115 |
int width, int height, |
| 116 |
int desiredWidth, int desiredHeight) |
| 117 |
{ return drawRescaledImage(image, srcX, srcY, |
| 118 |
dstX, dstY, |
| 119 |
width, height, |
| 120 |
desiredWidth, desiredHeight, |
| 121 |
false); }; |
| 122 |
|
| 123 |
/** |
| 124 |
* Draws a resclaled version of the image |
| 125 |
*/ |
| 126 |
virtual bool drawRescaledImage(Image *image, int srcX, int srcY, |
| 127 |
int dstX, int dstY, |
| 128 |
int width, int height, |
| 129 |
int desiredWidth, int desiredHeight, |
| 130 |
bool useColor = false); |
| 131 |
|
| 132 |
/** |
| 133 |
* Blits an image onto the screen. |
| 134 |
* |
| 135 |
* @return <code>true</code> if the image was blitted properly |
| 136 |
* <code>false</code> otherwise. |
| 137 |
*/ |
| 138 |
virtual bool drawImage(Image *image, |
| 139 |
int srcX, int srcY, |
| 140 |
int dstX, int dstY, |
| 141 |
int width, int height, |
| 142 |
bool useColor = false); |
| 143 |
|
| 144 |
virtual void drawImagePattern(Image *image, |
| 145 |
int x, int y, |
| 146 |
int w, int h); |
| 147 |
|
| 148 |
/** |
| 149 |
* Draw a pattern based on a rescaled version of the given image... |
| 150 |
*/ |
| 151 |
virtual void drawRescaledImagePattern(Image *image, |
| 152 |
int x, int y, int w, int h, |
| 153 |
int scaledWidth, int scaledHeight); |
| 154 |
|
| 155 |
/** |
| 156 |
* Draws a rectangle using images. 4 corner images, 4 side images and 1 |
| 157 |
* image for the inside. |
| 158 |
*/ |
| 159 |
void drawImageRect( |
| 160 |
int x, int y, int w, int h, |
| 161 |
Image *topLeft, Image *topRight, |
| 162 |
Image *bottomLeft, Image *bottomRight, |
| 163 |
Image *top, Image *right, |
| 164 |
Image *bottom, Image *left, |
| 165 |
Image *center); |
| 166 |
|
| 167 |
/** |
| 168 |
* Draws a rectangle using images. 4 corner images, 4 side images and 1 |
| 169 |
* image for the inside. |
| 170 |
*/ |
| 171 |
void drawImageRect( |
| 172 |
int x, int y, int w, int h, |
| 173 |
const ImageRect &imgRect); |
| 174 |
|
| 175 |
/** |
| 176 |
* Updates the screen. This is done by either copying the buffer to the |
| 177 |
* screen or swapping pages. |
| 178 |
*/ |
| 179 |
virtual void updateScreen(); |
| 180 |
|
| 181 |
/** |
| 182 |
* Returns the width of the screen. |
| 183 |
*/ |
| 184 |
int getWidth() const; |
| 185 |
|
| 186 |
/** |
| 187 |
* Returns the height of the screen. |
| 188 |
*/ |
| 189 |
int getHeight() const; |
| 190 |
|
| 191 |
/** |
| 192 |
* Takes a screenshot and returns it as SDL surface. |
| 193 |
*/ |
| 194 |
virtual SDL_Surface *getScreenshot(); |
| 195 |
|
| 196 |
protected: |
| 197 |
SDL_Surface *mScreen; |
| 198 |
bool mFullscreen, mHWAccel; |
| 199 |
}; |
| 200 |
|
| 201 |
extern Graphics *graphics; |
| 202 |
|
| 203 |
#endif |