Ejemplo n.º 1
0
    def render(self):
        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()

        imgui.end_frame()

        imgui.render()

        self.renderer.render(imgui.get_draw_data())
Ejemplo n.º 2
0
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")
Ejemplo n.º 3
0
def main():
    window = impl_glfw_init()
    impl = GlfwRenderer(window)
    font_scaling_factor = fb_to_window_factor(window)

    io = impl.io

    # clear font atlas to avoid downscaled default font
    # on highdensity screens. First font added to font
    # atlas will become default font.
    io.fonts.clear()

    # set global font scaling
    io.font_global_scale = 1. / font_scaling_factor

    # dictionary of font objects from our font directory
    fonts = {
        os.path.split(font_path)[-1]: io.fonts.add_font_from_file_ttf(
            font_path, FONT_SIZE_IN_PIXELS * font_scaling_factor,
            io.fonts.get_glyph_ranges_latin())
        for font_path in FONTS_DIR
    }
    secondary_window_main_font = random.choice(list(fonts.values()))

    impl.refresh_font_texture()

    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()

        imgui.new_frame()

        imgui.begin("Window with multiple custom fonts", True)
        imgui.text("This example showcases font usage on text() widget")

        for font_name, font in fonts.items():
            imgui.separator()

            imgui.text("Font:{}".format(font_name))

            with imgui.font(font):
                imgui.text("This text uses '{}' font.".format(font_name))

        imgui.end()

        with imgui.font(secondary_window_main_font):
            imgui.begin("Window one main custom font", True)
            imgui.text("This window uses same custom font for all widgets")
            imgui.end()

        gl.glClearColor(1., 1., 1., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()
        impl.render(imgui.get_draw_data())
        glfw.swap_buffers(window)

    impl.shutdown()
    glfw.terminate()
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
    def present(self):
        # __main__.SDLError: Surface doesn't have a colorkey
        SDL_RenderPresent(self.handle)
        imgui.render()
        self.imgui_impl.render(imgui.get_draw_data())

        SDL_GL_SwapWindow(self.window)
        SDL_ClearError()
Ejemplo n.º 6
0
    def render_frame(self):
        # increase frame count
        self.current_frame += 1

        # process imgui data
        imgui.new_frame()
        self.imgui_function()

        # clear buffer
        gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

        # enable opengl settings for rendering
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glEnable(gl.GL_LIGHTING)
        gl.glEnable(gl.GL_LIGHT0)
        gl.glEnable(gl.GL_COLOR_MATERIAL)

        # set up camera correctly
        gl.glMatrixMode(gl.GL_MODELVIEW)
        gl.glLoadIdentity()
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, [0.5, 0.5, 1.0, 0.0])
        gl.glTranslatef(0.0, 0.0, self.camera_distance)
        gl.glRotatef(self.camera_angles[1], 1, 0, 0)
        gl.glRotatef(self.camera_angles[0], 0, 1, 0)
        gl.glRotatef(self.camera_pre_rotation[2], 0, 0, 1)
        gl.glRotatef(self.camera_pre_rotation[1], 0, 1, 0)
        gl.glRotatef(self.camera_pre_rotation[0], 1, 0, 0)
        gl.glTranslatef(-self.camera_center[0], -self.camera_center[1],
                        -self.camera_center[2])
        self.modelview = gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX)

        # call the draw function
        self.draw_function(self.current_frame, self.clock.get_time())

        # grab framebuffer without ui if recording
        if self.recording:
            self.image_data = gl.glReadPixels(0, 0, self.window_size[0],
                                              self.window_size[1], gl.GL_RGB,
                                              gl.GL_UNSIGNED_BYTE,
                                              self.image_data)
            imageio.imwrite("image_{:04d}.jpg".format(self.recording_frame),
                            np.flipud(self.image_data))
            self.recording_frame += 1

        # draw ui on top
        gl.glDisable(gl.GL_LIGHTING)
        gl.glDisable(gl.GL_LIGHT0)
        imgui.render()
        self.imgui_impl.render(imgui.get_draw_data())

        # check for any errors
        err = gl.glGetError()
        while err != gl.GL_NO_ERROR:
            err = gl.glGetError()

        # swap double buffer
        self.clock.tick(60.0)
        pg.display.flip()
Ejemplo n.º 7
0
def imguiUpdate(select):
    impl.process_inputs()
    imgui.new_frame()
    imgui.begin("Custom window", True)
    clicked, select = imgui.listbox("Samples", select, samples, 10)
    imgui.end()
    imgui.render()
    impl.render(imgui.get_draw_data(), False)
    return clicked, select
Ejemplo n.º 8
0
    def render(self):
        super().render()

        imgui.new_frame()
        imgui.begin("debug")
        imgui.text(f"time {glfw.get_time():.2f}")
        imgui.end()
        imgui.render()
        self.imgui.render(imgui.get_draw_data())
Ejemplo n.º 9
0
    def update(self):
        self.impl.process_inputs()
        imgui.new_frame()

        self.on_gui and self.on_gui()
        self.on_gui_editor and self.on_gui_editor()

        imgui.render()
        self.impl.render(imgui.get_draw_data())
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def main_sdl2():
    def pysdl2_init():
        width, height = 1280, 720
        window_name = "minimal ImGui/SDL2 example"
        if SDL_Init(SDL_INIT_EVERYTHING) < 0:
            print("Error: SDL could not initialize! SDL Error: " + SDL_GetError())
            exit(1)
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1)
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)
        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8)
        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1)
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1)
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 16)
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG)
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4)
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1)
        SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE)
        SDL_SetHint(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, b"1")
        SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, b"1")
        window = SDL_CreateWindow(window_name.encode('utf-8'),
                                SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                                width, height,
                                SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE)
        if window is None:
            print("Error: Window could not be created! SDL Error: " + SDL_GetError())
            exit(1)
        gl_context = SDL_GL_CreateContext(window)
        if gl_context is None:
            print("Error: Cannot create OpenGL Context! SDL Error: " + SDL_GetError())
            exit(1)
        SDL_GL_MakeCurrent(window, gl_context)
        if SDL_GL_SetSwapInterval(1) < 0:
            print("Warning: Unable to set VSync! SDL Error: " + SDL_GetError())
            exit(1)
        return window, gl_context
    window, gl_context = pysdl2_init()
    renderer = SDL2Renderer(window)
    running = True
    event = SDL_Event()
    while running:
        while SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == SDL_QUIT:
                running = False
                break
            renderer.process_event(event)
        renderer.process_inputs()
        imgui.new_frame()
        on_frame()
        gl.glClearColor(1., 1., 1., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()
        SDL_GL_SwapWindow(window)
    renderer.shutdown()
    SDL_GL_DeleteContext(gl_context)
    SDL_DestroyWindow(window)
    SDL_Quit()
Ejemplo n.º 12
0
def draw(s, impl):
    MainFrame.draw(impl)

    # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
    #       does not support fill() on OpenGL sufraces
    gl.glClearColor(0.3, 0.4, 0.4, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    imgui.render()
    impl.render(imgui.get_draw_data())
    pygame.display.flip()
Ejemplo n.º 13
0
    def exec_snippet(self, source):

        # Strip out new_frame/end_frame from source
        if "# later" in source:
            raise Skipped(msg="multi-stage snippet, can't comprehend")

        lines = [
            line
            if all([
                "imgui.new_frame()" not in line,
                "imgui.render()" not in line,
                "imgui.end_frame()" not in line
            ]) else ""
            for line in
            source.split('\n')
        ]
        source = "\n".join(lines)

        if (
            "import array" in source
            and sys.version_info < (3, 0)
        ):
            pytest.skip(
                "array.array does not work properly under py27 as memory view"
            )

        code = compile(source, '<str>', 'exec')
        frameinfo = getframeinfo(currentframe())

        imgui.create_context()
        io = imgui.get_io()
        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()

        exec_ns = _ns(locals(), globals())

        try:
            exec(code, exec_ns, exec_ns)
        except Exception as err:
            # note: quick and dirty way to annotate sources with error marker
            print_exc()
            lines = source.split('\n')
            lines.insert(sys.exc_info()[2].tb_next.tb_lineno, "^^^")
            self.code = "\n".join(lines)
            imgui.end_frame()
            raise

        imgui.render()
Ejemplo n.º 14
0
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()

        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.same_line()
        imgui.text_colored("Eggs", 0.2, 1., 0.)
        #imgui.same_line()
        imgui.bullet_text("bullet_text")
        # 不换行
        #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()
        impl.render(imgui.get_draw_data())

        pygame.display.flip()
Ejemplo n.º 15
0
def on_draw(dt):
    app.clock.tick()
    window.clear()

    impl.process_inputs()

    imgui.new_frame()
    imgui.show_test_window()

    imgui.render()
    impl.render(imgui.get_draw_data())
Ejemplo n.º 16
0
def draw(s, impl):
    MainFrame.draw(impl)

    # note: cannot use screen.fill((1, 1, 1)) because pygame's screen
    #       does not support fill() on OpenGL sufraces
    x = math.fabs(math.sin(time.time()))
    y = math.fabs(math.cos(time.time()))
    gl.glClearColor(x, y, x, 1)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)
    imgui.render()
    impl.render(imgui.get_draw_data())
    pygame.display.flip()
Ejemplo n.º 17
0
    def render_ui(self):

        # Test window
        imgui.new_frame()
        imgui.begin("Custom window", True)
        imgui.text("Bar")
        imgui.text_colored("Eggs", 0.2, 1., 0.)
        imgui.end()

        # Render
        imgui.render()
        self.imgui.render(imgui.get_draw_data())
Ejemplo n.º 18
0
    def render_ui(self):
        imgui.new_frame()
        imgui.begin("camera")

        is_change_y, self.u_campos.y = imgui.slider_float(
            "y", self.u_campos.y, -3.14159 * 4.0, 3.14159 * 4.0)
        if is_change_y:
            self.uniform("u_campos", self.u_campos)

        imgui.end()
        imgui.render()
        self.imgui.render(imgui.get_draw_data())
Ejemplo n.º 19
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()
Ejemplo n.º 20
0
    def draw_imgui(self):
        io = self.io
        # start new frame context
        imgui.new_frame()
        if self.activate_plots:
            self.plot_manager.render_imgui()
        if self.show_console:
            self.console.render_lines()

        imgui.render()
        data = imgui.get_draw_data()
        self.imgui_renderer.render(data)
        imgui.end_frame()
Ejemplo n.º 21
0
def main():
    pygame.init()
    clock = pygame.time.Clock()
    size = 640, 480

    pygame.display.set_mode(size, pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.OPENGL)

    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("File", True):

                clicked_quit, selected_quit = imgui.menu_item(
                    "Quit", 'Cmd+Q', False, True
                )

                if clicked_quit:
                    pygame.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()

        # 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()
        clock.tick(60)
Ejemplo n.º 22
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())
Ejemplo n.º 23
0
def main():
    window, gl_context = impl_pysdl2_init()
    impl = SDL2Impl(window)

    opened = True

    running = True
    event = SDL_Event()
    while running:
        while SDL_PollEvent(ctypes.byref(event)) != 0:
            if event.type == SDL_QUIT:
                running = False
                break
            impl.process_event(event)
        impl.process_inputs()

        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_user_guide()
        imgui.show_test_window()

        if opened:
            expanded, opened = imgui.begin("fooo", True)
            imgui.text("Bar")
            imgui.text_colored("Eggs", 0.2, 1., 0.)
            imgui.end()

        with imgui.styled(imgui.STYLE_ALPHA, 1):
            imgui.show_metrics_window()

        gl.glClearColor(114 / 255., 144 / 255., 154 / 255., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()

        SDL_GL_SwapWindow(window)

    impl.shutdown()
    SDL_GL_DeleteContext(gl_context)
    SDL_DestroyWindow(window)
    SDL_Quit()
Ejemplo n.º 24
0
 def run(self):
     while 1:
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 sys.exit()
             self.impl.process_event(event)
         imgui.new_frame()
         # render game elements
         # render gui
         gl.glClearColor(1, 1, 1, 1)
         gl.glClear(gl.GL_COLOR_BUFFER_BIT)
         imgui.render()
         self.impl.render(imgui.get_draw_data())
         pygame.display.flip()
Ejemplo n.º 25
0
def main():
    imgui.create_context()
    window = impl_glfw_init()
    impl = GlfwRenderer(window)
    _ = gl.glGenFramebuffers(1)

    videoWindows = []

    def dropFile(window, files):
        for file in files:
            videoWindows.append(VideoPlayer(file))

    glfw.set_drop_callback(window, dropFile)

    while not glfw.window_should_close(window):

        glfw.poll_events()
        impl.process_inputs()

        imgui.new_frame()

        videoWindows = [x for x in videoWindows if x.open]
        if len(videoWindows) > 0:
            for videoWindow in videoWindows:
                videoWindow.render()
        else:
            imgui.core.set_next_window_position(10, 10)
            winw, winh = glfw.get_window_size(window)
            imgui.core.set_next_window_size(winw - 20, 10)

            imgui.begin("##Message",
                        True,
                        flags=imgui.WINDOW_NO_SCROLLBAR
                        | imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_TITLE_BAR
                        | imgui.WINDOW_NO_MOVE)
            imgui.text("Drop one or more video files onto this window to play")
            imgui.end()

        gl.glClearColor(0., 0., 0., 1.)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()
        impl.render(imgui.get_draw_data())
        glfw.swap_buffers(window)

    for videoWindow in videoWindows:
        videoWindow.terminate()
    impl.shutdown()
    glfw.terminate()
Ejemplo n.º 26
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
Ejemplo n.º 27
0
def main():
    imgui.create_context()
    window = impl_glfw_init()
    impl = GlfwRenderer(window)
    ip_address = "localhost:3333"
    #imgui.set_window_font_scale(1.0)
    comms = MouseSocket()
    click_guard = True

    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()
        imgui.new_frame()
        imgui.set_next_window_size(300, 120)
        imgui.set_next_window_position(10, 0)
        imgui.begin("", False, imgui.WINDOW_NO_RESIZE)
        changed, ip_address = imgui.input_text(label="IP:PORT",
                                               value=ip_address,
                                               buffer_length=30)
        clicked = imgui.button(label="CONNECT")
        if clicked:
            comms.connect(ip_address)

        max_x, max_y = glfw.get_window_size(window)
        x, y = glfw.get_cursor_pos(window)

        norm_x = x / max_x
        norm_y = y / max_y

        state = glfw.get_mouse_button(window, glfw.MOUSE_BUTTON_LEFT)
        if state == glfw.PRESS:
            click_guard = False
        elif state == glfw.RELEASE and not click_guard:
            click_guard = True
            comms.send_click(norm_x, norm_y)

        comms.send_mouse_coords(norm_x, norm_y)

        imgui.text("Mouse Coords: {:.2f}, {:.2f}".format(norm_x, norm_y))
        imgui.text("Connected: {}".format(comms.is_connected))
        imgui.end()

        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()
        impl.render(imgui.get_draw_data())
        glfw.swap_buffers(window)

    impl.shutdown()
    glfw.terminate()
Ejemplo n.º 28
0
def main():
    desktop = Desktop()
    imgui.create_context()
    window = core.impl_glfw_init()
    impl = GlfwRenderer(window)
    imgui.core.style_colors_light()

    app_list = list(get_app_list())

    # figure = plt.figure()
    # img = Image.open('./test.png')
    # texture, width, height = readImage(img)

    def update():
        imgui.new_frame()
        if imgui.begin_main_menu_bar():
            if imgui.begin_menu("System", True):
                for app in app_list:
                    clicked, selected = imgui.menu_item(
                        app.__name__, '', False, True)
                    if clicked:
                        desktop.add(app())
                imgui.separator()
                clicked_quit, selected_quit = imgui.menu_item(
                    "Quit", '', False, True)

                if clicked_quit:
                    exit(1)

                imgui.end_menu()
            imgui.end_main_menu_bar()

        desktop.render()

    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()
        update()

        gl.glClearColor(1., 1., 1., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)
        imgui.render()
        data = imgui.get_draw_data()
        impl.render(data)

        glfw.swap_buffers(window)

    impl.shutdown()
    glfw.terminate()
Ejemplo n.º 29
0
def main():
    window = impl_glfw_init()
    impl = GlfwRenderer(window)

    box1 = box2 = box3 = True

    while not glfw.window_should_close(window):
        glfw.poll_events()
        impl.process_inputs()

        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.begin("Scope Test")

        box1 = imgui.checkbox("Checkbox", box1)[1]

        with imgui.scope(2):
            imgui.new_line()
            imgui.text("Same name, different scope:")
            box2 = imgui.checkbox("Checkbox", box2)[1]

        imgui.new_line()
        imgui.text("Same name, same scope:")
        imgui.text("(This will not work right)")
        box3 = imgui.checkbox("Checkbox", box3)[1]

        imgui.end()

        gl.glClearColor(1., 1., 1., 1)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        imgui.render()
        glfw.swap_buffers(window)

    impl.shutdown()
    imgui.shutdown()
    glfw.terminate()
Ejemplo n.º 30
0
    def render_ui(self):
        imgui.new_frame()

        imgui.begin("Description - Histogram", False)
        imgui.text("Shows the histogram of a selected photo")
        imgui.text("FPS: %.2f" % self.fps)
        imgui.end()


        imgui.begin("Controls - Histogram", False)
        imgui.text("Press P to select a photo")
        imgui.end()

        imgui.render()
        self.imgui.render(imgui.get_draw_data())
Ejemplo n.º 31
0
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] = ...
#
#
Ejemplo n.º 32
0
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()