Constified many Graphics and Window methods

This commit is contained in:
Alex Szpakowski
2013-02-16 01:45:01 -04:00
parent eba8cbc0b5
commit a68bdfe7a2
5 changed files with 67 additions and 67 deletions
+20 -20
View File
@@ -60,7 +60,7 @@ const char *Graphics::getName() const
return "love.graphics.opengl"; return "love.graphics.opengl";
} }
bool Graphics::checkMode(int width, int height, bool fullscreen) bool Graphics::checkMode(int width, int height, bool fullscreen) const
{ {
return currentWindow->checkWindowSize(width, height, fullscreen); return currentWindow->checkWindowSize(width, height, fullscreen);
} }
@@ -181,7 +181,7 @@ bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int f
return success; return success;
} }
void Graphics::getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) void Graphics::getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) const
{ {
currentWindow->getWindow(width, height, fullscreen, vsync, fsaa); currentWindow->getWindow(width, height, fullscreen, vsync, fsaa);
} }
@@ -226,36 +226,36 @@ void Graphics::setCaption(const char *caption)
currentWindow->setWindowTitle(title); currentWindow->setWindowTitle(title);
} }
int Graphics::getCaption(lua_State *L) int Graphics::getCaption(lua_State *L) const
{ {
std::string title = currentWindow->getWindowTitle(); std::string title = currentWindow->getWindowTitle();
lua_pushstring(L, title.c_str()); lua_pushstring(L, title.c_str());
return 1; return 1;
} }
int Graphics::getWidth() int Graphics::getWidth() const
{ {
return currentWindow->getWidth(); return currentWindow->getWidth();
} }
int Graphics::getHeight() int Graphics::getHeight() const
{ {
return currentWindow->getHeight(); return currentWindow->getHeight();
} }
int Graphics::getRenderHeight() int Graphics::getRenderHeight() const
{ {
if (Canvas::current) if (Canvas::current)
return Canvas::current->getHeight(); return Canvas::current->getHeight();
return getHeight(); return getHeight();
} }
bool Graphics::isCreated() bool Graphics::isCreated() const
{ {
return currentWindow->isCreated(); return currentWindow->isCreated();
} }
int Graphics::getModes(lua_State *L) int Graphics::getModes(lua_State *L) const
{ {
int n; int n;
love::window::Window::WindowSize **modes = currentWindow->getFullscreenSizes(n); love::window::Window::WindowSize **modes = currentWindow->getFullscreenSizes(n);
@@ -302,7 +302,7 @@ void Graphics::setScissor()
glDisable(GL_SCISSOR_TEST); glDisable(GL_SCISSOR_TEST);
} }
int Graphics::getScissor(lua_State *L) int Graphics::getScissor(lua_State *L) const
{ {
if (glIsEnabled(GL_SCISSOR_TEST) == GL_FALSE) if (glIsEnabled(GL_SCISSOR_TEST) == GL_FALSE)
return 0; return 0;
@@ -451,7 +451,7 @@ void Graphics::setColor(const Color &c)
glColor4ubv(&c.r); glColor4ubv(&c.r);
} }
Color Graphics::getColor() Color Graphics::getColor() const
{ {
float c[4]; float c[4];
glGetFloatv(GL_CURRENT_COLOR, c); glGetFloatv(GL_CURRENT_COLOR, c);
@@ -470,7 +470,7 @@ void Graphics::setBackgroundColor(const Color &c)
glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f); glClearColor((float)c.r/255.0f, (float)c.g/255.0f, (float)c.b/255.0f, (float)c.a/255.0f);
} }
Color Graphics::getBackgroundColor() Color Graphics::getBackgroundColor() const
{ {
float c[4]; float c[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE, c); glGetFloatv(GL_COLOR_CLEAR_VALUE, c);
@@ -495,7 +495,7 @@ void Graphics::setFont(Font *font)
currentFont->retain(); currentFont->retain();
} }
Font *Graphics::getFont() Font *Graphics::getFont() const
{ {
return currentFont; return currentFont;
} }
@@ -549,7 +549,7 @@ void Graphics::setColorMode(Graphics::ColorMode mode)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
} }
Graphics::BlendMode Graphics::getBlendMode() Graphics::BlendMode Graphics::getBlendMode() const
{ {
GLint dst, src, equation; GLint dst, src, equation;
glGetIntegerv(GL_BLEND_DST, &dst); glGetIntegerv(GL_BLEND_DST, &dst);
@@ -572,7 +572,7 @@ Graphics::BlendMode Graphics::getBlendMode()
return BLEND_MAX_ENUM; // Should never be reached. return BLEND_MAX_ENUM; // Should never be reached.
} }
Graphics::ColorMode Graphics::getColorMode() Graphics::ColorMode Graphics::getColorMode() const
{ {
GLint mode; GLint mode;
glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &mode); glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &mode);
@@ -614,12 +614,12 @@ void Graphics::setLine(float width, Graphics::LineStyle style)
setLineStyle(style); setLineStyle(style);
} }
float Graphics::getLineWidth() float Graphics::getLineWidth() const
{ {
return lineWidth; return lineWidth;
} }
Graphics::LineStyle Graphics::getLineStyle() Graphics::LineStyle Graphics::getLineStyle() const
{ {
return lineStyle; return lineStyle;
} }
@@ -647,14 +647,14 @@ void Graphics::setPoint(float size, Graphics::PointStyle style)
glPointSize((GLfloat)size); glPointSize((GLfloat)size);
} }
float Graphics::getPointSize() float Graphics::getPointSize() const
{ {
GLfloat size; GLfloat size;
glGetFloatv(GL_POINT_SIZE, &size); glGetFloatv(GL_POINT_SIZE, &size);
return (float)size; return (float)size;
} }
Graphics::PointStyle Graphics::getPointStyle() Graphics::PointStyle Graphics::getPointStyle() const
{ {
if (glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE) if (glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE)
return POINT_SMOOTH; return POINT_SMOOTH;
@@ -662,7 +662,7 @@ Graphics::PointStyle Graphics::getPointStyle()
return POINT_ROUGH; return POINT_ROUGH;
} }
int Graphics::getMaxPointSize() int Graphics::getMaxPointSize() const
{ {
GLint max; GLint max;
glGetIntegerv(GL_POINT_SIZE_MAX, &max); glGetIntegerv(GL_POINT_SIZE_MAX, &max);
@@ -1113,7 +1113,7 @@ void Graphics::shear(float kx, float ky)
glMultMatrixf((const GLfloat *)t.getElements()); glMultMatrixf((const GLfloat *)t.getElements());
} }
bool Graphics::hasFocus() bool Graphics::hasFocus() const
{ {
return currentWindow->hasFocus(); return currentWindow->hasFocus();
} }
+20 -20
View File
@@ -117,7 +117,7 @@ public:
* @param width The window width. * @param width The window width.
* @param height The window height. * @param height The window height.
**/ **/
bool checkMode(int width, int height, bool fullscreen); bool checkMode(int width, int height, bool fullscreen) const;
DisplayState saveState(); DisplayState saveState();
@@ -141,7 +141,7 @@ public:
* @param vsync Pointer to a boolean for the vsync status. * @param vsync Pointer to a boolean for the vsync status.
* @param fsaa Pointer to an integer for the current number of full scene anti-aliasing buffers. * @param fsaa Pointer to an integer for the current number of full scene anti-aliasing buffers.
**/ **/
void getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa); void getMode(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) const;
/** /**
* Toggles fullscreen. Note that this also needs to reload the * Toggles fullscreen. Note that this also needs to reload the
@@ -177,22 +177,22 @@ public:
**/ **/
void setCaption(const char *caption); void setCaption(const char *caption);
int getCaption(lua_State *L); int getCaption(lua_State *L) const;
/** /**
* Gets the width of the current display mode. * Gets the width of the current display mode.
**/ **/
int getWidth(); int getWidth() const;
/** /**
* Gets the height of the current display mode. * Gets the height of the current display mode.
**/ **/
int getHeight(); int getHeight() const;
/** /**
* True if some display mode is set. * True if some display mode is set.
**/ **/
bool isCreated(); bool isCreated() const;
/** /**
* This native Lua function gets available modes * This native Lua function gets available modes
@@ -207,7 +207,7 @@ public:
* Only fullscreen modes are returned here, as all * Only fullscreen modes are returned here, as all
* window sizes are supported (normally). * window sizes are supported (normally).
**/ **/
int getModes(lua_State *L); int getModes(lua_State *L) const;
/** /**
* Scissor defines a box such that everything outside that box is discarded and not drawn. * Scissor defines a box such that everything outside that box is discarded and not drawn.
@@ -228,7 +228,7 @@ public:
* This native Lua function gets the current scissor box in the order of: * This native Lua function gets the current scissor box in the order of:
* x, y, width, height * x, y, width, height
**/ **/
int getScissor(lua_State *L); int getScissor(lua_State *L) const;
/** /**
* Enables the stencil buffer and set stencil function to fill it * Enables the stencil buffer and set stencil function to fill it
@@ -281,7 +281,7 @@ public:
/** /**
* Gets current color. * Gets current color.
**/ **/
Color getColor(); Color getColor() const;
/** /**
* Sets the background Color. * Sets the background Color.
@@ -291,7 +291,7 @@ public:
/** /**
* Gets the current background color. * Gets the current background color.
**/ **/
Color getBackgroundColor(); Color getBackgroundColor() const;
/** /**
* Sets the current font. * Sets the current font.
@@ -301,7 +301,7 @@ public:
/** /**
* Gets the current Font, or nil if none. * Gets the current Font, or nil if none.
**/ **/
Font *getFont(); Font *getFont() const;
/** /**
* Sets the current blend mode. * Sets the current blend mode.
@@ -321,12 +321,12 @@ public:
/** /**
* Gets the current blend mode. * Gets the current blend mode.
**/ **/
BlendMode getBlendMode(); BlendMode getBlendMode() const;
/** /**
* Gets the current color mode. * Gets the current color mode.
**/ **/
ColorMode getColorMode(); ColorMode getColorMode() const;
/** /**
* Gets the current image filter. * Gets the current image filter.
@@ -354,12 +354,12 @@ public:
/** /**
* Gets the line width. * Gets the line width.
**/ **/
float getLineWidth(); float getLineWidth() const;
/** /**
* Gets the line style. * Gets the line style.
**/ **/
LineStyle getLineStyle(); LineStyle getLineStyle() const;
/** /**
* Sets the size of points. * Sets the size of points.
@@ -380,18 +380,18 @@ public:
/** /**
* Gets the point size. * Gets the point size.
**/ **/
float getPointSize(); float getPointSize() const;
/** /**
* Gets the point style. * Gets the point style.
**/ **/
PointStyle getPointStyle(); PointStyle getPointStyle() const;
/** /**
* Gets the maximum point size supported. * Gets the maximum point size supported.
* This may vary from computer to computer. * This may vary from computer to computer.
**/ **/
int getMaxPointSize(); int getMaxPointSize() const;
/** /**
* Draws text at the specified coordinates, with rotation and * Draws text at the specified coordinates, with rotation and
@@ -511,7 +511,7 @@ public:
void translate(float x, float y); void translate(float x, float y);
void shear(float kx, float ky); void shear(float kx, float ky);
bool hasFocus(); bool hasFocus() const;
private: private:
Font *currentFont; Font *currentFont;
@@ -522,7 +522,7 @@ private:
GLint matrixLimit; GLint matrixLimit;
GLint userMatrices; GLint userMatrices;
int getRenderHeight(); int getRenderHeight() const;
}; // Graphics }; // Graphics
} // opengl } // opengl
+9 -9
View File
@@ -45,27 +45,27 @@ public:
virtual ~Window(); virtual ~Window();
virtual bool setWindow(int width = 800, int height = 600, bool fullscreen = false, bool vsync = true, int fsaa = 0) = 0; virtual bool setWindow(int width = 800, int height = 600, bool fullscreen = false, bool vsync = true, int fsaa = 0) = 0;
virtual void getWindow(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) = 0; virtual void getWindow(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) const = 0;
virtual bool checkWindowSize(int width, int height, bool fullscreen) = 0; virtual bool checkWindowSize(int width, int height, bool fullscreen) const = 0;
virtual WindowSize **getFullscreenSizes(int &n) = 0; virtual WindowSize **getFullscreenSizes(int &n) const = 0;
virtual int getWidth() = 0; virtual int getWidth() const = 0;
virtual int getHeight() = 0; virtual int getHeight() const = 0;
virtual bool isCreated() = 0; virtual bool isCreated() const = 0;
virtual void setWindowTitle(std::string &title) = 0; virtual void setWindowTitle(std::string &title) = 0;
virtual std::string getWindowTitle() = 0; virtual std::string getWindowTitle() const = 0;
virtual bool setIcon(love::image::ImageData *imgd) = 0; virtual bool setIcon(love::image::ImageData *imgd) = 0;
// default no-op implementation // default no-op implementation
virtual void swapBuffers(); virtual void swapBuffers();
virtual bool hasFocus() = 0; virtual bool hasFocus() const = 0;
virtual void setMouseVisible(bool visible) = 0; virtual void setMouseVisible(bool visible) = 0;
virtual bool getMouseVisible() = 0; virtual bool getMouseVisible() const = 0;
//virtual static Window *getSingleton() = 0; //virtual static Window *getSingleton() = 0;
// No virtual statics, of course, but you are supposed to implement this static. // No virtual statics, of course, but you are supposed to implement this static.
+9 -9
View File
@@ -157,7 +157,7 @@ bool Window::setWindow(int width, int height, bool fullscreen, bool vsync, int f
return true; return true;
} }
void Window::getWindow(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) void Window::getWindow(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) const
{ {
width = currentMode.width; width = currentMode.width;
height = currentMode.height; height = currentMode.height;
@@ -166,7 +166,7 @@ void Window::getWindow(int &width, int &height, bool &fullscreen, bool &vsync, i
fsaa = currentMode.fsaa; fsaa = currentMode.fsaa;
} }
bool Window::checkWindowSize(int width, int height, bool fullscreen) bool Window::checkWindowSize(int width, int height, bool fullscreen) const
{ {
Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL; Uint32 sdlflags = fullscreen ? (SDL_OPENGL | SDL_FULLSCREEN) : SDL_OPENGL;
@@ -178,7 +178,7 @@ bool Window::checkWindowSize(int width, int height, bool fullscreen)
typedef Window::WindowSize WindowSize; typedef Window::WindowSize WindowSize;
WindowSize **Window::getFullscreenSizes(int &n) WindowSize **Window::getFullscreenSizes(int &n) const
{ {
SDL_Rect **modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN); SDL_Rect **modes = SDL_ListModes(0, SDL_OPENGL | SDL_FULLSCREEN);
@@ -203,17 +203,17 @@ WindowSize **Window::getFullscreenSizes(int &n)
return sizes; return sizes;
} }
int Window::getWidth() int Window::getWidth() const
{ {
return currentMode.width; return currentMode.width;
} }
int Window::getHeight() int Window::getHeight() const
{ {
return currentMode.height; return currentMode.height;
} }
bool Window::isCreated() bool Window::isCreated() const
{ {
return created; return created;
} }
@@ -224,7 +224,7 @@ void Window::setWindowTitle(std::string &title)
SDL_WM_SetCaption(windowTitle.c_str(), 0); SDL_WM_SetCaption(windowTitle.c_str(), 0);
} }
std::string Window::getWindowTitle() std::string Window::getWindowTitle() const
{ {
// not a reference // not a reference
// because we want this untouched // because we want this untouched
@@ -262,7 +262,7 @@ void Window::swapBuffers()
SDL_GL_SwapBuffers(); SDL_GL_SwapBuffers();
} }
bool Window::hasFocus() bool Window::hasFocus() const
{ {
return (SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0; return (SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0;
} }
@@ -272,7 +272,7 @@ void Window::setMouseVisible(bool visible)
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE); SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
} }
bool Window::getMouseVisible() bool Window::getMouseVisible() const
{ {
return (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) ? true : false; return (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) ? true : false;
} }
+9 -9
View File
@@ -38,26 +38,26 @@ public:
~Window(); ~Window();
bool setWindow(int width = 800, int height = 600, bool fullscreen = false, bool vsync = true, int fsaa = 0); bool setWindow(int width = 800, int height = 600, bool fullscreen = false, bool vsync = true, int fsaa = 0);
void getWindow(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa); void getWindow(int &width, int &height, bool &fullscreen, bool &vsync, int &fsaa) const;
bool checkWindowSize(int width, int height, bool fullscreen); bool checkWindowSize(int width, int height, bool fullscreen) const;
WindowSize **getFullscreenSizes(int &n); WindowSize **getFullscreenSizes(int &n) const;
int getWidth(); int getWidth() const;
int getHeight(); int getHeight() const;
bool isCreated(); bool isCreated() const;
void setWindowTitle(std::string &title); void setWindowTitle(std::string &title);
std::string getWindowTitle(); std::string getWindowTitle() const;
bool setIcon(love::image::ImageData *imgd); bool setIcon(love::image::ImageData *imgd);
void swapBuffers(); void swapBuffers();
bool hasFocus(); bool hasFocus() const;
void setMouseVisible(bool visible); void setMouseVisible(bool visible);
bool getMouseVisible(); bool getMouseVisible() const;
static love::window::Window *getSingleton(); static love::window::Window *getSingleton();