3#include "sdl_painter/brush.h"
4#include "sdl_painter/color.h"
5#include "sdl_painter/export.h"
6#include "sdl_painter/font.h"
7#include "sdl_painter/frame_stats.h"
8#include "sdl_painter/geometry.h"
11#include "sdl_painter/image.h"
12#include "sdl_painter/path.h"
13#include "sdl_painter/pen.h"
14#include "sdl_painter/render_target.h"
15#include "sdl_painter/renderer.h"
16#include "sdl_painter/vertex.h"
32namespace sdl_painter {
43 BlendMode blend_mode{BlendMode::kAlpha};
66 Painter(SDL_Window* window, RendererBackend backend);
81 Painter(std::unique_ptr<IRenderer> renderer, int32_t viewport_width,
82 int32_t viewport_height);
93 [[nodiscard]]
bool IsValid() const noexcept {
return mRenderer !=
nullptr; }
132 void SetViewport(int32_t x, int32_t y, int32_t width, int32_t height);
148 int32_t width, int32_t height,
149 TextureFilter filter = TextureFilter::kLinear);
177 const Color& tint = Color::White(),
178 ImageFlip flip = ImageFlip::kNone);
182 const Color& tint = Color::White(),
183 ImageFlip flip = ImageFlip::kNone);
203 std::vector<uint8_t>& out_rgba);
244 [[nodiscard]]
const std::shared_ptr<Font>&
GetFont() const noexcept {
265 return mCurrentState.blend_mode;
269 void DrawLine(
float x1,
float y1,
float x2,
float y2);
313 void DrawArc(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
314 float sweep_degrees);
317 void DrawPie(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
318 float sweep_degrees);
321 void FillPie(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
322 float sweep_degrees);
325 void DrawChord(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
326 float sweep_degrees);
329 void FillChord(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
330 float sweep_degrees);
370 const Color& tint = Color::White(),
371 ImageFlip flip = ImageFlip::kNone);
375 const Color& tint = Color::White(),
376 ImageFlip flip = ImageFlip::kNone);
396 const std::vector<Point>& points,
397 const Color& tint = Color::White());
424 const Rect& dest_rect,
const Color& tint = Color::White(),
425 ImageFlip flip = ImageFlip::kNone);
432 void DrawText(
float x,
float y,
const std::string& text);
445 Alignment alignment = Alignment::kLeft,
446 TextWrap wrap = TextWrap::kNone);
456 TextWrap wrap)
const;
494 friend class RenderTarget;
501 void OnRenderTargetDestroyed(RenderTargetHandle handle);
508 void QueryDrawableSize(int32_t& out_width, int32_t& out_height)
const;
511 void ApplyDrawableSize(int32_t width, int32_t height);
514 void UpdateProjection();
526 [[nodiscard]]
bool YAxisMatchesGpu()
const;
529 [[nodiscard]] int32_t SurfaceWidth()
const;
532 [[nodiscard]] int32_t SurfaceHeight()
const;
539 [[nodiscard]]
bool OwnsTarget(
const RenderTarget& target)
const;
542 void ApplyViewport();
548 void PushTexturedQuad(TextureHandle texture,
float u0,
float v0,
float u1,
549 float v1,
const Rect& dest_rect,
const Color& tint,
554 void PushStroke(
const std::vector<Vertex>& verts,
const Color& color);
560 void PushFilled(std::vector<Vertex>& verts);
566 void DrawTextLine(
float x,
float y,
const std::string& text);
569 [[nodiscard]]
float AlignedX(
const Rect& rect,
const std::string& line,
570 Alignment alignment)
const;
575 void ApplyScissor(
const Rect& rect);
578 void ClearScissorCounted();
580 [[nodiscard]]
bool CanDrawPen() const noexcept {
581 return mRenderer && mBatcher && mCurrentState.pen.IsVisible();
583 [[nodiscard]]
bool CanDrawBrush() const noexcept {
584 return mRenderer && mBatcher && mCurrentState.brush.IsVisible();
587 SDL_Window* mWindow{
nullptr};
589 std::unique_ptr<IRenderer> mRenderer;
590 std::unique_ptr<RenderBatcher> mBatcher;
591 std::vector<RenderState> mStateStack;
592 RenderState mCurrentState;
593 std::shared_ptr<Font> mCurrentFont;
597 FrameStats mLastStats;
598 uint64_t mFrameStartNs{0};
601 int32_t mDrawableWidth{0};
602 int32_t mDrawableHeight{0};
607 int32_t mViewportX{0};
608 int32_t mViewportY{0};
609 int32_t mViewportWidth{0};
610 int32_t mViewportHeight{0};
614 bool mCustomViewport{
false};
617 RenderTargetHandle mActiveTarget{kInvalidRenderTarget};
618 int32_t mTargetWidth{0};
619 int32_t mTargetHeight{0};
622 int32_t mSavedViewportX{0};
623 int32_t mSavedViewportY{0};
624 int32_t mSavedViewportWidth{0};
625 int32_t mSavedViewportHeight{0};
626 bool mSavedCustomViewport{
false};
630 bool mAutoDrawableSize{
true};
638 std::shared_ptr<Painter*> mSelf;
Dolgu stili — düz renk veya gradient.
Definition brush.h:36
Backend-agnostik soyut renderer arayüzü.
Definition renderer.h:77
Yüklenmiş görüntü — texture sarmalayıcı.
Definition image.h:38
void DrawPolygon(const std::vector< Point > &points)
Çok kenarlı kapalı şeklin çerçevesini çiz.
void ClearClip()
Kırpma dikdörtgenini kaldır.
void DrawChord(float cx, float cy, float rx, float ry, float start_degrees, float sweep_degrees)
Kiriş (chord) çerçevesi — yay artı uçlarını birleştiren doğru.
void FillPie(float cx, float cy, float rx, float ry, float start_degrees, float sweep_degrees)
Dilimi doldur. Çizelgelerin (pasta grafik) temel yapı taşı.
void SetBrush(const Brush &brush)
Aktif fırçayı ayarla (dolgu rengi).
void Translate(float dx, float dy)
Öteleme uygula.
void Begin()
Frame başlangıcı — her frame başında çağrılmalı.
Painter(std::unique_ptr< IRenderer > renderer, int32_t viewport_width, int32_t viewport_height)
Hazır bir renderer ile pencere olmadan Painter oluştur.
void End()
Frame sonu — her frame sonunda çağrılmalı, ekrana sunar.
void DrawImage(const Image &image, const Rect &src_rect, const Rect &dest_rect, const Color &tint=Color::White(), ImageFlip flip=ImageFlip::kNone)
Görüntünün kaynak dikdörtgenini hedef dikdörtgene çiz.
void UpdateImage(const Image &image, const uint8_t *rgba)
Yüklenmiş bir görüntünün doku içeriğini yerinde güncelle.
void DrawPolyline(const std::vector< Point > &points)
Açık çizgi dizisi çiz.
void DrawEllipse(float cx, float cy, float rx, float ry)
Elips çerçeve çiz.
const std::shared_ptr< Font > & GetFont() const noexcept
Aktif font (yoksa nullptr).
Definition painter.h:244
void FillPath(const Path &path)
Yolun içini doldur (ear clipping tessellation).
void Restore()
Son kaydedilen durumu geri yükle.
void Save()
Mevcut render durumunu stack'e kaydet.
void FillRoundedRect(float x, float y, float w, float h, float radius)
Yuvarlatılmış köşeli dikdörtgeni doldur.
void SetOpacity(float alpha)
Global opaklığı ayarla.
const FrameStats & GetFrameStats() const noexcept
Son tamamlanan karenin çizim istatistikleri.
Definition painter.h:226
void DrawImage(const Image &image, const Rect &dest_rect, const Color &tint=Color::White(), ImageFlip flip=ImageFlip::kNone)
Görüntüyü hedef dikdörtgene ölçekleyerek çiz.
void DrawCircle(float cx, float cy, float radius)
Daire çerçeve çiz.
void ResetTransform()
Transform'u birim matrise sıfırla.
void Clear(const Color &color)
Çizim yüzeyini belirtilen renkle temizle.
std::size_t CountTextLines(const std::string &text, float max_width, TextWrap wrap) const
Sarmalanmış metnin kaç satır tutacağını hesapla (çizmeden).
void DrawImage(const Image &image, float x, float y, const Color &tint=Color::White(), ImageFlip flip=ImageFlip::kNone)
Görüntüyü orijinal boyutuyla çiz.
void SetViewport(int32_t x, int32_t y, int32_t width, int32_t height)
Çizimi pencerenin bir alt dikdörtgeniyle sınırla.
void DrawRoundedRect(float x, float y, float w, float h, float radius)
Yuvarlatılmış köşeli dikdörtgen çerçevesi çiz.
BlendMode GetBlendMode() const noexcept
Yürürlükteki karıştırma modu.
Definition painter.h:264
void ResetRenderTarget()
Çizimi ekrana geri al.
void DrawArc(float cx, float cy, float rx, float ry, float start_degrees, float sweep_degrees)
Yay çiz (açık — uçları birleştirilmez).
Painter(SDL_Window *window, RendererBackend backend)
Belirtilen pencere ve backend ile Painter oluştur.
void SetClipRect(const Rect &rect)
Scissor kırpma dikdörtgeni ayarla.
void DrawText(const Rect &rect, const std::string &text, Alignment alignment=Alignment::kLeft, TextWrap wrap=TextWrap::kNone)
Dikdörtgen içine hizalanmış metin çiz.
void FillPolygon(const std::vector< Point > &points)
Çok kenarlıyı doldur (ear clipping tessellation).
void ResetViewport()
Viewport'u tüm çizim yüzeyine geri al.
void DrawRenderTarget(const RenderTarget &target, float x, float y, const Color &tint=Color::White(), ImageFlip flip=ImageFlip::kNone)
Hedefin içeriğini orijinal boyutuyla çiz.
bool ReadRenderTarget(const RenderTarget &target, std::vector< uint8_t > &out_rgba)
Hedefin piksellerini ana belleğe oku.
void DrawImageMesh(const Image &image, int32_t cols, int32_t rows, const std::vector< Point > &points, const Color &tint=Color::White())
Dokuyu serbest biçimli bir ızgara üzerine çiz.
void SetPen(const Pen &pen)
Aktif kalemi ayarla (çizgi rengi ve kalınlığı).
void Scale(float sx, float sy)
Ölçekleme uygula.
void DrawPie(float cx, float cy, float rx, float ry, float start_degrees, float sweep_degrees)
Dilim (pie) çerçevesi — yay artı merkeze giden iki yarıçap.
void DrawLine(float x1, float y1, float x2, float y2)
İki nokta arasına çizgi çiz.
void DrawPath(const Path &path)
Yolun çerçevesini çiz.
void FillCircle(float cx, float cy, float radius)
Daireyi doldur.
bool IsValid() const noexcept
Renderer başarıyla başlatıldı mı?
Definition painter.h:93
void FillRect(float x, float y, float w, float h)
Dikdörtgeni doldur.
bool SetRenderTarget(const RenderTarget &target)
Sonraki çizimleri verilen hedefe yönlendir.
void DrawRenderTarget(const RenderTarget &target, const Rect &dest_rect, const Color &tint=Color::White(), ImageFlip flip=ImageFlip::kNone)
Hedefin içeriğini hedef dikdörtgene ölçekleyerek çiz.
RenderTarget CreateRenderTarget(int32_t width, int32_t height, TextureFilter filter=TextureFilter::kLinear)
Ekran yerine çizilebilen offscreen bir yüzey oluştur.
void SetBlendMode(BlendMode mode)
Renk karıştırma modunu ayarla.
void FillEllipse(float cx, float cy, float rx, float ry)
Elipsi doldur.
void DrawText(float x, float y, const std::string &text)
Noktaya metin çiz.
void FillChord(float cx, float cy, float rx, float ry, float start_degrees, float sweep_degrees)
Kirişi doldur.
void DrawRect(float x, float y, float w, float h)
Dikdörtgen çerçeve çiz (dolgu yok).
void SetDrawableSize(int32_t width, int32_t height)
Çizim yüzeyi boyutunu bildir (viewport + projeksiyon güncellenir).
void SetFont(std::shared_ptr< Font > font)
Aktif fontu ayarla.
void Rotate(float angle_degrees)
Döndürme uygula (derece).
Doğru parçaları ve Bézier eğrilerinden oluşan çizim yolu.
Definition path.h:66
Çizgi stili — renk, kalınlık ve isteğe bağlı dış kontur.
Definition pen.h:49
RGBA renk temsili. Her kanal [0, 255] aralığında.
Definition color.h:8
Bir karenin çizim maliyeti — profilleme ve ekran üstü gösterim için.
Definition frame_stats.h:16
2B dikdörtgen — sol üst köşe + genişlik/yükseklik.
Definition geometry.h:34
Aktif render durumu — transform stack elemanı.
Definition painter.h:38
glm::mat3 transform
3x3 affine dönüşüm (column-major, birim).
Definition painter.h:39