SDLPainter 1.2.0
SDL3 + OpenGL/Vulkan 2D çizim kütüphanesi
Yüklüyor...
Arıyor...
Eşleşme Yok
pen.h
1#pragma once
2
3#include "sdl_painter/color.h"
4
5#include <array>
6#include <cstddef>
7#include <cstdint>
8#include <initializer_list>
9
10namespace sdl_painter {
11
17enum class LineCap : uint8_t {
18 kButt,
19 kSquare,
20 kRound,
21};
22
27enum class LineJoin : uint8_t {
28 kRound,
29 kMiter,
31 kBevel,
32};
33
38inline constexpr float kMiterLimit = 4.0F;
39
46inline constexpr std::size_t kMaxDashSegments = 8;
47
49class Pen {
50 public:
52 Pen() = default;
53
57 explicit Pen(const Color& color, float width = 1.0F)
58 : mColor(color), mWidth(width) {}
59
70 Pen(const Color& color, float width, const Color& outline_color,
71 float outline_width)
72 : mColor(color),
73 mWidth(width),
74 mOutlineColor(outline_color),
75 mOutlineWidth(outline_width) {}
76
78 [[nodiscard]] const Color& GetColor() const noexcept { return mColor; }
79
81 [[nodiscard]] float GetWidth() const noexcept { return mWidth; }
82
84 [[nodiscard]] const Color& GetOutlineColor() const noexcept {
85 return mOutlineColor;
86 }
87
89 [[nodiscard]] float GetOutlineWidth() const noexcept { return mOutlineWidth; }
90
92 void SetColor(const Color& color) noexcept { mColor = color; }
93
95 void SetWidth(float width) noexcept { mWidth = width > 0.0F ? width : 0.0F; }
96
98 void SetOutlineColor(const Color& color) noexcept { mOutlineColor = color; }
99
101 void SetOutlineWidth(float width) noexcept { mOutlineWidth = width; }
102
104 void SetCapStyle(LineCap cap) noexcept { mCap = cap; }
105
107 void SetJoinStyle(LineJoin join) noexcept { mJoin = join; }
108
109 [[nodiscard]] LineCap GetCapStyle() const noexcept { return mCap; }
110
111 [[nodiscard]] LineJoin GetJoinStyle() const noexcept { return mJoin; }
112
127 void SetDashPattern(std::initializer_list<float> lengths) noexcept {
128 mDashCount = 0;
129 for (float len : lengths) {
130 if (mDashCount >= kMaxDashSegments) {
131 break;
132 }
133 if (len > 0.0F) {
134 mDash[mDashCount++] = len;
135 }
136 }
137 }
138
140 void ClearDashPattern() noexcept { mDashCount = 0; }
141
143 [[nodiscard]] std::size_t GetDashCount() const noexcept { return mDashCount; }
144
146 [[nodiscard]] const std::array<float, kMaxDashSegments>& GetDashPattern()
147 const noexcept {
148 return mDash;
149 }
150
152 [[nodiscard]] bool HasDash() const noexcept { return mDashCount > 0; }
153
155 [[nodiscard]] bool IsVisible() const noexcept {
156 return mColor.a > 0 && mWidth > 0.0F;
157 }
158
160 [[nodiscard]] bool HasOutline() const noexcept {
161 return mOutlineColor.a > 0 && mOutlineWidth > 0.0F;
162 }
163
164 [[nodiscard]] bool operator==(const Pen& other) const noexcept {
165 return mColor == other.mColor && mWidth == other.mWidth &&
166 mOutlineColor == other.mOutlineColor &&
167 mOutlineWidth == other.mOutlineWidth && mCap == other.mCap &&
168 mJoin == other.mJoin && DashEquals(other);
169 }
170 [[nodiscard]] bool operator!=(const Pen& other) const noexcept {
171 return !(*this == other);
172 }
173
175 [[nodiscard]] static Pen NoPen() noexcept {
176 return Pen(Color::Transparent(), 0.0F);
177 }
178
179 private:
180 Color mColor{Color::Black()};
181 float mWidth{1.0F};
182 Color mOutlineColor{Color::Transparent()};
183 float mOutlineWidth{0.0F};
184 // Varsayilanlar mevcut davranisi birebir korur: uc stili yoktu (duz kesik),
185 // birlesim ise daima yuvarlakti. Qt'nin varsayilanlari (square/bevel) farkli
186 // ama onlara gecmek sessizce her cizimin gorunumunu degistirirdi.
187 LineCap mCap{LineCap::kButt};
188 LineJoin mJoin{LineJoin::kRound};
189 std::array<float, kMaxDashSegments> mDash{};
190 std::size_t mDashCount{0};
191
193 [[nodiscard]] bool DashEquals(const Pen& other) const noexcept {
194 if (mDashCount != other.mDashCount) {
195 return false;
196 }
197 for (std::size_t i = 0; i < mDashCount; ++i) {
198 if (mDash[i] != other.mDash[i]) {
199 return false;
200 }
201 }
202 return true;
203 }
204};
205
206} // namespace sdl_painter
Çizgi stili — renk, kalınlık ve isteğe bağlı dış kontur.
Definition pen.h:49
void ClearDashPattern() noexcept
Kesiği kapat — çizgi kesintisiz olur.
Definition pen.h:140
void SetDashPattern(std::initializer_list< float > lengths) noexcept
Kesikli çizgi desenini ayarla.
Definition pen.h:127
const Color & GetOutlineColor() const noexcept
Dış kontur rengini döndür.
Definition pen.h:84
void SetOutlineWidth(float width) noexcept
Dış kontur kalınlığını ayarla.
Definition pen.h:101
bool IsVisible() const noexcept
Kalem görünür mü? (alpha > 0 ve width > 0).
Definition pen.h:155
std::size_t GetDashCount() const noexcept
Desendeki geçerli uzunluk sayısı (0 ise kesik yok).
Definition pen.h:143
void SetWidth(float width) noexcept
Çizgi kalınlığını ayarla.
Definition pen.h:95
void SetJoinStyle(LineJoin join) noexcept
Birleşim stilini ayarla.
Definition pen.h:107
void SetCapStyle(LineCap cap) noexcept
Uç stilini ayarla (yalnızca açık çizgiler için).
Definition pen.h:104
static Pen NoPen() noexcept
Şeffaf (çizim yapmayan) kalem.
Definition pen.h:175
bool HasOutline() const noexcept
Kalemin görünür bir dış konturu var mı?
Definition pen.h:160
Pen(const Color &color, float width=1.0F)
Renk ve kalınlıkla kalem oluştur.
Definition pen.h:57
float GetWidth() const noexcept
Çizgi kalınlığını döndür.
Definition pen.h:81
const std::array< float, kMaxDashSegments > & GetDashPattern() const noexcept
Desen uzunlukları. Yalnızca ilk GetDashCount tanesi anlamlı.
Definition pen.h:146
void SetOutlineColor(const Color &color) noexcept
Dış kontur rengini ayarla.
Definition pen.h:98
bool HasDash() const noexcept
Kalem kesikli mi?
Definition pen.h:152
const Color & GetColor() const noexcept
Çizgi rengini döndür.
Definition pen.h:78
float GetOutlineWidth() const noexcept
Dış kontur kalınlığını döndür.
Definition pen.h:89
void SetColor(const Color &color) noexcept
Çizgi rengini ayarla.
Definition pen.h:92
Pen(const Color &color, float width, const Color &outline_color, float outline_width)
Dış konturlu (outline) kalem oluştur.
Definition pen.h:70
Pen()=default
Varsayılan kalem: siyah, 1 piksel kalınlık.
RGBA renk temsili. Her kanal [0, 255] aralığında.
Definition color.h:8