def render_ui(self): global samples, observation_samples imgui.new_frame() imgui.begin("Options", True) if imgui.button("Random Scene"): random_scene() if imgui.button("Randomize Observations"): random_observations() _, samples = imgui.drag_int("Query SPP", samples, min_value=1, max_value=1024) _, observation_samples = imgui.drag_int("Observation SPP", observation_samples, min_value=1, max_value=1024) imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data())
def draw_gui(self): imgui.begin('Controls') imgui.text('Framerate: {:.2f}'.format(self.io.framerate)) imgui.text('Vertices: {}'.format(self.vao.vertices)) _, self.gui['animate'] = imgui.checkbox('Animate', self.gui['animate']) _, self.gui['u_unwrap'] = imgui.drag_float('Unwrap', self.gui['u_unwrap'], 0.01, 0, 1) _, self.gui['u_separation'] = imgui.drag_float( 'Separation', self.gui['u_separation'], 0.01, 0, 1) cam_changed, self.gui['isolate'] = imgui.drag_float( 'Isolate', self.gui['isolate'], 0.01, 0, 1) _, self.gui['piece'] = imgui.drag_int2('Piece', *self.gui['piece'], 0.1, 0, num_pieces - 1) _, self.gui['num_pieces'] = imgui.drag_int('Num pieces', self.gui['num_pieces'], 0.1, 0) _, self.gui['layers'] = imgui.drag_int('Layers', self.gui['layers'], 0.1, 0) if self.gui['animate']: self.gui['u_unwrap'] = (np.sin(self.time()) + 1) / 2 # for some reason imgui isn't enforcing these minimums self.gui['layers'] = max(self.gui['layers'], 0) self.gui['num_pieces'] = max(self.gui['num_pieces'], 0) if cam_changed: cam_pos = self.gui['isolate'] * np.array(self.gui['cam_final']) \ + (1.0 - self.gui['isolate']) * np.array(self.gui['cam_init']) # look at middle of piece x_coord = self.gui['isolate'] * ( (self.gui['piece'][0] + self.gui['num_pieces'] / 2) / num_pieces - 0.5) # avoid some weird perspective stuff z_coord = self.gui['isolate'] * -.3 cam_pos[0] = x_coord self.camera['look_at'] = (x_coord, 0, z_coord) # update camera self.move_camera(cam_pos) self.update_camera() self.prog['m_mvp'].write(self.camera['mat']) imgui.end()
def draw(self): imgui.begin("Example: drag int") changed, self.value = imgui.drag_int( "drag int", self.value, ) imgui.text("Changed: %s, Value: %s" % (changed, self.value)) imgui.end()
def draw(self): imgui.new_frame() imgui.set_next_window_position(16, 32, imgui.ONCE) imgui.set_next_window_size(512, 512, imgui.ONCE) imgui.begin("Example: drag int") changed, self.value = imgui.drag_int( "drag int", self.value, ) imgui.text("Changed: %s, Value: %s" % (changed, self.value)) imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def draw(self): #imgui.set_next_window_position(288, 32, imgui.ONCE) imgui.set_next_window_position(self.window.width - 256 - 16, 32, imgui.ONCE) imgui.set_next_window_size(256, 256, imgui.ONCE) imgui.begin("Ship") # Rotation imgui.image(self.texture.glo, *self.texture.size) changed, self.rotation = imgui.drag_float( "Rotation", self.rotation, ) self.sprite.angle = self.rotation # Scale changed, self.scale = imgui.drag_float("Scale", self.scale, .1) self.sprite.scale = self.scale # Alpha changed, self.alpha = imgui.drag_int("Alpha", self.alpha, 1, 0, 255) self.sprite.alpha = self.alpha # Color _, self.color_enabled = imgui.checkbox("Tint", self.color_enabled) if self.color_enabled: changed, self.color = imgui.color_edit3("Color", *self.color) self.sprite.color = (int(self.color[0] * 255), int(self.color[1] * 255), int(self.color[2] * 255)) else: self.sprite.color = 255, 255, 255 if imgui.button("Reset"): self.reset() imgui.end() self.sprite.draw()
def render_plugins_ui(window): "Draw UI windows for all plugins active for the current drawing." if not window.drawing: return drawing = window.drawing deactivated = set() for name, args in window.drawing.active_plugins.items(): plugin, sig = window.plugins[name] _, opened = imgui.begin(f"{ name } ##{ drawing.path or drawing.uuid }", True) if not opened: deactivated.add(name) imgui.columns(2) for param_name, param_sig in islice(sig.items(), 4, None): if param_sig.annotation == inspect._empty: continue imgui.text(param_name) imgui.next_column() default_value = args.get(param_name) if default_value is not None: value = default_value else: value = param_sig.default label = f"##{param_name}_val" if param_sig.annotation == int: changed, args[param_name] = imgui.drag_int(label, value) elif param_sig.annotation == float: changed, args[param_name] = imgui.drag_float(label, value) elif param_sig.annotation == str: changed, args[param_name] = imgui.input_text(label, value, 20) elif param_sig.annotation == bool: changed, args[param_name] = imgui.checkbox(label, value) imgui.next_column() imgui.columns(1) texture_and_size = getattr(plugin, "texture", None) if texture_and_size: texture, size = texture_and_size w, h = size ww, wh = imgui.get_window_size() scale = max(1, (ww - 10) // w) imgui.image(texture.name, w * scale, h * scale, border_color=(1, 1, 1, 1)) if hasattr(plugin, "ui"): result = plugin.ui(oldpaint, imgui, window.drawing, window.brush, **args) if result: args.update(result) last_run = getattr(plugin, "last_run", 0) period = getattr(plugin, "period", None) t = time() # TODO I've seen more readable if-statements in my days... if callable(plugin) and ((period and t > last_run + period) or (not period and imgui.button("Execute"))): plugin.last_run = t try: result = plugin(oldpaint, imgui, window.drawing, window.brush, **args) if result: args.update(result) except Exception: # We don't want crappy plugins to ruin everything # Still probably probably possible to crash opengl though... logger.error(f"Plugin {name}: {format_exc()}") imgui.button("Help") if imgui.begin_popup_context_item("Help", mouse_button=0): if plugin.__doc__: imgui.text(inspect.cleandoc(plugin.__doc__)) else: imgui.text("No documentation available.") imgui.end_popup() imgui.end() for name in deactivated: window.drawing.active_plugins.pop(name, None)
def draw(self): gui.new_frame() #gui.set_next_window_position(self.window.width - 256 - 16, 32, gui.ONCE) gui.set_next_window_size(512, 512, gui.ONCE) gui.begin("Framebuffer Example") # Rotation gui.image(self.texture.glo, *self.texture.size) changed, self.rotation = gui.drag_float( "Rotation", self.rotation, ) self.sprite.angle = self.rotation # Scale changed, self.scale = gui.drag_float( "Scale", self.scale, .1 ) self.sprite.scale = self.scale # Alpha changed, self.alpha = gui.drag_int( "Alpha", self.alpha, 1, 0, 255 ) self.sprite.alpha = self.alpha # Color _, self.color_enabled = gui.checkbox("Tint", self.color_enabled) if self.color_enabled: changed, self.color = gui.color_edit3("Color", *self.color) self.sprite.color = (int(self.color[0] * 255), int(self.color[1] * 255), int(self.color[2] * 255)) else: self.sprite.color = 255, 255, 255 if gui.button("Reset"): self.reset() fbtexture = self.offscreen.color_attachments[0] gui.image(fbtexture.glo, *FBSIZE) gui.end() self.offscreen.use() self.offscreen.clear((0, 0, 0, 0)) vp = arcade.get_viewport() arcade.set_viewport(0, FBSIZE[0], 0, FBSIZE[1]) prj = self.window.ctx.projection_2d self.window.ctx.projection_2d = (0, FBSIZE[0],FBSIZE[1],0) self.sprite.draw() arcade.draw_text("Simple line of text in 20 point", 0,0 , arcade.color.WHITE, 20) self.window.ctx.projection_2d = prj self.window.use() arcade.set_viewport(*vp) self.sprite.draw() gui.end_frame() gui.render() self.renderer.render(gui.get_draw_data())
def gui_newFrame(self): imgui.new_frame() imgui.begin("Properties", True) changed, self.pause = imgui.checkbox("Paused", self.pause) imgui.new_line() changed, self.map_type = imgui.combo( "Map Type", self.map_type, ["CubeT", "Cube", "Sphere", "SphereT"]) changed, self.map_size = imgui.drag_int( label="Map Size", value=self.map_size, change_speed=0.1, min_value=10, max_value=100, ) changed, new_boid_count = imgui.drag_int(label="Boid Count", value=self.boid_count, change_speed=100, min_value=1, max_value=self.max_boids) if changed: self.resize_boids_buffer(new_boid_count) imgui.new_line() changed, self.speed = imgui.drag_float(label="Speed", value=self.speed, change_speed=0.0005, min_value=0.001, max_value=0.5, format="%.3f") changed, self.view_distance = imgui.drag_float( label="View Distance", value=self.view_distance, change_speed=0.001, min_value=0.0, max_value=10.0, format="%.2f") changed, self.view_angle = imgui.drag_float(label="View Angle", value=self.view_angle, change_speed=0.001, min_value=0.0, max_value=pi, format="%.2f") changed, self.separation_force = imgui.drag_float( label="Separation Force", value=self.separation_force, change_speed=0.002, min_value=0.0, max_value=10.0, format="%.2f") changed, self.alignment_force = imgui.drag_float( label="Aligment Force", value=self.alignment_force, change_speed=0.002, min_value=0.0, max_value=10.0, format="%.2f") changed, self.cohesion_force = imgui.drag_float( label="Cohesion Force", value=self.cohesion_force, change_speed=0.002, min_value=0.0, max_value=10.0, format="%.2f") imgui.new_line() imgui.begin_group() imgui.text("Custom profiles:") if (imgui.button("Profile 1")): self.set_custom_profile_1() if (imgui.button("Profile 2")): self.set_custom_profile_2() imgui.end_group() imgui.end()
def render_plugins_ui(drawing): "Draw UI windows for all plugins active for the current drawing." # TODO there's an imgui related crash here somewhere preventing (at least) the # voxel plugin from being used in more than one drawing. For now: avoid that. if not drawing: return deactivated = set() for name, (plugin, sig, args) in drawing.plugins.items(): _, opened = imgui.begin(f"{name} {id(drawing)}", True) if not opened: deactivated.add(name) imgui.end() continue imgui.columns(2) for param_name, param_sig in islice(sig.items(), 2, None): imgui.text(param_name) imgui.next_column() default_value = args.get(param_name) if default_value is not None: value = default_value else: value = param_sig.default label = f"##{param_name}_val" if param_sig.annotation == int: changed, args[param_name] = imgui.drag_int(label, value) elif param_sig.annotation == float: changed, args[param_name] = imgui.drag_float(label, value) elif param_sig.annotation == str: changed, args[param_name] = imgui.input_text(label, value, 20) elif param_sig.annotation == bool: changed, args[param_name] = imgui.checkbox(label, value) imgui.next_column() imgui.columns(1) texture_and_size = getattr(plugin, "texture", None) if texture_and_size: texture, size = texture_and_size w, h = size ww, wh = imgui.get_window_size() scale = max(1, (ww - 10) // w) imgui.image(texture.name, w * scale, h * scale, border_color=(1, 1, 1, 1)) last_run = getattr(plugin, "last_run", 0) period = getattr(plugin, "period", None) t = time() if period and t > last_run + period or imgui.button("Execute"): plugin.last_run = last_run try: result = plugin(voxpaint, drawing, **args) if result: args.update(result) except Exception: print_exc() imgui.button("Help") if imgui.begin_popup_context_item("Help", mouse_button=0): if plugin.__doc__: imgui.text(inspect.cleandoc(plugin.__doc__)) else: imgui.text("No documentation available.") imgui.end_popup() imgui.end() for name in deactivated: drawing.plugins.pop(name, None)
def userInterface(graphicItem, app): """ Control graphicItem parameters interactively """ imgui.new_frame() expanded, opened = imgui.begin('Controls', closable=True, flags=imgui.WINDOW_ALWAYS_AUTO_RESIZE) if opened: # Field to show current = app.ifield changed, current = imgui.combo('Field', current, list(CHOICES)) if changed: app.setField(current) # Speed Rate changed, speed = imgui.drag_float('Speed', graphicItem.speedFactor, 0.01, 0.0, 10.0) if changed: graphicItem.speedFactor = speed # Decay changed, decay = imgui.drag_float('Decay', graphicItem.decay, 0.001, 0.001, 1.0) if changed: graphicItem.decay = decay # Drop Rate Bump changed, decayBoost = imgui.drag_float('Decay boost', graphicItem.decayBoost, 0.01, 0.001, 1.0) if changed: graphicItem.decayBoost = decayBoost # Unknown const changed, opacity = imgui.drag_float('Opacity', graphicItem.fadeOpacity, 0.001, 0.900, 0.999, '%.4f') if changed: graphicItem.fadeOpacity = opacity # Palette changed, color = imgui.color_edit3('Color', *graphicItem.color) if changed: graphicItem.color = color imgui.same_line() changed, palette = imgui.checkbox("Palette", graphicItem.palette) if changed: graphicItem.palette = palette changed, bg_color = imgui.color_edit4('Background color', *app.bg_color) if changed: app.bg_color = bg_color # Point size changed, pointSize = imgui.input_int("Point size", graphicItem.pointSize, 1, 1, 1) if changed: if pointSize > 5: pointSize = 5 elif pointSize < 1: pointSize = 1 graphicItem.pointSize = pointSize # Number of Points changed, tracersCount = imgui.drag_int("Number of " "Tracers", graphicItem.tracersCount, 1000.0, 4000, 10000000) if changed: graphicItem.tracersCount = tracersCount # Periodic border changed, periodic = imgui.checkbox("Periodic", graphicItem.periodic) if changed: graphicItem.periodic = periodic # Draw field changed, drawfield = imgui.checkbox("Draw Field", graphicItem.drawField) if changed: graphicItem.drawField = drawfield imgui.end() imgui.render() return opened