1 | /************************************************************************
|
---|
2 | filename: CEGUIScriptModule.h
|
---|
3 | created: 16/7/2004
|
---|
4 | author: Paul D Turner
|
---|
5 |
|
---|
6 | purpose: Abstract class interface for scripting support
|
---|
7 | *************************************************************************/
|
---|
8 | /*************************************************************************
|
---|
9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
11 |
|
---|
12 | This library is free software; you can redistribute it and/or
|
---|
13 | modify it under the terms of the GNU Lesser General Public
|
---|
14 | License as published by the Free Software Foundation; either
|
---|
15 | version 2.1 of the License, or (at your option) any later version.
|
---|
16 |
|
---|
17 | This library is distributed in the hope that it will be useful,
|
---|
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | Lesser General Public License for more details.
|
---|
21 |
|
---|
22 | You should have received a copy of the GNU Lesser General Public
|
---|
23 | License along with this library; if not, write to the Free Software
|
---|
24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | *************************************************************************/
|
---|
26 | #ifndef _CEGUIScriptModule_h_
|
---|
27 | #define _CEGUIScriptModule_h_
|
---|
28 |
|
---|
29 | #include "CEGUIBase.h"
|
---|
30 | #include "CEGUIString.h"
|
---|
31 | #include "CEGUIEvent.h"
|
---|
32 |
|
---|
33 |
|
---|
34 | // Start of CEGUI namespace section
|
---|
35 | namespace CEGUI
|
---|
36 | {
|
---|
37 | /*!
|
---|
38 | \brief
|
---|
39 | Abstract interface required for all scripting support modules to be used with
|
---|
40 | the CEGUI system.
|
---|
41 | */
|
---|
42 | class CEGUIEXPORT ScriptModule
|
---|
43 | {
|
---|
44 | public:
|
---|
45 | /*************************************************************************
|
---|
46 | Construction and Destruction
|
---|
47 | *************************************************************************/
|
---|
48 | /*!
|
---|
49 | \brief
|
---|
50 | Constructor for ScriptModule base class
|
---|
51 | */
|
---|
52 | ScriptModule(void);
|
---|
53 |
|
---|
54 |
|
---|
55 | /*!
|
---|
56 | \brief
|
---|
57 | Destructor for ScriptModule base class.
|
---|
58 | */
|
---|
59 | virtual ~ScriptModule(void) {}
|
---|
60 |
|
---|
61 |
|
---|
62 | /*************************************************************************
|
---|
63 | Abstract interface
|
---|
64 | *************************************************************************/
|
---|
65 | /*!
|
---|
66 | \brief
|
---|
67 | Execute a script file.
|
---|
68 |
|
---|
69 | \param filename
|
---|
70 | String object holding the filename of the script file that is to be executed
|
---|
71 |
|
---|
72 | \param resourceGroup
|
---|
73 | Resource group idendifier to be passed to the ResourceProvider when loading the script file.
|
---|
74 | */
|
---|
75 | virtual void executeScriptFile(const String& filename, const String& resourceGroup = "") = 0;
|
---|
76 |
|
---|
77 |
|
---|
78 | /*!
|
---|
79 | \brief
|
---|
80 | Execute a scripted global function. The function should not take any parameters and should return an integer.
|
---|
81 |
|
---|
82 | \param function_name
|
---|
83 | String object holding the name of the function, in the global script environment, that
|
---|
84 | is to be executed.
|
---|
85 |
|
---|
86 | \return
|
---|
87 | The integer value returned from the script function.
|
---|
88 | */
|
---|
89 | virtual int executeScriptGlobal(const String& function_name) = 0;
|
---|
90 |
|
---|
91 |
|
---|
92 | /*!
|
---|
93 | \brief
|
---|
94 | Execute a scripted global 'event handler' function. The function should take some kind of EventArgs like parameter
|
---|
95 | that the concrete implementation of this function can create from the passed EventArgs based object. The function
|
---|
96 | should not return anything.
|
---|
97 |
|
---|
98 | \param handler_name
|
---|
99 | String object holding the name of the scripted handler function.
|
---|
100 |
|
---|
101 | \param e
|
---|
102 | EventArgs based object that should be passed, by any appropriate means, to the scripted function.
|
---|
103 |
|
---|
104 | \return
|
---|
105 | - true if the event was handled.
|
---|
106 | - false if the event was not handled.
|
---|
107 | */
|
---|
108 | virtual bool executeScriptedEventHandler(const String& handler_name, const EventArgs& e) = 0;
|
---|
109 |
|
---|
110 |
|
---|
111 | /*!
|
---|
112 | \brief
|
---|
113 | Execute script code contained in the given CEGUI::String object.
|
---|
114 |
|
---|
115 | \param str
|
---|
116 | String object holding the valid script code that should be executed.
|
---|
117 |
|
---|
118 | \return
|
---|
119 | Nothing.
|
---|
120 | */
|
---|
121 | virtual void executeString(const String& str) = 0;
|
---|
122 |
|
---|
123 |
|
---|
124 | /*!
|
---|
125 | \brief
|
---|
126 | Method called during system initialisation, prior to running any scripts via the ScriptModule, to enable the ScriptModule
|
---|
127 | to perform any operations required to complete initialisation or binding of the script language to the gui system objects.
|
---|
128 |
|
---|
129 | \return
|
---|
130 | Nothing.
|
---|
131 | */
|
---|
132 | virtual void createBindings(void) {}
|
---|
133 |
|
---|
134 |
|
---|
135 | /*!
|
---|
136 | \brief
|
---|
137 | Method called during system destruction, after all scripts have been run via the ScriptModule, to enable the ScriptModule
|
---|
138 | to perform any operations required to cleanup bindings of the script language to the gui system objects, as set-up in the
|
---|
139 | earlier createBindings call.
|
---|
140 |
|
---|
141 | \return
|
---|
142 | Nothing.
|
---|
143 | */
|
---|
144 | virtual void destroyBindings(void) {}
|
---|
145 |
|
---|
146 | /*!
|
---|
147 | \brief
|
---|
148 | Return identification string for the ScriptModule. If the internal id string has not been
|
---|
149 | set by the ScriptModule creator, a generic string of "Unknown scripting module" will be returned.
|
---|
150 |
|
---|
151 | \return
|
---|
152 | String object holding a string that identifies the ScriptModule in use.
|
---|
153 | */
|
---|
154 | const String& getIdentifierString() const;
|
---|
155 |
|
---|
156 | protected:
|
---|
157 | String d_identifierString; //!< String that holds some id information about the module.
|
---|
158 | };
|
---|
159 |
|
---|
160 |
|
---|
161 | /*!
|
---|
162 | \brief
|
---|
163 | Functor class used for binding named script functions to events
|
---|
164 | */
|
---|
165 | class ScriptFunctor
|
---|
166 | {
|
---|
167 | public:
|
---|
168 | ScriptFunctor(const String& functionName) : scriptFunctionName(functionName) {}
|
---|
169 | ScriptFunctor(const ScriptFunctor& obj) : scriptFunctionName(obj.scriptFunctionName) {}
|
---|
170 | bool operator()(const EventArgs& e) const;
|
---|
171 |
|
---|
172 | private:
|
---|
173 | // no assignment possible
|
---|
174 | ScriptFunctor& operator=(const ScriptFunctor& rhs);
|
---|
175 |
|
---|
176 | const String scriptFunctionName;
|
---|
177 | };
|
---|
178 |
|
---|
179 | } // End of CEGUI namespace section
|
---|
180 |
|
---|
181 |
|
---|
182 | #endif // end of guard _CEGUIScriptModule_h_
|
---|