def onUpdateUIOverlay(self, overlay): if imgui.collapsing_header("Settings"): if self.deviceFeatures.fillModeNonSolid: res, value = imgui.checkbox("Wireframe", self.wireframe) if res: overlay.updated = True self.wireframe = value self.buildCommandBuffers() if self.scene: res, value = imgui.checkbox("Attach Light", self.attachLight) if res: overlay.updated = True self.attachLight = value self.updateUniformBuffers() res, value = imgui.checkbox("Render single part", self.scene.renderSingleScenePart) if res: overlay.updated = True self.scene.renderSingleScenePart = value self.buildCommandBuffers() if self.scene.renderSingleScenePart: res, value = imgui.slider_int("Part to render", self.scene.scenePartIndex, 0, len(self.scene.meshes)) if res: overlay.updated = True self.scene.scenePartIndex = value self.buildCommandBuffers()
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 render_ui(self, time, rotation, translation, model): imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", '', False, True ) if clicked_quit: exit(1) imgui.end_menu() imgui.end_main_menu_bar() # imgui.show_test_window() imgui.begin("Custom window", True) value = self.slider_value changed, changed_value = imgui.slider_int( "slide ints", value, min_value=0, max_value=100, format="%d" ) if changed: self.slider_value = changed_value imgui.text(string("time: \n", time)) imgui.text(string("rotation: \n", rotation)) imgui.text(string("translation: \n", translation)) imgui.text(string("model = translation * rotation: \n", model)) imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data())
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 __init__(self, export, uniform, type_str: str): self.name = export["name"] self.min = export["min"] self.max = export["max"] self.power = export.get("power", 1.0) self.uniform = uniform self._draw = { "float": lambda: imgui.slider_float(self.name, self.uniform.value, self.min, self.max, "%.5f", self.power), "int": lambda: imgui.slider_int(self.name, self.uniform.value, self.min, self.max) }[type_str]
def draw_layers_window(self, width, height): imgui.set_next_window_size(width / 6, height / 4) imgui.set_next_window_position(width * 5 / 6, height * 2 / 4) imgui.begin("Layers", flags=default_flags) _, self.show_grid = imgui.checkbox("Show Grid", self.show_grid) _, self.show_points = imgui.checkbox("Show Places", self.show_points) _, self.show_lines = imgui.checkbox("Show Connections", self.show_lines) _, self.point_size = imgui.slider_int("Point Size", self.point_size, min_value=1, max_value=6) clicked, self.font_scale = imgui.slider_float("Font Scale", self.font_scale, 0.1, 0.9, "%.1f") if clicked: self.update_font_scale(self.font_scale) imgui.end()
def ParsePdfWidget(): ''' Use subprocess.Popen to run another script in background ''' global WDIR global ODIR global N_Group global AllFileStatus with imgui.font(largefont): imgui.text("Step 1: 設定工作目錄") imgui.bullet_text("設定好推甄資料的目錄。") if WDIR: imgui.separator() with imgui.font(largefont): imgui.text("Step 2: 檢查各別檔案") imgui.push_text_wrap_position(450) imgui.bullet_text("檔案命名有些錯誤,需要額外調整,如: 10054818.pdf 變為10054818_1.pdf") imgui.dummy(50, 0) imgui.same_line() if imgui.button("檢查檔案"): AllFileStatus = GF.CheckAllFiles(WDIR) imgui.push_text_wrap_position(450) imgui.text(AllFileStatus) imgui.separator() with imgui.font(largefont): imgui.text("Step 3: 執行程式-解析成績單內容") imgui.dummy(50, 0) imgui.same_line() if imgui.button("設定輸出目錄"): ODIR = TkFileDialog() if ODIR != "": imgui.text("輸出目錄位置:") imgui.push_text_wrap_position(250) imgui.text(ODIR) imgui.dummy(50, 0) imgui.same_line() if imgui.button("開始解析"): if WDIR == "": imgui.text("請設定檔案目錄") else: subprocess.run(["python","Subprocesses/ParseScoreSheet.py", WDIR, ODIR]) imgui.separator() if os.path.isfile('ManualFiles.log'): with imgui.font(largefont): imgui.text("Step 4: 執行程式-手動檔案分類") imgui.push_item_width(150) changed, N_Group = imgui.slider_int("幾群?", N_Group, min_value = 2, max_value = 20) imgui.text(f"分成{N_Group}群") if imgui.button("開始分群"): subprocess.run(["python","Subprocesses/GroupPdf.py", ODIR, str(N_Group)]) imgui.separator() if os.path.isdir(ODIR+"/Manual"): with imgui.font(largefont): imgui.text("Step 5: 手動處理") imgui.push_text_wrap_position(250) imgui.text(""" 恭喜~~~ 只剩下一咪咪手動的作業就能完工了!! 祝你有美好的一天!! 你現在可以關閉這個程式。 """)
def make_gui(self, width, height): imgui.begin("Lighting", True) imgui.collapsing_header("Shadows") imgui.indent() ch, val = imgui.checkbox("Render Shadows", self.scene.shadowsEnabled) if ch: self.scene.shadowsEnabled = val if not val: self.scene.shadows.clear() ch, val = imgui.slider_float("Shadow Strength", self.lightingStage.shadowStrength, 0, 1) if ch: self.lightingStage.shadowStrength = val ch, val = imgui.slider_int("Shadows Update Frequency", self.scene.shadows.exponent, 1, 10) if ch: self.scene.shadows.exponent = val ch, val = imgui.slider_float("Shadows range", self.scene.shadows.rng, 0.01, 20) if ch: self.scene.shadows.rng = val imgui.unindent() imgui.collapsing_header("Ambient Occlusion") imgui.indent() ch, val = imgui.slider_float("Occlusion Strength", self.lightingStage.occlusionStrength, 0, 1) if ch: self.lightingStage.occlusionStrength = val ch, val = imgui.slider_float( "SSAO blur radius", self.lightingStage.SSAOBlurAmount, 0, 0.01, display_format="%.4f", ) if ch: self.lightingStage.SSAOBlurAmount = val ch, val = imgui.slider_int("SSAO Samples", self.lightingStage.SSAOSamples, 0, 20) if ch: self.lightingStage.SSAOSamples = val ch, val = imgui.slider_float("SSAO Radius", self.lightingStage.SSAORadius, 0, 2) if ch: self.lightingStage.SSAORadius = val ch, val = imgui.slider_float("SSAO Min Cutoff", self.lightingStage.SSAOMin, 0, 1) if ch: self.lightingStage.SSAOMin = val ch, val = imgui.slider_float("SSAO Max Cutoff", self.lightingStage.SSAOMax, 0, 1) if ch: self.lightingStage.SSAOMax = val imgui.unindent() imgui.collapsing_header("Raytracing") imgui.indent() ch, val = imgui.slider_int("Raytrace Count", self.lightingStage.raytraceCount, 0, 100) if ch: self.lightingStage.raytraceCount = val ch, val = imgui.slider_float("Raytrace Strength", self.lightingStage.raytraceStrength, 0, 1) if ch: self.lightingStage.raytraceStrength = val imgui.unindent() imgui.collapsing_header("Other") imgui.indent() ch, val = imgui.slider_float("Ambient light strength", self.lightingStage.ambientStrength, 0, 1) if ch: self.lightingStage.ambientStrength = val ch, val = imgui.slider_float("Sun Intesnity", self.lightingStage.sunIntensity, 0, 1) if ch: self.lightingStage.sunIntensity = val ch, val = imgui.slider_float("Specularity", self.lightingStage.specularity, 1, 10000, power=10) if ch: self.lightingStage.specularity = val imgui.unindent() imgui.end()
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 run(self): # Loop until the user closes the window while not glfw.window_should_close(self.window): # Poll for and process events glfw.poll_events() # build gui. self.impl.process_inputs() w, h = glfw.get_window_size(self.window) glViewport(0, 0, w, h) imgui.new_frame() timeline_height = 35 imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0) imgui.push_style_var(imgui.STYLE_FRAME_ROUNDING, 0) imgui.set_next_window_position(0, h - timeline_height - 10) imgui.set_next_window_size(w, timeline_height) imgui.begin( "Timeline", False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_SCROLLBAR) imgui.columns(1) imgui.same_line(0, 0) imgui.push_item_width(-50) changed, value = imgui.slider_int("", self.sliderValue, 0, self.num_scans - 1) if changed: self.sliderValue = value if self.sliderValue != self.currentTimestep: self.currentTimestep = self.sliderValue imgui.push_style_var(imgui.STYLE_FRAME_ROUNDING, 3) play_delay = 1 refresh_rate = 0.05 current_time = time.time() imgui.same_line(spacing=5) changed = imgui.button("<", 20) if self.currentTimestep > 0: # just a click if changed: self.currentTimestep = self.sliderValue = self.currentTimestep - 1 self.lastUpdate = current_time # button pressed. if imgui.is_item_active() and not self.button_backward_hold: self.hold_start = current_time self.button_backward_hold = True if not imgui.is_item_active() and self.button_backward_hold: self.button_backward_hold = False # start playback when button pressed long enough if self.button_backward_hold and ( (current_time - self.hold_start) > play_delay): if (current_time - self.lastUpdate) > refresh_rate: self.currentTimestep = self.sliderValue = self.currentTimestep - 1 self.lastUpdate = current_time imgui.same_line(spacing=2) changed = imgui.button(">", 20) if self.currentTimestep < self.num_scans - 1: # just a click if changed: self.currentTimestep = self.sliderValue = self.currentTimestep + 1 self.lastUpdate = current_time # button pressed. if imgui.is_item_active() and not self.button_forward_hold: self.hold_start = current_time self.button_forward_hold = True if not imgui.is_item_active() and self.button_forward_hold: self.button_forward_hold = False # start playback when button pressed long enough if self.button_forward_hold and ( (current_time - self.hold_start) > play_delay): if (current_time - self.lastUpdate) > refresh_rate: self.currentTimestep = self.sliderValue = self.currentTimestep + 1 self.lastUpdate = current_time imgui.pop_style_var(3) imgui.end() imgui.set_next_window_position(20, 20, imgui.FIRST_USE_EVER) imgui.set_next_window_size(200, 150, imgui.FIRST_USE_EVER) imgui.begin("Show Data") if len(self.subdirs) > 1: for i, subdir in enumerate(self.subdirs): changed, value = imgui.checkbox(subdir, self.current_subdir == i) if i < len(self.subdirs) - 1: imgui.same_line() if changed and value: self.current_subdir = i subdir = self.subdirs[self.current_subdir] data_available = "input" in self.availableData[subdir] if data_available: imgui.push_style_var(imgui.STYLE_ALPHA, 1.0) else: imgui.push_style_var(imgui.STYLE_ALPHA, 0.3) changed, value = imgui.checkbox("input", self.showInput) if changed and value and data_available: self.showInput = True self.showLabels = False imgui.pop_style_var() data_available = "labels" in self.availableData[subdir] if data_available: imgui.push_style_var(imgui.STYLE_ALPHA, 1.0) else: imgui.push_style_var(imgui.STYLE_ALPHA, 0.3) changed, value = imgui.checkbox("labels", self.showLabels) if changed and value and data_available: self.showInput = False self.showLabels = True imgui.pop_style_var() data_available = "invalid" in self.availableData[subdir] if data_available: imgui.push_style_var(imgui.STYLE_ALPHA, 1.0) else: imgui.push_style_var(imgui.STYLE_ALPHA, 0.3) changed, value = imgui.checkbox("invalid", self.showInvalid) if changed and data_available: self.showInvalid = value imgui.pop_style_var() data_available = "occluded" in self.availableData[subdir] if data_available: imgui.push_style_var(imgui.STYLE_ALPHA, 1.0) else: imgui.push_style_var(imgui.STYLE_ALPHA, 0.3) changed, value = imgui.checkbox("occluded", self.showOccluded) if changed and data_available: self.showOccluded = value imgui.pop_style_var() imgui.end() # imgui.show_demo_window() showData = [] if self.showInput: showData.append("input") if self.showOccluded: showData.append("occluded") if self.showInvalid: showData.append("invalid") mvp = self.projection_ @ self.cam.matrix @ self.conversion_ glClearColor(1.0, 1.0, 1.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glBindVertexArray(self.vao) self.program.bind() self.program["mvp"] = mvp.transpose() self.program["view_mat"] = ( self.cam.matrix @ self.conversion_).transpose() self.program["lightPos"] = glow.vec3(10, 10, 10) self.program["voxel_scale"] = 0.8 self.program["voxel_alpha"] = 1.0 self.program["use_label_colors"] = True self.label_colors.bind(0) if self.showLabels: self.setCurrentBufferData("labels", self.currentTimestep) glDrawArraysInstanced(GL_TRIANGLES, 0, 36, self.num_instances) self.program["use_label_colors"] = False self.program["voxel_color"] = glow.vec3(0.3, 0.3, 0.3) self.program["voxel_alpha"] = 0.5 for data_name in showData: self.program["voxel_scale"] = 0.5 if data_name == "input": self.program["voxel_scale"] = 0.8 self.setCurrentBufferData(data_name, self.currentTimestep) glDrawArraysInstanced(GL_TRIANGLES, 0, 36, self.num_instances) self.program.release() self.label_colors.release(0) glBindVertexArray(self.vao_no_points) self.prgDrawPose.bind() self.prgDrawPose["mvp"] = mvp.transpose() self.prgDrawPose["pose"] = np.identity(4, dtype=np.float32) self.prgDrawPose["size"] = 1.0 glDrawArrays(GL_POINTS, 0, 1) self.prgDrawPose.release() glBindVertexArray(0) # draw gui ontop. imgui.render() self.impl.render(imgui.get_draw_data()) # Swap front and back buffers glfw.swap_buffers(self.window)
if curr_width != width or curr_height != height: width, height = curr_width, curr_height timestep_changed = False if not hide_panel: # Timeline timeline_height = 80 imgui.set_next_window_position(0, height - timeline_height) imgui.set_next_window_size(width, timeline_height) imgui.set_next_window_bg_alpha(0.8) imgui.begin('timeline', False, imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE) n_frames = max([len(t) for t in traces]) timestep_changed, timestep = imgui.slider_int('timestep', timestep, min_value=0, max_value=n_frames, format='%d') 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')
def display_parameter(parameter, editable): global slider_indexes if parameter.type == "List": if len(parameter.list) == 0: imgui.text("Empty list") else: if parameter.id not in slider_indexes: slider_indexes[parameter.id] = 0 changed, values = imgui.slider_int("index", slider_indexes[parameter.id], 0, len(parameter.list)-1) if changed: slider_indexes[parameter.id] = values display_parameter(parameter.list[slider_indexes[parameter.id]], editable) if parameter.type == "Image": if parameter.image: image_to_texture = get_gl_texture(parameter.image, parameter.timestamp) # imgui.image(image_texture, image_width, image_height) window_width = 256 # imgui.get_window_width() display_width = 0 display_height = 0 image_width = image_to_texture.gl_widh image_height = image_to_texture.gl_height if image_width >= image_height: display_width = window_width display_height = image_height / (image_width/float(display_width)) else: display_height = window_width display_width = image_width / (image_height/float(display_height)) imgui.image(image_to_texture.gl_texture, display_width, display_height) imgui.text("width: " + str(parameter.image.width)) imgui.text("height: " + str(parameter.image.height)) else: imgui.text("No image available - run workflow or connect an image source") elif parameter.type == "Rectangle": if editable: changed, value = imgui.input_float("Left", parameter.left) if changed: parameter.left = value changed, value = imgui.input_float("Top", parameter.top) if changed: parameter.top = value changed, value = imgui.input_float("Right", parameter.right) if changed: parameter.right = value changed, value = imgui.input_float("Bottom", parameter.bottom) if changed: parameter.left = value else: imgui.text("Left: " + str(parameter.left)) imgui.text("Top: " + str(parameter.top)) imgui.text("Right: " + str(parameter.right)) imgui.text("Bottom: " + str(parameter.bottom)) elif parameter.type == "Coordinates": if editable: changed, value = imgui.input_float("x", parameter.x) if changed: parameter.x = value changed, value = imgui.input_float("y", parameter.y) if changed: parameter.y = value else: imgui.text("x: " + str(parameter.x)) imgui.text("y: " + str(parameter.y)) elif parameter.type == "Integer": # to do change to "number" if editable: changed, value = imgui.input_int("Value", parameter.value) if changed: parameter.value = value else: imgui.text("Value: " + str(parameter.value)) elif parameter.type == "Color": changed, color = imgui.color_edit4(parameter.id, parameter.r, parameter.g, parameter.b, parameter.a) if editable and changed: parameter.r = color[0] parameter.g = color[1] parameter.b = color[2] parameter.a = color[3] elif parameter.type == "URL": changed, textval = imgui.input_text(parameter.id, parameter.url, 1024) if editable and changed: parameter.url = textval if editable: if imgui.button("browse..."): root = tk.Tk() root.withdraw() file_path = filedialog.askopenfilename() if file_path: parameter.url = file_path elif parameter.type == "Text": changed, textval = imgui.input_text(parameter.id, parameter.text, 1024) if editable and changed: parameter.text = textval
def render_palette(drawing: Drawing): global color_editor_open # Need a persistent way to keep track of the popup being closed... global current_color_page palette = drawing.palette fg = palette.foreground bg = palette.background fg_color = palette.foreground_color bg_color = palette.background_color imgui.begin_child("Palette", border=False, height=460) # Edit foreground color if imgui.color_button(f"Foreground (#{fg})", *as_float(fg_color), 0, 30, 30): io = imgui.get_io() w, h = io.display_size imgui.open_popup("Edit foreground color") imgui.set_next_window_position(w - 115 - 120, 200) color_editor_open = True if imgui.begin_popup("Edit foreground color", flags=(imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SCROLL_WITH_MOUSE)): done, cancelled, new_color = render_color_editor( palette.colors[fg], fg_color) if done and new_color != fg_color: drawing.change_colors(fg, new_color) palette.clear_overlay() elif cancelled: palette.clear_overlay() else: palette.set_overlay(fg, new_color) imgui.end_popup() elif color_editor_open: # The popup was closed by clicking outside, keeping the change (same as OK) drawing.change_colors(fg, fg_color) palette.clear_overlay() color_editor_open = False imgui.same_line() imgui.color_button(f"Background (#{bg})", *as_float(bg_color), 0, 30, 30) max_pages = len(palette.colors) // 64 - 1 imgui.push_item_width(100) _, current_color_page = imgui.slider_int("Page", current_color_page, min_value=0, max_value=max_pages) start_color = 64 * current_color_page imgui.begin_child("Colors", border=False) imgui.push_style_var(imgui.STYLE_ITEM_SPACING, (0, 0)) # Make layout tighter width = int(imgui.get_window_content_region_width()) // 20 imgui.push_style_color(imgui.COLOR_FRAME_BACKGROUND, 0, 0, 0) colors = palette.colors # Order the colors by column instead of by row (which is the order we draw them) for i, c in enumerate( chain.from_iterable( zip(range(0, 16), range(16, 32), range(32, 48), range(48, 64)))): color = colors[start_color + c] is_foreground = c == fg is_background = (c == bg) * 2 selection = is_foreground | is_background color = as_float(color) if color[3] == 0 or selection: x, y = imgui.get_cursor_screen_pos() if imgui.color_button(f"color {i}", *color[:3], 1, 0, 25, 25): # io = imgui.get_io() # if io.key_shift: # if "spread_start" in temp_vars: # temp_vars["spread_end"] = i # else: # temp_vars["spread_start"] = i # else: fg = c if i % width != width - 1: imgui.same_line() draw_list = imgui.get_window_draw_list() if color[3] == 0: # Mark transparent color draw_list.add_line(x + 1, y + 1, x + 24, y + 24, imgui.get_color_u32_rgba(0, 0, 0, 1), 1) draw_list.add_line(x + 1, y + 2, x + 23, y + 24, imgui.get_color_u32_rgba(1, 1, 1, 1), 1) if is_foreground: # Mark foregroupd color draw_list.add_rect_filled(x + 2, y + 2, x + 10, y + 10, imgui.get_color_u32_rgba(1, 1, 1, 1)) draw_list.add_rect(x + 2, y + 2, x + 10, y + 10, imgui.get_color_u32_rgba(0, 0, 0, 1)) if is_background: # Mark background color draw_list.add_rect_filled(x + 15, y + 2, x + 23, y + 10, imgui.get_color_u32_rgba(0, 0, 0, 1)) draw_list.add_rect(x + 15, y + 2, x + 23, y + 10, imgui.get_color_u32_rgba(1, 1, 1, 1)) if imgui.core.is_item_clicked(2): # Right button sets background bg = c # Drag and drop (currently does not accomplish anything though) if imgui.begin_drag_drop_source(): imgui.set_drag_drop_payload('start_index', c.to_bytes(1, sys.byteorder)) imgui.color_button(f"color {c}", *color[:3], 1, 0, 20, 20) imgui.end_drag_drop_source() if imgui.begin_drag_drop_target(): start_index = imgui.accept_drag_drop_payload('start_index') if start_index is not None: start_index = int.from_bytes(start_index, sys.byteorder) io = imgui.get_io() image_only = io.key_shift drawing.swap_colors(start_index, c, image_only=image_only) palette.clear_overlay() imgui.end_drag_drop_target() imgui.pop_style_color(1) imgui.pop_style_var(1) imgui.end_child() imgui.end_child() if imgui.is_item_hovered(): io = imgui.get_io() delta = int(io.mouse_wheel) current_color_page = min(max(current_color_page - delta, 0), max_pages) palette.foreground = fg palette.background = bg
def interface(): imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("File", True): clicked_quit, selected_quit = imgui.menu_item( "Quit", 'Cmd+Q', False, True) if clicked_quit: exit(1) imgui.end_menu() if imgui.begin_menu('Windows', True): clicked_fixtureC, selected_fixtureC = imgui.menu_item( 'Fixture Controls', shortcut=None) if clicked_fixtureC: if values.showFixtureControl: values.showFixtureControl = False else: values.showFixtureControl = True imgui.end_menu() imgui.end_main_menu_bar() if values.showFixtureControl: imgui.begin("Fixture Control", True) for r in patch.rooms.values(): expanded, visible = imgui.collapsing_header(r.name) if expanded: imgui.indent() for f in r.fixtureList: expanded, visible = imgui.collapsing_header(f.name) rgb = values.values[f.name] if expanded: imgui.columns(2, f.name) imgui.indent() imgui.text('Red') changed, value = imgui.slider_int( '##int%sred' % f.name, rgb[0], 0, 255) if changed: rgb[0] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.text('Green') changed, value = imgui.slider_int( '##int%sgreen' % f.name, rgb[1], 0, 255) if changed: rgb[1] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.text('Blue') changed, value = imgui.slider_int( '##int%sblue' % f.name, rgb[2], 0, 255) if changed: rgb[2] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.next_column() imgui.color_button('Color Sample', rgb[0] / 255, rgb[1] / 255, rgb[2] / 255, width=100, height=100) imgui.columns(1) imgui.unindent() imgui.unindent() imgui.same_line(spacing=50) imgui.end()
imgui.same_line() _, _culling_enabled = imgui.checkbox("Culling", _culling_enabled) imgui.same_line() if imgui.button("Add"): for seq in range(_particle_nb): _handle = _particle.add(effect_list[effect_current], loop=_loop_enabled) _particle.set_dynamic_input(_handle, _dynamic) _particle.set_location(_handle, random.uniform(-10.0, 10.0), random.uniform(-10.0, 10.0), _position[2]) _particle.set_scale(_handle, _scale[0], _scale[1], _scale[2]) if _benchmark_enabled is True: _, _particle_nb = imgui.slider_int("Number", _particle_nb, min_value=1, max_value=500, format="%d") changed, _position = imgui.slider_float3("Position", *_position, min_value=-10.0, max_value=10.0, format="%.0f", power=1) if changed is True: _particle.set_location(_handle, _position[0], _position[1], _position[2]) changed, _rotation = imgui.slider_float3("Rotation", *_rotation,
def main(): # initialize glfw if not glfw.init(): return glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) #creating the window window = glfw.create_window(800, 600, "My OpenGL window", None, None) if not window: glfw.terminate() return glfw.make_context_current(window) imgui.create_context() impl = GlfwRenderer(window) # positions colors texture coords quad = [ -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, -1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0 ] quad = np.array(quad, dtype=np.float32) indices = [0, 1, 2, 2, 3, 0] indices = np.array(indices, dtype=np.uint32) vertex_shader = """ #version 430 in layout(location = 0) vec3 position; in layout(location = 1) vec3 color; in layout(location = 2) vec2 inTexCoords; out vec3 newColor; out vec2 outTexCoords; void main() { gl_Position = vec4(position, 1.0f); newColor = color; outTexCoords = vec2(inTexCoords.x, 1.0f - inTexCoords.y); } """ fragment_shader = """ #version 430 in vec3 newColor; in vec2 outTexCoords; out vec4 outColor; uniform sampler2DArray samplerTex; uniform int sliderR; uniform int sliderG; uniform int sliderB; void main() { // newcolor just shows you how to pass values through the shader stages //outColor = vec4(newColor, 1.0f); float texDataR = texture(samplerTex, vec3(outTexCoords, float(sliderR))).x; float texDataG = texture(samplerTex, vec3(outTexCoords, float(sliderG))).x; float texDataB = texture(samplerTex, vec3(outTexCoords, float(sliderB))).x; outColor = vec4(texDataR * 100.0f, texDataG * 100.0f, texDataB * 100.0f, 1.0f); } """ shader = OpenGL.GL.shaders.compileProgram( OpenGL.GL.shaders.compileShader(vertex_shader, GL_VERTEX_SHADER), OpenGL.GL.shaders.compileShader(fragment_shader, GL_FRAGMENT_SHADER)) compute_shader = """ #version 430 layout(local_size_x = 32, local_size_y = 32) in; layout(binding= 0, r8ui) uniform uimage2DArray imageArray; layout(binding= 1, rgba32f) uniform image2D outputImage; void main() { uvec2 pix = gl_GlobalInvocationID.xy; ivec3 imSize = imageSize(imageArray); float sumPixel = 0.0f; if (pix.x < imSize.x && pix.y < imSize.y) { for (int z = 0; z < imSize.z; z++) { sumPixel += float(imageLoad(imageArray, ivec3(pix, z)).z); } } imageStore(outputImage, ivec2(pix), vec4(sumPixel, sumPixel / float(imSize.z), 69.0f, 8008135.0f)); } """ computeShader = OpenGL.GL.shaders.compileProgram( OpenGL.GL.shaders.compileShader(compute_shader, GL_COMPUTE_SHADER)) VAO = glGenVertexArrays(1) glBindVertexArray(VAO) VBO = glGenBuffers(1) glBindBuffer(GL_ARRAY_BUFFER, VBO) glBufferData(GL_ARRAY_BUFFER, 128, quad, GL_STATIC_DRAW) EBO = glGenBuffers(1) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO) glBufferData(GL_ELEMENT_ARRAY_BUFFER, 24, indices, GL_STATIC_DRAW) glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 32, ctypes.c_void_p(0)) glEnableVertexAttribArray(0) glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 32, ctypes.c_void_p(12)) glEnableVertexAttribArray(1) glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 32, ctypes.c_void_p(24)) glEnableVertexAttribArray(2) sliderR_loc = glGetUniformLocation(shader, "sliderR") sliderG_loc = glGetUniformLocation(shader, "sliderG") sliderB_loc = glGetUniformLocation(shader, "sliderB") images, lambdas = get_data("D:\data\hysperspectral\snapscan_data_png") #image = Image.open("./maybotDance.JPG") #for index, image in enumerate(images): numberOfImages = len(images) #print(numberOfImages) height, width = images[0].shape[0:2] # GENERATE TEXTURES hyperspectralDataTexture = createTexture(GL_TEXTURE_2D_ARRAY, GL_R8, 1, width, height, numberOfImages, GL_LINEAR, GL_LINEAR) outputTexture = createTexture(GL_TEXTURE_2D, GL_RGBA32F, 1, width, height, 1, GL_LINEAR, GL_LINEAR) #img_data = numpy.array(list(image.getdata()), numpy.uint8) #print(width) #print(height) #print(images[0]) # Allocate the immutable GPU memory storage -more efficient than mutable memory if you are not going to change image size after creation glPixelStorei(GL_UNPACK_ALIGNMENT, 1) glPixelStorei(GL_UNPACK_ROW_LENGTH, width) # fill each image in the array with the same img_data for i in range(numberOfImages): #cv2.imshow('image', images[i]*1000.0) #cv2.waitKey(0) #print(images[i].strides) img_data = np.array(images[i].data, np.uint8) #print(img_data.shape[0:2]) glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, i, width, height, 1, GL_RED, GL_UNSIGNED_BYTE, img_data) #cv2.destroyAllWindows() #print("reached here") glClearColor(0.2, 0.3, 0.2, 1.0) sliderRValue = 0 sliderGValue = 0 sliderBValue = 0 while not glfw.window_should_close(window): glfw.poll_events() impl.process_inputs() imgui.new_frame() glUseProgram(shader) w, h = glfw.get_framebuffer_size(window) glViewport(0, 0, int(w / 2), h) glClear(GL_COLOR_BUFFER_BIT) glUniform1i(sliderR_loc, sliderRValue) glUniform1i(sliderG_loc, sliderGValue) glUniform1i(sliderB_loc, 50) #glPolygonMode(GL_FRONT_AND_BACK, GL_LINE ); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, None) glUniform1i(sliderB_loc, sliderBValue) glViewport(int(w / 2), 0, int(w / 2), h) glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, None) imgui.begin("My first imgui success!", True) changedR, sliderRValue = imgui.slider_int("sliceR", sliderRValue, min_value=0, max_value=numberOfImages) changedG, sliderGValue = imgui.slider_int("sliceG", sliderGValue, min_value=0, max_value=numberOfImages) changedB, sliderBValue = imgui.slider_int("sliceB", sliderBValue, min_value=0, max_value=numberOfImages) if imgui.button("do some compute"): do_some_compute(computeShader, hyperspectralDataTexture, outputTexture, width, height) if imgui.button("get memory back"): read_texture_memory(outputTexture, width, height) imgui.end() imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window) glfw.terminate()
def draw_scene_gui(self): imgui.begin("Scene", True) imgui.text('test:') changed0, self.solver_index = imgui.combo('solver', self.solver_index, self.solver_list) changed1, self.case_index = imgui.combo('case', self.case_index, self.case_list) if changed0 or changed1: self.load_scene = True new_scene = self.case_list[self.case_index] if 'box-case' in new_scene: self.build_mode_case(lambda: box_case(int(new_scene[-1]))) if new_scene == 'peg-in-hole-4': self.build_mode_case(lambda: peg_in_hole(4)) if new_scene == 'peg-in-hole-8': self.build_mode_case(lambda: peg_in_hole(8)) if 'box-box' in new_scene: self.build_mode_case(lambda: box_box_case(int(new_scene[-1]))) if new_scene == 'hand-football': self.build_mode_case(lambda: hand_football(False)) if new_scene == 'hand-football-fixed': self.build_mode_case(lambda: hand_football(True)) imgui.text('control:') changed, self.lattice_height = imgui.slider_float('height', self.lattice_height, 0, 500) changed, self.plot_gui = imgui.checkbox('plot', self.plot_gui) changed, self.max_steps = imgui.drag_float('max steps', self.max_steps, 1, 0, 200) changed, self.h = imgui.drag_float('h', self.h, 0.0001, 0, 0.05) imgui.text('render:') changed, self.alpha = imgui.slider_float('alpha', self.alpha, 0.0, 1.0) if changed or self.load_scene: self.renderer.opacity = self.alpha changed, self.peel_depth = imgui.slider_int( 'peel', self.peel_depth, 0, self.renderer.max_peel_depth) if changed or self.load_scene: self.renderer.peel_depth = self.peel_depth changed, new_color = imgui.color_edit4('object', *self.object_color) if changed or self.load_scene: [body.set_color(np.array(new_color)) for body in self.system.bodies] self.object_color = new_color changed, new_scale = imgui.drag_float3('frame', *self.frame_scale, 0.005, 0.0, 5.0) if changed or self.load_scene: self.frame.set_radius(new_scale[0]) self.frame.set_length(new_scale[1]) self.frame.set_alpha(new_scale[2]) self.frame_scale = new_scale changed, new_color = imgui.color_edit4('contact', *self.contact_color) if changed or self.load_scene: self.contact_spheres[0].set_color(np.array(new_color)) self.contact_arrows[0].set_color(np.array(new_color)) self.contact_color = new_color changed, new_color = imgui.color_edit4('separate', *self.separating_color) if changed or self.load_scene: self.contact_spheres[1].set_color(np.array(new_color)) self.contact_arrows[1].set_color(np.array(new_color)) self.separating_color = new_color changed, new_scale = imgui.drag_float('sphere r', self.contact_scale, 0.005, 0.0, 1.0) if changed or self.load_scene: for sphere in self.contact_spheres: sphere.set_radius(self.contact_scale) self.contact_scale = new_scale changed, new_scale = imgui.drag_float4('vel', *self.velocity_scale, 0.005, 0.0, 100.0) if changed or self.load_scene: for arrow in self.contact_arrows: arrow.set_shaft_length(new_scale[0]) arrow.set_shaft_radius(new_scale[1]) arrow.set_head_length(new_scale[2]) arrow.set_head_radius(new_scale[3]) self.velocity_scale = new_scale changed, new_color = imgui.color_edit4('obs', *self.obstacle_color) if changed or self.load_scene: [o.set_color(np.array(new_color)) for o in self.system.obstacles] self.obstacle_color = new_color changed, new_pos = imgui.slider_float3('light', *self.light_pos, -10.0, 10.0) if changed or self.load_scene: self.light_pos = new_pos # changed, new_pos = imgui.slider_float3('cam', *self.cam_focus, -10.0, 10.0) # if changed or self.load_scene: # self.cam_focus = new_pos changed, self.show_grid = imgui.checkbox('grid', self.show_grid) changed, self.big_lattice = imgui.checkbox('big lattice', self.big_lattice) changed, self.show_contact_frames = imgui.checkbox('frames', self.show_contact_frames) changed, self.show_contacts = imgui.checkbox('contacts', self.show_contacts) changed, self.show_velocities = imgui.checkbox('velocities', self.show_velocities) self.load_scene = False imgui.end()
imgui.separator() imgui.push_id('sfxr') imgui.text('sfxr + 3d') imgui.same_line() if imgui.button("play"): sfxr_handle = igeSound.play(sfxr_preset, is_3d=True, position=position_3d, loop=True) imgui.same_line() if imgui.button("stop"): igeSound.stop(sfxr_handle) _, sfxr_preset = imgui.slider_int("preset", sfxr_preset, min_value=0, max_value=6, format="%d") position_changed, position_3d = imgui.slider_float3("position", *position_3d, min_value=0, max_value=500, format="%.1f", power=1.0) if position_changed is True: igeSound.set3dSourcePosition(sfxr_handle, position_3d) igeSound.set3dAttenuation(sfxr_handle, igeSound.EXPONENTIAL_DISTANCE, 0.25) imgui.pop_id() if imgui.button("Stop All"):
def drawTools(self): imgui.begin("Drawing Tools") if imgui.button("Reset", 207, 20): self.color = .0, .0, .0 self.drawMode = "" self.vrad = 0 self.hrad = 0 self.x_center = 400 self.y_center = 300 if imgui.button( "Circle", 100, 20 ): # imgui.core.button, https://github.com/ocornut/imgui/issues/2481 self.drawMode = "c" imgui.same_line(115) if imgui.button("Ellipse", 100, 20): self.drawMode = "e" imgui.new_line() if self.drawMode == "c": changed, self.vrad = imgui.input_int("Radius", self.vrad, 1, 100) # imgui.core.input_int changed, self.x_center = imgui.slider_int( "X-axis center", self.x_center, 0, 800) # imgui.core.slider_int, set max to window size changed, self.y_center = imgui.slider_int("Y-axis center", self.y_center, 0, 600) changed, self.color = imgui.color_edit3( "Set Color", *self.color) # asterisk used for tuple, I think... elif self.drawMode == "e": changed, self.vrad = imgui.input_int("Vertical Radius", self.vrad, 1, 100) # imgui.core.input_int # changed, self.vrad = imgui.slider_int("", self.vrad, 0, 1000) changed, self.hrad = imgui.input_int("Horizontal Radius", self.hrad, 1, 100) # changed, self.hrad = imgui.slider_int("Horizontal Radius", self.hrad, 0, 1000) changed, self.x_center = imgui.slider_int( "X-axis center", self.x_center, 0, 800) # imgui.core.slider_int, set max to window size changed, self.y_center = imgui.slider_int("Y-axis center", self.y_center, 0, 600) changed, self.color = imgui.color_edit3( "Set Color", *self.color) # asterisk used for tuple, I think... imgui.new_line imgui.begin_child("Current Settings", border=True) # imgui.core.begin_child imgui.text("Currently Drawing: ") # imgui.core.text if self.drawMode == "c": imgui.same_line(200), imgui.text_colored( "Circle", 0, 1, 0) # imgui.core.same_line, imgui.core.text_colored imgui.text("Radius:"), imgui.same_line(200), imgui.text_colored( str(self.vrad), 0, 1, 0) imgui.text("X Position:"), imgui.same_line( 200), imgui.text_colored(str(self.x_center), 0, 1, 0) imgui.text("Y Position:"), imgui.same_line( 200), imgui.text_colored(str(self.y_center), 0, 1, 0) elif self.drawMode == "e": imgui.same_line(200), imgui.text_colored("Ellipse", 0, 1, 0) imgui.text("V. Radius:"), imgui.same_line(200), imgui.text_colored( str(self.vrad), 0, 1, 0) imgui.text("H. Radius:"), imgui.same_line(200), imgui.text_colored( str(self.hrad), 0, 1, 0) imgui.text("X Position:"), imgui.same_line( 200), imgui.text_colored(str(self.x_center), 0, 1, 0) imgui.text("Y Position:"), imgui.same_line( 200), imgui.text_colored(str(self.y_center), 0, 1, 0) else: imgui.text("Nothing Selected") imgui.end_child() imgui.end()
def main(): pygame.init() display = (1000, 700) screen = pygame.display.set_mode(display, DOUBLEBUF | OPENGLBLIT) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = display pygame.display.set_caption('solar panels') gluPerspective(45, (display[0] / display[1]), 0.1, 50.0) glTranslatef(0, 0, -10) glRotatef(25, 2, 1, 0) # Coordinates x = 0 y = 0 z = 0 a = 0 # Keystates KLEFT = False KRIGHT = False KUP = False KDOWN = False KJ = False KL = False KA = False KD = False KW = False KS = False KI = False KK = False KG = False KH = False b = 0 d = 0 c = 1 while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() # KEYEVENT KEYDOWN HANDLING if event.type == pygame.KEYDOWN: # TRANSLATE if event.key == pygame.K_LEFT: KLEFT = True if event.key == pygame.K_RIGHT: KRIGHT = True if event.key == pygame.K_UP: KUP = True if event.key == pygame.K_DOWN: KDOWN = True if event.key == pygame.K_j: KJ = True if event.key == pygame.K_l: KL = True # ROTATE if event.key == pygame.K_a: KA = True if event.key == pygame.K_d: KD = True if event.key == pygame.K_w: KW = True if event.key == pygame.K_s: KS = True if event.key == pygame.K_i: KI = True if event.key == pygame.K_k: KK = True # Arm Control # Optional key usage to move arm model if event.key == pygame.K_g: KG = True if event.key == pygame.K_h: KH = True # KEYEVENT KEYUP HANDLING if event.type == pygame.KEYUP: # TRANSLATE if event.key == pygame.K_LEFT: KLEFT = False if event.key == pygame.K_RIGHT: KRIGHT = False if event.key == pygame.K_UP: KUP = False if event.key == pygame.K_DOWN: KDOWN = False if event.key == pygame.K_j: KJ = False if event.key == pygame.K_l: KL = False # ROTATE if event.key == pygame.K_a: KA = False if event.key == pygame.K_d: KD = False if event.key == pygame.K_w: KW = False if event.key == pygame.K_s: KS = False if event.key == pygame.K_i: KI = False if event.key == pygame.K_k: KK = False # Arm Angle # Optional key usage to move arm model if event.key == pygame.K_g: KG = False if event.key == pygame.K_h: KH = False # KEY PRESS ACTIONS # TRANSLATE if KH == True: glTranslatef(0, -1, 0) y += 1 if KG == True: glTranslatef(0, 1, 0) y -= 1 if KJ == True: glTranslatef(0, 0, -1) z += 1 if KL == True: glTranslatef(0, 0, 1) z -= 1 # ROTATE if KI == True: glRotate(5, 0, 1, 0) if KK == True: glRotate(5, 0, 0, 1) # Arm Angle # Optional key usage to move arm model if KRIGHT == True: a += 1 if KLEFT == True: a -= 1 if KUP == True: b += 1 if KDOWN == True: b -= 1 if KA == True: c += 1 if KD == True: c -= 1 if KW == True: d += 1 if KS == True: d -= 1 impl.process_event(event) imgui.new_frame() imgui.begin("Controle du Mirroir", True) imgui.text("Les Angles") c = imgui.slider_int("Axe des x", c, -180., 180.)[1] a = imgui.slider_int("Axe des y", a, -180., 180.)[1] changed, c = imgui.input_int('Type coefficient:', c) imgui.text('The Va;ue you entered is: %f' % c) visible = True expanded, visible = imgui.collapsing_header("Expand me!", visible) if expanded: imgui.text("Now you see me qnd perhaps you don't !") imgui.show_style_editor() imgui.end() imgui.render() gl.glClearColor(1, 1, 1, 1) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) impl.render(imgui.get_draw_data()) glPushMatrix() house() glPopMatrix() glPushMatrix() house() Mirroir(c, a) glPopMatrix() glPushMatrix() mirroir2(c, a) glRotate(180, 0, 1, 0) glPopMatrix() glPushMatrix() support(c, a) glPopMatrix() support2() pygame.display.flip()
def render(): global selected_index, selected_file, clones_for_file, padding imgui.set_next_window_position(10, 10) imgui.set_next_window_size(280, 375) imgui.begin( "Clone Classes", False, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_MENU_BAR) if imgui.begin_menu_bar(): if imgui.begin_menu('Sort'): clicked, _ = imgui.menu_item('identifier (ascending)') if clicked: clones.sort(key=lambda x: x.class_identifier) clicked, _ = imgui.menu_item('identifier (descending)') if clicked: clones.sort(key=lambda x: x.class_identifier, reverse=True) clicked, _ = imgui.menu_item('clones (ascending)') if clicked: clones.sort(key=lambda x: x.num_clones) clicked, _ = imgui.menu_item('clones (descending)') if clicked: clones.sort(key=lambda x: x.num_clones, reverse=True) clicked, _ = imgui.menu_item('files (ascending)') if clicked: clones.sort(key=lambda x: len(x.files)) clicked, _ = imgui.menu_item('files (descending)') if clicked: clones.sort(key=lambda x: len(x.files), reverse=True) imgui.end_menu() imgui.end_menu_bar() for index, clone_class in enumerate(clones): if selected_index is clone_class.class_identifier: label = "--> Class {0:03d} ({1} files, {2} clones)".format( clone_class.class_identifier, len(clone_class.files), clone_class.num_clones) else: label = "Class {0:03d} ({1} files, {2} clones)".format( clone_class.class_identifier, len(clone_class.files), clone_class.num_clones) if imgui.button(label, width=260): select_clone(clone_class.class_identifier) imgui.end() imgui.set_next_window_position(10, 390) imgui.set_next_window_size(280, 380) imgui.begin( "Files", False, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE) for index, file_name in enumerate(unique_file_name): if selected_file is file_name: label = "--> {}".format(os.path.basename(file_name)) else: label = "{}".format(os.path.basename(file_name)) if imgui.button(label, width=260): select_file(file_name) imgui.end() imgui.set_next_window_position(300, 10) imgui.set_next_window_size(890, 760) imgui.begin( "Details", False, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_HORIZONTAL_SCROLLING_BAR | imgui.WINDOW_MENU_BAR) if selected_file is not None and clones_for_file is not None: if imgui.begin_menu_bar(): if imgui.begin_menu('Actions'): clicked, _ = imgui.menu_item('Open in editor') if clicked: os.system("open \"{}\"".format(selected_file)) imgui.end_menu() imgui.end_menu_bar() file_buffer = file_buffers[selected_file] total_cloned_lines = 0 for _, file in clones_for_file: total_cloned_lines += file.num_cloned_lines imgui.begin_group() imgui.text("Information for this file") imgui.bullet_text("This file contains {} lines".format( file_buffer.max_line)) imgui.bullet_text("{} lines are cloned".format(total_cloned_lines)) imgui.bullet_text("That is {0:.2f}% of the total file".format( total_cloned_lines / file_buffer.max_line * 100)) imgui.end_group() imgui.same_line(300) imgui.push_item_width(200) imgui.begin_group() changed, value = imgui.slider_int("Lines of padding", padding, 0, 100) if changed: padding = value imgui.end_group() imgui.pop_item_width() imgui.spacing() imgui.spacing() imgui.spacing() imgui.spacing() for class_identifier, file in clones_for_file: expanded, visible = imgui.collapsing_header( "Clone class {0:03d}".format(class_identifier), None, imgui.TREE_NODE_DEFAULT_OPEN) if expanded: if imgui.button( "View all files for clone class {0:03d}".format( class_identifier)): select_clone(class_identifier) file_buffers[file.file_name].to_imgui(file, padding) if selected_index is not None: imgui.push_item_width(200) imgui.begin_group() changed, value = imgui.slider_int("Lines of padding", padding, 0, 100) if changed: padding = value imgui.end_group() imgui.pop_item_width() clone_class = None for clone in clones: if clone.class_identifier is selected_index: clone_class = clone for i, file in enumerate(clone_class.files): expanded, visible = imgui.collapsing_header( file.file_name, None, imgui.TREE_NODE_DEFAULT_OPEN) if expanded: if imgui.button("View all clones for \"{}\"".format( file.file_name)): select_file(file.file_name) file_buffers[file.file_name].to_imgui(file, padding) imgui.end()