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 | Static Public Member Functions | Static Public Attributes | List of all members
OpenXcom::Palette Class Reference

Container for palettes (sets of 8bpp colors). More...

#include <Palette.h>

Public Member Functions

 Palette ()
 Creates a blank palette. More...
 
 ~Palette ()
 Cleans up the palette. More...
 
void loadDat (const std::string &filename, int ncolors, int offset=0)
 Loads the colors from an X-Com palette. More...
 
SDL_Color * getColors (int offset=0) const
 Provides access to colors contained in the palette. More...
 

Static Public Member Functions

static Uint32 getRGBA (SDL_Color *pal, Uint8 color)
 Converts a given color into a RGBA color value. More...
 
static int palOffset (int palette)
 Gets the position of a given palette. More...
 
static Uint8 blockOffset (Uint8 block)
 Gets the position of a certain color block in a palette. More...
 

Static Public Attributes

static const int backPos = 224
 Position of the background colors block in an X-Com palette (used for background images in screens).
 

Detailed Description

Container for palettes (sets of 8bpp colors).

Works as an encapsulation for SDL's SDL_Color struct and provides shortcuts for common tasks to make code more readable.

Constructor & Destructor Documentation

OpenXcom::Palette::Palette ( )

Creates a blank palette.

Initializes a brand new palette.

OpenXcom::Palette::~Palette ( )

Cleans up the palette.

Deletes any colors contained within.

Member Function Documentation

static Uint8 OpenXcom::Palette::blockOffset ( Uint8  block)
inlinestatic

Gets the position of a certain color block in a palette.

Returns the position of a certain color block in an X-Com palette (they're usually split in 16-color gradients). Makes setting element colors a lot easier than determining the exact color position.

Parameters
blockRequested block.
Returns
Color position.
SDL_Color * OpenXcom::Palette::getColors ( int  offset = 0) const

Provides access to colors contained in the palette.

Parameters
offsetOffset to a specific color.
Returns
Pointer to the requested SDL_Color.
Uint32 OpenXcom::Palette::getRGBA ( SDL_Color *  pal,
Uint8  color 
)
static

Converts a given color into a RGBA color value.

Converts an SDL_Color struct into an hexadecimal RGBA color value.

Mostly used for operations with SDL_gfx that require colors in this format.

Parameters
palRequested palette.
colorRequested color in the palette.
Returns
Hexadecimal RGBA value.
void OpenXcom::Palette::loadDat ( const std::string &  filename,
int  ncolors,
int  offset = 0 
)

Loads the colors from an X-Com palette.

Loads an X-Com palette from a file.

X-Com palettes are just a set of RGB colors in a row, on a 0-63 scale, which have to be adjusted for modern computers (0-255 scale).

Parameters
filenameFilename of the palette.
ncolorsNumber of colors in the palette.
offsetPosition of the palette in the file (in bytes).
See also
http://www.ufopaedia.org/index.php?title=PALETTES.DAT
static int OpenXcom::Palette::palOffset ( int  palette)
inlinestatic

Gets the position of a given palette.

Returns the position of a palette inside an X-Com palette file (each is a 768-byte chunks). Handy for loading the palettes from the game files.

Parameters
paletteRequested palette.
Returns
Palette position in bytes.

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