25 #include "video/opengl/fife_opengl.h"
28 #include <guichan/opengl.hpp>
29 #include <guichan/font.hpp>
35 #include "util/log/logger.h"
36 #include "util/base/exception.h"
37 #include "gui/guichan/base/gui_image.h"
38 #include "util/structures/rect.h"
39 #include "video/image.h"
40 #include "video/imagemanager.h"
41 #include "video/opengle/renderbackendopengle.h"
43 #include "opengle_gui_graphics.h"
46 static Logger _log(LM_GUI);
49 SDL_Surface* target = SDL_GetVideoSurface();
51 setTargetPlane(target->w, target->h);
52 mColor = gcn::Color(255, 255, 255, 255);
56 void OpenGLeGuiGraphics::drawImage(
const gcn::Image* image, int32_t srcX, int32_t srcY, int32_t dstX, int32_t dstY, int32_t width, int32_t height) {
57 const GuiImage* g_img =
dynamic_cast<const GuiImage*
>(image);
60 ImagePtr fifeimg = g_img->getFIFEImage();
61 const gcn::ClipRectangle& clip = mClipStack.top();
62 fifeimg->
render(
Rect(dstX + clip.xOffset, dstY + clip.yOffset,
66 void OpenGLeGuiGraphics::drawText(
const std::string& text, int32_t x, int32_t y,
70 throw GuiException(
"OpenGLGuiGraphics::drawText() - No font set!");
76 mFont->drawString(
this, text, x, y);
79 mFont->drawString(
this, text, x - mFont->getWidth(text) / 2, y);
82 mFont->drawString(
this, text, x - mFont->getWidth(text), y);
85 FL_WARN(_log, LMsg(
"OpenGLGuiGraphics::drawText() - ") <<
"Unknown alignment: " << alignment);
86 mFont->drawString(
this, text, x, y);
90 void OpenGLeGuiGraphics::drawPoint(int32_t x, int32_t y) {
91 const gcn::ClipRectangle& top = mClipStack.top();
92 m_renderbackend->
putPixel(x + top.xOffset, y + top.yOffset,
93 mColor.r, mColor.g, mColor.b, mColor.a);
96 void OpenGLeGuiGraphics::drawLine(int32_t x1, int32_t y1, int32_t x2, int32_t y2) {
97 const gcn::ClipRectangle& top = mClipStack.top();
103 Point pbegin(static_cast<int32_t>(ceil(x1 + 0.375f)), static_cast<int32_t>(ceil(y1 + 0.375f)));
104 Point pend(static_cast<int32_t>(ceil(x2 + 0.625f)), static_cast<int32_t>(ceil(y2 + 0.625f)));
106 m_renderbackend->
drawLine(pbegin, pend,
107 mColor.r, mColor.g, mColor.b, mColor.a);
108 m_renderbackend->
putPixel(pbegin.x, pbegin.y,
109 mColor.r, mColor.g, mColor.b, mColor.a);
110 m_renderbackend->
putPixel(pend.x, pend.y,
111 mColor.r, mColor.g, mColor.b, mColor.a);
114 void OpenGLeGuiGraphics::drawRectangle(
const gcn::Rectangle& rectangle) {
115 const gcn::ClipRectangle& top = mClipStack.top();
117 Point(rectangle.x + top.xOffset, rectangle.y + top.yOffset),
118 rectangle.width, rectangle.height,
119 mColor.r, mColor.g, mColor.b, mColor.a);
122 void OpenGLeGuiGraphics::fillRectangle(
const gcn::Rectangle& rectangle) {
123 const gcn::ClipRectangle& top = mClipStack.top();
125 Point(rectangle.x + top.xOffset, rectangle.y + top.yOffset),
126 rectangle.width, rectangle.height,
127 mColor.r, mColor.g, mColor.b, mColor.a);
130 void OpenGLeGuiGraphics::_beginDraw() {
131 gcn::Rectangle area(0, 0, mWidth, mHeight);
132 gcn::Graphics::pushClipArea(area);
133 m_renderbackend->
pushClipArea(Rect(0, 0, mWidth, mHeight),
false);
136 void OpenGLeGuiGraphics::_endDraw() {
140 gcn::Graphics::popClipArea();
144 bool OpenGLeGuiGraphics::pushClipArea(gcn::Rectangle area) {
147 gcn::Graphics::pushClipArea(area);
152 const gcn::ClipRectangle& top = mClipStack.top();
155 Rect(top.x, top.y, top.width, top.height),
false);
160 void OpenGLeGuiGraphics::popClipArea() {
163 gcn::Graphics::popClipArea();
167 void OpenGLeGuiGraphics::setColor(
const gcn::Color& color) {