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

This commit is contained in:
Bill Meltsner
2011-10-04 12:33:34 -04:00
parent 4cb247b3ea
commit 14348f6146
13 changed files with 233 additions and 40 deletions
+33
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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;
@@ -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;
}