1 /*--License:
2 	Kyra Sprite Engine
3 	Copyright Lee Thomason (Grinning Lizard Software) 2001-2005
4 	www.grinninglizard.com/kyra
5 	www.sourceforge.net/projects/kyra
6 
7 	Kyra is provided under the LGPL.
8 
9 	I kindly request you display a splash screen (provided in the HTML documentation)
10 	to promote Kyra and acknowledge the software and everyone who has contributed to it,
11 	but it is not required by the license.
12 
13 --- LGPL License --
14 
15     This library is free software; you can redistribute it and/or
16     modify it under the terms of the GNU Lesser General Public
17     License as published by the Free Software Foundation; either
18     version 2.1 of the License, or (at your option) any later version.
19 
20     This library is distributed in the hope that it will be useful,
21     but WITHOUT ANY WARRANTY; without even the implied warranty of
22     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23     Lesser General Public License for more details.
24 
25     You should have received a copy of the GNU Lesser General Public
26     License along with this library; if not, write to the Free Software
27     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28 
29 	The full text of the license can be found in lgpl.txt
30 */
31 
32 #ifndef KYRA_CANVAS_INCLUDED
33 #define KYRA_CANVAS_INCLUDED
34 
35 #include "image.h"
36 #include "canvasresource.h"
37 
38 
39 struct KrPaintInfo;
40 class  KrCanvasResource;
41 union  KrRGBA;
42 
43 
44 /**	A Canvas is a pixel area that a client program can draw to.
45 	A Canvas has the following advantages over just drawing to
46 	the framebuffer after the engine:
47 
48 	- automates dirty rectangle handling
49 	- applies color and alpha transforms like all other Kyra objects
50 	- can have multiple instances
51 	- depth
52 */
53 
54 class KrCanvas : public KrImage
55 {
56   public:
57 
58 	/// Construct from a resource - if the resource changes ALL the instances change.
59 	KrCanvas( KrCanvasResource* resource );
60 	virtual ~KrCanvas();
61 
62 	virtual void Draw(	KrPaintInfo* paintInfo,
63 						const grinliz::Rectangle2I& clip,
64 						int window );
65 
Width()66 	int Width()			{ return resource->Width(); }	///< Width
Height()67 	int Height()		{ return resource->Height(); }	///< Height
68 
69 	/** Note that this method is a pass through to a Canvas Resource;
70 		if you change the pixel data, all instances of the
71 		Canvas Resource will change.
72 		@sa KrCanvasResource
73 	*/
Pixels()74 	KrRGBA* Pixels()	{ return resource->Pixels(); }
75 
76 	/** Note that this method is a pass through to a Canvas Resource;
77 		if you change the Refresh data, all instances of the
78 		Canvas Resource will change.
79 		@sa KrCanvasResource
80 	*/
Refresh()81 	void Refresh()		{ resource->Refresh(); }
82 
83 	virtual KrImNode* Clone();
84 
85 	virtual void QueryBoundingBox( grinliz::Rectangle2I* boundingBox, int window = 0 );
86 	virtual bool HitTest( int x, int y, int flags, std::vector<KrImage*>* results, int window );
ToCanvas()87 	virtual KrCanvas* ToCanvas()	{ return this; }
88 	virtual void CalcTransform( int window );
Resource()89 	virtual KrResource* Resource()			{ return resource; }
90 
91   protected:
92 
93   private:
94 	KrCanvasResource* resource;
95 };
96 
97 
98 #endif
99