def main(): try: # initilize imgui context (see documentation) imgui.create_context() imgui.get_io().display_size = 100, 100 imgui.get_io().fonts.get_tex_data_as_rgba32() # start new frame context imgui.new_frame() # open new window context imgui.begin("Your first window!", True) # draw text label inside of current window imgui.text("Hello world!") # close current window context imgui.end() # pass all drawing comands to the rendering pipeline # and close frame context imgui.render() imgui.end_frame() except ModuleNotFoundError: print("Error found")
def __init__(self, framebufferid=0, font='', scale_factor=2, font_size=30): super().__init__() self.GUI_STATE = None self.SHADER = None self.props = DProp({ 'steps': 0.100, 'mode': 1, 'active': True }) # GUI_STATE.renderprop.img = framebufferid if framebufferid != 0 else Texture( # Image.new('RGBA', (512, 512), 'BLACK'), isimg=True).getTexID() if font == '': self.font = GUI.FONT imgui.get_io().fonts.get_tex_data_as_rgba32() self.io = imgui.get_io() self.font = 'assets/'+self.font self.new_font = self.io.fonts.add_font_from_file_ttf( self.font, font_size*scale_factor, ) win_w, win_h = glfw.get_window_size(GUI.WINDOW) fb_w, fb_h = glfw.get_framebuffer_size(GUI.WINDOW) font_scaling_factor = max(float(fb_w) / win_w, float(fb_h) / win_h) font_scaling_factor += 0.8 self.io.font_global_scale /= font_scaling_factor self.refresh_font_texture()
def get_pressed_keystrokes ( self ): for i in range( glfw.KEY_A, glfw.KEY_Z + 1 ): if imgui.get_io().keys_down[ i ]: yield KeyStroke( imgui.get_io().key_ctrl, imgui.get_io().key_alt, imgui.get_io().key_shift, chr( ord( 'a' ) + ( i - glfw.KEY_A ) ) )
def show(self, value, read_only): clicked, self.show_texture = imgui.checkbox("Show", self.show_texture) if not self.show_texture: return texture = value.value if texture is None: self.texture_aspect = None else: h, w, _ = texture.shape self.texture_aspect = w / h cursor_pos = imgui.get_cursor_screen_pos() imgui.set_next_window_size(500, 500, imgui.ONCE) imgui.set_next_window_size_constraints((0.0, 0.0), (float("inf"), float("inf")), self.window_size_callback) imgui.set_next_window_position(*imgui.get_io().mouse_pos, imgui.ONCE, pivot_x=0.5, pivot_y=0.5) expanded, opened = imgui.begin( "Texture of %s###%s%s" % (self.node.spec.name, id(self.node), id(self)), True, imgui.WINDOW_NO_SCROLLBAR) if not opened: self.show_texture = False if expanded: if texture is None: imgui.text("No texture associated") else: # [::-1] reverses list texture_size = texture.shape[:2][::-1] texture_aspect = texture_size[0] / texture_size[1] window_size = imgui.get_content_region_available() imgui.image(texture._handle, window_size[0], window_size[0] / texture_aspect) if imgui.is_item_hovered() and imgui.is_mouse_clicked(1): # little hack to have first context menu entry under cursor io = imgui.get_io() pos = io.mouse_pos io.mouse_pos = pos[0] - 20, pos[1] - 20 imgui.open_popup("context") io.mouse_pos = pos if imgui.begin_popup("context"): if imgui.menu_item("save")[0]: util.image.save_screenshot(texture.get()) imgui.menu_item("texture handle: %s" % texture._handle, None, False, False) imgui.menu_item("texture dtype: %s" % str(texture.dtype), None, False, False) imgui.menu_item("texture shape: %s" % str(texture.shape), None, False, False) imgui.end_popup() imgui.end()
def start(self): imgui.create_context() io = imgui.get_io() # io.fonts.add_font_default() io.fonts.add_font_from_file_ttf( "./res/font/Roboto-Medium.ttf", 14, io.fonts.get_glyph_ranges_chinese_full()) io.fonts.add_font_from_file_ttf( "./res/font/FZY3JW.ttf", 13, io.fonts.get_glyph_ranges_chinese_full(), True) self.window = App._impl_glfw_init() impl = GlfwRenderer(self.window) while not glfw.window_should_close(self.window): glfw.poll_events() impl.process_inputs() imgui.new_frame() # imgui.show_test_window() self.update() gl.glClearColor(1., 1., 1., 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(self.window) self.main_view and self.main_view.on_close() impl.shutdown() glfw.terminate()
def process_inputs(self): """Process the virtual user inputs. Called by `main` at the beginning of each frame.""" io = imgui.get_io() window_size = glfw.get_window_size(self.window) fb_size = glfw.get_framebuffer_size(self.window) io.display_size = window_size io.display_fb_scale = compute_fb_scale(window_size, fb_size) io.delta_time = 1.0 / 60 current_time = glfw.get_time() if self._gui_time: self.io.delta_time = current_time - self._gui_time else: self.io.delta_time = 1. / 60. self._gui_time = current_time for i, b in enumerate(self._click): if b: io.mouse_down[i] = True self._click[i] = False else: io.mouse_down[i] = False for i, b in enumerate(self._mouse_buttons): if b: io.mouse_down[i] = True io.mouse_pos = self._mouse_pos io.mouse_wheel = self._mouse_wheel self._mouse_wheel = 0.0
def mouse_release_event(self, x: int, y: int, button: int): self.imgui.mouse_release_event(x, y, button) if not imgui.get_io().want_capture_mouse: sp = x, self.camera.viewport()[1] - y wp = self.camera.unproject(sp[0], sp[1]) for o in self.scene: o.mouse_release_event(wp[0], wp[1], button)
def __init__(self): self.device = None self.queue = None self.rasterizationSamples = vk.VK_SAMPLE_COUNT_1_BIT self.subpass = 0 self.vertexBuffer = vks.vulkanbuffer.Buffer() self.indexBuffer = vks.vulkanbuffer.Buffer() self.vertexCount = 0 self.indexCount = 0 self.shaders = [] self.descriptorPool = None self.descriptorSetLayout = None self.descriptorSet = None self.pipelineLayout = None self.pipeline = None self.fontMemory = vk.VK_NULL_HANDLE self.fontImage = vk.VK_NULL_HANDLE self.fontView = vk.VK_NULL_HANDLE self.sampler = None self.pushConstBlock = {'scale': glm.vec2(), 'translate': glm.vec2()} self.pushConstBlockArray = np.array(glm.vec4(glm.vec2(), glm.vec2())) self.visible = True self.updated = False self.scale = 1.0 imgui.create_context() #self.style = imgui.get_style() # don't know yet how to change self.style.color(imgui.COLOR_*) io = imgui.get_io() io.font_global_scale = self.scale
def mouse_button_callback(self, window, button, action, mods): io = imgui.get_io() if io.want_capture_mouse: print("imgui handles") else: self.app.mouse_button_callback(window, button, action, mods)
def draw(self): imgui.begin("Image example") texture_id = imgui.get_io().fonts.texture_id draw_list = imgui.get_window_draw_list() draw_list.add_image(texture_id, (128, 64), (512, 256), col=imgui.get_color_u32_rgba(0.5, 0.5, 1, 1)) imgui.end()
def process_inputs(self): # todo: consider moving to init io = imgui.get_io() w, h = glfw.get_window_size(self.window) dw, dh = glfw.get_framebuffer_size(self.window) io.display_size = w, h io.display_fb_scale = float(dw) / w, float(dh) / h io.delta_time = 1.0 / 60 if glfw.get_window_attrib(self.window, glfw.FOCUSED): io.mouse_pos = glfw.get_cursor_pos(self.window) else: io.mouse_pos = -1, -1 io.mouse_down[0] = glfw.get_mouse_button(self.window, 0) io.mouse_down[1] = glfw.get_mouse_button(self.window, 1) io.mouse_down[2] = glfw.get_mouse_button(self.window, 2) current_time = glfw.get_time() if self._gui_time: self.io.delta_time = current_time - self._gui_time else: self.io.delta_time = 1. / 60. self._gui_time = current_time
def new_frame(self): # todo: consider moving to init if not self._font_texture: self._create_device_objects() io = imgui.get_io() w, h = glfw.get_window_size(self.window) dw, dh = glfw.get_framebuffer_size(self.window) io.display_size = w, h io.display_fb_scale = float(dw) / w, float(dh) / h io.delta_time = 1.0 / 60 if glfw.get_window_attrib(self.window, glfw.FOCUSED): io.mouse_pos = glfw.get_cursor_pos(self.window) else: io.mouse_pos = -1, -1 # todo: py3k compat for i in xrange(3): io.mouse_down[i] = glfw.get_mouse_button(self.window, i) imgui.new_frame()
def process_inputs(self): # todo: consider moving to init io = imgui.get_io() w, h = glfw.glfwGetWindowSize(self.handle) dw, dh = glfw.glfwGetFramebufferSize(self.handle) io.display_size = w, h io.display_fb_scale = float(dw) / w, float(dh) / h io.delta_time = 1.0 / 60 if glfw.glfwGetWindowAttrib(self.handle, glfw.GLFW_FOCUSED): io.mouse_pos = glfw.glfwGetCursorPos(self.handle) else: io.mouse_pos = -1, -1 io.mouse_down[0] = glfw.glfwGetMouseButton(self.handle, 0) io.mouse_down[1] = glfw.glfwGetMouseButton(self.handle, 1) io.mouse_down[2] = glfw.glfwGetMouseButton(self.handle, 2) current_time = glfw.glfwGetTime() if self._gui_time: self.io.delta_time = current_time - self._gui_time else: self.io.delta_time = 1. / 60. self._gui_time = current_time
def on_mouse_btn(self, window, button, action, mods): x, y = glfw.get_cursor_pos(self.window) imgui.get_io().mouse_pos = (x, y) if imgui.get_io().want_capture_mouse: return if action == glfw.PRESS: self.buttonPressed = button self.isDrag = True self.cam.mousePressed(x, y, self.buttonPressed, None) else: self.buttonPressed = None self.isDrag = False self.cam.mouseReleased(x, y, self.buttonPressed, None)
def __init__(self): super(ImguiLayer, self).__init__() self.renderer = None self.io = imgui.get_io() self._map_keys()
def exec_snippet(self, source): code = compile(source, '<str>', 'exec') frameinfo = getframeinfo(currentframe()) io = imgui.get_io() io.render_callback = lambda *args, **kwargs: None io.delta_time = 1.0 / 60.0 io.display_size = 300, 300 # setup default font io.fonts.get_tex_data_as_rgba32() io.fonts.add_font_default() io.fonts.texture_id = 0 # set any texture ID to avoid segfaults imgui.new_frame() try: exec(code, locals(), globals()) except Exception as err: # note: quick and dirty way to annotate sources with error marker lines = source.split('\n') lines.insert(sys.exc_info()[2].tb_next.tb_lineno, "^^^") self.code = "\n".join(lines) raise imgui.render()
def process_inputs(self): io = imgui.get_io() window_size = glfw.get_window_size(self.window) fb_size = glfw.get_framebuffer_size(self.window) io.display_size = window_size io.display_fb_scale = compute_fb_scale(window_size, fb_size) io.delta_time = 1.0 / 60 if glfw.get_window_attrib(self.window, glfw.FOCUSED): io.mouse_pos = glfw.get_cursor_pos(self.window) else: io.mouse_pos = -1, -1 io.mouse_down[0] = glfw.get_mouse_button(self.window, 0) io.mouse_down[1] = glfw.get_mouse_button(self.window, 1) io.mouse_down[2] = glfw.get_mouse_button(self.window, 2) current_time = glfw.get_time() if self._gui_time: self.io.delta_time = current_time - self._gui_time else: self.io.delta_time = 1. / 60. self._gui_time = current_time
def main(self): # Initialize pygame. pygame.init() size = (800, 600) # Initialize pygame in OpenGL mode. pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL) # Get number of milliseconds since pygame.init() was called. self.timeAtStartOfLastFrame = pygame.time.get_ticks() # Setup some vars for FPS counter. self.lastFPS = 0 self.frameCount = 0 self.frameResetTime = self.timeAtStartOfLastFrame # Setup some imgui stuff. self.imGuiManager = PygameRenderer() io = imgui.get_io() io.fonts.add_font_default() io.display_size = size # Create an instance of our Game class. self.game = GameDissolve.GameDissolve() # Main game loop: keep looping until Game says it's time to quit. self.running = True while self.running: self.processEvents() self.update() self.draw() pygame.quit()
def main(): pygame.init() size = 1280, 960 pygame.display.set_mode( size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) #imgui.create_context() imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) interface() # note: cannot use screen.fill((1, 1, 1)) because pygame's screen # does not support fill() on OpenGL sufraces gl.glClearColor(.1, .1, .1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip()
def draw_gui(self, camera, data, timeline): io = imgui.get_io() if not io.want_capture_mouse: x = imgui.get_mouse_pos().x y = camera.viewport()[1] - imgui.get_mouse_pos().y p = camera.unproject(x, y) i = timeline.intersect(p[0]) if i[0]: date = timeline.index_date(i[1]) if date is not None: df = data[data.Date == date] wp = x + 20, camera.viewport()[1] - y - 100 imgui.set_next_window_position(wp[0], wp[1]) imgui.set_next_window_bg_alpha(0.8) imgui.begin( "pointer", False, imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_ALWAYS_AUTO_RESIZE) imgui.text("Date: " + str(date)) for index, row in df.iterrows(): imgui.separator() imgui.text(row["Pattern"] + ": " + str(row["CandleTime"])) imgui.end() pass
def main(): pygame.init() size = 800, 600 pygame.display.set_mode( size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() impl = PygameRenderer() io = imgui.get_io() io.display_size = size while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() impl.process_event(event) imgui.new_frame() gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip()
def __init__(self): imgui.create_context() super().__init__(GUI.WINDOW) imgui.get_io().fonts.get_tex_data_as_rgba32() self.io = imgui.get_io() win_w, win_h = glfw.get_window_size(GUI.WINDOW) fb_w, fb_h = glfw.get_framebuffer_size(GUI.WINDOW) # self.scale_factor = max(float(fb_w) / win_w, float(fb_h) / win_h) self.font = 'assets/'+GUI.FONT self.io.display_size = win_w, win_h self.new_font = self.io.fonts.add_font_from_file_ttf( self.font, GUI.FONT_SIZE * GUI.SCALE_FACTOR, ) self.io.font_global_scale /= GUI.SCALE_FACTOR self.refresh_font_texture()
def __init__(self): self.io = imgui.get_io() self._shader_handle = None self._vert_handle = None self._fragment_handle = None self._attrib_location_tex = None self._attrib_proj_mtx = None self._attrib_location_position = None self._attrib_location_uv = None self._attrib_location_color = None self._vbo_handle = None self._elements_handle = None self._vao_handle = None self._font_texture = None self.io.delta_time = 1.0 / 60.0 self._create_device_objects() self.refresh_font_texture() # todo: add option to set new_frame callback/implementation self.io.render_callback = self.render
def _draw_brush_preview(self, x0, y0, x, y): if self.brush_preview_dirty: self.overlay.clear(self.brush_preview_dirty, frame=0) if self.drawing.locked: return self.brush_preview_dirty = None io = imgui.get_io() if io.want_capture_mouse: return if self.stroke: return ix0, iy0 = self.to_image_coords(x0, y0) ix, iy = self.to_image_coords(x, y) ix, iy = self.drawing.get_point(ix, iy) overlay = self.overlay brush = self.brush bw, bh = brush.size cx, cy = brush.center # Clear the previous brush preview # TODO when leaving the image, or screen, we also need to clear old_rect = Rectangle((ix0 - cx, iy0 - cy), brush.size) overlay.clear(old_rect, frame=0) rect = Rectangle((ix - cx, iy - cy), brush.size) color = None if isinstance( self.brush, PicBrush) else self.drawing.palette.foreground data = brush.get_draw_data(color) rect = overlay.blit(data, rect, frame=0) self.brush_preview_dirty = rect
def char_callback(self, window, char): io = imgui.get_io() if 0 < char < 0x10000: io.add_input_character(char) if not io.want_capture_keyboard and not io.want_text_input: self.window.on_keyboard_char(window, char)
def inner(*args): try: io = imgui.get_io() if not (io.want_capture_mouse or io.want_capture_keyboard): f(*args) except imgui.ImGuiError: # TODO sometimes happens on startup, guess it's a race conditions somehow pass
def on_init(self, im): 'app初始化:im为imgui环境对象' self.im = im for m in self.mods: m.__dict__['im'] = im # 给每个模块绑定imgui环境 # 清理默认字体 imgui.get_io().fonts.clear_fonts() # 装载首个字体,使之成为默认字体 im.load_font('msyh.ttf', 17, im.font_tag_zh) # 中文雅黑 # im.load_font('simhei.ttf', 16, im.font_tag_zh) #中文黑体 # 再装载其他字体 # im.load_font('Roboto-Medium.ttf', 16, im.font_tag_en,'./') #英文字体,Apache License im.load_font('consola.ttf', 15, im.font_tag_en) # 英文控制台字体 # imgui.get_io().fonts.add_font_default() #内置英文字体 im.imgui_bk.refresh_font_texture()
def on_mouse_drag(self, x, y, dx, dy, button, modifiers): if imgui.get_io().want_capture_mouse: return x = 2.0 * (x / self.window.width) - 1.0 y = 2.0 * (y / self.window.height) - 1.0 if button == 1: # left click self.camera.mouse_roll(x, y) if button == 4: # right click self.camera.mouse_zoom(x, y)
def init(self): pygame.init() size = 800, 600 pygame.display.set_mode( size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE) imgui.create_context() self.impl = PygameRenderer() self.io = imgui.get_io() self.io.display_size = size
def mouse_scroll_callback(self, window, xoffset, yoffset): io = imgui.get_io() if io.want_capture_mouse: print("imgui handles") else: #print( "processed by app: scroll: {},{}".format( xoffset, yoffset )); self.app.mouse_scroll_callback(window, xoffset, yoffset)
def test_getting_and_setting_display_size(): io = imgui.get_io() io.display_size = (1.0, 2.0) assert io.display_size == (1.0, 2.0) assert io.display_size == imgui.get_io().display_size
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] = ... # #
def main(): pygame.init() size = 800, 600 pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL) pygame.display.set_caption("GBDev tool window") io = imgui.get_io() io.fonts.add_font_default() io.display_size = size renderer = PygameRenderer() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() renderer.process_event(event) imgui.new_frame() if imgui.begin_main_menu_bar(): if imgui.begin_menu("Menu", True): open_gbtd, selected_none = imgui.menu_item("Open GBTD", None, False, True) open_gbtk, selected_none = imgui.menu_item("Open GBTK", None, False, True) export_json, selected_none = imgui.menu_item("Export Default Json", None, False, True) clicked_quit, selected_quit = imgui.menu_item("Quit", 'Cmd+Q', False, True) if clicked_quit: exit(1) if open_gbtd: os.system("wine tools/GBTD/GBTD.EXE &") if open_gbtk: os.system("wine tools/GBTK.exe &") if export_json: tools.json2c.default_use() imgui.end_menu() imgui.end_main_menu_bar() imgui.begin("Data", True) img_path = "data/img" onlyfiles = [f for f in listdir(img_path) if isfile(join(img_path, f))] #print(onlyfiles) for file in onlyfiles: imgui_image_menu(img_path+"/"+file) imgui.end() imgui.begin("Images", True) imgs_id = [] for img_filename in onlyfiles: if img_filename.split(".")[-1] == "png": imgs_id.append((img_path+"/"+img_filename, img_manager.load_image(img_path+"/"+img_filename))) for img in imgs_id: img_size = img_manager.get_image_size(img[0]) if img[1] is not 0 and img_size is not (): imgui.image(img[1], img_size[0]*2, img_size[1]*2, (0,1), (1,0)) imgui.same_line() imgui.end() # note: cannot use screen.fill((1, 1, 1)) because pygame's screen # does not support fill() on OpenGL sufraces gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) imgui.render() pygame.display.flip()