def imguiUpdate(select): impl.process_inputs() imgui.new_frame() imgui.begin("Custom window", True) clicked, select = imgui.listbox("Samples", select, samples, 10) imgui.end() imgui.render() impl.render(imgui.get_draw_data(), False) return clicked, select
def draw(self): imgui.begin(self.title) clicked, self.current = imgui.listbox( "List", self.current, self.options ) imgui.text("selection: ") imgui.same_line() imgui.text(self.options[self.current]) imgui.end()
def str_listbox(label: str, current_option: str, options: Sequence[str]) -> IMGui[Tuple[bool, str]]: assert current_option in options, \ "Current_option {co} not in options ({opts})"\ .format(co=current_option, opts=options) assert is_sequence_unique(options), "Duplicate options: {}".format(options) cur_option_ix = options.index(current_option) changed, selected_ix = im.listbox(label, cur_option_ix, options) assert selected_ix in range(len(options)), \ "Index ({ix}) not in list: {opts}, len={lo}" \ .format(ix=selected_ix, opts=options, lo=len(options)) return (changed, options[selected_ix])
def render_ui(self, time): imgui.new_frame() imgui.begin("Description - Music", False) imgui.text("Pick a song to vizualize:") comboOut = imgui.listbox("", -1, [ "Sweet Dreams", "Children of the Omnissiah", "We all lift together" ]) imgui.text("FPS: %.2f" % self.fps) imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data()) if comboOut[0]: self.playSong(comboOut[1], time)
def listbox_dict(dict_string_value, current_key, title_top="", title_right="", height_in_items=20, item_width=None): keys = [key for key, _ in dict_string_value.items()] if current_key in keys: current_idx = keys.index(current_key) else: current_idx = -1 if item_width is not None: imgui.push_item_width(item_width) if title_top != "": imgui.text(title_top) changed, new_idx = imgui.listbox(title_right, current_idx, keys, height_in_items=height_in_items) if 0 <= new_idx < len(keys): new_key = keys[new_idx] else: new_key = "" return changed, new_key
def FileWindow(): ''' string wdir, path to project folder ''' global WDIR global LoadedFile global InstIndex global PersonIndex global ReloadPDF if not WDIR: imgui.dummy(50, 0) imgui.same_line() if imgui.button("選擇推甄資料目錄"): WDIR = TkFileDialog() else: imgui.text("現行推甄資料目錄:") imgui.push_text_wrap_position(150) imgui.text(WDIR) imgui.dummy(80,0) imgui.same_line() if imgui.button("變更"): WDIR = TkFileDialog() imgui.separator() if GF.CheckWDIR(WDIR): imgui.text('目前系所:') IList = os.listdir(WDIR) _, InstIndex = imgui.combo("", InstIndex, IList) imgui.text('學生編號:') PersonList = os.listdir(WDIR+'/'+IList[InstIndex]) _, PersonIndex = imgui.listbox("", PersonIndex, PersonList, 15) imgui.text(f"目前檔案: {PersonList[PersonIndex]}") if imgui.button("查看檔案"): os.startfile(f'{WDIR}/{IList[InstIndex]}/{PersonList[PersonIndex]}/{PersonList[PersonIndex]}.pdf') else: with imgui.font(largefont): imgui.text('目錄錯誤,請重選!')
def draw_snapshots_window(self, width, height): imgui.set_next_window_size(width / 6, height / 4) imgui.set_next_window_position(width * 5 / 6, height * 3 / 4) imgui.begin("Snapshots", flags=default_flags) clicked, self.selected_snapshot = imgui.listbox( "", self.selected_snapshot, self.snapshots) if imgui.button("Load Selected"): self.snapshot = Snapshot.load_full_snapshot( f"snapshots/{self.snapshots[self.selected_snapshot]}") self.simulator.upload_all(self.snapshot.buffers) self.simulator.time = self.snapshot.time self.upload_hazards(self.snapshot.buffers.place_hazards) self.upload_locations(self.snapshot.buffers.place_coords) self.upload_links(self.snapshot.buffers.people_place_ids) self.current_snapshot = self.selected_snapshot if imgui.button("Save"): self.simulator.download_all(self.snapshot.buffers) self.snapshot.time = self.simulator.time self.snapshot.save( f"snapshots/{self.snapshots[self.current_snapshot]}") if imgui.button("Save As..."): self.show_saveas = True imgui.end()
if imgui.button( 'Pause Animation' if play_animation else 'Play Animation'): play_animation = not play_animation imgui.end() # Control panel panel_width = max(width // 4, 300) imgui.set_next_window_position(width - panel_width, 0) imgui.set_next_window_size(panel_width, height - timeline_height) imgui.set_next_window_bg_alpha(0.8) imgui.begin('controlpanel', False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE) imgui.text('Control Panel') imgui.dummy(0, 10) imgui.text('active fg element') clicked, active_fg_element = imgui.listbox('', active_fg_element, fg_element_labels) if imgui.button('Export GIF'): export_gif() if imgui.button('Export MOV'): export_mov() clicked, spray_trail = imgui.checkbox('spray_trail', spray_trail) clicked, ricochet = imgui.checkbox('ricochet', ricochet) imgui.end() glClearColor(1.0, 1.0, 1.0, 1.0) glClear(GL_COLOR_BUFFER_BIT) glUseProgram(shader) try: glActiveTexture(GL_TEXTURE0) if (play_animation or timestep_changed) and not trace_active:
def input(self, description, current): index = self.choices.index(current) changed, index = imgui.listbox(description, index, self.names) return changed, self.choices[index]
def view_obj(filename, display_surf): #pygame.init() #pygame.display.set_caption('Your Model') viewport = (800,600) hx = viewport[0]/2 hy = viewport[1]/2 display_surf = pygame.display.set_mode(viewport, OPENGL | DOUBLEBUF) imgui.create_context() #Does not work with pygame 2.0+ impl = CustomRenderer() io = imgui.get_io() io.display_size = viewport #Toggle visibility of hat #displayHat = False #Toggle which hat to display (0 = None, 1 = Leather Hat, 2 = Santa Hat) current = 0 glLightfv(GL_LIGHT0, GL_POSITION, (-40, 200, 100, 0.0)) glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, 0.2, 0.2, 1.0)) glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1.0)) glEnable(GL_LIGHT0) glEnable(GL_LIGHTING) glEnable(GL_COLOR_MATERIAL) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) # most obj files expect to be smooth-shaded # LOAD OBJECT AFTER PYGAME INIT hats = [ OBJ_vbo('hats/new_leather_hat.OBJ'), #Leather Hat OBJ_vbo('hats/bigger_santahat.OBJ') #Santa Hat ] hat_vals = [ [[0,0,0], [0,0,0]], [[0,-90,0], [0,-76,96]], #(rx, ry, rz), (tx, ty, tz) [[-175,88, 0], [0, 50, 130]] ] #hat = OBJ_vbo('hats/new_leather_hat.OBJ') output = OBJ_vbo(filename) clock = pygame.time.Clock() glMatrixMode(GL_PROJECTION) glLoadIdentity() width, height = viewport gluPerspective(90.0, width/float(height), 1, 500.0) glEnable(GL_DEPTH_TEST) glMatrixMode(GL_MODELVIEW) glLoadIdentity() model_1 = glGetDoublev(GL_MODELVIEW_MATRIX) model_2 = model_1 #Head model rotational and translational values rx, ry, rz = (-175,88, 0) #Values found through trial and error tx, ty = (0,0) #Current hat rotational and translational values rx_h, ry_h, rz_h = (0,0,0) tx_h, ty_h, tz_h = (0,0,0) zpos = 265 rotate = move = False is_running = True while is_running: time_delta = clock.tick(60)/1000.0 for e in pygame.event.get(): if e.type == QUIT: pygame.quit() elif e.type == KEYDOWN: if e.key == K_ESCAPE: is_running = False elif e.type == MOUSEBUTTONDOWN: if e.button == 4: zpos = max(1, zpos-1) elif e.button == 5: zpos += 1 elif e.button == 1: rotate = True elif e.button == 3: move = True elif e.type == MOUSEBUTTONUP: if e.button == 1: rotate = False elif e.button == 3: move = False elif e.type == MOUSEMOTION: i, j = e.rel if not imgui.core.is_any_item_active(): if rotate: if rz + i <= 60 and rz + i >= -60: rz += i for k in range(1, len(hat_vals)): #rz_h += i hat_vals[k][0][2] += i if move: tx += i ty -= j rx += i rx -= i if e.type != 16: #If not video resize event impl.process_event(e) imgui.new_frame() imgui.begin("Options", True, flags=imgui.WINDOW_NO_RESIZE) imgui.set_window_size(200,200) clicked, current = imgui.listbox("Hats", current, ["None", "Leather Hat", "Santa Hat"]) rx_h, ry_h, rz_h = hat_vals[current][0] tx_h, ty_h, tz_h = hat_vals[current][1] imgui.end() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() model_1 = glGetDoublev(GL_MODELVIEW_MATRIX) # RENDER OBJECT glTranslate(tx/20, ty/20., - zpos) glRotate(ry, 1, 0, 0) glRotate(rx, 0, 1, 0) glRotate(rz, 0, 0, 1) #glScalef(0.1,0.1,0.1) glMultMatrixf(model_1) model_1 = glGetDoublev(GL_MODELVIEW_MATRIX) output.render() glPopMatrix() glPushMatrix() glLoadIdentity() model_2 = glGetDoublev(GL_MODELVIEW_MATRIX) glTranslate(tx/20, ty/20, -zpos) glRotate(ry_h, 1, 0, 0) glRotate(rx_h, 0, 1, 0) glRotate(rz_h, 0, 0, 1) glTranslate(0,ty_h,tz_h) #glRotate(hat_vals[current][0][1], 1, 0, 0) #glRotate(hat_vals[current][0][0], 0, 1, 0) #glRotate(hat_vals[current][0][2], 0, 0, 1) #glTranslate(0,hat_vals[current][1][1],hat_vals[current][1][2]) glMultMatrixf(model_2) model_2 = glGetDoublev(GL_MODELVIEW_MATRIX) if current != 0: hats[current - 1].render() glPopMatrix() imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip() display_surf = pygame.display.set_mode((640,480))