gcn::Graphics Class Reference

#include <graphics.hpp>

Inheritance diagram for gcn::Graphics:

gcn::AllegroGraphics gcn::HGEGraphics gcn::OpenGLGraphics gcn::OpenLayerGraphics gcn::SDLGraphics List of all members.

Detailed Description

Abstract class for providing drawing primitve functions.

It contains all vital functions for drawing.

Guichan contains implementations of Graphics for common libraries like the Allegro library, the HGE library, the OpenGL library, the OpenLayer library, and the SDL library. To make Guichan usable with other libraries, 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 top most 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, HGEGraphics, OpenLayerGraphics, OpenGLGraphics, SDLGraphics, Image
Since:
0.1.0

Definition at line 107 of file graphics.hpp.

Public Types

enum  Alignment { LEFT = 0, CENTER, RIGHT }
 Alignments for text drawing. More...

Public Member Functions

virtual void _beginDraw ()
 Initializes drawing.
virtual void _endDraw ()
 Deinitializes drawing.
virtual void drawImage (const Image *image, int dstX, int dstY)
 Draws an image.
virtual void drawImage (const Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height)=0
 Draws a part of an image.
virtual void drawLine (int x1, int y1, int x2, int y2)=0
 Ddraws a line.
virtual void drawPoint (int x, int y)=0
 Draws a single point/pixel.
virtual void drawRectangle (const Rectangle &rectangle)=0
 Draws a simple, non-filled, rectangle with a one pixel width.
virtual void drawText (const std::string &text, int x, int y, Alignment alignment=LEFT)
 Draws text.
virtual void fillRectangle (const Rectangle &rectangle)=0
 Draws a filled rectangle.
virtual const ColorgetColor () const=0
 Gets the color to use when drawing.
virtual const ClipRectanglegetCurrentClipArea ()
 Gets the current clip area.
 Graphics ()
 Constructor.
virtual void popClipArea ()
 Removes the top most clip area from the stack.
virtual bool pushClipArea (Rectangle area)
 Pushes a clip area onto the stack.
virtual void setColor (const Color &color)=0
 Sets the color to use when drawing.
virtual void setFont (Font *font)
 Sets the font to use when drawing text.
virtual ~Graphics ()
 Destructor.

Protected Attributes

std::stack< ClipRectanglemClipStack
 Holds the clip area stack.
FontmFont
 Holds the current font.


Member Enumeration Documentation

enum gcn::Graphics::Alignment

Alignments for text drawing.

Enumerator:
LEFT 
CENTER 
RIGHT 

Definition at line 113 of file graphics.hpp.


Member Function Documentation

virtual void gcn::Graphics::_beginDraw (  )  [inline, 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 is the OpenGLGraphics.

NOTE: You will never need to call this function yourself, unless you use a Graphics object outside of Guichan.

See also:
_endDraw, Gui::draw

Reimplemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Definition at line 141 of file graphics.hpp.

Referenced by gcn::Gui::draw().

virtual void gcn::Graphics::_endDraw (  )  [inline, 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, unless you use a Graphics object outside of Guichan.

See also:
_beginDraw, Gui::draw

Reimplemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Definition at line 152 of file graphics.hpp.

Referenced by gcn::Gui::draw().

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()); 

Reimplemented in gcn::HGEGraphics.

Definition at line 147 of file graphics.cpp.

References drawImage(), gcn::Image::getHeight(), and gcn::Image::getWidth().

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:
image The image to draw.
srcX The source image x coordinate.
srcY The source image y coordinate.
dstX The destination x coordinate.
dstY The destination y coordinate.
width The width of the piece.
height The height of the piece.

Implemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Referenced by gcn::ImageButton::draw(), gcn::Icon::draw(), gcn::ImageFont::drawGlyph(), and drawImage().

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

Ddraws a line.

Parameters:
x1 The first x coordinate.
y1 The first y coordinate.
x2 The second x coordinate.
y2 The second y coordinate.

Implemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Referenced by gcn::Window::draw(), gcn::TextField::draw(), gcn::TabbedArea::draw(), gcn::Tab::draw(), gcn::RadioButton::draw(), gcn::ImageButton::draw(), gcn::DropDown::draw(), gcn::Button::draw(), gcn::RadioButton::drawBox(), gcn::CheckBox::drawBox(), gcn::DropDown::drawButton(), gcn::TextField::drawCaret(), gcn::TextBox::drawCaret(), gcn::ScrollArea::drawDownButton(), gcn::Widget::drawFrame(), gcn::ScrollArea::drawHBar(), gcn::ScrollArea::drawHMarker(), gcn::ScrollArea::drawLeftButton(), gcn::Slider::drawMarker(), gcn::ScrollArea::drawRightButton(), gcn::ScrollArea::drawUpButton(), gcn::ScrollArea::drawVBar(), and gcn::ScrollArea::drawVMarker().

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

Draws a single point/pixel.

Parameters:
x The x coordinate.
y The y coordinate.

Implemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

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

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

Parameters:
rectangle The rectangle to draw.

Implemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Referenced by gcn::Tab::draw(), gcn::ImageButton::draw(), gcn::DropDown::draw(), gcn::Button::draw(), gcn::CheckBox::drawBox(), gcn::ImageFont::drawGlyph(), gcn::DefaultFont::drawGlyph(), and gcn::Slider::drawMarker().

void gcn::Graphics::drawText ( const std::string &  text,
int  x,
int  y,
Alignment  alignment = LEFT 
) [virtual]

Draws text.

Parameters:
text The text to draw.
x The x coordinate where to draw the text.
y The y coordinate where to draw the text.
alignment The alignemnt to use when drawing.
Exceptions:
Exception when no font has been set.

Definition at line 157 of file graphics.cpp.

References CENTER, gcn::Font::drawString(), gcn::Font::getWidth(), LEFT, mFont, and RIGHT.

Referenced by gcn::Window::draw(), gcn::TextField::draw(), gcn::TextBox::draw(), gcn::RadioButton::draw(), gcn::ListBox::draw(), gcn::Label::draw(), gcn::DropDown::draw(), gcn::CheckBox::draw(), and gcn::Button::draw().

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

Draws a filled rectangle.

Parameters:
rectangle The filled rectangle to draw.

Implemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Referenced by gcn::Window::draw(), gcn::TextField::draw(), gcn::TextBox::draw(), gcn::TabbedArea::draw(), gcn::Tab::draw(), gcn::Slider::draw(), gcn::ScrollArea::draw(), gcn::ListBox::draw(), gcn::ImageButton::draw(), gcn::DropDown::draw(), gcn::Container::draw(), gcn::Button::draw(), gcn::ScrollArea::drawBackground(), gcn::CheckBox::drawBox(), gcn::DropDown::drawButton(), gcn::ScrollArea::drawDownButton(), gcn::ScrollArea::drawHBar(), gcn::ScrollArea::drawHMarker(), gcn::ScrollArea::drawLeftButton(), gcn::Slider::drawMarker(), gcn::ScrollArea::drawRightButton(), gcn::ScrollArea::drawUpButton(), gcn::ScrollArea::drawVBar(), and gcn::ScrollArea::drawVMarker().

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

Gets the color to use when drawing.

Returns:
The color used when drawing.
See also:
setColor

Implemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Referenced by gcn::HGEImageFont::drawString().

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

Gets the current clip area.

Usefull if you want to do drawing bypassing Graphics.

Returns:
The current clip area.

Definition at line 137 of file graphics.cpp.

References mClipStack.

Referenced by gcn::Tab::draw(), gcn::ListBox::draw(), gcn::DropDown::draw(), gcn::DropDown::drawButton(), gcn::TextField::drawCaret(), gcn::OpenLayerTTFont::drawString(), and gcn::AllegroFont::drawString().

void gcn::Graphics::popClipArea (  )  [virtual]

Removes the top most clip area from the stack.

Exceptions:
Exception if the stack is empty.

Reimplemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Definition at line 126 of file graphics.cpp.

References mClipStack.

Referenced by gcn::Window::draw(), gcn::TextField::draw(), gcn::Tab::draw(), gcn::RadioButton::draw(), gcn::Gui::draw(), gcn::DropDown::draw(), gcn::BasicContainer::drawChildren(), gcn::ScrollArea::drawDownButton(), gcn::ScrollArea::drawHBar(), gcn::ScrollArea::drawHMarker(), gcn::ScrollArea::drawLeftButton(), gcn::ScrollArea::drawRightButton(), gcn::ScrollArea::drawUpButton(), gcn::ScrollArea::drawVBar(), gcn::ScrollArea::drawVMarker(), gcn::SDLGraphics::popClipArea(), gcn::OpenLayerGraphics::popClipArea(), gcn::OpenGLGraphics::popClipArea(), gcn::HGEGraphics::popClipArea(), and gcn::AllegroGraphics::popClipArea().

bool gcn::Graphics::pushClipArea ( Rectangle  area  )  [virtual]

Pushes a clip area onto the stack.

The x and y coordinates in the rectangle is relative to the last pushed clip area. If the new area falls outside the current clip area, it will be clipped as necessary.

If a clip area is outside of the top clip area a clip area with zero width and height will be pushed.

Parameters:
area The clip area to be pushed onto the stack.
Returns:
False if the the new area lays outside the current clip area.

Reimplemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Definition at line 75 of file graphics.cpp.

References gcn::Rectangle::height, gcn::Rectangle::isIntersecting(), mClipStack, gcn::Rectangle::width, gcn::Rectangle::x, gcn::ClipRectangle::xOffset, gcn::Rectangle::y, and gcn::ClipRectangle::yOffset.

Referenced by gcn::Window::draw(), gcn::TextField::draw(), gcn::Tab::draw(), gcn::RadioButton::draw(), gcn::Gui::draw(), gcn::DropDown::draw(), gcn::BasicContainer::drawChildren(), gcn::ScrollArea::drawDownButton(), gcn::ScrollArea::drawHBar(), gcn::ScrollArea::drawHMarker(), gcn::ScrollArea::drawLeftButton(), gcn::ScrollArea::drawRightButton(), gcn::ScrollArea::drawUpButton(), gcn::ScrollArea::drawVBar(), gcn::ScrollArea::drawVMarker(), gcn::SDLGraphics::pushClipArea(), gcn::OpenLayerGraphics::pushClipArea(), gcn::OpenGLGraphics::pushClipArea(), gcn::HGEGraphics::pushClipArea(), and gcn::AllegroGraphics::pushClipArea().

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

Sets the color to use when drawing.

Parameters:
color A color.
See also:
getColor

Implemented in gcn::AllegroGraphics, gcn::HGEGraphics, gcn::OpenGLGraphics, gcn::OpenLayerGraphics, and gcn::SDLGraphics.

Referenced by gcn::Window::draw(), gcn::TextField::draw(), gcn::TextBox::draw(), gcn::TabbedArea::draw(), gcn::Tab::draw(), gcn::Slider::draw(), gcn::ScrollArea::draw(), gcn::RadioButton::draw(), gcn::ListBox::draw(), gcn::Label::draw(), gcn::ImageButton::draw(), gcn::DropDown::draw(), gcn::Container::draw(), gcn::CheckBox::draw(), gcn::Button::draw(), gcn::ScrollArea::drawBackground(), gcn::RadioButton::drawBox(), gcn::CheckBox::drawBox(), gcn::DropDown::drawButton(), gcn::TextField::drawCaret(), gcn::TextBox::drawCaret(), gcn::ScrollArea::drawDownButton(), gcn::Widget::drawFrame(), gcn::ScrollArea::drawHBar(), gcn::ScrollArea::drawHMarker(), gcn::ScrollArea::drawLeftButton(), gcn::Slider::drawMarker(), gcn::ScrollArea::drawRightButton(), gcn::ScrollArea::drawUpButton(), gcn::ScrollArea::drawVBar(), and gcn::ScrollArea::drawVMarker().

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

Sets the font to use when drawing text.

Parameters:
font The font to use when drawing.

Definition at line 152 of file graphics.cpp.

References mFont.

Referenced by gcn::Window::draw(), gcn::TextField::draw(), gcn::TextBox::draw(), gcn::RadioButton::draw(), gcn::ListBox::draw(), gcn::Label::draw(), gcn::DropDown::draw(), gcn::CheckBox::draw(), and gcn::Button::draw().


The documentation for this class was generated from the following files:
Generated on Sun Jan 20 21:48:15 2008 for Guichan by  doxygen 1.5.2