Browse Source

Add source:isPaused() (enhancement #141)

Bart van Strien 14 years ago
parent
commit
9856fbc705

+ 1 - 0
src/modules/audio/Source.h

@@ -55,6 +55,7 @@ namespace audio
 		virtual void resume() = 0;
 		virtual void rewind() = 0;
 		virtual bool isStopped() const = 0;
+		virtual bool isPaused() const = 0;
 		virtual bool isFinished() const = 0;
 		virtual void update() = 0;
 

+ 5 - 0
src/modules/audio/null/Source.cpp

@@ -67,6 +67,11 @@ namespace null
 		return true;
 	}
 
+	bool Source::isPaused() const
+	{
+		return false;
+	}
+
 	bool Source::isFinished() const
 	{
 		return true;

+ 1 - 0
src/modules/audio/null/Source.h

@@ -50,6 +50,7 @@ namespace null
 		virtual void resume();
 		virtual void rewind();
 		virtual bool isStopped() const;
+		virtual bool isPaused() const;
 		virtual bool isFinished() const;
 		virtual void update();
 		virtual void setPitch(float pitch);

+ 12 - 0
src/modules/audio/openal/Source.cpp

@@ -112,6 +112,18 @@ namespace openal
 		return true;
 	}
 
+	bool Source::isPaused() const
+	{
+		if(valid)
+		{
+			ALenum state;
+			alGetSourcei(source, AL_SOURCE_STATE, &state);
+			return (state == AL_PAUSED);
+		}
+
+		return false;
+	}
+
 	bool Source::isFinished() const
 	{
 		return type == TYPE_STATIC ? isStopped() : isStopped() && !isLooping() && decoder->isFinished();

+ 2 - 1
src/modules/audio/openal/Source.h

@@ -76,7 +76,8 @@ namespace openal
 		virtual void pause();
 		virtual void resume();
 		virtual void rewind();
-		virtual bool isStopped() const;
+		virtual bool isStopped() const;
+		virtual bool isPaused() const;
 		virtual bool isFinished() const;
 		virtual void update();
 		virtual void setPitch(float pitch);

+ 9 - 1
src/modules/audio/wrap_Source.cpp

@@ -181,6 +181,13 @@ namespace audio
 		return 1;
 	}
 
+	int w_Source_isPaused(lua_State * L)
+	{
+		Source * t = luax_checksource(L, 1);
+		luax_pushboolean(L, t->isPaused());
+		return 1;
+	}
+
 	int w_Source_isStatic(lua_State * L)
 	{
 		Source * t= luax_checksource(L, 1);
@@ -205,10 +212,11 @@ namespace audio
 		{ "getVelocity", w_Source_getVelocity },
 		{ "setDirection", w_Source_setDirection },
 		{ "getDirection", w_Source_getDirection },
-		
+
 		{ "setLooping", w_Source_setLooping },
 		{ "isLooping", w_Source_isLooping },
 		{ "isStopped", w_Source_isStopped },
+		{ "isPaused", w_Source_isPaused },
 		{ "isStatic", w_Source_isStatic },
 		{ 0, 0 }
 	};

+ 1 - 0
src/modules/audio/wrap_Source.h

@@ -47,6 +47,7 @@ namespace audio
 	int w_Source_setLooping(lua_State * L);
 	int w_Source_isLooping(lua_State * L);
 	int w_Source_isStopped(lua_State * L);
+	int w_Source_isPaused(lua_State * L);
 	int w_Source_isStatic(lua_State * L);
 	int luaopen_source(lua_State * L);