Finally abstracted constants properly. Changed how the event module works; wasn't really abstract before. Removed libs we're not going to use: native, signal.

This commit is contained in:
rude
2009-10-10 11:11:04 +02:00
parent 0a2ae705dd
commit 87e3c4131c
101 changed files with 3225 additions and 33496 deletions
+141
View File
@@ -0,0 +1,141 @@
/**
* Copyright (c) 2006-2009 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 "Graphics.h"
namespace love
{
namespace graphics
{
Graphics::~Graphics()
{
}
bool Graphics::getConstant(const char * in, DrawMode & out)
{
return drawModes.find(in, out);
}
bool Graphics::getConstant(DrawMode in, const char *& out)
{
return drawModes.find(in, out);
}
bool Graphics::getConstant(const char * in, AlignMode & out)
{
return alignModes.find(in, out);
}
bool Graphics::getConstant(AlignMode in, const char *& out)
{
return alignModes.find(in, out);
}
bool Graphics::getConstant(const char * in, BlendMode & out)
{
return blendModes.find(in, out);
}
bool Graphics::getConstant(BlendMode in, const char *& out)
{
return blendModes.find(in, out);
}
bool Graphics::getConstant(const char * in, ColorMode & out)
{
return colorModes.find(in, out);
}
bool Graphics::getConstant(ColorMode in, const char *& out)
{
return colorModes.find(in, out);
}
bool Graphics::getConstant(const char * in, LineStyle & out)
{
return lineStyles.find(in, out);
}
bool Graphics::getConstant(LineStyle in, const char *& out)
{
return lineStyles.find(in, out);
}
bool Graphics::getConstant(const char * in, PointStyle & out)
{
return pointStyles.find(in, out);
}
bool Graphics::getConstant(PointStyle in, const char *& out)
{
return pointStyles.find(in, out);
}
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
{
{ "line", Graphics::DRAW_LINE },
{ "fill", Graphics::DRAW_FILL },
};
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM> Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries));
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM>::Entry Graphics::alignModeEntries[] =
{
{ "left", Graphics::ALIGN_LEFT },
{ "right", Graphics::ALIGN_RIGHT },
{ "center", Graphics::ALIGN_CENTER },
};
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM> Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries));
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendModeEntries[] =
{
{ "alpha", Graphics::BLEND_ALPHA },
{ "additive", Graphics::BLEND_ADDITIVE },
};
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM> Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries));
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM>::Entry Graphics::colorModeEntries[] =
{
{ "replace", Graphics::COLOR_REPLACE },
{ "modulate", Graphics::COLOR_MODULATE },
};
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM> Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries));
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM>::Entry Graphics::lineStyleEntries[] =
{
{ "smooth", Graphics::LINE_SMOOTH },
{ "rough", Graphics::LINE_ROUGH }
};
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM> Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries));
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM>::Entry Graphics::pointStyleEntries[] =
{
{ "smooth", Graphics::POINT_SMOOTH },
{ "rough", Graphics::POINT_ROUGH }
};
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM> Graphics::pointStyles(Graphics::pointStyleEntries, sizeof(Graphics::pointStyleEntries));
} // graphics
} // love
+59 -14
View File
@@ -23,6 +23,7 @@
// LOVE
#include <common/Module.h>
#include <common/StringMap.h>
namespace love
{
@@ -34,43 +35,87 @@ namespace graphics
enum DrawMode
{
DRAW_LINE,
DRAW_FILL
DRAW_LINE = 1,
DRAW_FILL,
DRAW_MAX_ENUM
};
enum AlignMode
{
ALIGN_LEFT,
ALIGN_LEFT = 1,
ALIGN_CENTER,
ALIGN_RIGHT
ALIGN_RIGHT,
ALIGN_MAX_ENUM
};
enum BlendMode
{
BLEND_ALPHA,
BLEND_ADDITIVE
BLEND_ALPHA = 1,
BLEND_ADDITIVE,
BLEND_MAX_ENUM
};
enum ColorMode
{
COLOR_MODULATE,
COLOR_REPLACE
COLOR_MODULATE = 1,
COLOR_REPLACE,
COLOR_MAX_ENUM
};
enum LineStyle
{
LINE_ROUGH,
LINE_SMOOTH
LINE_ROUGH = 1,
LINE_SMOOTH,
LINE_MAX_ENUM
};
enum PointStyle
{
POINT_ROUGH,
POINT_SMOOTH
POINT_ROUGH = 1,
POINT_SMOOTH,
POINT_MAX_ENUM
};
virtual ~Graphics(){};
virtual ~Graphics();
static bool getConstant(const char * in, DrawMode & out);
static bool getConstant(DrawMode in, const char *& out);
static bool getConstant(const char * in, AlignMode & out);
static bool getConstant(AlignMode in, const char *& out);
static bool getConstant(const char * in, BlendMode & out);
static bool getConstant(BlendMode in, const char *& out);
static bool getConstant(const char * in, ColorMode & out);
static bool getConstant(ColorMode in, const char *& out);
static bool getConstant(const char * in, LineStyle & out);
static bool getConstant(LineStyle in, const char *& out);
static bool getConstant(const char * in, PointStyle & out);
static bool getConstant(PointStyle in, const char *& out);
private:
static StringMap<DrawMode, DRAW_MAX_ENUM>::Entry drawModeEntries[];
static StringMap<DrawMode, DRAW_MAX_ENUM> drawModes;
static StringMap<AlignMode, ALIGN_MAX_ENUM>::Entry alignModeEntries[];
static StringMap<AlignMode, ALIGN_MAX_ENUM> alignModes;
static StringMap<BlendMode, BLEND_MAX_ENUM>::Entry blendModeEntries[];
static StringMap<BlendMode, BLEND_MAX_ENUM> blendModes;
static StringMap<ColorMode, COLOR_MAX_ENUM>::Entry colorModeEntries[];
static StringMap<ColorMode, COLOR_MAX_ENUM> colorModes;
static StringMap<LineStyle, LINE_MAX_ENUM>::Entry lineStyleEntries[];
static StringMap<LineStyle, LINE_MAX_ENUM> lineStyles;
static StringMap<PointStyle, POINT_MAX_ENUM>::Entry pointStyleEntries[];
static StringMap<PointStyle, POINT_MAX_ENUM> pointStyles;
}; // Graphics
} // graphics
+24 -152
View File
@@ -38,7 +38,7 @@ namespace opengl
currentMode.width = 0;
currentMode.height = 0;
// Windows should be centered.
// Window should be centered.
SDL_putenv("SDL_VIDEO_CENTERED=center");
if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
@@ -511,7 +511,7 @@ namespace opengl
return currentFont;
}
void Graphics::setBlendMode( int mode )
void Graphics::setBlendMode( Graphics::BlendMode mode )
{
if(mode == BLEND_ADDITIVE)
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
@@ -519,7 +519,7 @@ namespace opengl
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void Graphics::setColorMode ( int mode )
void Graphics::setColorMode ( Graphics::ColorMode mode )
{
if(mode == COLOR_MODULATE)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -527,7 +527,7 @@ namespace opengl
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
}
int Graphics::getBlendMode()
Graphics::BlendMode Graphics::getBlendMode()
{
GLint dst, src;
glGetIntegerv(GL_BLEND_DST, &dst);
@@ -539,7 +539,7 @@ namespace opengl
return BLEND_ALPHA;
}
int Graphics::getColorMode()
Graphics::ColorMode Graphics::getColorMode()
{
GLint mode;
glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &mode);
@@ -555,7 +555,7 @@ namespace opengl
glLineWidth(width);
}
void Graphics::setLineStyle( int style )
void Graphics::setLineStyle(Graphics::LineStyle style )
{
if(style == LINE_ROUGH)
glDisable (GL_LINE_SMOOTH);
@@ -566,7 +566,7 @@ namespace opengl
}
}
void Graphics::setLine( float width, int style )
void Graphics::setLine( float width, Graphics::LineStyle style )
{
glLineWidth(width);
@@ -600,7 +600,7 @@ namespace opengl
return w;
}
int Graphics::getLineStyle()
Graphics::LineStyle Graphics::getLineStyle()
{
if(glIsEnabled(GL_LINE_SMOOTH) == GL_TRUE)
return LINE_SMOOTH;
@@ -626,7 +626,7 @@ namespace opengl
glPointSize((GLfloat)size);
}
void Graphics::setPointStyle( int style )
void Graphics::setPointStyle( Graphics::PointStyle style )
{
if( style == POINT_SMOOTH )
glEnable(GL_POINT_SMOOTH);
@@ -634,7 +634,7 @@ namespace opengl
glDisable(GL_POINT_SMOOTH);
}
void Graphics::setPoint( float size, int style )
void Graphics::setPoint( float size, Graphics::PointStyle style )
{
if( style == POINT_SMOOTH )
glEnable(GL_POINT_SMOOTH);
@@ -651,7 +651,7 @@ namespace opengl
return (float)size;
}
int Graphics::getPointStyle()
Graphics::PointStyle Graphics::getPointStyle()
{
if(glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE)
return POINT_SMOOTH;
@@ -724,7 +724,7 @@ namespace opengl
}
}
void Graphics::printf( const char * str, float x, float y, float wrap, int align)
void Graphics::printf( const char * str, float x, float y, float wrap, AlignMode align)
{
if(currentFont != 0)
{
@@ -846,13 +846,13 @@ namespace opengl
glEnable(GL_TEXTURE_2D);
}
void Graphics::triangle( int type, float x1, float y1, float x2, float y2, float x3, float y3 )
void Graphics::triangle(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3 )
{
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glPushMatrix();
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -877,12 +877,12 @@ namespace opengl
glEnable(GL_CULL_FACE);
}
void Graphics::rectangle( int type, float x, float y, float w, float h )
void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h )
{
glDisable(GL_TEXTURE_2D);
glPushMatrix();
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -908,13 +908,13 @@ namespace opengl
glEnable(GL_TEXTURE_2D);
}
void Graphics::quad( int type, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 )
void Graphics::quad(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 )
{
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
glPushMatrix();
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -941,7 +941,7 @@ namespace opengl
glEnable(GL_CULL_FACE);
}
void Graphics::circle( int type, float x, float y, float radius, int points )
void Graphics::circle(DrawMode mode, float x, float y, float radius, int points )
{
float two_pi = 3.14159265f * 2;
if(points <= 0) points = 1;
@@ -952,7 +952,7 @@ namespace opengl
glTranslatef(x, y, 0.0f);
switch(type)
switch(mode)
{
case DRAW_LINE:
glBegin(GL_LINE_LOOP);
@@ -987,12 +987,11 @@ namespace opengl
if( n < 2 )
return luaL_error(L, "Error: function needs at least two parameters.");
// The first one MUST be a number.
if( !lua_isnumber(L, 1) )
return luaL_error(L, "Error: first parameter must be a number.");
DrawMode mode;
// Get rendering mode. (line/fill)
int mode = (int)lua_tonumber(L, 1);
const char * str = luaL_checkstring(L, 1);
if(!getConstant(str, mode))
return luaL_error(L, "Invalid draw mode: %s", str);
// Get the type of the second argument.
int luatype = lua_type(L, 2);
@@ -1046,133 +1045,6 @@ namespace opengl
return 0;
}
int Graphics::polygong( lua_State * L )
{
// Get number of params.
int n = lua_gettop(L);
// Need at least two params.
if( n < 2 )
return luaL_error(L, "Error: function needs at least two parameters.");
// The first one MUST be a number.
if( !lua_isnumber(L, 1) )
return luaL_error(L, "Error: first parameter must be a number.");
int vertc = 0, colorc = 0;
if( n == 3 )
{
if((!lua_istable(L, 2) || !lua_istable(L, 3)))
return luaL_error(L, "Error: two tables expected.");
vertc = (int)lua_objlen(L, 2);
colorc = (int)lua_objlen(L, 3);
if( (vertc <= 0 || colorc <= 0))
return luaL_error(L, "Error: empty table.");
}
// Get rendering mode. (line/fill)
int mode = (int)lua_tonumber(L, 1);
GLenum glmode = (mode==DRAW_LINE) ? GL_LINE_LOOP : GL_POLYGON;
// Get the type of the second argument.
int luatype = lua_type(L, 2);
if(!(luatype == LUA_TTABLE || luatype == LUA_TNUMBER))
return luaL_error(L, "Error: expected number or table values.");
glPushAttrib(GL_CURRENT_BIT);
glDisable(GL_CULL_FACE);
glDisable(GL_TEXTURE_2D);
switch(luatype)
{
case LUA_TTABLE:
if( n == 2 )
{
glBegin(glmode);
lua_pushnil(L);
while(true)
{
if(lua_next(L, 2) == 0) break;
GLfloat x = (GLfloat)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLfloat y = (GLfloat)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte r = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte g = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte b = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
if(lua_next(L, 2) == 0) break;
GLubyte a = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
glColor4ub(r, g, b, a);
glVertex2f(x, y);
}
glEnd();
}
else if(n == 3)
{
// Allocate memory.
GLfloat * verts = new GLfloat[vertc];
GLubyte * colors = new GLubyte[colorc];
int verti = 0, colori = 0;
// Get verts.
lua_pushnil(L);
while(lua_next(L, 2))
{
verts[verti++] = (GLfloat)lua_tonumber(L, -1);
lua_pop(L, 1);
}
// Get colors.
lua_pushnil(L);
while(lua_next(L, 3))
{
colors[colori++] = (GLubyte)lua_tonumber(L, -1);
lua_pop(L, 1);
}
glEnable(GL_VERTEX_ARRAY);
glEnable(GL_COLOR_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors);
glVertexPointer(2, GL_FLOAT, 0, verts);
glDrawArrays(glmode, 0, (GLint)(vertc/2));
glDisable(GL_VERTEX_ARRAY);
glDisable(GL_COLOR_ARRAY);
delete [] verts;
delete [] colors;
}
break;
case LUA_TNUMBER:
// Assume params to be packed like this: x, y, r, g, b, a, x, y, r, ...
glBegin(glmode);
for(int i = 2; i < (n-1); i+=6)
{
glColor4ub((GLubyte)lua_tonumber(L, i+2), (GLubyte)lua_tonumber(L, i+3), (GLubyte)lua_tonumber(L, i+4), (GLubyte)lua_tonumber(L, i+5));
glVertex2f((GLfloat)lua_tonumber(L, i), (GLfloat)lua_tonumber(L, i+1));
}
glEnd();
break;
}
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glPopAttrib();
return 0;
}
love::image::ImageData * Graphics::newScreenshot(love::image::Image * image)
{
int w = getWidth();
+30 -30
View File
@@ -284,7 +284,7 @@ namespace opengl
* Sets the current font.
* @parm font A Font object.
**/
void setFont( Font * font );
void setFont(Font * font);
/**
* Sets a default font. The font is
@@ -293,7 +293,7 @@ namespace opengl
* @param data Data
* @param size The size of the font.
**/
void setFont( Data * data, int size = 12);
void setFont(Data * data, int size = 12);
/**
* Gets the current Font, or nil if none.
@@ -303,40 +303,40 @@ namespace opengl
/**
* Sets the current blend mode.
**/
void setBlendMode( int mode );
void setBlendMode(BlendMode mode);
/**
* Sets the current color mode.
**/
void setColorMode ( int mode );
void setColorMode (ColorMode mode);
/**
* Gets the current blend mode.
**/
int getBlendMode();
BlendMode getBlendMode();
/**
* Gets the current color mode.
**/
int getColorMode();
ColorMode getColorMode();
/**
* Sets the line width.
* @param width The new width of the line.
**/
void setLineWidth( float width );
void setLineWidth(float width);
/**
* Sets the line style.
* @param style LINE_ROUGH or LINE_SMOOTH.
**/
void setLineStyle( int style );
void setLineStyle(LineStyle style);
/**
* Sets the type of line used to draw primitives.
* A shorthand for setLineWidth and setLineStyle.
**/
void setLine( float width, int style = 0 );
void setLine(float width, LineStyle style);
/**
* Disables line stippling.
@@ -356,7 +356,7 @@ namespace opengl
/**
* Gets the line style.
**/
int getLineStyle();
LineStyle getLineStyle();
/**
* Gets the line stipple pattern and repeat factor.
@@ -368,18 +368,18 @@ namespace opengl
/**
* Sets the size of points.
**/
void setPointSize( float size );
void setPointSize(float size);
/**
* Sets the style of points.
* @param style POINT_SMOOTH or POINT_ROUGH.
**/
void setPointStyle( int style );
void setPointStyle(PointStyle style);
/**
* Shorthand for setPointSize and setPointStyle.
**/
void setPoint( float size, int style );
void setPoint(float size, PointStyle style);
/**
* Gets the point size.
@@ -389,7 +389,7 @@ namespace opengl
/**
* Gets the point style.
**/
int getPointStyle();
PointStyle getPointStyle();
/**
* Gets the maximum point size supported.
@@ -404,7 +404,7 @@ namespace opengl
* @param x The x-coordiante.
* @param y The y-coordiante.
**/
void print( const char * str, float x, float y );
void print(const char * str, float x, float y);
/**
* Draws text at the specified coordinates, with rotation.
@@ -412,7 +412,7 @@ namespace opengl
* @param y The y-coordinate.
* @param angle The amount of rotation.
**/
void print( const char * str, float x, float y , float angle );
void print(const char * str, float x, float y , float angle);
/**
* Draws text at the specified coordinates, with rotation and
@@ -422,7 +422,7 @@ namespace opengl
* @param angle The amount of rotation.
* @param s The scale factor. (1 = normal).
**/
void print( const char * str, float x, float y , float angle, float s );
void print(const char * str, float x, float y , float angle, float s);
/**
* Draws text at the specified coordinates, with rotation and
@@ -433,7 +433,7 @@ namespace opengl
* @param sx The scale factor along the x-axis. (1 = normal).
* @param sy The scale factor along the y-axis. (1 = normal).
**/
void print( const char * str, float x, float y , float angle, float sx, float sy);
void print(const char * str, float x, float y , float angle, float sx, float sy);
/**
* Draw formatted text on screen at the specified coordinates.
@@ -444,14 +444,14 @@ namespace opengl
* @param wrap The maximum width of the text area.
* @param align Where to align the text.
**/
void printf( const char * str, float x, float y, float wrap, int align = 0 );
void printf(const char * str, float x, float y, float wrap, AlignMode align);
/**
* Draws a point at (x,y).
* @param x Point along x-axis.
* @param y Point along y-axis.
**/
void point( float x, float y );
void point(float x, float y);
/**
* Draws a line from (x1,y1) to (x2,y2).
@@ -460,11 +460,11 @@ namespace opengl
* @param x2 Second x-coordinate.
* @param y2 Second y-coordinate.
**/
void line( float x1, float y1, float x2, float y2 );
void line(float x1, float y1, float x2, float y2);
/**
* Draws a triangle using the three coordinates passed.
* @param type The type of drawing (line/filled).
* @param mode The mode of drawing (line/filled).
* @param x1 First x-coordinate.
* @param y1 First y-coordinate.
* @param x2 Second x-coordinate.
@@ -472,7 +472,7 @@ namespace opengl
* @param x3 Third x-coordinate.
* @param y3 Third y-coordinate.
**/
void triangle( int type, float x1, float y1, float x2, float y2, float x3, float y3 );
void triangle(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3);
/**
* Draws a rectangle.
@@ -481,11 +481,11 @@ namespace opengl
* @param w The width of the rectangle.
* @param h The height of the rectangle.
**/
void rectangle( int type, float x, float y, float w, float h );
void rectangle(DrawMode mode, float x, float y, float w, float h);
/**
* Draws a quadrilateral using the four coordinates passed.
* @param type The type of drawing (line/filled).
* @param mode The mode of drawing (line/filled).
* @param x1 First x-coordinate.
* @param y1 First y-coordinate.
* @param x2 Second x-coordinate.
@@ -495,25 +495,25 @@ namespace opengl
* @param x4 Fourth x-coordinate.
* @param y4 Fourth y-coordinate.
**/
void quad( int type, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 );
void quad(DrawMode mode, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
/**
* Draws a circle using the specified arguments.
* @param type The type of drawing (line/filled).
* @param mode The mode of drawing (line/filled).
* @param x X-coordinate.
* @param y Y-coordinate.
* @param radius Radius of the circle.
* @param points Amount of points to use to draw the circle.
**/
void circle( int type, float x, float y, float radius, int points = 10 );
void circle(DrawMode mode, float x, float y, float radius, int points = 10);
/**
* Draws a polygon with an arbitrary number of vertices.
* @param type The type of drawing (line/filled).
* @param ... Vertex components (x1, y1, x2, y2, etc).
**/
int polygon( lua_State * L );
int polygong( lua_State * L );
int polygon(lua_State * L);
int polygong(lua_State * L);
/**
* Creates a screenshot of the view and saves it to the default folder.
+86 -70
View File
@@ -360,27 +360,45 @@ namespace opengl
int w_setBlendMode(lua_State * L)
{
int mode = luaL_checkint(L, 1);
Graphics::BlendMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
instance->setBlendMode(mode);
return 0;
}
int w_setColorMode(lua_State * L)
{
int mode = luaL_checkint(L, 1);
Graphics::ColorMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid color mode: %s", str);
instance->setColorMode(mode);
return 0;
}
int w_getBlendMode(lua_State * L)
{
lua_pushinteger(L, instance->getBlendMode());
Graphics::BlendMode mode = instance->getBlendMode();
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
lua_pushstring(L, str);
return 1;
}
int w_getColorMode(lua_State * L)
{
lua_pushinteger(L, instance->getColorMode());
Graphics::ColorMode mode = instance->getColorMode();
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
lua_pushstring(L, str);
return 1;
}
@@ -393,7 +411,11 @@ namespace opengl
int w_setLineStyle(lua_State * L)
{
int style = luaL_checkint(L, 1);
Graphics::LineStyle style;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid line style: %s", str);
instance->setLineStyle(style);
return 0;
}
@@ -401,7 +423,16 @@ namespace opengl
int w_setLine(lua_State * L)
{
float width = (float)luaL_checknumber(L, 1);
int style = luaL_optint(L, 2, Graphics::LINE_SMOOTH);
Graphics::LineStyle style = Graphics::LINE_SMOOTH;
if(lua_gettop(L) >= 2)
{
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid line style: %s", str);
}
instance->setLine(width, style);
return 0;
}
@@ -446,7 +477,15 @@ namespace opengl
int w_setPointStyle(lua_State * L)
{
int style = luaL_checkint(L, 1);
Graphics::PointStyle style = Graphics::POINT_SMOOTH;
if(lua_gettop(L) >= 2)
{
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid point style: %s", str);
}
instance->setPointStyle(style);
return 0;
}
@@ -454,7 +493,12 @@ namespace opengl
int w_setPoint(lua_State * L)
{
float size = (float)luaL_checknumber(L, 1);
int style = luaL_optint(L, 2, Graphics::POINT_SMOOTH);
Graphics::PointStyle style;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, style))
return luaL_error(L, "Invalid point style: %s", str);
instance->setPoint(size, style);
return 0;
}
@@ -587,7 +631,16 @@ namespace opengl
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float wrap = (float)luaL_checknumber(L, 4);
int align = luaL_optint(L, 5, 0);
Graphics::AlignMode align = Graphics::ALIGN_LEFT;
if(lua_gettop(L) >= 5)
{
const char * str = luaL_checkstring(L, 5);
if(!Graphics::getConstant(str, align))
return luaL_error(L, "Incorrect alignment: %s", str);
}
instance->printf(str, x, y, wrap, align);
return 0;
}
@@ -612,31 +665,43 @@ namespace opengl
int w_triangle(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x1 = (float)luaL_checknumber(L, 2);
float y1 = (float)luaL_checknumber(L, 3);
float x2 = (float)luaL_checknumber(L, 4);
float y2 = (float)luaL_checknumber(L, 5);
float x3 = (float)luaL_checknumber(L, 6);
float y3 = (float)luaL_checknumber(L, 7);
instance->triangle(type, x1, y1, x2, y2, x3, y3);
instance->triangle(mode, x1, y1, x2, y2, x3, y3);
return 0;
}
int w_rectangle(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float w = (float)luaL_checknumber(L, 4);
float h = (float)luaL_checknumber(L, 5);
instance->rectangle(type, x, y, w, h);
instance->rectangle(mode, x, y, w, h);
return 0;
}
int w_quad(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x1 = (float)luaL_checknumber(L, 2);
float y1 = (float)luaL_checknumber(L, 3);
float x2 = (float)luaL_checknumber(L, 4);
@@ -645,18 +710,22 @@ namespace opengl
float y3 = (float)luaL_checknumber(L, 7);
float x4 = (float)luaL_checknumber(L, 6);
float y4 = (float)luaL_checknumber(L, 7);
instance->quad(type, x1, y1, x2, y2, x3, y3, x4, y4);
instance->quad(mode, x1, y1, x2, y2, x3, y3, x4, y4);
return 0;
}
int w_circle(lua_State * L)
{
int type = luaL_checkint(L, 1);
Graphics::DrawMode mode;
const char * str = luaL_checkstring(L, 1);
if(!Graphics::getConstant(str, mode))
return luaL_error(L, "Incorrect draw mode %s", str);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float radius = (float)luaL_checknumber(L, 4);
int points = luaL_optint(L, 5, 10);
instance->circle(type, x, y, radius, points);
instance->circle(mode, x, y, radius, points);
return 0;
}
@@ -795,58 +864,6 @@ namespace opengl
0
};
// List of constants.
static const Constant constants[] = {
{ "align_left", Graphics::ALIGN_LEFT },
{ "align_right", Graphics::ALIGN_RIGHT },
{ "align_center", Graphics::ALIGN_CENTER },
{ "blend_alpha", Graphics::BLEND_ALPHA },
{ "blend_additive", Graphics::BLEND_ADDITIVE },
{ "color_replace", Graphics::COLOR_REPLACE },
{ "color_modulate", Graphics::COLOR_MODULATE },
{ "draw_line", Graphics::DRAW_LINE },
{ "draw_fill", Graphics::DRAW_FILL },
{ "line_smooth", Graphics::LINE_SMOOTH },
{ "line_rough", Graphics::LINE_ROUGH },
{ "point_smooth", Graphics::POINT_SMOOTH },
{ "point_rough", Graphics::POINT_ROUGH },
{ "filter_linear", Image::FILTER_LINEAR },
{ "filter_nearest", Image::FILTER_NEAREST },
{ "wrap_clamp", Image::WRAP_CLAMP },
{ "wrap_repeat", Image::WRAP_REPEAT },
/**
// Vertex buffer geometry types.
{ "type_points", TYPE_POINTS },
{ "type_lines", TYPE_LINES },
{ "type_line_strip", TYPE_LINE_STRIP },
{ "type_triangles", TYPE_TRIANGLES },
{ "type_triangle_strip", TYPE_TRIANGLE_STRIP },
{ "type_triangle_fan", TYPE_TRIANGLE_FAN },
{ "type_num", TYPE_NUM },
// Vertex buffer usage hints.
{ "usage_array", USAGE_ARRAY },
{ "usage_dynamic", USAGE_DYNAMIC },
{ "usage_static", USAGE_STATIC },
{ "usage_stream", USAGE_STREAM },
{ "usage_num", USAGE_NUM },
**/
{ 0, 0 }
};
int luaopen_love_graphics(lua_State * L)
{
if(instance == 0)
@@ -867,7 +884,6 @@ namespace opengl
w.flags = MODULE_T;
w.functions = functions;
w.types = types;
w.constants = constants;
luax_register_module(L, w);