From ea7eb94283f21c9cf86a7185a5face72520668c3 Mon Sep 17 00:00:00 2001
From: namark <namark@disroot.org>
Date: Sat, 12 Oct 2019 15:05:49 +0400
Subject: [PATCH] nanovg radial gradient wrappers and some TODOs.

---
 common/simple_vg.cpp | 25 +++++++++++++++++++++++++
 common/simple_vg.h   | 24 ++++++++++++++++++++----
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/common/simple_vg.cpp b/common/simple_vg.cpp
index 5c4ecd8..047cb8a 100644
--- a/common/simple_vg.cpp
+++ b/common/simple_vg.cpp
@@ -54,6 +54,19 @@ frame::frame(NVGcontext* context, float2 size, float pixelRatio) noexcept :
 	nvgBeginFrame(context, size.x(), size.y(), pixelRatio);
 }
 
+paint::paint(NVGpaint raw) noexcept : raw(raw) {}
+
+paint paint::radial_gradient(float2 center, rangef radius, support::range<rgba_vector> color) noexcept
+{
+	// sneaky nanovg you don't neeed a constext for thiiis
+	return paint(nvgRadialGradient(nullptr,
+		center.x(), center.y(),
+		radius.lower(), radius.upper(),
+		nvgRGBAf(color.lower().r(), color.lower().g(), color.lower().b(), color.lower().a()),
+		nvgRGBAf(color.upper().r(), color.upper().g(), color.upper().b(), color.upper().a())
+	));
+}
+
 frame::frame(frame&& other) noexcept :
 	size(other.size),
 	pixelRatio(other.pixelRatio),
@@ -131,6 +144,12 @@ sketch& sketch::arc(float2 center, rangef angle, float radius) noexcept
 	return *this;
 }
 
+sketch& sketch::fill(const paint& paint) noexcept
+{
+	nvgFillPaint(context, paint.raw);
+	return fill();
+}
+
 sketch& sketch::fill(const rgba_vector& color) noexcept
 {
 	nvgFillColor(context, nvgRGBAf(color.r(), color.g(), color.b(), color.a()));
@@ -172,6 +191,12 @@ sketch& sketch::miter_limit(float limit) noexcept
 	return *this;
 }
 
+sketch& sketch::outline(const paint& paint) noexcept
+{
+	nvgStrokePaint(context, paint.raw);
+	return outline();
+}
+
 sketch& sketch::outline(const rgba_vector& color) noexcept
 {
 	nvgStrokeColor(context, nvgRGBAf(color.r(), color.g(), color.b(), color.a()));
diff --git a/common/simple_vg.h b/common/simple_vg.h
index a44e2ed..41eb6be 100644
--- a/common/simple_vg.h
+++ b/common/simple_vg.h
@@ -20,6 +20,19 @@ namespace simple::vg
 	using rect2f = geom::segment<float2>;
 	using anchored_rect2f = geom::anchored_segment<float2>;
 
+	class paint
+	{
+		NVGpaint raw;
+		paint(NVGpaint) noexcept;
+
+		public:
+		paint() = delete;
+		static paint radial_gradient(float2 center, rangef radius, support::range<rgba_vector>) noexcept;
+		static paint linear_gradient() noexcept; // TODO
+		static paint range_gradient() noexcept; // TODO
+		friend class sketch;
+	};
+
 	class frame;
 
 	class canvas
@@ -92,16 +105,19 @@ namespace simple::vg
 			sketch& rectangle(const range2f&) noexcept;
 			sketch& line(float2 from, float2 to) noexcept;
 			sketch& arc(float2 center, rangef angle, float radius) noexcept;
+			sketch& arc(float2 center, float2 radius, float tau_factor, float anchor = 0) noexcept; // TODO
 
-			sketch& fill(const rgba_vector& color) noexcept;
-			sketch& fill(const rgba_pixel& color) noexcept;
+			sketch& fill(const paint&) noexcept;
+			sketch& fill(const rgba_vector&) noexcept;
+			sketch& fill(const rgba_pixel&) noexcept;
 			sketch& fill() noexcept;
 			sketch& line_cap(cap) noexcept;
 			sketch& line_join(join) noexcept;
 			sketch& line_width(float) noexcept;
 			sketch& miter_limit(float) noexcept;
-			sketch& outline(const rgba_vector& color) noexcept;
-			sketch& outline(const rgba_pixel& color) noexcept;
+			sketch& outline(const paint&) noexcept;
+			sketch& outline(const rgba_vector&) noexcept;
+			sketch& outline(const rgba_pixel&) noexcept;
 			sketch& outline() noexcept;
 
 			sketch(const sketch&) = delete;
-- 
GitLab