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

Public Types | Public Member Functions | Protected Attributes | List of all members
gcn::Graphics Class Referenceabstract

#include <graphics.h>

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

Public Types

enum  { LEFT = 0, CENTER, RIGHT }
 

Public Member Functions

 Graphics ()
 
virtual ~Graphics ()
 
virtual void _beginDraw ()
 
virtual void _endDraw ()
 
virtual bool pushClipArea (Rectangle area)
 
virtual void popClipArea ()
 
virtual const ClipRectanglegetCurrentClipArea ()
 
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)
 
virtual void drawPoint (int x, int y)=0
 
virtual void drawLine (int x1, int y1, int x2, int y2)=0
 
virtual void drawRectangle (const Rectangle &rectangle)=0
 
virtual void fillRectangle (const Rectangle &rectangle)=0
 
virtual void setColor (const Color &color)=0
 
virtual const ColorgetColor ()=0
 
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 Attributes

std::stack< ClipRectanglemClipStack
 
FontmFont
 

Detailed Description

Used for drawing graphics. It contains all vital functions for drawing. We include implemented Graphics classes for some common platforms like the Allegro library, the OpenGL library and the SDL library. To make Guichan usable under another platform, a Graphics class must be implemented.

In Graphics you can set clip areas to limit drawing to certain areas of the screen. Clip areas are put on a stack, which means that you can push smaller and smaller clip areas onto the stack. All coordinates will be relative to the topmost clip area. In most cases you won't have to worry about the clip areas, unless you want to implement some really complex widget. Pushing and poping of clip areas are handled automatically by container widgets when their child widgets are drawn.

IMPORTANT: Remember to pop each clip area that you pushed on the stack after you are done with it.

If you feel that Graphics is to restrictive for your needs, there is no one stopping you from using your own code for drawing in Widgets. You could for instance use pure SDL in the drawing of Widgets bypassing Graphics. This might however hurt portability of your application.

If you implement a Graphics class not present in Guichan we would be very happy to add it to Guichan.

See also
AllegroGraphics, OpenGLGraphics, SDLGraphics, Image

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Alignments for text drawing.

Enumerator
LEFT 
CENTER 
RIGHT 

Constructor & Destructor Documentation

◆ Graphics()

gcn::Graphics::Graphics ( )

◆ ~Graphics()

virtual gcn::Graphics::~Graphics ( )
inlinevirtual

Member Function Documentation

◆ _beginDraw()

virtual void gcn::Graphics::_beginDraw ( )
inlinevirtual

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 in gcn::SDLGraphics.

◆ _endDraw()

virtual void gcn::Graphics::_endDraw ( )
inlinevirtual

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 in gcn::SDLGraphics.

◆ drawImage() [1/2]

void gcn::Graphics::drawImage ( const Image image,
int  dstX,
int  dstY 
)
virtual

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/2]

virtual void gcn::Graphics::drawImage ( const Image image,
int  srcX,
int  srcY,
int  dstX,
int  dstY,
int  width,
int  height 
)
pure 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.

Implemented in gcn::SDLGraphics.

◆ drawLine()

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

Ddraws a line.

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

Implemented in gcn::SDLGraphics.

◆ drawPoint()

virtual void gcn::Graphics::drawPoint ( int  x,
int  y 
)
pure virtual

Draws a single point/pixel.

Parameters
xthe x coordinate.
ythe y coordinate.

Implemented in gcn::SDLGraphics.

◆ drawRectangle()

virtual void gcn::Graphics::drawRectangle ( const Rectangle rectangle)
pure virtual

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

Parameters
rectanglethe Rectangle to draw.

Implemented in gcn::SDLGraphics.

◆ drawText()

void gcn::Graphics::drawText ( const std::string &  text,
int  x,
int  y,
unsigned int  alignment = LEFT,
bool  is_normal = true 
)
virtual

Draws text.

Parameters
textthe text to draw.
xthe x coordinate where to draw the text.
ythe y coordinate where to draw the text.
alignmentGraphics::LEFT, Graphics::CENTER or Graphics::RIGHT.
Exceptions
Exceptionwhen no Font is set.

◆ fillRectangle()

virtual void gcn::Graphics::fillRectangle ( const Rectangle rectangle)
pure virtual

Draws a filled Rectangle.

Parameters
rectanglethe filled Rectangle to draw.

Implemented in gcn::SDLGraphics.

◆ getColor()

virtual const Color& gcn::Graphics::getColor ( )
pure virtual

Gets the Color to use when drawing.

Returns
the Color used when drawing.

Implemented in gcn::SDLGraphics.

◆ getCurrentClipArea()

const ClipRectangle & gcn::Graphics::getCurrentClipArea ( )
virtual

Gets the current ClipArea. Usefull if you want to do drawing bypassing Graphics.

Returns
the current ClipArea.

◆ popClipArea()

void gcn::Graphics::popClipArea ( )
virtual

Removes the topmost clip area from the stack.

Exceptions
Exceptionif the stack is empty.

Reimplemented in gcn::SDLGraphics.

◆ pushClipArea()

bool gcn::Graphics::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 in gcn::SDLGraphics.

◆ setColor()

virtual void gcn::Graphics::setColor ( const Color color)
pure virtual

Sets the Color to use when drawing.

Parameters
colora Color.

Implemented in gcn::SDLGraphics.

◆ setFont()

void gcn::Graphics::setFont ( Font font)
virtual

Sets the font to use when drawing text.

Parameters
fontthe Font to use when drawing.

Member Data Documentation

◆ mClipStack

std::stack<ClipRectangle> gcn::Graphics::mClipStack
protected

◆ mFont

Font* gcn::Graphics::mFont
protected

The documentation for this class was generated from the following files:
gcn::Graphics::drawImage
virtual void drawImage(const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height)=0
(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.