def draw_logs(self): imgui.push_style_var(imgui.STYLE_WINDOW_PADDING, (6, 6)) cur_style = imgui.get_style() padding = cur_style.window_padding cur_cursor_pos = imgui.get_cursor_pos() imgui.set_cursor_pos( (cur_cursor_pos[0] + padding[0], cur_cursor_pos[1] + padding[1])) imgui.begin_child(self.ID_CHILD_CONSOLE, self.width - cur_style.window_padding[0] * 2, self.height - 80, True) search_text = self.config.get_string(EConfigKey.CONTENT_SEARCH_TEXT) win_width = imgui.get_window_width() for idx, record in enumerate(self.log_mgr.log_lst): if not self.config.is_has_log_level(record.level): continue if not utils.filter_search_text(search_text, record): continue old_color = None if record.level == logging.ERROR: old_color = utils.set_style_color(imgui.COLOR_TEXT, TextColor.ERed) elif record.level == logging.WARN or record.level == logging.WARNING: old_color = utils.set_style_color(imgui.COLOR_TEXT, TextColor.EYellow) elif record.level == logging.INFO: old_color = utils.set_style_color(imgui.COLOR_TEXT, TextColor.EWhite) imgui.push_id(str(idx)) ret = imgui.selectable_wrap(record.msg_with_level, idx == self.sel_idx, imgui.SELECTABLE_ALLOW_DOUBLE_CLICK, win_width * 0.98, 30) if ret[1]: self.sel_idx = idx if imgui.is_item_hovered() and imgui.is_mouse_double_clicked(0): self.detail_idx = idx imgui.open_popup("detail_log_%d" % self.detail_idx) self.draw_log_detail_info_panel(idx, record) if old_color: utils.set_style_color(imgui.COLOR_TEXT, old_color) imgui.pop_id() if imgui.is_mouse_dragging() or imgui.get_io().mouse_wheel: if imgui.get_scroll_y() >= imgui.get_scroll_max_y(): self.config.set_bool(EConfigKey.CONTENT_SCROLL_TO_BOTTOM, True) else: self.config.set_bool(EConfigKey.CONTENT_SCROLL_TO_BOTTOM, False) is_to_bottom = self.config.get_bool( EConfigKey.CONTENT_SCROLL_TO_BOTTOM, True) if is_to_bottom: imgui.set_scroll_y(imgui.get_scroll_max_y()) imgui.end_child() imgui.pop_style_var()
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()
def image_explorer_impl(im, title=""): # type: (ImageWithZoomInfo, str) -> None """ :return: imgui.Vec2 (mouse_location_original_image) or None (if not on image) """ if im.image.size == 0: imgui.text("empty image !") return imgui.Vec2(0, 0) zoomed_image = im.zoomed_image() if not im.hide_buttons: _display_zoom_or_pan_buttons(im) if title != "": imgui.same_line() imgui.text(" " + title) mouse_location = imgui_cv.image(zoomed_image, image_adjustments=im.image_adjustments) mouse_location_original_image = None viewport_center_original_image = im.viewport_center_original_image() if not im.hide_buttons and mouse_location is not None: mouse_drag_button = 0 is_mouse_dragging = imgui.is_mouse_dragging( mouse_drag_button) and imgui.is_item_hovered() drag_delta = imgui.get_mouse_drag_delta(mouse_drag_button) mouse_location_original_image = im.zoom_info.mouse_location_original_image( mouse_location) # Handle dragging / zoom or pan if not is_mouse_dragging: im.zoom_info.last_delta = imgui.Vec2(0, 0) if is_mouse_dragging: drag_delta_delta = imgui.Vec2( drag_delta.x - im.zoom_info.last_delta.x, drag_delta.y - im.zoom_info.last_delta.y) if im.zoom_info.zoom_or_pan == ZoomOrPan.Zoom: k = 1.03 if drag_delta.y < 0: zoom_ratio = k else: zoom_ratio = 1. / k im.zoom_info.affine_transform = np.dot( im.zoom_info.affine_transform, compute_zoom_matrix(mouse_location_original_image, zoom_ratio)) if im.zoom_info.zoom_or_pan == ZoomOrPan.Pan: im.zoom_info.affine_transform = np.dot( im.zoom_info.affine_transform, compute_pan_matrix(drag_delta_delta, im.zoom_info.affine_transform[0, 0])) im.zoom_info.last_delta = drag_delta # Zoom & Pan buttons def perform_zoom(ratio): im.zoom_info.affine_transform = np.dot( im.zoom_info.affine_transform, compute_zoom_matrix(viewport_center_original_image, ratio)) import functools perform_zoom_plus = functools.partial(perform_zoom, 1.25) perform_zoom_minus = functools.partial(perform_zoom, 1. / 1.25) def perform_scale_one(): im.zoom_info.set_scale_one(SizePixel.from_image(im.image), im.current_viewport_size()) def perform_full_view(): im.zoom_info.set_full_view(SizePixel.from_image(im.image), im.current_viewport_size()) def perform_force_viewport_size(): im.set_force_viewport_size(True) def perform_reset_viewport_size(): im.set_force_viewport_size(False) def perform_hide_buttons(): im.hide_buttons = True def perform_show_buttons(): im.hide_buttons = False def show_zoom_button(name, action, same_line=True): if imgui.small_button(imgui_ext.make_unique_label(name)): action() if same_line: imgui.same_line() if im.hide_buttons: show_zoom_button("+", perform_show_buttons, False) imgui.same_line() imgui.text(title) else: show_zoom_button("-", perform_hide_buttons) if not im.hide_buttons: show_zoom_button("zoom +", perform_zoom_plus) show_zoom_button("zoom -", perform_zoom_minus) if im.can_show_big_viewport(): show_zoom_button("scale 1", perform_scale_one) if im.is_not_full_view(): show_zoom_button("full view", perform_full_view) if not im.show_adjustments: if imgui.small_button(imgui_ext.make_unique_label("Adjust")): im.show_adjustments = True # adjustments if im.show_adjustments: imgui.new_line() imgui.text("Adjust:") imgui.same_line() imgui.push_item_width(80) # noinspection PyArgumentList changed, im.image_adjustments.factor = imgui.slider_float( imgui_ext.make_unique_label("k"), im.image_adjustments.factor, 0., 32., display_format="%.3f", power=5.) imgui.same_line() imgui.push_item_width(80) changed, im.image_adjustments.delta = imgui.slider_float( imgui_ext.make_unique_label("delta"), im.image_adjustments.delta, 0., 255., display_format="%.3f", power=5.) imgui.same_line() if not im.image_adjustments.is_none(): if imgui.small_button(imgui_ext.make_unique_label("reset")): im.image_adjustments = imgui_cv.ImageAdjustments() imgui.same_line() if imgui.small_button(imgui_ext.make_unique_label("hide adjust")): im.show_adjustments = False # Show image info image_type_msg = str(im.image.dtype) + str(im.image.shape) zoom = im.zoom_info.affine_transform[0, 0] import math if not _is_close(zoom, 1): zoom_msg = "Zoom:{0:.2f} ".format(zoom) else: zoom_msg = "" msg = zoom_msg + image_type_msg imgui.text(msg) if im.can_show_big_viewport(): imgui.same_line() if im.get_force_viewport_size(): show_zoom_button("reset viewport", perform_reset_viewport_size) else: show_zoom_button("fit viewport", perform_force_viewport_size) imgui.new_line() # Save button # imgui.same_line() imgui.push_item_width(60) changed, im.filename = imgui.input_text( imgui_ext.make_unique_label(""), im.filename, 1000) imgui.same_line() if imgui.small_button(imgui_ext.make_unique_label("save")): cv2.imwrite(im.filename, im.image) # Show pixel color info if mouse_location is not None: color = zoomed_image[int(round(mouse_location.y)), int(round(mouse_location.x))] mouse2 = np.array([[mouse_location.x], [mouse_location.y], [1.]]) pt_original = np.dot( numpy.linalg.inv(im.zoom_info.affine_transform), mouse2) position_msg = "({0},{1})".format(int(round(pt_original[0, 0])), int(round(pt_original[1, 0]))) imgui.text(position_msg + " " + color_msg(color)) else: imgui.text("") return mouse_location_original_image
def debug_window() -> IMGui[None]: with window(name="debug"): debug_window_draw_start_t_s = glfw.get_time() if debug_dict['crash'] is not None: origin = debug_dict['crash']['origin'] cause = debug_dict['crash']['cause'] exception = debug_dict['crash']['exception'] with window(name="Crash report"): im.text( 'Exception raised during `{}`. State rolled back'.format( origin)) im.text('Caused by:') im.text('\t' + repr(cause)) im.text('\n' + str(exception.__cause__) if exception. __cause__ is not None else '') for line in traceback.format_tb(exception.__traceback__): im.text(line) im.text("{}: {}".format( type(exception).__qualname__, str.join(', ', map(repr, exception.args)))) if im.button('close'): debug_dict['crash'] = None # print some general app state # im.text("actions: "+str(frame_actions)) im.text("mouse: " + str(get_mouse_position())) im.text("click: " + str(im.is_mouse_clicked(button=0))) im.text("down: " + str(im.is_mouse_down(button=0))) im.text( "cl+down: " + str(im.is_mouse_clicked(button=0) and im.is_mouse_down(button=0))) im.text("drag: " + str(im.is_mouse_dragging(button=0))) im.text("drag-d: " + str(im.get_mouse_drag_delta())) im.new_line() # print the avg durations of ranges set with `debug_log_time` show_avg_durations_of_recorded_ranges() # print the values in dicts logged with `debug_log_dict` for name, sequence in debug_dict['sequences'].items(): im.new_line() show_sequence(sequence, name=name) # print the values in dicts logged with `debug_log_dict` for name, dictionary in debug_dict['dicts'].items(): im.new_line() # d = order_dict_by_key(stringify_keys(flatten_dict(dictionary))) show_varied_dict(dictionary, name=name) # print all other values in debug (set with `debug_log`) im.new_line() show_varied_dict(debug_dict['values']) # print how long it took to draw the debug window (hehe) debug_window_draw_end_t_s = glfw.get_time() debug_window_draw_dur_ms = (debug_window_draw_end_t_s - debug_window_draw_start_t_s) * 1000 im.new_line() im.text( "drawing debug took {:4.1f} ms".format(debug_window_draw_dur_ms))
def render_editor(self): if imgui.button("optimize track"): self.start_optimization() imgui.same_line() _, ks = imgui.slider_float2("kcurv, kdist", self.kcurv, self.kdist, min_value=0, max_value=100.0, power=2) self.kcurv, self.kdist = ks _, self.lanewidth = imgui.slider_float("lane width", self.lanewidth, min_value=10, max_value=1000, power=1.5) # use a child region just to keep appearing/disappearing widgets at the # top from shifting stuff around imgui.begin_child("region", 0, 25, border=False) if (self.editmode == 'turn' and self.selectedpt is not None and self.selectedpt < len(self.pts['turn'])): i = self.selectedpt T = self.pts['turn'] _, T[i][2] = imgui.slider_float("turn %d radius" % (i + 1), T[i][2], min_value=-1000., max_value=1000., power=1.2) if self.editmode == 'home': _, self.homeangle = imgui.slider_float("home position angle", self.homeangle, -3.141, 3.141) imgui.end_child() w, h = imgui.get_window_size() h = self.mapim.shape[0] * w / self.mapim.shape[1] imgui.image_button(self.maptex, w, h, frame_padding=0) rectmin = imgui.get_item_rect_min() if imgui.is_item_clicked(0): mxy = imgui.get_mouse_pos() u = (mxy[0] - rectmin[0]) * self.mapim.shape[1] / w v = (mxy[1] - rectmin[1]) * self.mapim.shape[1] / w if imgui.is_mouse_double_clicked(0): self.add_point(u, v) else: self.select_point(u, v) if (imgui.is_item_hovered() and self.selectedpt is not None and imgui.is_mouse_dragging(0)): mxy = imgui.get_mouse_pos() u = (mxy[0] - rectmin[0]) * self.mapim.shape[1] / w v = (mxy[1] - rectmin[1]) * self.mapim.shape[1] / w self.move_point(u, v) scale = w / self.mapim.shape[1] dl = imgui.get_window_draw_list() self.render_ptlist(dl, self.pts['cone'], rectmin, scale, imgui.get_color_u32_rgba(1, 0.7, 0, 1), 4, self.editmode == 'cone') self.render_ptlist(dl, self.pts['turn'], rectmin, scale, imgui.get_color_u32_rgba(0, 0.3, 1, 1), 3, self.editmode == 'turn') self.render_ptlist(dl, self.pts['home'], rectmin, scale, imgui.get_color_u32_rgba(1, 1, 1, 1), 10, self.editmode == 'home') # render home position angle if len(self.pts['home']) > 0: h = self.pts['home'][0] S = 100 * np.sin(self.homeangle) C = 100 * np.cos(self.homeangle) dl.add_line(rectmin[0] + h[0] * scale, rectmin[1] + h[1] * scale, rectmin[0] + h[0] * scale + C, rectmin[1] + h[1] * scale - S, imgui.get_color_u32_rgba(1, 1, 1, 1)) self.render_turns(scale, rectmin) self.render_opttrack(scale, rectmin) if self.editmode == "cone": zoomtip(self.maptex, self.mapim.shape, 2)