399 lines
		
	
	
		
			8.8 KiB
		
	
	
	
		
			C++
		
	
	
	
			
		
		
	
	
			399 lines
		
	
	
		
			8.8 KiB
		
	
	
	
		
			C++
		
	
	
	
| // Copyright (c) 2016-2018 Kiwano - Nomango
 | |
| // 
 | |
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | |
| // of this software and associated documentation files (the "Software"), to deal
 | |
| // in the Software without restriction, including without limitation the rights
 | |
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | |
| // copies of the Software, and to permit persons to whom the Software is
 | |
| // furnished to do so, subject to the following conditions:
 | |
| // 
 | |
| // The above copyright notice and this permission notice shall be included in
 | |
| // all copies or substantial portions of the Software.
 | |
| // 
 | |
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | |
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | |
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | |
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | |
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | |
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | |
| // THE SOFTWARE.
 | |
| 
 | |
| #pragma once
 | |
| #include <kiwano/2d/Actor.h>
 | |
| #include <kiwano/renderer/Geometry.h>
 | |
| #include <kiwano/renderer/StrokeStyle.h>
 | |
| 
 | |
| namespace kiwano
 | |
| {
 | |
| 	KGE_DECLARE_SMART_PTR(ShapeActor);
 | |
| 	KGE_DECLARE_SMART_PTR(LineActor);
 | |
| 	KGE_DECLARE_SMART_PTR(RectActor);
 | |
| 	KGE_DECLARE_SMART_PTR(RoundRectActor);
 | |
| 	KGE_DECLARE_SMART_PTR(CircleActor);
 | |
| 	KGE_DECLARE_SMART_PTR(EllipseActor);
 | |
| 	KGE_DECLARE_SMART_PTR(PolygonActor);
 | |
| 	KGE_DECLARE_SMART_PTR(PathActor);
 | |
| 
 | |
| 	/**
 | |
| 	* \addtogroup Actors
 | |
| 	* @{
 | |
| 	*/
 | |
| 
 | |
| 	/**
 | |
| 	* \~chinese
 | |
| 	* @brief ¶þάͼÐνÇÉ«
 | |
| 	*/
 | |
| 	class KGE_API ShapeActor
 | |
| 		: public Actor
 | |
| 	{
 | |
| 	public:
 | |
| 		ShapeActor();
 | |
| 
 | |
| 		ShapeActor(Geometry const& geometry);
 | |
| 
 | |
| 		virtual ~ShapeActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡Ìî³äÑÕÉ«
 | |
| 		Color GetFillColor() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡ÏßÌõÑÕÉ«
 | |
| 		Color GetStrokeColor() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡ÏßÌõ¿í¶È
 | |
| 		float GetStrokeWidth() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡ÏßÌõÑùʽ
 | |
| 		StrokeStyle SetStrokeStyle() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡ÐÎ×´
 | |
| 		Geometry GetGeometry() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡±ß½ç
 | |
| 		Rect GetBounds() const override;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡ÍâÇаüΧºÐ
 | |
| 		Rect GetBoundingBox() const override;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÅжϵãÊÇ·ñÔÚÐÎ×´ÄÚ
 | |
| 		bool ContainsPoint(const Point& point) const override;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÌî³äÑÕÉ«
 | |
| 		void SetFillColor(const Color& color);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÏßÌõÑÕÉ«
 | |
| 		void SetStrokeColor(const Color& color);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÏßÌõ¿í¶È£¬Ä¬ÈÏΪ 1.0
 | |
| 		void SetStrokeWidth(float width);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÏßÌõÑùʽ
 | |
| 		void SetStrokeStyle(StrokeStyle stroke_style);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖü¸ºÎÐÎ×´
 | |
| 		void SetGeometry(Geometry const& geometry);
 | |
| 
 | |
| 		void OnRender(RenderTarget* rt) override;
 | |
| 
 | |
| 	private:
 | |
| 		Color		fill_color_;
 | |
| 		Color		stroke_color_;
 | |
| 		float		stroke_width_;
 | |
| 		StrokeStyle	stroke_style_;
 | |
| 		Rect		bounds_;
 | |
| 		Geometry	geo_;
 | |
| 	};
 | |
| 
 | |
| 
 | |
| 	/// \~chinese
 | |
| 	/// @brief Ïß¶ÎͼÐνÇÉ«
 | |
| 	class KGE_API LineActor
 | |
| 		: public ShapeActor
 | |
| 	{
 | |
| 	public:
 | |
| 		LineActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief Ïß¶ÎͼÐνÇÉ«
 | |
| 		/// @param begin Ïß¶ÎÆðµã
 | |
| 		/// @param end Ïß¶ÎÖÕµã
 | |
| 		LineActor(Point const& begin, Point const& end);
 | |
| 
 | |
| 		virtual ~LineActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡Ïß¶ÎÆðµã
 | |
| 		Point const& GetBeginPoint() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡Ïß¶ÎÖÕµã
 | |
| 		Point const& GetEndPoint() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÏß¶ÎÆðµã
 | |
| 		/// @param begin Ïß¶ÎÆðµã
 | |
| 		void SetBeginPoint(Point const& begin);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÏß¶ÎÖÕµã
 | |
| 		/// @param end Ïß¶ÎÖÕµã
 | |
| 		void SetEndPoint(Point const& end);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖþØÐδóС
 | |
| 		/// @param begin Ïß¶ÎÆðµã
 | |
| 		/// @param end Ïß¶ÎÖÕµã
 | |
| 		void SetLine(Point const& begin, Point const& end);
 | |
| 
 | |
| 	private:
 | |
| 		Point begin_;
 | |
| 		Point end_;
 | |
| 	};
 | |
| 
 | |
| 
 | |
| 	/// \~chinese
 | |
| 	/// @brief ¾ØÐνÇÉ«
 | |
| 	class KGE_API RectActor
 | |
| 		: public ShapeActor
 | |
| 	{
 | |
| 	public:
 | |
| 		RectActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ¹¹Ôì¾ØÐνÇÉ«
 | |
| 		/// @param size ¾ØÐδóС
 | |
| 		RectActor(Size const& size);
 | |
| 
 | |
| 		virtual ~RectActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡¾ØÐδóС
 | |
| 		Size const& GetRectSize() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖþØÐδóС
 | |
| 		/// @param size ¾ØÐδóС
 | |
| 		void SetRectSize(Size const& size);
 | |
| 
 | |
| 	private:
 | |
| 		Size rect_size_;
 | |
| 	};
 | |
| 
 | |
| 
 | |
| 
 | |
| 	/// \~chinese
 | |
| 	/// @brief Ô²½Ç¾ØÐνÇÉ«
 | |
| 	class KGE_API RoundRectActor
 | |
| 		: public ShapeActor
 | |
| 	{
 | |
| 	public:
 | |
| 		RoundRectActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ¹¹ÔìÔ²½Ç¾ØÐνÇÉ«
 | |
| 		/// @param size Ô²½Ç¾ØÐδóС
 | |
| 		/// @param radius Ô²½Ç°ë¾¶
 | |
| 		RoundRectActor(Size const& size, Vec2 const& radius);
 | |
| 
 | |
| 		virtual ~RoundRectActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñȡԲ½Ç°ë¾¶
 | |
| 		Vec2 GetRadius() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñȡԲ½Ç¾ØÐδóС
 | |
| 		Size GetRectSize() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÔ²½Ç°ë¾¶
 | |
| 		/// @param radius Ô²½Ç°ë¾¶
 | |
| 		void SetRadius(Vec2 const& radius);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÔ²½Ç¾ØÐδóС
 | |
| 		/// @param size Ô²½Ç¾ØÐδóС
 | |
| 		void SetRectSize(Size const& size);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÔ²½Ç¾ØÐÎ
 | |
| 		/// @param size Ô²½Ç¾ØÐδóС
 | |
| 		/// @param radius Ô²½Ç°ë¾¶
 | |
| 		void SetRoundedRect(Size const& size, Vec2 const& radius);
 | |
| 
 | |
| 	private:
 | |
| 		Size rect_size_;
 | |
| 		Vec2 radius_;
 | |
| 	};
 | |
| 
 | |
| 
 | |
| 	/// \~chinese
 | |
| 	/// @brief Ô²ÐνÇÉ«
 | |
| 	class KGE_API CircleActor
 | |
| 		: public ShapeActor
 | |
| 	{
 | |
| 	public:
 | |
| 		CircleActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ¹¹ÔìÔ²ÐνÇÉ«
 | |
| 		/// @param radius Ô²Ðΰ뾶
 | |
| 		CircleActor(float radius);
 | |
| 
 | |
| 		virtual ~CircleActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñȡԲÐΰ뾶
 | |
| 		float GetRadius() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÔ²Ðΰ뾶
 | |
| 		/// @param radius Ô²Ðΰ뾶
 | |
| 		void SetRadius(float radius);
 | |
| 
 | |
| 	private:
 | |
| 		float radius_;
 | |
| 	};
 | |
| 
 | |
| 
 | |
| 	/// \~chinese
 | |
| 	/// @brief ÍÖÔ²½ÇÉ«
 | |
| 	class KGE_API EllipseActor
 | |
| 		: public ShapeActor
 | |
| 	{
 | |
| 	public:
 | |
| 		EllipseActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ¹¹ÔìÍÖÔ²½ÇÉ«
 | |
| 		/// @param radius ÍÖÔ²°ë¾¶
 | |
| 		EllipseActor(Vec2 const& radius);
 | |
| 
 | |
| 		virtual ~EllipseActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief »ñÈ¡ÍÖÔ²°ë¾¶
 | |
| 		Vec2 GetRadius() const;
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖÃÍÖÔ²°ë¾¶
 | |
| 		/// @param radius ÍÖÔ²°ë¾¶
 | |
| 		void SetRadius(Vec2 const& radius);
 | |
| 
 | |
| 	private:
 | |
| 		Vec2 radius_;
 | |
| 	};
 | |
| 
 | |
| 
 | |
| 	/// \~chinese
 | |
| 	/// @brief ¶à±ßÐνÇÉ«
 | |
| 	class KGE_API PolygonActor
 | |
| 		: public ShapeActor
 | |
| 	{
 | |
| 	public:
 | |
| 		PolygonActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ¹¹Ôì¶à±ßÐνÇÉ«
 | |
| 		/// @param points ¶à±ßÐζ˵㼯ºÏ
 | |
| 		PolygonActor(Vector<Point> const& points);
 | |
| 
 | |
| 		virtual ~PolygonActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ÉèÖöà±ßÐζ˵ã
 | |
| 		/// @param points ¶à±ßÐζ˵㼯ºÏ
 | |
| 		void SetVertices(Vector<Point> const& points);
 | |
| 	};
 | |
| 
 | |
| 
 | |
| 	/// \~chinese
 | |
| 	/// @brief ·¾¶Í¼ÐνÇÉ«
 | |
| 	class KGE_API PathActor
 | |
| 		: public ShapeActor
 | |
| 	{
 | |
| 	public:
 | |
| 		PathActor();
 | |
| 
 | |
| 		virtual ~PathActor();
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ¿ªÊ¼Ìí¼Ó·¾¶
 | |
| 		/// @param begin_pos Æðʼµã
 | |
| 		void BeginPath(Point const& begin_pos = Point());
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief ½áÊøÌí¼Ó·¾¶
 | |
| 		/// @param closed ·¾¶ÊÇ·ñ±ÕºÏ
 | |
| 		void EndPath(bool closed = true);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief Ìí¼ÓÒ»ÌõÏß¶Î
 | |
| 		/// @param point Ï߶ζ˵ã
 | |
| 		void AddLine(Point const& point);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief Ìí¼Ó¶àÌõÏß¶Î
 | |
| 		/// @param points Ï߶ζ˵㼯ºÏ
 | |
| 		void AddLines(Vector<Point> const& points);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief Ìí¼ÓÒ»ÌõÈý´Î·½±´Èû¶ûÇúÏß
 | |
| 		/// @param point1 ±´Èû¶ûÇúÏߵĵÚÒ»¸ö¿ØÖƵã
 | |
| 		/// @param point2 ±´Èû¶ûÇúÏߵĵڶþ¸ö¿ØÖƵã
 | |
| 		/// @param point3 ±´Èû¶ûÇúÏßµÄÖÕµã
 | |
| 		void AddBezier(Point const& point1, Point const& point2, Point const& point3);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief Ìí¼Ó»¡Ïß
 | |
| 		/// @param point ÍÖÔ²Ô²ÐÄ
 | |
| 		/// @param radius ÍÖÔ²°ë¾¶
 | |
| 		/// @param rotation ÍÖÔ²Ðýת½Ç¶È
 | |
| 		/// @param clockwise ˳ʱÕë or ÄæÊ±Õë
 | |
| 		/// @param is_small ÊÇ·ñȡСÓÚ 180¡ã µÄ»¡
 | |
| 		void AddArc(Point const& point, Size const& radius, float rotation, bool clockwise = true, bool is_small = true);
 | |
| 
 | |
| 		/// \~chinese
 | |
| 		/// @brief Çå³ý·¾¶
 | |
| 		void ClearPath();
 | |
| 
 | |
| 	private:
 | |
| 		GeometrySink sink_;
 | |
| 	};
 | |
| 
 | |
| 	/** @} */
 | |
| 	
 | |
| 
 | |
| 	inline Color		ShapeActor::GetFillColor() const				{ return fill_color_; }
 | |
| 	inline Color		ShapeActor::GetStrokeColor() const				{ return stroke_color_; }
 | |
| 	inline float		ShapeActor::GetStrokeWidth() const				{ return stroke_width_; }
 | |
| 	inline StrokeStyle	ShapeActor::SetStrokeStyle() const				{ return stroke_style_; }
 | |
| 	inline Geometry		ShapeActor::GetGeometry() const					{ return geo_; }
 | |
| 
 | |
| 	inline Point const& LineActor::GetBeginPoint() const				{ return begin_; }
 | |
| 	inline Point const& LineActor::GetEndPoint() const					{ return end_; }
 | |
| 	inline void			LineActor::SetBeginPoint(Point const& begin)	{ SetLine(begin, end_); }
 | |
| 	inline void			LineActor::SetEndPoint(Point const& end)		{ SetLine(begin_, end); }
 | |
| 
 | |
| 	inline Size const&	RectActor::GetRectSize() const					{ return rect_size_; }
 | |
| 
 | |
| 	inline Vec2			RoundRectActor::GetRadius() const				{ return radius_; }
 | |
| 	inline Size			RoundRectActor::GetRectSize() const				{ return GetSize(); }
 | |
| 
 | |
| 	inline float		CircleActor::GetRadius() const					{ return radius_; }
 | |
| 
 | |
| 	inline Vec2			EllipseActor::GetRadius() const					{ return radius_; }
 | |
| }
 |