def render_timeline(self): imgui.begin("timeline") tstamp = self.frame['tstamp'] if imgui.button("<"): self.playing = False if self.i > 0: self.loadframe(self.i - 1) imgui.same_line() if self.playing: if (self.i == len(self.ts) - 1) or imgui.button("stop"): self.playing = False elif time.time() >= self.ts[self.i + 1] - self.t0: self.nextframe() elif imgui.button("play"): self.playing = True self.t0 = tstamp - time.time() imgui.same_line() if imgui.button(">"): self.playing = False self.nextframe() tsfrac = tstamp - int(tstamp) tstring = time.strftime( "%H:%M:%S.", time.localtime(tstamp)) + "%02d" % (tsfrac * 100) imgui.same_line() imgui.text(tstring) w = imgui.get_window_width() imgui.image(self.frametexid, w, 480 * w / 640) changed, i = imgui.slider_int("frame", self.i, 0, self.scanner.num_frames() - 1) if changed: self.playing = False self.loadframe(i) imgui.end()
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 render_timeline(self): imgui.begin("timeline") tstamp = self.frame['tstamp'] if imgui.button("<"): self.playing = False if self.i > 0: self.loadframe(self.i - 1) imgui.same_line() if self.playing: if (self.i == self.scanner.num_frames() - 1) or imgui.button("stop"): self.playing = False elif time.time() >= self.ts[self.i + 1] - self.t0: self.nextframe() elif imgui.button("play"): self.playing = True self.t0 = tstamp - time.time() imgui.same_line() if imgui.button(">"): self.playing = False self.nextframe() tsfrac = tstamp - int(tstamp) tstring = time.strftime( "%H:%M:%S.", time.localtime(tstamp)) + "%02d" % (tsfrac * 100) imgui.same_line() imgui.text(tstring) w = imgui.get_window_width() if self.show_frontview: imgui.image(self.fronttexid, w, w / 2) # 2:1 aspect for front view else: # 4:3 aspect imgui.image(self.frametexid, w, 3 * w / 4) if self.acts is not None: imgui.plot_lines("activations", self.acts) nCtrlAngles = (len(self.controlstate[self.i]) - 14) // 3 cc = self.controlstate[self.i][-nCtrlAngles:] imgui.plot_lines("control costs", np.clip(cc, 0, 100)) # make a histogram of expected cone locations if self.acts is not None: hist = np.zeros(len(self.acts) * 2, np.float32) np.add.at(hist, self.frame['c0'], 1) np.add.at(hist, self.frame['c1'], -1) hist = np.cumsum(hist) hist = hist[:len(self.acts)] + hist[-len(self.acts):] imgui.plot_lines("expected cone locations", hist) changed, i = imgui.slider_int("frame", self.i, 0, self.scanner.num_frames() - 1) if changed: self.playing = False self.loadframe(i) imgui.end()
def light_props(self): expanded, visible = imgui.collapsing_header( 'Lighting', self.GUI_STATE.lightprop.isvisible) style = imgui.get_style() if expanded: self.SHADER.scene_shader.attach() imgui.columns(2, 'GHOST') w = imgui.get_window_width() imgui.set_column_width(0, w*0.6) changed, self.GUI_STATE.lightprop.shininess = imgui.drag_float( 'Shininess', self.GUI_STATE.lightprop.shininess, self.props.steps, 0.001, 30.0) if changed: self.SHADER.scene_shader.putDataInUniformLocation( 'shininess', self.GUI_STATE.lightprop.shininess) imgui.next_column() imgui.set_column_width(1, w*0.4) changed, self.props.steps = imgui.input_float( 'Step', self.props.steps ) imgui.columns(1) changed0, self.GUI_STATE.lightprop.specDamp = imgui.drag_float( 'Specular Damp', self.GUI_STATE.lightprop.specDamp, self.props.steps, 0.001, 30.0) if changed0: self.SHADER.scene_shader.putDataInUniformLocation( 'specDamp', self.GUI_STATE.lightprop.specDamp ) changed1, self.GUI_STATE.lightprop.lightcolor = imgui.color_edit3( 'Light Color', *self.GUI_STATE.lightprop.lightcolor ) self.GUI_STATE.lightprop.lightcolor = Color3( *self.GUI_STATE.lightprop.lightcolor) if changed1: self.SHADER.scene_shader.putDataInUniformLocation( 'lightColor', self.GUI_STATE.lightprop.lightcolor ) if imgui.radio_button('BLINN', self.props.active): self.props.active = not self.props.active if self.props.active: self.SHADER.scene_shader.putDataInUniformLocation( 'blinn', 1, dtype='i' ) else: self.SHADER.scene_shader.putDataInUniformLocation( 'blinn', 0, dtype='i' )
def do_show_text(self, title, x, y, w, h, text, use_hsbar=False): """在指定的位置显示窗口并输出指定的文本""" # 子窗口标记:不可移动不可改变 flags = imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS # 设置子窗口位置 imgui.set_next_window_position(x, y) imgui.set_next_window_size(w, h) # 显示子窗口 if imgui.begin(title, False, flags)[1]: flags = 0 if use_hsbar: flags |= imgui.WINDOW_HORIZONTAL_SCROLLING_BAR if text: imgui.begin_child("region", imgui.get_window_width() - 16, h - 40, True, flags) # 开启子区域,设定文本自动换行范围 if not use_hsbar: imgui.push_text_wrap_pos(imgui.get_window_width() - 4) imgui.text(text) imgui.end_child() imgui.end()
def draw_imgui(scene: Scene): if Settings.GuiEnabled: # Menu Bar if imgui.begin_main_menu_bar(): if imgui.begin_menu("File"): imgui.menu_item("Open") if imgui.menu_item("Exit")[0]: glfw.terminate() imgui.end_menu() if imgui.begin_menu("View"): if imgui.menu_item("Grid", shortcut='G', selected=Settings.GridEnabled)[0]: Settings.GridEnabled = not Settings.GridEnabled if imgui.menu_item("GUI", shortcut='TAB', selected=Settings.GuiEnabled)[0]: Settings.GuiEnabled = not Settings.GuiEnabled if imgui.menu_item("Stats", shortcut='P', selected=Settings.StatsEnabled)[0]: Settings.StatsEnabled = not Settings.StatsEnabled imgui.end_menu() if Settings.StatsEnabled: imgui.same_line(imgui.get_window_width() - 150) imgui.text("FPS: " + "%.2f" % Global.fps + " " + "%.2f" % Global.frametime + "ms") imgui.end_main_menu_bar() # imgui.show_demo_window() # Scene imgui.begin("Scene") draw_node_item(scene.nodelist[0], scene) imgui.end() imgui.begin("Properties") imgui.text("Model") imgui.end() else: pass
def do_gui(self): imgui.new_frame() imgui.set_next_window_position(self.width, 0, pivot_x=1.0) imgui.begin("win", closable=False, flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE) changed, self.time_per_div_selected = imgui.combo( "TIME/DIV", self.time_per_div_selected, [str(option) for option in TIME_PER_DIV_OPTIONS]) if changed: self.time_per_div = TIME_PER_DIV_OPTIONS[ self.time_per_div_selected] changed, self.y_per_div_selected = imgui.combo( "Y/DIV", self.y_per_div_selected, [str(option) for option in Y_PER_DIV_OPTIONS]) if changed: self.y_per_div = Y_PER_DIV_OPTIONS[self.y_per_div_selected] imgui.text("Values") for addr in self.addresses: color_changed = False if addr in self.lines: # Change text color to indicate the color of plot r, g, b = self.line_colors[addr] imgui.push_style_color(imgui.COLOR_TEXT, r, g, b) color_changed = True changed, selected = imgui.selectable(addr, addr in self.lines) if changed and selected: self.lines[addr] = collections.deque(maxlen=MAX_POINTS) elif changed and not selected: del self.lines[addr] if color_changed: imgui.pop_style_color() self.gui_width = imgui.get_window_width() imgui.end() # imgui.render() in on_draw caused a "newFrame is not called" error on Windows, # therefore we invoke it here imgui.render()
def render_ui(self): imgui.new_frame() if imgui.begin("Settings"): imgui.push_item_width(imgui.get_window_width() * 0.33) changed = False c, SlimeConfig.move_speed = imgui.slider_float( "Movement speed", SlimeConfig.move_speed, 0.5, 50 ) changed = changed or c c, SlimeConfig.turn_speed = imgui.slider_float( "Turn speed", SlimeConfig.turn_speed, 0.5, 50, ) changed = changed or c c, SlimeConfig.evaporation_speed = imgui.slider_float( "Evaporation speed", SlimeConfig.evaporation_speed, 0.1, 10 ) changed = changed or c c, SlimeConfig.diffusion_speed = imgui.slider_float( "Diffusion speed", SlimeConfig.diffusion_speed, 0.1, 10, ) changed = changed or c c, SlimeConfig.sensor_angle = imgui.slider_float( "Sensor-angle", SlimeConfig.sensor_angle, 0, np.pi, ) changed = changed or c c, SlimeConfig.sensor_size = imgui.slider_int( "Sensor-size", SlimeConfig.sensor_size, 1, 3, ) changed = changed or c c, SlimeConfig.sensor_distance = imgui.slider_int( "Sensor distance", SlimeConfig.sensor_distance, 1, 10, ) changed = changed or c if changed: self.update_uniforms() imgui.pop_item_width() imgui.end() if imgui.begin("Appearance"): imgui.push_item_width(imgui.get_window_width() * 0.33) changed_c1, SlimeConfig.color1 = imgui.color_edit3( "Color1", *SlimeConfig.color1 ) changed_c2, SlimeConfig.color2 = imgui.color_edit3( "Color2", *SlimeConfig.color2 ) if changed_c1 or changed_c2: self.update_uniforms() imgui.end() if imgui.begin("Actions"): imgui.push_item_width(imgui.get_window_width() * 0.33) changed, SlimeConfig.N = imgui.input_int( "Number of Slimes", SlimeConfig.N, step=1024, step_fast=2**15 ) SlimeConfig.N = min(max(2048, SlimeConfig.N), 2**24) if imgui.button("Restart Slimes"): self.restart_sim() imgui.pop_item_width() imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data())
def runProgram(title, startWidth, startHeight, renderFrame, initResources=None, drawUi=None, update=None): global g_simpleShader global g_vertexArrayObject global g_vertexDataBuffer global g_mousePos global g_coordinateSystemModel global g_numMsaaSamples global g_currentMsaaSamples if not glfw.init(): sys.exit(1) window, impl = initGlFwAndResources(title, startWidth, startHeight, initResources) currentTime = glfw.get_time() prevMouseX, prevMouseY = glfw.get_cursor_pos(window) time = 0 textures = AllTextures() vao = AllVAOs() glDisable(GL_CULL_FACE) while not glfw.window_should_close(window): prevTime = currentTime currentTime = glfw.get_time() dt = currentTime - prevTime keyStateMap = {} for name, id in g_glfwKeymap.items(): keyStateMap[name] = glfw.get_key(window, id) == glfw.PRESS for name, id in g_glfwMouseMap.items(): keyStateMap[name] = glfw.get_mouse_button(window, id) == glfw.PRESS mouseX, mouseY = glfw.get_cursor_pos(window) g_mousePos = [mouseX, mouseY] # Udpate 'game logic' if update: imIo = imgui.get_io() mouseDelta = [mouseX - prevMouseX, mouseY - prevMouseY] if imIo.want_capture_mouse: mouseDelta = [0, 0] update(dt, keyStateMap, mouseDelta) prevMouseX, prevMouseY = mouseX, mouseY width, height = glfw.get_framebuffer_size(window) imgui.new_frame() imgui.set_next_window_position(5.0, 5.0) imgui.set_next_window_size(400.0, 620.0, imgui.FIRST_USE_EVER) imgui.begin("UI", 0) if drawUi: drawUi(width, height) drawWidth = width uiWidth = int(imgui.get_window_width()) if not uiWidth: uiWidth = int(0.3 * width) drawWidth -= uiWidth renderFrame(uiWidth, drawWidth, height, time, textures, vao) #drawCoordinateSystem() #mgui.show_test_window() imgui.end() imgui.render() # Swap front and back buffers glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() impl.process_inputs() time += 1 glfw.terminate()
def draw(imgui) -> None: global show_sendable_debug global show_demo global active_widgets if imgui.begin_main_menu_bar(): if imgui.begin_menu("Help"): clicked, _ = imgui.menu_item( "Hide Demo" if show_demo else "Show Demo") if clicked: show_demo = not show_demo imgui.end_menu() imgui.end_main_menu_bar() if show_demo: imgui.show_test_window() if imgui.begin('All Entries'): if imgui.begin_popup_context_window(): clicked, do_debug = imgui.checkbox('Show Chooser Debug Info', show_sendable_debug) if clicked: show_sendable_debug = do_debug imgui.end_popup() 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() entries = buildList( sorted(NetworkTables.getEntries('', 0), key=lambda e: e.getName())) table_tree(entries) imgui.end() to_close: List[str] = [] for key, widget in active_widgets.items(): expanded, opened = imgui.begin(entry_name(key), True) if not opened: to_close.append(key) if ((widget.tipe.is_entry() and widget.entry is None) or (not widget.tipe.is_entry() and widget.table is None)): imgui.text_colored('WARNING! Disconnected!', 1, 0, 0) imgui.end() continue if widget.tipe == EntryType.Boolean: assert widget.entry is not None if widget.show_indicator: imgui.push_item_width(-1) r, g, b = (0, 1, 0) if widget.entry.value else (1, 0, 0) imgui.color_button(key + '/indicator', r, g, b, width=imgui.get_window_width(), height=100) clicked, new_val = imgui.checkbox('on', widget.entry.value) if clicked: widget.entry.setValue(new_val) elif widget.tipe == EntryType.Double: assert widget.entry is not None val = str(widget.entry.getDouble(0)) changed, new_val = imgui.input_text('', val, 64, imgui.INPUT_TEXT_CHARS_DECIMAL) if changed: try: widget.entry.setDouble(float(new_val)) except ValueError: pass elif widget.tipe == EntryType.String: assert widget.entry is not None changed, new_val = imgui.input_text('', widget.entry.getString(''), 256) if changed: widget.entry.setString(new_val) elif widget.tipe == EntryType.Chooser: assert widget.table is not None values = widget.table.getStringArray('options', []) try: selected = values.index(widget.table.getString('active', '')) except ValueError: selected = 0 changed, current = imgui.combo('', selected, values) if changed: widget.table.putString('active', values[current]) else: try: assert widget.entry is not None imgui.text(str(widget.entry.value)) except AttributeError: imgui.text('Could not view contents.') if imgui.begin_popup_context_window(): if widget.tipe == EntryType.Boolean: clicked, new_val = imgui.checkbox('Show Indicator', widget.show_indicator) if clicked: widget.show_indicator = new_val imgui.end_popup() # imgui.button('Options') imgui.end() for key in to_close: active_widgets.pop(key)