232 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			C++
		
	
	
	
			
		
		
	
	
			232 lines
		
	
	
		
			4.3 KiB
		
	
	
	
		
			C++
		
	
	
	
| // Copyright (c) 2016-2018 Easy2D - 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 "Node.h"
 | |
| #include "Font.hpp"
 | |
| #include "TextStyle.hpp"
 | |
| #include "TextRenderer.h"
 | |
| 
 | |
| #undef DrawText
 | |
| 
 | |
| namespace easy2d
 | |
| {
 | |
| 	// »²¼
 | |
| 	class Canvas
 | |
| 		: public Node
 | |
| 	{
 | |
| 	public:
 | |
| 		Canvas();
 | |
| 
 | |
| 		Canvas(
 | |
| 			Size const& size
 | |
| 		);
 | |
| 
 | |
| 		Canvas(
 | |
| 			float width,
 | |
| 			float height
 | |
| 		);
 | |
| 
 | |
| 		virtual ~Canvas();
 | |
| 
 | |
| 		// ¿ªÊ¼»æÍ¼
 | |
| 		void BeginDraw();
 | |
| 
 | |
| 		// ½áÊø»æÍ¼
 | |
| 		void EndDraw();
 | |
| 
 | |
| 		// »Ö±Ïß
 | |
| 		void DrawLine(
 | |
| 			const Point& begin,
 | |
| 			const Point& end
 | |
| 		);
 | |
| 
 | |
| 		// »Ô²Ðα߿ò
 | |
| 		void DrawCircle(
 | |
| 			const Point& center,
 | |
| 			float radius
 | |
| 		);
 | |
| 
 | |
| 		// »ÍÖÔ²Ðα߿ò
 | |
| 		void DrawEllipse(
 | |
| 			const Point& center,
 | |
| 			float radius_x,
 | |
| 			float radius_y
 | |
| 		);
 | |
| 
 | |
| 		// »¾ØÐα߿ò
 | |
| 		void DrawRect(
 | |
| 			const Rect& rect
 | |
| 		);
 | |
| 
 | |
| 		// »Ô²½Ç¾ØÐα߿ò
 | |
| 		void DrawRoundedRect(
 | |
| 			const Rect& rect,
 | |
| 			float radius_x,
 | |
| 			float radius_y
 | |
| 		);
 | |
| 
 | |
| 		// »Í¼Æ¬
 | |
| 		void DrawImage(
 | |
| 			spImage const& image,
 | |
| 			float opacity = 1.f
 | |
| 		);
 | |
| 
 | |
| 		// »ÎÄ×Ö
 | |
| 		void DrawText(
 | |
| 			String const& text,		/* ÎÄ×Ö */
 | |
| 			Point const& point		/* ÎÄ×ÖλÖà */
 | |
| 		);
 | |
| 
 | |
| 		// »¼¸ºÎͼÐα߿ò
 | |
| 		void DrawGeometry(
 | |
| 			spGeometry const& geo
 | |
| 		);
 | |
| 
 | |
| 		// Ìî³äÔ²ÐÎ
 | |
| 		void FillCircle(
 | |
| 			const Point& center,
 | |
| 			float radius
 | |
| 		);
 | |
| 
 | |
| 		// Ìî³äÍÖÔ²ÐÎ
 | |
| 		void FillEllipse(
 | |
| 			const Point& center,
 | |
| 			float radius_x,
 | |
| 			float radius_y
 | |
| 		);
 | |
| 
 | |
| 		// Ìî³ä¾ØÐÎ
 | |
| 		void FillRect(
 | |
| 			const Rect& rect
 | |
| 		);
 | |
| 
 | |
| 		// Ìî³äÔ²½Ç¾ØÐÎ
 | |
| 		void FillRoundedRect(
 | |
| 			const Rect& rect,
 | |
| 			float radius_x,
 | |
| 			float radius_y
 | |
| 		);
 | |
| 
 | |
| 		// Ìî³ä¼¸ºÎͼÐÎ
 | |
| 		void FillGeometry(
 | |
| 			spGeometry const& geo
 | |
| 		);
 | |
| 
 | |
| 		// ¿ªÊ¼»æÖÆÂ·¾¶
 | |
| 		void BeginPath(
 | |
| 			Point const& begin_pos	/* ·¾¶Æðʼµã */
 | |
| 		);
 | |
| 
 | |
| 		// ½áÊøÂ·¾¶
 | |
| 		void EndPath(
 | |
| 			bool closed = true		/* ·¾¶ÊÇ·ñ±ÕºÏ */
 | |
| 		);
 | |
| 
 | |
| 		// Ìí¼ÓÒ»ÌõÏß¶Î
 | |
| 		void AddLine(
 | |
| 			Point const& point		/* ¶Ëµã */
 | |
| 		);
 | |
| 
 | |
| 		// Ìí¼Ó¶àÌõÏß¶Î
 | |
| 		void AddLines(
 | |
| 			std::vector<Point> const& points
 | |
| 		);
 | |
| 
 | |
| 		// Ìí¼ÓÒ»ÌõÈý´Î·½±´Èû¶ûÇúÏß
 | |
| 		void AddBezier(
 | |
| 			Point const& point1,	/* ±´Èû¶ûÇúÏߵĵÚÒ»¸ö¿ØÖƵã */
 | |
| 			Point const& point2,	/* ±´Èû¶ûÇúÏߵĵڶþ¸ö¿ØÖƵã */
 | |
| 			Point const& point3		/* ±´Èû¶ûÇúÏßµÄÖÕµã */
 | |
| 		);
 | |
| 
 | |
| 		// ·¾¶Ãè±ß
 | |
| 		void StrokePath();
 | |
| 
 | |
| 		// ·¾¶Ìî³ä
 | |
| 		void FillPath();
 | |
| 
 | |
| 		// Çå¿Õ»²¼
 | |
| 		void Clear();
 | |
| 
 | |
| 		// ÉèÖÃÌî³äÑÕÉ«
 | |
| 		void SetFillColor(
 | |
| 			const Color& color
 | |
| 		);
 | |
| 
 | |
| 		// ÉèÖÃÏßÌõÑÕÉ«
 | |
| 		void SetStrokeColor(
 | |
| 			const Color& color
 | |
| 		);
 | |
| 
 | |
| 		// ÉèÖÃÏßÌõ¿í¶È
 | |
| 		void SetStrokeWidth(
 | |
| 			float width
 | |
| 		);
 | |
| 
 | |
| 		// ÉèÖÃÏßÌõÏཻÑùʽ
 | |
| 		void SetOutlineJoinStyle(
 | |
| 			StrokeStyle outline_join
 | |
| 		);
 | |
| 
 | |
| 		// ÉèÖÃÎÄ×ֻˢÑùʽ
 | |
| 		void SetTextStyle(
 | |
| 			Font const& font,
 | |
| 			TextStyle const& text_style
 | |
| 		);
 | |
| 
 | |
| 		// »ñÈ¡Ìî³äÑÕÉ«
 | |
| 		Color GetFillColor() const;
 | |
| 
 | |
| 		// »ñÈ¡ÏßÌõÑÕÉ«
 | |
| 		Color GetStrokeColor() const;
 | |
| 
 | |
| 		// »ñÈ¡ÏßÌõ¿í¶È
 | |
| 		float GetStrokeWidth() const;
 | |
| 
 | |
| 		// ±ä»»»±Ê
 | |
| 		void SetBrushTransform(
 | |
| 			math::Matrix const& transform
 | |
| 		);
 | |
| 
 | |
| 		// µ¼³öΪͼƬ
 | |
| 		spImage ExportToImage() const;
 | |
| 
 | |
| 		virtual void OnDraw() override;
 | |
| 
 | |
| 	protected:
 | |
| 		cpBitmap const& GetBitmap() const;
 | |
| 
 | |
| 	protected:
 | |
| 		mutable bool			cache_expired_;
 | |
| 		mutable cpBitmap		bitmap_cached_;
 | |
| 		float					stroke_width_;
 | |
| 		Font					text_font_;
 | |
| 		TextStyle				text_style_;
 | |
| 		cpPathGeometry			current_geometry_;
 | |
| 		cpGeometrySink			current_sink_;
 | |
| 		cpStrokeStyle			outline_join_style_;
 | |
| 		cpSolidColorBrush		fill_brush_;
 | |
| 		cpSolidColorBrush		stroke_brush_;
 | |
| 		cpSolidColorBrush		text_brush_;
 | |
| 		cpTextRenderer			text_renderer_;
 | |
| 		cpBitmapRenderTarget	render_target_;
 | |
| 	};
 | |
| } |