SDLPainter 1.4.0
SDL3 + OpenGL/Vulkan 2D çizim kütüphanesi
Yüklüyor...
Arıyor...
Eşleşme Yok
brush.h
1#pragma once
2
3#include "sdl_painter/color.h"
4#include "sdl_painter/geometry.h"
5
6#include <cstdint>
7
8namespace sdl_painter {
9
12enum class BrushType : uint8_t {
13 kSolid,
14 kLinear,
15 kRadial,
16};
17
36class Brush {
37 public:
39 Brush() = default;
40
42 explicit Brush(const Color& color) : mColor(color) {}
43
53 [[nodiscard]] static Brush LinearGradient(const Point& start,
54 const Point& end, const Color& from,
55 const Color& to) noexcept {
56 Brush b;
57 b.mType = BrushType::kLinear;
58 b.mColor = from;
59 b.mColor2 = to;
60 b.mStart = start;
61 b.mEnd = end;
62 return b;
63 }
64
71 [[nodiscard]] static Brush RadialGradient(const Point& center, float radius,
72 const Color& from,
73 const Color& to) noexcept {
74 Brush b;
75 b.mType = BrushType::kRadial;
76 b.mColor = from;
77 b.mColor2 = to;
78 b.mStart = center;
79 b.mRadius = radius;
80 return b;
81 }
82
84 [[nodiscard]] BrushType GetType() const noexcept { return mType; }
85
87 [[nodiscard]] bool IsGradient() const noexcept {
88 return mType != BrushType::kSolid;
89 }
90
92 [[nodiscard]] const Color& GetColor2() const noexcept { return mColor2; }
93
95 [[nodiscard]] const Point& GetStart() const noexcept { return mStart; }
96
98 [[nodiscard]] const Point& GetEnd() const noexcept { return mEnd; }
99
101 [[nodiscard]] float GetRadius() const noexcept { return mRadius; }
102
104 [[nodiscard]] const Color& GetColor() const noexcept { return mColor; }
105
107 void SetColor(const Color& color) noexcept { mColor = color; }
108
115 [[nodiscard]] bool IsVisible() const noexcept {
116 return mColor.a > 0 || (IsGradient() && mColor2.a > 0);
117 }
118
119 [[nodiscard]] bool operator==(const Brush& other) const noexcept {
120 if (mColor != other.mColor || mType != other.mType) {
121 return false;
122 }
123 if (mType == BrushType::kSolid) {
124 return true;
125 }
126 return mColor2 == other.mColor2 && mStart.x == other.mStart.x &&
127 mStart.y == other.mStart.y && mEnd.x == other.mEnd.x &&
128 mEnd.y == other.mEnd.y && mRadius == other.mRadius;
129 }
130 [[nodiscard]] bool operator!=(const Brush& other) const noexcept {
131 return !(*this == other);
132 }
133
135 [[nodiscard]] static Brush NoBrush() noexcept {
136 return Brush(Color::Transparent());
137 }
138
139 private:
140 Color mColor{Color::Black()};
141 Color mColor2{Color::White()};
142 Point mStart;
143 Point mEnd;
144 float mRadius{0.0F};
145 BrushType mType{BrushType::kSolid};
146};
147
148} // namespace sdl_painter
Dolgu stili — düz renk veya gradient.
Definition brush.h:36
static Brush LinearGradient(const Point &start, const Point &end, const Color &from, const Color &to) noexcept
Doğrusal gradient fırça.
Definition brush.h:53
bool IsVisible() const noexcept
Fırça görünür mü? (alpha > 0).
Definition brush.h:115
const Point & GetEnd() const noexcept
Doğrusal gradientte bitiş noktası.
Definition brush.h:98
BrushType GetType() const noexcept
Fırçanın dolgu türü.
Definition brush.h:84
float GetRadius() const noexcept
Işınsal gradientte yarıçap.
Definition brush.h:101
static Brush RadialGradient(const Point &center, float radius, const Color &from, const Color &to) noexcept
Işınsal gradient fırça.
Definition brush.h:71
const Color & GetColor() const noexcept
Dolgu rengini döndür.
Definition brush.h:104
const Point & GetStart() const noexcept
Doğrusal gradientte başlangıç, ışınsalda merkez.
Definition brush.h:95
Brush()=default
Varsayılan fırça: siyah, tam opak.
bool IsGradient() const noexcept
Gradient mi? (düz renk değil).
Definition brush.h:87
void SetColor(const Color &color) noexcept
Dolgu rengini ayarla.
Definition brush.h:107
Brush(const Color &color)
Renk ile fırça oluştur.
Definition brush.h:42
const Color & GetColor2() const noexcept
Gradient bitiş rengi (düz fırçada anlamsız).
Definition brush.h:92
static Brush NoBrush() noexcept
Şeffaf (dolgu yapmayan) fırça.
Definition brush.h:135
RGBA renk temsili. Her kanal [0, 255] aralığında.
Definition color.h:8
static constexpr Color Black() noexcept
Definition color.h:44
2B nokta — float koordinatlar.
Definition geometry.h:8