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()
while True: w, h = core.viewSize() curX = 0 curY = 0 press = 0 touch = core.singleTouch() if touch != None: curX = touch['cur_x'] + w // 2 curY = -touch['cur_y'] + h // 2 press = touch['is_holded'] | touch['is_moved'] impl.process_inputs() core.update() 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("Custom window", True) imgui.text("Virtual Keyboard : " + str(core.isVirtualKeyboardShown())) imgui.text("Value: " + core.getInputText()) if imgui.button("Show Virtual Keyboard"): core.showVirtualKeyboard()
def render_ui(self): imgui.new_frame() imgui.show_demo_window() imgui.render() self._ui.render(imgui.get_draw_data()) self._ui.process_inputs()
def view_obj(filename, display_surf): #pygame.init() #pygame.display.set_caption('Your Model') viewport = (800,600) hx = viewport[0]/2 hy = viewport[1]/2 display_surf = pygame.display.set_mode(viewport, OPENGL | DOUBLEBUF) imgui.create_context() #Does not work with pygame 2.0+ impl = CustomRenderer() io = imgui.get_io() io.display_size = viewport #Toggle visibility of hat #displayHat = False #Toggle which hat to display (0 = None, 1 = Leather Hat, 2 = Santa Hat) current = 0 glLightfv(GL_LIGHT0, GL_POSITION, (-40, 200, 100, 0.0)) glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, 0.2, 0.2, 1.0)) glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1.0)) glEnable(GL_LIGHT0) glEnable(GL_LIGHTING) glEnable(GL_COLOR_MATERIAL) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) # most obj files expect to be smooth-shaded # LOAD OBJECT AFTER PYGAME INIT hats = [ OBJ_vbo('hats/new_leather_hat.OBJ'), #Leather Hat OBJ_vbo('hats/bigger_santahat.OBJ') #Santa Hat ] hat_vals = [ [[0,0,0], [0,0,0]], [[0,-90,0], [0,-76,96]], #(rx, ry, rz), (tx, ty, tz) [[-175,88, 0], [0, 50, 130]] ] #hat = OBJ_vbo('hats/new_leather_hat.OBJ') output = OBJ_vbo(filename) clock = pygame.time.Clock() glMatrixMode(GL_PROJECTION) glLoadIdentity() width, height = viewport gluPerspective(90.0, width/float(height), 1, 500.0) glEnable(GL_DEPTH_TEST) glMatrixMode(GL_MODELVIEW) glLoadIdentity() model_1 = glGetDoublev(GL_MODELVIEW_MATRIX) model_2 = model_1 #Head model rotational and translational values rx, ry, rz = (-175,88, 0) #Values found through trial and error tx, ty = (0,0) #Current hat rotational and translational values rx_h, ry_h, rz_h = (0,0,0) tx_h, ty_h, tz_h = (0,0,0) zpos = 265 rotate = move = False is_running = True while is_running: time_delta = clock.tick(60)/1000.0 for e in pygame.event.get(): if e.type == QUIT: pygame.quit() elif e.type == KEYDOWN: if e.key == K_ESCAPE: is_running = False elif e.type == MOUSEBUTTONDOWN: if e.button == 4: zpos = max(1, zpos-1) elif e.button == 5: zpos += 1 elif e.button == 1: rotate = True elif e.button == 3: move = True elif e.type == MOUSEBUTTONUP: if e.button == 1: rotate = False elif e.button == 3: move = False elif e.type == MOUSEMOTION: i, j = e.rel if not imgui.core.is_any_item_active(): if rotate: if rz + i <= 60 and rz + i >= -60: rz += i for k in range(1, len(hat_vals)): #rz_h += i hat_vals[k][0][2] += i if move: tx += i ty -= j rx += i rx -= i if e.type != 16: #If not video resize event impl.process_event(e) imgui.new_frame() imgui.begin("Options", True, flags=imgui.WINDOW_NO_RESIZE) imgui.set_window_size(200,200) clicked, current = imgui.listbox("Hats", current, ["None", "Leather Hat", "Santa Hat"]) rx_h, ry_h, rz_h = hat_vals[current][0] tx_h, ty_h, tz_h = hat_vals[current][1] imgui.end() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_MODELVIEW) glPushMatrix() glLoadIdentity() model_1 = glGetDoublev(GL_MODELVIEW_MATRIX) # RENDER OBJECT glTranslate(tx/20, ty/20., - zpos) glRotate(ry, 1, 0, 0) glRotate(rx, 0, 1, 0) glRotate(rz, 0, 0, 1) #glScalef(0.1,0.1,0.1) glMultMatrixf(model_1) model_1 = glGetDoublev(GL_MODELVIEW_MATRIX) output.render() glPopMatrix() glPushMatrix() glLoadIdentity() model_2 = glGetDoublev(GL_MODELVIEW_MATRIX) glTranslate(tx/20, ty/20, -zpos) glRotate(ry_h, 1, 0, 0) glRotate(rx_h, 0, 1, 0) glRotate(rz_h, 0, 0, 1) glTranslate(0,ty_h,tz_h) #glRotate(hat_vals[current][0][1], 1, 0, 0) #glRotate(hat_vals[current][0][0], 0, 1, 0) #glRotate(hat_vals[current][0][2], 0, 0, 1) #glTranslate(0,hat_vals[current][1][1],hat_vals[current][1][2]) glMultMatrixf(model_2) model_2 = glGetDoublev(GL_MODELVIEW_MATRIX) if current != 0: hats[current - 1].render() glPopMatrix() imgui.render() impl.render(imgui.get_draw_data()) pygame.display.flip() display_surf = pygame.display.set_mode((640,480))
def main(): fail_exception = None status = WindowState.MAIN_MENU try: local_json, remote_json = fetch_json() except: fail_exception = traceback.format_exc() status = WindowState.FAILED else: if VERSION != remote_json["updater"]: status = WindowState.SELF_UPDATE_AVAILABLE can_update = False renderer = NXRenderer() 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("SwitchGuide Updater", flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS | imgui.WINDOW_NO_COLLAPSE) imgui.set_window_font_scale(2.0) if status is WindowState.MAIN_MENU: imgui.begin_group() imgui.text("Atmosphere Updater") imgui.text("Loaded Atmosphere version: {}\nRemote Atmosphere version: {}".format(local_json["atmosphere"], remote_json["atmosphere"])) if imgui.button("Update Atmosphere"): status = WindowState.UPDATING_AMS imgui.end_group() imgui.separator() imgui.begin_group() imgui.text("Loaded Hekate version: {}\nRemote Hekate version: {}" .format(local_json["hekate"], remote_json["hekate"])) if imgui.button("Update Hekate"): status = WindowState.UPDATING_HEKATE imgui.end_group() imgui.separator() imgui.begin_group() imgui.text("Loaded nx-hbmenu version: {}\nRemote nx-hbmenu version: {}" .format(local_json["nx-hbmenu"], remote_json["nx-hbmenu"])) imgui.text("Loaded nx-hbloader version: {}\nRemote nx-hbloader version: {}" .format(local_json["nx-hbloader"], remote_json["nx-hbloader"])) if imgui.button("Update nx-hbmenu"): status = WindowState.UPDATING_NX_HBMENU imgui.same_line() if imgui.button("Update nx-hbloader"): status = WindowState.UPDATING_NX_HBLOADER imgui.end_group() imgui.separator() imgui.text("SwitchGuide Updater {}".format(VERSION)) imgui.text("© 2018 - Valentijn \"noirscape\" V.") elif status is WindowState.SELF_UPDATE_AVAILABLE: imgui.begin_group() imgui.text("An update for SwitchGuide-Updater is available.") imgui.end_group() imgui.separator() if imgui.button("Install version {}".format(remote_json["updater"])): status = WindowState.UPDATING_SELF if imgui.button("Keep running version {}".format(VERSION)): status = WindowState.MAIN_MENU elif status is WindowState.UPDATING_AMS: imgui.text("Updating Atmosphere to version {}...".format(remote_json["atmosphere"])) can_update = True elif status is WindowState.UPDATING_HEKATE: imgui.text("Updating Hekate to version {}...".format(remote_json["hekate"])) can_update = True elif status is WindowState.UPDATING_SELF: imgui.text("Updating SwitchGuide-Updater to version {}...".format(remote_json["updater"])) can_update = True elif status is WindowState.UPDATING_NX_HBLOADER: imgui.text("Updating nx-hbloader to version {}...".format(remote_json["nx-hbloader"])) can_update = True elif status is WindowState.UPDATING_NX_HBMENU: imgui.text("Updating nx-hbmenu to version {}...".format(remote_json["nx-hbmenu"])) can_update = True elif status is WindowState.SELF_UPDATE_SUCCEEDED: imgui.text("Succesfully updated SwitchGuide-Updater") imgui.text("Press HOME to exit and reopen PyNX to run this application.") elif status is WindowState.FAILED: imgui.text(str(fail_exception)) imgui.end() imgui.render() renderer.render() if status is WindowState.UPDATING_AMS and can_update: try: update_atmosphere() except: fail_exception = traceback.format_exc() status = WindowState.FAILED else: try: write_update_file(local_json, remote_json, updated_ams=True) local_json, remote_json = fetch_json() status = WindowState.MAIN_MENU can_update = False except: fail_exception = traceback.format_exc() status = WindowState.FAILED elif status is WindowState.UPDATING_HEKATE and can_update: try: update_hekate() except: fail_exception = traceback.format_exc() status = WindowState.FAILED else: try: write_update_file(local_json, remote_json, updated_hekate=True) local_json, remote_json = fetch_json() status = WindowState.MAIN_MENU can_update = False except: fail_exception = traceback.format_exc() status = WindowState.FAILED elif status is WindowState.UPDATING_SELF and can_update: try: update_self() except: fail_exception = traceback.format_exc() status = WindowState.FAILED else: status = WindowState.SELF_UPDATE_SUCCEEDED can_update = False elif status is WindowState.UPDATING_NX_HBLOADER and can_update: try: update_nx_hbloader() except: fail_exception = traceback.format_exc() status = WindowState.FAILED else: try: write_update_file(local_json, remote_json, updated_nx_hbloader=True) local_json, remote_json = fetch_json() status = WindowState.MAIN_MENU can_update = False except: fail_exception = traceback.format_exc() status = WindowState.FAILED elif status is WindowState.UPDATING_NX_HBMENU and can_update: try: update_nx_hbmenu() except: fail_exception = traceback.format_exc() status = WindowState.FAILED else: try: write_update_file(local_json, remote_json, updated_nx_hbmenu=True) local_json, remote_json = fetch_json() status = WindowState.MAIN_MENU can_update = False except: fail_exception = traceback.format_exc() status = WindowState.FAILED renderer.shutdown()
def interface(): 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() if imgui.begin_menu('Windows', True): clicked_fixtureC, selected_fixtureC = imgui.menu_item( 'Fixture Controls', shortcut=None) if clicked_fixtureC: if values.showFixtureControl: values.showFixtureControl = False else: values.showFixtureControl = True imgui.end_menu() imgui.end_main_menu_bar() if values.showFixtureControl: imgui.begin("Fixture Control", True) for r in patch.rooms.values(): expanded, visible = imgui.collapsing_header(r.name) if expanded: imgui.indent() for f in r.fixtureList: expanded, visible = imgui.collapsing_header(f.name) rgb = values.values[f.name] if expanded: imgui.columns(2, f.name) imgui.indent() imgui.text('Red') changed, value = imgui.slider_int( '##int%sred' % f.name, rgb[0], 0, 255) if changed: rgb[0] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.text('Green') changed, value = imgui.slider_int( '##int%sgreen' % f.name, rgb[1], 0, 255) if changed: rgb[1] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.text('Blue') changed, value = imgui.slider_int( '##int%sblue' % f.name, rgb[2], 0, 255) if changed: rgb[2] = value ui.cache(f.setColor, [rgb, 0.2]) ui.update() imgui.next_column() imgui.color_button('Color Sample', rgb[0] / 255, rgb[1] / 255, rgb[2] / 255, width=100, height=100) imgui.columns(1) imgui.unindent() imgui.unindent() imgui.same_line(spacing=50) imgui.end()
def run( gui_loop_function, params=Params(), on_init = None, on_exit = None): if params.windowed_full_screen: os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % ( params.windowed_full_screen_x_margin / 2, params.window_title_height) imgui.create_context() 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 pygame_renderer = PygameRenderer() # if on_exit: # pygame.register_quit(on_exit) if on_init: on_init() while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: if on_exit: on_exit() try: sys.exit() except SystemExit as e: time.sleep(0.5) # sys.exit() # sys.terminate() os._exit(1) pygame_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_renderer.render(imgui.get_draw_data()) pygame.display.flip() imgui_cv._clear_all_cv_textures() imgui_ext.__clear_all_unique_labels()
def update(self, dt): imgui.new_frame() self.entities_gui() self.components_gui()
def main(): global ERROR 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.begin_group() 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_group() # end of file picker imgui.same_line(spacing=50) imgui.begin_group() imgui.text("Utils:") imgui.push_style_color(imgui.COLOR_BUTTON, *APP_COLOR) if imgui.button("Interactive Python", width=200, height=60): t = Terminal() t.main() imgui.pop_style_color(1) imgui.end_group() imgui.end() if ERROR: imgui.set_next_window_size(width, height) imgui.set_next_window_position(0, 0) imgui.begin("ERROR", flags=imgui.WINDOW_NO_RESIZE | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS) imgui.text(str(ERROR)) if imgui.button("OK", width=200, height=60): ERROR = "" imgui.end() imgui.render() renderer.render() renderer.shutdown()
def main_sdl2(): def pysdl2_init(): width, height = 1280, 800 window_name = "Map Edit" 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() render_3d.init_sdl_window() while running: while SDL_PollEvent(ctypes.byref(event)) != 0: if event.type == SDL_QUIT: running = False break elif event.type == SDL_WINDOWEVENT and event.window.event == SDL_WINDOWEVENT_CLOSE: 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() renderer.render(imgui.get_draw_data()) SDL_GL_SwapWindow(window) renderer.shutdown() SDL_GL_DeleteContext(gl_context) SDL_DestroyWindow(window) SDL_Quit()