Пример #1
0
    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())
Пример #2
0
def window(title: str,
           widget: Widget,
           position: Tuple[int, int] = None,
           size: Tuple[int, int] = None,
           flags: int = 0) -> Widget:
    """ Create a window with a given `widget` inside.

    Contents are drawn only if the window is opened.

    * **Window title must be unique.** Contents of windows with an identical title will appear
      inside a single window.
    * **Windows must not be nested.** Nested windows may lead to visibility feedback loops,
      which manifests as flicker on some docking operations.
    """
    while True:
        if position is not None:
            imgui.set_next_window_position(*position)
        if size is not None:
            imgui.set_next_window_size(*size)
        else:
            imgui.set_next_window_size(400, 300, imgui.FIRST_USE_EVER)
        expanded, opened = imgui.begin(title, flags=flags)
        try:
            if expanded and opened:
                next(widget)
        except StopIteration as e:
            return e.value
        finally:
            imgui.end()
        yield
Пример #3
0
 def draw_timeseries_window(self, width, height):
     imgui.set_next_window_size(width / 10, height)
     imgui.set_next_window_position(0, 0)
     imgui.begin("Time Series", flags=default_flags)
     graph_size = [width / 11, height / 7.5]
     self.summary.draw_plots(self.simulator.time, graph_size)
     imgui.end()
Пример #4
0
    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())
Пример #5
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(256, 256, imgui.ONCE)

        imgui.begin("Circle")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_circle(100,
                             60,
                             30,
                             imgui.get_color_u32_rgba(1, 1, 0, 1),
                             thickness=3)
        imgui.end()

        imgui.set_next_window_position(270, 32, imgui.ONCE)
        imgui.set_next_window_size(256, 256, imgui.ONCE)

        imgui.begin("Filled Circle")
        draw_list = imgui.get_window_draw_list()
        draw_list.add_circle_filled(100, 60, 30,
                                    imgui.get_color_u32_rgba(1, 1, 0, 1))
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Пример #6
0
    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 and drop")

        imgui.button('source')
        if imgui.begin_drag_drop_source():
            imgui.set_drag_drop_payload('itemtype', b'payload')
            imgui.button('dragged source')
            imgui.end_drag_drop_source()

        imgui.button('dest')
        if imgui.begin_drag_drop_target():
            payload = imgui.accept_drag_drop_payload('itemtype')
            if payload is not None:
                print('Received:', payload)
            imgui.end_drag_drop_target()

        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Пример #7
0
def draw_console():
    global _console_text_temp
    if console.SHOW_CONSOLE:
        imgui.set_next_window_bg_alpha(0.35)
        imgui.set_next_window_position(0, 0)
        imgui.set_next_window_size(screen_utils.WIDTH, 110)
        imgui.begin(
            "ConsoleWindow", False, imgui.WINDOW_NO_MOVE
            | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_COLLAPSE
            | imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_SAVED_SETTINGS)
        imgui.begin_child("ConsoleOutput", 0, -25, False)
        for text, color in console.text_buffer:
            if color is None:
                color = (0.25, 0.75, 1)
            imgui.text_colored(text, color[0], color[1], color[2], 0.8)
        imgui.text("")
        imgui.set_scroll_y(imgui.get_scroll_max_y())
        imgui.end_child()
        buf_size = 256
        if len(_console_text_temp) > 0 and not _console_text_temp[0] == "/":
            buf_size = 64
        enter, text = imgui.input_text("Input", _console_text_temp, buf_size,
                                       imgui.INPUT_TEXT_ENTER_RETURNS_TRUE)
        if enter:
            if str.startswith(text, "/"):
                text = str.replace(text, "/", "", 1)
                console.handle_input(text)
            else:
                client_net.send_message(text)
            text = ""
        _console_text_temp = text
        imgui.end()
Пример #8
0
    def update(self):
        self.window_size = pygame.display.get_surface().get_size()

        if self.use_base_window:
            imgui.set_next_window_position(0, 0)
            imgui.set_next_window_size(self.window_size[0],
                                       self.window_size[1])
            imgui.begin("main", False, self.base_window_flags)
            if self.use_menu_bar and imgui.begin_menu_bar():
                self.draw_menu()
                imgui.end_menu_bar()

            self.draw_base_window()

            imgui.end()
        else:
            if self.use_menu_bar and imgui.begin_main_menu_bar():
                self.draw_menu()
                imgui.end_main_menu_bar()

        self.draw_windows()

        if self.show_style_window:
            self.show_style_window = imgui.begin("Style Editor", True)[1]
            imgui.show_style_editor()
            imgui.end()

        if self.show_demo_window:
            self.show_demo_window = imgui.show_demo_window(True)
Пример #9
0
    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
Пример #10
0
 def draw_gui(self, sp, wp, c: OrthographicCamera):
     # render price pointer
     win_p = sp[0] - 100, c.viewport()[1] - sp[1] - 30
     imgui.set_next_window_position(win_p[0], win_p[1])
     imgui.set_next_window_bg_alpha(0.1)
     imgui.begin(
         "mouse_pointer", False,
         imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_TITLE_BAR
         | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_ALWAYS_AUTO_RESIZE)
     imgui.text("R$ %.2f" % wp[1])
     self.current_pointer = (wp[0], wp[1])
     imgui.end()
     # render box measure
     if self.dragging:
         ss = c.project(self.start[0], self.start[1])
         se = c.project(self.end[0], self.end[1])
         win_p = (ss[0] + se[0]) / 2, c.viewport()[1] - (ss[1] + se[1]) / 2
         imgui.set_next_window_position(win_p[0], win_p[1])
         imgui.set_next_window_bg_alpha(0.9)
         imgui.begin(
             "box_measure", False,
             imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_TITLE_BAR
             | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_ALWAYS_AUTO_RESIZE)
         imgui.text("R$ %.2f -> %.2f" % (self.start[1], self.end[1]))
         imgui.text("Profit: R$ %.2f (%.2f%%)" %
                    (self.end[1] - self.start[1],
                     ((self.end[1] - self.start[1]) / self.start[1] * 100)))
         imgui.end()
Пример #11
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        if imgui.begin_main_menu_bar():
            # first menu dropdown
            if imgui.begin_menu('File', True):
                imgui.menu_item('New', 'Ctrl+N', False, True)
                imgui.menu_item('Open ...', 'Ctrl+O', False, True)

                # submenu
                if imgui.begin_menu('Open Recent', True):
                    imgui.menu_item('doc.txt', None, False, True)
                    imgui.end_menu()

                imgui.end_menu()

            imgui.end_main_menu_bar()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Пример #12
0
 def render_callback(self, time: float, frametime: float):
     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()
         changed, value = imgui.input_text("", self.input_text, 30)
         if changed:
             imgui.set_next_window_position(imgui.get_item_rect_min().x,
                                            imgui.get_item_rect_max().y)
             imgui.set_next_window_size(imgui.get_item_rect_size().x, 0)
             if imgui.begin("##popup", False,
                            imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE):
                 for index, row in symbol_list.iterrows():
                     if value.upper() in row[0]:
                         opened, selected = imgui.selectable(row[0] + " - " + row[2])
                         if imgui.is_item_clicked():
                             input_text = row[0]
                             selected_symbol = row[0]
             imgui.end()
         if imgui.button("download"):
             yfc.download(self.selected_symbol, symbol_data_file())
         imgui.end_main_menu_bar()
     pass
Пример #13
0
    def draw(self):
        imgui.new_frame()

        imgui.set_next_window_position(16, 32, imgui.ONCE)
        imgui.set_next_window_size(512, 512, imgui.ONCE)

        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()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Пример #14
0
def show_main_menu():
    global text, ip_text
    style: GuiStyle = imgui.get_style()
    style.window_border_size = 0
    style.colors[imgui.COLOR_BUTTON] = Vec4(0.26, 0.59, 0.5, 0.4)
    style.colors[imgui.COLOR_BUTTON_ACTIVE] = Vec4(0.06, 0.53, 0.4, 1.0)
    style.colors[imgui.COLOR_BUTTON_HOVERED] = Vec4(0.26, 0.59, 0.5, 1.0)
    imgui.set_next_window_bg_alpha(0)
    imgui.set_next_window_position(300, 220)
    imgui.set_next_window_size(180, 200)
    imgui.begin("tremor0", False, imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_TITLE_BAR |
                imgui.WINDOW_ALWAYS_USE_WINDOW_PADDING)
    _, username = imgui.input_text("Name", text, 16)
    _, ip = imgui.input_text("Host", ip_text, 32)
    ip_text = ip
    text = username
    imgui.end()
    imgui.set_next_window_bg_alpha(0)
    imgui.set_next_window_size(100, 100)
    imgui.set_next_window_position(200, 200)
    imgui.begin("tremor1", False, imgui.WINDOW_NO_COLLAPSE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_TITLE_BAR |
                imgui.WINDOW_ALWAYS_USE_WINDOW_PADDING)
    imgui.text_colored("Tremor", 0.9, 0.6, 1.0)
    play_clicked = imgui.button("Play", 82, 25)
    exit_clicked = imgui.button("Exit", 82, 25)
    if exit_clicked:
        graphics_subsystem.request_close()
    if play_clicked:
        print(username)
        client_net.connect_to_server((ip, 27070), username)
    imgui.end()
Пример #15
0
    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())
Пример #16
0
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()
Пример #17
0
    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: color edit with alpha")

        # note: first element of return two-tuple notifies if the color was changed
        #       in currently processed frame and second element is current value
        #       of color and alpha
        _, self.color = imgui.color_edit4("Alpha",
                                          *self.color,
                                          show_alpha=True)
        _, self.color = imgui.color_edit4("No alpha",
                                          *self.color,
                                          show_alpha=False)

        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Пример #18
0
    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())
Пример #19
0
 def menu_bar(self):
     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:
                 self.cleanup()
                 exit(0)
             imgui.end_menu()
         changed, value = imgui.input_text("", self.input_text, 30)
         if changed:
             imgui.set_next_window_position(imgui.get_item_rect_min().x,
                                            imgui.get_item_rect_max().y)
             imgui.set_next_window_size(imgui.get_item_rect_size().x, 0)
             if imgui.begin(
                     "##popup", False, imgui.WINDOW_NO_TITLE_BAR
                     | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_RESIZE):
                 for index, row in self.symbol_list.iterrows():
                     if value.upper() in row[0]:
                         _, _ = imgui.selectable(row[0] + " - " + row[2])
                         if imgui.is_item_clicked():
                             self.input_text = row[0]
                             self.load_symbol(str(row[0]).lower())
             imgui.end()
         imgui.end_main_menu_bar()
Пример #20
0
    def __enter__(self):
        glClearColor(0, 1, 0, 0)

        while not glfw.window_should_close(self.window):
            cur_time = glfw.get_time()
            elapsed = cur_time - self.prev_time
            self.prev_time = cur_time

            glfw.poll_events()
            self.impl.process_inputs()

            self._process(elapsed)

            imgui.new_frame()

            imgui.set_next_window_position(0, 0)
            imgui.set_next_window_size(280, 180)

            imgui.begin("Uniforms", False, imgui.WINDOW_NO_RESIZE)

            imgui.push_item_width(-45)

            for cont in self.program.controls:
                cont.update()

            imgui.end()

            glClear(GL_COLOR_BUFFER_BIT)
            self._draw()

            imgui.render()
            self.impl.render(imgui.get_draw_data())

            glfw.swap_buffers(self.window)
Пример #21
0
def main():
    renderer = NXRenderer()
    currentDir = os.getcwd()

    while True:
        renderer.handleinputs()

        imgui.new_frame()

        width, height = renderer.io.display_size
        imgui.set_next_window_size(width, height)
        imgui.set_next_window_position(0, 0)
        imgui.begin("",
                    flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE
                    | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS)
        imgui.text("Welcome to PyNX!")
        imgui.text("Touch is supported")
        imgui.text("Current dir: " + os.getcwd())

        if os.getcwd() != "sdmc:/":
            imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR)
            if imgui.button("../", width=200, height=60):
                os.chdir("..")
            imgui.pop_style_color(1)

        dirs = []
        files = []
        for e in os.listdir():
            if os.path.isdir(e):
                dirs.append(e)
            else:
                files.append(e)

        dirs = sorted(dirs)
        files = sorted(files)

        for e in dirs:
            imgui.push_style_color(imgui.COLOR_BUTTON, *FOLDER_COLOR)
            if imgui.button(e + "/", width=200, height=60):
                os.chdir(e)
            imgui.pop_style_color(1)

        for e in files:
            if e.endswith(".py"):
                imgui.push_style_color(imgui.COLOR_BUTTON, *PYFILE_COLOR)
            else:
                imgui.push_style_color(imgui.COLOR_BUTTON, *FILE_COLOR)

            if imgui.button(e, width=200, height=60) and e.endswith(".py"):
                run_python_module(e)

            imgui.pop_style_color(1)

        imgui.end()

        imgui.render()
        renderer.render()

    renderer.shutdown()
Пример #22
0
    def _render_gui(self):
        w, h = self.get_size()

        imgui.new_frame()

        if self.stroke_tool and self.stroke_tool.show_rect:
            if self.stroke_tool.rect:
                rect = self.stroke_tool.rect
                p0 = self._to_window_coords(*rect.topleft)
                p1 = self._to_window_coords(*rect.bottomright)
                ui.render_selection_rectangle(self, p0, p1)

        with imgui.font(self._font):

            ui.render_menu(self)

            if self.drawing:

                imgui.set_next_window_size(115, h - 20)
                imgui.set_next_window_position(w - 115, 20)

                imgui.begin("Sidebar",
                            False,
                            flags=(imgui.WINDOW_NO_TITLE_BAR
                                   | imgui.WINDOW_NO_RESIZE
                                   | imgui.WINDOW_NO_MOVE))

                ui.render_tools(self.tools, self.icons)
                imgui.separator()

                ui.render_palette(self.drawing)
                imgui.separator()

                ui.render_layers(self.view)

                imgui.end()

                ui.render_unsaved_exit(self)
                ui.render_unsaved_close_drawing(self)

                render_plugins_ui(self.drawing)

            ui.render_new_drawing_popup(self)

            if self._error:
                imgui.open_popup("Error")
                if imgui.begin_popup_modal("Error")[0]:
                    imgui.text(self._error)
                    if imgui.button("Doh!"):
                        self._error = None
                        imgui.close_current_popup()
                    imgui.end_popup()

        imgui.render()
        imgui.end_frame()
        data = imgui.get_draw_data()
        self.imgui_renderer.render(data)
Пример #23
0
    def draw(self):
        imgui.set_next_window_position(self.window.width - 288, 32, imgui.ONCE)
        imgui.set_next_window_size(256, 256, imgui.ONCE)

        imgui.begin("Sparks")
        if imgui.button("Run"):
            self.reset()
        imgui.end()

        self.emitter.draw()
Пример #24
0
    def draw_platform_window(self, width, height):
        imgui.set_next_window_size(width / 6, height / 4)
        imgui.set_next_window_position(width * 5 / 6, 0)

        imgui.begin("Information", flags=default_flags)
        imgui.text(f"Platform:\n\t{self.platform}")
        imgui.text(f"Device: \n\t{self.device}")
        imgui.text(f"Snapshot:\n\t{self.snapshots[self.current_snapshot]}")
        imgui.text(f"Day:\n\t{self.simulator.time}")
        imgui.end()
Пример #25
0
    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()
Пример #26
0
    def update(self, curSceneGOs):
        imgui.set_next_window_position(self.position[0], self.position[1])
        imgui.set_next_window_size(self.width, self.height)
        imgui.begin("Hierarchy")

        for obj in curSceneGOs:
            self.displayGameObjectOnHierarchy(obj)
        imgui.end()

        if self.curControlObject != None and isinstance(
                self.curControlObject, GameObject):
            self.inspector.displayInspector(self.curControlObject)
Пример #27
0
def run(gui_loop_function, params=Params()):
    if params.windowed_full_screen:
        os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (
            params.windowed_full_screen_x_margin / 2,
            params.window_title_height)

    pygame.init()
    pygame.display.set_caption(params.win_title)
    win_size = params.win_size
    if params.windowed_full_screen:
        info = pygame.display.Info()
        screen_size = (info.current_w - params.windowed_full_screen_x_margin,
                       info.current_h)
        win_size = (screen_size[0], screen_size[1] -
                    params.window_title_height - params.windows_taskbar_height)

    pygame.display.set_mode(
        win_size, pygame.DOUBLEBUF | pygame.OPENGL | pygame.RESIZABLE)
    imgui_ext._load_fonts()

    io = imgui.get_io()
    io.display_size = win_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 params.provide_default_window:
            imgui.set_next_window_position(0, 0)
            imgui.set_next_window_size(win_size[0], win_size[1])
            imgui.begin("Default window")
        gui_loop_function()
        if params.provide_default_window:
            imgui.end()
        ImGuiImageLister._heartbeat()

        # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
        #       does not support fill() on OpenGL surfaces
        gl.glClearColor(1, 1, 1, 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()

        pygame.display.flip()

        imgui_cv._clear_all_cv_textures()
        imgui_ext.__clear_all_unique_labels()
Пример #28
0
def begin_maximized_window(name, glfw_window, menu_bar=False):
    imgui.set_next_window_position(0, 0)
    imgui.set_next_window_size(*glfw.get_window_size(glfw_window))
    imgui.push_style_var(imgui.STYLE_WINDOW_ROUNDING, 0)
    imgui.push_style_var(imgui.STYLE_WINDOW_BORDERSIZE, 0)
    window_flags = imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_COLLAPSE | \
        imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | \
        imgui.WINDOW_NO_BRING_TO_FRONT_ON_FOCUS | imgui.WINDOW_NO_NAV_FOCUS | \
        imgui.WINDOW_NO_DOCKING
    if menu_bar:
        window_flags |= imgui.WINDOW_MENU_BAR
    imgui.begin(name, True, window_flags)
    imgui.pop_style_var(2)
Пример #29
0
    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: empty window")
        imgui.end()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Пример #30
0
    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