Christmas coding work!

********* Node editor work:

- To enable Nodes for Materials, you have to set the "Use Nodes"
  button, in the new Material buttons "Nodes" Panel or in header
  of the Node editor. Doing this will disable Material-Layers.

- Nodes now execute materials ("shaders"), but still only using the
  previewrender code.

- Nodes have (optional) previews for rendered images.

- Node headers allow to hide buttons and/or preview image

- Nodes can be dragged larger/smaller (right-bottom corner)

- Nodes can be hidden (minimized) with hotkey H

- CTRL+click on an Input Socket gives a popup with default values.

- Changing Material/Texture or Mix node will adjust Node title.

- Click-drag outside of a Node changes cursor to "Knife' and allows to
  draw a rect where to cut Links.

- Added new node types RGBtoBW, Texture, In/Output, ColorRamp

- Material Nodes have options to ouput diffuse or specular, or to use
  a negative normal. The input socket 'Normal' will force the material
  to use that normal, otherwise it uses the normal from the Material
  that has the node tree.

- When drawing a link between two not-matching sockets, Blender inserts
  a converting node (now only for value/rgb combos)

- When drawing a link to an input socket that's already in use, the
  old link will either disappear or flip to another unused socket.

- A click on a Material Node will activate it, and show all its settings
  in the Material Buttons. Active Material Nodes draw the material icon
  in red.

- A click on any node will show its options in the Node Panel in the
  Material buttons.

- Multiple Output Nodes can be used, to sample contents of a tree, but
  only one Output is the real one, which is indicated in a different
  color and red material icon.

- Added ThemeColors for node types

- ALT+C will convert existing Material-Layers to Node... this currently
  only adds the material/mix nodes and connects them. Dunno if this is
  worth a lot of coding work to make perfect?

- Press C to call another "Solve order", which will show all possible
  cyclic conflicts (if there are).

- Technical: nodes now use "Type" structs which define the
  structure of nodes and in/output sockets. The Type structs store all
  fixed info, callbacks, and allow to reconstruct saved Nodes to match
  what is required by Blender.

- Defining (new) nodes now is as simple as filling in a fixed
  Type struct, plus code some callbacks. A doc will be made!

- Node preview images are by default float

********* Icon drawing:

- Cleanup of how old icons were implemented in new system, making
  them 16x16 too, correctly centered *and* scaled.

- Made drawing Icons use float coordinates

- Moved BIF_calcpreview_image() into interface_icons.c, renamed it
  icon_from_image(). Removed a lot of unneeded Imbuf magic here! :)

- Skipped scaling and imbuf copying when icons are OK size


********* Preview render:

- Huge cleanup of code....

- renaming BIF_xxx calls that only were used internally

- BIF_previewrender() now accepts an argument for rendering method,
  so it supports icons, buttonwindow previewrender and node editor

- Only a single BIF_preview_changed() call now exists, supporting all
  signals as needed for buttos and node editor


********* More stuff:

- glutil.c, glaDrawPixelsSafe() and glaDrawPixelsTex() now accept format
  argument for GL_FLOAT rects

- Made the ColorBand become a built-in button for interface.c
  Was a load of cleanup work in buttons_shading.c...

- removed a load of unneeded glBlendFunc() calls

- Fixed bug in calculating text length for buttons (ancient!)
This commit is contained in:
2005-12-28 15:42:51 +00:00
parent 7837866b1e
commit 9df1460777
52 changed files with 4884 additions and 3017 deletions

View File

@@ -37,40 +37,113 @@ struct bNodeTree;
struct bNode; struct bNode;
struct bNodeLink; struct bNodeLink;
struct bNodeSocket; struct bNodeSocket;
struct bNodeStack;
struct uiBlock;
struct rctf;
struct ListBase; struct ListBase;
#define SOCK_IN 1 #define SOCK_IN 1
#define SOCK_OUT 2 #define SOCK_OUT 2
/* ************** NODE TYPE DEFINITIONS ***** */
/* ************** GENERIC API *************** */ typedef struct bNodeSocketType {
int type, limit;
char *name;
float val1, val2, val3, val4; /* default alloc value for inputs */
float min, max; /* default range for inputs */
/* after this line is used internal only */
struct bNodeSocket *sock; /* to verify */
} bNodeSocketType;
typedef struct bNodeType {
int type;
char *name;
float width, minwidth, maxwidth;
short nclass, flag;
bNodeSocketType *inputs, *outputs;
char storagename[64]; /* struct name for DNA */
void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **);
/* after this line is set on startup of blender */
int (*butfunc)(struct uiBlock *, struct bNode *, rctf *);
} bNodeType;
/* nodetype->nclass, also for themes */
#define NODE_CLASS_INPUT 0
#define NODE_CLASS_OUTPUT 1
#define NODE_CLASS_GENERATOR 2
#define NODE_CLASS_OPERATOR 3
/* ************** GENERIC API, TREES *************** */
struct bNodeTree *ntreeAddTree(int type);
void ntreeInitTypes(struct bNodeTree *ntree);
void ntreeFreeTree(struct bNodeTree *ntree);
struct bNodeTree *ntreeCopyTree(struct bNodeTree *ntree, int internal_select);
void ntreeSolveOrder(struct bNodeTree *ntree);
void ntreeBeginExecTree(struct bNodeTree *ntree, int xsize, int ysize);
void ntreeExecTree(struct bNodeTree *ntree);
void ntreeEndExecTree(struct bNodeTree *ntree);
void ntreeClearPixelTree(struct bNodeTree *, int, int);
/* ************** GENERIC API, NODES *************** */
void nodeAddToPreview(struct bNode *, float *, int, int);
struct bNode *nodeAddNodeType(struct bNodeTree *ntree, int type);
void nodeFreeNode(struct bNodeTree *ntree, struct bNode *node); void nodeFreeNode(struct bNodeTree *ntree, struct bNode *node);
void nodeFreeTree(struct bNodeTree *ntree);
struct bNode *nodeAddNode(struct bNodeTree *ntree, char *name);
struct bNodeLink *nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock);
struct bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node); struct bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node);
struct bNodeSocket *nodeAddSocket(struct bNode *node, int type, int where, int limit, char *name); struct bNodeLink *nodeAddLink(struct bNodeTree *ntree, struct bNode *fromnode, struct bNodeSocket *fromsock, struct bNode *tonode, struct bNodeSocket *tosock);
void nodeRemLink(struct bNodeTree *ntree, struct bNodeLink *link);
struct bNodeLink *nodeFindLink(struct bNodeTree *ntree, struct bNodeSocket *from, struct bNodeSocket *to); struct bNodeLink *nodeFindLink(struct bNodeTree *ntree, struct bNodeSocket *from, struct bNodeSocket *to);
int nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock); int nodeCountSocketLinks(struct bNodeTree *ntree, struct bNodeSocket *sock);
struct bNode *nodeGetActive(struct bNodeTree *ntree);
void nodeSolveOrder(struct bNodeTree *ntree); struct bNode *nodeGetActiveID(struct bNodeTree *ntree, short idtype);
void nodeExecTree(struct bNodeTree *ntree);
/* ************** SHADER NODES *************** */ /* ************** SHADER NODES *************** */
/* types are needed to restore callbacks */ struct ShadeInput;
#define SH_NODE_TEST 0 struct ShadeResult;
#define SH_NODE_RGB 1
#define SH_NODE_VALUE 2
#define SH_NODE_MIX_RGB 3
#define SH_NODE_SHOW_RGB 4
struct bNode *node_shader_add(struct bNodeTree *ntree, int type); /* note: types are needed to restore callbacks, don't change values */
void node_shader_set_execfunc(struct bNode *node); #define SH_NODE_INPUT 0
#define SH_NODE_OUTPUT 1
#define SH_NODE_MATERIAL 100
#define SH_NODE_RGB 101
#define SH_NODE_VALUE 102
#define SH_NODE_MIX_RGB 103
#define SH_NODE_VALTORGB 104
#define SH_NODE_RGBTOBW 105
#define SH_NODE_TEXTURE 106
/* custom defines: options for Material node */
#define SH_NODE_MAT_DIFF 1
#define SH_NODE_MAT_SPEC 2
#define SH_NODE_MAT_NEG 4
/* the type definitions array */
extern bNodeType *node_all_shaders[];
/* API */
struct bNode *nodeShaderAdd(struct bNodeTree *ntree, int type);
void nodeShaderSetExecfunc(struct bNode *node);
void ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr);
/* switch material render loop */
void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *));
#endif #endif

View File

@@ -50,7 +50,7 @@ int test_dlerr(const char *name, const char *symbol);
void open_plugin_tex(struct PluginTex *pit); void open_plugin_tex(struct PluginTex *pit);
struct PluginTex *add_plugin_tex(char *str); struct PluginTex *add_plugin_tex(char *str);
void free_plugin_tex(struct PluginTex *pit); void free_plugin_tex(struct PluginTex *pit);
struct ColorBand *add_colorband(void); struct ColorBand *add_colorband(int rangetype);
int do_colorband(struct ColorBand *coba, float in, float out[4]); int do_colorband(struct ColorBand *coba, float in, float out[4]);
void default_tex(struct Tex *tex); void default_tex(struct Tex *tex);
struct Tex *add_texture(char *name); struct Tex *add_texture(char *name);

View File

@@ -40,6 +40,7 @@
#include "DNA_material_types.h" #include "DNA_material_types.h"
#include "DNA_mesh_types.h" #include "DNA_mesh_types.h"
#include "DNA_meta_types.h" #include "DNA_meta_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
#include "DNA_texture_types.h" #include "DNA_texture_types.h"
@@ -55,6 +56,7 @@
#include "BKE_main.h" #include "BKE_main.h"
#include "BKE_material.h" #include "BKE_material.h"
#include "BKE_mesh.h" #include "BKE_mesh.h"
#include "BKE_node.h"
#include "BKE_utildefines.h" #include "BKE_utildefines.h"
#include "BPY_extern.h" #include "BPY_extern.h"
@@ -84,6 +86,10 @@ void free_material(Material *ma)
if(ml->mat) ml->mat->id.us--; if(ml->mat) ml->mat->id.us--;
BLI_freelistN(&ma->layers); BLI_freelistN(&ma->layers);
if(ma->nodetree)
ntreeFreeTree(ma->nodetree);
} }
void init_material(Material *ma) void init_material(Material *ma)
@@ -169,6 +175,10 @@ Material *copy_material(Material *ma)
for(ml= man->layers.first; ml; ml= ml->next) for(ml= man->layers.first; ml; ml= ml->next)
id_us_plus((ID *)ml->mat); id_us_plus((ID *)ml->mat);
if(ma->nodetree) {
man->nodetree= ntreeCopyTree(ma->nodetree, 0); /* 0 == full new tree */
}
return man; return man;
} }
@@ -567,16 +577,25 @@ void new_material_to_objectdata(Object *ob)
ob->actcol= ob->totcol; ob->actcol= ob->totcol;
} }
/* will be renamed... now easy to re-use for nodes! */
Material *get_active_matlayer(Material *ma) Material *get_active_matlayer(Material *ma)
{ {
MaterialLayer *ml;
if(ma==NULL) return NULL; if(ma==NULL) return NULL;
for(ml= ma->layers.first; ml; ml= ml->next) if(ma->use_nodes) {
if(ml->flag & ML_ACTIVE) break; bNode *node= nodeGetActiveID(ma->nodetree, ID_MA);
if(ml) if(node && node->id) {
return ml->mat; return (Material *)node->id;
}
}
else {
MaterialLayer *ml;
for(ml= ma->layers.first; ml; ml= ml->next)
if(ml->flag & ML_ACTIVE) break;
if(ml)
return ml->mat;
}
return ma; return ma;
} }

View File

@@ -28,33 +28,197 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "DNA_ID.h" #include "DNA_ID.h"
#include "DNA_node_types.h" #include "DNA_node_types.h"
#include "BKE_blender.h" #include "BKE_blender.h"
#include "BKE_node.h" #include "BKE_node.h"
#include "BKE_utildefines.h"
#include "BLI_arithb.h" #include "BLI_arithb.h"
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
/* ************** Type stuff ********** */
static bNodeType *nodeGetType(bNodeTree *ntree, int type)
{
bNodeType **typedefs= ntree->alltypes;
while( *typedefs && (*typedefs)->type!=type)
typedefs++;
return *typedefs;
}
void ntreeInitTypes(bNodeTree *ntree)
{
bNode *node;
if(ntree->type==NTREE_SHADER)
ntree->alltypes= node_all_shaders;
else {
ntree->alltypes= NULL;
printf("Error: no type definitions for nodes\n");
}
for(node= ntree->nodes.first; node; node= node->next) {
node->typeinfo= nodeGetType(ntree, node->type);
if(node->typeinfo==NULL)
printf("Error: no typeinfo for node %s\n", node->name);
}
ntree->init |= NTREE_TYPE_INIT;
}
/* only used internal... we depend on type definitions! */
static bNodeSocket *node_add_socket_type(ListBase *lb, bNodeSocketType *stype)
{
bNodeSocket *sock= MEM_callocN(sizeof(bNodeSocket), "sock");
BLI_strncpy(sock->name, stype->name, NODE_MAXSTR);
if(stype->limit==0) sock->limit= 0xFFF;
else sock->limit= stype->limit;
sock->type= stype->type;
sock->ns.vec[0]= stype->val1;
sock->ns.vec[1]= stype->val2;
sock->ns.vec[2]= stype->val3;
sock->ns.vec[3]= stype->val4;
if(lb)
BLI_addtail(lb, sock);
return sock;
}
static void node_rem_socket(bNodeTree *ntree, ListBase *lb, bNodeSocket *sock)
{
bNodeLink *link, *next;
for(link= ntree->links.first; link; link= next) {
next= link->next;
if(link->fromsock==sock || link->tosock==sock) {
nodeRemLink(ntree, link);
}
}
BLI_remlink(lb, sock);
MEM_freeN(sock);
}
static bNodeSocket *verify_socket(ListBase *lb, bNodeSocketType *stype)
{
bNodeSocket *sock;
for(sock= lb->first; sock; sock= sock->next) {
if(strncmp(sock->name, stype->name, NODE_MAXSTR)==0)
break;
}
if(sock) {
sock->type= stype->type; /* in future, read this from tydefs! */
if(stype->limit==0) sock->limit= 0xFFF;
else sock->limit= stype->limit;
BLI_remlink(lb, sock);
return sock;
}
else {
return node_add_socket_type(NULL, stype);
}
}
static void verify_socket_list(bNodeTree *ntree, ListBase *lb, bNodeSocketType *stype_first)
{
bNodeSocketType *stype;
/* no inputs anymore? */
if(stype_first==NULL) {
while(lb->first)
node_rem_socket(ntree, lb, lb->first);
}
else {
/* step by step compare */
stype= stype_first;
while(stype->type != -1) {
stype->sock= verify_socket(lb, stype);
stype++;
}
/* leftovers are removed */
while(lb->first)
node_rem_socket(ntree, lb, lb->first);
/* and we put back the verified sockets */
stype= stype_first;
while(stype->type != -1) {
BLI_addtail(lb, stype->sock);
stype++;
}
}
}
void ntreeVerifyTypes(bNodeTree *ntree)
{
bNode *node;
bNodeType *ntype;
if((ntree->init & NTREE_TYPE_INIT)==0)
ntreeInitTypes(ntree);
/* check inputs and outputs, and remove or insert them */
for(node= ntree->nodes.first; node; node= node->next) {
ntype= node->typeinfo;
if(ntype) {
/* might add some other verify stuff here */
verify_socket_list(ntree, &node->inputs, ntype->inputs);
verify_socket_list(ntree, &node->outputs, ntype->outputs);
}
}
}
/* ************** Add stuff ********** */ /* ************** Add stuff ********** */
/* not very important, but the stack solver likes to know a maximum */ /* not very important, but the stack solver likes to know a maximum */
#define MAX_SOCKET 64 #define MAX_SOCKET 64
bNode *nodeAddNode(struct bNodeTree *ntree, char *name) bNode *nodeAddNodeType(bNodeTree *ntree, int type)
{ {
bNode *node= MEM_callocN(sizeof(bNode), "new node"); bNode *node;
bNodeType *ntype= nodeGetType(ntree, type);
bNodeSocketType *stype;
node= MEM_callocN(sizeof(bNode), "new node");
BLI_addtail(&ntree->nodes, node); BLI_addtail(&ntree->nodes, node);
BLI_strncpy(node->name, name, NODE_MAXSTR); node->typeinfo= ntype;
BLI_strncpy(node->name, ntype->name, NODE_MAXSTR);
node->type= ntype->type;
node->flag= NODE_SELECT|ntype->flag;
node->width= ntype->width;
if(ntype->inputs) {
stype= ntype->inputs;
while(stype->type != -1) {
node_add_socket_type(&node->inputs, stype);
stype++;
}
}
if(ntype->outputs) {
stype= ntype->outputs;
while(stype->type != -1) {
node_add_socket_type(&node->outputs, stype);
stype++;
}
}
return node; return node;
} }
/* keep listorder identical, for copying links */ /* keep socket listorder identical, for copying links */
/* ntree is the target tree */
bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node) bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node)
{ {
bNode *nnode= MEM_callocN(sizeof(bNode), "dupli node"); bNode *nnode= MEM_callocN(sizeof(bNode), "dupli node");
@@ -67,8 +231,13 @@ bNode *nodeCopyNode(struct bNodeTree *ntree, struct bNode *node)
if(nnode->id) if(nnode->id)
nnode->id->us++; nnode->id->us++;
node->flag= NODE_SELECT; if(nnode->storage)
nnode->storage= MEM_dupallocN(nnode->storage);
node->new= nnode;
nnode->new= NULL;
nnode->preview= NULL;
return nnode; return nnode;
} }
@@ -85,19 +254,22 @@ bNodeLink *nodeAddLink(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock,
return link; return link;
} }
bNodeSocket *nodeAddSocket(bNode *node, int type, int where, int limit, char *name) void nodeRemLink(bNodeTree *ntree, bNodeLink *link)
{ {
bNodeSocket *sock= MEM_callocN(sizeof(bNodeSocket), "sock"); BLI_remlink(&ntree->links, link);
if(link->tosock)
link->tosock->link= NULL;
MEM_freeN(link);
}
bNodeTree *ntreeAddTree(int type)
{
bNodeTree *ntree= MEM_callocN(sizeof(bNodeTree), "new node tree");
ntree->type= type;
BLI_strncpy(sock->name, name, NODE_MAXSTR); ntreeInitTypes(ntree);
sock->limit= limit; return ntree;
sock->type= type;
if(where==SOCK_IN)
BLI_addtail(&node->inputs, sock);
else
BLI_addtail(&node->outputs, sock);
return sock;
} }
/* ************** Free stuff ********** */ /* ************** Free stuff ********** */
@@ -125,8 +297,7 @@ static void node_unlink_node(bNodeTree *ntree, bNode *node)
break; break;
} }
if(sock) { if(sock) {
BLI_remlink(&ntree->links, link); nodeRemLink(ntree, link);
MEM_freeN(link);
} }
} }
} }
@@ -144,10 +315,18 @@ void nodeFreeNode(bNodeTree *ntree, bNode *node)
BLI_freelistN(&node->inputs); BLI_freelistN(&node->inputs);
BLI_freelistN(&node->outputs); BLI_freelistN(&node->outputs);
if(node->preview) {
if(node->preview->rect)
MEM_freeN(node->preview->rect);
MEM_freeN(node->preview);
}
if(node->storage)
MEM_freeN(node->storage);
MEM_freeN(node); MEM_freeN(node);
} }
void nodeFreeTree(bNodeTree *ntree) void ntreeFreeTree(bNodeTree *ntree)
{ {
bNode *node, *next; bNode *node, *next;
@@ -156,12 +335,64 @@ void nodeFreeTree(bNodeTree *ntree)
nodeFreeNode(NULL, node); /* NULL -> no unlinking needed */ nodeFreeNode(NULL, node); /* NULL -> no unlinking needed */
} }
BLI_freelistN(&ntree->links); BLI_freelistN(&ntree->links);
BLI_freelistN(&ntree->inputs);
BLI_freelistN(&ntree->outputs);
MEM_freeN(ntree); MEM_freeN(ntree);
} }
bNodeTree *ntreeCopyTree(bNodeTree *ntree, int internal_select)
{
bNodeTree *newtree;
bNode *node, *nnode, *last;
bNodeLink *link, *nlink;
bNodeSocket *sock;
int a;
if(ntree==NULL) return NULL;
if(internal_select==0) {
newtree= MEM_dupallocN(ntree);
newtree->nodes.first= newtree->nodes.last= NULL;
newtree->links.first= newtree->links.last= NULL;
}
else
newtree= ntree;
last= ntree->nodes.last;
for(node= ntree->nodes.first; node; node= node->next) {
node->new= NULL;
if(internal_select==0 || (node->flag & NODE_SELECT)) {
nnode= nodeCopyNode(newtree, node); /* sets node->new */
if(internal_select) {
node->flag &= ~NODE_SELECT;
nnode->flag |= NODE_SELECT;
}
node->flag &= ~NODE_ACTIVE;
}
if(node==last) break;
}
/* check for copying links */
for(link= ntree->links.first; link; link= link->next) {
if(link->fromnode->new && link->tonode->new) {
nlink= nodeAddLink(newtree, link->fromnode->new, NULL, link->tonode->new, NULL);
/* sockets were copied in order */
for(a=0, sock= link->fromnode->outputs.first; sock; sock= sock->next, a++) {
if(sock==link->fromsock)
break;
}
nlink->fromsock= BLI_findlink(&link->fromnode->new->outputs, a);
for(a=0, sock= link->tonode->inputs.first; sock; sock= sock->next, a++) {
if(sock==link->tosock)
break;
}
nlink->tosock= BLI_findlink(&link->tonode->new->inputs, a);
}
}
return newtree;
}
/* ************ find stuff *************** */ /* ************ find stuff *************** */
bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to) bNodeLink *nodeFindLink(bNodeTree *ntree, bNodeSocket *from, bNodeSocket *to)
@@ -189,6 +420,31 @@ int nodeCountSocketLinks(bNodeTree *ntree, bNodeSocket *sock)
return tot; return tot;
} }
bNode *nodeGetActive(bNodeTree *ntree)
{
bNode *node;
if(ntree==NULL) return NULL;
for(node= ntree->nodes.first; node; node= node->next)
if(node->flag & NODE_ACTIVE)
break;
return node;
}
bNode *nodeGetActiveID(bNodeTree *ntree, short idtype)
{
bNode *node;
if(ntree==NULL) return NULL;
for(node= ntree->nodes.first; node; node= node->next)
if(node->id && GS(node->id->name)==idtype)
if(node->flag & NODE_ACTIVE_ID)
break;
return node;
}
/* ************** dependency stuff *********** */ /* ************** dependency stuff *********** */
/* node is guaranteed to be not checked before */ /* node is guaranteed to be not checked before */
@@ -220,7 +476,7 @@ static int node_recurs_check(bNode *node, bNode ***nsort, int level)
return 0xFFF; return 0xFFF;
} }
void nodeSolveOrder(bNodeTree *ntree) void ntreeSolveOrder(bNodeTree *ntree)
{ {
bNode *node, **nodesort, **nsort; bNode *node, **nodesort, **nsort;
bNodeSocket *sock; bNodeSocket *sock;
@@ -266,78 +522,164 @@ void nodeSolveOrder(bNodeTree *ntree)
MEM_freeN(nodesort); MEM_freeN(nodesort);
/* find the active outputs, tree type dependant, might become handler */
if(ntree->type==NTREE_SHADER) {
/* shader nodes only accepts one output */
int output= 0;
for(node= ntree->nodes.first; node; node= node->next) {
if(node->typeinfo->nclass==NODE_CLASS_OUTPUT) {
if(output==0)
node->flag |= NODE_DO_OUTPUT;
else
node->flag &= ~NODE_DO_OUTPUT;
output= 1;
}
}
}
/* here we could recursively set which nodes have to be done,
might be different for editor or for "real" use... */
} }
/* *************** preview *********** */
/* if node->preview, then we assume the rect to exist */
static void nodeInitPreview(bNode *node, int xsize, int ysize)
{
/* signal we don't do anything, preview writing is protected */
if(xsize==0 || ysize==0)
return;
/* sanity checks & initialize */
if(node->preview) {
if(node->preview->xsize!=xsize && node->preview->ysize!=ysize) {
MEM_freeN(node->preview->rect);
node->preview->rect= NULL;
}
}
if(node->preview==NULL) {
node->preview= MEM_callocN(sizeof(bNodePreview), "node preview");
}
if(node->preview->rect==NULL) {
node->preview->rect= MEM_callocN(4*xsize + xsize*ysize*sizeof(float)*4, "node preview rect");
node->preview->xsize= xsize;
node->preview->ysize= ysize;
}
}
void nodeAddToPreview(bNode *node, float *col, int x, int y)
{
bNodePreview *preview= node->preview;
if(preview) {
if(x>=0 && y>=0) {
if(x<preview->xsize && y<preview->ysize) {
float *tar= preview->rect+ 4*((preview->xsize*y) + x);
QUATCOPY(tar, col);
}
else printf("prv out bound x y %d %d\n", x, y);
}
else printf("prv out bound x y %d %d\n", x, y);
}
}
/* ******************* executing ************* */ /* ******************* executing ************* */
void nodeBeginExecTree(bNodeTree *ntree) void ntreeBeginExecTree(bNodeTree *ntree, int xsize, int ysize)
{ {
bNode *node; bNode *node;
bNodeSocket *sock; bNodeSocket *sock;
int index= 0; int index= 0;
if((ntree->init & NTREE_EXEC_SET)==0) { if((ntree->init & NTREE_TYPE_INIT)==0)
for(node= ntree->nodes.first; node; node= node->next) { ntreeInitTypes(ntree);
if(ntree->type==NTREE_SHADER)
node_shader_set_execfunc(node);
}
ntree->init |= NTREE_EXEC_SET;
}
/* create indices for stack */ /* create indices for stack, check preview */
for(node= ntree->nodes.first; node; node= node->next) { for(node= ntree->nodes.first; node; node= node->next) {
for(sock= node->outputs.first; sock; sock= sock->next) { for(sock= node->outputs.first; sock; sock= sock->next) {
sock->stack_index= index++; sock->stack_index= index++;
} }
if(node->typeinfo->flag & NODE_PREVIEW) /* hrms, check for closed nodes? */
nodeInitPreview(node, xsize, ysize);
} }
if(index) { if(index) {
ntree->stack= MEM_callocN(index*sizeof(bNodeStack), "node stack"); bNodeStack *ns;
int a;
ns=ntree->stack= MEM_callocN(index*sizeof(bNodeStack), "node stack");
for(a=0; a<index; a++, ns++) ns->hasinput= 1;
} }
ntree->init |= NTREE_EXEC_INIT;
} }
void nodeEndExecTree(bNodeTree *ntree) void ntreeEndExecTree(bNodeTree *ntree)
{ {
if(ntree->stack) { if(ntree->stack) {
MEM_freeN(ntree->stack); MEM_freeN(ntree->stack);
ntree->stack= NULL; ntree->stack= NULL;
} }
ntree->init &= ~NTREE_EXEC_INIT;
} }
static void node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **spp) static void node_get_stack(bNode *node, bNodeStack *stack, bNodeStack **in, bNodeStack **out)
{ {
static bNodeStack empty= {{1.0f, 1.0f, 1.0f, 1.0f}, NULL};
bNodeSocket *sock; bNodeSocket *sock;
/* build pointer stack */ /* build pointer stack */
for(sock= node->inputs.first; sock; sock= sock->next) { for(sock= node->inputs.first; sock; sock= sock->next) {
if(sock->link) if(sock->link)
*(spp++)= stack + sock->link->fromsock->stack_index; *(in++)= stack + sock->link->fromsock->stack_index;
else else
*(spp++)= &empty; /* input is not written into */ *(in++)= &sock->ns;
} }
for(sock= node->outputs.first; sock; sock= sock->next) { for(sock= node->outputs.first; sock; sock= sock->next) {
*(spp++)= stack + sock->stack_index; *(out++)= stack + sock->stack_index;
} }
} }
/* nodes are presorted, so exec is in order of list */ /* nodes are presorted, so exec is in order of list */
void nodeExecTree(bNodeTree *ntree) void ntreeExecTree(bNodeTree *ntree)
{ {
bNode *node; bNode *node;
bNodeStack *ns[MAX_SOCKET]; /* arbitrary... watch this */ bNodeStack *nsin[MAX_SOCKET]; /* arbitrary... watch this */
bNodeStack *nsout[MAX_SOCKET]; /* arbitrary... watch this */
nodeBeginExecTree(ntree); /* only when initialized */
if(ntree->init & NTREE_EXEC_INIT) {
for(node= ntree->nodes.first; node; node= node->next) { for(node= ntree->nodes.first; node; node= node->next) {
if(node->execfunc) { if(node->typeinfo->execfunc) {
node_get_stack(node, ntree->stack, ns); node_get_stack(node, ntree->stack, nsin, nsout);
node->execfunc(node, ns); node->typeinfo->execfunc(ntree->data, node, nsin, nsout);
}
} }
} }
nodeEndExecTree(ntree);
} }
/* clear one pixel in all the preview images */
void ntreeClearPixelTree(bNodeTree *ntree, int x, int y)
{
bNode *node;
float vec[4]= {0.0f, 0.0f, 0.0f, 0.0f};
/* only when initialized */
if(ntree->init & NTREE_EXEC_INIT) {
for(node= ntree->nodes.first; node; node= node->next) {
if(node->preview)
nodeAddToPreview(node, vec, x, y);
}
}
}

View File

@@ -30,10 +30,13 @@
#include <stdlib.h> #include <stdlib.h>
#include "DNA_ID.h" #include "DNA_ID.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h" #include "DNA_node_types.h"
#include "DNA_texture_types.h"
#include "BKE_blender.h" #include "BKE_blender.h"
#include "BKE_node.h" #include "BKE_node.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h" #include "BKE_utildefines.h"
#include "BLI_arithb.h" #include "BLI_arithb.h"
@@ -41,186 +44,443 @@
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
/* **************** testnode ************ */ #include "render.h" /* <- shadeinput/output */
static void blendcolor(float *col1, float *col2, float *output, float fac) /* ********* exec data struct, remains internal *********** */
typedef struct ShaderCallData {
ShadeInput *shi;
ShadeResult *shr;
} ShaderCallData;
/* **************** call to switch lamploop for material node ************ */
static void (*node_shader_lamp_loop)(ShadeInput *, ShadeResult *);
void set_node_shader_lamp_loop(void (*lamp_loop_func)(ShadeInput *, ShadeResult *))
{ {
output[0]= (1.0f-fac)*col1[0] + (fac)*col2[0]; node_shader_lamp_loop= lamp_loop_func;
output[1]= (1.0f-fac)*col1[1] + (fac)*col2[1];
output[2]= (1.0f-fac)*col1[2] + (fac)*col2[2];
} }
static void node_shader_exec_test(bNode *node, bNodeStack **ns) /* **************** input node ************ */
{
blendcolor(ns[0]->vec, ns[1]->vec, ns[2]->vec, 0.5);
// printvecf(node->name, ns[2]->vec); static void node_shader_exec_input(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
if(data) {
ShadeResult *shr= ((ShaderCallData *)data)->shr;
ShadeInput *shi= ((ShaderCallData *)data)->shi;
float col[4];
/* stack order output sockets: color, alpha, normal */
VecAddf(col, shr->diff, shr->spec);
col[3]= shr->alpha;
VECCOPY(out[0]->vec, col);
out[1]->vec[0]= shr->alpha;
VECCOPY(out[2]->vec, shi->vn);
if(shi->do_preview)
nodeAddToPreview(node, col, shi->xs, shi->ys);
}
} }
static bNode *node_shader_add_test(bNodeTree *ntree)
/* **************** output node ************ */
static void node_shader_exec_output(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{ {
bNode *node= nodeAddNode(ntree, "TestNode"); if(data) {
static int tot= 0; ShadeInput *shi= ((ShaderCallData *)data)->shi;
float col[4];
/* stack order input sockets: col, alpha, normal */
VECCOPY(col, in[0]->vec);
col[3]= in[1]->vec[0];
if(shi->do_preview) {
nodeAddToPreview(node, col, shi->xs, shi->ys);
node->lasty= shi->ys;
}
if(node->flag & NODE_DO_OUTPUT) {
ShadeResult *shr= ((ShaderCallData *)data)->shr;
VECCOPY(shr->diff, col);
col[0]= col[1]= col[2]= 0.0f;
VECCOPY(shr->spec, col);
shr->alpha= col[3];
// VECCOPY(shr->nor, in[3]->vec);
}
}
}
/* **************** material node ************ */
static void node_shader_exec_material(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
if(data && node->id) {
ShadeResult shrnode;
ShadeInput *shi;
float col[4], *nor;
sprintf(node->name, "Testnode%d", tot++); shi= ((ShaderCallData *)data)->shi;
node->type= SH_NODE_TEST;
node->width= 80.0f; shi->mat= (Material *)node->id;
/* add sockets */ /* retrieve normal */
nodeAddSocket(node, SOCK_RGBA, SOCK_IN, 1, "Col"); if(in[0]->hasinput)
nodeAddSocket(node, SOCK_RGBA, SOCK_IN, 1, "Spec"); nor= in[0]->vec;
nodeAddSocket(node, SOCK_RGBA, SOCK_OUT, 0xFFF, "Diffuse"); else
nor= shi->vno;
return node;
if(node->custom1 & SH_NODE_MAT_NEG) {
shi->vn[0]= -nor[0];
shi->vn[1]= -nor[1];
shi->vn[2]= -nor[2];
}
else {
VECCOPY(shi->vn, nor);
}
node_shader_lamp_loop(shi, &shrnode);
if(node->custom1 & SH_NODE_MAT_DIFF) {
VECCOPY(col, shrnode.diff);
if(node->custom1 & SH_NODE_MAT_SPEC) {
VecAddf(col, col, shrnode.spec);
}
}
else if(node->custom1 & SH_NODE_MAT_SPEC) {
VECCOPY(col, shrnode.spec);
}
else
col[0]= col[1]= col[2]= 0.0f;
col[3]= shrnode.alpha;
if(shi->do_preview)
nodeAddToPreview(node, col, shi->xs, shi->ys);
/* stack order output: color, alpha, normal */
VECCOPY(out[0]->vec, col);
out[1]->vec[0]= shrnode.alpha;
if(node->custom1 & SH_NODE_MAT_NEG) {
shi->vn[0]= -shi->vn[0];
shi->vn[1]= -shi->vn[1];
shi->vn[2]= -shi->vn[2];
}
VECCOPY(out[2]->vec, shi->vn);
}
}
/* **************** texture node ************ */
static void node_shader_exec_texture(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
if(data && node->id) {
ShadeInput *shi;
shi= ((ShaderCallData *)data)->shi;
multitex_ext((Tex *)node->id, shi->co, out[0]->vec, out[1]->vec, out[1]->vec+1, out[1]->vec+2, out[1]->vec+3);
if(shi->do_preview)
nodeAddToPreview(node, out[1]->vec, shi->xs, shi->ys);
}
} }
/* **************** value node ************ */ /* **************** value node ************ */
static void node_shader_exec_value(bNode *node, bNodeStack **ns) static void node_shader_exec_value(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{ {
/* no input node! */ bNodeSocket *sock= node->outputs.first;
ns[0]->vec[0]= node->ns.vec[0];
// printf("%s %f\n", node->name, ns[0]->vec[0]);
}
static bNode *node_shader_add_value(bNodeTree *ntree)
{
bNode *node= nodeAddNode(ntree, "Value");
node->type= SH_NODE_VALUE; out[0]->vec[0]= sock->ns.vec[0];
node->width= 80.0f;
node->prv_h= 20.0f;
/* add sockets */
nodeAddSocket(node, SOCK_VALUE, SOCK_OUT, 0xFFF, "");
return node;
} }
/* **************** rgba node ************ */ /* **************** rgba node ************ */
static void node_shader_exec_rgb(bNode *node, bNodeStack **ns) static void node_shader_exec_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{ {
/* no input node! */ bNodeSocket *sock= node->outputs.first;
QUATCOPY(ns[0]->vec, node->ns.vec);
// printvecf(node->name, ns[0]->vec); VECCOPY(out[0]->vec, sock->ns.vec);
}
/* **************** mix rgb node ************ */
static void node_shader_exec_mix_rgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order in: fac, col1, col2 */
/* stack order out: col */
float col[3];
VECCOPY(col, in[1]->vec);
ramp_blend(node->custom1, col, col+1, col+2, in[0]->vec[0], in[2]->vec);
VECCOPY(out[0]->vec, col);
} }
static bNode *node_shader_add_rgb(bNodeTree *ntree) /* **************** val to rgb node ************ */
static void node_shader_exec_valtorgb(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{ {
bNode *node= nodeAddNode(ntree, "RGB"); /* stack order in: fac */
/* stack order out: col, alpha */
node->type= SH_NODE_RGB; if(node->storage) {
node->width= 100.0f; do_colorband(node->storage, in[0]->vec[0], out[0]->vec);
node->prv_h= 100.0f; out[1]->vec[0]= out[0]->vec[3];
node->ns.vec[3]= 1.0f; /* alpha init */
/* add sockets */
nodeAddSocket(node, SOCK_RGBA, SOCK_OUT, 0xFFF, "");
return node;
}
/* **************** mix rgba node ************ */
static void node_shader_exec_mix_rgb(bNode *node, bNodeStack **ns)
{
/* stack order is fac, col1, col2, out */
blendcolor(ns[1]->vec, ns[2]->vec, ns[3]->vec, ns[0]->vec[0]);
}
static bNode *node_shader_add_mix_rgb(bNodeTree *ntree)
{
bNode *node= nodeAddNode(ntree, "Mix RGB");
node->type= SH_NODE_MIX_RGB;
node->width= 80.0f;
node->prv_h= 0.0f;
/* add sockets */
nodeAddSocket(node, SOCK_VALUE, SOCK_IN, 1, "Fac");
nodeAddSocket(node, SOCK_RGBA, SOCK_IN, 1, "Color1");
nodeAddSocket(node, SOCK_RGBA, SOCK_IN, 1, "Color2");
nodeAddSocket(node, SOCK_RGBA, SOCK_OUT, 0xFFF, "Color");
return node;
}
/* **************** show rgba node ************ */
static void node_shader_exec_show_rgb(bNode *node, bNodeStack **ns)
{
/* only input node! */
QUATCOPY(node->ns.vec, ns[0]->vec);
// printvecf(node->name, ns[0]->vec);
}
static bNode *node_shader_add_show_rgb(bNodeTree *ntree)
{
bNode *node= nodeAddNode(ntree, "Show RGB");
node->type= SH_NODE_SHOW_RGB;
node->width= 80.0f;
node->prv_h= 0.0f;
node->ns.vec[3]= 1.0f; /* alpha init */
/* add sockets */
nodeAddSocket(node, SOCK_RGBA, SOCK_IN, 1, "");
return node;
}
/* **************** API for add ************** */
bNode *node_shader_add(bNodeTree *ntree, int type)
{
bNode *node= NULL;
switch(type) {
case SH_NODE_TEST:
node= node_shader_add_test(ntree);
break;
case SH_NODE_VALUE:
node= node_shader_add_value(ntree);
break;
case SH_NODE_RGB:
node= node_shader_add_rgb(ntree);
break;
case SH_NODE_SHOW_RGB:
node= node_shader_add_show_rgb(ntree);
break;
case SH_NODE_MIX_RGB:
node= node_shader_add_mix_rgb(ntree);
break;
}
return node;
}
/* ******************* set the callbacks, called from UI, loader ***** */
void node_shader_set_execfunc(bNode *node)
{
switch(node->type) {
case SH_NODE_TEST:
node->execfunc= node_shader_exec_test;
break;
case SH_NODE_VALUE:
node->execfunc= node_shader_exec_value;
break;
case SH_NODE_RGB:
node->execfunc= node_shader_exec_rgb;
break;
case SH_NODE_SHOW_RGB:
node->execfunc= node_shader_exec_show_rgb;
break;
case SH_NODE_MIX_RGB:
node->execfunc= node_shader_exec_mix_rgb;
break;
} }
} }
/* **************** rgb to bw node ************ */
static void node_shader_exec_rgbtobw(void *data, bNode *node, bNodeStack **in, bNodeStack **out)
{
/* stack order out: bw */
/* stack order in: col */
out[0]->vec[0]= in[0]->vec[0]*0.35f + in[0]->vec[1]*0.45f + in[0]->vec[2]*0.2f;
}
/* ******************* execute ************ */
void ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr)
{
ShaderCallData scd;
/* convert caller data to struct */
scd.shi= shi;
scd.shr= shr;
ntree->data= &scd;
ntreeExecTree(ntree);
}
/* ******************************************************** */
/* ********* Shader Node type definitions ***************** */
/* ******************************************************** */
/* SocketType syntax:
socket type, max connections (0 is no limit), name, 4 values for default, 2 values for range */
/* Verification rule: If name changes, a saved socket and its links will be removed! Type changes are OK */
/* *************** INPUT ********************* */
static bNodeSocketType sh_node_input_out[]= {
{ SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_input= {
/* type code */ SH_NODE_INPUT,
/* name */ "Input",
/* width+range */ 80, 60, 200,
/* class+opts */ NODE_CLASS_INPUT, NODE_PREVIEW,
/* input sock */ NULL,
/* output sock */ sh_node_input_out,
/* storage */ "",
/* execfunc */ node_shader_exec_input,
};
/* **************** OUTPUT ******************** */
static bNodeSocketType sh_node_output_in[]= {
{ SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ SOCK_VALUE, 1, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_output= {
/* type code */ SH_NODE_OUTPUT,
/* name */ "Output",
/* width+range */ 80, 60, 200,
/* class+opts */ NODE_CLASS_OUTPUT, NODE_PREVIEW,
/* input sock */ sh_node_output_in,
/* output sock */ NULL,
/* storage */ "",
/* execfunc */ node_shader_exec_output,
};
/* **************** MATERIAL ******************** */
static bNodeSocketType sh_node_material_in[]= {
{ SOCK_VECTOR, 1, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeSocketType sh_node_material_out[]= {
{ SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_material= {
/* type code */ SH_NODE_MATERIAL,
/* name */ "Material",
/* width+range */ 120, 60, 200,
/* class+opts */ NODE_CLASS_GENERATOR, NODE_OPTIONS|NODE_PREVIEW,
/* input sock */ sh_node_material_in,
/* output sock */ sh_node_material_out,
/* storage */ "",
/* execfunc */ node_shader_exec_material,
};
/* **************** TEXTURE ******************** */
static bNodeSocketType sh_node_texture_out[]= {
{ SOCK_VALUE, 0, "Value", 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ SOCK_RGBA , 0, "Color", 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f},
{ SOCK_VECTOR, 0, "Normal", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_texture= {
/* type code */ SH_NODE_TEXTURE,
/* name */ "Texture",
/* width+range */ 120, 60, 200,
/* class+opts */ NODE_CLASS_GENERATOR, NODE_OPTIONS|NODE_PREVIEW,
/* input sock */ NULL,
/* output sock */ sh_node_texture_out,
/* storage */ "",
/* execfunc */ node_shader_exec_texture,
};
/* **************** VALUE ******************** */
static bNodeSocketType sh_node_value_out[]= {
{ SOCK_VALUE, 0, "Value", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_value= {
/* type code */ SH_NODE_VALUE,
/* name */ "Value",
/* width+range */ 80, 40, 120,
/* class+opts */ NODE_CLASS_GENERATOR, NODE_OPTIONS,
/* input sock */ NULL,
/* output sock */ sh_node_value_out,
/* storage */ "",
/* execfunc */ node_shader_exec_value,
};
/* **************** RGB ******************** */
static bNodeSocketType sh_node_rgb_out[]= {
{ SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_rgb= {
/* type code */ SH_NODE_RGB,
/* name */ "RGB",
/* width+range */ 100, 60, 140,
/* class+opts */ NODE_CLASS_GENERATOR, NODE_OPTIONS,
/* input sock */ NULL,
/* output sock */ sh_node_rgb_out,
/* storage */ "",
/* execfunc */ node_shader_exec_rgb,
};
/* **************** MIX RGB ******************** */
static bNodeSocketType sh_node_mix_rgb_in[]= {
{ SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ SOCK_RGBA, 1, "Color1", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ SOCK_RGBA, 1, "Color2", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeSocketType sh_node_mix_rgb_out[]= {
{ SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_mix_rgb= {
/* type code */ SH_NODE_MIX_RGB,
/* name */ "Mix",
/* width+range */ 80, 40, 120,
/* class+opts */ NODE_CLASS_OPERATOR, NODE_OPTIONS,
/* input sock */ sh_node_mix_rgb_in,
/* output sock */ sh_node_mix_rgb_out,
/* storage */ "",
/* execfunc */ node_shader_exec_mix_rgb,
};
/* **************** VALTORGB ******************** */
static bNodeSocketType sh_node_valtorgb_in[]= {
{ SOCK_VALUE, 1, "Fac", 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeSocketType sh_node_valtorgb_out[]= {
{ SOCK_RGBA, 0, "Color", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ SOCK_VALUE, 0, "Alpha", 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_valtorgb= {
/* type code */ SH_NODE_VALTORGB,
/* name */ "ColorRamp",
/* width+range */ 240, 200, 300,
/* class+opts */ NODE_CLASS_OPERATOR, NODE_OPTIONS,
/* input sock */ sh_node_valtorgb_in,
/* output sock */ sh_node_valtorgb_out,
/* storage */ "ColorBand",
/* execfunc */ node_shader_exec_valtorgb,
};
/* **************** RGBTOBW ******************** */
static bNodeSocketType sh_node_rgbtobw_in[]= {
{ SOCK_RGBA, 1, "Color", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeSocketType sh_node_rgbtobw_out[]= {
{ SOCK_VALUE, 0, "Val", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
{ -1, 0, "" }
};
static bNodeType sh_node_rgbtobw= {
/* type code */ SH_NODE_RGBTOBW,
/* name */ "RGB to BW",
/* width+range */ 80, 40, 120,
/* class+opts */ NODE_CLASS_OPERATOR, 0,
/* input sock */ sh_node_rgbtobw_in,
/* output sock */ sh_node_rgbtobw_out,
/* storage */ "ColorBand",
/* execfunc */ node_shader_exec_rgbtobw,
};
/* ****************** types array for all shaders ****************** */
bNodeType *node_all_shaders[]= {
&sh_node_input,
&sh_node_output,
&sh_node_material,
&sh_node_value,
&sh_node_rgb,
&sh_node_mix_rgb,
&sh_node_valtorgb,
&sh_node_rgbtobw,
&sh_node_texture,
NULL
};

View File

@@ -199,25 +199,39 @@ void free_plugin_tex(PluginTex *pit)
/* ****************** COLORBAND ******************* */ /* ****************** COLORBAND ******************* */
ColorBand *add_colorband() ColorBand *add_colorband(int rangetype)
{ {
ColorBand *coba; ColorBand *coba;
int a; int a;
coba= MEM_callocN( sizeof(ColorBand), "colorband"); coba= MEM_callocN( sizeof(ColorBand), "colorband");
coba->data[0].r= 0.0;
coba->data[0].g= 0.0;
coba->data[0].b= 0.0;
coba->data[0].a= 0.0;
coba->data[0].pos= 0.0; coba->data[0].pos= 0.0;
coba->data[1].r= 0.0;
coba->data[1].g= 1.0;
coba->data[1].b= 1.0;
coba->data[1].a= 1.0;
coba->data[1].pos= 1.0; coba->data[1].pos= 1.0;
if(rangetype==0) {
coba->data[0].r= 0.0;
coba->data[0].g= 0.0;
coba->data[0].b= 0.0;
coba->data[0].a= 0.0;
coba->data[1].r= 0.0;
coba->data[1].g= 1.0;
coba->data[1].b= 1.0;
coba->data[1].a= 1.0;
}
else {
coba->data[0].r= 0.0;
coba->data[0].g= 0.0;
coba->data[0].b= 0.0;
coba->data[0].a= 1.0;
coba->data[1].r= 1.0;
coba->data[1].g= 1.0;
coba->data[1].b= 1.0;
coba->data[1].a= 1.0;
}
for(a=2; a<MAXCOLORBAND; a++) { for(a=2; a<MAXCOLORBAND; a++) {
coba->data[a].r= 0.5; coba->data[a].r= 0.5;
coba->data[a].g= 0.5; coba->data[a].g= 0.5;

View File

@@ -76,6 +76,7 @@
#include "DNA_meshdata_types.h" #include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h" #include "DNA_modifier_types.h"
#include "DNA_nla_types.h" #include "DNA_nla_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_object_force.h" #include "DNA_object_force.h"
#include "DNA_object_fluidsim.h" // NT #include "DNA_object_fluidsim.h" // NT
@@ -1205,6 +1206,61 @@ static void test_pointer_array(FileData *fd, void **mat)
} }
} }
/* ************ READ NODE TREE *************** */
/* ntree is not NULL */
static void lib_link_nodetree(FileData *fd, ID *id, bNodeTree *ntree)
{
bNode *node;
for(node= ntree->nodes.first; node; node= node->next)
node->id= newlibadr_us(fd, id->lib, node->id);
}
static bNodeTree *direct_link_nodetree(FileData *fd, bNodeTree *ntree)
{
/* note: writing and reading goes in sync, for speed */
if(ntree) {
ntree= newdataadr(fd, ntree);
if(ntree) {
bNode *node;
bNodeSocket *sock;
bNodeLink *link;
ntree->init= 0; /* to set callbacks */
ntree->data= NULL; /* safety only */
link_list(fd, &ntree->nodes);
for(node= ntree->nodes.first; node; node= node->next) {
node->storage= newdataadr(fd, node->storage);
link_list(fd, &node->inputs);
link_list(fd, &node->outputs);
}
link_list(fd, &ntree->links);
/* and we connect the rest */
for(node= ntree->nodes.first; node; node= node->next) {
node->preview= NULL;
node->lasty= 0;
for(sock= node->inputs.first; sock; sock= sock->next)
sock->link= newdataadr(fd, sock->link);
}
for(link= ntree->links.first; link; link= link->next) {
link->fromnode= newdataadr(fd, link->fromnode);
link->tonode= newdataadr(fd, link->tonode);
link->fromsock= newdataadr(fd, link->fromsock);
link->tosock= newdataadr(fd, link->tosock);
}
/* right after read file, the save-undo will need it */
/* verify also does a full type checking. This is relative slow... so we
might move this later to the do_versions, and put ntreeInitTypes() only here */
ntreeVerifyTypes(ntree);
}
}
return ntree;
}
/* ************ READ PACKEDFILE *************** */ /* ************ READ PACKEDFILE *************** */
static PackedFile *direct_link_packedfile(FileData *fd, PackedFile *oldpf) static PackedFile *direct_link_packedfile(FileData *fd, PackedFile *oldpf)
@@ -1993,7 +2049,7 @@ static void lib_link_material(FileData *fd, Main *main)
ma->ipo= newlibadr_us(fd, ma->id.lib, ma->ipo); ma->ipo= newlibadr_us(fd, ma->id.lib, ma->ipo);
ma->group= newlibadr_us(fd, ma->id.lib, ma->group); ma->group= newlibadr_us(fd, ma->id.lib, ma->group);
for(a=0; a<MAX_MTEX; a++) { for(a=0; a<MAX_MTEX; a++) {
mtex= ma->mtex[a]; mtex= ma->mtex[a];
if(mtex) { if(mtex) {
@@ -2005,7 +2061,10 @@ static void lib_link_material(FileData *fd, Main *main)
for (ml=ma->layers.first; ml; ml=ml->next) for (ml=ma->layers.first; ml; ml=ml->next)
ml->mat= newlibadr_us(fd, ma->id.lib, ml->mat); ml->mat= newlibadr_us(fd, ma->id.lib, ml->mat);
if(ma->nodetree)
lib_link_nodetree(fd, &ma->id, ma->nodetree);
ma->id.flag -= LIB_NEEDLINK; ma->id.flag -= LIB_NEEDLINK;
} }
ma= ma->id.next; ma= ma->id.next;
@@ -2026,7 +2085,8 @@ static void direct_link_material(FileData *fd, Material *ma)
direct_link_scriptlink(fd, &ma->scriptlink); direct_link_scriptlink(fd, &ma->scriptlink);
link_list(fd, &ma->layers); link_list(fd, &ma->layers);
ma->nodetree= direct_link_nodetree(fd, ma->nodetree);
} }
/* ************ READ MESH ***************** */ /* ************ READ MESH ***************** */
@@ -2994,6 +3054,13 @@ void lib_link_screen_restore(Main *newmain, Scene *curscene)
ssound->sound= restore_pointer_by_name(newmain, (ID *)ssound->sound, 1); ssound->sound= restore_pointer_by_name(newmain, (ID *)ssound->sound, 1);
} }
else if(sl->spacetype==SPACE_NODE) {
SpaceNode *snode= (SpaceNode *)sl;
snode->nodetree= NULL;
snode->block= NULL;
snode->flag |= SNODE_DO_PREVIEW;
}
} }
sa= sa->next; sa= sa->next;
} }
@@ -3088,6 +3155,7 @@ static void direct_link_screen(FileData *fd, bScreen *sc)
SpaceNode *snode= (SpaceNode *)sl; SpaceNode *snode= (SpaceNode *)sl;
snode->nodetree= NULL; snode->nodetree= NULL;
snode->block= NULL; snode->block= NULL;
snode->flag |= SNODE_DO_PREVIEW;
} }
} }
@@ -5115,11 +5183,8 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
ma->strand_sta= ma->strand_end= 1.0f; ma->strand_sta= ma->strand_end= 1.0f;
ma->mode |= MA_TANGENT_STR; ma->mode |= MA_TANGENT_STR;
} }
/* remove this test before 2.40 too! pad is set to denote check was done */ if(ma->mode & MA_TRACEBLE) ma->mode |= MA_SHADBUF;
if(ma->pad==0) {
if(ma->mode & MA_TRACEBLE) ma->mode |= MA_SHADBUF;
ma->pad= 1;
}
/* orange stuff, so should be done for 2.40 too */ /* orange stuff, so should be done for 2.40 too */
if(ma->layers.first==NULL) { if(ma->layers.first==NULL) {
ma->ml_flag= ML_RENDER; ma->ml_flag= ML_RENDER;
@@ -5379,6 +5444,13 @@ static void expand_material(FileData *fd, Main *mainvar, Material *ma)
if(ml->mat) if(ml->mat)
expand_doit(fd, mainvar, ml->mat); expand_doit(fd, mainvar, ml->mat);
} }
if(ma->nodetree) {
bNode *node;
for(node= ma->nodetree->nodes.first; node; node= node->next)
if(node->id)
expand_doit(fd, mainvar, node->id);
}
} }
static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la) static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la)

View File

@@ -124,6 +124,7 @@ Important to know is that 'streaming' has been added to files, for Blender Publi
#include "DNA_material_types.h" #include "DNA_material_types.h"
#include "DNA_modifier_types.h" #include "DNA_modifier_types.h"
#include "DNA_nla_types.h" #include "DNA_nla_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_object_force.h" #include "DNA_object_force.h"
#include "DNA_oops_types.h" #include "DNA_oops_types.h"
@@ -153,6 +154,7 @@ Important to know is that 'streaming' has been added to files, for Blender Publi
#include "BKE_global.h" // for G #include "BKE_global.h" // for G
#include "BKE_library.h" // for set_listbasepointers #include "BKE_library.h" // for set_listbasepointers
#include "BKE_main.h" // G.main #include "BKE_main.h" // G.main
#include "BKE_node.h"
#include "BKE_packedFile.h" // for packAll #include "BKE_packedFile.h" // for packAll
#include "BKE_screen.h" // for waitcursor #include "BKE_screen.h" // for waitcursor
#include "BKE_scene.h" // for do_seq #include "BKE_scene.h" // for do_seq
@@ -317,7 +319,7 @@ static void writestruct(WriteData *wd, int filecode, char *structname, int nr, v
BHead bh; BHead bh;
short *sp; short *sp;
if(adr==0 || nr==0) return; if(adr==NULL || nr==0) return;
/* init BHead */ /* init BHead */
bh.code= filecode; bh.code= filecode;
@@ -326,7 +328,7 @@ static void writestruct(WriteData *wd, int filecode, char *structname, int nr, v
bh.SDNAnr= dna_findstruct_nr(wd->sdna, structname); bh.SDNAnr= dna_findstruct_nr(wd->sdna, structname);
if(bh.SDNAnr== -1) { if(bh.SDNAnr== -1) {
printf("error: can't find SDNA code %s\n", structname); printf("error: can't find SDNA code <%s>\n", structname);
return; return;
} }
sp= wd->sdna->structs[bh.SDNAnr]; sp= wd->sdna->structs[bh.SDNAnr];
@@ -360,6 +362,33 @@ static void writedata(WriteData *wd, int filecode, int len, void *adr) /* do not
if(len) mywrite(wd, adr, len); if(len) mywrite(wd, adr, len);
} }
/* this is only direct data */
static void write_nodetree(WriteData *wd, bNodeTree *ntree)
{
bNode *node;
bNodeSocket *sock;
bNodeLink *link;
writestruct(wd, DATA, "bNodeTree", 1, ntree);
/* for link_list() speed, we write per list */
for(node= ntree->nodes.first; node; node= node->next)
writestruct(wd, DATA, "bNode", 1, node);
for(node= ntree->nodes.first; node; node= node->next) {
if(node->storage)
writestruct(wd, DATA, node->typeinfo->storagename, 1, node->storage);
for(sock= node->inputs.first; sock; sock= sock->next)
writestruct(wd, DATA, "bNodeSocket", 1, sock);
for(sock= node->outputs.first; sock; sock= sock->next)
writestruct(wd, DATA, "bNodeSocket", 1, sock);
}
for(link= ntree->links.first; link; link= link->next)
writestruct(wd, DATA, "bNodeLink", 1, link);
}
static void write_scriptlink(WriteData *wd, ScriptLink *slink) static void write_scriptlink(WriteData *wd, ScriptLink *slink)
{ {
writedata(wd, DATA, sizeof(void *)*slink->totscript, slink->scripts); writedata(wd, DATA, sizeof(void *)*slink->totscript, slink->scripts);
@@ -1014,7 +1043,9 @@ static void write_materials(WriteData *wd, ListBase *idbase)
for (ml=ma->layers.first; ml; ml=ml->next) for (ml=ma->layers.first; ml; ml=ml->next)
writestruct(wd, DATA, "MaterialLayer", 1, ml); writestruct(wd, DATA, "MaterialLayer", 1, ml);
if(ma->nodetree)
write_nodetree(wd, ma->nodetree);
} }
ma= ma->id.next; ma= ma->id.next;
} }

View File

@@ -125,7 +125,7 @@ void glaRasterPosSafe2f (float x, float y, float known_good_x, float known_good
* to use the glScissor functionality if images are to be drawn * to use the glScissor functionality if images are to be drawn
* with an inset view matrix. * with an inset view matrix.
*/ */
void glaDrawPixelsSafe (float x, float y, int img_w, int img_h, void *rect); void glaDrawPixelsSafe (float x, float y, int img_w, int img_h, int format, void *rect);
/** /**
* Functions like a limited glDrawPixels, but actually draws the * Functions like a limited glDrawPixels, but actually draws the
@@ -135,11 +135,11 @@ void glaDrawPixelsSafe (float x, float y, int img_w, int img_h, void *rect);
* pixel unpacking parameters are _not_ respected. * pixel unpacking parameters are _not_ respected.
* @attention This routine makes many assumptions: the rect data * @attention This routine makes many assumptions: the rect data
* is expected to be in RGBA unsigned byte format, and the * is expected to be in RGBA byte or float format, and the
* modelview and projection matrices are assumed to define a * modelview and projection matrices are assumed to define a
* 1-to-1 mapping to screen space. * 1-to-1 mapping to screen space.
*/ */
void glaDrawPixelsTex (float x, float y, int img_w, int img_h, void *rect); void glaDrawPixelsTex (float x, float y, int img_w, int img_h, int format, void *rect);
/* 2D Drawing Assistance */ /* 2D Drawing Assistance */

View File

@@ -153,6 +153,7 @@ struct ScrArea;
#define PULLDOWN (27<<9) #define PULLDOWN (27<<9)
#define ROUNDBOX (28<<9) #define ROUNDBOX (28<<9)
#define CHARTAB (29<<9) #define CHARTAB (29<<9)
#define BUT_COLORBAND (30<<9)
#define BUTTYPE (31<<9) #define BUTTYPE (31<<9)

View File

@@ -47,8 +47,8 @@ void BIF_icons_init(int first_dyn_id);
int BIF_icon_get_width(int icon_id); int BIF_icon_get_width(int icon_id);
int BIF_icon_get_height(int icon_id); int BIF_icon_get_height(int icon_id);
void BIF_icon_set_aspect(int icon_id, float aspect); void BIF_icon_set_aspect(int icon_id, float aspect);
void BIF_icon_draw(int x, int y, int icon_id); void BIF_icon_draw(float x, float y, int icon_id);
void BIF_icon_draw_blended(int x, int y, int icon_id, int colorid, int shade); void BIF_icon_draw_blended(float x, float y, int icon_id, int colorid, int shade);
void BIF_icons_free(); void BIF_icons_free();
void BIF_icons_free_drawinfo(void *drawinfo); void BIF_icons_free_drawinfo(void *drawinfo);

View File

@@ -35,6 +35,8 @@ struct RenderInfo;
struct Image; struct Image;
struct ScrArea; struct ScrArea;
#define PREVIEW_RENDERSIZE 140
typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha); typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
/* stores rendered preview - is also used for icons */ /* stores rendered preview - is also used for icons */
@@ -45,22 +47,23 @@ typedef struct RenderInfo {
short cury; short cury;
} RenderInfo; } RenderInfo;
/* Set the previewrect for drawing */
void BIF_set_previewrect(int win, int xmin, int ymin, int xmax, int ymax, short pr_rectx, short pr_recty);
void BIF_end_previewrect(void);
void BIF_all_preview_changed(void);
void BIF_preview_changed (struct SpaceButs *sbuts);
void BIF_previewrender_buts (struct SpaceButs *sbuts);
/* Render the preview /* Render the preview
* a) into the ri->rect
* b) draw it in the area using the block UIMat
if doDraw is false, the preview is not drawn and the function is not dynamic, pr_method:
so no events are processed. Hopefully fast enough for 64x64 rendering or - PR_DRAW_RENDER: preview is rendered and drawn, as indicated by called context (buttons panel)
at least 32x32 */ - PR_ICON_RENDER: the preview is not drawn and the function is not dynamic,
void BIF_previewrender (struct ID* id, struct RenderInfo *ri, struct ScrArea *area, int doDraw); so no events are processed. Hopefully fast enough for at least 32x32
- PR_DO_RENDER: preview is rendered, not drawn, but events are processed for afterqueue,
in use for node editor now.
*/
#define PR_DRAW_RENDER 0
#define PR_ICON_RENDER 1
#define PR_DO_RENDER 2
void BIF_previewrender (struct ID *id, struct RenderInfo *ri, struct ScrArea *area, int pr_method);
void BIF_previewrender_buts (struct SpaceButs *sbuts);
void BIF_previewdraw (void); void BIF_previewdraw (void);
void BIF_previewdraw_render(struct RenderInfo* ri, struct ScrArea* area); void BIF_preview_changed(short id_code);
void BIF_calcpreview_image(struct Image* img, struct RenderInfo* ri, unsigned int w, unsigned int h);

View File

@@ -182,8 +182,8 @@ typedef enum {
ICON_CHECKBOX_HLT, ICON_CHECKBOX_HLT,
ICON_LINK, ICON_LINK,
ICON_INLINK, ICON_INLINK,
ICON_BEVELBUT_HLT, ICON_BLANK12,
ICON_BEVELBUT_DEHLT, ICON_BLANK13,
ICON_PASTEDOWN, ICON_PASTEDOWN,
ICON_COPYDOWN, ICON_COPYDOWN,
ICON_CONSTANT, ICON_CONSTANT,
@@ -456,7 +456,13 @@ enum {
TH_STRIP, TH_STRIP,
TH_STRIP_SELECT, TH_STRIP_SELECT,
TH_LAMP TH_LAMP,
TH_NODE,
TH_NODE_IN_OUT,
TH_NODE_OPERATOR,
TH_NODE_GENERATOR,
TH_NODE_FREE,
}; };
/* XXX WARNING: previous is saved in file, so do not change order! */ /* XXX WARNING: previous is saved in file, so do not change order! */

View File

@@ -30,27 +30,36 @@
#ifndef BSE_NODE_H #ifndef BSE_NODE_H
#define BSE_NODE_H #define BSE_NODE_H
/* ********** drawing sizes *********** */
#define NODE_DY 20 #define NODE_DY 20
#define NODE_DYS 10 #define NODE_DYS 10
#define NODE_SOCK 5 #define NODE_SOCKSIZE 5
#define BASIS_RAD 8.0f
#define HIDDEN_RAD 15.0f
struct SpaceNode; struct SpaceNode;
struct bNode; struct bNode;
struct Material;
/* ************* button events *********** */
#define B_NODE_EXEC 1
/* ************* API for editnode.c *********** */ /* ************* API for editnode.c *********** */
void snode_tag_dirty(struct SpaceNode *snode);
void snode_set_context(struct SpaceNode *snode);
void node_deselectall(struct SpaceNode *snode, int swap); void node_deselectall(struct SpaceNode *snode, int swap);
void node_transform_ext(int mode, int unused); void node_transform_ext(int mode, int unused);
void node_shader_default(struct Material *ma);
/* ************* drawnode.c *************** */
void node_draw_link(struct SpaceNode *snode, struct bNodeLink *link);
void init_node_butfuncs(void);
/* ************* Shader nodes ***************** */ /* ************* Shader nodes ***************** */
void node_shader_set_drawfunc(struct bNode *node); struct bNode *node_add_shadernode(struct SpaceNode *snode, int type, float locx, float locy);
#endif #endif

View File

@@ -374,7 +374,8 @@
#define B_NLAHOME 801 #define B_NLAHOME 801
/* NODE: 851-900 */ /* NODE: 851-900 */
#define B_NODEHOME 851 #define B_NODEHOME 851
#define B_NODE_USEMAT 852
/* FREE 901 - 999 */ /* FREE 901 - 999 */

View File

@@ -37,7 +37,9 @@
struct Base; struct Base;
struct Object; struct Object;
struct ID; struct ID;
struct ColorBand;
struct uiBlock;
struct rctf;
/* buts->scaflag */ /* buts->scaflag */
#define BUTS_SENS_SEL 1 #define BUTS_SENS_SEL 1
@@ -87,6 +89,7 @@ extern void do_armbuts(unsigned short event);
extern char *get_vertexgroup_menustr(struct Object *ob); // used in object buttons extern char *get_vertexgroup_menustr(struct Object *ob); // used in object buttons
/* shading */ /* shading */
extern void draw_colorband_buts_small(struct uiBlock *block, struct ColorBand *coba, rctf *rct, int event);
extern void material_panels(void); extern void material_panels(void);
extern void do_matbuts(unsigned short event); extern void do_matbuts(unsigned short event);
extern void lamp_panels(void); extern void lamp_panels(void);
@@ -122,6 +125,7 @@ void test_matpoin_but(char *name, struct ID **idpp);
void test_scriptpoin_but(char *name, struct ID **idpp); void test_scriptpoin_but(char *name, struct ID **idpp);
void test_actionpoin_but(char *name, ID **idpp); void test_actionpoin_but(char *name, ID **idpp);
void test_grouppoin_but(char *name, ID **idpp); void test_grouppoin_but(char *name, ID **idpp);
void test_texpoin_but(char *name, ID **idpp);
void test_idbutton_cb(void *namev, void *arg2_unused); void test_idbutton_cb(void *namev, void *arg2_unused);
@@ -169,20 +173,25 @@ void test_idbutton_cb(void *namev, void *arg2_unused);
#define B_ACTCOL 1204 #define B_ACTCOL 1204
#define B_MATFROM 1205 #define B_MATFROM 1205
#define B_MATPRV 1206 #define B_MATPRV 1206
#define B_MTEXCOL 1207 #define B_LAMPPRV 1207
#define B_TEXCLEAR 1208 #define B_WORLDPRV 1208
#define B_MATPRV_DRAW 1209 #define B_TEXPRV 1209
#define B_MTEXPASTE 1210 #define B_MTEXCOL 1210
#define B_MTEXCOPY 1211 #define B_TEXCLEAR 1211
#define B_MATLAY 1212 #define B_MTEXPASTE 1212
#define B_MATHALO 1213 #define B_MTEXCOPY 1213
#define B_MATZTRANSP 1214 #define B_MATLAY 1214
#define B_MATRAYTRANSP 1215 #define B_MATHALO 1215
#define B_MATCOLORBAND 1216 #define B_MATZTRANSP 1216
/* yafray: material preset menu event */ #define B_MATRAYTRANSP 1217
#define B_MAT_YF_PRESET 1217 #define B_MATCOLORBAND 1218
/* yafray: material preset menu event */
#define B_MAT_YF_PRESET 1219
#define B_MAT_LAYERBROWSE 1218 #define B_MAT_LAYERBROWSE 1220
#define B_MAT_USENODES 1221
/* also handled in editnode.c */
#define B_NODE_EXEC 1222
/* *********************** */ /* *********************** */
#define B_TEXBUTS 1400 #define B_TEXBUTS 1400
@@ -207,7 +216,6 @@ void test_idbutton_cb(void *namev, void *arg2_unused);
#define B_REDRAWCBAND 1318 #define B_REDRAWCBAND 1318
#define B_BANDCOL 1319 #define B_BANDCOL 1319
#define B_LOADTEXIMA1 1320 #define B_LOADTEXIMA1 1320
#define B_TEXPRV 1321
#define B_PLUGBUT 1325 #define B_PLUGBUT 1325
/* B_PLUGBUT reserves 24 buttons at least! */ /* B_PLUGBUT reserves 24 buttons at least! */

View File

@@ -223,6 +223,8 @@ extern void gl_round_box_shade(int mode, float minx, float miny, float maxx, flo
extern void ui_set_embossfunc(uiBut *but, int drawtype); extern void ui_set_embossfunc(uiBut *but, int drawtype);
extern void ui_draw_but(uiBut *but); extern void ui_draw_but(uiBut *but);
extern void ui_rasterpos_safe(float x, float y, float aspect); extern void ui_rasterpos_safe(float x, float y, float aspect);
extern void ui_draw_tria_icon(float x, float y, float aspect, char dir);
extern void ui_draw_anti_x(float x1, float y1, float x2, float y2);
#endif #endif

View File

@@ -47,6 +47,7 @@ struct Ipo;
struct Material; struct Material;
struct ColorBand; struct ColorBand;
struct Group; struct Group;
struct bNodeTree;
typedef struct MaterialLayer { typedef struct MaterialLayer {
struct MaterialLayer *next, *prev; struct MaterialLayer *next, *prev;
@@ -88,7 +89,7 @@ typedef struct Material {
float sbias; /* shadow bias */ float sbias; /* shadow bias */
/* for buttons and render*/ /* for buttons and render*/
char rgbsel, texact, pr_type, pad; char rgbsel, texact, pr_type, use_nodes;
short pr_back, pr_lamp, septex, ml_flag; /* ml_flag is for disable base material */ short pr_back, pr_lamp, septex, ml_flag; /* ml_flag is for disable base material */
/* shaders */ /* shaders */
@@ -109,8 +110,9 @@ typedef struct Material {
struct MTex *mtex[10]; struct MTex *mtex[10];
ListBase layers; ListBase layers;
struct bNodeTree *nodetree;
struct Ipo *ipo; struct Ipo *ipo;
struct Group *group; struct Group *group; /* light group */
/* dynamic properties */ /* dynamic properties */
float friction, fh, reflect; float friction, fh, reflect;

View File

@@ -36,17 +36,28 @@
struct ID; struct ID;
struct SpaceNode; struct SpaceNode;
struct bNodeLink; struct bNodeLink;
struct bNodeType;
#define NODE_MAXSTR 32 #define NODE_MAXSTR 32
typedef struct bNodeStack {
float vec[4];
float min, max; /* min/max for values (UI writes it, execute might use it) */
void *data;
short hasinput, pad; /* hasinput tagged for executing */
int pad1;
} bNodeStack;
typedef struct bNodeSocket { typedef struct bNodeSocket {
struct bNodeSocket *next, *prev; struct bNodeSocket *next, *prev;
char name[32]; char name[32];
bNodeStack ns; /* custom data for inputs, only UI writes in this */
short type, flag, limit, stack_index; short type, flag, limit, stack_index;
float locx, locy; float locx, locy;
struct bNodeLink *link; /* input link to parent, max one! */ struct bNodeLink *link; /* input link to parent, max one! set in nodeSolveOrder() */
} bNodeSocket; } bNodeSocket;
@@ -57,11 +68,13 @@ typedef struct bNodeSocket {
#define SOCK_IMAGE 3 #define SOCK_IMAGE 3
/* sock->flag, first bit is select */ /* sock->flag, first bit is select */
#
#
typedef struct bNodePreview {
float *rect;
char xsize, ysize;
} bNodePreview;
typedef struct bNodeStack {
float vec[4];
void *data;
} bNodeStack;
/* limit data in bNode to what we want to see saved? */ /* limit data in bNode to what we want to see saved? */
typedef struct bNode { typedef struct bNode {
@@ -69,23 +82,32 @@ typedef struct bNode {
char name[32]; char name[32];
short type, flag, done, level; short type, flag, done, level;
short lasty, pad, pad1, pad2;
ListBase inputs, outputs; ListBase inputs, outputs;
struct ID *id; /* optional link to libdata */ struct ID *id; /* optional link to libdata */
bNodeStack ns; /* builtin data, for UI to write into */ void *storage; /* custom data, must be struct, for storage in file */
float locx, locy; /* root offset for drawing */ float locx, locy; /* root offset for drawing */
float width, prv_h; float width;
rctf tot; /* entire boundbox */ short custom1, custom2; /* to be abused for buttons */
rctf prv; /* optional preview area */ rctf totr; /* entire boundbox */
rctf butr; /* optional buttons area */
rctf prvr; /* optional preview area */
bNodePreview *preview; /* optional preview image */
void (*drawfunc)(struct SpaceNode *, struct bNode *); struct bNodeType *typeinfo; /* lookup of callbacks and defaults */
void (*execfunc)(struct bNode *, struct bNodeStack **);
} bNode; } bNode;
/* node->flag */ /* node->flag */
#define NODE_SELECT 1 #define NODE_SELECT 1
#define NODE_OPTIONS 2
#define NODE_PREVIEW 4
#define NODE_HIDDEN 8
#define NODE_ACTIVE 16
#define NODE_ACTIVE_ID 32
#define NODE_DO_OUTPUT 64
typedef struct bNodeLink { typedef struct bNodeLink {
struct bNodeLink *next, *prev; struct bNodeLink *next, *prev;
@@ -99,10 +121,11 @@ typedef struct bNodeLink {
typedef struct bNodeTree { typedef struct bNodeTree {
ListBase nodes, links; ListBase nodes, links;
ListBase inputs, outputs; /* default inputs and outputs, for solving tree */ void *data; /* custom data, set by execute caller, no read/write handling */
bNodeStack *stack; bNodeStack *stack; /* stack is only while executing */
int type, init; int type, init; /* set init on fileread */
struct bNodeType **alltypes; /* type definitions, set on fileread */
} bNodeTree; } bNodeTree;
@@ -111,9 +134,8 @@ typedef struct bNodeTree {
#define NTREE_COMPOSIT 1 #define NTREE_COMPOSIT 1
/* ntree->init, flag */ /* ntree->init, flag */
#define NTREE_EXEC_SET 1 #define NTREE_TYPE_INIT 1
#define NTREE_DRAW_SET 2 #define NTREE_EXEC_INIT 2
#endif #endif

View File

@@ -300,17 +300,19 @@ typedef struct SpaceNode {
View2D v2d; View2D v2d;
struct ID *from; struct ID *id, *from; /* context, no need to save in file? well... pinning... */
int flag; short flag, menunr; /* menunr: browse id block in header */
float aspect; float aspect;
void *curfont; void *curfont;
struct uiBlock *block; struct uiBlock *block;
struct bNodeTree *nodetree; struct bNodeTree *nodetree;
int treetype, pad; /* treetype: same nodetree->type */
} SpaceNode; } SpaceNode;
/* snode->flag */
#define SNODE_DO_PREVIEW 1
# #
# #

View File

@@ -85,7 +85,7 @@ typedef struct ThemeSpace {
char edge[4], edge_select[4]; char edge[4], edge_select[4];
char edge_seam[4], edge_facesel[4]; char edge_seam[4], edge_facesel[4];
char face[4], face_select[4]; // solid faces char face[4], face_select[4]; // solid faces
char face_dot[4]; // selected color char face_dot[4]; // selected color
char normal[4]; char normal[4];
char bone_solid[4], bone_pose[4]; char bone_solid[4], bone_pose[4];
char strip[4], strip_select[4]; char strip[4], strip_select[4];
@@ -93,8 +93,8 @@ typedef struct ThemeSpace {
char vertex_size, facedot_size; char vertex_size, facedot_size;
char bpad[2]; char bpad[2];
char syntaxl[4], syntaxn[4], syntaxb[4]; //syn- char syntaxl[4], syntaxn[4], syntaxb[4]; // syntax for textwindow and nodes
char syntaxv[4], syntaxc[4]; //tax char syntaxv[4], syntaxc[4];
} ThemeSpace; } ThemeSpace;
@@ -119,6 +119,7 @@ typedef struct bTheme {
ThemeSpace text; ThemeSpace text;
ThemeSpace toops; ThemeSpace toops;
ThemeSpace ttime; ThemeSpace ttime;
ThemeSpace tnode;
} bTheme; } bTheme;

View File

@@ -190,6 +190,7 @@ void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec);
void ramp_spec_result(float *specr, float *specg, float *specb, ShadeInput *shi); void ramp_spec_result(float *specr, float *specg, float *specb, ShadeInput *shi);
void matlayer_blend(struct MaterialLayer *ml, float blendfac, struct ShadeResult *target, struct ShadeResult *src); void matlayer_blend(struct MaterialLayer *ml, float blendfac, struct ShadeResult *target, struct ShadeResult *src);
void ramp_blend(int type, float *r, float *g, float *b, float fac, float *col);
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
/* ray.c (2) */ /* ray.c (2) */

View File

@@ -102,7 +102,8 @@ typedef struct ShadeInput
float dxrefract[3], dyrefract[3]; float dxrefract[3], dyrefract[3];
float dxstrand, dystrand; float dxstrand, dystrand;
float xs, ys; /* pixel to be rendered */ int xs, ys; /* pixel to be rendered */
short do_preview, pr_type; /* for nodes, in previewrender */
short osatex, puno; short osatex, puno;
int mask; int mask;
int depth; int depth;

View File

@@ -2071,7 +2071,7 @@ void ray_ao(ShadeInput *shi, World *wrld, float *shadfac)
nrm= shi->facenor; nrm= shi->facenor;
} }
vec= sphere_sampler(wrld->aomode, wrld->aosamp, floor(shi->xs+0.5), floor(shi->ys+0.5) ); vec= sphere_sampler(wrld->aomode, wrld->aosamp, shi->xs, shi->ys);
// warning: since we use full sphere now, and dotproduct is below, we do twice as much // warning: since we use full sphere now, and dotproduct is below, we do twice as much
tot= 2*wrld->aosamp*wrld->aosamp; tot= 2*wrld->aosamp*wrld->aosamp;
@@ -2202,7 +2202,7 @@ void ray_shadow(ShadeInput *shi, LampRen *lar, float *shadfac)
else shadfac[3]= 1.0; // 1.0=full light else shadfac[3]= 1.0; // 1.0=full light
fac= 0.0; fac= 0.0;
jitlamp= give_jitter_plane(lar, floor(shi->xs+0.5), floor(shi->ys+0.5)); jitlamp= give_jitter_plane(lar, shi->xs, shi->ys);
a= lar->ray_totsamp; a= lar->ray_totsamp;

View File

@@ -2198,7 +2198,7 @@ void shade_input_set_coords(ShadeInput *shi, float u, float v, int i1, int i2, i
} }
if(texco & TEXCO_REFL) { if(texco & TEXCO_REFL) {
/* mirror reflection colour textures (and envmap) */ /* mirror reflection colour textures (and envmap) */
calc_R_ref(shi); calc_R_ref(shi); /* wrong location for normal maps! XXXXXXXXXXXXXX */
} }
if(texco & TEXCO_STRESS) { if(texco & TEXCO_STRESS) {
float *s1, *s2, *s3; float *s1, *s2, *s3;
@@ -2279,9 +2279,10 @@ void *shadepixel(float x, float y, int z, int facenr, int mask, float *col, floa
return NULL; return NULL;
} }
/* currently in use for dithering (soft shadow) and detecting thread */ /* currently in use for dithering (soft shadow) and detecting thread */
shi.xs= x; shi.xs= (int)(x+0.5f);
shi.ys= y; shi.ys= (int)(y+0.5f);
shi.do_preview= 0;
/* mask is used to indicate amount of samples (ray shad/mir and AO) */ /* mask is used to indicate amount of samples (ray shad/mir and AO) */
shi.mask= mask; shi.mask= mask;
shi.depth= 0; // means first hit, not raytracing shi.depth= 0; // means first hit, not raytracing

View File

@@ -2352,7 +2352,7 @@ void render_realtime_texture(ShadeInput *shi)
tex2.type= TEX_IMAGE; tex2.type= TEX_IMAGE;
} }
if(((int)(shi->ys+0.5)) & 1) tex= &tex1; else tex= &tex2; // threadsafe if(shi->ys & 1) tex= &tex1; else tex= &tex2; // threadsafe
ima = shi->vlr->tface->tpage; ima = shi->vlr->tface->tpage;
if(ima) { if(ima) {

File diff suppressed because it is too large Load Diff

View File

@@ -221,6 +221,23 @@ void test_grouppoin_but(char *name, ID **idpp)
*idpp= NULL; *idpp= NULL;
} }
void test_texpoin_but(char *name, ID **idpp)
{
ID *id;
if( *idpp ) (*idpp)->us--;
id= G.main->tex.first;
while(id) {
if( strcmp(name, id->name+2)==0 ) {
*idpp= id;
id_us_plus(id);
return;
}
id= id->next;
}
*idpp= NULL;
}
/* --------------------------------- */ /* --------------------------------- */
@@ -372,11 +389,12 @@ void redraw_test_buttons(Object *new)
addqueue(sa->win, REDRAW, 1); addqueue(sa->win, REDRAW, 1);
buts->re_align= 1; buts->re_align= 1;
if(new) { if(new && buts->mainb==CONTEXT_SHADING) {
BIF_preview_changed(buts); /* does node previews too... */
BIF_preview_changed(ID_TE);
} }
} }
// always to context switch // always do context switch
if(new) butspace_context_switch(buts, new); if(new) butspace_context_switch(buts, new);
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1034,7 +1034,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
glPixelZoom((float)sima->zoom, (float)sima->zoom); glPixelZoom((float)sima->zoom, (float)sima->zoom);
if(sima->flag & SI_EDITTILE) { if(sima->flag & SI_EDITTILE) {
glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->rect); glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
glPixelZoom(1.0, 1.0); glPixelZoom(1.0, 1.0);
@@ -1079,14 +1079,14 @@ void drawimagespace(ScrArea *sa, void *spacedata)
/* rect= ibuf->rect; */ /* rect= ibuf->rect; */
for(sy= 0; sy+dy<=ibuf->y; sy+= dy) { for(sy= 0; sy+dy<=ibuf->y; sy+= dy) {
for(sx= 0; sx+dx<=ibuf->x; sx+= dx) { for(sx= 0; sx+dx<=ibuf->x; sx+= dx) {
glaDrawPixelsSafe(x1+sx*sima->zoom, y1+sy*sima->zoom, dx, dy, rect); glaDrawPixelsSafe(x1+sx*sima->zoom, y1+sy*sima->zoom, dx, dy, GL_UNSIGNED_BYTE, rect);
} }
} }
MEM_freeN(rect); MEM_freeN(rect);
} }
else else
glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->rect); glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
if(Gip.current == IMAGEPAINT_CLONE) { if(Gip.current == IMAGEPAINT_CLONE) {
int w, h; int w, h;
@@ -1103,7 +1103,7 @@ void drawimagespace(ScrArea *sa, void *spacedata)
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glaDrawPixelsSafe(x1 + offx, y1 + offy, w, h, clonerect); glaDrawPixelsSafe(x1 + offx, y1 + offy, w, h, GL_UNSIGNED_BYTE, clonerect);
glDisable(GL_BLEND); glDisable(GL_BLEND);
MEM_freeN(clonerect); MEM_freeN(clonerect);

View File

@@ -42,6 +42,7 @@
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
#include "DNA_space_types.h" #include "DNA_space_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "DNA_texture_types.h"
#include "DNA_userdef_types.h" #include "DNA_userdef_types.h"
#include "BKE_global.h" #include "BKE_global.h"
@@ -51,7 +52,9 @@
#include "BKE_utildefines.h" #include "BKE_utildefines.h"
#include "BIF_gl.h" #include "BIF_gl.h"
#include "BIF_glutil.h"
#include "BIF_interface.h" #include "BIF_interface.h"
#include "BIF_interface_icons.h"
#include "BIF_language.h" #include "BIF_language.h"
#include "BIF_mywindow.h" #include "BIF_mywindow.h"
#include "BIF_resources.h" #include "BIF_resources.h"
@@ -64,147 +67,324 @@
#include "BMF_Api.h" #include "BMF_Api.h"
#include "blendef.h" #include "blendef.h"
#include "butspace.h"
#include "interface.h" /* urm... for rasterpos_safe, roundbox */ #include "interface.h" /* urm... for rasterpos_safe, roundbox */
#include "mydevice.h"
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
/* ************** Draw callbacks *********** */ static void snode_drawstring(SpaceNode *snode, char *str, int okwidth)
static void node_shader_draw_value(SpaceNode *snode, bNode *node)
{ {
char drawstr[NODE_MAXSTR];
int width;
if(snode->block) { if(str[0]==0) return;
BLI_strncpy(drawstr, str, NODE_MAXSTR);
width= snode->aspect*BIF_GetStringWidth(snode->curfont, drawstr, 0);
if(width > okwidth) {
int len= strlen(drawstr)-1;
while(width > okwidth && len>=0) {
drawstr[len]= 0;
width= snode->aspect*BIF_GetStringWidth(snode->curfont, drawstr, 0);
len--;
}
if(len==0) return;
}
BIF_DrawString(snode->curfont, drawstr, 0);
}
/* ************** Socket callbacks *********** */
/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
static uiBlock *socket_value_menu(void *sock_v)
{
bNodeSocket *sock= sock_v;
uiBlock *block;
char name[NODE_MAXSTR];
/* don't add new block to a listbase if caller is LABEL button */
block= uiNewBlock(NULL, "socket menu", UI_EMBOSS, UI_HELV, curarea->win);
/* use this for a fake extra empy space around the buttons */
uiDefBut(block, LABEL, 0, "", -4, -4, 188, 28, NULL, 0, 0, 0, 0, "");
BLI_strncpy(name, sock->name, NODE_MAXSTR-1);
strcat(name, " ");
uiDefButF(block, NUMSLI, 0, name, 0,0,180,20, sock->ns.vec, 0.0, 1.0, 10, 0, "");
uiBlockSetDirection(block, UI_TOP);
return block;
}
/* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
static uiBlock *socket_vector_menu(void *sock_v)
{
bNodeSocket *sock= sock_v;
uiBlock *block;
/* don't add new block to a listbase if caller is LABEL button */
block= uiNewBlock(NULL, "socket menu", UI_EMBOSS, UI_HELV, curarea->win);
/* use this for a fake extra empy space around the buttons */
uiDefBut(block, LABEL, 0, "", -4, -4, 188, 68, NULL, 0, 0, 0, 0, "");
uiBlockBeginAlign(block);
uiDefButF(block, NUMSLI, 0, "X ", 0,40,180,20, sock->ns.vec, -1.0, 1.0, 10, 0, "");
uiDefButF(block, NUMSLI, 0, "Y ", 0,20,180,20, sock->ns.vec+1, -1.0, 1.0, 10, 0, "");
uiDefButF(block, NUMSLI, 0, "Z ", 0,0,180,20, sock->ns.vec+2, -1.0, 1.0, 10, 0, "");
uiBlockSetDirection(block, UI_TOP);
return block;
}
static uiBlock *socket_color_menu(void *sock_v)
{
bNodeSocket *sock= sock_v;
uiBlock *block;
/* don't add new block to a listbase if caller is LABEL button */
block= uiNewBlock(NULL, "socket menu", UI_EMBOSS, UI_HELV, curarea->win);
/* use this for a fake extra empy space around the buttons */
uiDefBut(block, LABEL, 0, "", -4, -4, 188, 68, NULL, 0, 0, 0, 0, "");
uiBlockBeginAlign(block);
uiDefButF(block, NUMSLI, 0, "R ", 0,40,180,20, sock->ns.vec, 0.0, 1.0, 10, 0, "");
uiDefButF(block, NUMSLI, 0, "G ", 0,20,180,20, sock->ns.vec+1, 0.0, 1.0, 10, 0, "");
uiDefButF(block, NUMSLI, 0, "B ", 0,0,180,20, sock->ns.vec+2, 0.0, 1.0, 10, 0, "");
uiBlockSetDirection(block, UI_TOP);
return block;
}
static void node_ID_title_cb(void *node_v, void *unused_v)
{
bNode *node= node_v;
if(node->id)
BLI_strncpy(node->name, node->id->name+2, 21);
}
/* ****************** BUTTON CALLBACKS FOR SHADER NODES ***************** */
static int node_shader_buts_material(uiBlock *block, bNode *node, rctf *butr)
{
if(block) {
uiBut *bt;
float dx= (butr->xmax-butr->xmin)/3.0f;
uiBlockBeginAlign(block);
bt= uiDefIDPoinBut(block, test_matpoin_but, ID_MA, B_NODE_EXEC, "",
butr->xmin, butr->ymin+19.0f, butr->xmax-butr->xmin, 19.0f,
&node->id, "");
uiButSetFunc(bt, node_ID_title_cb, node, NULL);
uiDefButBitS(block, TOG, SH_NODE_MAT_DIFF, B_NODE_EXEC, "Diff",
butr->xmin, butr->ymin, dx, 19.0f,
&node->custom1, 0, 0, 0, 0, "Material Node outputs Diffuse");
uiDefButBitS(block, TOG, SH_NODE_MAT_SPEC, B_NODE_EXEC, "Spec",
butr->xmin+dx, butr->ymin, dx, 19.0f,
&node->custom1, 0, 0, 0, 0, "Material Node outputs Specular");
uiDefButBitS(block, TOG, SH_NODE_MAT_NEG, B_NODE_EXEC, "Neg Normal",
butr->xmin+2.0f*dx, butr->ymin, dx, 19.0f,
&node->custom1, 0, 0, 0, 0, "Material Node uses inverted Normal");
uiBlockEndAlign(block);
}
return 38;
}
static int node_shader_buts_texture(uiBlock *block, bNode *node, rctf *butr)
{
if(block) {
uiBut *bt; uiBut *bt;
bt= uiDefButF(snode->block, NUM, B_NODE_EXEC, "", bt= uiDefIDPoinBut(block, test_texpoin_but, ID_TE, B_NODE_EXEC, "",
node->prv.xmin, node->prv.ymin, node->prv.xmax-node->prv.xmin, node->prv.ymax-node->prv.ymin, butr->xmin, butr->ymin, butr->xmax-butr->xmin, 19.0f,
node->ns.vec, 0.0f, 1.0f, 100, 2, ""); &node->id, "");
uiButSetFunc(bt, node_ID_title_cb, node, NULL);
} }
return 19;
} }
static void node_shader_draw_rgb(SpaceNode *snode, bNode *node) static int node_shader_buts_value(uiBlock *block, bNode *node, rctf *butr)
{ {
if(block) {
if(snode->block) { bNodeSocket *sock= node->outputs.first; /* first socket stores value */
uiDefButF(block, NUM, B_NODE_EXEC, "",
butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20.0f,
sock->ns.vec, 0.0f, 1.0f, 10, 2, "");
}
return 20;
}
static int node_shader_buts_rgb(uiBlock *block, bNode *node, rctf *butr)
{
if(block) {
bNodeSocket *sock= node->outputs.first; /* first socket stores value */
/* enforce square box drawing */ /* enforce square box drawing */
uiBlockSetEmboss(snode->block, UI_EMBOSSP); uiBlockSetEmboss(block, UI_EMBOSSP);
uiDefButF(snode->block, HSVCUBE, B_NODE_EXEC, "", uiDefButF(block, HSVCUBE, B_NODE_EXEC, "",
node->prv.xmin, node->prv.ymin, node->prv.xmax-node->prv.xmin, 10.0f, butr->xmin, butr->ymin, butr->xmax-butr->xmin, 12.0f,
node->ns.vec, 0.0f, 1.0f, 3, 0, ""); sock->ns.vec, 0.0f, 1.0f, 3, 0, "");
uiDefButF(snode->block, HSVCUBE, B_NODE_EXEC, "", uiDefButF(block, HSVCUBE, B_NODE_EXEC, "",
node->prv.xmin, node->prv.ymin+14.0f, node->prv.xmax-node->prv.xmin, node->prv.ymax-node->prv.ymin-14.0f, butr->xmin, butr->ymin+15.0f, butr->xmax-butr->xmin, butr->ymax-butr->ymin -15.0f -15.0f,
node->ns.vec, 0.0f, 1.0f, 2, 0, ""); sock->ns.vec, 0.0f, 1.0f, 2, 0, "");
uiDefButF(block, COL, B_NOP, "",
butr->xmin, butr->ymax-12.0f, butr->xmax-butr->xmin, 12.0f,
sock->ns.vec, 0.0, 0.0, -1, 0, "");
/* the -1 above prevents col button to popup a color picker */
uiDefButF(snode->block, COL, B_NOP, "", uiBlockSetEmboss(block, UI_EMBOSS);
node->prv.xmin, node->prv.ymax+10.0f, node->prv.xmax-node->prv.xmin, 15.0f,
node->ns.vec, 0.0, 0.0, -1, 0, "");
/* the -1 above prevents col button to popup a color picker */
uiBlockSetEmboss(snode->block, UI_EMBOSS);
} }
return 30 + (int)(node->width-NODE_DY);
} }
static void node_shader_draw_show_rgb(SpaceNode *snode, bNode *node) static void node_but_title_cb(void *node_v, void *but_v)
{ {
bNode *node= node_v;
if(snode->block) { uiBut *bt= but_v;
BLI_strncpy(node->name, bt->drawstr, NODE_MAXSTR);
/* enforce square box drawing */
uiBlockSetEmboss(snode->block, UI_EMBOSSP);
uiDefButF(snode->block, COL, B_NOP, "",
node->prv.xmin, node->prv.ymin-NODE_DY, node->prv.xmax-node->prv.xmin, NODE_DY,
node->ns.vec, 0.0f, 0.0f, -1, 0, "");
/* the -1 above prevents col button to popup a color picker */
uiBlockSetEmboss(snode->block, UI_EMBOSS);
}
} }
static int node_shader_buts_mix_rgb(uiBlock *block, bNode *node, rctf *butr)
/* exported to editnode.c */
void node_shader_set_drawfunc(bNode *node)
{ {
switch(node->type) { if(block) {
case SH_NODE_TEST: uiBut *bt;
node->drawfunc= NULL; bNodeSocket *sock= node->inputs.first; /* first socket stores "fac" */
uiBlockBeginAlign(block);
/* blend type */
bt=uiDefButS(block, MENU, B_NODE_EXEC, "Mix %x0|Add %x1|Subtract %x3|Multiply %x2|Screen %x4|Divide %x5|Difference %x6|Darken %x7|Lighten %x8",
butr->xmin, butr->ymin+20.0f, butr->xmax-butr->xmin, 20.0f,
&node->custom1, 0, 0, 0, 0, "");
uiButSetFunc(bt, node_but_title_cb, node, bt);
/* value */
uiDefButF(block, NUM, B_NODE_EXEC, "",
butr->xmin, butr->ymin, butr->xmax-butr->xmin, 20.0f,
sock->ns.vec, 0.0f, 1.0f, 10, 2, "");
uiBlockEndAlign(block);
}
return 40;
}
static int node_shader_buts_valtorgb(uiBlock *block, bNode *node, rctf *butr)
{
if(block && (node->flag & NODE_OPTIONS)) {
if(node->storage) {
draw_colorband_buts_small(block, node->storage, butr, B_NODE_EXEC);
}
}
return 40;
}
/* only once called */
static void node_shader_set_butfunc(bNodeType *ntype)
{
switch(ntype->type) {
case SH_NODE_MATERIAL:
ntype->butfunc= node_shader_buts_material;
break;
case SH_NODE_TEXTURE:
ntype->butfunc= node_shader_buts_texture;
break; break;
case SH_NODE_VALUE: case SH_NODE_VALUE:
node->drawfunc= node_shader_draw_value; ntype->butfunc= node_shader_buts_value;
break; break;
case SH_NODE_RGB: case SH_NODE_RGB:
node->drawfunc= node_shader_draw_rgb; ntype->butfunc= node_shader_buts_rgb;
break;
case SH_NODE_SHOW_RGB:
node->drawfunc= node_shader_draw_show_rgb;
break; break;
case SH_NODE_MIX_RGB: case SH_NODE_MIX_RGB:
node->drawfunc= NULL; ntype->butfunc= node_shader_buts_mix_rgb;
break; break;
case SH_NODE_VALTORGB:
ntype->butfunc= node_shader_buts_valtorgb;
break;
default:
ntype->butfunc= NULL;
} }
} }
/* ******* init draw callbacks for all tree types ************* */ /* ******* init draw callbacks for all tree types, only called in usiblender.c, once ************* */
static void ntree_init_callbacks(bNodeTree *ntree) void init_node_butfuncs(void)
{ {
bNode *node; bNodeType **typedefs;
for(node= ntree->nodes.first; node; node= node->next) { /* shader nodes */
if(ntree->type==NTREE_SHADER) typedefs= node_all_shaders; /* BKE_node.h */
node_shader_set_drawfunc(node); while( *typedefs) {
node_shader_set_butfunc(*typedefs);
typedefs++;
} }
ntree->init |= NTREE_DRAW_SET; }
}
/* ************** Generic drawing ************** */ /* ************** Generic drawing ************** */
static void draw_nodespace_grid(SpaceNode *snode) static void draw_nodespace_grid(SpaceNode *snode)
{ {
// float fac, step= 20.0f; float start, step= 25.0f;
/* window is 'pixel size', like buttons */ /* window is 'pixel size', like buttons */
BIF_ThemeColorShade(TH_BACK, 10); BIF_ThemeColorShade(TH_BACK, -10);
glRectf(0.0f, 0.0f, curarea->winx, curarea->winy); start= snode->v2d.cur.xmin -fmod(snode->v2d.cur.xmin, step);
glBegin(GL_LINES);
for(; start<snode->v2d.cur.xmax; start+=step) {
glVertex2f(start, snode->v2d.cur.ymin);
glVertex2f(start, snode->v2d.cur.ymax);
}
start= snode->v2d.cur.ymin -fmod(snode->v2d.cur.ymin, step);
for(; start<snode->v2d.cur.ymax; start+=step) {
glVertex2f(snode->v2d.cur.xmin, start);
glVertex2f(snode->v2d.cur.xmax, start);
}
glEnd();
} }
/* get from assigned ID */ static void nodeshadow(rctf *rct, float radius, int select)
static void get_nodetree(SpaceNode *snode)
{ {
/* note: once proper coded, remove free from freespacelist() */ float rad;
if(snode->nodetree==NULL) { float a;
snode->nodetree= MEM_callocN(sizeof(bNodeTree), "new node tree");
}
}
static void nodeshadow(rctf *rct, int select)
{
int a;
char alpha= 2; char alpha= 2;
uiSetRoundBox(15);
glEnable(GL_BLEND); glEnable(GL_BLEND);
if(select) a= 10; else a=7; if(radius > (rct->ymax-rct->ymin-10.0f)/2.0f)
for(; a>0; a-=1) { rad= (rct->ymax-rct->ymin-10.0f)/2.0f;
else
rad= radius;
if(select) a= 10.0f; else a= 7.0f;
for(; a>0.0f; a-=1.0f) {
/* alpha ranges from 2 to 20 or so */ /* alpha ranges from 2 to 20 or so */
glColor4ub(0, 0, 0, alpha); glColor4ub(0, 0, 0, alpha);
alpha+= 2; alpha+= 2;
gl_round_box(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, 8.0f+a); gl_round_box(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax-10.0f + a, rad+a);
} }
/* outline emphasis */ /* outline emphasis */
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glColor4ub(0, 0, 0, 100); glColor4ub(0, 0, 0, 100);
gl_round_box(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, 8.0f); gl_round_box(GL_LINE_LOOP, rct->xmin-0.5f, rct->ymin-0.5f, rct->xmax+0.5f, rct->ymax+0.5f, radius);
glDisable( GL_LINE_SMOOTH ); glDisable( GL_LINE_SMOOTH );
glDisable(GL_BLEND); glDisable(GL_BLEND);
@@ -230,7 +410,9 @@ static void socket_circle_draw(float x, float y, float size, int type, int selec
int a; int a;
if(select==0) { if(select==0) {
if(type==SOCK_VALUE) if(type==-1)
glColor3ub(0, 0, 0);
else if(type==SOCK_VALUE)
glColor3ub(160, 160, 160); glColor3ub(160, 160, 160);
else if(type==SOCK_VECTOR) else if(type==SOCK_VECTOR)
glColor3ub(100, 100, 200); glColor3ub(100, 100, 200);
@@ -266,54 +448,288 @@ static void socket_circle_draw(float x, float y, float size, int type, int selec
glDisable(GL_BLEND); glDisable(GL_BLEND);
} }
static int node_basis_draw(SpaceNode *snode, bNode *node) /* not a callback */
static void node_draw_preview(bNodePreview *preview, rctf *prv)
{
float scale= (prv->xmax-prv->xmin)/((float)preview->xsize);
glPixelZoom(scale, scale);
glEnable(GL_BLEND);
glaDrawPixelsTex(prv->xmin, prv->ymin, preview->xsize, preview->ysize, GL_FLOAT, preview->rect);
glDisable(GL_BLEND);
glPixelZoom(1.0f, 1.0f);
}
/* based on settings in node, sets drawing rect info */
static void node_update(bNode *node)
{
bNodeSocket *nsock;
float dy= node->locy;
if(node->flag & NODE_HIDDEN) {
float rad, drad;
node->totr.xmin= node->locx;
node->totr.xmax= node->locx + 3*HIDDEN_RAD;
node->totr.ymax= node->locy;
node->totr.ymin= node->locy - 2*HIDDEN_RAD;
/* output connectors */
rad=drad= M_PI/(1.0f + (float)BLI_countlist(&node->outputs));
for(nsock= node->outputs.first; nsock; nsock= nsock->next, rad+= drad) {
nsock->locx= node->totr.xmax - HIDDEN_RAD + sin(rad)*HIDDEN_RAD;
nsock->locy= node->totr.ymin + HIDDEN_RAD + cos(rad)*HIDDEN_RAD;
}
/* input connectors */
rad=drad= - M_PI/(1.0f + (float)BLI_countlist(&node->inputs));
for(nsock= node->inputs.first; nsock; nsock= nsock->next, rad+= drad) {
nsock->locx= node->totr.xmin + HIDDEN_RAD + sin(rad)*HIDDEN_RAD;
nsock->locy= node->totr.ymin + HIDDEN_RAD + cos(rad)*HIDDEN_RAD;
}
}
else {
/* header */
dy-= NODE_DY;
/* output connectors */
for(nsock= node->outputs.first; nsock; nsock= nsock->next) {
nsock->locx= node->locx + node->width;
nsock->locy= dy - NODE_DYS;
dy-= NODE_DY;
}
node->prvr.xmin= node->butr.xmin= node->locx + NODE_DYS;
node->prvr.xmax= node->butr.xmax= node->locx + node->width- NODE_DYS;
/* preview rect? */
if(node->flag & NODE_PREVIEW) {
dy-= NODE_DYS/2;
node->prvr.ymax= dy;
node->prvr.ymin= dy-(node->width-NODE_DY);
dy= node->prvr.ymin - NODE_DYS/2;
}
/* buttons rect? */
if((node->flag & NODE_OPTIONS) && node->typeinfo->butfunc) {
dy-= NODE_DYS/2;
node->butr.ymax= dy;
node->butr.ymin= dy - (float)node->typeinfo->butfunc(NULL, node, NULL);
dy= node->butr.ymin - NODE_DYS/2;
}
/* input connectors */
for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
nsock->locx= node->locx;
nsock->locy= dy - NODE_DYS;
dy-= NODE_DY;
}
node->totr.xmin= node->locx;
node->totr.xmax= node->locx + node->width;
node->totr.ymax= node->locy;
node->totr.ymin= dy;
}
}
static void node_scaling_widget(int color_id, float aspect, float xmin, float ymin, float xmax, float ymax)
{
float dx;
float dy;
dx= 0.5f*(xmax-xmin);
dy= 0.5f*(ymax-ymin);
BIF_ThemeColorShade(color_id, +30);
fdrawline(xmin, ymin, xmax, ymax);
fdrawline(xmin+dx, ymin, xmax, ymax-dy);
BIF_ThemeColorShade(color_id, -10);
fdrawline(xmin, ymin+aspect, xmax, ymax+aspect);
fdrawline(xmin+dx, ymin+aspect, xmax, ymax-dy+aspect);
}
static int node_get_colorid(bNode *node)
{
if(node->typeinfo->nclass==NODE_CLASS_INPUT)
return TH_NODE_IN_OUT;
if(node->typeinfo->nclass==NODE_CLASS_OUTPUT) {
if(node->flag & NODE_DO_OUTPUT)
return TH_NODE_IN_OUT;
else
return TH_NODE;
}
if(node->typeinfo->nclass==NODE_CLASS_GENERATOR)
return TH_NODE_GENERATOR;
if(node->typeinfo->nclass==NODE_CLASS_OPERATOR)
return TH_NODE_OPERATOR;
return TH_NODE;
}
static void node_basis_draw(SpaceNode *snode, bNode *node)
{ {
bNodeSocket *sock; bNodeSocket *sock;
rctf *rct= &node->tot; rctf *rct= &node->totr;
float slen; float slen, iconofs;
int trans= (U.transopts & USER_TR_BUTTONS); int ofs, color_id= node_get_colorid(node);
nodeshadow(rct, node->flag & SELECT); uiSetRoundBox(15-4);
nodeshadow(rct, BASIS_RAD, node->flag & SELECT);
BIF_ThemeColorShade(TH_HEADER, 0); /* header */
BIF_ThemeColorShade(color_id, 0);
uiSetRoundBox(3); uiSetRoundBox(3);
uiRoundBox(rct->xmin, rct->ymax-NODE_DY, rct->xmax, rct->ymax, 8); uiRoundBox(rct->xmin, rct->ymax-NODE_DY, rct->xmax, rct->ymax, BASIS_RAD);
BIF_ThemeColorShade(TH_HEADER, 20); /* open/close entirely? */
uiSetRoundBox(12); // ui_draw_tria_icon(rct->xmin+6.0f, rct->ymax-NODE_DY+5.0f, snode->aspect, 'h');
uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax-NODE_DY, 8);
ui_rasterpos_safe(rct->xmin+4.0f, rct->ymax-NODE_DY+5.0f, snode->aspect); /* show/hide icons */
iconofs= rct->xmax;
if(node->typeinfo->flag & NODE_PREVIEW) {
int icon_id;
if(node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))
icon_id= ICON_MATERIAL;
else
icon_id= ICON_MATERIAL_DEHLT;
iconofs-= 18.0f;
glEnable(GL_BLEND);
BIF_icon_set_aspect(icon_id, snode->aspect);
BIF_icon_draw_blended(iconofs, rct->ymax-NODE_DY+2, icon_id, 0, -50);
glDisable(GL_BLEND);
}
if(node->typeinfo->flag & NODE_OPTIONS) {
iconofs-= 18.0f;
glEnable(GL_BLEND);
BIF_icon_set_aspect(ICON_BUTS, snode->aspect);
BIF_icon_draw_blended(iconofs, rct->ymax-NODE_DY+2, ICON_BUTS, 0, -50);
glDisable(GL_BLEND);
}
/* title */
if(node->flag & SELECT) if(node->flag & SELECT)
BIF_ThemeColor(TH_TEXT_HI); BIF_ThemeColor(TH_TEXT_HI);
else else
BIF_ThemeColor(TH_TEXT); BIF_ThemeColor(TH_TEXT);
BIF_DrawString(snode->curfont, node->name, trans); ui_rasterpos_safe(rct->xmin+6.0f, rct->ymax-NODE_DY+5.0f, snode->aspect);
snode_drawstring(snode, node->name, (int)(iconofs - rct->xmin-6.0f));
/* body */
BIF_ThemeColorShade(color_id, 20);
uiSetRoundBox(8);
uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax-NODE_DY, BASIS_RAD);
/* scaling indicator */
node_scaling_widget(color_id, snode->aspect, rct->xmax-BASIS_RAD*snode->aspect, rct->ymin, rct->xmax, rct->ymin+BASIS_RAD*snode->aspect);
/* outline active emphasis */
if(node->flag & NODE_ACTIVE) {
glEnable(GL_BLEND);
glColor4ub(200, 200, 200, 140);
uiSetRoundBox(15-4);
gl_round_box(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
glDisable(GL_BLEND);
}
/* socket inputs, label buttons */
for(sock= node->inputs.first; sock; sock= sock->next) { for(sock= node->inputs.first; sock; sock= sock->next) {
socket_circle_draw(sock->locx, sock->locy, NODE_SOCK, sock->type, sock->flag & SELECT); socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
if(sock->type==SOCK_VALUE) {
uiBut *bt= uiDefBut(snode->block, LABEL, B_NODE_EXEC, sock->name, sock->locx+5.0f, sock->locy-10.0f, node->width-NODE_DY, NODE_DY, sock, 0, 0, 0, 0, "");
bt->block_func= socket_value_menu;
}
else if(sock->type==SOCK_VECTOR) {
uiBut *bt= uiDefBut(snode->block, LABEL, B_NODE_EXEC, sock->name, sock->locx+5.0f, sock->locy-10.0f, node->width-NODE_DY, NODE_DY, sock, 0, 0, 0, 0, "");
bt->block_func= socket_vector_menu;
}
else if(sock->type==SOCK_RGBA) {
uiBut *bt= uiDefBut(snode->block, LABEL, B_NODE_EXEC, sock->name, sock->locx+5.0f, sock->locy-10.0f, node->width-NODE_DY, NODE_DY, sock, 0, 0, 0, 0, "");
bt->block_func= socket_color_menu;
}
else {
BIF_ThemeColor(TH_TEXT);
ui_rasterpos_safe(sock->locx+8.0f, sock->locy-5.0f, snode->aspect);
BIF_DrawString(snode->curfont, sock->name, 0);
}
}
/* socket outputs */
for(sock= node->outputs.first; sock; sock= sock->next) {
socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
BIF_ThemeColor(TH_TEXT); BIF_ThemeColor(TH_TEXT);
ui_rasterpos_safe(sock->locx+8.0f, sock->locy-5.0f, snode->aspect); ofs= 0;
BIF_DrawString(snode->curfont, sock->name, trans); slen= snode->aspect*BIF_GetStringWidth(snode->curfont, sock->name, 0);
while(slen > node->width) {
ofs++;
slen= snode->aspect*BIF_GetStringWidth(snode->curfont, sock->name+ofs, 0);
}
ui_rasterpos_safe(sock->locx-8.0f-slen, sock->locy-5.0f, snode->aspect);
BIF_DrawString(snode->curfont, sock->name+ofs, 0);
}
/* preview */
if(node->flag & NODE_PREVIEW)
if(node->preview)
node_draw_preview(node->preview, &node->prvr);
/* buttons */
if(node->flag & NODE_OPTIONS)
if(node->typeinfo->butfunc)
node->typeinfo->butfunc(snode->block, node, &node->butr);
}
void node_hidden_draw(SpaceNode *snode, bNode *node)
{
bNodeSocket *sock;
rctf *rct= &node->totr;
int color_id= node_get_colorid(node);
/* shadow */
uiSetRoundBox(15);
nodeshadow(rct, HIDDEN_RAD, node->flag & SELECT);
/* body */
BIF_ThemeColorShade(color_id, 20);
uiRoundBox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, HIDDEN_RAD);
/* outline active emphasis */
if(node->flag & NODE_ACTIVE) {
glEnable(GL_BLEND);
glColor4ub(200, 200, 200, 140);
gl_round_box(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, HIDDEN_RAD);
glDisable(GL_BLEND);
}
/* icon */
if(node->id) {
glEnable(GL_BLEND);
BIF_icon_set_aspect(node->id->icon_id, snode->aspect);
BIF_icon_draw(rct->xmin+HIDDEN_RAD, -1.0f+rct->ymin+HIDDEN_RAD/2, node->id->icon_id);
glDisable(GL_BLEND);
}
/* sockets */
for(sock= node->inputs.first; sock; sock= sock->next) {
socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
} }
for(sock= node->outputs.first; sock; sock= sock->next) { for(sock= node->outputs.first; sock; sock= sock->next) {
socket_circle_draw(sock->locx, sock->locy, NODE_SOCK, sock->type, sock->flag & SELECT); socket_circle_draw(sock->locx, sock->locy, NODE_SOCKSIZE, sock->type, sock->flag & SELECT);
BIF_ThemeColor(TH_TEXT);
slen= snode->aspect*BIF_GetStringWidth(snode->curfont, sock->name, trans);
ui_rasterpos_safe(sock->locx-8.0f-slen, sock->locy-5.0f, snode->aspect);
BIF_DrawString(snode->curfont, sock->name, trans);
} }
return 0;
} }
void node_draw_link(SpaceNode *snode, bNodeLink *link)
static void node_draw_link(SpaceNode *snode, bNodeLink *link)
{ {
float vec[4][3]; float vec[4][3];
float dist, spline_step, mx=0.0f, my=0.0f; float dist, spline_step, mx=0.0f, my=0.0f;
@@ -358,7 +774,7 @@ static void node_draw_link(SpaceNode *snode, bNodeLink *link)
vec[3][1]= my; vec[3][1]= my;
} }
dist= 0.5*VecLenf(vec[0], vec[3]); dist= 0.5f*ABS(vec[0][0] - vec[3][0]);
/* check direction later, for top sockets */ /* check direction later, for top sockets */
vec[1][0]= vec[0][0]+dist; vec[1][0]= vec[0][0]+dist;
@@ -414,15 +830,17 @@ void drawnodespace(ScrArea *sa, void *spacedata)
draw_nodespace_grid(snode); draw_nodespace_grid(snode);
/* nodes */ /* nodes */
get_nodetree(snode); /* editor context */
snode_set_context(snode);
if(snode->nodetree) { if(snode->nodetree) {
bNode *node; bNode *node;
bNodeLink *link; bNodeLink *link;
if((snode->nodetree->init & NTREE_DRAW_SET)==0) /* for now, we set drawing coordinates on each redraw */
ntree_init_callbacks(snode->nodetree); for(node= snode->nodetree->nodes.first; node; node= node->next)
node_update(node);
/* node lines */ /* node lines */
glEnable(GL_BLEND); glEnable(GL_BLEND);
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
@@ -437,8 +855,10 @@ void drawnodespace(ScrArea *sa, void *spacedata)
for(node= snode->nodetree->nodes.first; node; node= node->next) { for(node= snode->nodetree->nodes.first; node; node= node->next) {
if(!(node->flag & SELECT)) { if(!(node->flag & SELECT)) {
node_basis_draw(snode, node); if(node->flag & NODE_HIDDEN)
if(node->drawfunc) node->drawfunc(snode, node); node_hidden_draw(snode, node);
else
node_basis_draw(snode, node);
} }
} }
uiDrawBlock(snode->block); uiDrawBlock(snode->block);
@@ -449,8 +869,10 @@ void drawnodespace(ScrArea *sa, void *spacedata)
for(node= snode->nodetree->nodes.first; node; node= node->next) { for(node= snode->nodetree->nodes.first; node; node= node->next) {
if(node->flag & SELECT) { if(node->flag & SELECT) {
node_basis_draw(snode, node); if(node->flag & NODE_HIDDEN)
if(node->drawfunc) node->drawfunc(snode, node); node_hidden_draw(snode, node);
else
node_basis_draw(snode, node);
} }
} }
@@ -465,4 +887,10 @@ void drawnodespace(ScrArea *sa, void *spacedata)
draw_area_emboss(sa); draw_area_emboss(sa);
curarea->win_swap= WIN_BACK_OK; curarea->win_swap= WIN_BACK_OK;
/* in the end, this is a delayed previewrender test, to allow buttons to be first */
if(snode->flag & SNODE_DO_PREVIEW) {
addafterqueue(sa->win, RENDERPREVIEW, 1);
snode->flag &= ~SNODE_DO_PREVIEW;
}
} }

View File

@@ -503,7 +503,7 @@ static void draw_image_seq(ScrArea *sa)
glaDefine2DArea(&curarea->winrct); glaDefine2DArea(&curarea->winrct);
glPixelZoom(zoom, zoom); glPixelZoom(zoom, zoom);
glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, ibuf->rect); glaDrawPixelsSafe(x1, y1, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect);
glPixelZoom(1.0, 1.0); glPixelZoom(1.0, 1.0);

View File

@@ -435,7 +435,7 @@ static void draw_bgpic(void)
glaDefine2DArea(&curarea->winrct); glaDefine2DArea(&curarea->winrct);
glPixelZoom(zoomx, zoomy); glPixelZoom(zoomx, zoomy);
glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, bgpic->rect); glaDrawPixelsSafe(x1, y1, ima->ibuf->x, ima->ibuf->y, GL_UNSIGNED_BYTE, bgpic->rect);
glPixelZoom(1.0, 1.0); glPixelZoom(1.0, 1.0);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);

View File

@@ -129,12 +129,12 @@ void circle_selectCB(select_CBfunc func);
/* local protos ---------------*/ /* local protos ---------------*/
void snap_curs_to_firstsel(void); void snap_curs_to_firstsel(void);
/* flag==2 only border, flag==3 cross+border */
int get_border(rcti *rect, short col) int get_border(rcti *rect, short flag)
{ {
float dvec[4], fac1, fac2; float dvec[4], fac1, fac2;
int retval=1; int retval=1;
unsigned short event; unsigned short event= 0;
short mval[2], mvalo[4], val, x1, y1; short mval[2], mvalo[4], val, x1, y1;
char str[64]; char str[64];
@@ -153,56 +153,59 @@ int get_border(rcti *rect, short col)
persp(PERSP_WIN); persp(PERSP_WIN);
initgrabz(0.0, 0.0, 0.0); initgrabz(0.0, 0.0, 0.0);
getmouseco_areawin(mvalo); if(flag & 1) {
getmouseco_areawin(mvalo);
/* draws the selection initial cross */ /* draws the selection initial cross */
sdrawXORline4(0, 0, mvalo[1], curarea->winx, mvalo[1]); sdrawXORline4(0, 0, mvalo[1], curarea->winx, mvalo[1]);
sdrawXORline4(1, mvalo[0], 0, mvalo[0], curarea->winy); sdrawXORline4(1, mvalo[0], 0, mvalo[0], curarea->winy);
glFlush(); glFlush();
while(TRUE) {
/* selection loop while mouse pressed */
getmouseco_areawin(mval);
if(mvalo[0]!=mval[0] || mvalo[1]!=mval[1]) {
/* aiming cross */
sdrawXORline4(0, 0, mval[1], curarea->winx, mval[1]);
sdrawXORline4(1, mval[0], 0, mval[0], curarea->winy);
glFlush();
mvalo[0]= mval[0];
mvalo[1]= mval[1];
}
event= extern_qread(&val);
if(event && val) {
/* for when a renderwindow is open, and a mouse cursor activates it */
persp(PERSP_VIEW);
mywinset(curarea->win);
persp(PERSP_WIN);
if(event==ESCKEY) {
retval= 0;
break;
}
else if(event==BKEY) {
/* b has been pressed twice: proceed with circle select */
retval= 0;
break;
}
else if(event==LEFTMOUSE) break;
else if(event==MIDDLEMOUSE) break;
else if(event==RIGHTMOUSE) break;
}
else PIL_sleep_ms(10);
} /* end while (TRUE) */ while(TRUE) {
/* selection loop while mouse pressed */
getmouseco_areawin(mval);
if(mvalo[0]!=mval[0] || mvalo[1]!=mval[1]) {
/* erase XORed lines */ /* aiming cross */
sdrawXORline4(-1, 0, 0, 0, 0); sdrawXORline4(0, 0, mval[1], curarea->winx, mval[1]);
sdrawXORline4(1, mval[0], 0, mval[0], curarea->winy);
glFlush();
mvalo[0]= mval[0];
mvalo[1]= mval[1];
}
event= extern_qread(&val);
if(event && val) {
/* for when a renderwindow is open, and a mouse cursor activates it */
persp(PERSP_VIEW);
mywinset(curarea->win);
persp(PERSP_WIN);
if(event==ESCKEY) {
retval= 0;
break;
}
else if(event==BKEY) {
/* b has been pressed twice: proceed with circle select */
retval= 0;
break;
}
else if(event==LEFTMOUSE) break;
else if(event==MIDDLEMOUSE) break;
else if(event==RIGHTMOUSE) break;
}
else PIL_sleep_ms(10);
} /* end while (TRUE) */
/* erase XORed lines */
sdrawXORline4(-1, 0, 0, 0, 0);
}
else getmouseco_areawin(mval);
if(retval) { if(retval) {
/* box select */ /* box select */

File diff suppressed because it is too large Load Diff

View File

@@ -1039,8 +1039,10 @@ void set_active_base(Base *base)
/* signal to ipo */ /* signal to ipo */
allqueue(REDRAWIPO, base->object->ipowin); allqueue(REDRAWIPO, base->object->ipowin);
allqueue(REDRAWACTION, 0); allqueue(REDRAWACTION, 0);
allqueue(REDRAWNLA, 0); allqueue(REDRAWNLA, 0);
allqueue(REDRAWNODE, 0);
/* signal to action */ /* signal to action */
select_actionchannel_by_name(base->object->action, "Object", 1); select_actionchannel_by_name(base->object->action, "Object", 1);
@@ -1957,7 +1959,7 @@ void set_render_border(void)
if(G.vd->persp!=2) return; if(G.vd->persp!=2) return;
val= get_border(&rect, 2); val= get_border(&rect, 3);
if(val) { if(val) {
rcti vb; rcti vb;

View File

@@ -220,9 +220,9 @@ static int get_cached_work_texture(int *w_r, int *h_r)
glBindTexture(GL_TEXTURE_2D, texid); glBindTexture(GL_TEXTURE_2D, texid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
tbuf= MEM_callocN(tex_w*tex_h*4, "tbuf"); tbuf= MEM_callocN(tex_w*tex_h*4, "tbuf");
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tbuf); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, tbuf);
@@ -236,9 +236,10 @@ static int get_cached_work_texture(int *w_r, int *h_r)
return texid; return texid;
} }
void glaDrawPixelsTex(float x, float y, int img_w, int img_h, void *rect) void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *rect)
{ {
unsigned char *uc_rect= (unsigned char*) rect; unsigned char *uc_rect= (unsigned char*) rect;
float *f_rect= (float *)rect;
float xzoom= glaGetOneFloat(GL_ZOOM_X), yzoom= glaGetOneFloat(GL_ZOOM_Y); float xzoom= glaGetOneFloat(GL_ZOOM_X), yzoom= glaGetOneFloat(GL_ZOOM_Y);
int ltexid= glaGetOneInteger(GL_TEXTURE_2D); int ltexid= glaGetOneInteger(GL_TEXTURE_2D);
int lrowlength= glaGetOneInteger(GL_UNPACK_ROW_LENGTH); int lrowlength= glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
@@ -256,9 +257,12 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, void *rect)
int subpart_h= (subpart_y==nsubparts_y-1)?(img_h-subpart_y*tex_h):tex_h; int subpart_h= (subpart_y==nsubparts_y-1)?(img_h-subpart_y*tex_h):tex_h;
float rast_x= x+subpart_x*tex_w*xzoom; float rast_x= x+subpart_x*tex_w*xzoom;
float rast_y= y+subpart_y*tex_h*yzoom; float rast_y= y+subpart_y*tex_h*yzoom;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, GL_RGBA, GL_UNSIGNED_BYTE, &uc_rect[(subpart_y*tex_w)*img_w*4 + (subpart_x*tex_w)*4]); if(format==GL_FLOAT)
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, GL_RGBA, GL_FLOAT, &f_rect[(subpart_y*tex_w)*img_w*4 + (subpart_x*tex_w)*4]);
else
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, GL_RGBA, GL_UNSIGNED_BYTE, &uc_rect[(subpart_y*tex_w)*img_w*4 + (subpart_x*tex_w)*4]);
glColor3ub(255, 255, 255); glColor3ub(255, 255, 255);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS); glBegin(GL_QUADS);
@@ -282,10 +286,8 @@ void glaDrawPixelsTex(float x, float y, int img_w, int img_h, void *rect)
glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength); glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength);
} }
void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, void *rect) void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int format, void *rect)
{ {
unsigned char *uc_rect= (unsigned char*) rect;
float xzoom= glaGetOneFloat(GL_ZOOM_X); float xzoom= glaGetOneFloat(GL_ZOOM_X);
float yzoom= glaGetOneFloat(GL_ZOOM_Y); float yzoom= glaGetOneFloat(GL_ZOOM_Y);
@@ -337,7 +339,15 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, void *rect)
} }
glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w); glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect + (off_y*img_w + off_x)*4); if(format==GL_FLOAT) {
float *f_rect= (float *)rect;
glDrawPixels(draw_w, draw_h, GL_RGBA, GL_FLOAT, f_rect + (off_y*img_w + off_x)*4);
}
else {
unsigned char *uc_rect= (unsigned char *) rect;
glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, uc_rect + (off_y*img_w + off_x)*4);
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, old_row_length); glPixelStorei(GL_UNPACK_ROW_LENGTH, old_row_length);
} }
} }

View File

@@ -137,7 +137,7 @@ void do_buts_buttons(short event)
scrarea_queue_winredraw(curarea); scrarea_queue_winredraw(curarea);
break; break;
case B_BUTSPREVIEW: case B_BUTSPREVIEW:
BIF_preview_changed(G.buts); BIF_preview_changed(ID_TE);
G.buts->oldkeypress = 0; G.buts->oldkeypress = 0;
scrarea_queue_headredraw(curarea); scrarea_queue_headredraw(curarea);
scrarea_queue_winredraw(curarea); scrarea_queue_winredraw(curarea);
@@ -203,7 +203,7 @@ void do_buts_buttons(short event)
for(ml= ma->layers.first; ml; ml= ml->next) for(ml= ma->layers.first; ml; ml= ml->next)
if(ml->mat) ml->mat->id.us++; if(ml->mat) ml->mat->id.us++;
BIF_preview_changed(G.buts); BIF_preview_changed(ID_MA);
BIF_undo_push("Paste material settings"); BIF_undo_push("Paste material settings");
scrarea_queue_winredraw(curarea); scrarea_queue_winredraw(curarea);
} }

View File

@@ -471,7 +471,7 @@ void do_info_buttons(unsigned short event)
set_scene(sce); set_scene(sce);
} }
BIF_preview_changed(G.buts); BIF_preview_changed(ID_TE);
break; break;
case B_INFODELSCE: case B_INFODELSCE:

View File

@@ -886,7 +886,7 @@ void do_ipo_buttons(short event)
scrarea_queue_winredraw(curarea); scrarea_queue_winredraw(curarea);
break; break;
case B_IPOBORDER: case B_IPOBORDER:
val= get_border(&rect, 2); val= get_border(&rect, 3);
if(val) { if(val) {
mval[0]= rect.xmin; mval[0]= rect.xmin;
mval[1]= rect.ymin; mval[1]= rect.ymin;

View File

@@ -33,6 +33,9 @@
#include <stdio.h> #include <stdio.h>
#include "DNA_ID.h" #include "DNA_ID.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "DNA_scene_types.h" #include "DNA_scene_types.h"
#include "DNA_space_types.h" #include "DNA_space_types.h"
@@ -41,6 +44,7 @@
#include "BIF_gl.h" #include "BIF_gl.h"
#include "BIF_interface.h" #include "BIF_interface.h"
#include "BIF_previewrender.h"
#include "BIF_resources.h" #include "BIF_resources.h"
#include "BIF_screen.h" #include "BIF_screen.h"
#include "BIF_space.h" #include "BIF_space.h"
@@ -49,8 +53,10 @@
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "BKE_material.h"
#include "BSE_headerbuttons.h" #include "BSE_headerbuttons.h"
#include "BSE_node.h"
#include "blendef.h" #include "blendef.h"
#include "butspace.h" #include "butspace.h"
@@ -58,17 +64,29 @@
void do_node_buttons(ScrArea *sa, unsigned short event) void do_node_buttons(ScrArea *sa, unsigned short event)
{ {
// SpaceNode *snode= sa->spacedata.first; SpaceNode *snode= sa->spacedata.first;
Material *ma;
switch(event) { switch(event) {
; case B_NODE_USEMAT:
ma= (Material *)snode->id;
if(ma) {
if(ma->use_nodes && ma->nodetree==NULL) {
node_shader_default(ma);
snode_set_context(snode);
}
BIF_preview_changed(ID_MA);
allqueue(REDRAWNODE, 0);
allqueue(REDRAWBUTSSHADING, 0);
}
break;
} }
} }
void node_buttons(ScrArea *sa) void node_buttons(ScrArea *sa)
{ {
// SpaceNode *snode= sa->spacedata.first; SpaceNode *snode= sa->spacedata.first;
uiBlock *block; uiBlock *block;
short xco; short xco;
char name[256]; char name[256];
@@ -106,7 +124,6 @@ void node_buttons(ScrArea *sa)
&(sa->flag), 0, 0, 0, 0, &(sa->flag), 0, 0, 0, 0,
"Hide pulldown menus"); "Hide pulldown menus");
} }
uiBlockSetEmboss(block, UI_EMBOSS);
xco+=XIC; xco+=XIC;
if((sa->flag & HEADER_NO_PULLDOWN)==0) { if((sa->flag & HEADER_NO_PULLDOWN)==0) {
@@ -119,6 +136,25 @@ void node_buttons(ScrArea *sa)
// xco+= xmax; // xco+= xmax;
} }
uiBlockSetEmboss(block, UI_EMBOSS);
/* find and set the context */
snode_set_context(snode);
if(snode->treetype==NTREE_SHADER) {
if(snode->from) {
/* 0, NULL -> pin */
xco= std_libbuttons(block, xco, 0, 0, NULL, B_MATBROWSE, snode->id, snode->from, &(snode->menunr),
B_MATALONE, B_MATLOCAL, B_MATDELETE, B_AUTOMATNAME, B_KEEPDATA);
if(snode->id) {
Material *ma= (Material *)snode->id;
uiDefButC(block, TOG, B_NODE_USEMAT, "Use Nodes", xco+5,0,70,19, &ma->use_nodes, 0.0f, 0.0f, 0, 0, "");
xco+=80;
}
}
}
/* always as last */ /* always as last */
sa->headbutlen= xco+2*XIC; sa->headbutlen= xco+2*XIC;

View File

@@ -782,7 +782,8 @@ void do_global_buttons(unsigned short event)
BIF_undo_push("Browse Material"); BIF_undo_push("Browse Material");
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
BIF_preview_changed(G.buts); allqueue(REDRAWNODE, 0);
BIF_preview_changed(ID_MA);
} }
} }
@@ -799,7 +800,7 @@ void do_global_buttons(unsigned short event)
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_MA);
} }
} }
break; break;
@@ -819,7 +820,7 @@ void do_global_buttons(unsigned short event)
ma->mtex[ ma->texact ]= NULL; ma->mtex[ ma->texact ]= NULL;
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_MA);
} }
} }
} }
@@ -833,7 +834,7 @@ void do_global_buttons(unsigned short event)
wrld->mtex[ wrld->texact ]= NULL; wrld->mtex[ wrld->texact ]= NULL;
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_WO);
} }
} }
} }
@@ -847,7 +848,7 @@ void do_global_buttons(unsigned short event)
la->mtex[ la->texact ]= NULL; la->mtex[ la->texact ]= NULL;
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_LA);
} }
} }
} }
@@ -913,7 +914,7 @@ void do_global_buttons(unsigned short event)
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_MA);
} }
} }
break; break;
@@ -1101,7 +1102,7 @@ void do_global_buttons(unsigned short event)
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_WO);
} }
break; break;
case B_WORLDDELETE: case B_WORLDDELETE:
@@ -1169,7 +1170,7 @@ void do_global_buttons(unsigned short event)
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_WO);
} }
} }
break; break;
@@ -1209,7 +1210,7 @@ void do_global_buttons(unsigned short event)
allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWVIEW3D, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_LA);
} }
break; break;
@@ -1266,7 +1267,7 @@ void do_global_buttons(unsigned short event)
allqueue(REDRAWBUTSSHADING, 0); allqueue(REDRAWBUTSSHADING, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
BIF_preview_changed(G.buts); BIF_preview_changed(ID_LA);
} }
} }
break; break;

View File

@@ -69,11 +69,13 @@
#include "DNA_userdef_types.h" #include "DNA_userdef_types.h"
#include "DNA_vec_types.h" #include "DNA_vec_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_texture_types.h"
#include "DNA_vfont_types.h" #include "DNA_vfont_types.h"
#include "BKE_blender.h" #include "BKE_blender.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_library.h" #include "BKE_library.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h" #include "BKE_utildefines.h"
#include "BIF_gl.h" #include "BIF_gl.h"
@@ -908,6 +910,9 @@ void uiDrawBlock(uiBlock *block)
uiBut *but; uiBut *but;
short testmouse=0, mouse[2]; short testmouse=0, mouse[2];
/* we set this only once */
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
/* handle pending stuff */ /* handle pending stuff */
if(block->autofill) ui_autofill(block); if(block->autofill) ui_autofill(block);
if(block->minx==0.0 && block->maxx==0.0) uiBoundsBlock(block, 0); if(block->minx==0.0 && block->maxx==0.0) uiBoundsBlock(block, 0);
@@ -2453,7 +2458,7 @@ static int ui_do_but_NUMSLI(uiBut *but)
} }
/* event denotes if we make first item active or not */ /* event denotes if we make first item active or not */
static int ui_do_but_BLOCK(uiBut *but, int event) static uiBlock *ui_do_but_BLOCK(uiBut *but, int event)
{ {
uiBlock *block; uiBlock *block;
uiBut *bt; uiBut *bt;
@@ -2494,7 +2499,7 @@ static int ui_do_but_BLOCK(uiBut *but, int event)
but->flag &= ~UI_SELECT; but->flag &= ~UI_SELECT;
uibut_do_func(but); uibut_do_func(but);
return 0; return block;
} }
static int ui_do_but_BUTM(uiBut *but) static int ui_do_but_BUTM(uiBut *but)
@@ -2510,9 +2515,25 @@ static int ui_do_but_BUTM(uiBut *but)
static int ui_do_but_LABEL(uiBut *but) static int ui_do_but_LABEL(uiBut *but)
{ {
/* new label type, for nodes, ctrl+clock on text gives options */
uibut_do_func(but); if(but->block_func) {
return but->retval; if(G.qual & LR_CTRLKEY) {
ListBase listb={NULL, NULL};
uiBlock *block= ui_do_but_BLOCK(but, 0);
BLI_addtail(&listb, block);
block->parent= NULL; /* we abused ui_do_but_BLOCK */
uiDoBlocks(&listb, 0);
uibut_do_func(but);
return but->retval;
}
return 0;
}
else {
uibut_do_func(but);
return but->retval;
}
} }
static uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval) static uiBut *ui_get_valid_link_button(uiBlock *block, uiBut *but, short *mval)
@@ -3147,6 +3168,104 @@ static int ui_do_but_CHARTAB(uiBut *but)
#endif #endif
static int vergcband(const void *a1, const void *a2)
{
const CBData *x1=a1, *x2=a2;
if( x1->pos > x2->pos ) return 1;
else if( x1->pos < x2->pos) return -1;
return 0;
}
static void do_colorband_evt(ColorBand *coba)
{
int a;
if(coba==NULL) return;
if(coba->tot<2) return;
for(a=0; a<coba->tot; a++) coba->data[a].cur= a;
qsort(coba->data, coba->tot, sizeof(CBData), vergcband);
for(a=0; a<coba->tot; a++) {
if(coba->data[a].cur==coba->cur) {
if(coba->cur!=a) addqueue(curarea->win, REDRAW, 0); /* button cur */
coba->cur= a;
break;
}
}
}
static int ui_do_but_COLORBAND(uiBut *but)
{
ColorBand *coba= (ColorBand *)but->poin;
CBData *cbd;
float dx, width= but->x2-but->x1;
int a;
int mindist= 12, xco;
short mval[2], mvalo[2];
uiGetMouse(mywinget(), mvalo);
if(G.qual & LR_CTRLKEY) {
/* insert new key on mouse location */
if(coba->tot < MAXCOLORBAND-1) {
float pos= ((float)(mvalo[0] - but->x1))/width;
float col[4];
do_colorband(coba, pos, col); /* executes it */
coba->tot++;
coba->cur= coba->tot-1;
coba->data[coba->cur].r= col[0];
coba->data[coba->cur].g= col[1];
coba->data[coba->cur].b= col[2];
coba->data[coba->cur].a= col[3];
coba->data[coba->cur].pos= pos;
do_colorband_evt(coba);
}
}
else {
/* first, activate new key when mouse is close */
for(a=0, cbd= coba->data; a<coba->tot; a++, cbd++) {
xco= but->x1 + (cbd->pos*width);
xco= ABS(xco-mvalo[0]);
if(a==coba->cur) xco+= 5; // selected one disadvantage
if(xco<mindist) {
coba->cur= a;
mindist= xco;
}
}
cbd= coba->data + coba->cur;
while(get_mbut() & L_MOUSE) {
uiGetMouse(mywinget(), mval);
if(mval[0]!=mvalo[0]) {
dx= mval[0]-mvalo[0];
dx/= width;
cbd->pos+= dx;
CLAMP(cbd->pos, 0.0, 1.0);
ui_draw_but(but);
ui_block_flush_back(but->block);
do_colorband_evt(coba);
cbd= coba->data + coba->cur; /* because qsort */
mvalo[0]= mval[0];
}
BIF_wait_for_statechange();
}
}
return but->retval;
}
/* ************************************************ */ /* ************************************************ */
@@ -3320,7 +3439,8 @@ static int ui_do_button(uiBlock *block, uiBut *but, uiEvent *uevent)
case BLOCK: case BLOCK:
case PULLDOWN: case PULLDOWN:
if(uevent->val) { if(uevent->val) {
retval= ui_do_but_BLOCK(but, uevent->event); ui_do_but_BLOCK(but, uevent->event);
retval= 0;
if(block->auto_open==0) block->auto_open= 1; if(block->auto_open==0) block->auto_open= 1;
} }
break; break;
@@ -3341,6 +3461,9 @@ static int ui_do_button(uiBlock *block, uiBut *but, uiEvent *uevent)
case HSVCUBE: case HSVCUBE:
retval= ui_do_but_HSVCUBE(but); retval= ui_do_but_HSVCUBE(but);
break; break;
case BUT_COLORBAND:
retval= ui_do_but_COLORBAND(but);
break;
#ifdef INTERNATIONAL #ifdef INTERNATIONAL
case CHARTAB: case CHARTAB:
@@ -4869,37 +4992,32 @@ void ui_check_but(uiBut *but)
/* calc but->ofs, to draw the string shorter if too long */ /* calc but->ofs, to draw the string shorter if too long */
but->ofs= 0; but->ofs= 0;
while(but->strwidth > (int)okwidth ) { while(but->strwidth > (int)okwidth ) {
but->ofs++;
if(but->drawstr[but->ofs]) if ELEM(but->type, NUM, TEX) { // only these cut off left
but->ofs++;
but->strwidth= but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, transopts); but->strwidth= but->aspect*BIF_GetStringWidth(but->font, but->drawstr+but->ofs, transopts);
else but->strwidth= 0;
/* textbut exception */
/* textbut exception */ if(but->pos != -1) {
if(but->pos != -1) { pos= but->pos+strlen(but->str);
pos= but->pos+strlen(but->str); if(pos-1 < but->ofs) {
if(pos-1 < but->ofs) { pos= but->ofs-pos+1;
pos= but->ofs-pos+1; but->ofs -= pos;
but->ofs -= pos; if(but->ofs<0) {
if(but->ofs<0) { but->ofs= 0;
but->ofs= 0; pos--;
pos--; }
but->drawstr[ strlen(but->drawstr)-pos ]= 0;
} }
but->drawstr[ strlen(but->drawstr)-pos ]= 0;
} }
} }
else {
but->drawstr[ strlen(but->drawstr)-1 ]= 0;
but->strwidth= but->aspect*BIF_GetStringWidth(but->font, but->drawstr, transopts);
}
if(but->strwidth < 10) break; if(but->strwidth < 10) break;
} }
/* fix for buttons that better not have text cut off to the right */
if(but->ofs) {
if ELEM(but->type, NUM, TEX); // only these cut off left
else {
but->drawstr[ strlen(but->drawstr)-but->ofs ]= 0;
but->ofs= 0;
}
}
} }
} }

View File

@@ -55,17 +55,19 @@
#include "BLI_blenlib.h" #include "BLI_blenlib.h"
#include "BLI_arithb.h" #include "BLI_arithb.h"
#include "DNA_packedFile_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "DNA_space_types.h" #include "DNA_space_types.h"
#include "DNA_texture_types.h"
#include "DNA_userdef_types.h" #include "DNA_userdef_types.h"
#include "DNA_vec_types.h" #include "DNA_vec_types.h"
#include "DNA_vfont_types.h" #include "DNA_vfont_types.h"
#include "DNA_packedFile_types.h"
#include "BKE_blender.h" #include "BKE_blender.h"
#include "BKE_utildefines.h"
#include "BKE_font.h" #include "BKE_font.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_utildefines.h"
#include "datatoc.h" /* std font */ #include "datatoc.h" /* std font */
#include "BIF_gl.h" #include "BIF_gl.h"
@@ -151,15 +153,24 @@ void uiEmboss(float x1, float y1, float x2, float y2, int sel)
/* ************** GENERIC ICON DRAW, NO THEME HERE ************* */ /* ************** GENERIC ICON DRAW, NO THEME HERE ************* */
/* icons have been standardized... and this call draws in untransformed coordinates */
#define ICON_HEIGHT 16.0f
static void ui_draw_icon(uiBut *but, BIFIconID icon) static void ui_draw_icon(uiBut *but, BIFIconID icon)
{ {
// void BIF_icon_pos(float xs, float ys); float xs=0, ys=0, aspect, height;
int blend= 0; int blend= 0;
float xs=0, ys=0;
// this icon doesn't need draw... /* this icon doesn't need draw... */
if(icon==ICON_BLANK1) return; if(icon==ICON_BLANK1) return;
/* we need aspect from block, for menus... these buttons are scaled in uiPositionBlock() */
aspect= but->block->aspect;
if(aspect != but->aspect)
height= ICON_HEIGHT/aspect;
else
height= ICON_HEIGHT;
if(but->flag & UI_ICON_LEFT) { if(but->flag & UI_ICON_LEFT) {
if (but->type==BUTM) { if (but->type==BUTM) {
xs= but->x1+1.0; xs= but->x1+1.0;
@@ -170,22 +181,21 @@ static void ui_draw_icon(uiBut *but, BIFIconID icon)
else { else {
xs= but->x1+6.0; xs= but->x1+6.0;
} }
ys= (but->y1+but->y2- BIF_icon_get_height(icon))/2.0; ys= (but->y1+but->y2- height)/2.0;
} }
if(but->flag & UI_ICON_RIGHT) { if(but->flag & UI_ICON_RIGHT) {
xs= but->x2-17.0; xs= but->x2-17.0;
ys= (but->y1+but->y2- BIF_icon_get_height(icon))/2.0; ys= (but->y1+but->y2- height)/2.0;
} }
if (!((but->flag & UI_ICON_RIGHT) || (but->flag & UI_ICON_LEFT))) { if (!((but->flag & UI_ICON_RIGHT) || (but->flag & UI_ICON_LEFT))) {
xs= (but->x1+but->x2- BIF_icon_get_width(icon))/2.0; xs= (but->x1+but->x2- height)/2.0;
ys= (but->y1+but->y2- BIF_icon_get_height(icon))/2.0; ys= (but->y1+but->y2- height)/2.0;
} }
if(but->aspect>1.1) glPixelZoom(1.0/but->aspect, 1.0/but->aspect); /* aspect for the icon has to be stored */
else if(but->aspect<0.9) glPixelZoom(1.0/but->aspect, 1.0/but->aspect); BIF_icon_set_aspect(icon, aspect);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* calculate blend color */ /* calculate blend color */
if ELEM4(but->type, ICONTOG, TOG, ROW, TOGN) { if ELEM4(but->type, ICONTOG, TOG, ROW, TOGN) {
@@ -193,12 +203,10 @@ static void ui_draw_icon(uiBut *but, BIFIconID icon)
else if(but->flag & UI_ACTIVE); else if(but->flag & UI_ACTIVE);
else blend= -60; else blend= -60;
} }
BIF_icon_draw_blended(xs, ys, icon, but->themecol, blend); BIF_icon_draw_blended((int)(xs+0.5f), (int)(ys+0.5f), icon, but->themecol, blend);
glBlendFunc(GL_ONE, GL_ZERO);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glPixelZoom(1.0, 1.0);
} }
@@ -406,7 +414,6 @@ static void ui_default_iconrow_arrows(float x1, float y1, float x2, float y2)
{ {
glEnable( GL_POLYGON_SMOOTH ); glEnable( GL_POLYGON_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
@@ -430,7 +437,6 @@ static void ui_default_menu_arrows(float x1, float y1, float x2, float y2)
{ {
glEnable( GL_POLYGON_SMOOTH ); glEnable( GL_POLYGON_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
@@ -456,7 +462,6 @@ static void ui_default_num_arrows(float x1, float y1, float x2, float y2)
glEnable( GL_POLYGON_SMOOTH ); glEnable( GL_POLYGON_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
@@ -486,7 +491,6 @@ static void ui_tog3_invert(float x1, float y1, float x2, float y2, int seltype)
short alpha = 30; short alpha = 30;
if (seltype == 0) { if (seltype == 0) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glColor4ub(0, 0, 0, alpha); glColor4ub(0, 0, 0, alpha);
@@ -497,7 +501,6 @@ static void ui_tog3_invert(float x1, float y1, float x2, float y2, int seltype)
glDisable(GL_BLEND); glDisable(GL_BLEND);
} else { } else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glColor4ub(255, 255, 255, alpha); glColor4ub(255, 255, 255, alpha);
@@ -521,7 +524,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
if (!((align == UI_BUT_ALIGN_DOWN) || if (!((align == UI_BUT_ALIGN_DOWN) ||
(align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT)) || (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT)) ||
(align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT)))) { (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT)))) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
MM_WHITE_OP; MM_WHITE_OP;
fdrawline(x1, y1-1, x2, y1-1); fdrawline(x1, y1-1, x2, y1-1);
@@ -547,7 +549,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
case UI_BUT_ALIGN_LEFT: case UI_BUT_ALIGN_LEFT:
/* RIGHT OUTER SUNKEN EFFECT */ /* RIGHT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -564,7 +565,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
case UI_BUT_ALIGN_RIGHT: case UI_BUT_ALIGN_RIGHT:
/* LEFT OUTER SUNKEN EFFECT */ /* LEFT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -590,7 +590,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT: case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
/* LEFT OUTER SUNKEN EFFECT */ /* LEFT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -607,7 +606,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT: case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
/* RIGHT OUTER SUNKEN EFFECT */ /* RIGHT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -628,7 +626,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
} }
} }
else { else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
@@ -663,7 +660,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
case ICONROW: case ICONROW:
case ICONTEXTROW: case ICONTEXTROW:
/* DARKENED AREA */ /* DARKENED AREA */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glColor4ub(0, 0, 0, 30); glColor4ub(0, 0, 0, 30);
@@ -679,7 +675,6 @@ static void ui_default_button(int type, int colorid, float asp, float x1, float
break; break;
case MENU: case MENU:
/* DARKENED AREA */ /* DARKENED AREA */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glColor4ub(0, 0, 0, 30); glColor4ub(0, 0, 0, 30);
@@ -708,7 +703,6 @@ static void ui_default_flat(int type, int colorid, float asp, float x1, float y1
if (!((align == UI_BUT_ALIGN_DOWN) || if (!((align == UI_BUT_ALIGN_DOWN) ||
(align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT)) || (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_RIGHT)) ||
(align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT)))) { (align == (UI_BUT_ALIGN_DOWN|UI_BUT_ALIGN_LEFT)))) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
MM_WHITE_OP; MM_WHITE_OP;
fdrawline(x1, y1-1, x2, y1-1); fdrawline(x1, y1-1, x2, y1-1);
@@ -734,7 +728,6 @@ static void ui_default_flat(int type, int colorid, float asp, float x1, float y1
case UI_BUT_ALIGN_LEFT: case UI_BUT_ALIGN_LEFT:
/* RIGHT OUTER SUNKEN EFFECT */ /* RIGHT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -751,7 +744,6 @@ static void ui_default_flat(int type, int colorid, float asp, float x1, float y1
case UI_BUT_ALIGN_RIGHT: case UI_BUT_ALIGN_RIGHT:
/* LEFT OUTER SUNKEN EFFECT */ /* LEFT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -777,7 +769,6 @@ static void ui_default_flat(int type, int colorid, float asp, float x1, float y1
case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT: case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_RIGHT:
/* LEFT OUTER SUNKEN EFFECT */ /* LEFT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -794,7 +785,6 @@ static void ui_default_flat(int type, int colorid, float asp, float x1, float y1
case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT: case UI_BUT_ALIGN_TOP|UI_BUT_ALIGN_LEFT:
/* RIGHT OUTER SUNKEN EFFECT */ /* RIGHT OUTER SUNKEN EFFECT */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
glBegin(GL_LINES); glBegin(GL_LINES);
@@ -816,7 +806,6 @@ static void ui_default_flat(int type, int colorid, float asp, float x1, float y1
} }
else { else {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
@@ -1079,7 +1068,6 @@ static void round_button(float x1, float y1, float x2, float y2, float asp,
/* fake AA */ /* fake AA */
uiSetRoundBox(round); uiSetRoundBox(round);
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
BIF_GetThemeColor3ubv(colorid, col); BIF_GetThemeColor3ubv(colorid, col);
@@ -1318,7 +1306,6 @@ static void ui_draw_slider(int colorid, float fac, float aspect, float x1, float
static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha) static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
{ {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH); glShadeModel(GL_SMOOTH);
@@ -1399,7 +1386,6 @@ static void ui_draw_pulldown_item(int type, int colorid, float asp, float x1, fl
BIF_GetThemeColor4ubv(TH_MENU_BACK, col); BIF_GetThemeColor4ubv(TH_MENU_BACK, col);
if(col[3]!=255) { if(col[3]!=255) {
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
} }
if((flag & UI_ACTIVE) && type!=LABEL) { if((flag & UI_ACTIVE) && type!=LABEL) {
@@ -1427,7 +1413,6 @@ static void ui_draw_pulldown_round(int type, int colorid, float asp, float x1, f
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
gl_round_box(GL_LINE_LOOP, x1, y1+3, x2, y2-3, 7.0); gl_round_box(GL_LINE_LOOP, x1, y1+3, x2, y2-3, 7.0);
glDisable( GL_LINE_SMOOTH ); glDisable( GL_LINE_SMOOTH );
glDisable( GL_BLEND ); glDisable( GL_BLEND );
@@ -1873,9 +1858,120 @@ static void ui_draw_but_CHARTAB(uiBut *but)
#endif // INTERNATIONAL #endif // INTERNATIONAL
static void ui_draw_but_COLORBAND(uiBut *but)
{
ColorBand *coba= (ColorBand *)but->poin;
CBData *cbd;
float x1, y1, sizex, sizey;
float dx, v3[2], v1[2], v2[2];
int a;
if(coba==NULL) return;
x1= but->x1;
y1= but->y1;
sizex= but->x2-x1;
sizey= but->y2-y1;
/* first background, to show tranparency */
dx= sizex/12.0;
v1[0]= x1;
for(a=0; a<12; a++) {
if(a & 1) glColor3f(0.3, 0.3, 0.3); else glColor3f(0.8, 0.8, 0.8);
glRectf(v1[0], y1, v1[0]+dx, y1+0.5*sizey);
if(a & 1) glColor3f(0.8, 0.8, 0.8); else glColor3f(0.3, 0.3, 0.3);
glRectf(v1[0], y1+0.5*sizey, v1[0]+dx, y1+sizey);
v1[0]+= dx;
}
glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
cbd= coba->data;
v1[0]= v2[0]= x1;
v1[1]= y1;
v2[1]= y1+sizey;
glBegin(GL_QUAD_STRIP);
glColor4fv( &cbd->r );
glVertex2fv(v1); glVertex2fv(v2);
for(a=0; a<coba->tot; a++, cbd++) {
v1[0]=v2[0]= x1+ cbd->pos*sizex;
glColor4fv( &cbd->r );
glVertex2fv(v1); glVertex2fv(v2);
}
v1[0]=v2[0]= x1+ sizex;
glVertex2fv(v1); glVertex2fv(v2);
glEnd();
glShadeModel(GL_FLAT);
glDisable(GL_BLEND);
/* outline */
v1[0]= x1; v1[1]= y1;
cpack(0x0);
glBegin(GL_LINE_LOOP);
glVertex2fv(v1);
v1[0]+= sizex;
glVertex2fv(v1);
v1[1]+= sizey;
glVertex2fv(v1);
v1[0]-= sizex;
glVertex2fv(v1);
glEnd();
/* help lines */
v1[0]= v2[0]=v3[0]= x1;
v1[1]= y1;
v2[1]= y1+0.5*sizey;
v3[1]= y1+sizey;
cbd= coba->data;
glBegin(GL_LINES);
for(a=0; a<coba->tot; a++, cbd++) {
v1[0]=v2[0]=v3[0]= x1+ cbd->pos*sizex;
glColor3ub(0, 0, 0);
glVertex2fv(v1);
glVertex2fv(v2);
if(a==coba->cur) {
glVertex2f(v1[0]-1, v1[1]);
glVertex2f(v2[0]-1, v2[1]);
glVertex2f(v1[0]+1, v1[1]);
glVertex2f(v2[0]+1, v2[1]);
}
glColor3ub(255, 255, 255);
glVertex2fv(v2);
glVertex2fv(v3);
if(a==coba->cur) {
if(cbd->pos>0.01) {
glVertex2f(v2[0]-1, v2[1]);
glVertex2f(v3[0]-1, v3[1]);
}
if(cbd->pos<0.99) {
glVertex2f(v2[0]+1, v2[1]);
glVertex2f(v3[0]+1, v3[1]);
}
}
}
glEnd();
}
static void ui_draw_roundbox(uiBut *but) static void ui_draw_roundbox(uiBut *but)
{ {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
BIF_ThemeColorShadeAlpha(TH_PANEL, but->a2, but->a2); BIF_ThemeColorShadeAlpha(TH_PANEL, but->a2, but->a2);
@@ -1988,7 +2084,12 @@ void ui_draw_but(uiBut *but)
case ROUNDBOX: case ROUNDBOX:
ui_draw_roundbox(but); ui_draw_roundbox(but);
break;
case BUT_COLORBAND:
ui_draw_but_COLORBAND(but);
break;
default: default:
but->embossfunc(but->type, but->themecol, but->aspect, but->x1, but->y1, but->x2, but->y2, but->flag); but->embossfunc(but->type, but->themecol, but->aspect, but->x1, but->y1, but->x2, but->y2, but->flag);
ui_draw_text_icon(but); ui_draw_text_icon(but);

View File

@@ -470,13 +470,18 @@ static void clear_transp_rect(unsigned char *transp, unsigned char *rect, int w,
static void prepare_internal_icons(ImBuf* bbuf) static void prepare_internal_icons(ImBuf* bbuf)
{ {
int x, y; int x, y;
int rowstride= bbuf->x*4;
char *back= (char *)bbuf->rect;
unsigned char transp[4];
/* this sets blueish outside of icon to zero alpha */
QUATCOPY(transp, back);
clear_transp_rect(transp, back, bbuf->x, bbuf->y, rowstride);
/* hack! */ /* hack! */
for (y=0; y<12; y++) { for (y=0; y<12; y++) {
for (x=0; x<21; x++) { for (x=0; x<21; x++) {
int rowstride= bbuf->x*4;
unsigned char *start= ((unsigned char*) bbuf->rect) + (y*21 + 3)*rowstride + (x*20 + 3)*4; unsigned char *start= ((unsigned char*) bbuf->rect) + (y*21 + 3)*rowstride + (x*20 + 3)*4;
unsigned char transp[4];
/* this sets backdrop of icon to zero alpha */ /* this sets backdrop of icon to zero alpha */
transp[0]= start[0]; transp[0]= start[0];
transp[1]= start[1]; transp[1]= start[1];
@@ -485,10 +490,6 @@ static void prepare_internal_icons(ImBuf* bbuf)
clear_transp_rect(transp, start, 20, 21, rowstride); clear_transp_rect(transp, start, 20, 21, rowstride);
clear_transp_rect_soft(transp, start, 20, 21, rowstride); clear_transp_rect_soft(transp, start, 20, 21, rowstride);
/* this sets outside of icon to zero alpha */
start= ((unsigned char*) bbuf->rect) + (y*21)*rowstride + (x*20)*4;
QUATCOPY(transp, start);
clear_transp_rect(transp, start, 20, 21, rowstride);
} }
} }
} }
@@ -503,13 +504,7 @@ static void init_internal_icons()
for (y=0; y<12; y++) { for (y=0; y<12; y++) {
for (x=0; x<21; x++) { for (x=0; x<21; x++) {
if (x==11 && y==6) { def_internal_icon(bbuf, BIFICONID_FIRST + y*21 + x, x*20+3, y*21+3, 16, 16);
def_internal_icon(bbuf, ICON_BEVELBUT_HLT, (x*20 + 3 + 4), (y*21 + 3 + 2), 7, 13);
} else if (x==12 && y==6) {
def_internal_icon(bbuf, ICON_BEVELBUT_DEHLT, (x*20 + 3 + 4), (y*21 + 3 + 2), 7, 13);
} else {
def_internal_icon(bbuf, BIFICONID_FIRST + y*21 + x, x*20+3, y*21+3, 15, 16);
}
} }
} }
@@ -617,6 +612,51 @@ void BIF_icons_init(int first_dyn_id)
init_internal_icons(); init_internal_icons();
} }
/* create single icon from jpg, png etc. */
static void icon_from_image(Image* img, RenderInfo* ri, unsigned int w, unsigned int h)
{
struct ImBuf *ima;
float scaledx, scaledy;
int pr_size = w*h*sizeof(unsigned int);
short ex, ey, dx, dy;
if (!img)
return;
if (!ri->rect) {
ri->rect= MEM_callocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "butsrect");
memset(ri->rect, 0xFF, w*h*sizeof(unsigned int));
}
if(img->ibuf==NULL) {
load_image(img, IB_rect, G.sce, G.scene->r.cfra);
}
ima = IMB_dupImBuf(img->ibuf);
if (!ima)
return;
if (ima->x > ima->y) {
scaledx = (float)w;
scaledy = ( (float)ima->y/(float)ima->x )*(float)w;
}
else {
scaledx = ( (float)ima->x/(float)ima->y )*(float)h;
scaledy = (float)h;
}
ex = (short)scaledx;
ey = (short)scaledy;
dx = (w - ex) / 2;
dy = (h - ey) / 2;
IMB_scaleImBuf(ima, ex, ey);
memcpy(ri->rect, ima->rect, pr_size);
IMB_freeImBuf(ima);
}
/* only called when icon has changed */ /* only called when icon has changed */
/* only call with valid pointer from BIF_icon_draw */ /* only call with valid pointer from BIF_icon_draw */
static void icon_set_image(ID* id, DrawInfo* di) static void icon_set_image(ID* id, DrawInfo* di)
@@ -636,16 +676,9 @@ static void icon_set_image(ID* id, DrawInfo* di)
/* no drawing (see last parameter doDraw, just calculate preview image /* no drawing (see last parameter doDraw, just calculate preview image
- hopefully small enough to be fast */ - hopefully small enough to be fast */
if (GS(id->name) == ID_IM) if (GS(id->name) == ID_IM)
BIF_calcpreview_image((struct Image*)id, &ri, ri.pr_rectx, ri.pr_recty); icon_from_image((struct Image*)id, &ri, ri.pr_rectx, ri.pr_recty);
else { else {
BIF_previewrender(id, &ri, NULL, 0); BIF_previewrender(id, &ri, NULL, PR_ICON_RENDER);
/* need to correct alpha */
/*
for( it = 0; it < ri.pr_rectx*ri.pr_recty; ++it) {
ri.rect[it] |= 0xFF000000;
}
*/
} }
/* and copy the image into the icon */ /* and copy the image into the icon */
@@ -657,13 +690,11 @@ static void icon_set_image(ID* id, DrawInfo* di)
} }
void BIF_icon_draw( int x, int y, int icon_id) void BIF_icon_draw(float x, float y, int icon_id)
{ {
Icon* icon = 0; Icon* icon = 0;
DrawInfo* di = 0; DrawInfo* di = 0;
ImBuf *ima;
icon = BKE_icon_get(icon_id); icon = BKE_icon_get(icon_id);
if (!icon) { if (!icon) {
@@ -694,24 +725,28 @@ void BIF_icon_draw( int x, int y, int icon_id)
if (!di->rect) return; /* something has gone wrong! */ if (!di->rect) return; /* something has gone wrong! */
/* di->rect contains image in 'rendersize' */
/* first allocate imbuf for scaling and copy preview into it */
ima = IMB_allocImBuf(di->rw, di->rh, 32, IB_rect, 0);
memcpy(ima->rect, di->rect,di->rw*di->rh*sizeof(unsigned int));
/* scale it */
IMB_scaleImBuf(ima, di->w, di->h);
glRasterPos2f(x, y); glRasterPos2f(x, y);
glDrawPixels(di->w, di->h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
/* di->rect contains image in 'rendersize', we only scale if needed */
if(di->rw!=di->w && di->rh!=di->h) {
ImBuf *ima;
/* first allocate imbuf for scaling and copy preview into it */
ima = IMB_allocImBuf(di->rw, di->rh, 32, IB_rect, 0);
memcpy(ima->rect, di->rect, di->rw*di->rh*sizeof(unsigned int));
IMB_freeImBuf(ima); /* scale it */
IMB_scaleImBuf(ima, di->w, di->h);
glDrawPixels(di->w, di->h, GL_RGBA, GL_UNSIGNED_BYTE, ima->rect);
IMB_freeImBuf(ima);
}
else
glDrawPixels(di->w, di->h, GL_RGBA, GL_UNSIGNED_BYTE, di->rect);
} }
} }
void BIF_icon_draw_blended(int x, int y, int icon_id, int colorid, int shade) void BIF_icon_draw_blended(float x, float y, int icon_id, int colorid, int shade)
{ {
if(shade < 0) { if(shade < 0) {
@@ -724,7 +759,8 @@ void BIF_icon_draw_blended(int x, int y, int icon_id, int colorid, int shade)
glPixelTransferf(GL_ALPHA_SCALE, 1.0); glPixelTransferf(GL_ALPHA_SCALE, 1.0);
} }
void BIF_icon_set_aspect(int icon_id, float aspect) { void BIF_icon_set_aspect(int icon_id, float aspect)
{
Icon* icon = 0; Icon* icon = 0;
DrawInfo* di = 0; DrawInfo* di = 0;
@@ -746,8 +782,8 @@ void BIF_icon_set_aspect(int icon_id, float aspect) {
} }
di->aspect = aspect; di->aspect = aspect;
/* scale width and height according to aspect */ /* scale width and height according to aspect */
di->w = 16.0 / di->aspect; di->w = (int)(16.0f/di->aspect + 0.5f);
di->h = 16.0 / di->aspect; di->h = (int)(16.0f/di->aspect + 0.5f);
} }

View File

@@ -344,7 +344,6 @@ void uiRoundBoxEmboss(float minx, float miny, float maxx, float maxy, float rad,
color[3]= 0.5; color[3]= 0.5;
glColor4fv(color); glColor4fv(color);
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
} }
/* solid part */ /* solid part */
@@ -357,7 +356,6 @@ void uiRoundBoxEmboss(float minx, float miny, float maxx, float maxy, float rad,
/* set antialias line */ /* set antialias line */
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
/* top shade */ /* top shade */
gl_round_box_topshade(minx+1, miny+1, maxx-1, maxy-1, rad); gl_round_box_topshade(minx+1, miny+1, maxx-1, maxy-1, rad);
@@ -387,13 +385,11 @@ void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad)
color[3]= 0.5; color[3]= 0.5;
glColor4fv(color); glColor4fv(color);
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
} }
/* set antialias line */ /* set antialias line */
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
gl_round_box(GL_LINE_LOOP, minx, miny, maxx, maxy, rad); gl_round_box(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
@@ -413,7 +409,6 @@ void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad)
color[3]= 0.5; color[3]= 0.5;
glColor4fv(color); glColor4fv(color);
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
} }
/* solid part */ /* solid part */
@@ -422,7 +417,6 @@ void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad)
/* set antialias line */ /* set antialias line */
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
gl_round_box(GL_LINE_LOOP, minx, miny, maxx, maxy, rad); gl_round_box(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
@@ -764,7 +758,6 @@ static void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3,
/* set antialias line */ /* set antialias line */
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glBegin(GL_LINE_LOOP); glBegin(GL_LINE_LOOP);
glVertex2f(x1, y1); glVertex2f(x1, y1);
@@ -778,7 +771,7 @@ static void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3,
} }
/* triangle 'icon' for panel header */ /* triangle 'icon' for panel header */
static void ui_draw_tria_icon(float x, float y, float aspect, char dir) void ui_draw_tria_icon(float x, float y, float aspect, char dir)
{ {
BIF_ThemeColor(TH_TEXT_HI); BIF_ThemeColor(TH_TEXT_HI);
@@ -790,13 +783,12 @@ static void ui_draw_tria_icon(float x, float y, float aspect, char dir)
} }
} }
static void ui_draw_anti_x(float x1, float y1, float x2, float y2) void ui_draw_anti_x(float x1, float y1, float x2, float y2)
{ {
/* set antialias line */ /* set antialias line */
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glLineWidth(2.0); glLineWidth(2.0);
@@ -1039,7 +1031,6 @@ void ui_draw_panel(uiBlock *block)
uiRoundBox(block->minx, block->maxy, block->maxx, block->maxy+PNL_HEADER, 8); uiRoundBox(block->minx, block->maxy, block->maxx, block->maxy+PNL_HEADER, 8);
// blend now for panels in 3d window, test... // blend now for panels in 3d window, test...
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable(GL_BLEND); glEnable(GL_BLEND);
BIF_ThemeColor4(TH_PANEL); BIF_ThemeColor4(TH_PANEL);
@@ -1070,7 +1061,6 @@ void ui_draw_panel(uiBlock *block)
uiSetRoundBox(3); uiSetRoundBox(3);
uiRoundBox(block->minx, block->maxy, block->maxx, block->maxy+PNL_HEADER, 8); uiRoundBox(block->minx, block->maxy, block->maxx, block->maxy+PNL_HEADER, 8);
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glEnable(GL_BLEND); glEnable(GL_BLEND);
BIF_ThemeColor4(TH_PANEL); BIF_ThemeColor4(TH_PANEL);
glRectf(block->minx, block->miny, block->maxx, block->maxy); glRectf(block->minx, block->miny, block->maxx, block->maxy);
@@ -1100,7 +1090,6 @@ void ui_draw_panel(uiBlock *block)
/* and a soft shadow-line for now */ /* and a soft shadow-line for now */
/* /*
glEnable( GL_BLEND ); glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glColor4ub(0, 0, 0, 50); glColor4ub(0, 0, 0, 50);
fdrawline(block->maxx, block->miny, block->maxx, block->maxy+PNL_HEADER/2); fdrawline(block->maxx, block->miny, block->maxx, block->maxy+PNL_HEADER/2);
fdrawline(block->minx, block->miny, block->maxx, block->miny); fdrawline(block->minx, block->miny, block->maxx, block->miny);

View File

@@ -1033,8 +1033,9 @@ static int tree_element_active_material(SpaceOops *soops, TreeElement *te, int s
} }
if(set) { if(set) {
extern_set_butspace(F5KEY); // force shading buttons extern_set_butspace(F5KEY); // force shading buttons
BIF_all_preview_changed(); BIF_preview_changed(ID_MA);
allqueue(REDRAWBUTSSHADING, 1); allqueue(REDRAWBUTSSHADING, 1);
allqueue(REDRAWNODE, 0);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);
} }
@@ -1128,7 +1129,7 @@ static int tree_element_active_lamp(SpaceOops *soops, TreeElement *te, int set)
if(set) { if(set) {
extern_set_butspace(F5KEY); extern_set_butspace(F5KEY);
BIF_all_preview_changed(); BIF_preview_changed(ID_LA);
allqueue(REDRAWBUTSSHADING, 1); allqueue(REDRAWBUTSSHADING, 1);
allqueue(REDRAWOOPS, 0); allqueue(REDRAWOOPS, 0);
allqueue(REDRAWIPO, 0); allqueue(REDRAWIPO, 0);

View File

@@ -47,7 +47,6 @@
#endif #endif
#include "MEM_guardedalloc.h" #include "MEM_guardedalloc.h"
#include "BLI_arithb.h" #include "BLI_arithb.h"
#include "BKE_utildefines.h"
#include "MTC_matrixops.h" #include "MTC_matrixops.h"
@@ -60,6 +59,7 @@
#include "DNA_camera_types.h" #include "DNA_camera_types.h"
#include "DNA_image_types.h" #include "DNA_image_types.h"
#include "DNA_material_types.h" #include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_lamp_types.h" #include "DNA_lamp_types.h"
#include "DNA_space_types.h" #include "DNA_space_types.h"
@@ -71,13 +71,16 @@
#include "BKE_icons.h" #include "BKE_icons.h"
#include "BKE_texture.h" #include "BKE_texture.h"
#include "BKE_material.h" #include "BKE_material.h"
#include "BKE_node.h"
#include "BKE_world.h" #include "BKE_world.h"
#include "BKE_texture.h" #include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "IMB_imbuf.h" #include "IMB_imbuf.h"
#include "IMB_imbuf_types.h" #include "IMB_imbuf_types.h"
#include "BSE_headerbuttons.h" #include "BSE_headerbuttons.h"
#include "BSE_node.h"
#include "BIF_gl.h" #include "BIF_gl.h"
#include "BIF_screen.h" #include "BIF_screen.h"
@@ -101,8 +104,6 @@
#define PR_XMAX 200 #define PR_XMAX 200
#define PR_YMAX 195 #define PR_YMAX 195
#define PREVIEW_RENDERSIZE 141;
#define PR_FACY (PR_YMAX-PR_YMIN-4)/(PR_RECTY) #define PR_FACY (PR_YMAX-PR_YMIN-4)/(PR_RECTY)
static rctf prerect; static rctf prerect;
@@ -111,7 +112,7 @@ static float pr_facx, pr_facy;
/* implementation */ /* implementation */
static short snijpunt(float *v1, float *v2, float *v3, float *rtlabda, float *ray1, float *ray2) static short intersect(float *v1, float *v2, float *v3, float *rtlabda, float *ray1, float *ray2)
{ {
float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22; float x0,x1,x2,t00,t01,t02,t10,t11,t12,t20,t21,t22;
float m0,m1,m2,deeldet,det1,det2,det3; float m0,m1,m2,deeldet,det1,det2,det3;
@@ -192,13 +193,13 @@ static int ray_previewrender(int x, int y, float *vec, float *vn, short pr_rec
minlabda= 1.0f; minlabda= 1.0f;
for(a=0; a<totface; a++) { for(a=0; a<totface; a++) {
if(snijpunt( rcubev[rcubi[a][0]], rcubev[rcubi[a][1]], rcubev[rcubi[a][2]], &labda, ray1, ray2)) { if(intersect( rcubev[rcubi[a][0]], rcubev[rcubi[a][1]], rcubev[rcubi[a][2]], &labda, ray1, ray2)) {
if( labda < minlabda) { if( labda < minlabda) {
minlabda= labda; minlabda= labda;
hitface= a; hitface= a;
} }
} }
if(snijpunt( rcubev[rcubi[a][0]], rcubev[rcubi[a][2]], rcubev[rcubi[a][3]], &labda, ray1, ray2)) { if(intersect( rcubev[rcubi[a][0]], rcubev[rcubi[a][2]], rcubev[rcubi[a][3]], &labda, ray1, ray2)) {
if( labda < minlabda) { if( labda < minlabda) {
minlabda= labda; minlabda= labda;
hitface= a; hitface= a;
@@ -219,14 +220,13 @@ static int ray_previewrender(int x, int y, float *vec, float *vn, short pr_rec
return 0; return 0;
} }
static unsigned int previewback(int type, int x, int y) static unsigned int previewback(int type, int x, int y)
{ {
unsigned int col; unsigned int col;
char* pcol; char* pcol;
/* checkerboard, for later /* checkerboard, for later
x+= PR_RECTX/2; x+= PR_RECTX/2;
y+= PR_RECTX/2; y+= PR_RECTX/2;
if( ((x/24) + (y/24)) & 1) return 0x40404040; if( ((x/24) + (y/24)) & 1) return 0x40404040;
else return 0xa0a0a0a0; else return 0xa0a0a0a0;
@@ -246,7 +246,22 @@ static unsigned int previewback(int type, int x, int y)
return col; return col;
} }
void BIF_set_previewrect(int win, int xmin, int ymin, int xmax, int ymax, short pr_rectx, short pr_recty) static float previewbackf(int type, int x, int y)
{
float col;
if(type & MA_DARK) {
if(abs(x)>abs(y)) col= 0.0f;
else col= 0.25f;
}
else {
if(abs(x)>abs(y)) col= 0.25f;
else col= 0.625f;
}
return col;
}
void set_previewrect(int win, int xmin, int ymin, int xmax, int ymax, short pr_rectx, short pr_recty)
{ {
float pr_sizex, pr_sizey; float pr_sizex, pr_sizey;
@@ -279,7 +294,7 @@ void BIF_set_previewrect(int win, int xmin, int ymin, int xmax, int ymax, short
} }
void BIF_end_previewrect(void) static void end_previewrect(void)
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPopMatrix(); glPopMatrix();
@@ -301,11 +316,11 @@ static void display_pr_scanline(unsigned int *rect, int recty, short pr_rectx)
if( (recty & 3)==3) { if( (recty & 3)==3) {
if(recty == 3) { if(recty == 3) {
glaDrawPixelsSafe(prerect.xmin, prerect.ymin, pr_rectx, 4, rect); glaDrawPixelsSafe(prerect.xmin, prerect.ymin, pr_rectx, 4, GL_UNSIGNED_BYTE, rect);
} }
else { else {
rect+= (recty-4)*pr_rectx; rect+= (recty-4)*pr_rectx;
glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), pr_rectx, 5, rect); glaDrawPixelsSafe(prerect.xmin, prerect.ymin + (((float)recty-4.0)*pr_facy), pr_rectx, 5, GL_UNSIGNED_BYTE, rect);
} }
} }
} }
@@ -342,47 +357,43 @@ static void draw_tex_crop(Tex *tex)
} }
void BIF_all_preview_changed(void) void BIF_preview_changed(short id_code)
{ {
ScrArea *sa; ScrArea *sa;
SpaceButs *sbuts;
sa= G.curscreen->areabase.first; for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
while(sa) {
if(sa->spacetype==SPACE_BUTS) { if(sa->spacetype==SPACE_BUTS) {
sbuts= sa->spacedata.first; SpaceButs *sbuts= sa->spacedata.first;
if (sbuts->ri) sbuts->ri->cury= 0; if(sbuts->mainb==CONTEXT_SHADING) {
addafterqueue(sa->win, RENDERPREVIEW, 1); int tab= sbuts->tab[CONTEXT_SHADING];
} if(tab==TAB_SHADING_MAT && (id_code==ID_MA || id_code==ID_TE)) {
sa= sa->next;
}
}
/* signal all previews in current screen of current type */
void BIF_preview_changed(SpaceButs *sbuts)
{
/* can be called when no buttonswindow visible */
if(sbuts) {
ScrArea *sa;
short mainb= sbuts->mainb;
short tab= sbuts->tab[mainb];
sa= G.curscreen->areabase.first;
while(sa) {
if(sa->spacetype==SPACE_BUTS) {
sbuts= sa->spacedata.first;
if(sbuts->mainb==mainb && sbuts->tab[mainb]==tab) {
if (sbuts->ri) sbuts->ri->cury= 0; if (sbuts->ri) sbuts->ri->cury= 0;
addafterqueue(sbuts->area->win, RENDERPREVIEW, 1); addafterqueue(sa->win, RENDERPREVIEW, 1);
}
else if(tab==TAB_SHADING_TEX && (id_code==ID_TE)) {
if (sbuts->ri) sbuts->ri->cury= 0;
addafterqueue(sa->win, RENDERPREVIEW, 1);
}
else if(tab==TAB_SHADING_LAMP && (id_code==ID_LA || id_code==ID_TE)) {
if (sbuts->ri) sbuts->ri->cury= 0;
addafterqueue(sa->win, RENDERPREVIEW, 1);
}
else if(tab==TAB_SHADING_WORLD && (id_code==ID_WO || id_code==ID_TE)) {
if (sbuts->ri) sbuts->ri->cury= 0;
addafterqueue(sa->win, RENDERPREVIEW, 1);
} }
} }
sa= sa->next; }
else if(sa->spacetype==SPACE_NODE) {
SpaceNode *snode= sa->spacedata.first;
if(snode->treetype==NTREE_SHADER && (id_code==ID_MA || id_code==ID_TE)) {
snode_tag_dirty(snode);
}
} }
} }
} }
void BIF_previewdraw_render(struct RenderInfo* ri, ScrArea* area) static void previewdraw_render(struct RenderInfo* ri, ScrArea* area)
{ {
int y; int y;
@@ -395,28 +406,6 @@ void BIF_previewdraw_render(struct RenderInfo* ri, ScrArea* area)
} }
} }
/* is panel callback, supposed to be called with correct panel offset matrix */
void BIF_previewdraw(void)
{
SpaceButs *sbuts= curarea->spacedata.first;
if (!sbuts->ri) {
sbuts->ri= MEM_callocN(sizeof(RenderInfo), "butsrenderinfo");
sbuts->ri->cury = 0;
sbuts->ri->rect = 0;
sbuts->ri->pr_rectx = PREVIEW_RENDERSIZE;
sbuts->ri->pr_recty = PREVIEW_RENDERSIZE;
}
if (sbuts->ri->rect==0) BIF_preview_changed(sbuts);
else {
BIF_set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, sbuts->ri->pr_rectx, sbuts->ri->pr_recty);
BIF_previewdraw_render(sbuts->ri, sbuts->area);
BIF_end_previewrect();
}
if(sbuts->ri->cury==0) BIF_preview_changed(sbuts);
}
static void sky_preview_pixel(float lens, int x, int y, char *rect, short pr_rectx, short pr_recty) static void sky_preview_pixel(float lens, int x, int y, char *rect, short pr_rectx, short pr_recty)
{ {
@@ -479,16 +468,16 @@ static void sky_preview_pixel(float lens, int x, int y, char *rect, short pr_rec
the preview, because this only works for the the preview, because this only works for the
current selected lamp. current selected lamp.
*/ */
static LampRen* create_preview_render_lamp(Lamp* la) static LampRen* create_preview_render_lamp(Lamp* la)
{ {
LampRen *lar; LampRen *lar;
int c; int c;
lar= (LampRen *)MEM_callocN(sizeof(LampRen),"lampren"); lar= (LampRen *)MEM_callocN(sizeof(LampRen),"lampren");
MTC_Mat3One(lar->mat); MTC_Mat3One(lar->mat);
MTC_Mat3One(lar->imat); MTC_Mat3One(lar->imat);
lar->type= la->type; lar->type= la->type;
lar->mode= la->mode; lar->mode= la->mode;
lar->energy= la->energy; lar->energy= la->energy;
@@ -500,25 +489,25 @@ static void sky_preview_pixel(float lens, int x, int y, char *rect, short pr_rec
lar->dist= la->dist; lar->dist= la->dist;
lar->ld1= la->att1; lar->ld1= la->att1;
lar->ld2= la->att2; lar->ld2= la->att2;
/* exceptions: */ /* exceptions: */
lar->spottexfac= 1.0; lar->spottexfac= 1.0;
lar->spotsi= cos( M_PI/3.0 ); lar->spotsi= cos( M_PI/3.0 );
lar->spotbl= (1.0-lar->spotsi)*la->spotblend; lar->spotbl= (1.0-lar->spotsi)*la->spotblend;
MTC_Mat3One(lar->imat); MTC_Mat3One(lar->imat);
if(lar->type==LA_SPOT) { if(lar->type==LA_SPOT) {
if(lar->mode & LA_ONLYSHADOW) { if(lar->mode & LA_ONLYSHADOW) {
if((lar->mode & (LA_SHAD|LA_SHAD_RAY))==0) lar->mode -= LA_ONLYSHADOW; if((lar->mode & (LA_SHAD|LA_SHAD_RAY))==0) lar->mode -= LA_ONLYSHADOW;
} }
} }
memcpy(lar->mtex, la->mtex, MAX_MTEX*sizeof(void *)); memcpy(lar->mtex, la->mtex, MAX_MTEX*sizeof(void *));
for(c=0; c<MAX_MTEX; c++) { for(c=0; c<MAX_MTEX; c++) {
if(la->mtex[c] && la->mtex[c]->tex) { if(la->mtex[c] && la->mtex[c]->tex) {
lar->mode |= LA_TEXTURE; lar->mode |= LA_TEXTURE;
if(R.flag & R_RENDERING) { if(R.flag & R_RENDERING) {
if(R.osa) { if(R.osa) {
if(la->mtex[c]->tex->type==TEX_IMAGE) lar->mode |= LA_OSATEX; if(la->mtex[c]->tex->type==TEX_IMAGE) lar->mode |= LA_OSATEX;
@@ -526,7 +515,7 @@ static void sky_preview_pixel(float lens, int x, int y, char *rect, short pr_rec
} }
} }
} }
return lar; return lar;
} }
@@ -670,13 +659,13 @@ static void halo_preview_pixel(HaloRen *har, int startx, int endx, int y, char *
if(dist<har->radsq) { if(dist<har->radsq) {
RE_shadehalo(har, front, colf, 0, dist, xn, yn, har->flarec); RE_shadehalo(har, front, colf, 0, dist, xn, yn, har->flarec);
RE_addalphaAddfac(rect, front, har->add); RE_addalphaAddfac(rect, front, har->add);
rect[3] = 0xFF; rect[3] = 0xFF; /* makes icon display all pixels */
} }
rect+= 4; rect+= 4;
} }
} }
static void previewflare(RenderInfo *ri, HaloRen *har, short pr_rectx, short pr_recty, int doDraw) static void previewflare(RenderInfo *ri, HaloRen *har, short pr_rectx, short pr_recty, int pr_method)
{ {
float ycor; float ycor;
unsigned int *rectot; unsigned int *rectot;
@@ -707,8 +696,8 @@ static void previewflare(RenderInfo *ri, HaloRen *har, short pr_rectx, short pr_
// not sure why, either waitcursor or renderflare screws up (disabled then) // not sure why, either waitcursor or renderflare screws up (disabled then)
//areawinset(curarea->win); //areawinset(curarea->win);
/* draw can just be this way, all settings are OK */ /* draw can just be called this way, all settings are OK */
if (doDraw) { if (pr_method==PR_DRAW_RENDER) {
for (y=0; y<pr_recty; y++) { for (y=0; y<pr_recty; y++) {
display_pr_scanline(ri->rect, y, pr_rectx); display_pr_scanline(ri->rect, y, pr_rectx);
} }
@@ -851,7 +840,7 @@ static void refraction_prv(int *x, int *y, float *n, float index)
*y= (int)(len*(index*view[1] + fac*n[1])); *y= (int)(len*(index*view[1] + fac*n[1]));
} }
static void shade_lamp_loop_preview(ShadeInput *shi, ShadeResult *shr, int pr_lamp) static void shade_lamp_loop_preview(ShadeInput *shi, ShadeResult *shr)
{ {
extern float fresnel_fac(float *view, float *vn, float ior, float fac); extern float fresnel_fac(float *view, float *vn, float ior, float fac);
Material *mat= shi->mat; Material *mat= shi->mat;
@@ -889,9 +878,19 @@ static void shade_lamp_loop_preview(ShadeInput *shi, ShadeResult *shr, int pr_la
} }
else { else {
if(mat->texco & TEXCO_REFL) {
inp= -2.0*(shi->vn[0]*shi->view[0]+shi->vn[1]*shi->view[1]+shi->vn[2]*shi->view[2]);
shi->ref[0]= (shi->view[0]+inp*shi->vn[0]);
shi->ref[1]= (shi->view[1]+inp*shi->vn[1]);
shi->ref[2]= (shi->view[2]+inp*shi->vn[2]);
/* normals in render are pointing different... rhm */
if(shi->pr_type==MA_SPHERE)
shi->ref[1]= -shi->ref[1];
}
for(a=0; a<2; a++) { for(a=0; a<2; a++) {
if((pr_lamp & (1<<a))==0) continue; if((mat->pr_lamp & (1<<a))==0) continue;
if(a==0) la= pr1_lamp; if(a==0) la= pr1_lamp;
else la= pr2_lamp; else la= pr2_lamp;
@@ -1000,6 +999,8 @@ static void shade_lamp_loop_preview(ShadeInput *shi, ShadeResult *shr, int pr_la
shi->refcol[3]= shi->refcol[0]*0.8f*div; shi->refcol[3]= shi->refcol[0]*0.8f*div;
} }
} }
else
shi->refcol[0]= 0.0f;
shr->diff[0]+= shi->ambr; shr->diff[0]+= shi->ambr;
shr->diff[1]+= shi->ambg; shr->diff[1]+= shi->ambg;
@@ -1025,14 +1026,13 @@ static void shade_lamp_loop_preview(ShadeInput *shi, ShadeResult *shr, int pr_la
} }
} }
static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char *rect, int smooth, short pr_rectx, short pr_recty) static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char *rect, short pr_rectx, short pr_recty)
{ {
Material *mat; Material *mat;
MaterialLayer *ml; MaterialLayer *ml;
ShadeResult shr; ShadeResult shr;
float v1, inp; float v1;
float eul[3], tmat[3][3], imat[3][3], col[3]; float eul[3], tmat[3][3], imat[3][3], col[4];
char tracol;
mat= shi->mat; mat= shi->mat;
@@ -1042,8 +1042,8 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char
shi->view[2]= 1.0f; shi->view[2]= 1.0f;
Normalise(shi->view); Normalise(shi->view);
shi->xs= (float)x; shi->xs= x + pr_rectx/2;
shi->ys= (float)y; shi->ys= y + pr_recty/2;
shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0f; shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0f;
VECCOPY(shi->co, vec); VECCOPY(shi->co, vec);
@@ -1092,22 +1092,10 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char
shi->orn[1]= shi->vn[1]; shi->orn[1]= shi->vn[1];
shi->orn[2]= shi->vn[2]; shi->orn[2]= shi->vn[2];
} }
if(mat->texco & TEXCO_REFL) {
inp= -2.0*(shi->vn[0]*shi->view[0]+shi->vn[1]*shi->view[1]+shi->vn[2]*shi->view[2]);
shi->ref[0]= (shi->view[0]+inp*shi->vn[0]);
shi->ref[1]= (shi->view[1]+inp*shi->vn[1]);
shi->ref[2]= (shi->view[2]+inp*shi->vn[2]);
}
/* Clear displase vec for preview */ /* Clear displase vec for preview */
shi->displace[0]= shi->displace[1]= shi->displace[2]= 0.0; shi->displace[0]= shi->displace[1]= shi->displace[2]= 0.0;
if(mat->texco & TEXCO_REFL) {
/* normals in render are pointing different... rhm */
if(smooth) shi->ref[1]= -shi->ref[1];
}
if(mat->pr_type==MA_CUBE) { if(mat->pr_type==MA_CUBE) {
/* rotate normal back for normals texture */ /* rotate normal back for normals texture */
SWAP(float, shi->vn[0], shi->vn[1]); SWAP(float, shi->vn[0], shi->vn[1]);
@@ -1127,24 +1115,29 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char
/* ------ main shading loop with material layers */ /* ------ main shading loop with material layers */
VECCOPY(shi->vno, shi->vn); VECCOPY(shi->vno, shi->vn);
if(mat->ml_flag & ML_RENDER) if(mat->ml_flag & ML_RENDER)
shade_lamp_loop_preview(shi, &shr, mat->pr_lamp); shade_lamp_loop_preview(shi, &shr);
else { else {
memset(&shr, 0, sizeof(ShadeResult)); memset(&shr, 0, sizeof(ShadeResult));
shr.alpha= 1.0f; shr.alpha= 1.0f;
} }
for(ml= mat->layers.first; ml; ml= ml->next) { if(mat->nodetree && mat->use_nodes) {
if(ml->mat && (ml->flag & ML_RENDER)) { ntreeShaderExecTree(mat->nodetree, shi, &shr);
ShadeResult shrlay; }
else {
shi->mat= ml->mat; for(ml= mat->layers.first; ml; ml= ml->next) {
shi->layerfac= ml->blendfac; if(ml->mat && (ml->flag & ML_RENDER)) {
VECCOPY(shi->vn, shi->vno); ShadeResult shrlay;
if(ml->flag & ML_NEG_NORMAL)
VecMulf(shi->vn, -1.0); shi->mat= ml->mat;
shi->layerfac= ml->blendfac;
VECCOPY(shi->vn, shi->vno);
if(ml->flag & ML_NEG_NORMAL)
VecMulf(shi->vn, -1.0);
shade_lamp_loop_preview(shi, &shrlay, mat->pr_lamp); shade_lamp_loop_preview(shi, &shrlay);
matlayer_blend(ml, shi->layerfac, &shr, &shrlay); matlayer_blend(ml, shi->layerfac, &shr, &shrlay);
}
} }
} }
@@ -1160,34 +1153,40 @@ static void shade_preview_pixel(ShadeInput *shi, float *vec, int x, int y, char
if(shr.diff[2]<0.0f) shr.diff[2]= 0.0f; if(shr.diff[2]<0.0f) shr.diff[2]= 0.0f;
VECADD(col, shr.diff, shr.spec); VECADD(col, shr.diff, shr.spec);
if(col[0]<=0.0f) rect[0]= 0; else if(col[0]>=1.0f) rect[0]= 255; else rect[0]= (char)(255.0*col[0]); col[3]= shr.alpha;
if(col[1]<=0.0f) rect[1]= 0; else if(col[1]>=1.0f) rect[1]= 255; else rect[1]= (char)(255.0*col[1]);
if(col[2]<=0.0f) rect[2]= 0; else if(col[2]>=1.0f) rect[2]= 255; else rect[2]= (char)(255.0*col[2]);
if(shr.alpha!=1.0f) { /* handle backdrop now */
if(col[3]!=1.0f) {
float back, backm;
/* distorts x and y */
if(mat->mode & MA_RAYTRANSP) { if(mat->mode & MA_RAYTRANSP) {
refraction_prv(&x, &y, shi->vn, shi->ang); refraction_prv(&x, &y, shi->vn, shi->ang);
} }
tracol= previewback(mat->pr_back, x, y) & 255; back= previewbackf(mat->pr_back, x, y);
backm= (1.0f-shr.alpha)*back;
tracol= (1.0f-shr.alpha)*tracol;
if((mat->mode & MA_RAYTRANSP) && mat->filter!=0.0) { if((mat->mode & MA_RAYTRANSP) && mat->filter!=0.0) {
float fr= 1.0f+ mat->filter*(shr.diff[0]-1.0f); float fr= 1.0f+ mat->filter*(shr.diff[0]-1.0f);
rect[0]= fr*tracol+ (rect[0]*shr.alpha) ; col[0]= fr*backm+ (col[3]*col[0]);
fr= 1.0f+ mat->filter*(shr.diff[0]-1.0f); fr= 1.0f+ mat->filter*(shr.diff[1]-1.0f);
rect[1]= fr*tracol+ (rect[1]*shr.alpha) ; col[1]= fr*backm+ (col[3]*col[1]);
fr= 1.0f+ mat->filter*(shr.diff[0]-1.0f); fr= 1.0f+ mat->filter*(shr.diff[2]-1.0f);
rect[2]= fr*tracol+ (rect[2]*shr.alpha) ; col[2]= fr*backm+ (col[3]*col[2]);
} }
else { else {
rect[0]= tracol+ (rect[0]*shr.alpha) ; col[0]= backm + (col[3]*col[0]);
rect[1]= tracol+ (rect[1]*shr.alpha) ; col[1]= backm + (col[3]*col[1]);
rect[2]= tracol+ (rect[2]*shr.alpha) ; col[2]= backm + (col[3]*col[2]);
} }
} }
rect[3] = 0xFF;
if(col[0]<=0.0f) rect[0]= 0; else if(col[0]>=1.0f) rect[0]= 255; else rect[0]= (char)(255.0f*col[0]);
if(col[1]<=0.0f) rect[1]= 0; else if(col[1]>=1.0f) rect[1]= 255; else rect[1]= (char)(255.0f*col[1]);
if(col[2]<=0.0f) rect[2]= 0; else if(col[2]>=1.0f) rect[2]= 255; else rect[2]= (char)(255.0f*col[2]);
if(col[3]<=0.0f) rect[3]= 0; else if(col[3]>=1.0f) rect[3]= 255; else rect[3]= (char)(255.0f*col[3]);
} }
static void preview_init_render_textures(MTex **mtex) static void preview_init_render_textures(MTex **mtex)
@@ -1210,65 +1209,8 @@ static void preview_init_render_textures(MTex **mtex)
} }
void BIF_previewrender_buts(SpaceButs *sbuts) /* main previewrender loop */
{ void BIF_previewrender(struct ID *id, struct RenderInfo *ri, struct ScrArea *area, int pr_method)
uiBlock *block;
struct ID* id = 0;
struct ID* idfrom = 0;
struct ID* idshow = 0;
Object *ob;
if (!sbuts->ri) return;
/* we safely assume curarea has panel "preview" */
/* quick hack for now, later on preview should become uiBlock itself */
block= uiFindOpenPanelBlockName(&curarea->uiblocks, "Preview");
if(block==NULL) return;
ob= ((G.scene->basact)? (G.scene->basact)->object: 0);
/* we cant trust this global lockpoin.. for example with headerless window */
buttons_active_id(&id, &idfrom);
G.buts->lockpoin= id;
if(sbuts->mainb==CONTEXT_SHADING) {
int tab= sbuts->tab[CONTEXT_SHADING];
if(tab==TAB_SHADING_MAT)
idshow = sbuts->lockpoin;
else if(tab==TAB_SHADING_TEX)
idshow = sbuts->lockpoin;
else if(tab==TAB_SHADING_LAMP) {
if(ob && ob->type==OB_LAMP) idshow= ob->data;
}
else if(tab==TAB_SHADING_WORLD)
idshow = sbuts->lockpoin;
}
else if(sbuts->mainb==CONTEXT_OBJECT) {
if(ob && ob->type==OB_LAMP) idshow = ob->data;
}
if (idshow) {
BKE_icon_changed(BKE_icon_getid(idshow));
uiPanelPush(block);
BIF_set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, sbuts->ri->pr_rectx, sbuts->ri->pr_recty); // uses UImat
BIF_previewrender(idshow, sbuts->ri, sbuts->area, 1);
uiPanelPop(block);
BIF_end_previewrect();
}
else {
/* no active block to draw. But we do draw black if possible */
if(sbuts->ri->rect) {
memset(sbuts->ri->rect, 0, sizeof(int)*sbuts->ri->pr_rectx*sbuts->ri->pr_recty);
sbuts->ri->cury= sbuts->ri->pr_recty;
addqueue(curarea->win, REDRAW, 1);
}
return;
}
}
void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *area, int doDraw)
{ {
static double lasttime= 0; static double lasttime= 0;
Material *mat= NULL; Material *mat= NULL;
@@ -1303,9 +1245,9 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
} }
har.flarec= 0; /* below is a test for postrender flare */ har.flarec= 0; /* below is a test for postrender flare */
if(doDraw && qtest()) { /* no event escape for icon render */
if(pr_method!=PR_ICON_RENDER && qtest()) {
addafterqueue(curarea->win, RENDERPREVIEW, 1); addafterqueue(curarea->win, RENDERPREVIEW, 1);
return; return;
} }
@@ -1331,11 +1273,33 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
mat->texco |= ml->mat->texco; mat->texco |= ml->mat->texco;
} }
} }
if(mat->nodetree && mat->use_nodes) {
bNode *node;
for(node=mat->nodetree->nodes.first; node; node= node->next) {
if(node->id && GS(node->id->name)==ID_MA) {
Material *ma= (Material *)node->id;
init_render_material(ma);
preview_init_render_textures(ma->mtex);
mat->texco |= ma->texco;
}
}
/* signal to node editor to store previews or not */
if(pr_method==PR_ICON_RENDER) {
ntreeBeginExecTree(mat->nodetree, 0, 0);
shi.do_preview= 0;
}
else {
ntreeBeginExecTree(mat->nodetree, ri->pr_rectx, ri->pr_recty);
shi.do_preview= 1;
}
}
shi.vlr= NULL; shi.vlr= NULL;
shi.mat= mat; shi.mat= mat;
shi.pr_type= mat->pr_type;
if(mat->mode & MA_HALO) init_previewhalo(&har, mat, ri->pr_rectx, ri->pr_recty); if(mat->mode & MA_HALO) init_previewhalo(&har, mat, ri->pr_rectx, ri->pr_recty);
set_node_shader_lamp_loop(shade_lamp_loop_preview);
} }
else if(tex) { else if(tex) {
@@ -1384,39 +1348,18 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
preview_init_render_textures(wrld->mtex); preview_init_render_textures(wrld->mtex);
} }
if (doDraw) {
/* BIF_set_previewrect(area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, ri->pr_rectx, ri->pr_recty); // uses UImat */
}
if(ri->rect==NULL) { if(ri->rect==NULL) {
ri->rect= MEM_callocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "butsrect"); ri->rect= MEM_callocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "butsrect");
/* built in emboss */
if (doDraw) {
rect= ri->rect;
for(y=0; y<ri->pr_recty; y++, rect++) *rect= 0xFFFFFFFF;
rect= ri->rect + ri->pr_rectx-1;
for(y=0; y<ri->pr_recty; y++, rect+=ri->pr_rectx) *rect= 0xFFFFFFFF;
}
} }
starty= -ri->pr_recty/2; starty= -ri->pr_recty/2;
endy= starty+ri->pr_recty; endy= starty+ri->pr_recty;
starty+= ri->cury; starty+= ri->cury;
if (doDraw) { startx= -ri->pr_rectx/2;
/* offset +1 for emboss */ endx= startx+ri->pr_rectx;
startx= -ri->pr_rectx/2 +1;
endx= startx+ri->pr_rectx -2;
}
else {
/* offset +1 for emboss */
startx= -ri->pr_rectx/2;
endx= startx+ri->pr_rectx-1;
}
radsq= (ri->pr_rectx/2-1)*(ri->pr_recty/2-1); /* -1 to make sure sphere fits into preview rect completely */ radsq= (ri->pr_rectx/2)*(ri->pr_recty/2);
if(mat) { if(mat) {
if(mat->pr_type==MA_SPHERE) { if(mat->pr_type==MA_SPHERE) {
@@ -1429,24 +1372,23 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
} }
} }
/* here it starts! */ if (pr_method==PR_DRAW_RENDER)
if (doDraw) glDrawBuffer(GL_FRONT); glDrawBuffer(GL_FRONT);
/* here it starts! */
for(y=starty; y<endy; y++) { for(y=starty; y<endy; y++) {
rect= ri->rect + 1 + ri->pr_rectx*ri->cury; rect= ri->rect + ri->pr_rectx*ri->cury;
if(y== -ri->pr_recty/2 || y==endy-1); /* emboss */ if(mat) {
else if(mat) {
if(mat->mode & MA_HALO) { if(mat->mode & MA_HALO) {
for(x=startx; x<endx; x++, rect++) { for(x=startx; x<endx; x++, rect++) {
rect[0]= previewback(mat->pr_back, x, y); rect[0]= previewback(mat->pr_back, x, y);
rect[0] |= 0xFF000000;
} }
if(har.flarec) { if(har.flarec) {
if(y==endy-2) previewflare(ri, &har, ri->pr_rectx, ri->pr_recty, doDraw); if(y==endy-2) previewflare(ri, &har, ri->pr_rectx, ri->pr_recty, pr_method);
} }
else { else {
halo_preview_pixel(&har, startx, endx, y, (char *) (rect-ri->pr_rectx), ri->pr_rectx); halo_preview_pixel(&har, startx, endx, y, (char *) (rect-ri->pr_rectx), ri->pr_rectx);
@@ -1476,19 +1418,25 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
Normalise(shi.tang); Normalise(shi.tang);
} }
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 1, ri->pr_rectx, ri->pr_recty); shade_preview_pixel(&shi, vec, x, y, (char *)rect, ri->pr_rectx, ri->pr_recty);
} }
else { else {
rect[0]= previewback(mat->pr_back, x, y); rect[0]= previewback(mat->pr_back, x, y);
if(pr_method!=PR_ICON_RENDER && mat->nodetree && mat->use_nodes)
ntreeClearPixelTree(mat->nodetree, x+ri->pr_rectx/2, y+ri->pr_recty/2);
} }
} }
else if(mat->pr_type==MA_CUBE) { else if(mat->pr_type==MA_CUBE) {
if( ray_previewrender(x, y, vec, shi.vn, ri->pr_rectx, ri->pr_recty) ) { if( ray_previewrender(x, y, vec, shi.vn, ri->pr_rectx, ri->pr_recty) ) {
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0, ri->pr_rectx, ri->pr_recty); shade_preview_pixel(&shi, vec, x, y, (char *)rect, ri->pr_rectx, ri->pr_recty);
} }
else { else {
rect[0]= previewback(mat->pr_back, x, y); rect[0]= previewback(mat->pr_back, x, y);
if(pr_method!=PR_ICON_RENDER && mat->nodetree && mat->use_nodes)
ntreeClearPixelTree(mat->nodetree, x+ri->pr_rectx/2, y+ri->pr_recty/2);
} }
} }
else { else {
@@ -1499,7 +1447,7 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
shi.vn[0]= shi.vn[1]= 0.0f; shi.vn[0]= shi.vn[1]= 0.0f;
shi.vn[2]= 1.0f; shi.vn[2]= 1.0f;
shade_preview_pixel(&shi, vec, x, y, (char *)rect, 0, ri->pr_rectx, ri->pr_recty); shade_preview_pixel(&shi, vec, x, y, (char *)rect, ri->pr_rectx, ri->pr_recty);
} }
} }
} }
@@ -1520,7 +1468,7 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
} }
} }
if (doDraw) { if (pr_method!=PR_ICON_RENDER) {
if(y<endy-2) { if(y<endy-2) {
if(qtest()) { if(qtest()) {
addafterqueue(curarea->win, RENDERPREVIEW, 1); addafterqueue(curarea->win, RENDERPREVIEW, 1);
@@ -1538,15 +1486,13 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
ri->cury++; ri->cury++;
} }
if (doDraw) { if (pr_method==PR_DRAW_RENDER) {
/* BIF_end_previewrect(); */
if(ri->cury>=ri->pr_recty && tex) if(ri->cury>=ri->pr_recty && tex)
draw_tex_crop((Tex*)id); draw_tex_crop((Tex*)id);
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
/* draw again for clean swapbufers */ /* draw again for clean swapbufers */
BIF_previewdraw_render(ri, area); previewdraw_render(ri, area);
} }
if(lar) { if(lar) {
@@ -1556,59 +1502,99 @@ void BIF_previewrender(struct ID* id, struct RenderInfo *ri, struct ScrArea *are
R.lights.first= R.lights.last= NULL; R.lights.first= R.lights.last= NULL;
*/ */
} }
if(mat && mat->nodetree && mat->use_nodes) {
ntreeEndExecTree(mat->nodetree);
if(ri->cury>=ri->pr_recty)
allqueue(REDRAWNODE, 0);
}
} }
/* create single icon from jpg, png etc. */ void BIF_previewrender_buts(SpaceButs *sbuts)
void BIF_calcpreview_image(Image* img, RenderInfo* ri, unsigned int w, unsigned int h)
{ {
struct ImBuf *ima; uiBlock *block;
struct ImBuf *imb; struct ID* id = 0;
short ex, ey, dx, dy; struct ID* idfrom = 0;
float scaledx, scaledy; struct ID* idshow = 0;
int pr_size = w*h*sizeof(unsigned int); Object *ob;
if (!img)
return;
if (!ri->rect) {
ri->rect= MEM_callocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "butsrect");
memset(ri->rect, 0xFF, w*h*sizeof(unsigned int));
}
if(img->ibuf==0) {
load_image(img, IB_rect, G.sce, G.scene->r.cfra);
}
ima = IMB_dupImBuf(img->ibuf);
if (!ima)
return;
if (ima->x > ima->y) {
scaledx = (float)w;
scaledy = ( (float)ima->y/(float)ima->x )*(float)w;
}
else {
scaledx = ( (float)ima->x/(float)ima->y )*(float)h;
scaledy = (float)h;
}
ex = (short)scaledx;
ey = (short)scaledy;
dx = (w - ex) / 2; if (!sbuts->ri) return;
dy = (h - ey) / 2;
IMB_scaleImBuf(ima, ex, ey); /* we safely assume curarea has panel "preview" */
/* quick hack for now, later on preview should become uiBlock itself */
imb = IMB_allocImBuf(w, h, 32, IB_rect, 0);
block= uiFindOpenPanelBlockName(&curarea->uiblocks, "Preview");
IMB_rectop(imb, 0, 0, 0, 0, 0, w, h, IMB_rectfill, 0x00000000); if(block==NULL) return;
IMB_rectop(imb, ima, dx, dy, 0, 0, ex, ey, IMB_rectcpy, 0); ob= ((G.scene->basact)? (G.scene->basact)->object: 0);
IMB_freeImBuf(ima); /* we cant trust this global lockpoin.. for example with headerless window */
buttons_active_id(&id, &idfrom);
memcpy(ri->rect, imb->rect,pr_size); G.buts->lockpoin= id;
IMB_freeImBuf(imb); if(sbuts->mainb==CONTEXT_SHADING) {
int tab= sbuts->tab[CONTEXT_SHADING];
if(tab==TAB_SHADING_MAT)
idshow = sbuts->lockpoin;
else if(tab==TAB_SHADING_TEX)
idshow = sbuts->lockpoin;
else if(tab==TAB_SHADING_LAMP) {
if(ob && ob->type==OB_LAMP) idshow= ob->data;
}
else if(tab==TAB_SHADING_WORLD)
idshow = sbuts->lockpoin;
}
else if(sbuts->mainb==CONTEXT_OBJECT) {
if(ob && ob->type==OB_LAMP) idshow = ob->data;
}
if (idshow) {
BKE_icon_changed(BKE_icon_getid(idshow));
uiPanelPush(block);
set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, sbuts->ri->pr_rectx, sbuts->ri->pr_recty); // uses UImat
BIF_previewrender(idshow, sbuts->ri, sbuts->area, PR_DRAW_RENDER);
uiPanelPop(block);
end_previewrect();
}
else {
/* no active block to draw. But we do draw black if possible */
if(sbuts->ri->rect) {
memset(sbuts->ri->rect, 0, sizeof(int)*sbuts->ri->pr_rectx*sbuts->ri->pr_recty);
sbuts->ri->cury= sbuts->ri->pr_recty;
addqueue(curarea->win, REDRAW, 1);
}
return;
}
} }
/* is panel callback, supposed to be called with correct panel offset matrix */
void BIF_previewdraw(void)
{
SpaceButs *sbuts= curarea->spacedata.first;
short id_code= 0;
if(sbuts->lockpoin) {
ID *id= sbuts->lockpoin;
id_code= GS(id->name);
}
if (!sbuts->ri) {
sbuts->ri= MEM_callocN(sizeof(RenderInfo), "butsrenderinfo");
sbuts->ri->cury = 0;
sbuts->ri->rect = NULL;
sbuts->ri->pr_rectx = PREVIEW_RENDERSIZE;
sbuts->ri->pr_recty = PREVIEW_RENDERSIZE;
}
if (sbuts->ri->rect==NULL) BIF_preview_changed(id_code);
else {
set_previewrect(sbuts->area->win, PR_XMIN, PR_YMIN, PR_XMAX, PR_YMAX, sbuts->ri->pr_rectx, sbuts->ri->pr_recty);
previewdraw_render(sbuts->ri, sbuts->area);
end_previewrect();
}
if(sbuts->ri->cury==0) BIF_preview_changed(id_code);
}

View File

@@ -329,16 +329,16 @@ static void renderwin_draw(RenderWin *rw, int just_clear)
char *rect= (char *)R.rectot; char *rect= (char *)R.rectot;
glColorMask(1, 0, 0, 0); glColorMask(1, 0, 0, 0);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, rect+3); glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, rect+3);
glColorMask(0, 1, 0, 0); glColorMask(0, 1, 0, 0);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, rect+2); glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, rect+2);
glColorMask(0, 0, 1, 0); glColorMask(0, 0, 1, 0);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, rect+1); glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, rect+1);
glColorMask(1, 1, 1, 1); glColorMask(1, 1, 1, 1);
} }
else { else {
glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, R.rectot); glaDrawPixelsSafe(disprect[0][0], disprect[0][1], R.rectx, R.recty, GL_UNSIGNED_BYTE, R.rectot);
} }
glPixelZoom(1.0, 1.0); glPixelZoom(1.0, 1.0);
} }
@@ -743,7 +743,7 @@ static void renderwin_progress(RenderWin *rw, int start_y, int nlines, int rect_
glDrawBuffer(GL_FRONT); glDrawBuffer(GL_FRONT);
glPixelZoom(rw->zoom, rw->zoom); glPixelZoom(rw->zoom, rw->zoom);
glaDrawPixelsSafe(disprect[0][0], disprect[0][1] + start_y*rw->zoom, rect_w, nlines, &rect[start_y*rect_w*4]); glaDrawPixelsSafe(disprect[0][0], disprect[0][1] + start_y*rw->zoom, rect_w, nlines, GL_UNSIGNED_BYTE, &rect[start_y*rect_w*4]);
glPixelZoom(1.0, 1.0); glPixelZoom(1.0, 1.0);
glFlush(); glFlush();
glDrawBuffer(GL_BACK); glDrawBuffer(GL_BACK);
@@ -830,7 +830,7 @@ static void renderview_progress_display_cb(int y1, int y2, int w, int h, unsigne
sy= vb.ymin + facy*y1; sy= vb.ymin + facy*y1;
glPixelZoom(facx, facy); glPixelZoom(facx, facy);
glaDrawPixelsSafe(sx, sy, w, nlines, rect+w*y1); glaDrawPixelsSafe(sx, sy, w, nlines, GL_UNSIGNED_BYTE, rect+w*y1);
glPixelZoom(1.0, 1.0); glPixelZoom(1.0, 1.0);
glFlush(); glFlush();
@@ -1090,7 +1090,7 @@ static void do_render(View3D *ogl_render_view3d, int anim, int force_dispwin)
/* after an envmap creation... */ /* after an envmap creation... */
if(R.flag & R_REDRAW_PRV) { if(R.flag & R_REDRAW_PRV) {
BIF_all_preview_changed(); BIF_preview_changed(ID_TE);
} }
allqueue(REDRAWBUTSSCENE, 0); // visualize fbuf for example allqueue(REDRAWBUTSSCENE, 0); // visualize fbuf for example
} }

View File

@@ -185,6 +185,9 @@ char *BIF_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case SPACE_TIME: case SPACE_TIME:
ts= &btheme->ttime; ts= &btheme->ttime;
break; break;
case SPACE_NODE:
ts= &btheme->tnode;
break;
default: default:
ts= &btheme->tv3d; ts= &btheme->tv3d;
break; break;
@@ -272,6 +275,17 @@ char *BIF_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colorid)
case TH_SYNTAX_N: case TH_SYNTAX_N:
cp= ts->syntaxn; break; cp= ts->syntaxn; break;
case TH_NODE:
cp= ts->syntaxl; break;
case TH_NODE_IN_OUT:
cp= ts->syntaxn; break;
case TH_NODE_OPERATOR:
cp= ts->syntaxb; break;
case TH_NODE_GENERATOR:
cp= ts->syntaxv; break;
case TH_NODE_FREE:
cp= ts->syntaxc; break;
} }
} }
@@ -463,6 +477,15 @@ void BIF_InitTheme(void)
/* space time */ /* space time */
btheme->ttime= btheme->tsnd; // same as sound space btheme->ttime= btheme->tsnd; // same as sound space
/* space node, re-uses syntax color storage */
btheme->tnode= btheme->tv3d;
SETCOL(btheme->tnode.syntaxl, 120, 120, 120, 255); /* TH_NODE */
SETCOL(btheme->tnode.syntaxn, 110, 110, 120, 255); /* in-out */
SETCOL(btheme->tnode.syntaxb, 140, 140, 140, 255); /* operator */
SETCOL(btheme->tnode.syntaxv, 120, 120, 120, 255); /* generator */
SETCOL(btheme->tnode.syntaxc, 120, 120, 120, 255); /* free */
} }
char *BIF_ThemeColorsPup(int spacetype) char *BIF_ThemeColorsPup(int spacetype)
@@ -590,6 +613,14 @@ char *BIF_ThemeColorsPup(int spacetype)
else if(spacetype==SPACE_TIME) { else if(spacetype==SPACE_TIME) {
sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str); sprintf(str, "Grid %%x%d|", TH_GRID); strcat(cp, str);
} }
else if(spacetype==SPACE_NODE) {
strcat(cp,"%l|");
sprintf(str, "Default Node %%x%d|", TH_NODE); strcat(cp, str);
sprintf(str, "In/Out Node %%x%d|", TH_NODE_IN_OUT); strcat(cp, str);
sprintf(str, "Operator Node %%x%d|", TH_NODE_OPERATOR); strcat(cp, str);
sprintf(str, "Generator Node %%x%d|", TH_NODE_GENERATOR); strcat(cp, str);
// sprintf(str, " %%x%d|", TH_NODE_FREE); strcat(cp, str);
}
} }
return cp; return cp;
} }

View File

@@ -3362,11 +3362,12 @@ void extern_set_butspace(int fkey)
sbuts->mainb= CONTEXT_SHADING; sbuts->mainb= CONTEXT_SHADING;
sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT; sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_MAT;
} }
BIF_preview_changed(ID_TE);
} }
else if(fkey==F6KEY) { else if(fkey==F6KEY) {
sbuts->mainb= CONTEXT_SHADING; sbuts->mainb= CONTEXT_SHADING;
sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX; sbuts->tab[CONTEXT_SHADING]= TAB_SHADING_TEX;
BIF_preview_changed(ID_TE);
} }
else if(fkey==F7KEY) { else if(fkey==F7KEY) {
/* if it's already in object context, cycle between tabs with the same key */ /* if it's already in object context, cycle between tabs with the same key */
@@ -3403,7 +3404,6 @@ void extern_set_butspace(int fkey)
scrarea_queue_headredraw(sa); scrarea_queue_headredraw(sa);
scrarea_queue_winredraw(sa); scrarea_queue_winredraw(sa);
BIF_preview_changed(sbuts);
} }
/* ******************** SPACE: SEQUENCE ********************** */ /* ******************** SPACE: SEQUENCE ********************** */
@@ -4639,9 +4639,7 @@ void freespacelist(ListBase *lb)
free_soundspace((SpaceSound *)sl); free_soundspace((SpaceSound *)sl);
} }
else if(sl->spacetype==SPACE_NODE) { else if(sl->spacetype==SPACE_NODE) {
SpaceNode *snode= (SpaceNode *)sl; /* SpaceNode *snode= (SpaceNode *)sl; */
if(snode->nodetree)
nodeFreeTree(snode->nodetree);
} }
} }

View File

@@ -96,10 +96,11 @@
#include "BIF_cursors.h" #include "BIF_cursors.h"
#include "BSE_drawview.h" #include "BSE_drawview.h"
#include "BSE_headerbuttons.h" #include "BSE_edit.h"
#include "BSE_editipo.h" #include "BSE_editipo.h"
#include "BSE_filesel.h" #include "BSE_filesel.h"
#include "BSE_edit.h" #include "BSE_headerbuttons.h"
#include "BSE_node.h"
#include "BLO_readfile.h" #include "BLO_readfile.h"
#include "BLO_writefile.h" #include "BLO_writefile.h"
@@ -265,10 +266,23 @@ static void init_userdef_file(void)
255); 255);
} }
} }
if(U.obcenter_dia==0) U.obcenter_dia= 6; if(U.obcenter_dia==0) U.obcenter_dia= 6;
} }
if (G.main->versionfile <= 240) {
bTheme *btheme;
for(btheme= U.themes.first; btheme; btheme= btheme->next) {
/* Node editor theme, check for alpha==0 is safe, then color was never set */
if(btheme->tnode.syntaxn[3]==0) {
/* re-uses syntax color storage */
btheme->tnode= btheme->tv3d;
SETCOL(btheme->tnode.syntaxl, 120, 120, 120, 255); /* TH_NODE */
SETCOL(btheme->tnode.syntaxn, 110, 110, 120, 255); /* in-out */
SETCOL(btheme->tnode.syntaxb, 140, 140, 140, 255); /* operator */
SETCOL(btheme->tnode.syntaxv, 120, 120, 120, 255); /* generator */
SETCOL(btheme->tnode.syntaxc, 120, 120, 120, 255); /* free */
}
}
}
if (U.undosteps==0) U.undosteps=32; if (U.undosteps==0) U.undosteps=32;
@@ -660,6 +674,7 @@ void BIF_init(void)
initbuttons(); initbuttons();
InitCursorData(); InitCursorData();
sound_init_listener(); sound_init_listener();
init_node_butfuncs();
BIF_read_homefile(); BIF_read_homefile();
init_gl_stuff(); /* drawview.c, after homefile */ init_gl_stuff(); /* drawview.c, after homefile */