SDLPainter 1.2.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
11enum class BrushType : uint8_t {
12 kSolid,
13 kLinear,
14 kRadial,
15};
16
34class Brush {
35 public:
37 Brush() = default;
38
40 explicit Brush(const Color& color) : mColor(color) {}
41
51 [[nodiscard]] static Brush LinearGradient(const Point& start,
52 const Point& end, const Color& from,
53 const Color& to) noexcept {
54 Brush b;
55 b.mType = BrushType::kLinear;
56 b.mColor = from;
57 b.mColor2 = to;
58 b.mStart = start;
59 b.mEnd = end;
60 return b;
61 }
62
69 [[nodiscard]] static Brush RadialGradient(const Point& center, float radius,
70 const Color& from,
71 const Color& to) noexcept {
72 Brush b;
73 b.mType = BrushType::kRadial;
74 b.mColor = from;
75 b.mColor2 = to;
76 b.mStart = center;
77 b.mRadius = radius;
78 return b;
79 }
80
82 [[nodiscard]] BrushType GetType() const noexcept { return mType; }
83
85 [[nodiscard]] bool IsGradient() const noexcept {
86 return mType != BrushType::kSolid;
87 }
88
90 [[nodiscard]] const Color& GetColor2() const noexcept { return mColor2; }
91
93 [[nodiscard]] const Point& GetStart() const noexcept { return mStart; }
94
96 [[nodiscard]] const Point& GetEnd() const noexcept { return mEnd; }
97
99 [[nodiscard]] float GetRadius() const noexcept { return mRadius; }
100
102 [[nodiscard]] const Color& GetColor() const noexcept { return mColor; }
103
105 void SetColor(const Color& color) noexcept { mColor = color; }
106
113 [[nodiscard]] bool IsVisible() const noexcept {
114 return mColor.a > 0 || (IsGradient() && mColor2.a > 0);
115 }
116
117 [[nodiscard]] bool operator==(const Brush& other) const noexcept {
118 if (mColor != other.mColor || mType != other.mType) {
119 return false;
120 }
121 if (mType == BrushType::kSolid) {
122 return true;
123 }
124 return mColor2 == other.mColor2 && mStart.x == other.mStart.x &&
125 mStart.y == other.mStart.y && mEnd.x == other.mEnd.x &&
126 mEnd.y == other.mEnd.y && mRadius == other.mRadius;
127 }
128 [[nodiscard]] bool operator!=(const Brush& other) const noexcept {
129 return !(*this == other);
130 }
131
133 [[nodiscard]] static Brush NoBrush() noexcept {
134 return Brush(Color::Transparent());
135 }
136
137 private:
138 Color mColor{Color::Black()};
139 Color mColor2{Color::White()};
140 Point mStart;
141 Point mEnd;
142 float mRadius{0.0F};
143 BrushType mType{BrushType::kSolid};
144};
145
146} // namespace sdl_painter
Dolgu stili — düz renk veya gradient.
Definition brush.h:34
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:51
bool IsVisible() const noexcept
Fırça görünür mü? (alpha > 0).
Definition brush.h:113
const Point & GetEnd() const noexcept
Doğrusal gradientte bitiş noktası.
Definition brush.h:96
BrushType GetType() const noexcept
Fırçanın dolgu türü.
Definition brush.h:82
float GetRadius() const noexcept
Işınsal gradientte yarıçap.
Definition brush.h:99
static Brush RadialGradient(const Point &center, float radius, const Color &from, const Color &to) noexcept
Işınsal gradient fırça.
Definition brush.h:69
const Color & GetColor() const noexcept
Dolgu rengini döndür.
Definition brush.h:102
const Point & GetStart() const noexcept
Doğrusal gradientte başlangıç, ışınsalda merkez.
Definition brush.h:93
Brush()=default
Varsayılan fırça: siyah, tam opak.
bool IsGradient() const noexcept
Gradient mi? (düz renk değil).
Definition brush.h:85
void SetColor(const Color &color) noexcept
Dolgu rengini ayarla.
Definition brush.h:105
Brush(const Color &color)
Renk ile fırça oluştur.
Definition brush.h:40
const Color & GetColor2() const noexcept
Gradient bitiş rengi (düz fırçada anlamsız).
Definition brush.h:90
static Brush NoBrush() noexcept
Şeffaf (dolgu yapmayan) fırça.
Definition brush.h:133
RGBA renk temsili. Her kanal [0, 255] aralığında.
Definition color.h:8
2B nokta — float koordinatlar.
Definition geometry.h:8