def mediaDropDown(flight): # create a drop down for raw if imgui.tree_node("Raw ##" + str(flight.id)): # loop through all the 'raw' media in the flight for raw in flight.getFlightMedia().raw: # display the media name in the dropdown imgui.text(raw) imgui.tree_pop() # create a drop down for photos if imgui.tree_node("Photos ##" + str(flight.id)): # loop through all the 'photo' aka non raw media in the flight for photo in flight.getFlightMedia().images: # display the media name in the dropdown imgui.text(photo) # on the same line create the preview button for photos imgui.same_line() handlePhotoPreviewButtonClick(flight.flight_directory, photo) imgui.tree_pop() # create a drop down for videos if imgui.tree_node("Videos ##" + str(flight.id)): # loop through all the 'video' media in the flight for video in flight.getFlightMedia().video: # display the media name in the dropdown imgui.text(video) imgui.tree_pop()
def table_tree(table: EntryGroup): for key, entry in table.items(): if isinstance(entry, NetworkTableEntry): imgui.text(entry_name(key) + ': ' + str(entry.value)) imgui.same_line() imgui.push_id(key) if imgui.button('Add'): active_widgets[key] = Widget(entry) imgui.pop_id() else: t = NetworkTables.getTable(key) if '.type' in t.getKeys(): name = t.getString('.name', '') imgui.text(name) imgui.same_line() imgui.push_id(key) if imgui.button('Add'): active_widgets[key] = Widget(t, EntryType.Chooser) imgui.pop_id() if show_sendable_debug: if imgui.tree_node('Chooser Debug (' + key + ')'): table_tree(entry) imgui.tree_pop() elif imgui.tree_node(entry_name(key), imgui.TREE_NODE_DEFAULT_OPEN): # nothing fancy, just a subtable table_tree(entry) imgui.tree_pop()
def update(dt, keyStateMap, mouseDelta): global g_sunPosition global g_sunAngle global g_globalAmbientLight global g_sunLightColour global g_sunAngle global g_updateSun global g_viewTarget global g_viewPosition global g_followCamOffset global g_followCamLookOffset if g_updateSun: g_sunAngle += dt * 0.25 g_sunAngle = g_sunAngle % (2.0 * math.pi) g_sunPosition = lu.Mat3( lu.make_rotation_x(g_sunAngle)) * g_sunStartPosition g_sunLightColour = sampleKeyFrames( lu.dot(lu.normalize(g_sunPosition), vec3(0.0, 0.0, 1.0)), g_sunKeyFrames) g_globalAmbientLight = sampleKeyFrames( lu.dot(lu.normalize(g_sunPosition), vec3(0.0, 0.0, 1.0)), g_ambientKeyFrames) g_racer.update(dt, keyStateMap) # TODO 1.2: Make the camera look at the racer. Code for updating the camera should be done after the # racer, otherwise the offset will lag and it generally looks weird. if imgui.tree_node("Camera", imgui.TREE_NODE_DEFAULT_OPEN): _, g_followCamOffset = imgui.slider_float("FollowCamOffset ", g_followCamOffset, 2.0, 100.0) _, g_followCamLookOffset = imgui.slider_float("FollowCamLookOffset", g_followCamLookOffset, 0.0, 100.0) imgui.tree_pop() if imgui.tree_node("Racer", imgui.TREE_NODE_DEFAULT_OPEN): g_racer.drawUi() imgui.tree_pop() if imgui.tree_node("Terrain", imgui.TREE_NODE_DEFAULT_OPEN): g_terrain.drawUi() imgui.tree_pop() if imgui.tree_node("Lighting", imgui.TREE_NODE_DEFAULT_OPEN): _, g_globalAmbientLight = lu.imguiX_color_edit3_list( "GlobalAmbientLight", g_globalAmbientLight ) #, imgui.GuiColorEditFlags_Float);// | ImGuiColorEditFlags_HSV); _, g_sunLightColour = lu.imguiX_color_edit3_list( "SunLightColour", g_sunLightColour ) #, imgui.GuiColorEditFlags_Float);// | ImGuiColorEditFlags_HSV); _, g_sunAngle = imgui.slider_float("SunAngle", g_sunAngle, 0.0, 2.0 * math.pi) _, g_updateSun = imgui.checkbox("UpdateSun", g_updateSun) imgui.tree_pop()
def update(world: World, g_renderingSystem: RenderingSystem, dt, keyStateMap, mouseDelta): if world.should_update_sun: world.sun_angle += dt * 0.25 world.sun_angle = world.sun_angle % (2.0 * math.pi) world.sun_position = lu.Mat3(lu.make_rotation_x( world.sun_angle)) * world.sun_start_position world.sunlight_color = sampleKeyFrames( lu.dot(lu.normalize(world.sun_position), vec3(0.0, 0.0, 1.0)), world.sun_keyframes) world.global_ambient_light = sampleKeyFrames( lu.dot(lu.normalize(world.sun_position), vec3(0.0, 0.0, 1.0)), world.ambient_keyframes) world.racer.update(dt, keyStateMap) world.view_position = world.racer.position - \ (world.racer.heading * world.follow_cam_offset) + \ [0, 0, world.follow_cam_offset] world.view_target = world.racer.position + vec3( 0, 0, world.follow_cam_look_offset) if imgui.tree_node("Camera", imgui.TREE_NODE_DEFAULT_OPEN): _, world.follow_cam_offset = imgui.slider_float( "FollowCamOffset ", world.follow_cam_offset, 2.0, 100.0) _, world.follow_cam_look_offset = imgui.slider_float( "FollowCamLookOffset", world.follow_cam_look_offset, 0.0, 100.0) imgui.tree_pop() if imgui.tree_node("Racer", imgui.TREE_NODE_DEFAULT_OPEN): world.racer.draw_ui() imgui.tree_pop() if imgui.tree_node("Terrain", imgui.TREE_NODE_DEFAULT_OPEN): world.terrain.draw_ui() imgui.tree_pop() if imgui.tree_node("Lighting", imgui.TREE_NODE_DEFAULT_OPEN): _, world.global_ambient_light = lu.imguiX_color_edit3_list( "GlobalAmbientLight", world.global_ambient_light ) # , imgui.GuiColorEditFlags_Float);// | ImGuiColorEditFlags_HSV); _, world.sunlight_color = lu.imguiX_color_edit3_list( "SunLightColour", world.sunlight_color ) # , imgui.GuiColorEditFlags_Float);// | ImGuiColorEditFlags_HSV); _, world.sun_angle = imgui.slider_float("SunAngle", world.sun_angle, 0.0, 2.0 * math.pi) _, world.should_update_sun = imgui.checkbox("UpdateSun", world.should_update_sun) imgui.tree_pop()
def drawUi(self): if imgui.tree_node("FreeCamera", imgui.TREE_NODE_DEFAULT_OPEN): _, self.yawDeg = imgui.slider_float("Yaw (Deg)", self.yawDeg, -180.00, 180.0) _, self.pitchDeg = imgui.slider_float("Pitch (Deg)", self.pitchDeg, -89.00, 89.0) imgui.tree_pop()
def _draw_component(self, entity, component_name, component_name_display): if not entity.has_component(component_name): return treeNodeFlags = imgui.TREE_NODE_DEFAULT_OPEN | imgui.TREE_NODE_FRAMED | imgui.TREE_NODE_ALLOW_ITEM_OVERLAP | imgui.TREE_NODE_FRAME_PADDING component = entity.get_component(component_name) # contentRegionAvailable = imgui.get_content_region_available() # lineHeight = imgui.push_style_var(imgui.STYLE_FRAME_PADDING, (4, 4)) imgui.separator() open = imgui.tree_node(component_name_display, treeNodeFlags) imgui.pop_style_var() # TODO imgui.same_line(contentRegionAvailable.x - lin) imgui.same_line() if imgui.button("+"): imgui.open_popup("ComponentSettings") removeComponent = False if imgui.begin_popup("ComponentSettings"): if menu_item_clicked("Remove component"): removeComponent = True imgui.end_popup() if open: getattr(self, "_draw_component_%s" % component_name)(component) imgui.tree_pop() if removeComponent: entity.remove_component(component_name)
def _draw_entity_node(self, entity): tag = entity.tag flags = imgui.TREE_NODE_SELECTED if self.selected_entity == entity else 0 opened = imgui.tree_node(tag, flags) if imgui.is_item_clicked(): self.selected_entity = entity entityDeleted = False # get delete entity if imgui.begin_popup_context_item(): if menu_item_clicked("Delete Entity"): entityDeleted = True imgui.end_popup() # handle opened if opened: # flags = imgui.TREE_NODE_OPEN_ON_ARROW # pass # TODO draw sub object HERE # if imgui.tree_node(tag, flags): # imgui.tree_pop() imgui.tree_pop() # handle delete entity if entityDeleted: self.scene.destroy_entity(entity) if self.selected_entity == entity: self.selected_entity = None
def draw(self): imgui.begin(self.title) #if imgui.tree_node("Expand me!", imgui.TREE_NODE_DEFAULT_OPEN): if imgui.tree_node("Expand me!"): imgui.text("Lorem Ipsum") imgui.tree_pop() imgui.end()
def render_inspector ( self, obj, prefix = None ): properties = obj.__dict__ if hasattr( obj, '__dict__' ) else obj node_name = f"{obj.__class__.__name__}###{id( obj )}"; if imgui.tree_node( node_name if prefix == None else f"{prefix}: {node_name}", imgui.TREE_NODE_DEFAULT_OPEN ): for key, value in properties.items(): self.render_inspector_value( key, value ); imgui.tree_pop()
def ui(self): """Create the imgui UI node to control lighting """ if imgui.tree_node("Lighting", imgui.TREE_NODE_DEFAULT_OPEN): _, self.sun_yaw = imgui.slider_float("Yaw (Deg)", self.sun_yaw, -180.00, 180.0) _, self.sun_pitch = imgui.slider_float("Pitch (Deg)", self.sun_pitch, -180.00, 180.0) imgui.tree_pop()
def ui(self): """Super lame UI for adjusting the position of the object """ if True: return if imgui.tree_node("Object", imgui.TREE_NODE_DEFAULT_OPEN): _, x = imgui.slider_float("X", self.position[0], -10, 10) _, y = imgui.slider_float("Y", self.position[1], -10, 10) _, z = imgui.slider_float("Z", self.position[2], -10, 10) self.position = gltypes.vec3(x, y, z) imgui.tree_pop()
def show_outputs_popup(iggraph): if imgui.begin_popup_modal("Outputs")[0]: output_nodes = iggraph.get_output_nodes() for output_node in output_nodes: if imgui.tree_node(output_node.inputs["parameter name"].text): value = output_node.outputs["output"] display_parameter(value,True) imgui.tree_pop() imgui.separator() if imgui.button("ok"): imgui.close_current_popup() imgui.end_popup()
def ui(self): """Basic UI node to adjust yaw, pitch, and distance Yaw can also be controlled with arrow keys (see above) """ if imgui.tree_node("Camera", imgui.TREE_NODE_DEFAULT_OPEN): _, self.yaw = imgui.slider_float("Yaw (Deg)", self.yaw, -180.00, 180.0) _, self.pitch = imgui.slider_float("Pitch (Deg)", self.pitch, -89.00, 89.0) _, self.distance = imgui.slider_float("Distance", self.distance, 1.00, 1000.0) imgui.tree_pop()
def render(self, scene): imgui.new_frame() changed = False if scene is not None: imgui.style_colors_classic() imgui.begin("Scene") imgui.text("Filename Template:") _, self.snapshot_format = imgui.input_text("", self.snapshot_format, 256) if imgui.button("Save Snapshot"): # Call render again, since we're in the middle of overlaying # some stuff and we want a clean scene snapshot scene.render() write_bitmap( scene.image[:, :, :3], self.snapshot_format.format(count=self.snapshot_count), ) self.snapshot_count += 1 if imgui.tree_node("Debug"): if imgui.button("Save Depth"): scene.render() write_image( scene.depth, self.snapshot_format.format(count=self.snapshot_count), ) self.snapshot_count += 1 imgui.tree_pop() _ = self.render_camera(scene) changed = changed or _ # imgui.show_style_editor() for i, element in enumerate(scene): if imgui.tree_node(f"element {i + 1}: {element.name}"): changed = changed or element.render_gui( imgui, self.renderer, scene) imgui.tree_pop() self.window._do_update = self.window._do_update or changed imgui.end() imgui.render() self.renderer.render(imgui.get_draw_data())
def draw_node_item(node, scene): nd = node if imgui.tree_node("Node: {} {}".format(str(nd.id), nd.name), imgui.TREE_NODE_OPEN_ON_ARROW): if nd.mesh: if imgui.tree_node("Mesh: {}".format(str(nd.mesh.id)), imgui.TREE_NODE_OPEN_ON_ARROW): if nd.mesh.primitives: for i, prim in enumerate(nd.mesh.primitives): if imgui.tree_node("Primitive: {}".format(str(i))): if imgui.tree_node("Material", flags=imgui.TREE_NODE_LEAF | imgui.TREE_NODE_SELECTED): imgui.tree_pop() imgui.tree_pop() imgui.tree_pop() if nd.children: for i in nd.children: draw_node_item(scene.nodelist[i], scene) imgui.tree_pop() if imgui.is_item_clicked(): print("clicked")
def displayGameObjectOnHierarchy(self, obj): if len(obj.childs) <= 0: if imgui.selectable(obj.name)[1]: self.curControlObject = obj else: object_layer = imgui.tree_node(obj.name, flags=imgui.TREE_NODE_OPEN_ON_ARROW) clicked = imgui.is_item_clicked() if clicked: self.curControlObject = obj if object_layer: for childObj in obj.childs: self.displayGameObjectOnHierarchy(childObj) imgui.tree_pop()
def tree_node(text, widget, open=True): """Display a collapsible tree node. It can be open or closed by default (parameter `open`). Tree node content has left offset, unlike `collapsing_header`. """ while True: expanded = imgui.tree_node(text, flags=open and imgui.TREE_NODE_DEFAULT_OPEN) try: if expanded: next(widget) except StopIteration as e: return e.value finally: if expanded: imgui.tree_pop() yield
def render_camera(self, scene): if not imgui.tree_node("Camera"): return changed = False with scene.camera.hold_trait_notifications(): for attr in ("position", "up", "focus"): arr = getattr(scene.camera, attr) imgui.text(f"Camera {attr}") _, values = imgui.input_float3( "", arr[0], arr[1], arr[2], flags=imgui.INPUT_TEXT_ENTER_RETURNS_TRUE, ) changed = changed or _ if _: setattr(scene.camera, attr, np.array(values)) _, values = imgui.input_float2( "Camera Planes", scene.camera.near_plane, scene.camera.far_plane, format="%0.6f", flags=imgui.INPUT_TEXT_ENTER_RETURNS_TRUE, ) changed = changed or _ if _: scene.camera.near_plane = values[0] scene.camera.far_plane = values[1] if imgui.button("Center"): scene.camera.position = np.array([0.499, 0.499, 0.499]) scene.camera.focus = np.array([0.5, 0.5, 0.5]) changed = True if imgui.button("Outside"): scene.camera.position = np.array([1.5, 1.5, 1.5]) scene.camera.focus = np.array([0.5, 0.5, 0.5]) changed = True if changed: scene.camera._update_matrices() imgui.tree_pop() return changed
def render_inspector_value ( self, key, value ): if isinstance( value, int )\ or isinstance( value, bool )\ or isinstance( value, float )\ or isinstance( value, str )\ or isinstance( value, tuple )\ or isinstance( value, Fraction ) \ or value is None: imgui.bullet_text( f"{key}: {value}" ) elif isinstance( value, list ): if imgui.tree_node( f"{ key }: { value.__class__.__name__ }({ len( value ) } items)###{ id( value ) }", imgui.TREE_NODE_DEFAULT_OPEN ): i = 0; for obj in value: self.render_inspector_value( str( i ), obj ); i += 1 imgui.tree_pop() else: self.render_inspector( value, key )
def show_inputs_popup(iggraph): show_result = False if imgui.begin_popup_modal("User Input")[0]: input_nodes = iggraph.get_input_nodes() for input_node in input_nodes: if imgui.tree_node(input_node.inputs["parameter name"].text): default_value = input_node.inputs["default value"] display_parameter(default_value,True) imgui.tree_pop() imgui.separator() if imgui.button("run workflow"): imgui.close_current_popup() # iggraph.reset() iggraph.run() show_result = True imgui.same_line() if imgui.button("cancel"): iggraph.reset() iggraph.set_state(iggraph.STATE_IDLE) imgui.close_current_popup() imgui.end_popup() return show_result
def displayInterface(self): imgui.begin_child("left_bottom", width=606, height=370) imgui.text("Watch Paths") imgui.begin_child("left_bottom", width=606, height=310, border=True) for path in list(self.watchInformation.keys()): imgui.push_text_wrap_position() imgui.text(path) imgui.same_line() if (imgui.button("- Remove Path")): del self.watchInformation[path] self.saveWatchInformation() imgui.end_child() imgui.text("Add new path:") addNewPathInputChanged, self.addingPathText = imgui.input_text( "##Path input", self.addingPathText, 2048) imgui.same_line() if (imgui.button("+ Add Path")): self.handleNewPathAdding() imgui.end_child() imgui.same_line() imgui.begin_child("file_dir_alerts") imgui.text("File/Directory Change Alerts") imgui.begin_child("file_dir_alerts_logger", border=True) for alert in self.alertsData: data = self.alertsData[alert] if (imgui.tree_node(data["timestamp"] + " " + data["path"])): imgui.indent() imgui.push_text_wrap_position() imgui.text("Change Path: " + data["path"]) if (os.path.isfile(data["path"])): if (imgui.tree_node("Last Content")): imgui.push_text_wrap_position() imgui.text(data["last-content"]) imgui.tree_pop() if (imgui.tree_node("New Content")): imgui.push_text_wrap_position() imgui.text(data["new-content"]) imgui.tree_pop() if (os.path.isdir(data["path"])): if (imgui.tree_node("Last Content")): if (imgui.tree_node( "Files (" + str(len(data["last-content"]["files"])) + ")")): for file in data["last-content"]["files"]: imgui.push_text_wrap_position() imgui.text(file) imgui.tree_pop() if (imgui.tree_node( "Directories (" + str(len(data["last-content"]["directories"])) + ")")): for file in data["last-content"]["directories"]: imgui.push_text_wrap_position() imgui.text(file) imgui.tree_pop() imgui.tree_pop() if (imgui.tree_node("New Content")): if (imgui.tree_node( "Files (" + str(len(data["new-content"]["files"])) + ")")): for file in data["new-content"]["files"]: imgui.push_text_wrap_position() imgui.text(file) imgui.tree_pop() if (imgui.tree_node( "Directories (" + str(len(data["new-content"]["directories"])) + ")")): for file in data["new-content"]["directories"]: imgui.push_text_wrap_position() imgui.text(file) imgui.tree_pop() imgui.tree_pop() imgui.tree_pop() imgui.unindent() imgui.end_child() imgui.end_child()
clicked_animation_paused, animation_paused = imgui.checkbox( "Pause", animation_paused ) clicked_camera, camera.r = imgui.slider_float("Camera Radius", camera.r, 10, 1000.0) clicked_animation_time_multiplier, animation_time_multiplier = imgui.slider_float( "Sim Speed", animation_time_multiplier, 0.1, 10.0 ) if imgui.button("Restart"): animation_time = 0.0 clicked_enlarged_axises, enlarged_axis = imgui.checkbox( "Enlarged Axises", enlarged_axis ) if imgui.tree_node( "From World Space, Against Arrows, Read Bottom Up", imgui.TREE_NODE_DEFAULT_OPEN ): if imgui.tree_node("Paddle 1->World", imgui.TREE_NODE_DEFAULT_OPEN): imgui.text("f_paddle1_to_world(x) = ") imgui.text(" = (") imgui.same_line() if highlighted_button("T", 5, animation_time): animation_time = 5.0 imgui.same_line() imgui.text(" o ") imgui.same_line() if highlighted_button("R_z", 10, animation_time): animation_time = 10.0 imgui.same_line() imgui.text(" ) (x) ") if imgui.tree_node("Square->World", imgui.TREE_NODE_DEFAULT_OPEN):
def main(): global width_library global width_shematic global width_context global height_window global previous_key_callback global selected_link global selected_node global iggraph global node_library global debug_is_mouse_dragging global show_debug_window # states ------------------------- scrolling = imgui.Vec2(0, 0) iggraph = IGGraph(node_library) # iggraph.reset() node_hovered_in_scene = -1 parameter_link_start = None selected_parameter = None io_hovered = None io_anchors_width_not_hovered = 10 io_anchors_width_hovered = 15 right_splitter_is_active = False left_splitter_is_active = False image_width = 0 image_height = 0 image_texture = None # states ------------------------- imgui.create_context() window = impl_glfw_init() impl = GlfwRenderer(window) io = imgui.get_io() previous_key_callback = glfw.set_key_callback(window,key_event) init_textures() assign_parameter_colors(node_library) while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_new, selected_new = imgui.menu_item( "New", 'Cmd+N', False, True ) if clicked_new: iggraph = IGGraph(node_library) clicked_load, selected_load = imgui.menu_item( "Load", 'Cmd+L', False, True ) if clicked_load: root = tk.Tk() root.withdraw() filename = filedialog.askopenfilename() if filename : f=open(filename) iggraph.from_json(json.load(f)) f.close() clicked_save, selected_save = imgui.menu_item( "Save", 'Cmd+S', False, True ) if clicked_save: iggraph.reset() graph_json = iggraph.to_json() text2save = json.dumps(graph_json, indent=4, sort_keys=True) root = tk.Tk() root.withdraw() f = filedialog.asksaveasfile(mode='w', defaultextension=".json") if f is None: # asksaveasfile return `None` if dialog closed with "cancel". return f.write(text2save) f.close() clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True ) if clicked_quit: exit(0) imgui.end_menu() if imgui.begin_menu("Debug", True): show_debug_window_clicked, show_debug_window_selected = imgui.menu_item( "Show Debug window", 'Cmd+D', show_debug_window, True ) if show_debug_window_clicked: show_debug_window = not show_debug_window catch_exceptions_clicked, catch_exceptions_selected = imgui.menu_item( "Catch Exceptions", '', iggraph.catch_exceptions, True ) if catch_exceptions_clicked: iggraph.catch_exceptions = not iggraph.catch_exceptions imgui.separator() imgui.menu_item( "Examples", '', False, False ) show_example_mosaic_clicked, show_example_mosaic_selected = imgui.menu_item( "Mosaic", '', False, True ) if show_example_mosaic_clicked: example_mosaic(iggraph) imgui.end_menu() imgui.end_main_menu_bar() height_window = io.display_size.y - 18 # imgui.get_cursor_pos_y() imgui.push_style_var(imgui.STYLE_ITEM_SPACING, imgui.Vec2(0,0)) imgui.set_next_window_size(io.display_size.x, height_window) imgui.set_next_window_position(0, 18) imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0) imgui.begin("Splitter test", False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS) imgui.pop_style_var() imgui.pop_style_var() width_shematic = io.display_size.x - separator_width - width_context - separator_width - width_library # ============================================================================== # Library # ============================================================================== imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0) imgui.begin_child("Library", width_library, 0, True) for node_name in node_library.nodes: if imgui.button(node_name, width_library): iggraph.create_node(node_name) imgui.end_child() imgui.pop_style_var() imgui.same_line() imgui.button("left_splitter", separator_width, height_window - 20) left_splitter_is_active = imgui.is_item_active() if (left_splitter_is_active): width_library += io.mouse_delta.x scrolling = imgui.Vec2(scrolling.x - io.mouse_delta.x, scrolling.y) if (imgui.is_item_hovered()): imgui.set_mouse_cursor(imgui.MOUSE_CURSOR_RESIZE_EW) imgui.same_line() # ============================================================================== # Shematic # ============================================================================== imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0) imgui.begin_child("shematic", width_shematic, 0, True) if show_inputs_popup(iggraph): imgui.open_popup("Outputs") show_outputs_popup(iggraph) # create our child canvas if iggraph.get_state() == iggraph.STATE_IDLE: imgui.text("status: edit | ") elif iggraph.get_state() == iggraph.STATE_RUNNING: imgui.text("status: run | ") imgui.same_line() if iggraph.get_state() == iggraph.STATE_IDLE: if imgui.button("run"): #TODO if not running iggraph.set_state(iggraph.STATE_RUNNING) iggraph.prepare_to_run() imgui.open_popup("User Input") imgui.same_line() if imgui.button("run one step"): iggraph.set_state(iggraph.STATE_RUNNING) iggraph.prepare_to_run() iggraph.run_one_step() elif iggraph.get_state() == iggraph.STATE_RUNNING: if imgui.button("stop running"): iggraph.reset() iggraph.set_state(iggraph.STATE_IDLE) imgui.same_line() if imgui.button("run one step"): iggraph.set_state(iggraph.STATE_RUNNING) iggraph.run_one_step() # imgui.same_line(imgui.get_window_width() - 100) imgui.push_style_var(imgui.STYLE_FRAME_PADDING, imgui.Vec2(1, 1)) imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, imgui.Vec2(0, 0)) imgui.begin_child("scrolling_region", 0, 0, True, imgui.WINDOW_NO_SCROLLBAR | imgui.WINDOW_NO_MOVE) imgui.pop_style_var() imgui.pop_style_var() imgui.push_item_width(120.0) offset = add(imgui.get_cursor_screen_pos(), scrolling) draw_list = imgui.get_window_draw_list() # Display links draw_list.channels_split(2) draw_list.channels_set_current(0) for link in iggraph.links: draw_link_param_to_param(draw_list, offset, link.output_parameter, link.input_parameter, selected_link == link) # Display nodes parameter_link_end = None one_parameter_hovered = False one_node_moving_active = False for node in iggraph.nodes: imgui.push_id(str(node.id)) node_rect_min = add(offset, node.pos) draw_list.channels_set_current(1) # foreground old_any_active = imgui.is_any_item_active() #display node content first # todo test = add(node_rect_min, NODE_WINDOW_PADDING) imgui.set_cursor_screen_position(add(node_rect_min, NODE_WINDOW_PADDING)) imgui.begin_group() imgui.text("") imgui.text(node.name) imgui.text("") imgui.end_group() # save size node_widgets_active = False # (not old_any_active and imgui.is_any_item_active()) node.size = add( add( imgui.get_item_rect_size(), NODE_WINDOW_PADDING) , NODE_WINDOW_PADDING) node_rect_max = add(node.size, node_rect_min) #display node box draw_list.channels_set_current(0) # background imgui.set_cursor_screen_position(node_rect_min) imgui.invisible_button(str(node.id), node.size.x, node.size.y) if imgui.is_item_hovered(): node_hovered_in_scene = node.id else: node_hovered_in_scene = None node_moving_active = imgui.is_item_active() use_hovered_color = node_hovered_in_scene or selected_node == node draw_list.add_rect_filled(node_rect_min.x, node_rect_min.y, node_rect_max.x, node_rect_max.y, get_node_color(node, iggraph, use_hovered_color), 5) if node_hovered_in_scene and iggraph.is_error(node): imgui.begin_tooltip() imgui.text(iggraph.error_nodes[node]) imgui.end_tooltip() # input parameters for parameter_name in node.inputs: parameter = node.inputs[parameter_name] center = node.get_intput_slot_pos(parameter) center_with_offset = add(offset, center) if io_hovered == parameter: io_anchors_width = io_anchors_width_hovered else: io_anchors_width = io_anchors_width_not_hovered imgui.set_cursor_pos(imgui.Vec2(center.x-io_anchors_width/2, center.y-io_anchors_width/2)) imgui.push_id(str(str(node.id) + "input" + parameter.id)) if (imgui.invisible_button("input", io_anchors_width, io_anchors_width)): selected_parameter = parameter # imgui.is_item_hovered() does not work when dragging is_hovering = ((io.mouse_pos.x-offset.x>center.x-io_anchors_width/2) and (io.mouse_pos.x-offset.x<center.x+io_anchors_width/2) and (io.mouse_pos.y-offset.y>center.y-io_anchors_width/2) and (io.mouse_pos.y-offset.y<center.y+io_anchors_width/2)) if is_hovering: io_hovered = parameter one_parameter_hovered = True imgui.begin_tooltip() imgui.text(parameter_name) imgui.end_tooltip() if is_hovering and imgui.is_mouse_released(0): parameter_link_end = parameter imgui.pop_id() draw_list.add_circle_filled(center_with_offset.x, center_with_offset.y, io_anchors_width/2, get_parameter_color(parameter)) # output parameters for parameter_name in node.outputs: parameter = node.outputs[parameter_name] center = node.get_output_slot_pos(parameter) center_with_offset = add(offset, center) if io_hovered == parameter: io_anchors_width = io_anchors_width_hovered else: io_anchors_width = io_anchors_width_not_hovered imgui.set_cursor_pos(imgui.Vec2(center.x-io_anchors_width/2, center.y-io_anchors_width/2)) imgui.push_id(str(str(node.id) + "output" + parameter.id)) if (imgui.invisible_button("output", io_anchors_width, io_anchors_width)): selected_parameter = parameter is_hovering = ((io.mouse_pos.x-offset.x>center.x-io_anchors_width/2) and (io.mouse_pos.x-offset.x<center.x+io_anchors_width/2) and (io.mouse_pos.y-offset.y>center.y-io_anchors_width/2) and (io.mouse_pos.y-offset.y<center.y+io_anchors_width/2)) if is_hovering: io_hovered = parameter one_parameter_hovered = True imgui.begin_tooltip() imgui.text(parameter_name) imgui.end_tooltip() draw_list.add_circle_filled(center_with_offset.x, center_with_offset.y, io_anchors_width/2, get_parameter_color(parameter)) imgui.pop_id() # cannot use imgui.is_item_active, seems buggy with the scroll if is_hovering and imgui.is_mouse_down(0): parameter_link_start = parameter if node_widgets_active or node_moving_active: selected_node = node one_node_moving_active = True if node_moving_active and imgui.is_mouse_dragging(0) and node.id==selected_node.id: node.pos = add(node.pos, io.mouse_delta) debug_is_mouse_dragging = imgui.is_mouse_dragging(0) imgui.pop_id() draw_list.channels_merge() if not one_parameter_hovered: io_hovered = None # scrolling mouse_is_in_schematic = (io.mouse_pos.x > width_library) and\ (io.mouse_pos.x < (width_library + width_shematic)) and\ (io.mouse_pos.y < height_window) and\ (io.mouse_pos.y > 18) if not one_node_moving_active and\ not parameter_link_start and\ imgui.is_mouse_dragging(0) and\ mouse_is_in_schematic and\ not left_splitter_is_active and\ not right_splitter_is_active and\ imgui.is_window_focused(): scroll_offset = imgui.Vec2(io.mouse_delta.x, io.mouse_delta.y) scrolling = add(scrolling, scroll_offset) # link creation if parameter_link_start and parameter_link_end: iggraph.add_link(parameter_link_start, parameter_link_end) # creating link elif parameter_link_start and imgui.is_mouse_dragging(0): draw_link_param_to_point(draw_list, offset, parameter_link_start, io.mouse_pos.x, io.mouse_pos.y, True) # mouse release if imgui.is_mouse_released(0): parameter_link_start = None imgui.pop_item_width() imgui.end_child() # mouse click on the scene if imgui.is_mouse_clicked(0): mouse_pos = imgui.get_mouse_pos() local_mouse_pos = imgui.Vec2(mouse_pos.x - offset.x, mouse_pos.y - offset.y) selected_link = None for link in iggraph.links: start_node = link.output_parameter.owner start_pos = start_node.get_output_slot_pos(link.output_parameter) end_node = link.input_parameter.owner end_pos = end_node.get_intput_slot_pos(link.input_parameter) distance_mouse_start = math.sqrt(((local_mouse_pos.x-start_pos.x)**2) + ((local_mouse_pos.y-start_pos.y)**2)) distance_mouse_end = math.sqrt(((local_mouse_pos.x-end_pos.x)**2) + ((local_mouse_pos.y-end_pos.y)**2)) distance_start_end = math.sqrt(((start_pos.x-end_pos.x)**2) + ((start_pos.y-end_pos.y)**2)) if ((distance_mouse_start + distance_mouse_end) - distance_start_end) < 0.1: selected_link = link imgui.end_child() imgui.pop_style_var() imgui.same_line() imgui.button("right_splitter", separator_width, height_window - 20) right_splitter_is_active = imgui.is_item_active() if (right_splitter_is_active): width_context -= io.mouse_delta.x if (imgui.is_item_hovered()): imgui.set_mouse_cursor(imgui.MOUSE_CURSOR_RESIZE_EW) # ============================================================================== # Context # ============================================================================== imgui.same_line() imgui.push_style_var(imgui.STYLE_CHILD_BORDERSIZE, 0) imgui.begin_child("child3", width_context, 0, True); if selected_node: if selected_node.handle_dynamic_parameters(): if imgui.button("add parameter"): selected_node.add_dynamic_parameter() if imgui.tree_node("Inputs"): for parameter_name in selected_node.inputs: parameter = selected_node.inputs[parameter_name] if imgui.tree_node(parameter.id): display_parameter(parameter, True) imgui.tree_pop() imgui.tree_pop() if imgui.tree_node("Output"): for parameter_name in selected_node.outputs: parameter = selected_node.outputs[parameter_name] if imgui.tree_node(parameter.id): display_parameter(parameter, False) imgui.tree_pop() imgui.tree_pop() imgui.end_child() imgui.pop_style_var() # imgui.end() # ============================================================================== # Debug Window # ============================================================================== if show_debug_window: debug_window_expanded, show_debug_window = imgui.begin("Debug", True) if parameter_link_start: imgui.text("parameter_link_start: " + parameter_link_start.id) else: imgui.text("parameter_link_start: " + "None") if selected_parameter: imgui.text("selected_parameter: " + selected_parameter.id) else: imgui.text("selected_parameter: " + "None") imgui.text("is_mouse_dragging: " + str(debug_is_mouse_dragging)) imgui.text("mouse: (" + str(io.mouse_pos.x) + ", " + str(io.mouse_pos.y) + ")") imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) impl.shutdown() glfw.terminate()
imgui.new_frame() imgui.set_next_window_bg_alpha(0.05) imgui.begin("Time", True) clicked_animation_paused, animation_paused = imgui.checkbox( "Pause", animation_paused) clicked_camera, camera.r = imgui.slider_float("Camera Radius", camera.r, 10, 1000.0) clicked_animation_time_multiplier, animation_time_multiplier = imgui.slider_float( "Sim Speed", animation_time_multiplier, 0.1, 10.0) if imgui.button("Restart"): animation_time = 0.0 if imgui.tree_node("From World Space, Against Arrows, Read Bottom Up", imgui.TREE_NODE_DEFAULT_OPEN): if imgui.tree_node("Paddle 1->World", imgui.TREE_NODE_DEFAULT_OPEN): imgui.text("f_paddle1_to_world(x) = ") imgui.text(" = (") imgui.same_line() if highlighted_button("T", 5, animation_time): animation_time = 5.0 imgui.same_line() imgui.text(" o ") imgui.same_line() if highlighted_button("R", 10, animation_time): animation_time = 10.0 imgui.same_line() imgui.text(" ) (x) ") if imgui.tree_node("Square->World", imgui.TREE_NODE_DEFAULT_OPEN): imgui.text("f_square_to_world(x) = ")