00001 /****************************************************************************** 00002 * This file is part of the Gluon Development Platform 00003 * Copyright (c) 2010 Arjen Hiemstra <ahiemstra@heimr.nl> 00004 * Copyright (C) 2010 Dan Leinir Turthra Jensen <admin@leinir.dk> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 */ 00020 00021 #ifndef GLUON_ENGINE_QTSCRIPTCOMPONENT_H 00022 #define GLUON_ENGINE_QTSCRIPTCOMPONENT_H 00023 00024 #include <engine/gluon_engine_export.h> 00025 #include <engine/component.h> 00026 00027 class QScriptValue; 00028 class QScriptEngine; 00029 00030 namespace GluonGraphics 00031 { 00032 class MaterialInstance; 00033 } 00034 00035 namespace GluonEngine 00036 { 00037 class Asset; 00038 00039 class GLUON_ENGINE_EXPORT QtScriptComponent : public Component 00040 { 00041 Q_OBJECT 00042 GLUON_OBJECT( GluonEngine::QtScriptComponent ) 00043 Q_INTERFACES( GluonEngine::Component ) 00044 00045 Q_PROPERTY( GluonEngine::Asset* script READ script WRITE setScript ) 00046 00047 public: 00048 Q_INVOKABLE QtScriptComponent( QObject* parent = 0 ); 00049 QtScriptComponent( const QtScriptComponent& other ); 00050 virtual ~QtScriptComponent(); 00051 virtual QString category() const; 00052 00053 virtual void initialize(); 00054 virtual void start(); 00055 virtual void update( int elapsedMilliseconds ); 00056 virtual void draw( int timeLapse = 0 ); 00057 virtual void stop(); 00058 virtual void cleanup(); 00059 00060 virtual Asset* script(); 00061 00062 public slots: 00063 virtual void setScript( GluonEngine::Asset* asset ); 00064 00065 private: 00066 class QtScriptComponentPrivate; 00067 QtScriptComponentPrivate* d; 00068 }; 00069 00070 } 00071 00072 Q_DECLARE_METATYPE( GluonEngine::QtScriptComponent ) 00073 Q_DECLARE_METATYPE( GluonEngine::QtScriptComponent* ) 00074 00075 typedef GluonCore::GluonObject* pGluonObject; 00076 typedef GluonEngine::GameObject* pGameObject; 00077 typedef GluonGraphics::MaterialInstance* pMaterialInstance; 00078 00079 QScriptValue GLUON_ENGINE_EXPORT gluonObjectToScriptValue( QScriptEngine* engine, const pGluonObject& in ); 00080 void GLUON_ENGINE_EXPORT gluonObjectFromScriptValue( const QScriptValue& object, pGluonObject& out ); 00081 QScriptValue GLUON_ENGINE_EXPORT gameObjectToScriptValue( QScriptEngine* engine, const pGameObject& in ); 00082 void GLUON_ENGINE_EXPORT gameObjectFromScriptValue( const QScriptValue& object, GluonEngine::GameObject *&out ); 00083 QScriptValue GLUON_ENGINE_EXPORT materialInstanceToScriptValue( QScriptEngine* engine, const pMaterialInstance& in ); 00084 void GLUON_ENGINE_EXPORT materialInstanceFromScriptValue( const QScriptValue& object, pMaterialInstance& out ); 00085 00086 #endif // GLUON_ENGINE_QTSCRIPTCOMPONENT_H