OpenXcom
1.0
Open-source clone of the original X-Com
|
Element that is blit (rendered) onto the screen. More...
#include <Surface.h>
Public Member Functions | |
Surface (int width, int height, int x=0, int y=0, int bpp=8) | |
Creates a new surface with the specified size and position. More... | |
Surface (const Surface &other) | |
Creates a new surface from an existing one. More... | |
virtual | ~Surface () |
Cleans up the surface. More... | |
void | loadScr (const std::string &filename) |
Loads an X-Com SCR graphic. More... | |
void | loadSpk (const std::string &filename) |
Loads an X-Com SPK graphic. More... | |
void | loadBdy (const std::string &filename) |
Loads a TFTD BDY graphic. More... | |
void | loadImage (const std::string &filename) |
Loads a general image file. More... | |
void | clear () |
Clears the surface's contents. More... | |
void | offset (int off, int min=-1, int max=-1, int mul=1) |
Offsets the surface's colors by a set amount. More... | |
void | invert (Uint8 mid) |
Inverts the surface's colors. More... | |
virtual void | think () |
Runs surface functionality every cycle. More... | |
virtual void | draw () |
Draws the surface's graphic. More... | |
virtual void | blit (Surface *surface) |
Blits this surface onto another one. More... | |
virtual void | initText (Font *, Font *, Language *) |
Initializes the surface's various text resources. | |
void | copy (Surface *surface) |
Copies a portion of another surface into this one. More... | |
void | drawRect (SDL_Rect *rect, Uint8 color) |
Draws a filled rectangle on the surface. More... | |
void | drawRect (Sint16 x, Sint16 y, Sint16 w, Sint16 h, Uint8 color) |
Draws a filled rectangle on the surface. More... | |
void | drawLine (Sint16 x1, Sint16 y1, Sint16 x2, Sint16 y2, Uint8 color) |
Draws a line on the surface. More... | |
void | drawCircle (Sint16 x, Sint16 y, Sint16 r, Uint8 color) |
Draws a filled circle on the surface. More... | |
void | drawPolygon (Sint16 *x, Sint16 *y, int n, Uint8 color) |
Draws a filled polygon on the surface. More... | |
void | drawTexturedPolygon (Sint16 *x, Sint16 *y, int n, Surface *texture, int dx, int dy) |
Draws a textured polygon on the surface. More... | |
void | drawString (Sint16 x, Sint16 y, const char *s, Uint8 color) |
Draws a string on the surface. More... | |
virtual void | setPalette (SDL_Color *colors, int firstcolor=0, int ncolors=256) |
Sets the surface's palette. More... | |
SDL_Color * | getPalette () const |
Returns the surface's 8bpp palette. More... | |
virtual void | setX (int x) |
Sets the X position of the surface. More... | |
int | getX () const |
Returns the position of the surface in the X axis. More... | |
virtual void | setY (int y) |
Sets the Y position of the surface. More... | |
int | getY () const |
Returns the position of the surface in the Y axis. More... | |
void | setVisible (bool visible) |
Sets the surface's visibility. More... | |
bool | getVisible () const |
Gets the surface's visibility. More... | |
void | resetCrop () |
Resets the cropping rectangle for the surface. More... | |
SDL_Rect * | getCrop () |
Gets the cropping rectangle for the surface. More... | |
void | setPixel (int x, int y, Uint8 pixel) |
Changes the color of a pixel in the surface, relative to the top-left corner of the surface. More... | |
void | setPixelIterative (int *x, int *y, Uint8 pixel) |
Changes the color of a pixel in the surface and returns the next pixel position. More... | |
Uint8 | getPixel (int x, int y) const |
Returns the color of a specified pixel in the surface. More... | |
SDL_Surface * | getSurface () const |
Returns the internal SDL_Surface for SDL calls. More... | |
int | getWidth () const |
Returns the width of the surface. More... | |
virtual void | setWidth (int width) |
Sets the width of the surface. More... | |
int | getHeight () const |
Returns the height of the surface. More... | |
virtual void | setHeight (int height) |
Sets the height of the surface. More... | |
void | setHidden (bool hidden) |
Sets the surface's special hidden flag. More... | |
void | lock () |
Locks the surface. More... | |
void | unlock () |
Unlocks the surface. More... | |
void | blitNShade (Surface *surface, int x, int y, int off, bool half=false, int newBaseColor=0) |
Specific blit function to blit battlescape terrain data in different shades in a fast way. More... | |
void | invalidate () |
Invalidate the surface: force it to be redrawn. More... | |
std::string | getTooltip () const |
Gets the tooltip of the surface. More... | |
void | setTooltip (const std::string &tooltip) |
Sets the tooltip of the surface. More... | |
Protected Member Functions | |
void | resize (int width, int height) |
Recreates the surface with a new size. More... | |
Element that is blit (rendered) onto the screen.
Mainly an encapsulation for SDL's SDL_Surface struct, so it borrows a lot of its terminology. Takes care of all the common rendering tasks and color effects, while serving as the base class for more specialized screen elements.
OpenXcom::Surface::Surface | ( | int | width, |
int | height, | ||
int | x = 0 , |
||
int | y = 0 , |
||
int | bpp = 8 |
||
) |
Creates a new surface with the specified size and position.
Sets up a blank 8bpp surface with the specified size and position, with pure black as the transparent color.
width | Width in pixels. |
height | Height in pixels. |
x | X position in pixels. |
y | Y position in pixels. |
bpp | Bits-per-pixel depth. |
OpenXcom::Surface::Surface | ( | const Surface & | other | ) |
Creates a new surface from an existing one.
Performs a deep copy of an existing surface.
other | Surface to copy from. |
|
virtual |
Cleans up the surface.
Deletes the surface from memory.
|
virtual |
Blits this surface onto another one.
Blits this surface onto another one, with its position relative to the top-left corner of the target surface.
The cropping rectangle controls the portion of the surface that is blitted.
surface | Pointer to surface to blit onto. |
Reimplemented in OpenXcom::Globe, OpenXcom::TextList, OpenXcom::ComboBox, OpenXcom::BaseView, OpenXcom::Inventory, OpenXcom::Slider, OpenXcom::ScrollBar, and OpenXcom::BattlescapeMessage.
void OpenXcom::Surface::blitNShade | ( | Surface * | surface, |
int | x, | ||
int | y, | ||
int | off, | ||
bool | half = false , |
||
int | newBaseColor = 0 |
||
) |
Specific blit function to blit battlescape terrain data in different shades in a fast way.
Notice there is no surface locking here - you have to make sure you lock the surface yourself at the start of blitting and unlock it when done.
surface | to blit to |
x | |
y | |
off | |
half | some tiles are blitted only the right half |
newBaseColor | Attention: the actual color + 1, because 0 is no new base color. |
void OpenXcom::Surface::clear | ( | ) |
Clears the surface's contents.
Clears the entire contents of the surface, resulting in a blank image.
void OpenXcom::Surface::copy | ( | Surface * | surface | ) |
Copies a portion of another surface into this one.
Copies the exact contents of another surface onto this one.
Only the content that would overlap both surfaces is copied, in accordance with their positions. This is handy for applying effects over another surface without modifying the original.
surface | Pointer to surface to copy from. |
|
virtual |
Draws the surface's graphic.
Draws the graphic that the surface contains before it gets blitted onto other surfaces.
The surface is only redrawn if the flag is set by a property change, to avoid unecessary drawing.
Reimplemented in OpenXcom::TextList, OpenXcom::Globe, OpenXcom::Text, OpenXcom::TextEdit, OpenXcom::BaseView, OpenXcom::Map, OpenXcom::TextButton, OpenXcom::UnitSprite, OpenXcom::ScrollBar, OpenXcom::Bar, OpenXcom::Window, OpenXcom::Inventory, OpenXcom::MiniMapView, OpenXcom::ActionMenuItem, OpenXcom::WarningMessage, OpenXcom::ArrowButton, OpenXcom::MiniBaseView, OpenXcom::FpsCounter, OpenXcom::Frame, OpenXcom::NumberText, OpenXcom::Cursor, OpenXcom::MedikitView, OpenXcom::ScannerView, and OpenXcom::ToggleTextButton.
void OpenXcom::Surface::drawCircle | ( | Sint16 | x, |
Sint16 | y, | ||
Sint16 | r, | ||
Uint8 | color | ||
) |
Draws a filled circle on the surface.
x | X coordinate in pixels. |
y | Y coordinate in pixels. |
r | Radius in pixels. |
color | Color of the circle. |
void OpenXcom::Surface::drawLine | ( | Sint16 | x1, |
Sint16 | y1, | ||
Sint16 | x2, | ||
Sint16 | y2, | ||
Uint8 | color | ||
) |
Draws a line on the surface.
x1 | Start x coordinate in pixels. |
y1 | Start y coordinate in pixels. |
x2 | End x coordinate in pixels. |
y2 | End y coordinate in pixels. |
color | Color of the line. |
void OpenXcom::Surface::drawPolygon | ( | Sint16 * | x, |
Sint16 * | y, | ||
int | n, | ||
Uint8 | color | ||
) |
Draws a filled polygon on the surface.
x | Array of x coordinates. |
y | Array of y coordinates. |
n | Number of points. |
color | Color of the polygon. |
void OpenXcom::Surface::drawRect | ( | SDL_Rect * | rect, |
Uint8 | color | ||
) |
Draws a filled rectangle on the surface.
rect | Pointer to Rect. |
color | Color of the rectangle. |
void OpenXcom::Surface::drawRect | ( | Sint16 | x, |
Sint16 | y, | ||
Sint16 | w, | ||
Sint16 | h, | ||
Uint8 | color | ||
) |
Draws a filled rectangle on the surface.
x | X position in pixels. |
y | Y position in pixels. |
w | Width in pixels. |
h | Height in pixels. |
color | Color of the rectangle. |
void OpenXcom::Surface::drawString | ( | Sint16 | x, |
Sint16 | y, | ||
const char * | s, | ||
Uint8 | color | ||
) |
Draws a string on the surface.
Draws a text string on the surface.
x | X coordinate in pixels. |
y | Y coordinate in pixels. |
s | Character string to draw. |
color | Color of string. |
void OpenXcom::Surface::drawTexturedPolygon | ( | Sint16 * | x, |
Sint16 * | y, | ||
int | n, | ||
Surface * | texture, | ||
int | dx, | ||
int | dy | ||
) |
Draws a textured polygon on the surface.
x | Array of x coordinates. |
y | Array of y coordinates. |
n | Number of points. |
texture | Texture for polygon. |
dx | X offset of texture relative to the screen. |
dy | Y offset of texture relative to the screen. |
SDL_Rect * OpenXcom::Surface::getCrop | ( | ) |
Gets the cropping rectangle for the surface.
Returns the cropping rectangle for this surface.
|
inline |
Returns the height of the surface.
|
inline |
Returns the surface's 8bpp palette.
|
inline |
Returns the color of a specified pixel in the surface.
x | X position of the pixel. |
y | Y position of the pixel. |
|
inline |
Returns the internal SDL_Surface for SDL calls.
std::string OpenXcom::Surface::getTooltip | ( | ) | const |
Gets the tooltip of the surface.
Returns the help description of this surface, for example for showing in tooltips.
bool OpenXcom::Surface::getVisible | ( | ) | const |
Gets the surface's visibility.
Returns the visible state of the surface.
|
inline |
Returns the width of the surface.
|
inline |
Returns the position of the surface in the X axis.
|
inline |
Returns the position of the surface in the Y axis.
void OpenXcom::Surface::invalidate | ( | ) |
Invalidate the surface: force it to be redrawn.
Set the surface to be redrawn.
void OpenXcom::Surface::invert | ( | Uint8 | mid | ) |
Inverts the surface's colors.
Inverts all the colors in the surface according to a middle point.
Used for effects like shifting a button between pressed and unpressed.
mid | Middle point. |
void OpenXcom::Surface::loadBdy | ( | const std::string & | filename | ) |
Loads a TFTD BDY graphic.
Loads the contents of a TFTD BDY image file into the surface.
BDY files are compressed with a custom algorithm.
filename | Filename of the BDY image. |
void OpenXcom::Surface::loadImage | ( | const std::string & | filename | ) |
Loads a general image file.
Loads the contents of an image file of a known format into the surface.
filename | Filename of the image. |
void OpenXcom::Surface::loadScr | ( | const std::string & | filename | ) |
Loads an X-Com SCR graphic.
Loads the contents of an X-Com SCR image file into the surface.
SCR files are simply uncompressed images containing the palette offset of each pixel.
filename | Filename of the SCR image. |
void OpenXcom::Surface::loadSpk | ( | const std::string & | filename | ) |
Loads an X-Com SPK graphic.
Loads the contents of an X-Com SPK image file into the surface.
SPK files are compressed with a custom algorithm since they're usually full-screen images.
filename | Filename of the SPK image. |
void OpenXcom::Surface::lock | ( | ) |
Locks the surface.
Locks the surface from outside access for pixel-level access.
Must be unlocked afterwards.
void OpenXcom::Surface::offset | ( | int | off, |
int | min = -1 , |
||
int | max = -1 , |
||
int | mul = 1 |
||
) |
Offsets the surface's colors by a set amount.
Shifts all the colors in the surface by a set amount.
This is a common method in 8bpp games to simulate color effects for cheap.
off | Amount to shift. |
min | Minimum color to shift to. |
max | Maximum color to shift to. |
mul | Shift multiplier. |
void OpenXcom::Surface::resetCrop | ( | ) |
Resets the cropping rectangle for the surface.
Resets the cropping rectangle set for this surface, so the whole surface is blitted.
|
protected |
Recreates the surface with a new size.
Old contents will not be altered, and may be cropped to fit the new size.
width | Width in pixels. |
height | Height in pixels. |
|
virtual |
Sets the height of the surface.
Changes the height of the surface.
height | New height in pixels. |
Reimplemented in OpenXcom::Map, OpenXcom::TextList, OpenXcom::BattlescapeMessage, and OpenXcom::ScrollBar.
void OpenXcom::Surface::setHidden | ( | bool | hidden | ) |
Sets the surface's special hidden flag.
This is a separate visibility setting intended for temporary effects like window popups, so as to not override the default visibility setting.
hidden | Shown or hidden. |
|
virtual |
Sets the surface's palette.
Replaces a certain amount of colors in the surface's palette.
colors | Pointer to the set of colors. |
firstcolor | Offset of the first color to replace. |
ncolors | Amount of colors to replace. |
Reimplemented in OpenXcom::Globe, OpenXcom::TextList, OpenXcom::Map, OpenXcom::TextEdit, OpenXcom::TextButton, OpenXcom::ComboBox, OpenXcom::ScrollBar, OpenXcom::Slider, OpenXcom::Inventory, OpenXcom::ActionMenuItem, OpenXcom::BattlescapeMessage, OpenXcom::WarningMessage, OpenXcom::NumberText, and OpenXcom::FpsCounter.
|
inline |
Changes the color of a pixel in the surface, relative to the top-left corner of the surface.
x | X position of the pixel. |
y | Y position of the pixel. |
pixel | New color for the pixel. |
|
inline |
Changes the color of a pixel in the surface and returns the next pixel position.
Useful when changing a lot of pixels in a row, eg. loading images.
x | Pointer to the X position of the pixel. Changed to the next X position in the sequence. |
y | Pointer to the Y position of the pixel. Changed to the next Y position in the sequence. |
pixel | New color for the pixel. |
void OpenXcom::Surface::setTooltip | ( | const std::string & | tooltip | ) |
Sets the tooltip of the surface.
Changes the help description of this surface, for example for showing in tooltips.
tooltip | String ID. |
void OpenXcom::Surface::setVisible | ( | bool | visible | ) |
Sets the surface's visibility.
Changes the visibility of the surface.
A hidden surface isn't blitted nor receives events.
visible | New visibility. |
|
virtual |
Sets the width of the surface.
Changes the width of the surface.
width | New width in pixels. |
Reimplemented in OpenXcom::Map.
|
virtual |
Sets the X position of the surface.
Changes the position of the surface in the X axis.
x | X position in pixels. |
Reimplemented in OpenXcom::TextList, OpenXcom::ComboBox, OpenXcom::Slider, OpenXcom::ScrollBar, and OpenXcom::BattlescapeMessage.
|
virtual |
Sets the Y position of the surface.
Changes the position of the surface in the Y axis.
y | Y position in pixels. |
Reimplemented in OpenXcom::TextList, OpenXcom::ComboBox, OpenXcom::Slider, OpenXcom::ScrollBar, and OpenXcom::BattlescapeMessage.
|
virtual |
Runs surface functionality every cycle.
Runs any code the surface needs to keep updating every game cycle, like animations and other real-time elements.
Reimplemented in OpenXcom::TextList, OpenXcom::Globe, OpenXcom::ComboBox, OpenXcom::TextEdit, OpenXcom::Map, OpenXcom::BaseView, OpenXcom::Inventory, OpenXcom::Window, OpenXcom::WarningMessage, OpenXcom::ArrowButton, and OpenXcom::FpsCounter.
void OpenXcom::Surface::unlock | ( | ) |
Unlocks the surface.
Unlocks the surface after it's been locked to resume blitting operations.