svn merge -r 17502:18705 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / gameengine / GameLogic / SCA_2DFilterActuator.cpp
1 #include "SCA_IActuator.h"
2
3 #include "SCA_2DFilterActuator.h"
4
5 #ifdef HAVE_CONFIG_H
6 #include <config.h>
7 #endif
8 #include <iostream>
9
10 SCA_2DFilterActuator::~SCA_2DFilterActuator()
11 {
12 }
13
14 SCA_2DFilterActuator::SCA_2DFilterActuator(
15         SCA_IObject *gameobj, 
16         RAS_2DFilterManager::RAS_2DFILTER_MODE type,
17                 short flag,
18                 float float_arg,
19                 int int_arg,
20                 RAS_IRasterizer* rasterizer,
21                 RAS_IRenderTools* rendertools,
22         PyTypeObject* T)
23     : SCA_IActuator(gameobj, T),
24      m_type(type),
25          m_flag(flag),
26          m_float_arg(float_arg),
27          m_int_arg(int_arg),
28          m_rasterizer(rasterizer),
29          m_rendertools(rendertools)
30 {
31         m_gameObj = NULL;
32         if(gameobj){
33                 m_propNames = gameobj->GetPropertyNames();
34                 m_gameObj = gameobj;
35         }
36 }
37
38 void SCA_2DFilterActuator::SetShaderText(STR_String text)
39 {
40         m_shaderText = text;
41 }
42
43
44
45 CValue* SCA_2DFilterActuator::GetReplica()
46 {
47     SCA_2DFilterActuator* replica = new SCA_2DFilterActuator(*this);
48     replica->ProcessReplica();
49     CValue::AddDataToReplica(replica);
50
51     return replica;
52 }
53
54
55 bool SCA_2DFilterActuator::Update()
56 {
57         bool bNegativeEvent = IsNegativeEvent();
58         RemoveAllEvents();
59
60
61         if (bNegativeEvent)
62                 return false; // do nothing on negative events
63
64         if( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR )
65         {
66                 if(!m_flag)
67                         m_rasterizer->EnableMotionBlur(m_float_arg);
68                 else
69                         m_rasterizer->DisableMotionBlur();
70
71                 return false;
72         }
73         else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS)
74         {
75                 m_rendertools->Update2DFilter(m_propNames, m_gameObj, m_type, m_int_arg, m_shaderText);
76         }
77         // once the filter is in place, no need to update it again => disable the actuator
78     return false;
79 }
80
81
82 PyTypeObject SCA_2DFilterActuator::Type = {
83         PyObject_HEAD_INIT(&PyType_Type)
84         0,
85         "SCA_2DFilterActuator",
86         sizeof(SCA_2DFilterActuator),
87         0,
88         PyDestructor,
89         0,
90         __getattr,
91         __setattr,
92         0, 
93          __repr,
94         0,
95         0,
96         0,
97         0,
98         0
99 };
100
101
102 PyParentObject SCA_2DFilterActuator::Parents[] = {
103         &SCA_2DFilterActuator::Type,
104         &SCA_IActuator::Type,
105         &SCA_ILogicBrick::Type,
106         &CValue::Type,
107         NULL
108 };
109
110
111 PyMethodDef SCA_2DFilterActuator::Methods[] = {
112     /* add python functions to deal with m_msg... */
113     {NULL,NULL}
114 };
115
116
117 PyObject* SCA_2DFilterActuator::_getattr(const STR_String& attr) {
118     _getattr_up(SCA_IActuator);
119 }