This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/nodes/composite/nodes/node_composite_switchview.c
Dalai Felinto be4b5551c7 Fix T51863: CompositorNodeSwitchView have the wrong rna API
Although the original report was about the docs, the real issue was in
the API.

My original commit started from a copy-paste from the Switch
Node. However I don't use custom1 for thew Switch View node.

The docs is slightly incomplete since it would be nice to mention the
views here. Or maybe even expose them via Python. But honestly they are
generated depending on the scene multi-view settings.
2017-06-22 10:25:05 +02:00

153 lines
4.1 KiB
C

/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2006 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s):
* Dalai Felinto
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/nodes/composite/nodes/node_composite_switchview.c
* \ingroup cmpnodes
*/
#include "BKE_context.h"
#include "../node_composite_util.h"
/* **************** SWITCH VIEW ******************** */
static bNodeSocketTemplate cmp_node_switch_view_out[] = {
{ SOCK_RGBA, 0, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeSocket *ntreeCompositSwitchViewAddSocket(bNodeTree *ntree, bNode *node, const char *name)
{
bNodeSocket *sock = nodeAddStaticSocket(ntree, node, SOCK_IN, SOCK_RGBA, PROP_NONE, NULL, name);
return sock;
}
static void cmp_node_switch_view_sanitycheck(bNodeTree *ntree, bNode *node)
{
bNodeSocket *sock;
if (!BLI_listbase_is_empty(&node->inputs))
return;
sock = ntreeCompositSwitchViewAddSocket(ntree, node, "No View");
sock->flag |= SOCK_HIDDEN;
}
static void cmp_node_switch_view_update(bNodeTree *ntree, bNode *node)
{
bNodeSocket *sock;
SceneRenderView *srv;
Scene *scene = (Scene *)node->id;
/* only update when called from the operator button */
if (node->update != NODE_UPDATE_OPERATOR)
return;
if (scene == NULL) {
nodeRemoveAllSockets(ntree, node);
/* make sure there is always one socket */
cmp_node_switch_view_sanitycheck(ntree, node);
return;
}
/* remove the views that were removed */
sock = node->inputs.last;
while (sock) {
srv = BLI_findstring(&scene->r.views, sock->name, offsetof(SceneRenderView, name));
if (srv == NULL) {
bNodeSocket *sock_del = sock;
sock = sock->prev;
nodeRemoveSocket(ntree, node, sock_del);
}
else {
if (srv->viewflag & SCE_VIEW_DISABLE)
sock->flag |= SOCK_HIDDEN;
else
sock->flag &= ~SOCK_HIDDEN;
sock = sock->prev;
}
}
/* add the new views */
for (srv = scene->r.views.first; srv; srv = srv->next) {
sock = BLI_findstring(&node->inputs, srv->name, offsetof(bNodeSocket, name));
if (sock == NULL)
sock = ntreeCompositSwitchViewAddSocket(ntree, node, srv->name);
if (srv->viewflag & SCE_VIEW_DISABLE)
sock->flag |= SOCK_HIDDEN;
else
sock->flag &= ~SOCK_HIDDEN;
}
/* make sure there is always one socket */
cmp_node_switch_view_sanitycheck(ntree, node);
}
static void init_switch_view(const bContext *C, PointerRNA *ptr)
{
Scene *scene = CTX_data_scene(C);
bNodeTree *ntree = ptr->id.data;
bNode *node = ptr->data;
SceneRenderView *srv;
bNodeSocket *sock;
int nr;
/* store scene for updates */
node->id = (ID *)scene;
if (scene) {
RenderData *rd = &scene->r;
for (nr = 0, srv = rd->views.first; srv; srv = srv->next, nr++) {
sock = ntreeCompositSwitchViewAddSocket(ntree, node, srv->name);
if ((srv->viewflag & SCE_VIEW_DISABLE))
sock->flag |= SOCK_HIDDEN;
}
}
/* make sure there is always one socket */
cmp_node_switch_view_sanitycheck(ntree, node);
}
void register_node_type_cmp_switch_view(void)
{
static bNodeType ntype;
cmp_node_type_base(&ntype, CMP_NODE_SWITCH_VIEW, "Switch View", NODE_CLASS_CONVERTOR, 0);
node_type_socket_templates(&ntype, NULL, cmp_node_switch_view_out);
ntype.initfunc_api = init_switch_view;
node_type_update(&ntype, cmp_node_switch_view_update, NULL);
nodeRegisterType(&ntype);
}