From: Ingo Ruhnke Date: Mon, 5 May 2008 15:05:57 +0000 (+0000) Subject: Replaced rectangular shrinkfade with a circular one X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d7f25606f0a2bb011c9fcf3eaf4498076f40f503;p=supertux.git Replaced rectangular shrinkfade with a circular one SVN-Revision: 5412 --- diff --git a/src/shrinkfade.cpp b/src/shrinkfade.cpp index d921efbc9..0b579b430 100644 --- a/src/shrinkfade.cpp +++ b/src/shrinkfade.cpp @@ -46,24 +46,11 @@ ShrinkFade::update(float elapsed_time) void ShrinkFade::draw(DrawingContext& context) { - Color black(0, 0, 0); - float left = speedleft * accum_time; - float top = speedtop * accum_time; - float right = SCREEN_WIDTH - speedright * accum_time; - float bottom = SCREEN_HEIGHT - speedbottom * accum_time; - - context.draw_filled_rect(Vector(0, 0), - Vector(left, SCREEN_HEIGHT), - black, LAYER_GUI+1); - context.draw_filled_rect(Vector(0, 0), - Vector(SCREEN_WIDTH, top), - black, LAYER_GUI+1); - context.draw_filled_rect(Vector(right, 0), - Vector(SCREEN_WIDTH, SCREEN_HEIGHT), - black, LAYER_GUI+1); - context.draw_filled_rect(Vector(0, bottom), - Vector(SCREEN_WIDTH, SCREEN_HEIGHT), - black, LAYER_GUI+1); + float progress = accum_time / fade_time; + context.draw_inverse_ellipse(dest, + Vector(2*SCREEN_WIDTH * (1.0f - progress), + 2*SCREEN_HEIGHT * (1.0f - progress)), + Color(0, 0, 0), LAYER_GUI+1); } bool diff --git a/src/video/drawing_context.cpp b/src/video/drawing_context.cpp index 62c6ee341..309c4c139 100644 --- a/src/video/drawing_context.cpp +++ b/src/video/drawing_context.cpp @@ -256,6 +256,29 @@ DrawingContext::draw_filled_rect(const Rect& rect, const Color& color, float rad } 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 DrawingContext::get_light(const Vector& position, Color* color) { if( ambient_color.red == 1.0f && ambient_color.green == 1.0f @@ -365,6 +388,9 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests) case FILLRECT: renderer->draw_filled_rect(request); break; + case INVERSEELLIPSE: + renderer->draw_inverse_ellipse(request); + break; case GETLIGHT: lightmap->get_light(request); break; @@ -391,6 +417,9 @@ DrawingContext::handle_drawing_requests(DrawingRequests& requests) case FILLRECT: lightmap->draw_filled_rect(request); break; + case INVERSEELLIPSE: + assert(!"InverseEllipse doesn't make sense on the lightmap"); + break; case GETLIGHT: lightmap->get_light(request); break; diff --git a/src/video/drawing_context.hpp b/src/video/drawing_context.hpp index 73713f794..abfab2220 100644 --- a/src/video/drawing_context.hpp +++ b/src/video/drawing_context.hpp @@ -80,6 +80,8 @@ public: void draw_filled_rect(const Rect& rect, const Color& color, int layer); void draw_filled_rect(const Rect& rect, const Color& color, float radius, int layer); + void draw_inverse_ellipse(const Vector& pos, const Vector& size, const Color& color, int layer); + /// Processes all pending drawing requests and flushes the list. void do_drawing(); diff --git a/src/video/drawing_request.hpp b/src/video/drawing_request.hpp index 5eeb71197..448700dc7 100644 --- a/src/video/drawing_request.hpp +++ b/src/video/drawing_request.hpp @@ -70,7 +70,7 @@ enum Target { enum RequestType { - SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, GETLIGHT + SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, INVERSEELLIPSE, GETLIGHT }; struct SurfacePartRequest @@ -99,6 +99,12 @@ struct FillRectRequest float radius; }; +struct InverseEllipseRequest +{ + Color color; + Vector size; +}; + struct DrawingRequest { Target target; diff --git a/src/video/gl_renderer.cpp b/src/video/gl_renderer.cpp index 3654a4969..76a7975be 100644 --- a/src/video/gl_renderer.cpp +++ b/src/video/gl_renderer.cpp @@ -326,6 +326,81 @@ namespace GL } } + void + Renderer::draw_inverse_ellipse(const DrawingRequest& request) + { + const InverseEllipseRequest* ellipse = (InverseEllipseRequest*)request.request_data; + + glDisable(GL_TEXTURE_2D); + glColor4f(ellipse->color.red, ellipse->color.green, + ellipse->color.blue, ellipse->color.alpha); + + float x = request.pos.x; + float y = request.pos.y; + float w = ellipse->size.x/2.0f; + float h = ellipse->size.y/2.0f; + + glBegin(GL_TRIANGLES); + + // Bottom + glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT); + glVertex2f(0, SCREEN_HEIGHT); + glVertex2f(x, y+h); + + // Top + glVertex2f(SCREEN_WIDTH, 0); + glVertex2f(0, 0); + glVertex2f(x, y-h); + + // Left + glVertex2f(SCREEN_WIDTH, 0); + glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT); + glVertex2f(x+w, y); + + // Right + glVertex2f(0, 0); + glVertex2f(0, SCREEN_HEIGHT); + glVertex2f(x-w, y); + + glEnd(); + + int slices = 8; + for(int i = 0; i < slices; ++i) + { + float ex1 = sinf(M_PI/2 / slices * i) * w; + float ey1 = cosf(M_PI/2 / slices * i) * h; + + float ex2 = sinf(M_PI/2 / slices * (i+1)) * w; + float ey2 = cosf(M_PI/2 / slices * (i+1)) * h; + + glBegin(GL_TRIANGLES); + + // Bottom/Right + glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT); + glVertex2f(x + ex1, y + ey1); + glVertex2f(x + ex2, y + ey2); + + // Top/Left + glVertex2f(0, 0); + glVertex2f(x - ex1, y - ey1); + glVertex2f(x - ex2, y - ey2); + + // Top/Right + glVertex2f(SCREEN_WIDTH, 0); + glVertex2f(x + ex1, y - ey1); + glVertex2f(x + ex2, y - ey2); + + // Bottom/Left + glVertex2f(0, SCREEN_HEIGHT); + glVertex2f(x - ex1, y + ey1); + glVertex2f(x - ex2, y + ey2); + + glEnd(); + } + glEnable(GL_TEXTURE_2D); + glColor4f(1, 1, 1, 1); + } + void Renderer::do_take_screenshot() { diff --git a/src/video/gl_renderer.hpp b/src/video/gl_renderer.hpp index 1eef6b489..3a45629f4 100644 --- a/src/video/gl_renderer.hpp +++ b/src/video/gl_renderer.hpp @@ -38,6 +38,7 @@ namespace GL void draw_text(const DrawingRequest& request); void draw_gradient(const DrawingRequest& request); void draw_filled_rect(const DrawingRequest& request); + void draw_inverse_ellipse(const DrawingRequest& request); void do_take_screenshot(); void flip(); }; diff --git a/src/video/renderer.hpp b/src/video/renderer.hpp index 2bd96d70b..8e97e377f 100644 --- a/src/video/renderer.hpp +++ b/src/video/renderer.hpp @@ -48,6 +48,7 @@ public: virtual void draw_surface_part(const DrawingRequest& request) = 0; virtual void draw_gradient(const DrawingRequest& request) = 0; virtual void draw_filled_rect(const DrawingRequest& request)= 0; + virtual void draw_inverse_ellipse(const DrawingRequest& request)= 0; virtual void do_take_screenshot() = 0; virtual void flip() = 0; }; diff --git a/src/video/sdl_renderer.cpp b/src/video/sdl_renderer.cpp index dede6c832..a48d7f914 100644 --- a/src/video/sdl_renderer.cpp +++ b/src/video/sdl_renderer.cpp @@ -396,6 +396,11 @@ namespace SDL } } + void + Renderer::draw_inverse_ellipse(const DrawingRequest&) + { + } + void Renderer::do_take_screenshot() { diff --git a/src/video/sdl_renderer.hpp b/src/video/sdl_renderer.hpp index 24dcb84ff..5a6d31add 100644 --- a/src/video/sdl_renderer.hpp +++ b/src/video/sdl_renderer.hpp @@ -36,6 +36,7 @@ namespace SDL void draw_text(const DrawingRequest& request); void draw_gradient(const DrawingRequest& request); void draw_filled_rect(const DrawingRequest& request); + void draw_inverse_ellipse(const DrawingRequest& request); void do_take_screenshot(); void flip(); private: diff --git a/src/worldmap/worldmap.cpp b/src/worldmap/worldmap.cpp index 45310ec1e..bb012d9b3 100644 --- a/src/worldmap/worldmap.cpp +++ b/src/worldmap/worldmap.cpp @@ -712,7 +712,7 @@ WorldMap::update(float delta) save_state(); main_loop->push_screen(new GameSession(levelfile, &level->statistics), - new ShrinkFade(shrinkpos, 0.5)); + new ShrinkFade(shrinkpos, 1.0f)); in_level = true; } catch(std::exception& e) { log_fatal << "Couldn't load level: " << e.what() << std::endl;