def __init__( self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1)): if len(__windows__) > 0: log.critical( """SDL backend cannot have more than one window.\n""" """Exiting...""") sys.exit(0) window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) flags = __flags__ if self._decoration == False: flags = __flags__ | pygame.NOFRAME pygame.display.set_mode((width, height), flags) pygame.display.set_caption(self._title) __windows__.append(self)
def __init__( self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1)): """ """ window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) flags = sdl2.SDL_WINDOW_SHOWN # flags |= sdl2.SDL_WINDOW_ALLOW_HIGHDPI flags |= sdl2.SDL_WINDOW_RESIZABLE flags |= sdl2.SDL_WINDOW_OPENGL if visible: flags |= sdl2.SDL_WINDOW_SHOWN else: flags |= SDL_WINDOW_HIDDEN if not decoration: flags |= sdl2.SDL_WINDOW_BORDERLESS self._native_window = sdl2.SDL_CreateWindow(self._title, sdl2.SDL_WINDOWPOS_UNDEFINED, sdl2.SDL_WINDOWPOS_UNDEFINED, width, height, flags) self._native_context = sdl2.SDL_GL_CreateContext(self._native_window) self._native_id = sdl2.SDL_GetWindowID(self._native_window) sdl2.SDL_GL_SetSwapInterval(0) # OSX: check framebuffer size / window size. On retina display, they # can be different so we try to correct window size such as having # the framebuffer size of the right size # w,h = ctypes.c_int(),ctypes.c_int() # sdl2.SDL_GL_GetDrawableSize(self._native_window, w, h) # w,h = w.value(), h.value() # if w != width or h!= height: # width = width/2 # height= height/2 # sdl2.SDL_SetWindowSize(self._native_window, int(width), int(height)) self._height = height self._width = width __windows__[self._native_id] = self
def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0, 0, 0, 1), vsync=False): if vsync: log.warn('vsync not implemented for freeglut backend') if len(__windows__) > 0: log.critical( """OSXGLUT backend is unstable with more than one window.\n""" """Exiting...""") sys.exit(0) window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) self._native_window = glut.glutCreateWindow(self._title) if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutWMCloseFunc(self._close) glut.glutDisplayFunc(self._display) glut.glutReshapeFunc(self._reshape) glut.glutKeyboardFunc(self._keyboard) glut.glutKeyboardUpFunc(self._keyboard_up) glut.glutMouseFunc(self._mouse) glut.glutMotionFunc(self._motion) glut.glutPassiveMotionFunc(self._passive_motion) glut.glutVisibilityFunc(self._visibility) glut.glutEntryFunc(self._entry) glut.glutSpecialFunc(self._special) glut.glutSpecialUpFunc(self._special_up) glut.glutReshapeWindow(self._width, self._height) if visible: glut.glutShowWindow() else: glut.glutHideWindow() # This ensures glutCheckLoop never blocks def on_idle(): pass glut.glutIdleFunc(on_idle) __windows__.append(self)
def __init__(self, width=512, height=512, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0, 0, 0, 1), vsync=False): window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) # Whether hidpi is active self._hidpi = False def on_error(error, message): log.warning(message) glfw.glfwSetErrorCallback(on_error) glfw.glfwWindowHint(glfw.GLFW_RESIZABLE, True) glfw.glfwWindowHint(glfw.GLFW_DECORATED, True) glfw.glfwWindowHint(glfw.GLFW_VISIBLE, True) if not decoration: glfw.glfwWindowHint(glfw.GLFW_DECORATED, False) if not visible: glfw.glfwWindowHint(glfw.GLFW_VISIBLE, False) if config is None: config = configuration.Configuration() set_configuration(config) self._native_window = glfw.glfwCreateWindow(self._width, self._height, self._title, None, None) if not self._native_window: log.critical("Window creation failed") __exit__() sys.exit() glfw.glfwMakeContextCurrent(self._native_window) glfw.glfwSwapInterval(1 if vsync else 0) # OSX: check framebuffer size / window size. On retina display, they # can be different so we try to correct window size such as having # the framebuffer size of the right size w, h = glfw.glfwGetFramebufferSize(self._native_window) if w != width or h != height: width, height = width // 2, height // 2 glfw.glfwSetWindowSize(self._native_window, width, height) log.info("HiDPI detected, fixing window size") self._hidpi = True def on_framebuffer_resize(win, width, height): self._width, self._height = width, height self.dispatch_event('on_resize', width, height) glfw.glfwSetFramebufferSizeCallback(self._native_window, on_framebuffer_resize) # def on_resize(win, width, height): # self._width, self._height = width, height # self.dispatch_event('on_resize', width, height) # glfw.glfwSetWindowSizeCallback(self._native_window, on_resize) def on_cursor_enter(win, entered): if entered: self.dispatch_event('on_enter') else: self.dispatch_event('on_leave') glfw.glfwSetCursorEnterCallback(self._native_window, on_cursor_enter) def on_window_close(win): self.close() glfw.glfwSetWindowCloseCallback(self._native_window, on_window_close) def on_keyboard(win, key, scancode, action, mods): symbol = self._keyboard_translate(key) modifiers = self._modifiers_translate(mods) if action in [glfw.GLFW_PRESS, glfw.GLFW_REPEAT]: self.dispatch_event('on_key_press', symbol, modifiers) else: self.dispatch_event('on_key_release', symbol, modifiers) glfw.glfwSetKeyCallback(self._native_window, on_keyboard) def on_character(win, character): self.dispatch_event('on_character', u"%c" % character) glfw.glfwSetCharCallback(self._native_window, on_character) def on_mouse_button(win, button, action, mods): x, y = glfw.glfwGetCursorPos(win) if self._hidpi: x, y = 2 * x, 2 * y button = __mouse_map__.get(button, window.mouse.UNKNOWN) if action == glfw.GLFW_RELEASE: self._button = window.mouse.NONE self._mouse_x = x self._mouse_y = y self.dispatch_event('on_mouse_release', x, y, button) elif action == glfw.GLFW_PRESS: self._button = button self._mouse_x = x self._mouse_y = y self.dispatch_event('on_mouse_press', x, y, button) glfw.glfwSetMouseButtonCallback(self._native_window, on_mouse_button) def on_mouse_motion(win, x, y): if self._hidpi: x, y = 2 * x, 2 * y dx = x - self._mouse_x dy = y - self._mouse_y self._mouse_x = x self._mouse_y = y if self._button != window.mouse.NONE: self.dispatch_event('on_mouse_drag', x, y, dx, dy, self._button) else: self.dispatch_event('on_mouse_motion', x, y, dx, dy) glfw.glfwSetCursorPosCallback(self._native_window, on_mouse_motion) def on_scroll(win, xoffset, yoffset): x, y = glfw.glfwGetCursorPos(win) if self._hidpi: x, y = 2 * x, 2 * y self.dispatch_event('on_mouse_scroll', x, y, xoffset, yoffset) glfw.glfwSetScrollCallback(self._native_window, on_scroll) self._width, self._height = self.get_size() __windows__.append(self)
def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0, 0, 0, 1), vsync=False): window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) __glformat__.setSwapInterval(1 if vsync else 0) self._native_app = QtWidgets.QApplication.instance() if self._native_app is None: self._native_app = QtWidgets.QApplication(sys.argv) context = QtOpenGL.QGLContext(__glformat__) if context.isValid(): self._native_window = QtOpenGL.QGLWidget(context) else: self._native_window = QtOpenGL.QGLWidget(__glformat__) self._native_window.resize(width, height) self._native_window.makeCurrent() self._native_window.setAutoBufferSwap(False) self._native_window.setMouseTracking(True) self._native_window.setWindowTitle(self._title) def paint_gl(): self.dispatch_event("on_draw", 0.0) self._native_window.paintGL = paint_gl def resize_gl(width, height): self.dispatch_event("on_resize", width, height) self._native_window.resizeGL = resize_gl def close_event(event): __windows__.remove(self) for i in range(len(self._timer_stack)): handler, interval = self._timer_stack[i] self._clock.unschedule(handler) self.dispatch_event("on_close") self._native_window.closeEvent = close_event def mouse_press_event(event): x = event.pos().x() y = event.pos().y() button = __mouse_map__.get(event.button(), window.mouse.UNKNOWN) self._button = button self._mouse_x = x self._mouse_y = y self.dispatch_event("on_mouse_press", x, y, button) self._native_window.mousePressEvent = mouse_press_event def mouse_release_event(event): x = event.pos().x() y = event.pos().y() button = __mouse_map__.get(event.button(), window.mouse.UNKNOWN) self._button = window.mouse.NONE self._mouse_x = x self._mouse_y = y self.dispatch_event("on_mouse_release", x, y, button) self._native_window.mouseReleaseEvent = mouse_release_event def mouse_move_event(event): x = event.pos().x() y = event.pos().y() dx = x - self._mouse_x dy = y - self._mouse_y self._mouse_x = x self._mouse_y = y if self._button is not window.mouse.NONE: self.dispatch_event('on_mouse_drag', x, y, dx, dy, self._button) else: self.dispatch_event('on_mouse_motion', x, y, dx, dy) self._native_window.mouseMoveEvent = mouse_move_event def wheel_event(event): offset_x = event.angleDelta().x() offset_y = event.angleDelta().y() x = event.pos().x() y = event.pos().y() self.dispatch_event("on_mouse_scroll", x, y, offset_x / 10.0, offset_y / 10.0) self._native_window.wheelEvent = wheel_event def key_press_event(event): code = self._keyboard_translate(event.key()) modifiers = self._modifiers_translate(event.modifiers()) self.dispatch_event("on_key_press", code, modifiers) self.dispatch_event("on_character", event.text()) self._native_window.keyPressEvent = key_press_event def key_release_event(event): code = self._keyboard_translate(event.key()) modifiers = self._modifiers_translate(event.modifiers()) self.dispatch_event("on_key_release", code, modifiers) self._native_window.keyReleaseEvent = key_release_event self._native_window.show() __windows__.append(self)
def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0, 0, 0, 1), vsync=False): window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) self._native_window = pyglet.window.Window(width=self._width, height=self._height, caption=title, resizable=True, vsync=vsync, config=__configuration__) def on_mouse_drag(x, y, dx, dy, button, modifiers): # BUGFIX self.dispatch_event("on_mouse_drag", x, y, dx, -dy, button) self._native_window.on_mouse_drag = on_mouse_drag def on_mouse_enter(x, y): y = self.height - y self.dispatch_event("on_enter", x, y) self._native_window.on_mouse_enter = on_mouse_enter def on_mouse_leave(x, y): y = self.height - y self.dispatch_event("on_leave", x, y) self._native_window.on_mouse_leave = on_mouse_leave def on_mouse_motion(x, y, dx, dy): self.dispatch_event("on_mouse_motion", x, y, dx, -dy) self._native_window.on_mouse_motion = on_mouse_motion def on_mouse_press(x, y, button, modifiers): self.dispatch_event("on_mouse_press", x, y, button) self._native_window.on_mouse_press = on_mouse_press def on_mouse_release(x, y, button, modifiers): self.dispatch_event("on_mouse_release", x, y, button) self._native_window.on_mouse_release = on_mouse_release def on_mouse_scroll(x, y, scroll_x, scroll_y): # BUGFIX y = self.height - y self.dispatch_event("on_mouse_scroll", x, y, scroll_x, -scroll_y) self._native_window.on_mouse_scroll = on_mouse_scroll def on_resize(width, height): self.dispatch_event("on_resize", width, height) self._native_window.on_resize = on_resize def on_show(): self.dispatch_event("on_show") self._native_window.on_show = on_show def on_hide(): self.dispatch_event("on_hide") self._native_window.on_hide = on_hide def on_close(): self.close() self._native_window.on_close = on_close def on_key_press(symbol, modifiers): self.dispatch_event("on_key_press", symbol, modifiers) self._native_window.on_key_press = on_key_press def on_key_release(symbol, modifiers): self.dispatch_event("on_key_release", symbol, modifiers) self._native_window.on_key_release = on_key_release def on_draw(): self.dispatch_event("on_draw") self._native_window.on_draw = on_draw __windows__.append(self)