sdlterm/cython/sdlterm.pyx
changeset 49 1611c462c3e3
parent 48 1f00e90fd72a
child 50 c5b8b9d2da95
equal deleted inserted replaced
48:1f00e90fd72a 49:1611c462c3e3
     1 # distutils: language = c++
     1 # distutils: language = c++
     2 # distutils: sources = src/sdlterm.cc
     2 # distutils: sources = src/sdlterm.cc
     3 # distutils: include_dirs = /usr/include/SDL src
     3 # distutils: include_dirs = /usr/include/SDL src
     4 # distutils: libraries = SDL SDL_ttf
     4 # distutils: libraries = SDL SDL_ttf
     5 # distutils: define_macros = _GNU_SOURCE=1 _REENTRANT
     5 # distutils: define_macros = _GNU_SOURCE=1 _REENTRANT
     6 # distutils: extra_compile_args = --std=c++0x
     6 # distutils: extra_compile_args = --std=c++11
     7 # cython: language_level=3
     7 # cython: language_level=3
     8 
     8 
     9 from libcpp cimport bool
     9 from libcpp cimport bool
    10 
    10 
    11 
    11 
    33         Event_mouse mouse
    33         Event_mouse mouse
    34 
    34 
    35     cdef cppclass Terminal:
    35     cdef cppclass Terminal:
    36         Terminal() except +
    36         Terminal() except +
    37 
    37 
    38         void select_font(char *fname_regular, char *fname_bold, int ptsize)
    38         void select_font(char *fname_regular, char *fname_bold, int ptsize) except +
    39         void resize(int pxwidth, int pxheight)
    39         void resize(int pxwidth, int pxheight) except +
    40 
    40 
    41         void erase()
    41         void erase()
    42         void putch(int x, int y, Py_UNICODE ch)
    42         void putch(int x, int y, Py_UNICODE ch)
    43         void commit()
    43         void commit()
    44 
    44 
    54         int get_height()
    54         int get_height()
    55 
    55 
    56 
    56 
    57 cdef class SDLTerminal:
    57 cdef class SDLTerminal:
    58     cdef Terminal *thisptr      # hold a C++ instance which we're wrapping
    58     cdef Terminal *thisptr      # hold a C++ instance which we're wrapping
       
    59     cdef Event event
    59 
    60 
    60     def __cinit__(self):
    61     def __cinit__(self):
    61         self.thisptr = new Terminal()
    62         self.thisptr = new Terminal()
    62     def __dealloc__(self):
    63     def __dealloc__(self):
    63         del self.thisptr
    64         del self.thisptr
    75         self.thisptr.putch(x, y, ch)
    76         self.thisptr.putch(x, y, ch)
    76     def commit(self):
    77     def commit(self):
    77         self.thisptr.commit()
    78         self.thisptr.commit()
    78 
    79 
    79     def get_next_event(self):
    80     def get_next_event(self):
    80         cdef Event event
    81         self.thisptr.get_next_event(self.event)
    81         self.thisptr.get_next_event(event)
    82         event = self.event
    82         if event.type == event.MOUSEMOVE:
    83         if event.type == event.MOUSEMOVE:
    83             return ('mousemove', event.mouse.x, event.mouse.y)
    84             return ('mousemove', event.mouse.x, event.mouse.y)
    84         if event.type == event.MOUSEDOWN:
    85         if event.type == event.MOUSEDOWN:
    85             return ('mousedown', event.mouse.x, event.mouse.y, event.mouse.button)
    86             return ('mousedown', event.mouse.x, event.mouse.y, event.mouse.button)
    86         if event.type == event.MOUSEUP:
    87         if event.type == event.MOUSEUP: