Cleanup: comment line length (editors)
[blender.git] / source / blender / compositor / nodes / COM_ScaleNode.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor:
19  *      Jeroen Bakker
20  *      Monique Dewanchand
21  */
22
23 #include "COM_ScaleNode.h"
24
25 #include "COM_ScaleOperation.h"
26 #include "COM_ExecutionSystem.h"
27 #include "BKE_node.h"
28 #include "COM_SetValueOperation.h"
29 #include "COM_SetSamplerOperation.h"
30
31 ScaleNode::ScaleNode(bNode *editorNode) : Node(editorNode)
32 {
33         /* pass */
34 }
35
36 void ScaleNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
37 {
38         bNode *bnode = this->getbNode();
39
40         NodeInput *inputSocket = this->getInputSocket(0);
41         NodeInput *inputXSocket = this->getInputSocket(1);
42         NodeInput *inputYSocket = this->getInputSocket(2);
43         NodeOutput *outputSocket = this->getOutputSocket(0);
44
45         switch (bnode->custom1) {
46                 case CMP_SCALE_RELATIVE:
47                 {
48                         ScaleOperation *operation = new ScaleOperation();
49                         converter.addOperation(operation);
50
51                         converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
52                         converter.mapInputSocket(inputXSocket, operation->getInputSocket(1));
53                         converter.mapInputSocket(inputYSocket, operation->getInputSocket(2));
54                         converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
55
56                         operation->setVariableSize(inputXSocket->isLinked() ||
57                                                    inputYSocket->isLinked());
58                         break;
59                 }
60                 case CMP_SCALE_SCENEPERCENT:
61                 {
62                         SetValueOperation *scaleFactorOperation = new SetValueOperation();
63                         scaleFactorOperation->setValue(context.getRenderData()->size / 100.0f);
64                         converter.addOperation(scaleFactorOperation);
65
66                         ScaleOperation *operation = new ScaleOperation();
67                         converter.addOperation(operation);
68
69                         converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
70                         converter.addLink(scaleFactorOperation->getOutputSocket(), operation->getInputSocket(1));
71                         converter.addLink(scaleFactorOperation->getOutputSocket(), operation->getInputSocket(2));
72                         converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
73
74                         operation->setVariableSize(inputXSocket->isLinked() ||
75                                                    inputYSocket->isLinked());
76
77                         break;
78                 }
79                 case CMP_SCALE_RENDERPERCENT:
80                 {
81                         const RenderData *rd = context.getRenderData();
82                         ScaleFixedSizeOperation *operation = new ScaleFixedSizeOperation();
83                         /* framing options */
84                         operation->setIsAspect((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) != 0);
85                         operation->setIsCrop((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0);
86                         operation->setOffset(bnode->custom3, bnode->custom4);
87                         operation->setNewWidth(rd->xsch * rd->size / 100.0f);
88                         operation->setNewHeight(rd->ysch * rd->size / 100.0f);
89                         operation->getInputSocket(0)->setResizeMode(COM_SC_NO_RESIZE);
90                         converter.addOperation(operation);
91
92                         converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
93                         converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
94
95                         operation->setVariableSize(inputXSocket->isLinked() ||
96                                                    inputYSocket->isLinked());
97
98                         break;
99                 }
100                 case CMP_SCALE_ABSOLUTE:
101                 {
102                         /* TODO: what is the use of this one.... perhaps some issues when the ui was updated... */
103                         ScaleAbsoluteOperation *operation = new ScaleAbsoluteOperation();
104                         converter.addOperation(operation);
105
106                         converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
107                         converter.mapInputSocket(inputXSocket, operation->getInputSocket(1));
108                         converter.mapInputSocket(inputYSocket, operation->getInputSocket(2));
109                         converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
110
111                         operation->setVariableSize(inputXSocket->isLinked() ||
112                                                    inputYSocket->isLinked());
113
114                         break;
115                 }
116         }
117 }