[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34577] trunk/blender: Added transparency feature to node editor backdrop, similar to image editor.

Lukas Toenne lukas.toenne at googlemail.com
Mon Jan 31 12:17:52 CET 2011


Revision: 34577
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34577
Author:   lukastoenne
Date:     2011-01-31 11:17:50 +0000 (Mon, 31 Jan 2011)
Log Message:
-----------
Added transparency feature to node editor backdrop, similar to image editor. Alpha blending can be enabled by a button when "Use Backdrop" is selected.

Modified Paths:
--------------
    trunk/blender/release/scripts/ui/space_node.py
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/makesrna/intern/rna_space.c

Modified: trunk/blender/release/scripts/ui/space_node.py
===================================================================
--- trunk/blender/release/scripts/ui/space_node.py	2011-01-31 07:52:45 UTC (rev 34576)
+++ trunk/blender/release/scripts/ui/space_node.py	2011-01-31 11:17:50 UTC (rev 34577)
@@ -68,6 +68,9 @@
             layout.prop(scene, "use_nodes")
             layout.prop(scene.render, "use_free_unused_nodes", text="Free Unused")
             layout.prop(snode, "show_backdrop")
+            if snode.show_backdrop:
+                row = layout.row(align=True)
+                row.prop(snode, "backdrop_channels", text="", expand=True)
 
         layout.separator()
 

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2011-01-31 07:52:45 UTC (rev 34576)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2011-01-31 11:17:50 UTC (rev 34577)
@@ -44,6 +44,7 @@
 
 #include "BKE_context.h"
 #include "BKE_curve.h"
+#include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_library.h"
 #include "BKE_main.h"
@@ -1367,9 +1368,35 @@
 			}
 
 			if(ibuf->rect) {
-				glPixelZoom(snode->zoom, snode->zoom);
-				glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
-				glPixelZoom(1.0f, 1.0f);
+				if (snode->flag & SNODE_SHOW_ALPHA) {
+					glEnable(GL_BLEND);
+					glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+					glPixelZoom(snode->zoom, snode->zoom);
+					/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
+					if(ENDIAN_ORDER == B_ENDIAN)
+						glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
+					
+					glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
+					
+					glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
+					glPixelZoom(1.0f, 1.0f);
+					glDisable(GL_BLEND);
+				} else if (snode->flag & SNODE_USE_ALPHA) {
+					glEnable(GL_BLEND);
+					glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+					glPixelZoom(snode->zoom, snode->zoom);
+					
+					glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+					
+					glPixelZoom(1.0f, 1.0f);
+					glDisable(GL_BLEND);
+				} else {
+					glPixelZoom(snode->zoom, snode->zoom);
+					
+					glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+					
+					glPixelZoom(1.0f, 1.0f);
+				}
 			}
 			
 			glMatrixMode(GL_PROJECTION);

Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h	2011-01-31 07:52:45 UTC (rev 34576)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h	2011-01-31 11:17:50 UTC (rev 34577)
@@ -405,6 +405,8 @@
 /* snode->flag */
 #define SNODE_BACKDRAW		2
 #define SNODE_DISPGP		4
+#define SNODE_USE_ALPHA		8
+#define SNODE_SHOW_ALPHA	16
 
 /* snode->texfrom */
 #define SNODE_TEX_OBJECT	0

Modified: trunk/blender/source/blender/makesrna/intern/rna_space.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_space.c	2011-01-31 07:52:45 UTC (rev 34576)
+++ trunk/blender/source/blender/makesrna/intern/rna_space.c	2011-01-31 11:17:50 UTC (rev 34577)
@@ -2267,7 +2267,13 @@
 		{SNODE_TEX_WORLD, "WORLD", ICON_WORLD_DATA, "World", "Edit texture nodes from World"},
 		{SNODE_TEX_BRUSH, "BRUSH", ICON_BRUSH_DATA, "Brush", "Edit texture nodes from Brush"},
 		{0, NULL, 0, NULL, NULL}};
-	
+
+	static EnumPropertyItem backdrop_channels_items[] = {
+		{0, "COLOR", ICON_IMAGE_RGB, "Color", "Draw image with RGB colors"},
+		{SNODE_USE_ALPHA, "COLOR_ALPHA", ICON_IMAGE_RGB_ALPHA, "Color and Alpha", "Draw image with RGB colors and alpha transparency"},
+		{SNODE_SHOW_ALPHA, "ALPHA", ICON_IMAGE_ALPHA, "Alpha", "Draw alpha transparency channel"},
+		{0, NULL, 0, NULL, NULL}};
+
 	srna= RNA_def_struct(brna, "SpaceNodeEditor", "Space");
 	RNA_def_struct_sdna(srna, "SpaceNode");
 	RNA_def_struct_ui_text(srna, "Space Node Editor", "Node editor space data");
@@ -2317,6 +2323,12 @@
 	RNA_def_property_float_sdna(prop, NULL, "yof");
 	RNA_def_property_ui_text(prop, "Backdrop Y", "Backdrop Y offset");
 	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
+
+	prop= RNA_def_property(srna, "backdrop_channels", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
+	RNA_def_property_enum_items(prop, backdrop_channels_items);
+	RNA_def_property_ui_text(prop, "Draw Channels", "Channels of the image to draw");
+	RNA_def_property_update(prop, NC_SPACE|ND_SPACE_NODE_VIEW, NULL);
 }
 
 static void rna_def_space_logic(BlenderRNA *brna)




More information about the Bf-blender-cvs mailing list