Esempio n. 1
0
 def init_window(self):
     window_width, window_height = glfw.get_window_size(self.window)
     _, _, center_x, center_y = glfw.get_monitor_workarea(
         glfw.get_primary_monitor())
     window_x = (center_x // 2) - (window_width // 2)
     window_y = (center_y // 2) - (window_height // 2)
     glfw.set_window_pos(self.window, window_x, window_y)
Esempio n. 2
0
 def window_pos_clb(glfw_window, x_pos: int, y_pos: int):
     if len(glfw.get_monitors()) >= 1:
         for monitor_id, monitor in enumerate(glfw.get_monitors()):
             m_x, m_y, width, height = glfw.get_monitor_workarea(
                 monitor)
             if m_x <= x_pos < m_x + width and m_y <= y_pos < m_y + height:
                 self.config["monitor_id"] = monitor_id
     self.config["screen_x"] = x_pos
     self.config["screen_y"] = y_pos
     self.config.store()
Esempio n. 3
0
 def set_pos(self, x=None, y=None):
     '设置窗口位置'
     if self.window is None:
         return
     if x is None or x is None:
         ws = glfw.get_window_size(self.window)
         ma = glfw.get_monitor_workarea(glfw.get_primary_monitor())
         if x is None:
             x = (ma[2] - ws[0]) // 2
         if y is None:
             y = (ma[3] - ws[1]) // 2
     glfw.set_window_pos(self.window, x, y)
Esempio n. 4
0
    def __init__(self, window):
        super(Client, self).__init__()
        self.window = window

        self._is_drag = False
        self._pre_cursor = ivec2(0, 0)

        monitor = glfw.get_primary_monitor()
        x, y, w, h = glfw.get_monitor_workarea(monitor)
        ww, wh = glfw.get_window_size(window)
        glfw.set_window_pos(window, (w >> 1) - (ww >> 1), (h >> 1) - (wh >> 1))

        glfw.set_mouse_button_callback(window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(window, self.on_cursor_pos)
Esempio n. 5
0
def main():
    glfw.init()
    glfw.window_hint(glfw.FLOATING, glfw.TRUE)
    glfw.window_hint(glfw.DECORATED, glfw.FALSE)
    window = glfw.create_window(WIDTH, HEIGHT, TITLE, None, None)
    m = glfw.get_primary_monitor()
    x, y, w, h = glfw.get_monitor_workarea(m)
    glfw.set_window_pos(window, w // 2 - WIDTH // 2, h // 2 - HEIGHT // 2)
    glfw.make_context_current(window)
    client = RenderClient(window)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        glfw.swap_buffers(window)
        client.update()
Esempio n. 6
0
    def __init__(self, window):
        super(Client, self).__init__()

        self.window = window

        m = glfw.get_primary_monitor()
        _, _, w, h = glfw.get_monitor_workarea(m)
        ww, hh = glfw.get_window_size(window)
        glfw.set_window_pos(window, w // 2 - ww // 2, h // 2 - hh // 2)

        self._isdrag = False
        self._prevpos = ivec2(0, 0)

        glfw.set_mouse_button_callback(window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(window, self.on_cursor_pos)
Esempio n. 7
0
def main():
    WIDTH, HEIGHT = 400, 400
    glfw.init()
    glfw.window_hint(glfw.DECORATED, glfw.FALSE)
    glfw.window_hint(glfw.FLOATING, glfw.TRUE)
    window = glfw.create_window(WIDTH, HEIGHT, "", None, None)
    monitor = glfw.get_primary_monitor()
    x, y, w, h = glfw.get_monitor_workarea(monitor)
    glfw.set_window_pos(window, (w >> 1) - (WIDTH >> 1),
                        (h >> 1) - (HEIGHT >> 1))
    glfw.make_context_current(window)
    client = Client(window)
    while not glfw.window_should_close(window):
        glfw.swap_buffers(window)
        glfw.poll_events()
        client.update()
Esempio n. 8
0
def main():
    width, height = 800, 800

    glfw.init()
    glfw.window_hint(glfw.FLOATING, glfw.TRUE)
    glfw.window_hint(glfw.DECORATED, glfw.FALSE)
    window = glfw.create_window(width, height, "", None, None)
    glfw.make_context_current(window)
    monitor = glfw.get_primary_monitor()
    _, _, w, h = glfw.get_monitor_workarea(monitor)
    glfw.set_window_pos(window, w - width, h - height)

    client = Client(window)
    while not glfw.window_should_close(window):
        client.update()
        glfw.poll_events()
        glfw.swap_buffers(window)
Esempio n. 9
0
    def __init__(self, window):
        super(Client, self).__init__()
        self.window = window

        self.isdrag_camera = False
        self.isdrag_window = False
        self.prev_cursor = vec2(0, 0)
        self.campos = vec3(-2.0, 3.0, -2.0)

        self.init()

        # set window center to the screen
        m = glfw.get_primary_monitor()
        ww, hh = glfw.get_window_size(window)
        x, y, w, h = glfw.get_monitor_workarea(m)
        glfw.set_window_pos(window, w // 2 - ww // 2, h // 2 - hh // 2)

        # mouse event
        glfw.set_mouse_button_callback(window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(window, self.on_cursor_pos)
        glfw.set_scroll_callback(window, self.on_scroll)
        glfw.set_key_callback(window, self.on_key)
Esempio n. 10
0
    def main(self):
        self.drag_offset = ivec2(0.0, 0.0)
        self.drag_start_winpos = ivec2(0.0, 0.0)
        self.is_drag = False

        glfw.init()
        glfw.window_hint(glfw.FLOATING, glfw.TRUE)
        glfw.window_hint(glfw.DECORATED, glfw.FALSE)
        glfw.window_hint(glfw.TRANSPARENT_FRAMEBUFFER, glfw.TRUE)

        self.width, self.height = 512, 512
        self.window = glfw.create_window(self.width, self.height, "render_0",
                                         None, None)

        x, y, w, h = glfw.get_monitor_workarea(glfw.get_primary_monitor())
        glfw.set_window_pos(self.window, (w - self.width) >> 1,
                            (h - self.height) >> 1)
        glfw.make_context_current(self.window)

        glfw.set_mouse_button_callback(self.window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(self.window, self.on_cursor_pos)
        glfw.set_key_callback(self.window, self.on_key)

        self.init_gl()

        handler = FileSystemEventHandler()
        handler.on_modified = self.on_modified
        observer = Observer()
        observer.schedule(handler, "./gl/", True)
        observer.start()

        while not glfw.window_should_close(self.window):
            if self.should_recomile:
                self.compile_vao()

            self.paint_gl()
            glfw.swap_buffers(self.window)
            glfw.poll_events()
Esempio n. 11
0
    def __init__(self, window):
        super(Client, self).__init__()
        self.window = window

        self.gl = mg.create_context()
        if not self.gl:
            print("can't create gl context")
            return

        self._compile()

        def on_mod(e):
            self._dirty = True

        handler = FileSystemEventHandler()
        handler.on_modified = on_mod
        observer = Observer()
        observer.schedule(handler, "./gl", True)
        observer.start()

        self._isresizing = False
        self._isdrag_camera = False
        self._isdrag_light = False
        self._isdrag_right = False
        self._isdrag_mid = False
        self._campos = vec3(-2.0, 3.0, -5.0)
        self._lightpos = vec3(-10.0, 20.0, -50.0)
        self._prevpos = (0, 0)

        _, _, w0, h0 = glfw.get_monitor_workarea(glfw.get_primary_monitor())
        w1, h1 = glfw.get_window_size(window)
        glfw.set_window_pos(window, w0 // 2 - w1 // 2, h0 // 2 - h1 // 2)
        glfw.set_framebuffer_size_callback(window, self.on_framebuffer_size)
        glfw.set_mouse_button_callback(window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(window, self.on_cursor_pos)
        glfw.set_scroll_callback(window, self.on_scroll)
        glfw.set_cursor_enter_callback(window, self.on_cursor_enter)
Esempio n. 12
0
def get_monitor_workarea_rect(monitor) -> _Rectangle:
    x, y, w, h = glfw.get_monitor_workarea(monitor)
    return _Rectangle(x=x, y=y, width=w, height=h)
Esempio n. 13
0
def main():
    if not glfw.init():
        raise RuntimeError('Failed to initialize GLFW')

    version = glfw.get_version_string().decode('ASCII')
    print('GLFW', version)

    monitors = glfw.get_monitors()
    for i, monitor in enumerate(monitors):
        name = glfw.get_monitor_name(monitor)
        primary = (glfw.get_monitor_pos(monitor) ==
                   glfw.get_monitor_pos(glfw.get_primary_monitor()))
        print('Monitor #{}: {}{}'.format(i, name.decode('utf8'),
              ' (primary)' if primary else ''))
        width_mm, height_mm = glfw.get_monitor_physical_size(monitor)
        diag_mm = math.sqrt(width_mm*width_mm + height_mm*height_mm)
        print('Diagonal: {:.1f}"'.format(diag_mm / 25.4))
        mode = glfw.get_video_mode(monitor)
        print('Video mode: {}x{} {}Hz {}'.format(mode.size.width, mode.size.height,
              mode.refresh_rate, mode.bits))
        xscale, yscale = glfw.get_monitor_content_scale(monitor)
        print('Scale: {}|{}'.format(xscale, yscale))
        print('Virtual position:', glfw.get_monitor_pos(monitor))
        print('Work ares:', glfw.get_monitor_workarea(monitor))
        for mode in glfw.get_video_modes(monitor):
            print('Supported: {}x{} {}Hz {}'.format(mode.size.width, mode.size.height,
                mode.refresh_rate, mode.bits))
            print(mode)

        print()

    glfw.window_hint(glfw.RESIZABLE, True)
    glfw.window_hint(glfw.STENCIL_BITS, 8)
    glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 6)
    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

    monitor = glfw.get_primary_monitor()
    mode = glfw.get_video_mode(monitor)

    window = glfw.create_window(640, 480, 'Title', None, None)
    # window = glfw.create_window(mode.size.width, mode.size.height, 'Title', monitor, None)
    if window is None:
        glfw.terminate()
        raise RuntimeError('Failed to create a window')

    # glfw.set_window_monitor(window, monitor, 0, 0, mode.size.width, mode.size.height, mode.refresh_rate)

    width, height = glfw.get_window_size(window)
    print('Window size: {}x{}'.format(width, height))
    print('Frame size:', glfw.get_window_frame_size(window))
    width, height = glfw.get_framebuffer_size(window)
    print('Framebuffer size: {}x{}'.format(width, height))
    print('Client API:', glfw.get_window_attrib(window, glfw.CLIENT_API))
    version_major = glfw.get_window_attrib(window, glfw.CONTEXT_VERSION_MAJOR)
    version_minor = glfw.get_window_attrib(window, glfw.CONTEXT_VERSION_MINOR)
    revision = glfw.get_window_attrib(window, glfw.CONTEXT_REVISION)
    print('Version: {}.{} rev{}'.format(version_major, version_minor, revision))

    glfw.make_context_current(window)
    renderer = Renderer(window)

    while not glfw.window_should_close(window):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT)
        renderer.render()
        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()