mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
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:
+4
-2
@@ -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.
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user