Beispiel #1
0
    def getWindowPosition(self):
        # Use pointers
        X = ctypes.pointer(ctypes.c_long(0))
        Y = ctypes.pointer(ctypes.c_long(0))
        sdl2.SDL_GetWindowPosition(self.window, X, Y)

        return X.contents.value, Y.contents.value
Beispiel #2
0
 def GetWindowRect(self):
     x, y, w, h = ctypes.c_int(), ctypes.c_int(), ctypes.c_int(
     ), ctypes.c_int()
     sdl2.SDL_GetWindowPosition(self.window, ctypes.byref(x),
                                ctypes.byref(y))
     sdl2.SDL_GetWindowSize(self.window, ctypes.byref(w), ctypes.byref(h))
     return sdl2.SDL_Rect(x.value, y.value, w.value, h.value)
Beispiel #3
0
 def _vispy_get_position(self):
     if self._id is None:
         return
     x, y = ctypes.c_int(), ctypes.c_int()
     sdl2.SDL_GetWindowPosition(self._id.window, ctypes.byref(x),
                                ctypes.byref(y))
     x, y = x.value, y.value
     return x, y
Beispiel #4
0
    def position(self) -> Tuple[int, int]:
        """Tuple[int, int]: The current window position.

        This property can also be set to move the window::

            # Move window to 100, 100
            window.position = 100, 100
        """
        x = c_int(0)
        y = c_int(0)
        sdl2.SDL_GetWindowPosition(self._window, x, y)
        return x.value, y.value
Beispiel #5
0
 def __init__(self, app):
     self.app = app
     self.ui = self.app.ui
     # read from binds.cfg file or create it from template
     # exec results in edit_binds, a dict whose keys are keys+mods
     # and whose values are bound functions
     self.edit_bind_src = None
     # bad probs if a command isn't in binds.cfg, so just blow it away
     # if the template is newer than it
     # TODO: better solution is find any binds in template but not binds.cfg
     # and add em
     binds_filename = self.app.config_dir + BINDS_FILENAME
     binds_outdated = not os.path.exists(
         binds_filename) or os.path.getmtime(
             binds_filename) < os.path.getmtime(BINDS_TEMPLATE_FILENAME)
     if not binds_outdated and os.path.exists(binds_filename):
         exec(open(binds_filename).read())
         self.app.log('Loaded key binds from %s' % binds_filename)
     else:
         default_data = open(BINDS_TEMPLATE_FILENAME).readlines()[1:]
         new_binds = open(binds_filename, 'w')
         new_binds.writelines(default_data)
         new_binds.close()
         self.app.log('Created new key binds file %s' % binds_filename)
         exec(''.join(default_data))
     if not self.edit_bind_src:
         self.app.log('No bind data found, Is binds.cfg.default present?')
         exit()
     # associate key + mod combos with methods
     self.edit_binds = {}
     for bind_string in self.edit_bind_src:
         bind = self.parse_key_bind(bind_string)
         if not bind:
             continue
         # bind data could be a single item (string) or a list/tuple
         bind_data = self.edit_bind_src[bind_string]
         if type(bind_data) is str:
             bind_fnames = ['BIND_%s' % bind_data]
         else:
             bind_fnames = ['BIND_%s' % s for s in bind_data]
         bind_functions = []
         for bind_fname in bind_fnames:
             if not hasattr(self, bind_fname):
                 continue
             bind_functions.append(getattr(self, bind_fname))
         self.edit_binds[bind] = bind_functions
     # get controller(s)
     # TODO: use kewl SDL2 gamepad system
     js_init = sdl2.SDL_InitSubSystem(sdl2.SDL_INIT_JOYSTICK)
     if js_init != 0:
         self.app.log(
             "SDL2: Couldn't initialize joystick subsystem, code %s" %
             js_init)
         return
     sticks = sdl2.SDL_NumJoysticks()
     #self.app.log('%s gamepads found' % sticks)
     self.gamepad = None
     self.gamepad_left_x, self.gamepad_left_y = 0, 0
     # for now, just grab first pad
     if sticks > 0:
         pad = sdl2.SDL_JoystickOpen(0)
         pad_name = sdl2.SDL_JoystickName(pad).decode('utf-8')
         pad_axes = sdl2.SDL_JoystickNumAxes(pad)
         pad_buttons = sdl2.SDL_JoystickNumButtons(pad)
         self.app.log('Gamepad found: %s with %s axes, %s buttons' %
                      (pad_name, pad_axes, pad_buttons))
         self.gamepad = pad
     # before main loop begins, set initial mouse position -
     # SDL_GetMouseState returns 0,0 if the mouse hasn't yet moved
     # in the new window!
     wx, wy = ctypes.c_int(0), ctypes.c_int(0)
     sdl2.SDL_GetWindowPosition(self.app.window, wx, wy)
     wx, wy = int(wx.value), int(wy.value)
     mx, my = ctypes.c_int(0), ctypes.c_int(0)
     sdl2.mouse.SDL_GetGlobalMouseState(mx, my)
     mx, my = int(mx.value), int(my.value)
     self.app.mouse_x, self.app.mouse_y = mx - wx, my - wy
     # set flag so we know whether handle_input's SDL_GetMouseState result
     # is accurate :/
     self.mouse_has_moved = False