def draw(self): imgui.begin("Example: drag float") changed, self.value = imgui.drag_float( "Default", self.value, ) changed, self.value = imgui.drag_float("Less precise", self.value, format="%.1f") imgui.text("Changed: %s, Value: %s" % (changed, self.value)) 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 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 _show(self, value, read_only): imgui.push_item_width(self.width) imgui.push_id("v0") changed0, v0 = imgui.drag_float("", value.value[0], change_speed=self.drag_factor, format="%0.4f") imgui.pop_id() imgui.push_item_width(self.width) imgui.push_id("v1") changed1, v1 = imgui.drag_float("", value.value[1], change_speed=self.drag_factor, format="%0.4f") imgui.pop_id() if (changed0 or changed1) and not read_only: value.value = np.array([v0, v1])
def _show(self, value, read_only): imgui.push_item_width(self.width) changed, v = imgui.drag_float("", value.value, change_speed=self.drag_factor, min_value=self.minmax[0], max_value=self.minmax[1], format="%0.4f") if changed and not read_only: value.value = self.clamper(v)
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 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 float") changed, self.value = imgui.drag_float( "Default", self.value, ) changed, self.value = imgui.drag_float("Less precise", self.value, format="%.1f") imgui.text("Changed: %s, Value: %s" % (changed, self.value)) imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
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 main(): pygame.init() size = 800, 600 screen = pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL) io = imgui.get_io() io.fonts.add_font_default() io.display_size = size renderer = PygameRenderer() clock = pygame.time.Clock() ## Test ####### # Setup OpenGL for 2D rendering glEnable(GL_TEXTURE_2D) glClearColor(0.0, 0.0, 0.0, 0.0) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0.0, size[0], size[1], 0.0) # Important glMatrixMode(GL_MODELVIEW) # new pygame.Surface test = pygame.Surface((300, 300)) test_x = 100 test_y = 100 test.fill((255, 0, 0)) tex_id = None # pygame surface to OpenGL tex ix, iy = test.get_width(), test.get_height() image = pygame.image.tostring(test, "RGBA", True) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) tex_id = glGenTextures(1) glBindTexture(GL_TEXTURE_2D, tex_id) glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) ############### while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: sys.exit() renderer.process_event(event) # Start frame 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() imgui.end_main_menu_bar() global cb_another, w_closable, dg_val if imgui.begin("Main window")[1]: imgui.begin_child("aaa", 300 , -10, border=False) imgui.begin_group() imgui.text("Toggle") _, cb_another = imgui.checkbox("Another Window", cb_another) imgui.text("Another Window state = {}".format(cb_another)) w_closable = cb_another imgui.end_group() imgui.begin_group() imgui.text("Example: drag float") changed, test_x = imgui.drag_float( "test_x", test_x, ) changed, test_y = imgui.drag_float( "test_y", test_y, ) imgui.text("Changed: {}, x: {:.2f} y: {:.2f}".format(changed, test_x, test_y)) imgui.end_group() imgui.end_child() imgui.end() # Disable perm if w_closable: _, w_closable = imgui.begin("Another window", False) # return (collapse, state) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.text("AAAA") imgui.end() # Clean screen glClearColor(0.5, 0.5, 0.5, 1) glClear(GL_COLOR_BUFFER_BIT) ## Draw ########## x = test_x y = test_y w = test.get_width() h = test.get_height() # Prepare the matrix glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(x, y, 0.0) # shift to (x, y) glBindTexture(GL_TEXTURE_2D, tex_id) # Actual draw glBegin(GL_QUADS) glTexCoord2f(0.0, 1.0); glVertex3f(0.0, 0.0, 0.0) # Left top glTexCoord2f(1.0, 1.0); glVertex3f(w, 0.0, 0.0) # Right top glTexCoord2f(1.0, 0.0); glVertex3f(w, h, 0.0) # Right bottom glTexCoord2f(0.0, 0.0); glVertex3f(0.0, h, 0.0) # Left bottom glEnd() ################## imgui.render() pygame.display.flip() clock.tick(60)
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 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()
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