| 
									
										
										
										
											2020-04-06 11:09:01 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/RefCounted.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-12 19:22:42 +02:00
										 |  |  | #include <LibGfx/AffineTransform.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  | #include <LibGfx/Color.h>
 | 
					
						
							|  |  |  | #include <LibGfx/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-16 21:06:03 +02:00
										 |  |  | #include <LibGfx/Path.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  | #include <LibWeb/Bindings/Wrappable.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CanvasRenderingContext2D | 
					
						
							|  |  |  |     : public RefCounted<CanvasRenderingContext2D> | 
					
						
							|  |  |  |     , public Bindings::Wrappable { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D); | 
					
						
							|  |  |  |     AK_MAKE_NONMOVABLE(CanvasRenderingContext2D); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     using WrapperType = Bindings::CanvasRenderingContext2DWrapper; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static NonnullRefPtr<CanvasRenderingContext2D> create(HTMLCanvasElement& element) { return adopt(*new CanvasRenderingContext2D(element)); } | 
					
						
							|  |  |  |     ~CanvasRenderingContext2D(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void set_fill_style(String); | 
					
						
							|  |  |  |     String fill_style() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 01:09:17 -07:00
										 |  |  |     void set_stroke_style(String); | 
					
						
							|  |  |  |     String stroke_style() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 11:22:40 +02:00
										 |  |  |     void fill_rect(float x, float y, float width, float height); | 
					
						
							|  |  |  |     void stroke_rect(float x, float y, float width, float height); | 
					
						
							| 
									
										
										
										
											2020-04-14 20:38:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void draw_image(const HTMLImageElement&, float x, float y); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 11:22:40 +02:00
										 |  |  |     void scale(float sx, float sy); | 
					
						
							|  |  |  |     void translate(float x, float y); | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-16 21:06:03 +02:00
										 |  |  |     void set_line_width(float line_width) { m_line_width = line_width; } | 
					
						
							|  |  |  |     float line_width() const { return m_line_width; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void begin_path(); | 
					
						
							|  |  |  |     void close_path(); | 
					
						
							|  |  |  |     void move_to(float x, float y); | 
					
						
							|  |  |  |     void line_to(float x, float y); | 
					
						
							| 
									
										
										
										
											2020-05-05 06:54:26 +04:30
										 |  |  |     void quadratic_curve_to(float cx, float cy, float x, float y); | 
					
						
							| 
									
										
										
										
											2020-04-16 21:06:03 +02:00
										 |  |  |     void stroke(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 23:49:51 +02:00
										 |  |  |     RefPtr<ImageData> create_image_data(JS::GlobalObject&, int width, int height) const; | 
					
						
							|  |  |  |     void put_image_data(const ImageData&, float x, float y); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     explicit CanvasRenderingContext2D(HTMLCanvasElement&); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 11:22:40 +02:00
										 |  |  |     void did_draw(const Gfx::FloatRect&); | 
					
						
							| 
									
										
										
										
											2020-03-22 21:15:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  |     OwnPtr<Gfx::Painter> painter(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WeakPtr<HTMLCanvasElement> m_element; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-12 19:22:42 +02:00
										 |  |  |     Gfx::AffineTransform m_transform; | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  |     Gfx::Color m_fill_style; | 
					
						
							| 
									
										
										
										
											2020-04-07 01:09:17 -07:00
										 |  |  |     Gfx::Color m_stroke_style; | 
					
						
							| 
									
										
										
										
											2020-04-16 21:06:03 +02:00
										 |  |  |     float m_line_width { 1 }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Gfx::Path m_path; | 
					
						
							| 
									
										
										
										
											2020-03-19 19:07:56 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |