annotate pytouhou/lib/glfw.pyx @ 762:cad9e422b18f

interpreters, runners: Add missing mod/lib files.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 06 Jan 2021 01:47:24 +0100
parents f953ae5b3732
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
636
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 ##
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 ## Copyright (C) 2016 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 ##
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 ## This program is free software; you can redistribute it and/or modify
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 ## it under the terms of the GNU General Public License as published
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 ## by the Free Software Foundation; version 3 only.
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 ##
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 ## This program is distributed in the hope that it will be useful,
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 ## GNU General Public License for more details.
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 ##
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 from .gui cimport SHOOT, BOMB, FOCUS, UP, DOWN, LEFT, RIGHT, SKIP
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 CLIENT_API = GLFW_CLIENT_API
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 OPENGL_PROFILE = GLFW_OPENGL_PROFILE
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 CONTEXT_VERSION_MAJOR = GLFW_CONTEXT_VERSION_MAJOR
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 CONTEXT_VERSION_MINOR = GLFW_CONTEXT_VERSION_MINOR
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 DEPTH_BITS = GLFW_DEPTH_BITS
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 ALPHA_BITS = GLFW_ALPHA_BITS
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 RESIZABLE = GLFW_RESIZABLE
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 DOUBLEBUFFER = GLFW_DOUBLEBUFFER
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 OPENGL_API = GLFW_OPENGL_API
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 OPENGL_ES_API = GLFW_OPENGL_ES_API
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 OPENGL_CORE_PROFILE = GLFW_OPENGL_CORE_PROFILE
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29
729
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
30 cdef void error_callback(int a, const char* b) nogil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
31 with gil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
32 print('GLFW error 0x%x: %s' % (a, b.decode('utf-8')))
636
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 cdef list _global_events = []
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35
729
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
36 cdef void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) nogil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
37 with gil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
38 if action != GLFW_PRESS:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
39 return
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
40 if key == GLFW_KEY_ESCAPE:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
41 _global_events.append((gui.PAUSE, None))
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
42 elif key in (GLFW_KEY_P, GLFW_KEY_HOME):
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
43 _global_events.append((gui.SCREENSHOT, None))
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
44 elif key == GLFW_KEY_DOWN:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
45 _global_events.append((gui.DOWN, None))
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
46 elif key == GLFW_KEY_F11:
636
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 _global_events.append((gui.FULLSCREEN, None))
729
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
48 elif key == GLFW_KEY_ENTER:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
49 if mods & GLFW_MOD_ALT:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
50 _global_events.append((gui.FULLSCREEN, None))
636
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
729
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
52 cdef void size_callback(GLFWwindow* window, int width, int height) nogil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
53 with gil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
54 _global_events.append((gui.RESIZE, (width, height)))
636
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55
729
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
56 cdef void close_callback(GLFWwindow* window) nogil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
57 with gil:
f953ae5b3732 PyTouhou: Fix GLFW callbacks to be nogil
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 636
diff changeset
58 _global_events.append((gui.EXIT, None))
636
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 cdef void init() except *:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 glfwSetErrorCallback(<GLFWerrorfun>error_callback)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 ret = glfwInit()
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 if not ret:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 raise Exception('TODO')
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 cdef void terminate() nogil:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 glfwTerminate()
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 cdef void window_hint(int hint, int value) nogil:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 glfwWindowHint(hint, value)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 cdef class Window:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 def __init__(self, int width, int height, str title, Monitor monitor=None, Window share=None):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 cdef GLFWmonitor* c_monitor = NULL
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 cdef GLFWwindow* c_share = NULL
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76 if monitor is not None:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 c_monitor = monitor.monitor
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 if share is not None:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 c_share = share.window
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 self.window = glfwCreateWindow(width, height, title.encode('utf-8'), c_monitor, c_share)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 if self.window == NULL:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 raise Exception('TODO')
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 glfwSetFramebufferSizeCallback(self.window, <GLFWframebuffersizefun>size_callback)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 glfwSetWindowCloseCallback(self.window, <GLFWwindowclosefun>close_callback)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 glfwSetKeyCallback(self.window, <GLFWkeyfun>key_callback)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 def __del__(self):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 glfwDestroyWindow(self.window)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 cdef void create_gl_context(self) except *:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91 glfwMakeContextCurrent(self.window)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 cdef void present(self) nogil:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 glfwSwapBuffers(self.window)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 cdef void set_window_size(self, int width, int height) nogil:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 pass
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99 cdef list get_events(self):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 glfwPollEvents()
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 events = _global_events[:]
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 _global_events.clear()
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 return events
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 cdef void toggle_fullscreen(self) nogil:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 monitor = glfwGetWindowMonitor(self.window)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 if monitor == NULL:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 monitor = glfwGetPrimaryMonitor()
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109 else:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 monitor = NULL
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 # TODO: save the previous size.
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 glfwSetWindowMonitor(self.window, monitor, 0, 0, 640, 480, 60)
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114 cdef int get_keystate(self) nogil:
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 cdef int keystate = 0
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 if glfwGetKey(self.window, GLFW_KEY_Z):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 keystate |= SHOOT
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 if glfwGetKey(self.window, GLFW_KEY_X):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 keystate |= BOMB
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 if glfwGetKey(self.window, GLFW_KEY_LEFT_SHIFT):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 keystate |= FOCUS
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 if glfwGetKey(self.window, GLFW_KEY_UP):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 keystate |= UP
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 if glfwGetKey(self.window, GLFW_KEY_DOWN):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 keystate |= DOWN
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 if glfwGetKey(self.window, GLFW_KEY_LEFT):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 keystate |= LEFT
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 if glfwGetKey(self.window, GLFW_KEY_RIGHT):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 keystate |= RIGHT
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 if glfwGetKey(self.window, GLFW_KEY_LEFT_CONTROL):
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 keystate |= SKIP
4fa0a8e7d941 Add a GLFW implementation of gui.Window.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 return keystate