opengl_gui_graphics.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <guichan/opengl.hpp>
00026 #include <guichan/font.hpp>
00027 #include <guichan/exception.hpp>
00028
00029
00030
00031
00032
00033 #include "video/image.h"
00034 #include "gui/base/gui_image.h"
00035 #include "util/structures/rect.h"
00036 #include "video/opengl/fife_opengl.h"
00037
00038 #include "opengl_gui_graphics.h"
00039
00040 namespace FIFE {
00041 OpenGLGuiGraphics::OpenGLGuiGraphics(ImagePool& pool): m_pool(pool) {
00042 mTarget = SDL_GetVideoSurface();
00043 assert(mTarget);
00044 setTargetPlane(mTarget->w, mTarget->h);
00045
00046 }
00047
00048 void OpenGLGuiGraphics::drawImage(const gcn::Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) {
00049 const GuiImage* g_img = dynamic_cast<const GuiImage*>(image);
00050 assert(g_img);
00051 Image& fifeimg = m_pool.getImage(g_img->getPoolId());
00052 const gcn::ClipRectangle& clip = getCurrentClipArea();
00053 Rect rect(dstX, dstY, width, height);
00054 rect.x += clip.xOffset;
00055 rect.y += clip.yOffset;
00056 GLEnable flag(GL_TEXTURE_2D);
00057 fifeimg.render(rect, mTarget);
00058 }
00059
00060 void OpenGLGuiGraphics::drawText(const std::string& text, int x, int y,
00061 unsigned int alignment) {
00062 if (mFont == NULL)
00063 {
00064 throw GCN_EXCEPTION("No font set.");
00065 }
00066
00067 GLEnable flag(GL_TEXTURE_2D);
00068 switch (alignment)
00069 {
00070 case LEFT:
00071 mFont->drawString(this, text, x, y);
00072 break;
00073 case CENTER:
00074 mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y);
00075 break;
00076 case RIGHT:
00077 mFont->drawString(this, text, x - mFont->getWidth(text), y);
00078 break;
00079 default:
00080 throw GCN_EXCEPTION("Unknown alignment.");
00081 }
00082 }
00083
00084 void OpenGLGuiGraphics::drawPoint(int x, int y) {
00085 GLDisable flag(GL_TEXTURE_2D);
00086 gcn::OpenGLGraphics::drawPoint(x, y);
00087 }
00088
00089 void OpenGLGuiGraphics::drawLine(int x1, int y1, int x2, int y2) {
00090 GLDisable flag(GL_TEXTURE_2D);
00091 gcn::OpenGLGraphics::drawLine(x1, y1, x2, y2);
00092 }
00093
00094 void OpenGLGuiGraphics::drawRectangle(const gcn::Rectangle& rectangle) {
00095 GLDisable flag(GL_TEXTURE_2D);
00096 gcn::OpenGLGraphics::drawRectangle(rectangle);
00097 }
00098 }