OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Protected Member Functions | List of all members
OpenXcom::Surface Class Reference

Element that is blit (rendered) onto the screen. More...

#include <Surface.h>

Inheritance diagram for OpenXcom::Surface:
OpenXcom::Bar OpenXcom::BattlescapeMessage OpenXcom::Cursor OpenXcom::FpsCounter OpenXcom::Frame OpenXcom::InteractiveSurface OpenXcom::NumberText OpenXcom::Text OpenXcom::UnitSprite OpenXcom::WarningMessage OpenXcom::Window

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Note
Surfaces don't have to fill the whole size since their background is transparent, specially subclasses with their own drawing logic, so it just covers the maximum drawing area.
Parameters
widthWidth in pixels.
heightHeight in pixels.
xX position in pixels.
yY position in pixels.
bppBits-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.

Parameters
otherSurface to copy from.
OpenXcom::Surface::~Surface ( )
virtual

Cleans up the surface.

Deletes the surface from memory.

Member Function Documentation

void OpenXcom::Surface::blit ( Surface surface)
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.

Parameters
surfacePointer 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.

Parameters
surfaceto blit to
x
y
off
halfsome tiles are blitted only the right half
newBaseColorAttention: 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.

Parameters
surfacePointer to surface to copy from.
void OpenXcom::Surface::draw ( )
virtual
void OpenXcom::Surface::drawCircle ( Sint16  x,
Sint16  y,
Sint16  r,
Uint8  color 
)

Draws a filled circle on the surface.

Parameters
xX coordinate in pixels.
yY coordinate in pixels.
rRadius in pixels.
colorColor of the circle.
void OpenXcom::Surface::drawLine ( Sint16  x1,
Sint16  y1,
Sint16  x2,
Sint16  y2,
Uint8  color 
)

Draws a line on the surface.

Parameters
x1Start x coordinate in pixels.
y1Start y coordinate in pixels.
x2End x coordinate in pixels.
y2End y coordinate in pixels.
colorColor of the line.
void OpenXcom::Surface::drawPolygon ( Sint16 *  x,
Sint16 *  y,
int  n,
Uint8  color 
)

Draws a filled polygon on the surface.

Parameters
xArray of x coordinates.
yArray of y coordinates.
nNumber of points.
colorColor of the polygon.
void OpenXcom::Surface::drawRect ( SDL_Rect *  rect,
Uint8  color 
)

Draws a filled rectangle on the surface.

Parameters
rectPointer to Rect.
colorColor of the rectangle.
void OpenXcom::Surface::drawRect ( Sint16  x,
Sint16  y,
Sint16  w,
Sint16  h,
Uint8  color 
)

Draws a filled rectangle on the surface.

Parameters
xX position in pixels.
yY position in pixels.
wWidth in pixels.
hHeight in pixels.
colorColor 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.

Parameters
xX coordinate in pixels.
yY coordinate in pixels.
sCharacter string to draw.
colorColor 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.

Parameters
xArray of x coordinates.
yArray of y coordinates.
nNumber of points.
textureTexture for polygon.
dxX offset of texture relative to the screen.
dyY 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.

Returns
Pointer to the cropping rectangle.
int OpenXcom::Surface::getHeight ( ) const
inline

Returns the height of the surface.

Returns
Height in pixels
SDL_Color* OpenXcom::Surface::getPalette ( ) const
inline

Returns the surface's 8bpp palette.

Returns
Pointer to the palette's colors.
Uint8 OpenXcom::Surface::getPixel ( int  x,
int  y 
) const
inline

Returns the color of a specified pixel in the surface.

Parameters
xX position of the pixel.
yY position of the pixel.
Returns
Color of the pixel.
SDL_Surface* OpenXcom::Surface::getSurface ( ) const
inline

Returns the internal SDL_Surface for SDL calls.

Returns
Pointer to the surface.
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.

Returns
String ID.
bool OpenXcom::Surface::getVisible ( ) const

Gets the surface's visibility.

Returns the visible state of the surface.

Returns
Current visibility.
int OpenXcom::Surface::getWidth ( ) const
inline

Returns the width of the surface.

Returns
Width in pixels.
int OpenXcom::Surface::getX ( ) const
inline

Returns the position of the surface in the X axis.

Returns
X position in pixels.
int OpenXcom::Surface::getY ( ) const
inline

Returns the position of the surface in the Y axis.

Returns
Y position in pixels.
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.

Parameters
midMiddle 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.

Parameters
filenameFilename of the BDY image.
See also
http://www.ufopaedia.org/index.php?title=Image_Formats#BDY
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.

Parameters
filenameFilename 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.

Parameters
filenameFilename of the SCR image.
See also
http://www.ufopaedia.org/index.php?title=Image_Formats#SCR_.26_DAT
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.

Parameters
filenameFilename of the SPK image.
See also
http://www.ufopaedia.org/index.php?title=Image_Formats#SPK
void OpenXcom::Surface::lock ( )

Locks the surface.

Locks the surface from outside access for pixel-level access.

Must be unlocked afterwards.

See also
unlock()
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.

Parameters
offAmount to shift.
minMinimum color to shift to.
maxMaximum color to shift to.
mulShift 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.

void OpenXcom::Surface::resize ( int  width,
int  height 
)
protected

Recreates the surface with a new size.

Old contents will not be altered, and may be cropped to fit the new size.

Parameters
widthWidth in pixels.
heightHeight in pixels.
void OpenXcom::Surface::setHeight ( int  height)
virtual

Sets the height of the surface.

Changes the height of the surface.

Warning
This is not a trivial setter! It will force the surface to be recreated for the new size.
Parameters
heightNew 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.

Note
Do not confuse with setVisible!
Parameters
hiddenShown or hidden.
void OpenXcom::Surface::setPalette ( SDL_Color *  colors,
int  firstcolor = 0,
int  ncolors = 256 
)
virtual

Sets the surface's palette.

Replaces a certain amount of colors in the surface's palette.

Parameters
colorsPointer to the set of colors.
firstcolorOffset of the first color to replace.
ncolorsAmount 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.

void OpenXcom::Surface::setPixel ( int  x,
int  y,
Uint8  pixel 
)
inline

Changes the color of a pixel in the surface, relative to the top-left corner of the surface.

Parameters
xX position of the pixel.
yY position of the pixel.
pixelNew color for the pixel.
void OpenXcom::Surface::setPixelIterative ( int *  x,
int *  y,
Uint8  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.

Parameters
xPointer to the X position of the pixel. Changed to the next X position in the sequence.
yPointer to the Y position of the pixel. Changed to the next Y position in the sequence.
pixelNew 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.

Parameters
tooltipString 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.

Parameters
visibleNew visibility.
void OpenXcom::Surface::setWidth ( int  width)
virtual

Sets the width of the surface.

Changes the width of the surface.

Warning
This is not a trivial setter! It will force the surface to be recreated for the new size.
Parameters
widthNew width in pixels.

Reimplemented in OpenXcom::Map.

void OpenXcom::Surface::setX ( int  x)
virtual

Sets the X position of the surface.

Changes the position of the surface in the X axis.

Parameters
xX position in pixels.

Reimplemented in OpenXcom::TextList, OpenXcom::ComboBox, OpenXcom::Slider, OpenXcom::ScrollBar, and OpenXcom::BattlescapeMessage.

void OpenXcom::Surface::setY ( int  y)
virtual

Sets the Y position of the surface.

Changes the position of the surface in the Y axis.

Parameters
yY position in pixels.

Reimplemented in OpenXcom::TextList, OpenXcom::ComboBox, OpenXcom::Slider, OpenXcom::ScrollBar, and OpenXcom::BattlescapeMessage.

void OpenXcom::Surface::think ( )
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.

See also
lock()

The documentation for this class was generated from the following files: