3#include "sdl_painter/color.h"
8#include <initializer_list>
10namespace sdl_painter {
17enum class LineCap : uint8_t {
27enum class LineJoin : uint8_t {
38inline constexpr float kMiterLimit = 4.0F;
46inline constexpr std::size_t kMaxDashSegments = 8;
57 explicit Pen(
const Color& color,
float width = 1.0F)
58 : mColor(color), mWidth(width) {}
74 mOutlineColor(outline_color),
75 mOutlineWidth(outline_width) {}
81 [[nodiscard]]
float GetWidth() const noexcept {
return mWidth; }
95 void SetWidth(
float width)
noexcept { mWidth = width > 0.0F ? width : 0.0F; }
109 [[nodiscard]] LineCap GetCapStyle() const noexcept {
return mCap; }
111 [[nodiscard]] LineJoin GetJoinStyle() const noexcept {
return mJoin; }
129 for (
float len : lengths) {
130 if (mDashCount >= kMaxDashSegments) {
134 mDash[mDashCount++] = len;
143 [[nodiscard]] std::size_t
GetDashCount() const noexcept {
return mDashCount; }
152 [[nodiscard]]
bool HasDash() const noexcept {
return mDashCount > 0; }
156 return mColor.a > 0 && mWidth > 0.0F;
161 return mOutlineColor.a > 0 && mOutlineWidth > 0.0F;
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);
170 [[nodiscard]]
bool operator!=(
const Pen& other)
const noexcept {
171 return !(*
this == other);
176 return Pen(Color::Transparent(), 0.0F);
180 Color mColor{Color::Black()};
182 Color mOutlineColor{Color::Transparent()};
183 float mOutlineWidth{0.0F};
187 LineCap mCap{LineCap::kButt};
188 LineJoin mJoin{LineJoin::kRound};
189 std::array<float, kMaxDashSegments> mDash{};
190 std::size_t mDashCount{0};
193 [[nodiscard]]
bool DashEquals(
const Pen& other)
const noexcept {
194 if (mDashCount != other.mDashCount) {
197 for (std::size_t i = 0; i < mDashCount; ++i) {
198 if (mDash[i] != other.mDash[i]) {
Ç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