Mercurial > fife-parpg
comparison engine/core/gui/base/opengl/opengl_gui_graphics.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 | |
24 // 3rd party library includes | |
25 #include <guichan/opengl.hpp> | |
26 #include <guichan/font.hpp> | |
27 #include <guichan/exception.hpp> | |
28 | |
29 | |
30 // FIFE includes | |
31 // These includes are split up in two parts, separated by one empty line | |
32 // First block: files included from the FIFE root src dir | |
33 #include "video/image.h" | |
34 #include "gui/base/gui_image.h" | |
35 #include "util/structures/rect.h" | |
36 | |
37 #include "opengl_gui_graphics.h" | |
38 | |
39 namespace FIFE { | |
40 struct GLEnable { | |
41 GLenum m_flag; | |
42 GLboolean m_oldval; | |
43 GLEnable(GLenum flag) : m_flag(flag) { | |
44 glGetBooleanv(flag, &m_oldval); | |
45 if (!m_oldval) { | |
46 glEnable(flag); | |
47 } | |
48 } | |
49 ~GLEnable() { | |
50 if (!m_oldval) { | |
51 glDisable(m_flag); | |
52 } | |
53 } | |
54 }; | |
55 | |
56 struct GLDisable { | |
57 GLenum m_flag; | |
58 GLboolean m_oldval; | |
59 GLDisable(GLenum flag) : m_flag(flag) { | |
60 glGetBooleanv(flag, &m_oldval); | |
61 if (m_oldval) { | |
62 glDisable(flag); | |
63 } | |
64 } | |
65 ~GLDisable() { | |
66 if (m_oldval) { | |
67 glEnable(m_flag); | |
68 } | |
69 } | |
70 }; | |
71 | |
72 OpenGLGuiGraphics::OpenGLGuiGraphics(ImagePool& pool): m_pool(pool) { | |
73 mTarget = SDL_GetVideoSurface(); | |
74 assert(mTarget); | |
75 setTargetPlane(mTarget->w, mTarget->h); | |
76 | |
77 } | |
78 | |
79 void OpenGLGuiGraphics::drawImage(const gcn::Image* image, int srcX, int srcY, int dstX, int dstY, int width, int height) { | |
80 const GuiImage* g_img = dynamic_cast<const GuiImage*>(image); | |
81 assert(g_img); | |
82 Image& fifeimg = m_pool.getImage(g_img->getPoolId()); | |
83 const gcn::ClipRectangle& clip = getCurrentClipArea(); | |
84 Rect rect(dstX, dstY, width, height); | |
85 rect.x += clip.xOffset; | |
86 rect.y += clip.yOffset; | |
87 GLEnable flag(GL_TEXTURE_2D); | |
88 fifeimg.render(rect, mTarget); | |
89 } | |
90 | |
91 void OpenGLGuiGraphics::drawText(const std::string& text, int x, int y, | |
92 unsigned int alignment) { | |
93 if (mFont == NULL) | |
94 { | |
95 throw GCN_EXCEPTION("No font set."); | |
96 } | |
97 | |
98 GLEnable flag(GL_TEXTURE_2D); | |
99 switch (alignment) | |
100 { | |
101 case LEFT: | |
102 mFont->drawString(this, text, x, y); | |
103 break; | |
104 case CENTER: | |
105 mFont->drawString(this, text, x - mFont->getWidth(text) / 2, y); | |
106 break; | |
107 case RIGHT: | |
108 mFont->drawString(this, text, x - mFont->getWidth(text), y); | |
109 break; | |
110 default: | |
111 throw GCN_EXCEPTION("Unknown alignment."); | |
112 } | |
113 } | |
114 | |
115 void OpenGLGuiGraphics::drawPoint(int x, int y) { | |
116 GLDisable flag(GL_TEXTURE_2D); | |
117 gcn::OpenGLGraphics::drawPoint(x, y); | |
118 } | |
119 | |
120 void OpenGLGuiGraphics::drawLine(int x1, int y1, int x2, int y2) { | |
121 GLDisable flag(GL_TEXTURE_2D); | |
122 gcn::OpenGLGraphics::drawLine(x1, y1, x2, y2); | |
123 } | |
124 | |
125 void OpenGLGuiGraphics::drawRectangle(const gcn::Rectangle& rectangle) { | |
126 GLDisable flag(GL_TEXTURE_2D); | |
127 gcn::OpenGLGraphics::drawRectangle(rectangle); | |
128 } | |
129 } |