#include <graphics.hpp>
Inheritance diagram for gcn::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.
Definition at line 97 of file graphics.hpp.
Public Types | |
enum | { LEFT = 0, CENTER, RIGHT } |
Alignments for text drawing. | |
Public Member Functions | |
virtual void | _beginDraw () |
Initializes drawing. | |
virtual void | _endDraw () |
Deinitializes drawing. | |
virtual bool | pushClipArea (Rectangle area) |
Pushes a clip area onto the stack. | |
virtual void | popClipArea () |
Removes the topmost clip area from the stack. | |
virtual const ClipRectangle & | getCurrentClipArea () |
Gets the current ClipArea. | |
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 | drawImage (const Image *image, int dstX, int dstY) |
Draws an image. | |
virtual void | drawPoint (int x, int y)=0 |
Draws a single point/pixel. | |
virtual void | drawLine (int x1, int y1, int x2, int y2)=0 |
Ddraws a line. | |
virtual void | drawRectangle (const Rectangle &rectangle)=0 |
Draws a simple, non-filled, Rectangle with one pixel width. | |
virtual void | fillRectangle (const Rectangle &rectangle)=0 |
Draws a filled Rectangle. | |
virtual void | setColor (const Color &color)=0 |
Sets the Color to use when drawing. | |
virtual const Color & | getColor ()=0 |
Gets the Color to use when drawing. | |
virtual void | setFont (Font *font) |
Sets the font to use when drawing text. | |
virtual void | drawText (const std::string &text, int x, int y, unsigned int alignment=LEFT) |
Draws text. | |
Protected Attributes | |
std::stack< ClipRectangle > | mClipStack |
Font * | mFont |
|
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.
Reimplemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. Definition at line 115 of file graphics.hpp. Referenced by gcn::Gui::draw(). |
|
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.
Reimplemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. Definition at line 126 of file graphics.hpp. Referenced by gcn::Gui::draw(). |
|
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()); Definition at line 120 of file graphics.cpp. References 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);
Implemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. Referenced by drawImage(). |
|
Ddraws a line.
Implemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. |
|
Draws a single point/pixel.
Implemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. |
|
Draws a simple, non-filled, Rectangle with one pixel width.
Implemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. |
|
Draws text.
Definition at line 130 of file graphics.cpp. References gcn::Font::drawString(), and gcn::Font::getWidth(). |
|
Draws a filled Rectangle.
Implemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. |
|
Gets the Color to use when drawing.
Implemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. |
|
Gets the current ClipArea. Usefull if you want to do drawing bypassing Graphics.
Definition at line 110 of file graphics.cpp. |
|
Removes the topmost clip area from the stack.
Reimplemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. Definition at line 99 of file graphics.cpp. Referenced by gcn::Gui::draw(). |
|
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.
Reimplemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. Definition at line 71 of file graphics.cpp. References gcn::Rectangle::height, gcn::Rectangle::intersect(), gcn::Rectangle::width, gcn::Rectangle::x, gcn::ClipRectangle::xOffset, gcn::Rectangle::y, and gcn::ClipRectangle::yOffset. Referenced by gcn::Gui::draw(). |
|
Sets the Color to use when drawing.
Implemented in gcn::AllegroGraphics, gcn::OpenGLGraphics, and gcn::SDLGraphics. |
|
Sets the font to use when drawing text.
Definition at line 125 of file graphics.cpp. |