Replaced rectangular shrinkfade with a circular one
authorIngo Ruhnke <grumbel@gmx.de>
Mon, 5 May 2008 15:05:57 +0000 (15:05 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Mon, 5 May 2008 15:05:57 +0000 (15:05 +0000)
SVN-Revision: 5412

src/shrinkfade.cpp
src/video/drawing_context.cpp
src/video/drawing_context.hpp
src/video/drawing_request.hpp
src/video/gl_renderer.cpp
src/video/gl_renderer.hpp
src/video/renderer.hpp
src/video/sdl_renderer.cpp
src/video/sdl_renderer.hpp
src/worldmap/worldmap.cpp

index d921efb..0b579b4 100644 (file)
@@ -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
index 62c6ee3..309c4c1 100644 (file)
@@ -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;
index 73713f7..abfab22 100644 (file)
@@ -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();
 
index 5eeb711..448700d 100644 (file)
@@ -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;
index 3654a49..76a7975 100644 (file)
@@ -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()
   {
index 1eef6b4..3a45629 100644 (file)
@@ -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();
   };
index 2bd96d7..8e97e37 100644 (file)
@@ -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;
 };
index dede6c8..a48d7f9 100644 (file)
@@ -396,6 +396,11 @@ namespace SDL
     }
   }
 
+  void
+  Renderer::draw_inverse_ellipse(const DrawingRequest&)
+  {
+  }
+
   void 
   Renderer::do_take_screenshot()
   {
index 24dcb84..5a6d31a 100644 (file)
@@ -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:
index 45310ec..bb012d9 100644 (file)
@@ -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;