void Draw CircleFilled SDL_Renderer renderer const float2 center float

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void Draw::CircleFilled(SDL_Renderer* renderer, const float2& center, float radius)
{
const float2 texture_size = Ceil(radius * Max(1.0f, Config::RenderScale)) * 32;
static const float smoothing_width = 0.1f;
static bool init = GeneratedTextureCache::Get().SetGenerator("CF", 0xFF, [](const float2& uv, Color& pixel)
{
float center_distance = uv.DistanceTo(float2(0.5f)) * 8.0f;
if (center_distance < 1.0f) return;
pixel.a *= Clamp(1.0f - (center_distance - 1.0f) / smoothing_width);
});
auto texture = GeneratedTextureCache::Get().GetTexture(renderer, "CF", texture_size);
const float2 texture_scale = float2(radius) / texture_size * 4.0f;
const float2 render_size = Ceil(texture_scale * texture_size);
const int2 top_left = center - Ceil(render_size / 2.0f);
const int2 bottom_right = top_left + render_size;
const float2 sprite_center = float2(top_left + bottom_right) * 0.5f;
float2 offset = (sprite_center - center) / texture_scale * 0.5f;
::Rect src = { texture_size / 4.0f + offset, texture_size / 2.0f };
::Rect dst = { top_left, render_size };
Draw::Utility::UpdateTextureTintColor(renderer, texture.get());
SDL_RenderCopy(renderer, texture.get(), &src, &dst);
}