示例#1
0
def key_callback(window, key, code, action, mods):
    self = glfw.get_window_user_pointer(window)

    # take a screenshot on F2 press
    if key == glfw.KEY_F2 and action == glfw.PRESS:
        PPM().create("./screenshot.ppm", self.image, self.image_width,
                     self.image_height)
示例#2
0
    def setGamma(self, gamma):
        """Set the gamma for this window.

        :param gamma:
        :return:
        """
        win = glfw.get_window_user_pointer(self.winHandle)
        # if not fullscreen, we get an access violation (bug?)
        if not win._isFullScr:
            return None

        # make sure gamma is 3x1 array
        if type(gamma) in [float, int]:
            newGamma = np.tile(gamma, [3, 1])
        elif type(gamma) in [list, tuple]:
            newGamma = np.array(gamma)
            newGamma.shape = [3, 1]
        elif type(gamma) is np.ndarray:
            gamma.shape = [3, 1]

        # create linear LUT
        newLUT = np.tile(
            createLinearRamp(rampSize=self.getGammaRampSize()), (3, 1)
        ).T
        if np.all(gamma == 1.0) == False:
            # correctly handles 1 or 3x1 gamma vals
            newLUT = newLUT ** (1.0 / np.array(gamma))

        self.setGammaRamp(newLUT)
示例#3
0
    def setGamma(self, gamma):
        """Set the gamma for this window.

        :param gamma:
        :return:
        """
        win = glfw.get_window_user_pointer(self.winHandle)
        # if not fullscreen, we get an access violation (bug?)
        if not win._isFullScr:
            return None

        # make sure gamma is 3x1 array
        if type(gamma) in [float, int]:
            newGamma = np.tile(gamma, [3, 1])
        elif type(gamma) in [list, tuple]:
            newGamma = np.array(gamma)
            newGamma.shape = [3, 1]
        elif type(gamma) is np.ndarray:
            gamma.shape = [3, 1]

        # create linear LUT
        newLUT = np.tile(createLinearRamp(rampSize=self.getGammaRampSize()),
                         (3, 1))
        if np.all(gamma == 1.0) == False:
            # correctly handles 1 or 3x1 gamma vals
            newLUT = newLUT**(1.0 / np.array(gamma))

        self.setGammaRamp(newLUT)
def mouse_callback(window, pos_x, pos_y):
    ps = glfw.get_window_user_pointer(window)

    if ps.last_mouse_pos_x is None:
        ps.last_mouse_pos_x = pos_x
        ps.last_mouse_pos_y = pos_y
    else:
        x_offset = (pos_x - ps.last_mouse_pos_x)
        y_offset = (ps.last_mouse_pos_y - pos_y)
        ps.last_mouse_pos_x = pos_x
        ps.last_mouse_pos_y = pos_y

        # Send shader the mouse (x, y) in NDC space
        mouse_ndc_x = pos_x / SCREEN_WIDTH * 2 - 1
        mouse_ndc_y = -(pos_y / SCREEN_HEIGHT * 2 - 1)

        ps.shader.set_float('mouse_x', mouse_ndc_x)
        ps.shader.set_float('mouse_y', mouse_ndc_y)

        # Set the particle generator position
        if glfw.get_key(
                window, glfw.KEY_LEFT_CONTROL
        ) == glfw.PRESS and 0 < pos_x < SCREEN_WIDTH and 0 < pos_y < SCREEN_HEIGHT:
            set_generator_position(ps, mouse_ndc_x, mouse_ndc_y)

        # Rotate camera
        if glfw.get_key(window, glfw.KEY_LEFT_SHIFT) == glfw.PRESS:
            ps.camera.update_yaw_pitch(x_offset * MOUSE_SENSITIVITY,
                                       y_offset * MOUSE_SENSITIVITY)
示例#5
0
 def get_window_node(self, window):
     if hasattr(window, "window"):
         window = window.window
     id_ = glfw.get_window_user_pointer(window)
     try:
         return self.children[id_]
     except KeyError as e:
         raise RuntimeError("No node assigned to window") from e
示例#6
0
 def set_window_node(self, window, node):
     if hasattr(window, "window"):
         node.size = (window.width, window.height)
         node.recalc_size()
         window = window.window
     id_ = glfw.get_window_user_pointer(window)
     self.children[id_] = node
     self.selected[id_] = None
示例#7
0
    def getGammaRamp(self):
        # get the current gamma ramp
        win = glfw.get_window_user_pointer(self.winHandle)
        # if not fullscreen, we get an access violation (bug?)
        if not win._isFullScr:
            return None

        monitor = glfw.get_window_monitor(self.winHandle)
        currentGammaRamp = glfw.get_gamma_ramp(monitor)

        return np.asarray(currentGammaRamp, dtype=np.float32)
示例#8
0
    def getGammaRamp(self):
        # get the current gamma ramp
        win = glfw.get_window_user_pointer(self.winHandle)
        # if not fullscreen, we get an access violation (bug?)
        if not win._isFullScr:
            return None

        monitor = glfw.get_window_monitor(self.winHandle)
        currentGammaRamp = glfw.get_gamma_ramp(monitor)

        return np.asarray(currentGammaRamp, dtype=np.float32)
示例#9
0
    def setGammaRamp(self, gammaRamp):
        """Set the hardware CLUT to use the specified ramp. This is a custom
        function for doing so using GLFW.

        :param gammaRamp:
        :return:

        """
        win = glfw.get_window_user_pointer(self.winHandle)
        # if not fullscreen, we get an access violation
        if not win._isFullScr:
            return None

        monitor = glfw.get_window_monitor(self.winHandle)

        if self.getGammaRampSize() == gammaRamp.shape[1]:
            new_ramp = (gammaRamp[0, :], gammaRamp[1, :], gammaRamp[2, :])
            glfw.set_gamma_ramp(monitor, new_ramp)
示例#10
0
    def setGammaRamp(self, gammaRamp):
        """Set the hardware CLUT to use the specified ramp. This is a custom
        function for doing so using GLFW.

        :param gammaRamp:
        :return:

        """
        win = glfw.get_window_user_pointer(self.winHandle)
        # if not fullscreen, we get an access violation
        if not win._isFullScr:
            return None

        monitor = glfw.get_window_monitor(self.winHandle)

        if self.getGammaRampSize() == gammaRamp.shape[1]:
            new_ramp = (gammaRamp[0, :], gammaRamp[1, :], gammaRamp[2, :])
            glfw.set_gamma_ramp(monitor, new_ramp)
示例#11
0
    def getGammaRampSize(self):
        """Get the gamma ramp size for the current display. The size of the ramp
        depends on the bits-per-color of the current video mode.

        :return:
        """
        # get the current gamma ramp
        win = glfw.get_window_user_pointer(self.winHandle)
        if not win._isFullScr:
            return None
        monitor = glfw.get_window_monitor(self.winHandle)
        currentGammaRamp = glfw.get_gamma_ramp(monitor)

        # get the gamma ramps for each color channel
        red_ramp = currentGammaRamp[0]
        green_ramp = currentGammaRamp[1]
        blue_ramp = currentGammaRamp[2]

        return max(len(red_ramp), len(green_ramp), len(blue_ramp))
示例#12
0
    def getGammaRampSize(self):
        """Get the gamma ramp size for the current display. The size of the ramp
        depends on the bits-per-color of the current video mode.

        :return:
        """
        # get the current gamma ramp
        win = glfw.get_window_user_pointer(self.winHandle)
        if not win._isFullScr:
            return None
        monitor = glfw.get_window_monitor(self.winHandle)
        currentGammaRamp = glfw.get_gamma_ramp(monitor)

        # get the gamma ramps for each color channel
        red_ramp = currentGammaRamp[0]
        green_ramp = currentGammaRamp[1]
        blue_ramp = currentGammaRamp[2]

        return max(len(red_ramp), len(green_ramp), len(blue_ramp))
示例#13
0
 def close(self):
     """Close the window and uninitialize the resources
     """
     _hw_handle = None
     try:
         _hw_handle = self.win._hw_handle
         # We need to call this when closing a window, however the window
         # object is None at this point! So the GLFW window object lives on.
         win = glfw.get_window_user_pointer(self.winHandle)
         glfw.destroy_window(win)
     except Exception:
         pass
     # If iohub is running, inform it to stop looking for this win id
     # when filtering kb and mouse events (if the filter is enabled of
     # course)
     try:
         if IOHUB_ACTIVE and _hw_handle:
             from psychopy.iohub.client import ioHubConnection
             conn = ioHubConnection.ACTIVE_CONNECTION
             conn.unregisterWindowHandles(_hw_handle)
     except Exception:
         pass
示例#14
0
 def close(self):
     """Close the window and uninitialize the resources
     """
     _hw_handle = None
     try:
         _hw_handle = self.win._hw_handle
         # We need to call this when closing a window, however the window
         # object is None at this point! So the GLFW window object lives on.
         win = glfw.get_window_user_pointer(self.winHandle)
         glfw.destroy_window(win)
     except Exception:
         pass
     # If iohub is running, inform it to stop looking for this win id
     # when filtering kb and mouse events (if the filter is enabled of
     # course)
     try:
         if IOHUB_ACTIVE and _hw_handle:
             from psychopy.iohub.client import ioHubConnection
             conn = ioHubConnection.ACTIVE_CONNECTION
             conn.unregisterWindowHandles(_hw_handle)
     except Exception:
         pass
示例#15
0
def key_callback(window, key, scancode, action, mods):
    ps = glfw.get_window_user_pointer(window)

    if action == glfw.PRESS:
        if key == glfw.KEY_ESCAPE:
            glfw.set_window_should_close(window, True)
        elif key == glfw.KEY_P:
            ps.toggle_projection_mode()
        elif key == glfw.KEY_Z:
            ps.toggle_spawn_location()
        elif key == glfw.KEY_L:
            ps.toggle_lifetime()
        elif key == glfw.KEY_G:
            ps.toggle_gravity()
        elif key == glfw.KEY_T:
            ps.toggle_texture()
        elif key == glfw.KEY_X:
            ps.toggle_shrinking()
        elif key == glfw.KEY_TAB:
            ps.toggle_particle_mode()
        elif key == glfw.KEY_C:
            ps.toggle_color_profile()
示例#16
0
    def screenID(self):
        """Return the window's screen ID.
        """
        win = glfw.get_window_user_pointer(self.winHandle)

        return win.screen
示例#17
0
 def set_selected_node(self, window, node):
     if hasattr(window, "window"):
         window = window.window
     id_ = glfw.get_window_user_pointer(window)
     self.selected[id_] = node
     logger.debug(self.selected)
示例#18
0
    def screenID(self):
        """Return the window's screen ID.
        """
        win = glfw.get_window_user_pointer(self.winHandle)

        return win.screen
示例#19
0
 def get_selected_node(self, window):
     if hasattr(window, "window"):
         window = window.window
     id_ = glfw.get_window_user_pointer(window)
     return self.selected[id_]
def get_saved_embedder_state(window):
    user_pointer = glfw.get_window_user_pointer(window)
    return ffi.cast('FlutterEmbedderState*', user_pointer)