+void
+Renderer::draw_surface(const DrawingRequest& request)
+{
+ const Surface* surface = (const Surface*) request.request_data;
+ GL::Texture *gltexture = dynamic_cast<GL::Texture *>(surface->get_texture());
+ GL::SurfaceData *surface_data = reinterpret_cast<GL::SurfaceData *>(surface->get_surface_data());
+
+ glBindTexture(GL_TEXTURE_2D, gltexture->get_handle());
+ intern_draw(request.pos.x, request.pos.y,
+ request.pos.x + surface->get_width(),
+ request.pos.y + surface->get_height(),
+ surface_data->get_uv_left(),
+ surface_data->get_uv_top(),
+ surface_data->get_uv_right(),
+ surface_data->get_uv_bottom(),
+ request.angle,
+ request.alpha,
+ request.color,
+ request.blend,
+ request.drawing_effect);
+}
+
+void
+Renderer::draw_surface_part(const DrawingRequest& request)
+{
+ const SurfacePartRequest* surfacepartrequest
+ = (SurfacePartRequest*) request.request_data;
+ const Surface *surface = surfacepartrequest->surface;
+ GL::Texture *gltexture = dynamic_cast<GL::Texture *>(surface->get_texture());
+ GL::SurfaceData *surface_data = reinterpret_cast<GL::SurfaceData *>(surface->get_surface_data());
+
+ float uv_width = surface_data->get_uv_right() - surface_data->get_uv_left();
+ float uv_height = surface_data->get_uv_bottom() - surface_data->get_uv_top();
+
+ float uv_left = surface_data->get_uv_left() + (uv_width * surfacepartrequest->source.x) / surface->get_width();
+ float uv_top = surface_data->get_uv_top() + (uv_height * surfacepartrequest->source.y) / surface->get_height();
+ float uv_right = surface_data->get_uv_left() + (uv_width * (surfacepartrequest->source.x + surfacepartrequest->size.x)) / surface->get_width();
+ float uv_bottom = surface_data->get_uv_top() + (uv_height * (surfacepartrequest->source.y + surfacepartrequest->size.y)) / surface->get_height();
+
+ glBindTexture(GL_TEXTURE_2D, gltexture->get_handle());
+ intern_draw(request.pos.x, request.pos.y,
+ request.pos.x + surfacepartrequest->size.x,
+ request.pos.y + surfacepartrequest->size.y,
+ uv_left,
+ uv_top,
+ uv_right,
+ uv_bottom,
+ 0.0,
+ request.alpha,
+ request.color,
+ Blend(),
+ request.drawing_effect);
+}
+
+void
+Renderer::draw_gradient(const DrawingRequest& request)
+{
+ const GradientRequest* gradientrequest
+ = (GradientRequest*) request.request_data;
+ const Color& top = gradientrequest->top;
+ const Color& bottom = gradientrequest->bottom;
+
+ glDisable(GL_TEXTURE_2D);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+
+ float vertices[] = {
+ 0, 0,
+ SCREEN_WIDTH, 0,
+ SCREEN_WIDTH, SCREEN_HEIGHT,
+ 0, SCREEN_HEIGHT
+ };
+ glVertexPointer(2, GL_FLOAT, 0, vertices);
+
+ float colors[] = {
+ top.red, top.green, top.blue, top.alpha,
+ top.red, top.green, top.blue, top.alpha,
+ bottom.red, bottom.green, bottom.blue, bottom.alpha,
+ bottom.red, bottom.green, bottom.blue, bottom.alpha,
+ };
+ glColorPointer(4, GL_FLOAT, 0, colors);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ glDisableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1, 1, 1, 1);
+}
+
+void
+Renderer::draw_filled_rect(const DrawingRequest& request)
+{
+ const FillRectRequest* fillrectrequest
+ = (FillRectRequest*) request.request_data;
+
+ glDisable(GL_TEXTURE_2D);
+ glColor4f(fillrectrequest->color.red, fillrectrequest->color.green,
+ fillrectrequest->color.blue, fillrectrequest->color.alpha);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ if (fillrectrequest->radius != 0.0f)
+ {
+ // draw round rect
+ // Keep radius in the limits, so that we get a circle instead of
+ // just graphic junk
+ float radius = std::min(fillrectrequest->radius,
+ std::min(fillrectrequest->size.x/2,
+ fillrectrequest->size.y/2));
+
+ // inner rectangle
+ Rect irect(request.pos.x + radius,
+ request.pos.y + radius,
+ request.pos.x + fillrectrequest->size.x - radius,
+ request.pos.y + fillrectrequest->size.y - radius);
+
+
+ int n = 8;
+ int p = 0;
+ float vertices[(n+1) * 4 * 2];
+
+ for(int i = 0; i <= n; ++i)
+ {
+ float x = sinf(i * (M_PI/2) / n) * radius;
+ float y = cosf(i * (M_PI/2) / n) * radius;
+
+ vertices[p++] = irect.get_left() - x;
+ vertices[p++] = irect.get_top() - y;
+
+ vertices[p++] = irect.get_right() + x;
+ vertices[p++] = irect.get_top() - y;
+ }
+
+ for(int i = 0; i <= n; ++i)
+ {
+ float x = cosf(i * (M_PI/2) / n) * radius;
+ float y = sinf(i * (M_PI/2) / n) * radius;
+
+ vertices[p++] = irect.get_left() - x;
+ vertices[p++] = irect.get_bottom() + y;
+
+ vertices[p++] = irect.get_right() + x;
+ vertices[p++] = irect.get_bottom() + y;
+ }
+
+ glVertexPointer(2, GL_FLOAT, 0, vertices);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, sizeof(vertices)/sizeof(float)/2);
+ }
+ else
+ {
+ float x = request.pos.x;
+ float y = request.pos.y;
+ float w = fillrectrequest->size.x;
+ float h = fillrectrequest->size.y;
+
+ float vertices[] = {
+ x, y,
+ x+w, y,
+ x+w, y+h,
+ x, y+h
+ };
+ glVertexPointer(2, GL_FLOAT, 0, vertices);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+ }
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1, 1, 1, 1);
+}