|
|
@@ -1,433 +0,0 @@
|
|
|
-#!/usr/bin/python
|
|
|
-from gui import *
|
|
|
-
|
|
|
-def create_layer(name):
|
|
|
- win_id = api.lookup_node_id("/window")
|
|
|
-
|
|
|
- node_id = api.add_node(name, SceneNodeType.RENDER_LAYER)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "is_visible", PropertyType.BOOL, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Is Visible", "Visibility of this layer",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "rect", PropertyType.UINT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Rectangle", "The position and size within the layer",
|
|
|
- False, True, 4, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- api.link_node(node_id, win_id)
|
|
|
- return node_id
|
|
|
-
|
|
|
-def create_mesh(name, layer_id):
|
|
|
- node_id = api.add_node(name, SceneNodeType.RENDER_MESH)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "data", PropertyType.BUFFER, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Mesh Data", "The face and vertex data for the mesh",
|
|
|
- False, False, 2, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "rect", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Rectangle", "The position and size within the layer",
|
|
|
- False, True, 4, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "z_index", PropertyType.UINT32, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Z-index", "Z-index: values greater than zero are deferred draws",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- #prop = Property(
|
|
|
- # "is_visible", PropertyType.UINT32, PropertySubType.NULL,
|
|
|
- # None,
|
|
|
- # "Is Visible", "Visibility of this object",
|
|
|
- # False, False, 1, None, None, []
|
|
|
- #)
|
|
|
- #api.add_property(node_id, prop)
|
|
|
-
|
|
|
- api.link_node(node_id, layer_id)
|
|
|
- return node_id
|
|
|
-
|
|
|
-def create_text(name, layer_id):
|
|
|
- node_id = api.add_node(name, SceneNodeType.RENDER_TEXT)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "rect", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Rectangle", "The position and size within the layer",
|
|
|
- False, True, 4, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "baseline", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Baseline", "Y offset of baseline inside rect",
|
|
|
- False, True, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "font_size", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Font Size", "Font Size",
|
|
|
- False, True, 1, 0.0, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "text", PropertyType.STR, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Text", "Text",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "color", PropertyType.FLOAT32, PropertySubType.COLOR,
|
|
|
- None,
|
|
|
- "Color", "Color of the text",
|
|
|
- False, False, 4, 0, 1, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "z_index", PropertyType.UINT32, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Z-index", "Z-index: values greater than zero are deferred draws",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "debug", PropertyType.BOOL, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Debug", "Draw debug outlines",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- api.link_node(node_id, layer_id)
|
|
|
- return node_id
|
|
|
-
|
|
|
-def create_editbox(name, layer_id):
|
|
|
- node_id = api.add_node("editz", SceneNodeType.EDIT_BOX)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "is_active", PropertyType.BOOL, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Is Active", "Whether the editbox is active",
|
|
|
- False, True, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "rect", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Rectangle", "The position and size within the layer",
|
|
|
- False, True, 4, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "baseline", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Baseline", "Y offset of baseline inside rect",
|
|
|
- False, True, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "scroll", PropertyType.FLOAT32, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Scroll", "Current scroll",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "cursor_pos", PropertyType.UINT32, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Cursor Position", "Cursor position within the text",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "font_size", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Font Size", "Font Size",
|
|
|
- False, True, 1, 0.0, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "text", PropertyType.STR, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Text", "Text",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "text_color", PropertyType.FLOAT32, PropertySubType.COLOR,
|
|
|
- None,
|
|
|
- "Text Color", "Color of the text",
|
|
|
- False, False, 4, 0, 1, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "cursor_color", PropertyType.FLOAT32, PropertySubType.COLOR,
|
|
|
- None,
|
|
|
- "Cursor Color", "Color of the cursor",
|
|
|
- False, False, 4, 0, 1, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "hi_bg_color", PropertyType.FLOAT32, PropertySubType.COLOR,
|
|
|
- None,
|
|
|
- "Highlight Bg Color", "Background color for highlighted text",
|
|
|
- False, False, 4, 0, 1, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "selected", PropertyType.UINT32, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Selected", "Selected range",
|
|
|
- True, False, 2, 0, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "z_index", PropertyType.UINT32, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Z-index", "Z-index: values greater than zero are deferred draws",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "debug", PropertyType.BOOL, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Debug", "Draw debug outlines",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- #win_id = api.lookup_node_id("/window")
|
|
|
- #arg_data = bytearray()
|
|
|
- #serial.write_u32(arg_data, node_id)
|
|
|
- #api.call_method(win_id, "create_edit_box", arg_data)
|
|
|
-
|
|
|
- #api.link_node(node_id, layer_id)
|
|
|
- return node_id
|
|
|
-
|
|
|
-def create_chatview(name, layer_id):
|
|
|
- node_id = api.add_node(name, SceneNodeType.CHAT_VIEW)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "rect", PropertyType.FLOAT32, PropertySubType.PIXEL,
|
|
|
- None,
|
|
|
- "Rectangle", "The position and size within the layer",
|
|
|
- False, True, 4, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "debug", PropertyType.BOOL, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Debug", "Draw debug outlines",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- prop = Property(
|
|
|
- "z_index", PropertyType.UINT32, PropertySubType.NULL,
|
|
|
- None,
|
|
|
- "Z-index", "Z-index: values greater than zero are deferred draws",
|
|
|
- False, False, 1, None, None, []
|
|
|
- )
|
|
|
- api.add_property(node_id, prop)
|
|
|
-
|
|
|
- win_id = api.lookup_node_id("/window")
|
|
|
- arg_data = bytearray()
|
|
|
- serial.write_u32(arg_data, node_id)
|
|
|
- api.call_method(win_id, "create_chat_view", arg_data)
|
|
|
-
|
|
|
- api.link_node(node_id, layer_id)
|
|
|
- return node_id
|
|
|
-
|
|
|
-class Buffer:
|
|
|
-
|
|
|
- def __init__(self):
|
|
|
- self.verts = bytearray()
|
|
|
- self.faces = bytearray()
|
|
|
- self.verts_len = 0
|
|
|
-
|
|
|
- def draw_box(self, rect=(0, 0, 1, 1), r=0, g=0, b=0):
|
|
|
- x, y, w, h = rect
|
|
|
- vert1 = vertex(x, y, r, g, b, 1, 0, 0)
|
|
|
- vert2 = vertex(x + w, y, r, g, b, 1, 1, 0)
|
|
|
- vert3 = vertex(x, y + h, r, g, b, 1, 0, 1)
|
|
|
- vert4 = vertex(x + w, y + h, r, g, b, 1, 1, 1)
|
|
|
- verts = vert1 + vert2 + vert3 + vert4
|
|
|
-
|
|
|
- k = self.verts_len
|
|
|
- faces = face(k, k + 2, k + 1) + face(k + 1, k + 2, k + 3)
|
|
|
- self.verts_len += 4
|
|
|
-
|
|
|
- self.verts += verts
|
|
|
- self.faces += faces
|
|
|
-
|
|
|
- def draw_outline(self, rect=(0, 0, 1, 1), r=0, g=0, b=0, pad=1, layer_dim=(0, 0)):
|
|
|
- layer_w, layer_h = layer_dim
|
|
|
- pad_x, pad_y = 1/layer_w, 1/layer_h
|
|
|
- x, y, w, h = rect
|
|
|
- # left side
|
|
|
- self.draw_box((x, y, pad_x, h), r, g, b)
|
|
|
- # top side
|
|
|
- self.draw_box((x, y, w, pad_y), r, g, b)
|
|
|
- # right side
|
|
|
- rhs = x + w
|
|
|
- self.draw_box((rhs - pad_x, y, pad_x, h), r, g, b)
|
|
|
- # bottom side
|
|
|
- bhs = y + h
|
|
|
- self.draw_box((x, bhs - pad_y, w, pad_y), r, g, b)
|
|
|
-
|
|
|
-def main():
|
|
|
- layer_id = create_layer("view")
|
|
|
- api.set_property_u32(layer_id, "rect", 0, 0)
|
|
|
- api.set_property_u32(layer_id, "rect", 1, 0)
|
|
|
- code = [["as_u32", ["load", "sw"]]]
|
|
|
- api.set_property_expr(layer_id, "rect", 2, code)
|
|
|
- code = [["as_u32", ["load", "sh"]]]
|
|
|
- api.set_property_expr(layer_id, "rect", 3, code)
|
|
|
-
|
|
|
- # Make the black background
|
|
|
- # Maybe we should use a RenderPass for this instead
|
|
|
- node_id = create_mesh("bg", layer_id)
|
|
|
- api.set_property_f32(node_id, "rect", 0, 0)
|
|
|
- api.set_property_f32(node_id, "rect", 1, 0)
|
|
|
- code = [["load", "lw"]]
|
|
|
- api.set_property_expr(node_id, "rect", 2, code)
|
|
|
- code = [["load", "lh"]]
|
|
|
- api.set_property_expr(node_id, "rect", 3, code)
|
|
|
-
|
|
|
- buff = Buffer()
|
|
|
- buff.draw_box(r=0.05, g=0.05, b=0.05)
|
|
|
- api.set_property_buf(node_id, "data", 0, buff.verts)
|
|
|
- api.set_property_buf(node_id, "data", 1, buff.faces)
|
|
|
-
|
|
|
- # Make the chatedit bg
|
|
|
- node_id = create_mesh("chateditbg", layer_id)
|
|
|
- api.set_property_f32(node_id, "rect", 0, 100)
|
|
|
- code = [["-", ["load", "lh"], ["f32", 50]]]
|
|
|
- api.set_property_expr(node_id, "rect", 1, code)
|
|
|
- code = [["-", ["load", "lw"], ["f32", 100]]]
|
|
|
- api.set_property_expr(node_id, "rect", 2, code)
|
|
|
- api.set_property_f32(node_id, "rect", 3, 50)
|
|
|
-
|
|
|
- buff = Buffer()
|
|
|
- buff.draw_box(r=0.0, g=0.13, b=0.08)
|
|
|
- buff.draw_outline(r=0.22, g=0.22, b=0.22, pad=1, layer_dim=(1000, 50))
|
|
|
- api.set_property_buf(node_id, "data", 0, buff.verts)
|
|
|
- api.set_property_buf(node_id, "data", 1, buff.faces)
|
|
|
-
|
|
|
- # Make the nicktext border
|
|
|
- node_id = create_mesh("nickbg", layer_id)
|
|
|
- api.set_property_f32(node_id, "rect", 0, 0)
|
|
|
- code = [["-", ["load", "lh"], ["f32", 50]]]
|
|
|
- api.set_property_expr(node_id, "rect", 1, code)
|
|
|
- api.set_property_f32(node_id, "rect", 2, 100)
|
|
|
- api.set_property_f32(node_id, "rect", 3, 50)
|
|
|
-
|
|
|
- buff = Buffer()
|
|
|
- buff.draw_outline(r=0.0, g=0.13, b=0.08, pad=1, layer_dim=(100, 50))
|
|
|
- api.set_property_buf(node_id, "data", 0, buff.verts)
|
|
|
- api.set_property_buf(node_id, "data", 1, buff.faces)
|
|
|
-
|
|
|
- # The nickname
|
|
|
- node_id = create_text("nick", layer_id)
|
|
|
- api.set_property_f32(node_id, "rect", 0, 20)
|
|
|
- code = [["-", ["load", "lh"], ["f32", 50]]]
|
|
|
- api.set_property_expr(node_id, "rect", 1, code)
|
|
|
- api.set_property_f32(node_id, "rect", 2, 100)
|
|
|
- api.set_property_f32(node_id, "rect", 3, 50)
|
|
|
- api.set_property_f32(node_id, "baseline", 0, 30)
|
|
|
- api.set_property_f32(node_id, "font_size", 0, 20)
|
|
|
- api.set_property_str(node_id, "text", 0, "anon1")
|
|
|
- api.set_property_f32(node_id, "color", 0, 0)
|
|
|
- api.set_property_f32(node_id, "color", 1, 1)
|
|
|
- api.set_property_f32(node_id, "color", 2, 0)
|
|
|
- api.set_property_f32(node_id, "color", 3, 1)
|
|
|
- api.set_property_u32(node_id, "z_index", 0, 1)
|
|
|
-
|
|
|
- # Make the text edit
|
|
|
- node_id = create_editbox("editz", layer_id)
|
|
|
- api.set_property_bool(node_id, "is_active", 0, True)
|
|
|
- api.set_property_f32(node_id, "rect", 0, 100)
|
|
|
- code = [["-", ["load", "lh"], ["f32", 50]]]
|
|
|
- api.set_property_expr(node_id, "rect", 1, code)
|
|
|
- code = [["-", ["load", "lw"], ["f32", 100]]]
|
|
|
- api.set_property_expr(node_id, "rect", 2, code)
|
|
|
- api.set_property_f32(node_id, "rect", 3, 50)
|
|
|
- api.set_property_f32(node_id, "baseline", 0, 30)
|
|
|
- api.set_property_f32(node_id, "font_size", 0, 20)
|
|
|
- api.set_property_str(node_id, "text", 0, "hello king!😁🍆jelly 🍆1234")
|
|
|
- api.set_property_f32(node_id, "text_color", 0, 1)
|
|
|
- api.set_property_f32(node_id, "text_color", 1, 1)
|
|
|
- api.set_property_f32(node_id, "text_color", 2, 1)
|
|
|
- api.set_property_f32(node_id, "text_color", 3, 1)
|
|
|
- api.set_property_f32(node_id, "cursor_color", 0, 1)
|
|
|
- api.set_property_f32(node_id, "cursor_color", 1, 0.5)
|
|
|
- api.set_property_f32(node_id, "cursor_color", 2, 0.5)
|
|
|
- api.set_property_f32(node_id, "cursor_color", 3, 1)
|
|
|
- api.set_property_f32(node_id, "hi_bg_color", 0, 1)
|
|
|
- api.set_property_f32(node_id, "hi_bg_color", 1, 1)
|
|
|
- api.set_property_f32(node_id, "hi_bg_color", 2, 1)
|
|
|
- api.set_property_f32(node_id, "hi_bg_color", 3, 0.5)
|
|
|
- api.set_property_null(node_id, "selected", 0)
|
|
|
- api.set_property_null(node_id, "selected", 1)
|
|
|
- api.set_property_u32(node_id, "z_index", 0, 1)
|
|
|
- api.set_property_bool(node_id, "debug", 0, False)
|
|
|
-
|
|
|
- win_id = api.lookup_node_id("/window")
|
|
|
- arg_data = bytearray()
|
|
|
- serial.write_u32(arg_data, node_id)
|
|
|
- api.call_method(win_id, "create_edit_box", arg_data)
|
|
|
- api.link_node(node_id, layer_id)
|
|
|
-
|
|
|
- # Add the chatview
|
|
|
- node_id = create_chatview("chatty", layer_id)
|
|
|
- api.set_property_f32(node_id, "rect", 0, 0)
|
|
|
- api.set_property_f32(node_id, "rect", 1, 0)
|
|
|
- code = [["load", "lw"]]
|
|
|
- api.set_property_expr(node_id, "rect", 2, code)
|
|
|
- code = [["-", ["load", "lh"], ["f32", 50]]]
|
|
|
- api.set_property_expr(node_id, "rect", 3, code)
|
|
|
- #api.set_property_bool(node_id, "debug", 0, True)
|
|
|
- api.set_property_u32(node_id, "z_index", 0, 1)
|
|
|
-
|
|
|
- api.set_property_bool(layer_id, "is_visible", 0, True)
|
|
|
-
|
|
|
-main()
|
|
|
-print_tree()
|
|
|
-
|