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
}
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
case FILLRECT:
renderer->draw_filled_rect(request);
break;
+ case INVERSEELLIPSE:
+ renderer->draw_inverse_ellipse(request);
+ break;
case GETLIGHT:
lightmap->get_light(request);
break;
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;
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();
enum RequestType
{
- SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, GETLIGHT
+ SURFACE, SURFACE_PART, TEXT, GRADIENT, FILLRECT, INVERSEELLIPSE, GETLIGHT
};
struct SurfacePartRequest
float radius;
};
+struct InverseEllipseRequest
+{
+ Color color;
+ Vector size;
+};
+
struct DrawingRequest
{
Target target;
}
}
+ 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()
{
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();
};
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;
};
}
}
+ void
+ Renderer::draw_inverse_ellipse(const DrawingRequest&)
+ {
+ }
+
void
Renderer::do_take_screenshot()
{
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:
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;