Fix keys again

This commit is contained in:
rute 2014-05-01 00:43:12 +02:00
parent 01e7a46753
commit b06732787a
5 changed files with 69 additions and 9 deletions

View file

@ -135,6 +135,12 @@ cdef extern from "GLFW/glfw3.h":
GLFW_KEY_MENU
GLFW_KEY_LAST
# Modifiers
GLFW_MOD_SHIFT
GLFW_MOD_CONTROL
GLFW_MOD_ALT
GLFW_MOD_SUPER
# Mouse button definitions
GLFW_MOUSE_BUTTON_1
GLFW_MOUSE_BUTTON_2

View file

@ -4,6 +4,53 @@ class ACTION:
PRESS = GLFW_PRESS
class KEY:
SPACE = GLFW_KEY_SPACE
APOSTROPHE = GLFW_KEY_APOSTROPHE
COMMA = GLFW_KEY_COMMA
MINUS = GLFW_KEY_MINUS
PERIOD = GLFW_KEY_PERIOD
SLASH = GLFW_KEY_SLASH
ZERO = GLFW_KEY_0
ONE = GLFW_KEY_1
TWO = GLFW_KEY_2
THREE = GLFW_KEY_3
FOUR = GLFW_KEY_4
FIVE = GLFW_KEY_5
SIX = GLFW_KEY_6
SEVEN = GLFW_KEY_7
EIGHT = GLFW_KEY_8
NINE = GLFW_KEY_9
SEMICOLON = GLFW_KEY_SEMICOLON
EQUAL = GLFW_KEY_EQUAL
A = GLFW_KEY_A
B = GLFW_KEY_B
C = GLFW_KEY_C
D = GLFW_KEY_D
E = GLFW_KEY_E
F = GLFW_KEY_F
G = GLFW_KEY_G
H = GLFW_KEY_H
I = GLFW_KEY_I
J = GLFW_KEY_J
K = GLFW_KEY_K
L = GLFW_KEY_L
M = GLFW_KEY_M
N = GLFW_KEY_N
O = GLFW_KEY_O
P = GLFW_KEY_P
Q = GLFW_KEY_Q
R = GLFW_KEY_R
S = GLFW_KEY_S
T = GLFW_KEY_T
U = GLFW_KEY_U
V = GLFW_KEY_V
W = GLFW_KEY_W
X = GLFW_KEY_X
Y = GLFW_KEY_Y
Z = GLFW_KEY_Z
LEFT_BRACKET = GLFW_KEY_LEFT_BRACKET
BACKSLASH = GLFW_KEY_BACKSLASH
RIGHT_BRACKET = GLFW_KEY_RIGHT_BRACKET
SPACE = GLFW_KEY_SPACE
ESCAPE = GLFW_KEY_ESCAPE
ENTER = GLFW_KEY_ENTER
@ -43,6 +90,12 @@ class KEY:
RIGHT_CONTROL = GLFW_KEY_RIGHT_CONTROL
RIGHT_ALT = GLFW_KEY_RIGHT_ALT
class MOD:
SHIFT = GLFW_MOD_SHIFT
CONTROL = GLFW_MOD_CONTROL
ALT = GLFW_MOD_ALT
SUPER = GLFW_MOD_SUPER
class MOUSE:
LEFT = GLFW_MOUSE_BUTTON_LEFT
RIGHT = GLFW_MOUSE_BUTTON_RIGHT

View file

@ -74,7 +74,7 @@ cdef class Image:
for i in range(self.bytesPerPixel):
pixels[swapOffset + i], pixels[offset + i] = pixels[offset + i], pixels[swapOffset + i]
cpdef writePNG(self, char *filename, int stride = 0):
cpdef writePNG(self, filename, int stride = 0):
'''
Write image to PNG file. Note that the file
will be overwritten if not locked.
@ -84,7 +84,11 @@ cdef class Image:
Raises GLError on failure.
'''
if not stbi_write_png(filename, self.width, self.height, self.bytesPerPixel,
cdef char *c_filename
bytetext = unicode(filename).encode('UTF-8','ignore')
c_filename = bytetext
if not stbi_write_png(c_filename, self.width, self.height, self.bytesPerPixel,
self._buffer, stride):
raise GLError("failed to write to PNG '%s'" % filename)

View file

@ -142,7 +142,7 @@ cdef class Image:
cdef __cythonbufferdefaults__ = {"ndim": 1, "mode": "c"}
cpdef flipY(self)
cpdef writePNG(self, char *filename, int stride = ?)
cpdef writePNG(self, filename, int stride = ?)
cpdef InitGLExt()
cpdef int Check()

View file

@ -310,6 +310,9 @@ class MainWindow(gl.Window):
#print('onKey ', key, action)
if key == gl.KEY.ESCAPE:
self.running = False
elif key == gl.KEY.F:
self.cam.zoomExtents(self.near, self.far)
self.onRefresh()
elif key == gl.KEY.F1:
self.makeContextCurrent()
img = gl.Image(self.width, self.height, gl.RGBA)
@ -317,12 +320,6 @@ class MainWindow(gl.Window):
img.flipY()
img.writePNG('screenshot01.png')
def onChar(self, ch):
#print('onChar ', ch)
if ch == 'f':
self.cam.zoomExtents(self.near, self.far)
self.onRefresh()
def onScroll(self, scx, scy):
x, y = self.lastPos
self.uiScroll = -int(scy)