Commits

Alex Szpakowski committed 2061cc4

Constified many Graphics and Window methods

Comments (0)

Files changed (5)

src/modules/graphics/opengl/Graphics.cpp

 	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 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->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);
 	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;
 	glColor4ubv(&c.r);
 }
 
-Color Graphics::getColor()
+Color Graphics::getColor() const
 {
 	float c[4];
 	glGetFloatv(GL_CURRENT_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);
 		currentFont->retain();
 }
 
-Font *Graphics::getFont()
+Font *Graphics::getFont() const
 {
 	return currentFont;
 }
 		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);
 	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);
 	setLineStyle(style);
 }
 
-float Graphics::getLineWidth()
+float Graphics::getLineWidth() const
 {
 	return lineWidth;
 }
 
-Graphics::LineStyle Graphics::getLineStyle()
+Graphics::LineStyle Graphics::getLineStyle() const
 {
 	return lineStyle;
 }
 	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;
 		return POINT_ROUGH;
 }
 
-int Graphics::getMaxPointSize()
+int Graphics::getMaxPointSize() const
 {
 	GLint max;
 	glGetIntegerv(GL_POINT_SIZE_MAX, &max);
 	glMultMatrixf((const GLfloat *)t.getElements());
 }
 
-bool Graphics::hasFocus()
+bool Graphics::hasFocus() const
 {
 	return currentWindow->hasFocus();
 }

src/modules/graphics/opengl/Graphics.h

 	 * @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();
 
 	 * @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
 	 **/
 	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
 	 * 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.
 	 * 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
 	/**
 	 * Gets current color.
 	 **/
-	Color getColor();
+	Color getColor() const;
 
 	/**
 	 * Sets the background Color.
 	/**
 	 * Gets the current background color.
 	 **/
-	Color getBackgroundColor();
+	Color getBackgroundColor() const;
 
 	/**
 	 * Sets the current font.
 	/**
 	 * Gets the current Font, or nil if none.
 	 **/
-	Font *getFont();
+	Font *getFont() const;
 
 	/**
 	 * Sets the current blend mode.
 	/**
 	 * 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.
 	/**
 	 * Gets the line width.
 	 **/
-	float getLineWidth();
+	float getLineWidth() const;
 
 	/**
 	 * Gets the line style.
 	 **/
-	LineStyle getLineStyle();
+	LineStyle getLineStyle() const;
 
 	/**
 	 * Sets the size of points.
 	/**
 	 * 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
 	void translate(float x, float y);
 	void shear(float kx, float ky);
 
-	bool hasFocus();
+	bool hasFocus() const;
 private:
 
 	Font *currentFont;
 	GLint matrixLimit;
 	GLint userMatrices;
 
-	int getRenderHeight();
+	int getRenderHeight() const;
 }; // Graphics
 
 } // opengl

src/modules/window/Window.h

 	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.

src/modules/window/sdl/Window.cpp

 	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;
 	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;
 
 
 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);
 
 	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;
 }
 	SDL_WM_SetCaption(windowTitle.c_str(), 0);
 }
 
-std::string Window::getWindowTitle()
+std::string Window::getWindowTitle() const
 {
 	// not a reference
 	// because we want this untouched
 	SDL_GL_SwapBuffers();
 }
 
-bool Window::hasFocus()
+bool Window::hasFocus() const
 {
 	return (SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0;
 }
 	SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
 }
 
-bool Window::getMouseVisible()
+bool Window::getMouseVisible() const
 {
 	return (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE) ? true : false;
 }

src/modules/window/sdl/Window.h

 	~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();
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.