X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fvideo%2Fdrawing_context.cpp;h=d5a5be12b0baba7c22138d7af190fbd31364986a;hb=ff08b8e1983016221967a024dab76799a3d75059;hp=0a6485068831774d4787851f10eab1ca16f71c67;hpb=e7a12ed844f040d270e50ce25f74de5f017c1157;p=supertux.git diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 0a6485068..d5a5be12b 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // Copyright (C) 2006 Matthias Braun // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,31 +12,23 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include +// along with this program. If not, see . -#include #include -#include -#include -#include -#include -#include -#include - -#include "drawing_context.hpp" -#include "drawing_request.hpp" -#include "video_systems.hpp" -#include "renderer.hpp" -#include "lightmap.hpp" -#include "surface.hpp" -#include "main.hpp" -#include "gameconfig.hpp" -#include "texture.hpp" -#include "texture_manager.hpp" -#include "obstack/obstackpp.hpp" -#define LIGHTMAP_DIV 5 +#include + +#include "video/drawing_context.hpp" + +#include "supertux/gameconfig.hpp" +#include "supertux/globals.hpp" +#include "util/obstackpp.hpp" +#include "video/drawing_request.hpp" +#include "video/lightmap.hpp" +#include "video/renderer.hpp" +#include "video/surface.hpp" +#include "video/texture.hpp" +#include "video/texture_manager.hpp" +#include "video/video_systems.hpp" static inline int next_po2(int val) { @@ -50,7 +40,20 @@ static inline int next_po2(int val) } DrawingContext::DrawingContext() : - renderer(0), lightmap(0), ambient_color(1.0f, 1.0f, 1.0f, 1.0f), target(NORMAL), screenshot_requested(false) + renderer(0), + lightmap(0), + transformstack(), + transform(), + blend_stack(), + blend_mode(), + drawing_requests(), + lightmap_requests(), + requests(), + ambient_color(1.0f, 1.0f, 1.0f, 1.0f), + target(NORMAL), + target_stack(), + obst(), + screenshot_requested(false) { requests = &drawing_requests; obstack_init(&obst); @@ -88,8 +91,8 @@ DrawingContext::draw_surface(const Surface* surface, const Vector& position, request->pos = transform.apply(position); if(request->pos.x >= SCREEN_WIDTH || request->pos.y >= SCREEN_HEIGHT - || request->pos.x + surface->get_width() < 0 - || request->pos.y + surface->get_height() < 0) + || request->pos.x + surface->get_width() < 0 + || request->pos.y + surface->get_height() < 0) return; request->layer = layer; @@ -106,14 +109,14 @@ DrawingContext::draw_surface(const Surface* surface, const Vector& position, void DrawingContext::draw_surface(const Surface* surface, const Vector& position, - int layer) + int layer) { draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer); } void DrawingContext::draw_surface_part(const Surface* surface, const Vector& source, - const Vector& size, const Vector& dest, int layer) + const Vector& size, const Vector& dest, int layer) { assert(surface != 0); @@ -153,7 +156,7 @@ DrawingContext::draw_surface_part(const Surface* surface, const Vector& source, void DrawingContext::draw_text(const Font* font, const std::string& text, - const Vector& position, FontAlignment alignment, int layer) + const Vector& position, FontAlignment alignment, int layer, Color color) { DrawingRequest* request = new(obst) DrawingRequest(); @@ -163,6 +166,7 @@ DrawingContext::draw_text(const Font* font, const std::string& text, request->layer = layer; request->drawing_effect = transform.drawing_effect; request->alpha = transform.alpha; + request->color = color; TextRequest* textrequest = new(obst) TextRequest(); textrequest->font = font; @@ -175,10 +179,10 @@ DrawingContext::draw_text(const Font* font, const std::string& text, void DrawingContext::draw_center_text(const Font* font, const std::string& text, - const Vector& position, int layer) + const Vector& position, int layer, Color color) { draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y), - ALIGN_CENTER, layer); + ALIGN_CENTER, layer, color); } void @@ -220,21 +224,28 @@ DrawingContext::draw_filled_rect(const Vector& topleft, const Vector& size, fillrectrequest->size = size; fillrectrequest->color = color; fillrectrequest->color.alpha = color.alpha * transform.alpha; + fillrectrequest->radius = 0.0f; request->request_data = fillrectrequest; requests->push_back(request); } void -DrawingContext::draw_filled_rect(const Rect& rect, const Color& color, +DrawingContext::draw_filled_rect(const Rectf& rect, const Color& color, int layer) { + draw_filled_rect(rect, color, 0.0f, layer); +} + +void +DrawingContext::draw_filled_rect(const Rectf& rect, const Color& color, float radius, int layer) +{ DrawingRequest* request = new(obst) DrawingRequest(); request->target = target; - request->type = FILLRECT; - request->pos = transform.apply(rect.p1); - request->layer = layer; + request->type = FILLRECT; + request->pos = transform.apply(rect.p1); + request->layer = layer; request->drawing_effect = transform.drawing_effect; request->alpha = transform.alpha; @@ -243,9 +254,33 @@ DrawingContext::draw_filled_rect(const Rect& rect, const Color& color, fillrectrequest->size = Vector(rect.get_width(), rect.get_height()); fillrectrequest->color = color; fillrectrequest->color.alpha = color.alpha * transform.alpha; + fillrectrequest->radius = radius; request->request_data = fillrectrequest; - requests->push_back(request); + requests->push_back(request); +} + +void +DrawingContext::draw_inverse_ellipse(const Vector& pos, const Vector& size, const Color& color, int layer) +{ + DrawingRequest* request = new(obst) DrawingRequest(); + + request->target = target; + request->type = INVERSEELLIPSE; + request->pos = transform.apply(pos); + request->layer = layer; + + request->drawing_effect = transform.drawing_effect; + request->alpha = transform.alpha; + + InverseEllipseRequest* ellipse = new(obst)InverseEllipseRequest; + + ellipse->color = color; + ellipse->color.alpha = color.alpha * transform.alpha; + ellipse->size = size; + request->request_data = ellipse; + + requests->push_back(request); } void @@ -264,7 +299,7 @@ DrawingContext::get_light(const Vector& position, Color* color) //There is no light offscreen. if(request->pos.x >= SCREEN_WIDTH || request->pos.y >= SCREEN_HEIGHT - || request->pos.x < 0 || request->pos.y < 0){ + || request->pos.x < 0 || request->pos.y < 0){ *color = Color( 0, 0, 0); return; } @@ -279,10 +314,8 @@ DrawingContext::get_light(const Vector& position, Color* color) void DrawingContext::do_drawing() { -#ifdef DEBUG assert(transformstack.empty()); assert(target_stack.empty()); -#endif transformstack.clear(); target_stack.clear(); @@ -295,12 +328,17 @@ DrawingContext::do_drawing() lightmap->start_draw(ambient_color); handle_drawing_requests(lightmap_requests); lightmap->end_draw(); + + DrawingRequest* request = new(obst) DrawingRequest(); + request->target = NORMAL; + request->type = DRAW_LIGHTMAP; + request->layer = LAYER_HUD - 1; + drawing_requests.push_back(request); } + lightmap_requests.clear(); handle_drawing_requests(drawing_requests); - if(use_lightmap) { - lightmap->do_draw(); - } + drawing_requests.clear(); obstack_free(&obst, NULL); obstack_init(&obst); @@ -314,9 +352,6 @@ DrawingContext::do_drawing() } class RequestPtrCompare - : public std::binary_function { public: bool operator()(const DrawingRequest* r1, const DrawingRequest* r2) const @@ -347,11 +382,21 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests) renderer->draw_gradient(request); break; case TEXT: - renderer->draw_text(request); - break; + { + const TextRequest* textrequest = (TextRequest*) request.request_data; + textrequest->font->draw(renderer, textrequest->text, request.pos, + textrequest->alignment, request.drawing_effect, request.color, request.alpha); + } + break; case FILLRECT: renderer->draw_filled_rect(request); break; + case INVERSEELLIPSE: + renderer->draw_inverse_ellipse(request); + break; + case DRAW_LIGHTMAP: + lightmap->do_draw(); + break; case GETLIGHT: lightmap->get_light(request); break; @@ -369,11 +414,21 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests) lightmap->draw_gradient(request); break; case TEXT: - lightmap->draw_text(request); - break; + { + const TextRequest* textrequest = (TextRequest*) request.request_data; + textrequest->font->draw(renderer, textrequest->text, request.pos, + textrequest->alignment, request.drawing_effect, request.color, request.alpha); + } + break; case FILLRECT: lightmap->draw_filled_rect(request); break; + case INVERSEELLIPSE: + assert(!"InverseEllipse doesn't make sense on the lightmap"); + break; + case DRAW_LIGHTMAP: + lightmap->do_draw(); + break; case GETLIGHT: lightmap->get_light(request); break; @@ -381,7 +436,6 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests) break; } } - requests.clear(); } void @@ -460,3 +514,4 @@ DrawingContext::take_screenshot() screenshot_requested = true; } +/* EOF */