def draw_sector_mode(): if imgui.button("New sector"): cur_state.cur_sector = add_new_sector() if cur_state.cur_sector is not None: cur_sect = cur_state.cur_sector imgui.same_line() imgui.text("Sector {}".format(cur_sect.index)) input_int("Floor height: ", "##sector{}_floor_height".format(cur_sect.index), cur_sect.floor_height, lambda v: setattr(cur_sect, 'floor_height', v)) input_int("Floor color: ", "##sector{}_floor_color".format(cur_sect.index), cur_sect.floor_color, lambda v: setattr(cur_sect, 'floor_color', v)) input_int("Ceiling height: ", "##sector{}_ceil".format(cur_sect.index), cur_sect.ceil_height, lambda v: setattr(cur_sect, 'ceil_height', v)) input_int("Ceiling color: ", "##sector{}_ceil_color".format(cur_sect.index), cur_sect.ceil_color, lambda v: setattr(cur_sect, 'ceil_color', v)) def set_cur_sector(idx): cur_state.cur_sector = cur_state.map_data.sectors[idx] draw_list("Sectors", "Sector list", cur_state.map_data.sectors, set_cur_sector)
def draw_list(id_str, label, items, select_item, delete_callback=None): imgui.begin_child(id_str) imgui.text(label) cur_state.hovered_item = None for idx, item in enumerate(items): cur_id_str = "##list_{}_{}".format(id_str, idx) sel_btn_id = "Select {} {}".format(idx, cur_id_str) del_btn_id = "X{}".format(cur_id_str) imgui.begin_group() if imgui.button(sel_btn_id): print("clicked {}".format(idx)) select_item(idx) imgui.same_line() imgui.text(str(item)) if delete_callback is not None: imgui.same_line() if imgui.button(del_btn_id): delete_callback(item) print("delete!!") imgui.end_group() if imgui.is_item_hovered(): cur_state.hovered_item = item imgui.end_child()
def to_imgui(self, file_entry: FileEntry, padding: int): for entry in file_entry.entries: start, end = self.range_for_entry(entry, padding) for i in range(start, end + 1): if i >= self.max_line: break text = self.content[i] in_range = i in range(entry.begin_line, entry.end_line + 1) if in_range: imgui.push_style_color(imgui.COLOR_TEXT, 0.0, 1.0, 0.0) imgui.text("{0:03d} {1}".format(i, text)) if in_range: imgui.pop_style_color(1) if entry is not file_entry.entries[-1]: imgui.spacing() imgui.separator() imgui.spacing()
def show_sequence(seq: Sequence[A], name: str = None) -> IMGui[None]: seq_str = sequence_to_str(seq) if name == None: im.text(seq_str) else: im.text(name_and_multiline_str(name, seq_str))
def draw(self): imgui.begin("Example: popup context view") imgui.text("Right-click to set value.") if imgui.begin_popup_context_item("Item Context Menu"): imgui.selectable("Set to Zero") imgui.end_popup() imgui.end()
def draw(self, *args, **kwargs): 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() imgui.show_test_window() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render()
def render_alert(alertItem): alert, count = alertItem imgui.text(str(count)) imgui.next_column() alert.render() imgui.next_column() imgui.separator()
def input_select(label, id_str, input_choices, cur_value, set_val): imgui.text(label) imgui.same_line() changed, new_val = imgui.core.combo(id_str, cur_value, input_choices) if changed: set_val(new_val)
def input_int2(label, id_str, input_vals, set_vals): imgui.text(label) imgui.same_line() changed, new_vals = imgui.input_int2(id_str, *input_vals) if changed: set_vals(new_vals)
def input_int(label, id_str, input_val, set_val): imgui.text(label) imgui.same_line() changed, new_val = imgui.input_int(id_str, input_val) if changed: set_val(new_val)
def render_ui(self): """Render the UI""" 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() imgui.show_test_window() imgui.begin("Custom window", True) imgui.text("Bar") imgui.text_colored("Eggs", 0.2, 1., 0.) imgui.end() # Create window with the framebuffer image imgui.begin("Custom window with Image", True) # Create an image control by passing in the OpenGL texture ID (glo) # and pass in the image size as well. # The texture needs to he registered using register_texture for this to work imgui.image(self.fbo.color_attachments[0].glo, *self.fbo.size) imgui.end() imgui.render() self.imgui.render(imgui.get_draw_data())
def on_draw(self): imgui.create_context() imgui.new_frame() imgui.begin("FrameBuffer", True) fbs = [ o for o in gc.get_referrers(FrameBuffer) if isinstance(o, FrameBuffer) ] gl.glClearColor(0, 0, 0, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) clicked, self.current_framebuffer = imgui.combo( "FrameBuffer", self.current_framebuffer, [str(fb) for fb in fbs]) fb = fbs[self.current_framebuffer] w, h = fb.size for name, tex in fb.textures.items(): imgui.text(name) imgui.image(tex.name, 200, 200 * h / w) imgui.end() imgui.render() imgui.end_frame() data = imgui.get_draw_data() if data: self.imgui_renderer.render(imgui.get_draw_data())
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: item groups") imgui.begin_group() imgui.text("First group (buttons):") imgui.button("Button A") imgui.button("Button B") imgui.end_group() imgui.same_line(spacing=50) imgui.begin_group() imgui.text("Second group (text and bullet texts):") imgui.bullet_text("Bullet A") imgui.bullet_text("Bullet B") imgui.end_group() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def render(self, *args): imgui.columns(2, 'fileLlist') imgui.separator() pathlist = os.listdir(os.curdir) pathlist.insert(0, os.pardir) pathlist.insert(0, os.curdir) length = len(pathlist) selected = [False] * length for i in range(length): _, selected[i] = imgui.selectable(pathlist[i], selected[i]) imgui.next_column() size = os.path.getsize(pathlist[i]) imgui.text(str(size)+' byte') imgui.next_column() if(selected[i] is True): self.path = os.path.abspath(pathlist[i]) print('clicked ' + pathlist[i]) if os.path.isdir(self.path): os.chdir(self.path) break imgui.next_column() imgui.columns(1) return {'path': self.path}
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()
def draw(self): imgui.begin("Example: collapsing header") expanded, self.visible = imgui.collapsing_header("Expand me!", self.visible) if expanded: imgui.text("Now you see me!") imgui.end()
def render_layers(view): "Layer selector. Currently extremely spare." index = view.index # changed, new_index = imgui.v_slider_int("##layer_index", 30, 100, index, # min_value=0, max_value=n_layers - 1) # if changed: # x, y, z = view.direction # delta = new_index - index # view.switch_layer(delta) # imgui.same_line() draw_list = imgui.get_window_draw_list() x, y = imgui.get_cursor_screen_pos() draw_list.add_rect_filled(x, y, x + 30, y + 100, imgui.get_color_u32_rgba(0.5, 0.5, 0.5, 1)) top_layer = view.depth h = 100 / top_layer for layer in view.hidden_layers: dy = 100 - 100 * (view.index_of_layer(layer) + 1) / top_layer draw_list.add_rect_filled(x, y + dy, x + 30, y + dy + h, imgui.get_color_u32_rgba(0.5, 0.1, 0.1, 1)) dy = 100 - 100 * (index + 1) / top_layer draw_list.add_rect_filled(x, y + dy, x + 30, y + dy + h, imgui.get_color_u32_rgba(1, 1, 1, 0.5)) imgui.set_cursor_screen_pos((x, y)) imgui.text(str(index))
def draw_vert_mode(cur_state): #if imgui.button("New vertex"): # cur_state.cur_vertex = add_new_vertex() if cur_state.cur_vertex != -1: cur_vertex_index = cur_state.cur_vertex imgui.text("Vertex {}".format(cur_vertex_index)) vert = cur_state.map_data.vertexes[cur_vertex_index] def set_xy(xy): (x, y) = xy cur_state.map_data.vertexes[cur_vertex_index].x = x cur_state.map_data.vertexes[cur_vertex_index].y = y input_int2("x,y: ", "##vert{}_xy".format(cur_vertex_index), (vert.x, vert.y), set_xy) def set_cur_vertex(idx): cur_state.cur_vertex = idx draw_list(cur_state, "Vertex", "Vertex list", cur_state.map_data.vertexes, set_cur_vertex)
def dynamic_popup_button(self, label, error, tag=None): """ Validating button. Behaves in the same way as a regular `concur.widgets.button` when `error` is None. When `error` is a string, it displays an error popup instead of emitting an event. """ while True: if imgui.button(label): if error is not None: imgui.open_popup("Error Popup") else: return tag if tag is not None else label, None if imgui.begin_popup("Error Popup"): imgui.text(error) if self.is_continuable: if imgui.button("Continue anyway"): imgui.close_current_popup() imgui.end_popup() return tag if tag is not None else label, None imgui.same_line() if imgui.button("Cancel"): imgui.close_current_popup() imgui.end_popup() else: if imgui.button("OK"): imgui.close_current_popup() imgui.end_popup() yield
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: simple popup modal") if imgui.button("Open Modal popup"): imgui.open_popup("select-popup") imgui.same_line() if imgui.begin_popup_modal("select-popup")[0]: imgui.text("Select an option:") imgui.separator() imgui.selectable("One") imgui.selectable("Two") imgui.selectable("Three") imgui.end_popup() imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
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: checkboxes for flags", flags=self.flags) clicked, self.flags = imgui.checkbox_flags( "No resize", self.flags, imgui.WINDOW_NO_RESIZE ) clicked, self.flags = imgui.checkbox_flags( "No move", self.flags, imgui.WINDOW_NO_MOVE ) clicked, self.flags = imgui.checkbox_flags( "No collapse", self.flags, imgui.WINDOW_NO_COLLAPSE ) # note: it also allows to use multiple flags at once clicked, self.flags = imgui.checkbox_flags( "No resize & no move", self.flags, imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE ) imgui.text("Current flags value: {0:b}".format(self.flags)) imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def __call__(self): _, show = imgui.begin("Custom window1", True) if not show: main_frame.s1 = False imgui.text("BarBarBar") imgui.text_colored("Eggs", 1., 0.1, 0.2) imgui.end()
def render_unsaved_exit(window): "Popup to prevent exiting the application with unsaved work." if window.exit_unsaved_drawings: imgui.open_popup("Really exit?") imgui.set_next_window_size(500, 200) if imgui.begin_popup_modal("Really exit?")[0]: imgui.text("You have unsaved work in these drawing(s):") imgui.begin_child("unsaved", border=True, height=imgui.get_content_region_available()[1] - 26) for drawing in window.exit_unsaved_drawings: imgui.text(drawing.filename) if imgui.is_item_hovered(): pass # TODO popup thumbnail of the picture? imgui.end_child() if imgui.button("Yes, exit anyway"): imgui.close_current_popup() pyglet.app.exit() imgui.same_line() if imgui.button("Yes, but save first"): for drawing in window.exit_unsaved_drawings: window.save_drawing(drawing) pyglet.app.exit() imgui.same_line() if imgui.button("No, cancel"): window.exit_unsaved_drawings = None imgui.close_current_popup() imgui.end_popup()
def render_new_drawing_popup(window): "Settings for creating a new drawing." if window._new_drawing: imgui.open_popup("New drawing") w, h = window.get_size() imgui.set_next_window_size(200, 120) imgui.set_next_window_position(w // 2 - 100, h // 2 - 60) if imgui.begin_popup_modal("New drawing")[0]: imgui.text("Creating a new drawing.") imgui.separator() changed, new_size = imgui.drag_int3("Shape", *window._new_drawing["shape"], min_value=1, max_value=2048) if changed: window._new_drawing["shape"] = new_size if imgui.button("OK"): window.really_create_drawing() imgui.close_current_popup() imgui.same_line() if imgui.button("Cancel"): window._new_drawing = None imgui.close_current_popup() imgui.end_popup()
def draw(self): imgui.begin(self.title) changed, self.text_val = imgui.input_text('Text', self.text_val, 256) imgui.text('You wrote:') imgui.same_line() imgui.text(self.text_val) imgui.end()
def render_unsaved_close_drawing(window): "Popup to prevent accidentally closing a drawing with unsaved work." drawing = window.close_unsaved_drawing if drawing and drawing.unsaved: imgui.open_popup("Really close?") if imgui.begin_popup_modal("Really close?", flags=imgui.WINDOW_NO_RESIZE)[0]: imgui.text("The drawing contains unsaved work.") if imgui.button("Yes, close anyway"): window.drawings.remove(drawing) window.close_unsaved_drawing = None imgui.close_current_popup() imgui.same_line() if imgui.button("Yes, but save first"): window.save_drawing(drawing) window.drawings.remove(drawing) window.close_unsaved_drawing = None imgui.close_current_popup() imgui.same_line() if imgui.button("No, cancel"): window.close_unsaved_drawing = None imgui.close_current_popup() imgui.end_popup()
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: checkboxes") # note: first element of return two-tuple notifies if there was a click # event in currently processed frame and second element is actual # checkbox state. _, self.checkbox1_enabled = imgui.checkbox("Checkbox 1", self.checkbox1_enabled) _, self.checkbox2_enabled = imgui.checkbox("Checkbox 2", self.checkbox2_enabled) imgui.text("Checkbox 1 state value: {}".format(self.checkbox1_enabled)) imgui.text("Checkbox 2 state value: {}".format(self.checkbox2_enabled)) imgui.end() imgui.end_frame() imgui.render() self.renderer.render(imgui.get_draw_data())
def __call__(self): _, show = imgui.begin("LOL", True) if not show: main_frame.s1 = False imgui.text("BarBar") imgui.text_colored("Eggs", 0.7, 0.4, 0.2) imgui.end()
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_laptimer(self): _, self.lap_timer = imgui.begin("lap timer", True) if not self.lap_timer: imgui.end() return # _, self.startlinexy[0] = imgui.slider_float("start line x", self.startlinexy[0], 0, 20) # _, self.startlinexy[1] = imgui.slider_float("top lane y", self.startlinexy[0], 0, 10) x = self.controlstate[:, 0] y = self.controlstate[:, 1] lapidxs = np.nonzero((x[:-1] < self.startlinexy[0]) & (x[1:] > self.startlinexy[0]) & (y[1:] > self.startlinexy[1]))[0] n = 0 for i in range(1, len(lapidxs)): if self.i < lapidxs[i]: break dt = self.ts[lapidxs[i]] - self.ts[lapidxs[i - 1]] n += 1 imgui.text("Lap %d: %d.%03d" % (n, int(dt), 1000 * (dt - int(dt)))) if self.i > lapidxs[0]: dt = self.ts[self.i] - self.ts[lapidxs[n]] imgui.text("Lap %d: %d.%03d" % (n + 1, int(dt), 1000 * (dt - int(dt)))) imgui.set_scroll_here(1.0) imgui.end()
def imgui_image_menu(path): filename = path.split("/")[-1] if filename.split(".")[-1] == "bin": imgui.text(filename) if imgui.begin_popup_context_item("Convert "+filename, 2): if imgui.button("Convert to 8x8 images"): tools.bin2png.bin2png(path,8) img_manager.reload_img(path.replace(".bin", ".png")) if imgui.button("Convert to 16x16 images"): tools.bin2png.bin2png(path, 16) img_manager.reload_img(path.replace(".bin", ".png")) if imgui.button("Convert to 32x32 images"): tools.bin2png.bin2png(path, 32) img_manager.reload_img(path.replace(".bin", ".png")) imgui.end_popup()
def onDrawGuiCallback(self, *args, **kw): if self.window_visable: try: if imgui.begin('AutoLoot {0} - {1}##Entity_mainwindow'.format(autoloot.__version__, autoloot.__author__), (600,350)): # button bar if imgui.checkbox('Enable Auto-Loot', self.enabled_auto_loot): self.enabled_auto_loot = not self.enabled_auto_loot if imgui.collapsingHeader('Available Loot ({0} items)'.format(len(self.bot.items))): imgui.columns(4) for item in self.bot.items: if not item: continue imgui.text(item.roleName) imgui.nextColumn() if item.__module__ == 'DroppedItem': try: imgui.text('Lootable' if item._checkPickItem(self.bot.p) else 'Not Lootable') except AttributeError: imgui.text('Not _checkPickItem') else: imgui.text('Openable?') imgui.nextColumn() imgui.text('{0}'.format(self.bot.p.position.distTo(item.position))) imgui.nextColumn() if imgui.button('Go To {0}##NavToEntity'.format(item.__module__)): nav.moveToEntityPathFind(item) imgui.nextColumn() imgui.separator() imgui.columns(1) if imgui.collapsingHeader('Debug All Entities'): for entity_name, entities in sorted(self.bot.entities.iteritems()): for entity in entities: imgui.columns(5) imgui.separator() imgui.text('{0}'.format(entity_name)) imgui.nextColumn() imgui.text('{0}'.format(entity.id)) imgui.nextColumn() if entity_name == 'DroppedItem' and hasattr(entity, '_checkPickItem') and entity._checkPickItem(self.bot.p): imgui.text('{0}'.format('Lootable')) elif not entity_name == 'DroppedItem': imgui.text('No Data Available') else: imgui.text('Not your Loot!') imgui.nextColumn() if entity and hasattr(entity, 'position') and self.bot.p and hasattr(self.bot.p, 'position'): imgui.text('{0}'.format(self.bot.p.position.distTo(entity.position))) else: imgui.text('No Position Information') imgui.nextColumn() if imgui.button('NavToEntity##NavToEntity'): nav.moveToEntityPathFind(entity) imgui.nextColumn() imgui.columns(1) imgui.end() except Exception: import traceback for line in traceback.format_exc().splitlines(): roplus.log(line) self.window_visable = False
import imgui def my_render_function(): print 'foo' io = imgui.get_io() io.display_size = 1920.0, 1280.0 io.render_draw_lists_fn = my_render_function io.fonts.add_font_default() io.fonts.get_tex_data_as_rgba32() ## Application main loop while True: io = imgui.get_io(); io.delta_time = 1.0/60.0; print 'Render' imgui.new_frame() imgui.begin("My window") imgui.text("Hello, world.") imgui.end() imgui.render() print '...done' #io.mouse_pos = mouse_pos; #io.mouse_down[0] = mouse_button_0; # io.KeysDown[i] = ... # #