+ const GradientRequest* gradientrequest
+ = (GradientRequest*) request.request_data;
+ const Color& top = gradientrequest->top;
+ const Color& bottom = gradientrequest->bottom;
+
+ int w;
+ int h;
+ SDL_GetWindowSize(window, &w, &h);
+
+ // calculate the maximum number of steps needed for the gradient
+ int n = static_cast<int>(std::max(std::max(fabsf(top.red - bottom.red),
+ fabsf(top.green - bottom.green)),
+ std::max(fabsf(top.blue - bottom.blue),
+ fabsf(top.alpha - bottom.alpha))) * 255);
+ for(int i = 0; i < n; ++i)
+ {
+ SDL_Rect rect;
+ rect.x = 0;
+ rect.y = h * i / n;
+ rect.w = w;
+ rect.h = (h * (i+1) / n) - rect.y;
+
+ float p = static_cast<float>(i+1) / static_cast<float>(n);
+ Uint8 r = static_cast<Uint8>(((1.0f - p) * top.red + p * bottom.red) * 255);
+ Uint8 g = static_cast<Uint8>(((1.0f - p) * top.green + p * bottom.green) * 255);
+ Uint8 b = static_cast<Uint8>(((1.0f - p) * top.blue + p * bottom.blue) * 255);
+ Uint8 a = static_cast<Uint8>(((1.0f - p) * top.alpha + p * bottom.alpha) * 255);
+
+ SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
+ SDL_SetRenderDrawColor(renderer, r, g, b, a);
+ SDL_RenderFillRect(renderer, &rect);
+ }
+