Browse Source

Create DrawQable class, make Image and Canvas DrawQable, and make love.graphics.drawq take a DrawQable as its first argument

Bill Meltsner 14 years ago
parent
commit
14348f6146

+ 12 - 0
platform/macosx/love.xcodeproj/project.pbxproj

@@ -8,6 +8,8 @@
 
 /* Begin PBXBuildFile section */
 		8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
+		A901B882143B65C500D77063 /* DrawQable.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A901B880143B65C400D77063 /* DrawQable.cpp */; };
+		A901B885143B661400D77063 /* Quad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A901B883143B661300D77063 /* Quad.cpp */; };
 		A9255DD11043183600BA1496 /* FreeType.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E4810420B4A007D418B /* FreeType.framework */; };
 		A9255DD21043183600BA1496 /* SDL.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5210420B57007D418B /* SDL.framework */; };
 		A9255DD31043183600BA1496 /* Lua.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A93E6E5310420B57007D418B /* Lua.framework */; };
@@ -223,6 +225,10 @@
 /* Begin PBXFileReference section */
 		1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
 		8D1107320486CEB800E47090 /* love.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = love.app; sourceTree = BUILT_PRODUCTS_DIR; };
+		A901B880143B65C400D77063 /* DrawQable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DrawQable.cpp; sourceTree = "<group>"; };
+		A901B881143B65C400D77063 /* DrawQable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawQable.h; sourceTree = "<group>"; };
+		A901B883143B661300D77063 /* Quad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Quad.cpp; sourceTree = "<group>"; };
+		A901B884143B661300D77063 /* Quad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Quad.h; sourceTree = "<group>"; };
 		A9255DEA1043188D00BA1496 /* SDLMain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLMain.m; sourceTree = "<group>"; };
 		A9255DEB1043188D00BA1496 /* SDLMain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLMain.h; sourceTree = "<group>"; };
 		A9255E021043195A00BA1496 /* Vorbis.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Vorbis.framework; path = /Library/Frameworks/Vorbis.framework; sourceTree = "<absolute>"; };
@@ -977,11 +983,15 @@
 			children = (
 				A93E6A8210420AC2007D418B /* Drawable.cpp */,
 				A93E6A8310420AC2007D418B /* Drawable.h */,
+				A901B880143B65C400D77063 /* DrawQable.cpp */,
+				A901B881143B65C400D77063 /* DrawQable.h */,
 				A968F0D21083A9D400A895AA /* Graphics.cpp */,
 				A93E6A8410420AC2007D418B /* Graphics.h */,
 				A93A3AB41121E86E003B04A4 /* Image.cpp */,
 				A93E6A8510420AC2007D418B /* Image.h */,
 				A93E6A8610420AC2007D418B /* opengl */,
+				A901B883143B661300D77063 /* Quad.cpp */,
+				A901B884143B661300D77063 /* Quad.h */,
 				A93E6AA510420AC3007D418B /* Volatile.cpp */,
 				A93E6AA610420AC3007D418B /* Volatile.h */,
 			);
@@ -1695,6 +1705,8 @@
 				A96F41981412BC000067FE9A /* VertexBuffer.cpp in Sources */,
 				A96F419B1412BC070067FE9A /* wrap_Canvas.cpp in Sources */,
 				A96F419E1412BC0E0067FE9A /* wrap_PixelEffect.cpp in Sources */,
+				A901B882143B65C500D77063 /* DrawQable.cpp in Sources */,
+				A901B885143B661400D77063 /* Quad.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 4 - 2
src/common/types.h

@@ -44,6 +44,7 @@ namespace love
 
 		// Graphics
 		GRAPHICS_DRAWABLE_ID,
+		GRAPHICS_DRAWQABLE_ID,
 		GRAPHICS_IMAGE_ID,
 		GRAPHICS_QUAD_ID,
 		GRAPHICS_FONT_ID,
@@ -107,12 +108,13 @@ namespace love
 
 	// Graphics.
 	const bits GRAPHICS_DRAWABLE_T = (bits(1) << GRAPHICS_DRAWABLE_ID) | OBJECT_T;
-	const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWABLE_T;
+	const bits GRAPHICS_DRAWQABLE_T = (bits(1) << GRAPHICS_DRAWQABLE_ID) | GRAPHICS_DRAWABLE_T;
+	const bits GRAPHICS_IMAGE_T = (bits(1) << GRAPHICS_IMAGE_ID) | GRAPHICS_DRAWQABLE_T;
 	const bits GRAPHICS_QUAD_T = (bits(1) << GRAPHICS_QUAD_ID) | OBJECT_T;
 	const bits GRAPHICS_FONT_T = (bits(1) << GRAPHICS_FONT_ID) | OBJECT_T;
 	const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T;
 	const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T;
-	const bits GRAPHICS_CANVAS_T = (bits(1) << GRAPHICS_CANVAS_ID) | GRAPHICS_DRAWABLE_T;
+	const bits GRAPHICS_CANVAS_T = (bits(1) << GRAPHICS_CANVAS_ID) | GRAPHICS_DRAWQABLE_T;
 	const bits GRAPHICS_PIXELEFFECT_T = (bits(1) << GRAPHICS_PIXELEFFECT_ID) | OBJECT_T;
 
 	// Image.

+ 33 - 0
src/modules/graphics/DrawQable.cpp

@@ -0,0 +1,33 @@
+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#include "DrawQable.h"
+
+namespace love
+{
+namespace graphics
+{
+
+	DrawQable::~DrawQable()
+	{
+	}
+	
+} // graphics
+} // love

+ 64 - 0
src/modules/graphics/DrawQable.h

@@ -0,0 +1,64 @@
+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#ifndef LOVE_GRAPHICS_DRAWQABLE_H
+#define LOVE_GRAPHICS_DRAWQABLE_H
+
+// LOVE
+#include "Drawable.h"
+#include "Quad.h"
+
+namespace love
+{
+namespace graphics
+{
+	/**
+	* A DrawQable is anything that be drawn in part with a Quad.
+	**/
+	class DrawQable : public Drawable
+	{
+	public:
+
+		/**
+		* Destructor.
+		**/
+		virtual ~DrawQable();
+
+		/**
+		* Draws the object with the specified transformation.
+		* 
+		* @param quad The Quad to use to draw the object.
+		* @param x The position of the object along the x-axis.
+		* @param y The position of the object along the y-axis.
+		* @param angle The angle of the object (in radians).
+		* @param sx The scale factor along the x-axis.
+		* @param sy The scale factor along the y-axis.
+		* @param ox The origin offset along the x-axis.
+		* @param oy The origin offset along the y-axis.
+		* @param kx Shear along the x-axis.
+		* @param ky Shear along the y-axis.
+		**/
+		virtual void drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const = 0;
+	};
+
+} // graphics
+} // love
+
+#endif // LOVE_GRAPHICS_DRAWQABLE_H

+ 2 - 2
src/modules/graphics/Image.h

@@ -23,7 +23,7 @@
 
 // LOVE
 #include <graphics/Volatile.h>
-#include <graphics/Drawable.h>
+#include <graphics/DrawQable.h>
 #include <common/StringMap.h>
 
 namespace love
@@ -31,7 +31,7 @@ namespace love
 namespace graphics
 {
 	
-	class Image : public Drawable, public Volatile
+	class Image : public DrawQable, public Volatile
 	{
 	public:
 	

+ 36 - 0
src/modules/graphics/Quad.cpp

@@ -0,0 +1,36 @@
+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#include "Quad.h"
+
+namespace love
+{
+namespace graphics
+{
+	Quad::Quad()
+	{
+	}
+
+	Quad::~Quad()
+	{
+	}
+
+} // graphics
+} // love

+ 61 - 0
src/modules/graphics/Quad.h

@@ -0,0 +1,61 @@
+/**
+* Copyright (c) 2006-2011 LOVE Development Team
+* 
+* This software is provided 'as-is', without any express or implied
+* warranty.  In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* 
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 
+* 1. The origin of this software must not be misrepresented; you must not
+*    claim that you wrote the original software. If you use this software
+*    in a product, an acknowledgment in the product documentation would be
+*    appreciated but is not required.
+* 2. Altered source versions must be plainly marked as such, and must not be
+*    misrepresented as being the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+**/
+
+#ifndef LOVE_GRAPHICS_QUAD_H
+#define LOVE_GRAPHICS_QUAD_H
+
+// LOVE
+#include <common/Object.h>
+#include <common/math.h>
+
+namespace love
+{
+namespace graphics
+{
+	class Quad : public Object
+	{
+	public:
+
+		struct Viewport
+		{
+			float x, y, w, h;
+		};
+
+	public:
+		Quad();
+
+		virtual ~Quad();
+
+		virtual void refresh(const Viewport & v, float sw, float sh) = 0;
+
+		virtual void setViewport(const Viewport & v) = 0;
+		virtual Viewport getViewport() const = 0;
+
+		virtual void flip(bool x, bool y) = 0;
+
+		/**
+		* Gets a pointer to the vertices.
+		**/
+		virtual const vertex * getVertices() const = 0;
+	};
+} // graphics
+} // love
+
+#endif // LOVE_GRAPHICS_QUAD_H

+ 1 - 1
src/modules/graphics/opengl/Canvas.cpp

@@ -276,7 +276,7 @@ namespace opengl
 		drawv(t, vertices);
 	}
 	
-	void Canvas::drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
+	void Canvas::drawq(love::graphics::Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 	{
 		static Matrix t;
 		const vertex * v = quad->getVertices();

+ 7 - 10
src/modules/graphics/opengl/Canvas.h

@@ -1,7 +1,7 @@
-#ifndef LOVE_GRAPHICS_CANVAS_H
-#define LOVE_GRAPHICS_CANVAS_H
+#ifndef LOVE_GRAPHICS_OPENGL_CANVAS_H
+#define LOVE_GRAPHICS_OPENGL_CANVAS_H
 
-#include <graphics/Drawable.h>
+#include <graphics/DrawQable.h>
 #include <graphics/Volatile.h>
 #include <graphics/Image.h>
 #include <graphics/Color.h>
@@ -10,7 +10,6 @@
 #include <common/math.h>
 #include <common/Matrix.h>
 #include "GLee.h"
-#include "Quad.h"
 
 namespace love
 {
@@ -18,7 +17,7 @@ namespace graphics
 {
 namespace opengl
 {
-	class Canvas : public Drawable, public Volatile
+	class Canvas : public DrawQable, public Volatile
 	{
 	public:
 		Canvas(int width, int height);
@@ -39,11 +38,9 @@ namespace opengl
 		virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
 
 		/**
-		* This function draws a section of the canvas using a Quad object.
-		*
-		* @param quad Represents the region of the Canvas to draw.
+		* @copydoc DrawQable::drawq()
 		**/
-		void drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
+		void drawq(love::graphics::Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
 		
 		love::image::ImageData * getImageData(love::image::Image * image);
 
@@ -85,4 +82,4 @@ namespace opengl
 } // graphics
 } // love
 
-#endif // LOVE_GRAPHICS_CANVAS_H
+#endif // LOVE_GRAPHICS_OPENGL_CANVAS_H

+ 1 - 1
src/modules/graphics/opengl/Image.cpp

@@ -110,7 +110,7 @@ namespace opengl
 		drawv(t, vertices);
 	}
 
-	void Image::drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
+	void Image::drawq(love::graphics::Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
 	{
 		static Matrix t;
 		const vertex * v = quad->getVertices();

+ 2 - 7
src/modules/graphics/opengl/Image.h

@@ -27,11 +27,9 @@
 #include <common/config.h>
 #include <image/ImageData.h>
 #include <graphics/Image.h>
-#include "Quad.h"
 
 // OpenGL
 #include "GLee.h"
-#include <SDL/SDL_opengl.h>
 
 namespace love
 {
@@ -114,12 +112,9 @@ namespace opengl
 		void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
 
 		/**
-		* This function draws a section of the image using a Quad object.
-		*
-		* @copydetails Image::draws()
-		* @param frame Represents the region of the Image to draw.
+		* @copydoc DrawQable::drawq()
 		**/
-		void drawq(Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
+		void drawq(love::graphics::Quad * quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
 
 		/**
 		* Sets the filter mode.

+ 6 - 13
src/modules/graphics/opengl/Quad.h

@@ -22,9 +22,8 @@
 #define LOVE_GRAPHICS_OPENGL_QUAD_H
 
 // LOVE
-#include <common/Object.h>
 #include <common/math.h>
-#include <graphics/Drawable.h>
+#include <graphics/Quad.h>
 
 namespace love
 {
@@ -32,19 +31,13 @@ namespace graphics
 {
 namespace opengl
 {
-	class Quad : public Object
+	class Quad : public love::graphics::Quad
 	{
-	public:
-
-		struct Viewport
-		{
-			float x, y, w, h;
-		};
-
-	private:
-
+		
+	protected:
+		
 		vertex vertices[4];
-
+		
 		Viewport viewport;
 		float sw, sh;
 

+ 4 - 4
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -19,7 +19,7 @@
 **/
 
 #include "wrap_Graphics.h"
-
+#include "DrawQable.h"
 #include <image/ImageData.h>
 #include <font/Rasterizer.h>
 
@@ -800,7 +800,7 @@ namespace opengl
 	}
 
 	/**
-	* Draws an Quad of an Image at the specified coordinates,
+	* Draws an Quad of a DrawQable at the specified coordinates,
 	* with rotation and scaling along both axes.
 	*
 	* @param q The Quad to draw.
@@ -816,7 +816,7 @@ namespace opengl
 	**/
 	int w_drawq(lua_State * L)
 	{
-		Image * image = luax_checktype<Image>(L, 1, "Image", GRAPHICS_IMAGE_T);
+		DrawQable * dq = luax_checktype<DrawQable>(L, 1, "DrawQable", GRAPHICS_DRAWQABLE_T);
 		Quad * q = luax_checkframe(L, 2);
 		float x = (float)luaL_checknumber(L, 3);
 		float y = (float)luaL_checknumber(L, 4);
@@ -827,7 +827,7 @@ namespace opengl
 		float oy = (float)luaL_optnumber(L, 9, 0);
 		float kx = (float)luaL_optnumber(L, 10, 0);
 		float ky = (float)luaL_optnumber(L, 11, 0);
-		image->drawq(q, x, y, angle, sx, sy, ox, oy, kx, ky);
+		dq->drawq(q, x, y, angle, sx, sy, ox, oy, kx, ky);
 		return 0;
 	}