Browse Source

Constified many Graphics and Window methods

Alex Szpakowski 12 years ago
parent
commit
a68bdfe7a2

+ 20 - 20
src/modules/graphics/opengl/Graphics.cpp

@@ -60,7 +60,7 @@ const char *Graphics::getName() const
 	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);
 }
@@ -181,7 +181,7 @@ bool Graphics::setMode(int width, int height, bool fullscreen, bool vsync, int f
 	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);
 }
@@ -226,36 +226,36 @@ void Graphics::setCaption(const char *caption)
 	currentWindow->setWindowTitle(title);
 }
 
-int Graphics::getCaption(lua_State *L)
+int Graphics::getCaption(lua_State *L) const
 {
 	std::string title = currentWindow->getWindowTitle();
 	lua_pushstring(L, title.c_str());
 	return 1;
 }
 
-int Graphics::getWidth()
+int Graphics::getWidth() const
 {
 	return currentWindow->getWidth();
 }
 
-int Graphics::getHeight()
+int Graphics::getHeight() const
 {
 	return currentWindow->getHeight();
 }
 
-int Graphics::getRenderHeight()
+int Graphics::getRenderHeight() const
 {
 	if (Canvas::current)
 		return Canvas::current->getHeight();
 	return getHeight();
 }
 
-bool Graphics::isCreated()
+bool Graphics::isCreated() const
 {
 	return currentWindow->isCreated();
 }
 
-int Graphics::getModes(lua_State *L)
+int Graphics::getModes(lua_State *L) const
 {
 	int n;
 	love::window::Window::WindowSize **modes = currentWindow->getFullscreenSizes(n);
@@ -302,7 +302,7 @@ void Graphics::setScissor()
 	glDisable(GL_SCISSOR_TEST);
 }
 
-int Graphics::getScissor(lua_State *L)
+int Graphics::getScissor(lua_State *L) const
 {
 	if (glIsEnabled(GL_SCISSOR_TEST) == GL_FALSE)
 		return 0;
@@ -451,7 +451,7 @@ void Graphics::setColor(const Color &c)
 	glColor4ubv(&c.r);
 }
 
-Color Graphics::getColor()
+Color Graphics::getColor() const
 {
 	float c[4];
 	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);
 }
 
-Color Graphics::getBackgroundColor()
+Color Graphics::getBackgroundColor() const
 {
 	float c[4];
 	glGetFloatv(GL_COLOR_CLEAR_VALUE, c);
@@ -495,7 +495,7 @@ void Graphics::setFont(Font *font)
 		currentFont->retain();
 }
 
-Font *Graphics::getFont()
+Font *Graphics::getFont() const
 {
 	return currentFont;
 }
@@ -549,7 +549,7 @@ void Graphics::setColorMode(Graphics::ColorMode mode)
 		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 }
 
-Graphics::BlendMode Graphics::getBlendMode()
+Graphics::BlendMode Graphics::getBlendMode() const
 {
 	GLint dst, src, equation;
 	glGetIntegerv(GL_BLEND_DST, &dst);
@@ -572,7 +572,7 @@ Graphics::BlendMode Graphics::getBlendMode()
 	return BLEND_MAX_ENUM; // Should never be reached.
 }
 
-Graphics::ColorMode Graphics::getColorMode()
+Graphics::ColorMode Graphics::getColorMode() const
 {
 	GLint mode;
 	glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &mode);
@@ -614,12 +614,12 @@ void Graphics::setLine(float width, Graphics::LineStyle style)
 	setLineStyle(style);
 }
 
-float Graphics::getLineWidth()
+float Graphics::getLineWidth() const
 {
 	return lineWidth;
 }
 
-Graphics::LineStyle Graphics::getLineStyle()
+Graphics::LineStyle Graphics::getLineStyle() const
 {
 	return lineStyle;
 }
@@ -647,14 +647,14 @@ void Graphics::setPoint(float size, Graphics::PointStyle style)
 	glPointSize((GLfloat)size);
 }
 
-float Graphics::getPointSize()
+float Graphics::getPointSize() const
 {
 	GLfloat size;
 	glGetFloatv(GL_POINT_SIZE, &size);
 	return (float)size;
 }
 
-Graphics::PointStyle Graphics::getPointStyle()
+Graphics::PointStyle Graphics::getPointStyle() const
 {
 	if (glIsEnabled(GL_POINT_SMOOTH) == GL_TRUE)
 		return POINT_SMOOTH;
@@ -662,7 +662,7 @@ Graphics::PointStyle Graphics::getPointStyle()
 		return POINT_ROUGH;
 }
 
-int Graphics::getMaxPointSize()
+int Graphics::getMaxPointSize() const
 {
 	GLint max;
 	glGetIntegerv(GL_POINT_SIZE_MAX, &max);
@@ -1113,7 +1113,7 @@ void Graphics::shear(float kx, float ky)
 	glMultMatrixf((const GLfloat *)t.getElements());
 }
 
-bool Graphics::hasFocus()
+bool Graphics::hasFocus() const
 {
 	return currentWindow->hasFocus();
 }

+ 20 - 20
src/modules/graphics/opengl/Graphics.h

@@ -117,7 +117,7 @@ public:
 	 * @param width The window width.
 	 * @param height The window height.
 	 **/
-	bool checkMode(int width, int height, bool fullscreen);
+	bool checkMode(int width, int height, bool fullscreen) const;
 
 	DisplayState saveState();
 
@@ -141,7 +141,7 @@ public:
 	 * @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.
 	 **/
-	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
@@ -177,22 +177,22 @@ public:
 	 **/
 	void setCaption(const char *caption);
 
-	int getCaption(lua_State *L);
+	int getCaption(lua_State *L) const;
 
 	/**
 	 * Gets the width of the current display mode.
 	 **/
-	int getWidth();
+	int getWidth() const;
 
 	/**
 	 * Gets the height of the current display mode.
 	 **/
-	int getHeight();
+	int getHeight() const;
 
 	/**
 	 * True if some display mode is set.
 	 **/
-	bool isCreated();
+	bool isCreated() const;
 
 	/**
 	 * This native Lua function gets available modes
@@ -207,7 +207,7 @@ public:
 	 * Only fullscreen modes are returned here, as all
 	 * 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.
@@ -228,7 +228,7 @@ public:
 	 * This native Lua function gets the current scissor box in the order of:
 	 * 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
@@ -281,7 +281,7 @@ public:
 	/**
 	 * Gets current color.
 	 **/
-	Color getColor();
+	Color getColor() const;
 
 	/**
 	 * Sets the background Color.
@@ -291,7 +291,7 @@ public:
 	/**
 	 * Gets the current background color.
 	 **/
-	Color getBackgroundColor();
+	Color getBackgroundColor() const;
 
 	/**
 	 * Sets the current font.
@@ -301,7 +301,7 @@ public:
 	/**
 	 * Gets the current Font, or nil if none.
 	 **/
-	Font *getFont();
+	Font *getFont() const;
 
 	/**
 	 * Sets the current blend mode.
@@ -321,12 +321,12 @@ public:
 	/**
 	 * Gets the current blend mode.
 	 **/
-	BlendMode getBlendMode();
+	BlendMode getBlendMode() const;
 
 	/**
 	 * Gets the current color mode.
 	 **/
-	ColorMode getColorMode();
+	ColorMode getColorMode() const;
 
 	/**
 	 * Gets the current image filter.
@@ -354,12 +354,12 @@ public:
 	/**
 	 * Gets the line width.
 	 **/
-	float getLineWidth();
+	float getLineWidth() const;
 
 	/**
 	 * Gets the line style.
 	 **/
-	LineStyle getLineStyle();
+	LineStyle getLineStyle() const;
 
 	/**
 	 * Sets the size of points.
@@ -380,18 +380,18 @@ public:
 	/**
 	 * Gets the point size.
 	 **/
-	float getPointSize();
+	float getPointSize() const;
 
 	/**
 	 * Gets the point style.
 	 **/
-	PointStyle getPointStyle();
+	PointStyle getPointStyle() const;
 
 	/**
 	 * Gets the maximum point size supported.
 	 * This may vary from computer to computer.
 	 **/
-	int getMaxPointSize();
+	int getMaxPointSize() const;
 
 	/**
 	 * Draws text at the specified coordinates, with rotation and
@@ -511,7 +511,7 @@ public:
 	void translate(float x, float y);
 	void shear(float kx, float ky);
 
-	bool hasFocus();
+	bool hasFocus() const;
 private:
 
 	Font *currentFont;
@@ -522,7 +522,7 @@ private:
 	GLint matrixLimit;
 	GLint userMatrices;
 
-	int getRenderHeight();
+	int getRenderHeight() const;
 }; // Graphics
 
 } // opengl

+ 9 - 9
src/modules/window/Window.h

@@ -45,27 +45,27 @@ public:
 	virtual ~Window();
 
 	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 WindowSize **getFullscreenSizes(int &n) = 0;
+	virtual bool checkWindowSize(int width, int height, bool fullscreen) const = 0;
+	virtual WindowSize **getFullscreenSizes(int &n) const = 0;
 
-	virtual int getWidth() = 0;
-	virtual int getHeight() = 0;
+	virtual int getWidth() const = 0;
+	virtual int getHeight() const = 0;
 
-	virtual bool isCreated() = 0;
+	virtual bool isCreated() const = 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;
 
 	// default no-op implementation
 	virtual void swapBuffers();
 
-	virtual bool hasFocus() = 0;
+	virtual bool hasFocus() const = 0;
 	virtual void setMouseVisible(bool visible) = 0;
-	virtual bool getMouseVisible() = 0;
+	virtual bool getMouseVisible() const = 0;
 
 	//virtual static Window *getSingleton() = 0;
 	// No virtual statics, of course, but you are supposed to implement this static.

+ 9 - 9
src/modules/window/sdl/Window.cpp

@@ -157,7 +157,7 @@ bool Window::setWindow(int width, int height, bool fullscreen, bool vsync, int f
 	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;
 	height = currentMode.height;
@@ -166,7 +166,7 @@ void Window::getWindow(int &width, int &height, bool &fullscreen, bool &vsync, i
 	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;
 
@@ -178,7 +178,7 @@ bool Window::checkWindowSize(int width, int height, bool fullscreen)
 
 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);
 
@@ -203,17 +203,17 @@ WindowSize **Window::getFullscreenSizes(int &n)
 	return sizes;
 }
 
-int Window::getWidth()
+int Window::getWidth() const
 {
 	return currentMode.width;
 }
 
-int Window::getHeight()
+int Window::getHeight() const
 {
 	return currentMode.height;
 }
 
-bool Window::isCreated()
+bool Window::isCreated() const
 {
 	return created;
 }
@@ -224,7 +224,7 @@ void Window::setWindowTitle(std::string &title)
 	SDL_WM_SetCaption(windowTitle.c_str(), 0);
 }
 
-std::string Window::getWindowTitle()
+std::string Window::getWindowTitle() const
 {
 	// not a reference
 	// because we want this untouched
@@ -262,7 +262,7 @@ void Window::swapBuffers()
 	SDL_GL_SwapBuffers();
 }
 
-bool Window::hasFocus()
+bool Window::hasFocus() const
 {
 	return (SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0;
 }
@@ -272,7 +272,7 @@ void Window::setMouseVisible(bool visible)
 	SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
 }
 
-bool Window::getMouseVisible()
+bool Window::getMouseVisible() const
 {
 	return (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) ? true : false;
 }

+ 9 - 9
src/modules/window/sdl/Window.h

@@ -38,26 +38,26 @@ public:
 	~Window();
 
 	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);
-	WindowSize **getFullscreenSizes(int &n);
+	bool checkWindowSize(int width, int height, bool fullscreen) const;
+	WindowSize **getFullscreenSizes(int &n) const;
 
-	int getWidth();
-	int getHeight();
+	int getWidth() const;
+	int getHeight() const;
 
-	bool isCreated();
+	bool isCreated() const;
 
 	void setWindowTitle(std::string &title);
-	std::string getWindowTitle();
+	std::string getWindowTitle() const;
 
 	bool setIcon(love::image::ImageData *imgd);
 
 	void swapBuffers();
 
-	bool hasFocus();
+	bool hasFocus() const;
 	void setMouseVisible(bool visible);
-	bool getMouseVisible();
+	bool getMouseVisible() const;
 
 	static love::window::Window *getSingleton();