code cleanup: pass mouse position as int[2] rather then wmEvent
[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
30 ScaleNode::ScaleNode(bNode *editorNode) : Node(editorNode)
31 {
32         /* pass */
33 }
34
35 void ScaleNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
36 {
37         InputSocket *inputSocket = this->getInputSocket(0);
38         InputSocket *inputXSocket = this->getInputSocket(1);
39         InputSocket *inputYSocket = this->getInputSocket(2);
40         OutputSocket *outputSocket = this->getOutputSocket(0);
41         bNode *bnode = this->getbNode();
42         switch (bnode->custom1) {
43                 case CMP_SCALE_RELATIVE: {
44                         ScaleOperation *operation = new ScaleOperation();
45
46                         inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
47                         inputXSocket->relinkConnections(operation->getInputSocket(1), 1, graph);
48                         inputYSocket->relinkConnections(operation->getInputSocket(2), 2, graph);
49                         outputSocket->relinkConnections(operation->getOutputSocket(0));
50                         graph->addOperation(operation);
51                 }
52                 break;
53                 case CMP_SCALE_SCENEPERCENT: {
54                         SetValueOperation *scaleFactorOperation = new SetValueOperation();
55                         scaleFactorOperation->setValue(context->getRenderData()->size / 100.0f);
56                         ScaleOperation *operation = new ScaleOperation();
57                         inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
58                         addLink(graph, scaleFactorOperation->getOutputSocket(), operation->getInputSocket(1));
59                         addLink(graph, scaleFactorOperation->getOutputSocket(), operation->getInputSocket(2));
60                         outputSocket->relinkConnections(operation->getOutputSocket(0));
61                         graph->addOperation(scaleFactorOperation);
62                         graph->addOperation(operation);
63                 }
64                 break;
65
66                 case CMP_SCALE_RENDERPERCENT: {
67                         const RenderData *rd = context->getRenderData();
68                         ScaleFixedSizeOperation *operation = new ScaleFixedSizeOperation();
69
70                         /* framing options */
71                         operation->setIsAspect((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_ASPECT) != 0);
72                         operation->setIsCrop((bnode->custom2 & CMP_SCALE_RENDERSIZE_FRAME_CROP) != 0);
73                         operation->setOffset(bnode->custom3, bnode->custom4);
74
75                         operation->setNewWidth(rd->xsch * rd->size / 100.0f);
76                         operation->setNewHeight(rd->ysch * rd->size / 100.0f);
77                         inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
78                         outputSocket->relinkConnections(operation->getOutputSocket(0));
79                         operation->getInputSocket(0)->getConnection()->setIgnoreResizeCheck(true);
80                         graph->addOperation(operation);
81                 }
82                 break;
83
84                 case CMP_SCALE_ABSOLUTE: {
85                         ScaleAbsoluteOperation *operation = new ScaleAbsoluteOperation(); // TODO: what is the use of this one.... perhaps some issues when the ui was updated....
86
87                         inputSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
88                         inputXSocket->relinkConnections(operation->getInputSocket(1), 1, graph);
89                         inputYSocket->relinkConnections(operation->getInputSocket(2), 2, graph);
90                         outputSocket->relinkConnections(operation->getOutputSocket(0));
91                         graph->addOperation(operation);
92                 }
93                 break;
94         }
95 }