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"
33namespace sdl_painter {
44 BlendMode blend_mode{BlendMode::kAlpha};
63 Painter(SDL_Window* window, RendererBackend backend);
78 Painter(std::unique_ptr<IRenderer> renderer, int32_t viewport_width,
79 int32_t viewport_height);
90 [[nodiscard]]
bool IsValid() const noexcept {
return mRenderer !=
nullptr; }
133 void SetViewport(int32_t x, int32_t y, int32_t width, int32_t height);
151 int32_t width, int32_t height,
152 TextureFilter filter = TextureFilter::kLinear);
175 const Color& tint = Color::White(),
176 ImageFlip flip = ImageFlip::kNone);
180 const Color& tint = Color::White(),
181 ImageFlip flip = ImageFlip::kNone);
197 std::vector<uint8_t>& out_rgba);
233 [[nodiscard]]
const std::shared_ptr<Font>&
GetFont() const noexcept {
253 return mCurrentState.blend_mode;
259 void DrawLine(
float x1,
float y1,
float x2,
float y2);
303 void DrawArc(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
304 float sweep_degrees);
307 void DrawPie(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
308 float sweep_degrees);
311 void FillPie(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
312 float sweep_degrees);
315 void DrawChord(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
316 float sweep_degrees);
319 void FillChord(
float cx,
float cy,
float rx,
float ry,
float start_degrees,
320 float sweep_degrees);
364 const Color& tint = Color::White(),
365 ImageFlip flip = ImageFlip::kNone);
369 const Color& tint = Color::White(),
370 ImageFlip flip = ImageFlip::kNone);
390 const std::vector<Point>& points,
391 const Color& tint = Color::White());
418 const Rect& dest_rect,
const Color& tint = Color::White(),
419 ImageFlip flip = ImageFlip::kNone);
428 void DrawText(
float x,
float y,
const std::string& text);
441 Alignment alignment = Alignment::kLeft,
442 TextWrap wrap = TextWrap::kNone);
452 TextWrap wrap)
const;
488 void QueryDrawableSize(int32_t& out_width, int32_t& out_height)
const;
491 void ApplyDrawableSize(int32_t width, int32_t height);
494 void UpdateProjection();
506 [[nodiscard]]
bool YAxisMatchesGpu()
const;
509 [[nodiscard]] int32_t SurfaceHeight()
const;
512 void ApplyViewport();
518 void PushTexturedQuad(TextureHandle texture,
float u0,
float v0,
float u1,
519 float v1,
const Rect& dest_rect,
const Color& tint,
524 void PushStroke(
const std::vector<Vertex>& verts,
const Color& color);
530 void PushFilled(std::vector<Vertex>& verts);
536 void DrawTextLine(
float x,
float y,
const std::string& text);
539 [[nodiscard]]
float AlignedX(
const Rect& rect,
const std::string& line,
540 Alignment alignment)
const;
545 void ApplyScissor(
const Rect& rect);
548 void ClearScissorCounted();
550 [[nodiscard]]
bool CanDrawPen() const noexcept {
551 return mRenderer && mBatcher && mCurrentState.pen.IsVisible();
553 [[nodiscard]]
bool CanDrawBrush() const noexcept {
554 return mRenderer && mBatcher && mCurrentState.brush.IsVisible();
557 SDL_Window* mWindow{
nullptr};
559 std::unique_ptr<IRenderer> mRenderer;
560 std::unique_ptr<RenderBatcher> mBatcher;
561 std::vector<RenderState> mStateStack;
562 RenderState mCurrentState;
563 std::shared_ptr<Font> mCurrentFont;
567 FrameStats mLastStats;
568 uint64_t mFrameStartNs{0};
571 int32_t mDrawableWidth{0};
572 int32_t mDrawableHeight{0};
577 int32_t mViewportX{0};
578 int32_t mViewportY{0};
579 int32_t mViewportWidth{0};
580 int32_t mViewportHeight{0};
584 bool mCustomViewport{
false};
587 RenderTargetHandle mActiveTarget{kInvalidRenderTarget};
588 int32_t mTargetWidth{0};
589 int32_t mTargetHeight{0};
592 int32_t mSavedViewportX{0};
593 int32_t mSavedViewportY{0};
594 int32_t mSavedViewportWidth{0};
595 int32_t mSavedViewportHeight{0};
596 bool mSavedCustomViewport{
false};
600 bool mAutoDrawableSize{
true};
Dolgu stili — düz renk veya gradient.
Definition brush.h:34
Yüklenmiş görüntü — texture sarmalayıcı.
Definition image.h:39
Ana çizim sınıfı
Definition painter.h:60
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:233
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 [0.0, 1.0].
const FrameStats & GetFrameStats() const noexcept
Son tamamlanan karenin çizim istatistikleri.
Definition painter.h:213
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)
Ekranı 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:252
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:90
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
Ekran yerine çizilebilen offscreen bir yüzey (dokuya çizim).
Definition render_target.h:51
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:39
glm::mat3 transform
3x3 affine dönüşüm (column-major, birim).
Definition painter.h:40