4#include <SDL3_image/SDL_image.h>
5#include <SDL3_ttf/SDL_ttf.h>
19 SDL_SetRenderDrawColor(r, color.
r, color.
g, color.
b, color.
a);
38 SDL_RenderTexture(r, tex.get(),
nullptr, &dest);
57 SDL_FlipMode flip = SDL_FLIP_NONE;
60 flip =
static_cast<SDL_FlipMode
>(flip | SDL_FLIP_HORIZONTAL);
64 flip =
static_cast<SDL_FlipMode
>(flip | SDL_FLIP_VERTICAL);
67 SDL_RenderTextureRotated(r, tex.get(),
nullptr, &dest, 0,
nullptr, flip);
80 dest.w = position.
size.x;
81 dest.h = position.
size.y;
83 SDL_RenderTexture(r, tex.get(),
nullptr, &dest);
103 const double angleDeg = angle * (180.0 / std::numbers::pi);
105 SDL_RenderTextureRotated(r, tex.get(),
nullptr, &dest, angleDeg,
nullptr, SDL_FLIP_NONE);
119 r_src.w = source.
size.x;
120 r_src.h = source.
size.y;
125 r_dest.w = dest.
size.x;
126 r_dest.h = dest.
size.y;
128 SDL_RenderTexture(r, tex.get(), &r_src, &r_dest);
142 r_src.w = source.
size.x;
143 r_src.h = source.
size.y;
148 r_dest.w = dest.
size.x;
149 r_dest.h = dest.
size.y;
151 const double angleDeg = angle * (180.0 / std::numbers::pi);
153 SDL_RenderTextureRotated(r, tex.get(), &r_src, &r_dest, angleDeg,
nullptr, SDL_FLIP_NONE);
160 if (
text.empty() || r ==
nullptr) {
164 const auto sdlColor = SDL_Color { color.
r, color.
g, color.
b, color.
a };
165 SDL_Surface* textSurface = TTF_RenderText_Blended(font.get(),
text.c_str(), 0, sdlColor);
166 SDL_Texture* textTexture = SDL_CreateTextureFromSurface(r, textSurface);
168 SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
169 SDL_SetTextureScaleMode(textTexture, SDL_SCALEMODE_LINEAR);
174 dest.w = float(textSurface->w);
175 dest.h = float(textSurface->h);
179 dest.x -= dest.w / 2.0F;
184 SDL_RenderTexture(r, textTexture,
nullptr, &dest);
185 SDL_DestroySurface(textSurface);
186 SDL_DestroyTexture(textTexture);
196 SDL_SetRenderDrawColor(r, color.
r, color.
g, color.
b, color.
a);
197 SDL_RenderPoint(r, position.
x, position.
y);
208 SDL_SetRenderDrawColor(r, color.
r, color.
g, color.
b, color.
a);
209 SDL_RenderLine(r, position1.
x, position1.
y, position2.
x, position2.
y);
219 SDL_SetRenderDrawColor(r, color.
r, color.
g, color.
b, color.
a);
226 SDL_RenderRect(r, &
rect);
236 SDL_SetRenderDrawColor(r, color.
r, color.
g, color.
b, color.
a);
243 SDL_RenderFillRect(r, &
rect);
253 SDL_SetRenderDrawColor(r, color.
r, color.
g, color.
b, color.
a);
259 const float cx = position.
x;
260 const float cy = position.
y;
263 SDL_RenderPoint(r, cx + x, cy + y);
264 SDL_RenderPoint(r, cx - x, cy + y);
265 SDL_RenderPoint(r, cx + x, cy - y);
266 SDL_RenderPoint(r, cx - x, cy - y);
267 SDL_RenderPoint(r, cx + y, cy + x);
268 SDL_RenderPoint(r, cx - y, cy + x);
269 SDL_RenderPoint(r, cx + y, cy - x);
270 SDL_RenderPoint(r, cx - y, cy - x);
273 err += (2.0F * y) + 1.0F;
276 err += (2.0F * (y - x)) + 1.0F;
288 SDL_SetRenderDrawColor(r, color.
r, color.
g, color.
b, color.
a);
293 float err = 1.0F - x;
294 const float cx = position.
x;
295 const float cy = position.
y;
298 SDL_RenderLine(r, cx - x, cy + y, cx + x, cy + y);
299 SDL_RenderLine(r, cx - x, cy - y, cx + x, cy - y);
300 SDL_RenderLine(r, cx - y, cy + x, cx + y, cy + x);
301 SDL_RenderLine(r, cx - y, cy - x, cx + y, cy - x);
304 err += (2.0F * y) + 1.0F;
307 err += (2.0F * (y - x)) + 1.0F;
314 SDL_SetTextureBlendMode(texture.get(),
static_cast<SDL_BlendMode
>(mode));
319 SDL_SetTextureAlphaModFloat(texture.get(), alpha);
Vec2< T > size
The size of the rectangle.
Vec2< T > position
The position of the rectangle.
T y
The y component of the vector.
T x
The x component of the vector.
Display and window routines for the ASW library.
Routines for drawing sprites and primitives to the screen.
asw::Renderer * get_renderer()
Get the SDL renderer.
void sprite(const asw::Texture &tex, const asw::Vec2< float > &position)
Draw a sprite.
void circle_fill(const asw::Vec2< float > &position, float radius, asw::Color color)
Draw a filled circle.
void clear_color(asw::Color color)
Clear the screen to a color.
void line(const asw::Vec2< float > &position1, const asw::Vec2< float > &position2, asw::Color color)
Draw a line.
void rotate_sprite(const asw::Texture &tex, const asw::Vec2< float > &position, float angle)
Draw a sprite with the option to rotate it.
void stretch_sprite(const asw::Texture &tex, const asw::Quad< float > &position)
Draw a sprite with the option to stretch it.
void text(const asw::Font &font, const std::string &text, const asw::Vec2< float > &position, asw::Color color, asw::TextJustify justify=asw::TextJustify::Left)
Draw text.
void stretch_sprite_rotate_blit(const asw::Texture &tex, const asw::Quad< float > &source, const asw::Quad< float > &dest, float angle)
Draw a sprite with the option to stretch and rotate a portion of it.
void rect(const asw::Quad< float > &position, asw::Color color)
Draw a rectangle.
void circle(const asw::Vec2< float > &position, float radius, asw::Color color)
Draw a circle.
void rect_fill(const asw::Quad< float > &position, asw::Color color)
Draw a filled rectangle.
void sprite_flip(const asw::Texture &tex, const asw::Vec2< float > &position, bool flip_x, bool flip_y)
Draw a sprite with the option to flip it.
void point(const asw::Vec2< float > &position, asw::Color color)
Draw a point.
void set_blend_mode(const asw::Texture &texture, asw::BlendMode mode)
Set the blend mode of a texture.
void stretch_sprite_blit(const asw::Texture &tex, const asw::Quad< float > &source, const asw::Quad< float > &dest)
Draw a sprite with the option to stretch a portion of it.
void set_alpha(const asw::Texture &texture, float alpha)
Set the alpha of a texture.
asw::Vec2< float > get_texture_size(const asw::Texture &tex)
Get texture size.
std::shared_ptr< TTF_Font > Font
Alias for a shared pointer to an TTF_Font.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
BlendMode
Mappings from SDL_BLENDMODE to ASW BlendMode.
TextJustify
Text justification options for text rendering.
RGBA color struct with 8-bit channels.
General utility functions.