added format() to PyOutStream

This commit is contained in:
Jack Andersen 2015-08-02 16:05:04 -10:00
parent 7f0617fcb3
commit 0087ede1a4
3 changed files with 64 additions and 0 deletions

View File

@ -9,6 +9,7 @@
#endif
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <functional>
#include <mutex>
@ -108,6 +109,17 @@ public:
BlenderLog.report(LogVisor::FatalError, "unable to close PyOutStream with blender");
}
}
void format(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
char* result = nullptr;
int length = vasprintf(&result, fmt, ap);
if (length > 0)
this->write(result, length);
free(result);
va_end(ap);
}
};
inline PyOutStream beginPythonOut()
{

View File

@ -1,5 +1,6 @@
list(APPEND PY_SOURCES
addon/__init__.py
addon/Nodegrid.py
addon/hmdl/__init__.py
addon/hmdl/HMDLMesh.py
addon/hmdl/HMDLShader.py

View File

@ -0,0 +1,51 @@
# Node Grid Arranger Class
NODE_PADDING = 80
FRAME_NAMES = ['Dynamics','Textures','Combiners','Output']
FRAME_WIDTHS = [250, 250, 800, 180]
TOTAL_WIDTH = 0.0
for width in FRAME_WIDTHS:
TOTAL_WIDTH += width + NODE_PADDING
FRAME_COLORS = [(0.6,0.46,0.6),(0.6,0.48,0.44),(0.33,0.48,0.6),(0.53,0.6,0.47)]
class Nodegrid:
def __init__(self, nodetree):
self.ncol = len(FRAME_NAMES)
self.heights = []
self.frames = []
self.col_roffs = [[0.0,0.0]] * self.ncol
for i in range(self.ncol):
self.heights.append(0.0)
frame_node = new_nodetree.nodes.new('NodeFrame')
frame_node.label = FRAME_NAMES[i]
frame_node.use_custom_color = True
frame_node.color = FRAME_COLORS[i]
self.frames.append(frame_node)
def place_node(self, node, col):
if col < 0 or col >= self.ncol:
return False
x_pos = NODE_PADDING
for i in range(col):
x_pos += FRAME_WIDTHS[i] + NODE_PADDING*2
node.location[0] = x_pos - TOTAL_WIDTH/2
node.location[1] = self.heights[col]
self.heights[col] -= node.height + NODE_PADDING
self.frames[col].height += node.height + NODE_PADDING
node.parent = self.frames[col]
return True
def place_node_right(self, node, col, srow):
heights_backup = self.heights[col]
if self.place_node(node, col):
node.location[0] += self.col_roffs[col][srow]
if srow == 1:
node.location[1] -= 175
self.col_roffs[col][srow] += 200
self.heights[col] = heights_backup
def row_break(self, col):
self.heights[col] -= 350
self.col_roffs[col][0] = 0.0
self.col_roffs[col][1] = 0.0