def draw(self, data): # render to texture time = default_timer() - self.t0 with self.preview_surface: self.preview_draw(self.preview_surface.cam) # start flashing message & allow input if time > 3.14: self.can_finish = True self.render_start.color.a = sin(time*3)/2 + 0.85 self.start_text_bg.draw(self.preview_surface.cam) self.render_start.draw(self.preview_surface.cam) self.mock_keys.draw(self.preview_surface.cam) self.preview_surface.draw(self.win.cam) self.render_title.draw(self.win.cam) # imgui window imgui.new_frame() imgui.push_font(self.imgui_font) imgui.set_next_window_size(*self.imgui_dims) imgui.set_next_window_position(*self.imgui_pos) title = {'en': 'Instructions', 'es': 'Instrucciones'} imgui.begin(title[self.default_lang], False, flags=self.flags) imgui.push_text_wrap_pos(1000) imgui.text(self.it2) imgui.pop_text_wrap_pos() imgui.end() imgui.set_next_window_position(100, 100) imgui.set_next_window_size(180, 50) imgui.begin('##blockcount', flags=self.flags | WINDOW_NO_TITLE_BAR) rnd = {'en': 'Round', 'es': 'La ronda'} imgui.text('%s %s/%s' % (rnd[self.default_lang], self.num, self.tot)) imgui.end() imgui.pop_font() imgui.render() self.imgui_renderer.render(imgui.get_draw_data()) # fade in effect if self.fade_in: self.fade_sqr.fill_color.a -= 0.05 if self.fade_sqr.fill_color.a <= 0: self.fade_in = False self.fade_sqr.draw(self.win.cam) if self.fade_out: self.fade_sqr.fill_color.a += 0.05 self.fade_sqr.draw(self.win.cam) if self.fade_sqr.fill_color.a >= 1: return True if data and self.can_finish: self.fade_out = True return False
def render_frame(impl, window, font): glfw.poll_events() impl.process_inputs() imgui.new_frame() gl.glClearColor(0.1, 0.1, 0.1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT) if font is not None: imgui.push_font(font) frame_commands() if font is not None: imgui.pop_font() imgui.render() impl.render(imgui.get_draw_data()) glfw.swap_buffers(window)
def is_active(self): """Cycles a frame and returns whether the window remains open. Returns: True if the application is still open, otherwise False. """ active = not glfw.window_should_close(self.window) if active and not self.first: imgui.pop_font() imgui.render() self.impl.render(imgui.get_draw_data()) glfw.swap_buffers(self.window) if active: glfw.poll_events() self.impl.process_inputs() imgui.new_frame() imgui.push_font(self.font) self.first = False return active
def font(font_, widget): """ Render `widget` with a given font. The easiest way to create `font_` is probably to call this before the call to `concur.integrations.glfw.main`: ```python imgui.create_context() font = imgui.get_io().fonts.add_font_from_file_ttf("font_file.ttf", 16) ``` See the [font guide in PyImGui](https://pyimgui.readthedocs.io/en/latest/guide/using-fonts.html) for more details. """ while True: imgui.push_font(font_) try: next(widget) except StopIteration as e: return e.value finally: imgui.pop_font() yield
def update(self): # return done, value do_return = False recipe = '' if self.extra_font: imgui.push_font(self.extra_font) width = 750 height = 250 imgui.set_next_window_size(width, height) imgui.set_next_window_position(self.center_x - width // 2, self.center_y - height // 2) imgui.push_style_var(imgui.STYLE_ALPHA, self.alpha) imgui.begin('Drop', False, flags=self.flags) self.left_label('ID:') xx, self.id = imgui.input_text('\n', self.id, 128) self.tooltip_help('Participant ID/Name') self.add_space(3) self.left_label('Español:') _, self.spanish = imgui.checkbox('', self.spanish) self.tooltip_help('Spanish text for subsequent instructions') self.add_space(3) self.left_label('Recipe:') # current filenames recipe_names = [] recipe_short = [] for file in glob.glob('recipes/**/*.toml', recursive=True): if (os.path.sep + 'defaults' + os.path.sep) not in file: recipe_names.append(file) recipe_short.append(os.path.relpath(file, 'recipes')) changed, self.current_recipe = imgui.combo(' ', self.current_recipe, recipe_short) self.tooltip_help( 'Available recipes (TOML files) in the recipe directory') imgui.same_line() imgui.button('Preview') if imgui.is_item_hovered() and recipe_names: with open(recipe_names[self.current_recipe], 'r') as f: prev = f.read() # width in characters, height in number of newlines if prev: wid = len( max(open(recipe_names[self.current_recipe], 'r'), key=len)) # TODO: need to be careful of newline char?? hei = prev.count('\n') + 1 else: wid = 10 hei = 1 fac = 0.6 font_size = imgui.get_font_size() * fac wid = int(wid * font_size / 2) # get something like pix hei = int(hei * font_size) # if height is >= half the window height, turn to scroll val = hei if hei >= self.center_y: val = self.center_y imgui.begin_tooltip() imgui.begin_child('region', wid, val) imgui.set_scroll_y(imgui.get_scroll_y() - imgui.get_io().mouse_wheel * 30) imgui.set_window_font_scale(fac) imgui.text(prev) imgui.end_child() imgui.end_tooltip() imgui.set_item_default_focus() # imgui.set_tooltip(prev) self.add_space(3) if imgui.button('Ok'): do_return = True if imgui.get_io().keys_down[imgui.KEY_ENTER]: do_return = True imgui.pop_style_var(1) imgui.end() if self.extra_font: imgui.pop_font() # disallow depending on current state if not self.id: do_return = False try: recipe = recipe_names[self.current_recipe] except IndexError: do_return = False if not os.path.isdir(self.recipe_dir): do_return = False # no need to validate data dir, we'll create it data = { 'id': self.id, 'recipe': recipe, 'spanish': 'es' if self.spanish else 'en' } return do_return, data
def pop_font(): imgui.pop_font()