| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2022-12-11 22:09:57 +02:00
										 |  |  |  * Canvas.h, part of VCMI engine | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Authors: listed in file AUTHORS in main folder | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * License: GNU General Public License v2.0 or later | 
					
						
							|  |  |  |  * Full text of license available in license.txt file, in main folder | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | #include "Geometries.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-25 16:32:23 +02:00
										 |  |  | struct SDL_Color; | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | struct SDL_Surface; | 
					
						
							|  |  |  | class IImage; | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | enum EFonts : int; | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /// Class that represents surface for drawing on
 | 
					
						
							| 
									
										
										
										
											2022-12-11 22:09:57 +02:00
										 |  |  | class Canvas | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	SDL_Surface * surface; | 
					
						
							| 
									
										
										
										
											2022-12-11 22:09:57 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	Canvas & operator = (Canvas & other) = delete; | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/// constructs canvas using existing surface. Caller maintains ownership on the surface
 | 
					
						
							| 
									
										
										
										
											2022-12-11 22:09:57 +02:00
										 |  |  | 	Canvas(SDL_Surface * surface); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/// copy contructor
 | 
					
						
							|  |  |  | 	Canvas(Canvas & other); | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	/// constructs canvas of specified size
 | 
					
						
							| 
									
										
										
										
											2022-12-11 22:09:57 +02:00
										 |  |  | 	Canvas(const Point & size); | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-11 22:09:57 +02:00
										 |  |  | 	~Canvas(); | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-27 22:50:18 +02:00
										 |  |  | 	/// renders image onto this canvas at specified position
 | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | 	void draw(std::shared_ptr<IImage> image, const Point & pos); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-27 22:50:18 +02:00
										 |  |  | 	/// renders section of image bounded by sourceRect at specified position
 | 
					
						
							|  |  |  | 	void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-14 12:04:37 +02:00
										 |  |  | 	/// renders section of image bounded by sourceRect at specified position at specific transparency value
 | 
					
						
							|  |  |  | 	void draw(std::shared_ptr<IImage> image, const Point & pos, const Rect & sourceRect, uint8_t alpha); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	/// renders another canvas onto this canvas
 | 
					
						
							| 
									
										
										
										
											2022-12-11 22:09:57 +02:00
										 |  |  | 	void draw(Canvas & image, const Point & pos); | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	/// renders continuous, 1-pixel wide line with color gradient
 | 
					
						
							| 
									
										
										
										
											2022-11-25 16:32:23 +02:00
										 |  |  | 	void drawLine(const Point & from, const Point & dest, const SDL_Color & colorFrom, const SDL_Color & colorDest); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-26 23:12:20 +02:00
										 |  |  | 	/// renders single line of text with specified parameters
 | 
					
						
							|  |  |  | 	void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::string & text ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/// renders multiple lines of text with specified parameters
 | 
					
						
							|  |  |  | 	void drawText(const Point & position, const EFonts & font, const SDL_Color & colorDest, ETextAlignment alignment, const std::vector<std::string> & text ); | 
					
						
							| 
									
										
										
										
											2022-11-25 11:46:47 +02:00
										 |  |  | }; |