3 Commits 287303a3f5 ... 80573a08c2

Author SHA1 Message Date
  namark 80573a08c2 Fixed ambiguity due to geom::vector implicit conversions, 5 months ago
  namark 0cf877f247 Small improvements and a bunch of TODOs. 5 months ago
  namark b8420f53bf Accessor for window flags. 5 months ago

+ 1 - 1
examples/09_texture.cpp

@@ -43,7 +43,7 @@ int main(int argc, char const* argv[]) try
 		auto pixels = std::get<pixel_writer<rgba_pixel, pixel_byte>>(pixels_variant);
 		for(int2 p{}; p < pixels.size(); ++p.y(), p.x() = 0)
 		for(; p < pixels.size(); p += int2::i())
-			pixels.set( rgb_pixel(rgb_vector(
+			pixels.set( rgba_pixel(rgb_vector(
 							( (float2)p /(float2)pixels.size() ).xyz(blue) )), p );
 	};
 

+ 1 - 1
examples/10_opengl.cpp

@@ -37,5 +37,5 @@ catch(...)
 }
 
 #else
-int main() { std::puts("Example not enabled!"); return 0; }
+int main() { std::puts("Example not enabled! Set ENABLE_OPENGL_EXAMPLES to enable."); return 0; }
 #endif

+ 1 - 1
examples/11_nanovg.cpp

@@ -149,5 +149,5 @@ void black_ball_sketch::draw(NVGcontext* vg)
 }
 
 #else
-int main() { std::puts("Example not enabled!"); return 0; }
+int main() { std::puts("Example not enabled! Set ENABLE_OPENGL_EXAMPLES to enable."); return 0; }
 #endif

+ 1 - 2
examples/13_draw_line.cpp

@@ -148,8 +148,7 @@ void bresenham_line(line<int2> line, rgb_pixels pixels, rgb_pixel value)
 
 void xiaolin_wu_line(line<int2> line, rgb_pixels pixels, rgb_pixel value)
 {
-	using rational = rational<int>;
-	bresenham_line(line, [&pixels, &value](int2 position, rational ratio)
+	bresenham_line(line, [&pixels, &value](int2 position, rational<int> ratio)
 	{
 		const auto blended = value.transformed([&ratio](auto color)
 			{ return rgb_pixel::coordinate_type(int(color * ratio)); });

+ 2 - 1
examples/bonus_04_inversion.cpp

@@ -44,7 +44,8 @@ enum class commands
 	// TODO:
 	// zoom,
 	// size(window),
-	// view(current state),
+	// view(current state), // present me: what? I prosume this print current params
+	// markers [on/off], // visual markers for center and radius
 	// resolution?,
 	save,
 	commit,

+ 4 - 1
source/simple/graphical/color_vector.hpp

@@ -8,7 +8,7 @@
 namespace simple::graphical
 {
 
-	// TODO: this is to customize for YUV so this really needs to return a vector not just a number
+	// TODO: this really needs to return a vector not just a number, for individual limits per component
 	// better to support both probably
 	template <typename T>
 	class default_color_limits
@@ -23,6 +23,7 @@ namespace simple::graphical
 		}
 	};
 
+	// TODO: rename to rgb_vector, with some generaliztions in vector might even be able to squezze sub byte types here (like rgb565), but things like yuv will need their own type.
 	template<typename Type, size_t Size, typename RGBA_Order = std::make_index_sequence<Size>, typename Limits = default_color_limits<Type>,
 	std::enable_if_t<Size == 3 || Size == 4>* = nullptr>
 	struct color_vector : public geom::vector<Type, Size, RGBA_Order>
@@ -34,6 +35,7 @@ namespace simple::graphical
 			return Limits::get();
 		}
 
+		// FIXME: got to somehow disable implicit convertions inherited from vector
 		using base::base;
 
 		// TODO: workaround for clang bug, that prevents inheriting the default constructor
@@ -156,6 +158,7 @@ namespace simple::graphical
 
 	};
 
+	// TODO: rename to rgb[a]_byte, rgb[a]_float
 	using rgb_pixel = color_vector<uint8_t, 3>;
 	using rgba_pixel = color_vector<uint8_t, 4>;
 	using rgb_vector = color_vector<float, 3>;

+ 8 - 0
source/simple/graphical/initializer.h

@@ -7,6 +7,7 @@
 namespace simple::graphical
 {
 
+	// in general we want this class to not exist and library initialization to be unnecessary
 	class initializer : private sdlcore::initializer
 	{
 		private:
@@ -23,12 +24,19 @@ namespace simple::graphical
 			[[nodiscard]] static bool global_kept_alive() noexcept;
 			private:
 			int keep_alive_count;
+			// TODO: make the global state atomic maybe?
 			static int global_keep_alive_count;
 		};
 
 		public:
 		initializer();
+
+		// the main reason this is here is to change SDL's default by enabling screensaver in the constructor, which SDL just disables, cause idk, it's a game?
+		// in contrast to doing it in initializer constructor without the global state, it's impervious to library reinitialization, goes with our theme of pretending that it doesn't exist
+		// TODO: all the counting stuff is a bit dubious though, it's a generic thing akin to reference counting, so doesn't feel right to bake it into this API
 		screensaver_control screensaver;
+
+		// TODO: no point in this being member though
 		display_list displays() const noexcept;
 	};
 

+ 5 - 0
source/simple/graphical/pixels.h

@@ -73,6 +73,7 @@ namespace simple::graphical
 			int2 size() const noexcept;
 
 			// TODO: proper row_iterator interface?
+			// TODO: simple::geom::iterator/vectirator interface
 			raw_type* row(int index = 0) const noexcept;
 
 			raw_type* row_offset(raw_type* row, int offset = 1) const noexcept;
@@ -129,6 +130,10 @@ namespace simple::graphical
 		PixelView<rgba_pixel, pixel_byte> // 4 bytes per pixel
 	>;
 
+	static_assert(sizeof(rgb_pixel) == sizeof(rgb_pixel::value_type) * rgb_pixel::dimensions);
+	static_assert(sizeof(rgba_pixel) == sizeof(rgba_pixel::value_type) * rgba_pixel::dimensions);
+	static_assert(sizeof(uint16_t) == sizeof(pixel_byte) * 2);
+
 	template<typename Pixel, typename RawType = Pixel>
 	class pixel_writer :
 		public pixel_view_details::impl<pixel_view_details::tag::writer, Pixel, RawType>

+ 5 - 0
source/simple/graphical/window.cpp

@@ -103,6 +103,11 @@ namespace simple::graphical
 		SDL_MaximizeWindow(guts().get());
 	}
 
+	window::flags window::state() const noexcept
+	{
+		return static_cast<flags>(SDL_GetWindowFlags(guts().get()));
+	}
+
 	uint32_t window::id() const noexcept
 	{
 		return SDL_GetWindowID(guts().get());

+ 0 - 0
source/simple/graphical/window.h


Some files were not shown because too many files changed in this diff