____ _ __
/ __ )____ _____ | | / /___ ___________
/ __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
/ /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
/_____/\____/____/ |__/|__/\__,_/_/ /____/
A futuristic real-time strategy game.
This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project.
Distributed under the "GNU General Public License"#include <graphics.h>

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 ClipRectangle & | getCurrentClipArea () |
| 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 Color & | getColor ()=0 |
| virtual void | setFont (Font *font) |
| virtual void | drawText (const std::string &text, int x, int y, unsigned int alignment=LEFT) |
Protected Attributes | |
| std::stack< ClipRectangle > | mClipStack |
| Font * | mFont |
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.h.
| anonymous enum |
Alignments for text drawing.
Definition at line 255 of file graphics.h.
| gcn::Graphics::Graphics | ( | ) |
| virtual gcn::Graphics::~Graphics | ( | ) | [inline, virtual] |
Definition at line 102 of file graphics.h.
| 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 would be OpenGLGraphics.
NOTE: You will never need to call this function yourself. Gui will do it for you.
Reimplemented in gcn::SDLGraphics, and MyOpenGLGraphics.
Definition at line 115 of file graphics.h.
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. Gui will do it for you.
Reimplemented in gcn::SDLGraphics, and MyOpenGLGraphics.
Definition at line 126 of file graphics.h.
Referenced by gcn::Gui::draw().
| 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.
| area | the clip area to be pushed onto the stack. |
Reimplemented in gcn::SDLGraphics.
Definition at line 71 of file graphics.cpp.
References gcn::Rectangle::height, gcn::Rectangle::intersect(), mClipStack, gcn::Rectangle::width, gcn::Rectangle::x, gcn::ClipRectangle::xOffset, gcn::Rectangle::y, and gcn::ClipRectangle::yOffset.
Referenced by MyOpenGLGraphics::_beginDraw(), gcn::ScrollArea::draw(), gcn::Gui::draw(), gcn::DropDown::draw(), gcn::Container::drawChildren(), gcn::Window::drawContent(), gcn::ScrollArea::drawDownButton(), gcn::ScrollArea::drawHBar(), gcn::ScrollArea::drawHMarker(), gcn::ScrollArea::drawLeftButton(), gcn::ScrollArea::drawRightButton(), gcn::ScrollArea::drawUpButton(), gcn::ScrollArea::drawVBar(), gcn::ScrollArea::drawVMarker(), and gcn::SDLGraphics::pushClipArea().
| void gcn::Graphics::popClipArea | ( | ) | [virtual] |
Removes the topmost clip area from the stack.
| Exception | if the stack is empty. |
Reimplemented in gcn::SDLGraphics.
Definition at line 99 of file graphics.cpp.
References GCN_EXCEPTION, and mClipStack.
Referenced by MyOpenGLGraphics::_endDraw(), gcn::ScrollArea::draw(), gcn::Gui::draw(), gcn::DropDown::draw(), gcn::Container::drawChildren(), gcn::Window::drawContent(), gcn::ScrollArea::drawDownButton(), gcn::ScrollArea::drawHBar(), gcn::ScrollArea::drawHMarker(), gcn::ScrollArea::drawLeftButton(), gcn::ScrollArea::drawRightButton(), gcn::ScrollArea::drawUpButton(), gcn::ScrollArea::drawVBar(), gcn::ScrollArea::drawVMarker(), and gcn::SDLGraphics::popClipArea().
| const ClipRectangle & gcn::Graphics::getCurrentClipArea | ( | ) | [virtual] |
Gets the current ClipArea. Usefull if you want to do drawing bypassing Graphics.
Definition at line 110 of file graphics.cpp.
References GCN_EXCEPTION, and mClipStack.
Referenced by MyOpenGLGraphics::drawImage(), and CFont::drawString().
| 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);
| image | the Image to draw. | |
| srcX | source Image x coordinate. | |
| srcY | source Image y coordinate. | |
| dstX | destination x coordinate. | |
| dstY | destination y coordinate. | |
| width | the width of the piece. | |
| height | the height of the piece. |
Implemented in gcn::SDLGraphics, and MyOpenGLGraphics.
Referenced by ImageSlider::draw(), ImageButton::draw(), gcn::Icon::draw(), ImageCheckBox::drawBox(), ImageRadioButton::drawBox(), gcn::ImageFont::drawGlyph(), drawImage(), and ImageSlider::drawMarker().
| 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());
Definition at line 120 of file graphics.cpp.
References drawImage(), gcn::Image::getHeight(), and gcn::Image::getWidth().
| virtual void gcn::Graphics::drawPoint | ( | int | x, | |
| int | y | |||
| ) | [pure virtual] |
Draws a single point/pixel.
| x | the x coordinate. | |
| y | the y coordinate. |
Implemented in gcn::SDLGraphics, and MyOpenGLGraphics.
| virtual void gcn::Graphics::drawLine | ( | int | x1, | |
| int | y1, | |||
| int | x2, | |||
| int | y2 | |||
| ) | [pure virtual] |
Ddraws a line.
| x1 | the first x coordinate. | |
| y1 | the first y coordinate. | |
| x2 | the second x coordinate. | |
| y2 | the second y coordinate. |
Implemented in gcn::SDLGraphics, and MyOpenGLGraphics.
Referenced by gcn::Window::draw(), gcn::DropDown::draw(), gcn::Button::draw(), gcn::Window::drawBorder(), MultiLineLabel::drawBorder(), gcn::TextField::drawBorder(), gcn::TextBox::drawBorder(), gcn::Slider::drawBorder(), gcn::ScrollArea::drawBorder(), gcn::RadioButton::drawBorder(), gcn::ListBox::drawBorder(), gcn::Label::drawBorder(), gcn::Icon::drawBorder(), gcn::DropDown::drawBorder(), gcn::Container::drawBorder(), gcn::CheckBox::drawBorder(), gcn::Button::drawBorder(), gcn::RadioButton::drawBox(), gcn::CheckBox::drawBox(), gcn::DropDown::drawButton(), gcn::TextField::drawCaret(), gcn::TextBox::drawCaret(), 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 void gcn::Graphics::drawRectangle | ( | const Rectangle & | rectangle | ) | [pure virtual] |
Draws a simple, non-filled, Rectangle with one pixel width.
| rectangle | the Rectangle to draw. |
Implemented in gcn::SDLGraphics, and MyOpenGLGraphics.
Referenced by StatBoxWidget::draw(), ImageCheckBox::draw(), ImageRadioButton::draw(), ImageButton::draw(), gcn::RadioButton::draw(), gcn::ListBox::draw(), gcn::DropDown::draw(), gcn::CheckBox::draw(), gcn::Button::draw(), gcn::ImageFont::drawGlyph(), gcn::DefaultFont::drawGlyph(), and gcn::Slider::drawMarker().
| virtual void gcn::Graphics::fillRectangle | ( | const Rectangle & | rectangle | ) | [pure virtual] |
Draws a filled Rectangle.
| rectangle | the filled Rectangle to draw. |
Implemented in gcn::SDLGraphics, and MyOpenGLGraphics.
Referenced by gcn::Window::draw(), StatBoxWidget::draw(), gcn::TextField::draw(), gcn::TextBox::draw(), gcn::Slider::draw(), gcn::ScrollArea::draw(), gcn::ListBox::draw(), gcn::DropDown::draw(), gcn::Container::draw(), gcn::Button::draw(), 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 void gcn::Graphics::setColor | ( | const Color & | color | ) | [pure virtual] |
Sets the Color to use when drawing.
| color | a Color. |
Implemented in gcn::SDLGraphics, and MyOpenGLGraphics.
Referenced by gcn::Window::draw(), StatBoxWidget::draw(), MultiLineLabel::draw(), ImageCheckBox::draw(), ImageRadioButton::draw(), ImageButton::draw(), gcn::TextField::draw(), gcn::TextBox::draw(), gcn::Slider::draw(), gcn::ScrollArea::draw(), gcn::RadioButton::draw(), gcn::ListBox::draw(), gcn::Label::draw(), gcn::DropDown::draw(), gcn::Container::draw(), gcn::CheckBox::draw(), gcn::Button::draw(), gcn::Window::drawBorder(), MultiLineLabel::drawBorder(), gcn::TextField::drawBorder(), gcn::TextBox::drawBorder(), gcn::Slider::drawBorder(), gcn::ScrollArea::drawBorder(), gcn::RadioButton::drawBorder(), gcn::ListBox::drawBorder(), gcn::Label::drawBorder(), gcn::Icon::drawBorder(), gcn::DropDown::drawBorder(), gcn::Container::drawBorder(), gcn::CheckBox::drawBorder(), gcn::Button::drawBorder(), gcn::RadioButton::drawBox(), gcn::CheckBox::drawBox(), gcn::DropDown::drawButton(), gcn::TextField::drawCaret(), gcn::TextBox::drawCaret(), 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 | ( | ) | [pure virtual] |
Gets the Color to use when drawing.
Implemented in gcn::SDLGraphics, and MyOpenGLGraphics.
| void gcn::Graphics::setFont | ( | Font * | font | ) | [virtual] |
Sets the font to use when drawing text.
| font | the Font to use when drawing. |
Definition at line 125 of file graphics.cpp.
References mFont.
Referenced by gcn::Window::draw(), StatBoxWidget::draw(), MultiLineLabel::draw(), ImageCheckBox::draw(), ImageRadioButton::draw(), ImageButton::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().
| void gcn::Graphics::drawText | ( | const std::string & | text, | |
| int | x, | |||
| int | y, | |||
| unsigned int | alignment = LEFT | |||
| ) | [virtual] |
Draws text.
| text | the text to draw. | |
| x | the x coordinate where to draw the text. | |
| y | the y coordinate where to draw the text. | |
| alignment | Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT. |
Definition at line 130 of file graphics.cpp.
References CENTER, gcn::Font::drawString(), GCN_EXCEPTION, gcn::Font::getWidth(), LEFT, mFont, and RIGHT.
Referenced by gcn::Window::draw(), StatBoxWidget::draw(), MultiLineLabel::draw(), ImageCheckBox::draw(), ImageRadioButton::draw(), ImageButton::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().
std::stack<ClipRectangle> gcn::Graphics::mClipStack [protected] |
Definition at line 263 of file graphics.h.
Referenced by gcn::SDLGraphics::drawHLine(), MyOpenGLGraphics::drawImage(), gcn::SDLGraphics::drawImage(), MyOpenGLGraphics::drawLine(), gcn::SDLGraphics::drawLine(), MyOpenGLGraphics::drawPoint(), gcn::SDLGraphics::drawPoint(), MyOpenGLGraphics::drawRectangle(), gcn::SDLGraphics::drawSDLSurface(), gcn::SDLGraphics::drawVLine(), MyOpenGLGraphics::fillRectangle(), gcn::SDLGraphics::fillRectangle(), getCurrentClipArea(), gcn::SDLGraphics::popClipArea(), popClipArea(), gcn::SDLGraphics::pushClipArea(), and pushClipArea().
Font* gcn::Graphics::mFont [protected] |
1.5.6