Filling in branch from trunk
[blender.git] / source / gameengine / Ketsji / KX_VisibilityActuator.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  * Actuator to toggle visibility/invisibility of objects
32  */
33
34 #include "KX_VisibilityActuator.h"
35 #include "KX_GameObject.h"
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 KX_VisibilityActuator::KX_VisibilityActuator(
42         SCA_IObject* gameobj,
43         bool visible,
44         PyTypeObject* T
45         ) 
46         : SCA_IActuator(gameobj,T),
47           m_visible(visible)
48 {
49         // intentionally empty
50 }
51
52 KX_VisibilityActuator::~KX_VisibilityActuator(
53         void
54         )
55 {
56         // intentionally empty
57 }
58
59 CValue*
60 KX_VisibilityActuator::GetReplica(
61         void
62         )
63 {
64         KX_VisibilityActuator* replica = new KX_VisibilityActuator(*this);
65         replica->ProcessReplica();
66         // this will copy properties and so on...
67         CValue::AddDataToReplica(replica);
68         return replica;
69 }
70
71 bool
72 KX_VisibilityActuator::Update()
73 {
74         bool bNegativeEvent = IsNegativeEvent();
75         
76         RemoveAllEvents();
77         if (bNegativeEvent) return false;
78
79         KX_GameObject *obj = (KX_GameObject*) GetParent();
80         
81         obj->SetVisible(m_visible);
82         obj->MarkVisible();
83
84         return true;
85 }
86
87 /* ------------------------------------------------------------------------- */
88 /* Python functions                                                          */
89 /* ------------------------------------------------------------------------- */
90
91
92
93 /* Integration hooks ------------------------------------------------------- */
94 PyTypeObject 
95 KX_VisibilityActuator::Type = {
96         PyObject_HEAD_INIT(&PyType_Type)
97         0,
98         "KX_VisibilityActuator",
99         sizeof(KX_VisibilityActuator),
100         0,
101         PyDestructor,
102         0,
103         __getattr,
104         __setattr,
105         0, //&MyPyCompare,
106         __repr,
107         0, //&cvalue_as_number,
108         0,
109         0,
110         0,
111         0
112 };
113
114 PyParentObject 
115 KX_VisibilityActuator::Parents[] = {
116         &KX_VisibilityActuator::Type,
117         &SCA_IActuator::Type,
118         &SCA_ILogicBrick::Type,
119         &CValue::Type,
120         NULL
121 };
122
123 PyMethodDef 
124 KX_VisibilityActuator::Methods[] = {
125         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, 
126          METH_VARARGS, SetVisible_doc},
127         {NULL,NULL} //Sentinel
128 };
129
130 PyObject* 
131 KX_VisibilityActuator::_getattr(
132         const STR_String& attr
133         ) 
134 {
135         _getattr_up(SCA_IActuator);
136 };
137
138
139
140 /* set visibility ---------------------------------------------------------- */
141 char 
142 KX_VisibilityActuator::SetVisible_doc[] = 
143 "setVisible(visible?)\n"
144 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
145 "\tSet the properties of the actuator.\n";
146 PyObject* 
147
148 KX_VisibilityActuator::PySetVisible(PyObject* self, 
149                                     PyObject* args, 
150                                     PyObject* kwds) {
151         int vis;
152
153         if(!PyArg_ParseTuple(args, "i", &vis)) {
154                 return NULL;
155         }
156
157         m_visible = PyArgToBool(vis);
158
159         Py_Return;
160 }
161
162