_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
gcn::SDLGraphics Class Reference

#include <sdlgraphics.h>

Inheritance diagram for gcn::SDLGraphics:
gcn::Graphics

Public Member Functions

 SDLGraphics ()
 
virtual void setTarget (SDL_Surface **surface)
 
virtual void drawSDLSurface (SDL_Surface *surface, SDL_Rect source, SDL_Rect destination)
 
virtual void _beginDraw ()
 
virtual void _endDraw ()
 
virtual bool pushClipArea (Rectangle area)
 
virtual void popClipArea ()
 
virtual void drawImage (const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height)
 
virtual void drawPoint (int x, int y)
 
virtual void drawLine (int x1, int y1, int x2, int y2)
 
virtual void drawRectangle (const Rectangle &rectangle)
 
virtual void fillRectangle (const Rectangle &rectangle)
 
virtual void setColor (const Color &color)
 
virtual const ColorgetColor ()
 
virtual void drawImage (const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height)=0
 
virtual void drawImage (const Image *image, int dstX, int dstY)
 
- Public Member Functions inherited from gcn::Graphics
 Graphics ()
 
virtual ~Graphics ()
 
virtual const ClipRectanglegetCurrentClipArea ()
 
virtual void drawImage (const Image *image, int dstX, int dstY)
 
virtual void setFont (Font *font)
 
virtual void drawText (const std::string &text, int x, int y, unsigned int alignment=LEFT, bool is_normal=true)
 

Protected Member Functions

virtual void drawHLine (int x1, int y, int x2)
 
virtual void drawVLine (int x, int y1, int y2)
 

Protected Attributes

SDL_Surface ** mTarget
 
Color mColor
 
bool mAlpha
 
- Protected Attributes inherited from gcn::Graphics
std::stack< ClipRectanglemClipStack
 
FontmFont
 

Additional Inherited Members

- Public Types inherited from gcn::Graphics
enum  { LEFT = 0, CENTER, RIGHT }
 

Detailed Description

SDL implementation of the Graphics.

Constructor & Destructor Documentation

◆ SDLGraphics()

gcn::SDLGraphics::SDLGraphics ( )

Constructor.

Member Function Documentation

◆ _beginDraw()

void gcn::SDLGraphics::_beginDraw ( )
virtual

Initializes drawing. Called by the Gui when Gui::draw() is called. It is needed by some implementations of Graphics to perform preparations before drawing. An example of such an implementation would be OpenGLGraphics.

NOTE: You will never need to call this function yourself. Gui will do it for you.

See also
_endDraw, Gui::draw

Reimplemented from gcn::Graphics.

◆ _endDraw()

void gcn::SDLGraphics::_endDraw ( )
virtual

Deinitializes drawing. Called by the Gui when a Gui::draw() is done. done. It should reset any state changes made by _beginDraw().

NOTE: You will never need to call this function yourself. Gui will do it for you.

See also
_beginDraw, Gui::draw

Reimplemented from gcn::Graphics.

◆ drawHLine()

void gcn::SDLGraphics::drawHLine ( int  x1,
int  y,
int  x2 
)
protectedvirtual

Draws a horizontal line.

Parameters
x1the start coordinate of the line.
ythe y coordinate of the line.
x2the end coordinate of the line.

◆ drawImage() [1/3]

void gcn::Graphics::drawImage

Draws an image. A simplified version of the other drawImage. It will draw a whole image at the coordinate you specify. It is equivalent to calling:

drawImage(myImage, 0, 0, dstX, dstY, image->getWidth(), image->getHeight());

◆ drawImage() [2/3]

void gcn::SDLGraphics::drawImage ( const Image image,
int  srcX,
int  srcY,
int  dstX,
int  dstY,
int  width,
int  height 
)
virtual

Draws a part of an Image.

NOTE: Width and height arguments will not scale the Image but specifies the size of the part to be drawn. If you want to draw the whole Image there is a simplified version of this function.

EXAMPLE:

drawImage(myImage, 10, 10, 20, 20, 40, 40);

Will draw a rectangular piece of myImage starting at coordinate (10, 10) in myImage, with width and height 40. The piece will be drawn with it's top left corner at coordinate (20, 20).

Parameters
imagethe Image to draw.
srcXsource Image x coordinate.
srcYsource Image y coordinate.
dstXdestination x coordinate.
dstYdestination y coordinate.
widththe width of the piece.
heightthe height of the piece.

Implements gcn::Graphics.

◆ drawImage() [3/3]

virtual void gcn::Graphics::drawImage

Draws a part of an Image.

NOTE: Width and height arguments will not scale the Image but specifies the size of the part to be drawn. If you want to draw the whole Image there is a simplified version of this function.

EXAMPLE:

drawImage(myImage, 10, 10, 20, 20, 40, 40);

Will draw a rectangular piece of myImage starting at coordinate (10, 10) in myImage, with width and height 40. The piece will be drawn with it's top left corner at coordinate (20, 20).

Parameters
imagethe Image to draw.
srcXsource Image x coordinate.
srcYsource Image y coordinate.
dstXdestination x coordinate.
dstYdestination y coordinate.
widththe width of the piece.
heightthe height of the piece.

◆ drawLine()

void gcn::SDLGraphics::drawLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
virtual

Ddraws a line.

Parameters
x1the first x coordinate.
y1the first y coordinate.
x2the second x coordinate.
y2the second y coordinate.

Implements gcn::Graphics.

◆ drawPoint()

void gcn::SDLGraphics::drawPoint ( int  x,
int  y 
)
virtual

Draws a single point/pixel.

Parameters
xthe x coordinate.
ythe y coordinate.

Implements gcn::Graphics.

◆ drawRectangle()

void gcn::SDLGraphics::drawRectangle ( const Rectangle rectangle)
virtual

Draws a simple, non-filled, Rectangle with one pixel width.

Parameters
rectanglethe Rectangle to draw.

Implements gcn::Graphics.

◆ drawSDLSurface()

void gcn::SDLGraphics::drawSDLSurface ( SDL_Surface *  surface,
SDL_Rect  source,
SDL_Rect  destination 
)
virtual

Draws an SDL_Surface on the target surface. Normaly you'll use drawImage, but if you want to write SDL specific code this function might come in handy.

NOTE: The clip areas will be taken into account.

◆ drawVLine()

void gcn::SDLGraphics::drawVLine ( int  x,
int  y1,
int  y2 
)
protectedvirtual

Draws a vertical line.

Parameters
xthe x coordinate of the line.
y1the start coordinate of the line.
y2the end coordinate of the line.

◆ fillRectangle()

void gcn::SDLGraphics::fillRectangle ( const Rectangle rectangle)
virtual

Draws a filled Rectangle.

Parameters
rectanglethe filled Rectangle to draw.

Implements gcn::Graphics.

◆ getColor()

const Color & gcn::SDLGraphics::getColor ( )
virtual

Gets the Color to use when drawing.

Returns
the Color used when drawing.

Implements gcn::Graphics.

◆ popClipArea()

void gcn::SDLGraphics::popClipArea ( )
virtual

Removes the topmost clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented from gcn::Graphics.

◆ pushClipArea()

bool gcn::SDLGraphics::pushClipArea ( Rectangle  area)
virtual

Pushes a clip area onto the stack. The x and y coordinates in the Rectangle will be relative to the last pushed clip area. If the new area falls outside the current clip area, it will be clipped as necessary.

Parameters
areathe clip area to be pushed onto the stack.
Returns
false if the the new area lays totally outside the current clip area. Note that an empty clip area will be pused in this case.

Reimplemented from gcn::Graphics.

◆ setColor()

void gcn::SDLGraphics::setColor ( const Color color)
virtual

Sets the Color to use when drawing.

Parameters
colora Color.

Implements gcn::Graphics.

◆ setTarget()

void gcn::SDLGraphics::setTarget ( SDL_Surface **  surface)
virtual

Pointer to the target surface to render into. The target can be any SDL_Surface. This funtion also pushes a clip areas corresponding to the dimension of the target.

Parameters
targetthe target to draw to.

Member Data Documentation

◆ mAlpha

bool gcn::SDLGraphics::mAlpha
protected

◆ mColor

Color gcn::SDLGraphics::mColor
protected

◆ mTarget

SDL_Surface** gcn::SDLGraphics::mTarget
protected

The documentation for this class was generated from the following files:
gcn::SDLGraphics::drawImage
virtual void drawImage(const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height)
Definition: sdlgraphics.cpp:137
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.