From 0d0d12b27ed07902df0e2a8efb4ef8377c83227e Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 30 Jul 2014 07:31:13 +0200 Subject: [PATCH] Implemented SDLRenderer::draw_inverse_ellipse() --- src/video/sdl/sdl_renderer.cpp | 57 +++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index bc0bece6b..b4d958ff6 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -510,32 +510,61 @@ SDLRenderer::draw_filled_rect(const DrawingRequest& request) void SDLRenderer::draw_inverse_ellipse(const DrawingRequest& request) { -#ifdef OLD_SDL1 const InverseEllipseRequest* ellipse = (InverseEllipseRequest*)request.request_data; - Uint8 r = static_cast(ellipse->color.red * 255); - Uint8 g = static_cast(ellipse->color.green * 255); - Uint8 b = static_cast(ellipse->color.blue * 255); - Uint8 a = static_cast(ellipse->color.alpha * 255); - int window_w; int window_h; SDL_GetWindowSize(window, &window_w, &window_h); float x = request.pos.x; - float y = request.pos.y; - float w = ellipse->size.x/2.0f; - float h = ellipse->size.y/2.0f; + float w = ellipse->size.x; + float h = ellipse->size.y; - SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); - SDL_SetRenderDrawColor(renderer, r, g, b, a); + int top = request.pos.y - (h / 2); - int slices = 32; + const int max_slices = 256; + SDL_Rect rects[2*max_slices+2]; + int slices = std::min(static_cast(ellipse->size.y), max_slices); for(int i = 0; i < slices; ++i) { - //SDL_RenderFillRect(renderer, &rect); + float p = ((static_cast(i) + 0.5f) / static_cast(slices)) * 2.0f - 1.0f; + int xoff = static_cast(sqrtf(1.0f - p*p) * w / 2); + + SDL_Rect& left = rects[2*i+0]; + SDL_Rect& right = rects[2*i+1]; + + left.x = 0; + left.y = top + (i * h / slices); + left.w = x - xoff; + left.h = (top + ((i+1) * h / slices)) - left.y; + + right.x = x + xoff; + right.y = left.y; + right.w = window_w - right.x; + right.h = left.h; } -#endif + + SDL_Rect& top_rect = rects[2*slices+0]; + SDL_Rect& bottom_rect = rects[2*slices+1]; + + top_rect.x = 0; + top_rect.y = 0; + top_rect.w = window_w; + top_rect.h = top; + + bottom_rect.x = 0; + bottom_rect.y = top + h; + bottom_rect.w = window_w; + bottom_rect.h = window_h - bottom_rect.y; + + Uint8 r = static_cast(ellipse->color.red * 255); + Uint8 g = static_cast(ellipse->color.green * 255); + Uint8 b = static_cast(ellipse->color.blue * 255); + Uint8 a = static_cast(ellipse->color.alpha * 255); + + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); + SDL_SetRenderDrawColor(renderer, r, g, b, a); + SDL_RenderFillRects(renderer, rects, 2*slices+2); } void -- 2.11.0