From fda005c5ff18d79d1f9fead5bd1934130cfe789e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 9 Jan 2014 22:49:00 -0400 Subject: [PATCH] love.graphics.getScissor now has a proper C++ module method --- src/common/Module.cpp | 2 +- src/common/Module.h | 1 - src/modules/filesystem/physfs/Filesystem.h | 1 + src/modules/graphics/opengl/Graphics.cpp | 15 ++++++--------- src/modules/graphics/opengl/Graphics.h | 8 ++++---- src/modules/graphics/opengl/wrap_Graphics.cpp | 11 ++++++++++- src/modules/joystick/sdl/wrap_JoystickModule.h | 1 + src/modules/keyboard/wrap_Keyboard.h | 1 + src/modules/timer/wrap_Timer.h | 1 + 9 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/common/Module.cpp b/src/common/Module.cpp index 9f58f065c..8b025e72a 100644 --- a/src/common/Module.cpp +++ b/src/common/Module.cpp @@ -78,7 +78,7 @@ Module::~Module() void Module::registerInstance(Module *instance) { if (instance == nullptr) - throw Exception("Module instance is NULL"); + throw Exception("Module instance is null"); std::string name(instance->getName()); diff --git a/src/common/Module.h b/src/common/Module.h index 7ae1e6089..feea22af8 100644 --- a/src/common/Module.h +++ b/src/common/Module.h @@ -22,7 +22,6 @@ #define LOVE_MODULE_H // LOVE -#include "runtime.h" #include "Exception.h" #include "Object.h" diff --git a/src/modules/filesystem/physfs/Filesystem.h b/src/modules/filesystem/physfs/Filesystem.h index aaf892a3f..a6ef9af5a 100644 --- a/src/modules/filesystem/physfs/Filesystem.h +++ b/src/modules/filesystem/physfs/Filesystem.h @@ -31,6 +31,7 @@ #include "common/Module.h" #include "common/config.h" #include "common/int.h" +#include "common/runtime.h" #include "filesystem/FileData.h" #include "File.h" diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 77226a42a..075887c4a 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -273,19 +273,16 @@ void Graphics::setScissor() glDisable(GL_SCISSOR_TEST); } -int Graphics::getScissor(lua_State *L) const +bool Graphics::getScissor(int &x, int &y, int &width, int &height) const { - if (glIsEnabled(GL_SCISSOR_TEST) == GL_FALSE) - return 0; - OpenGL::Viewport scissor = gl.getScissor(); - lua_pushinteger(L, scissor.x); - lua_pushinteger(L, scissor.y); - lua_pushinteger(L, scissor.w); - lua_pushinteger(L, scissor.h); + x = scissor.x; + y = scissor.y; + width = scissor.w; + height = scissor.h; - return 4; + return glIsEnabled(GL_SCISSOR_TEST) == GL_TRUE; } void Graphics::defineStencil() diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 36e3c10bb..1dc2c5c82 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -163,10 +163,10 @@ public: void setScissor(); /** - * This native Lua function gets the current scissor box in the order of: - * x, y, width, height - **/ - int getScissor(lua_State *L) const; + * Gets the current scissor box. + * @return Whether the scissor is enabled. + */ + bool getScissor(int &x, int &y, int &width, int &height) const; /** * Enables the stencil buffer and set stencil function to fill it diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index a7f27e7fa..4ceda2c31 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -104,7 +104,16 @@ int w_setScissor(lua_State *L) int w_getScissor(lua_State *L) { - return instance->getScissor(L); + int x, y, w, h; + if (!instance->getScissor(x, y, w, h)) + return 0; + + lua_pushinteger(L, x); + lua_pushinteger(L, y); + lua_pushinteger(L, w); + lua_pushinteger(L, h); + + return 4; } static int setStencil(lua_State *L, bool invert) diff --git a/src/modules/joystick/sdl/wrap_JoystickModule.h b/src/modules/joystick/sdl/wrap_JoystickModule.h index 70f6f9066..24de3264c 100644 --- a/src/modules/joystick/sdl/wrap_JoystickModule.h +++ b/src/modules/joystick/sdl/wrap_JoystickModule.h @@ -23,6 +23,7 @@ // LOVE #include "common/config.h" +#include "common/runtime.h" #include "JoystickModule.h" namespace love diff --git a/src/modules/keyboard/wrap_Keyboard.h b/src/modules/keyboard/wrap_Keyboard.h index c87d55f0d..717f241c3 100644 --- a/src/modules/keyboard/wrap_Keyboard.h +++ b/src/modules/keyboard/wrap_Keyboard.h @@ -22,6 +22,7 @@ #define LOVE_KEYBOARD_WRAP_KEYBOARD_H // LOVE +#include "common/runtime.h" #include "Keyboard.h" namespace love diff --git a/src/modules/timer/wrap_Timer.h b/src/modules/timer/wrap_Timer.h index 4f7616e96..698d3864f 100644 --- a/src/modules/timer/wrap_Timer.h +++ b/src/modules/timer/wrap_Timer.h @@ -22,6 +22,7 @@ #define LOVE_TIMER_WRAP_TIMER_H // LOVE +#include "common/runtime.h" #include "Timer.h" namespace love