updated to match C API

develop
doomchild 2011-03-29 10:04:19 -05:00
parent e34831a354
commit c18167224b
1 changed files with 37 additions and 27 deletions

@ -1,22 +1,31 @@
from ctypes import *
from pydfhack import libdfhack, ViewScreen
from ctypes import c_void_p, c_int, c_uint, byref
from dftypes import libdfhack, ViewScreen, Hotkey
from util import check_pointer_cache
libdfhack.Gui_getViewCoords.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int), POINTER(c_int) ]
libdfhack.Gui_setViewCoords.argtypes = [ c_void_p, c_int, c_int, c_int ]
libdfhack.Gui_getCursorCoords.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int), POINTER(c_int) ]
libdfhack.Gui_setCursorCoords.argtypes = [ c_void_p, c_int, c_int, c_int ]
libdfhack.Gui_getWindowSize.argtypes = [ c_void_p, POINTER(c_int), POINTER(c_int) ]
libdfhack.Gui_ReadHotkeys.restype = c_void_p
libdfhack.Gui_ReadViewScreen.argtypes = [ c_void_p, c_void_p ]
libdfhack.Gui_ReadHotkeys.restype = c_void_p
libdfhack.Gui_getScreenTiles.argtypes = [ c_void_p, c_int, c_int ]
libdfhack.Gui_getScreenTiles.restype = c_void_p
class Gui(object):
def __init__(self, ptr):
self._gui_ptr = ptr
self._vx, self._vy, self._vz = c_int(), c_int(), c_int()
self._cx, self._cy, self._cz = c_int(), c_int(), c_int()
self._ww, self._wh = c_int(), c_int()
def start(self):
return libdfhack.Gui_Start(self._gui_ptr)
return libdfhack.Gui_Start(self._gui_ptr) > 0
def finish(self):
return libdfhack.Gui_Finish(self._gui_ptr)
return libdfhack.Gui_Finish(self._gui_ptr) > 0
def read_view_screen(self):
s = ViewScreen()
@ -27,37 +36,38 @@ class Gui(object):
return None
def get_view_coords(self):
if libdfhack.Gui_getViewCoords(self._gui_ptr, byref(self._vx), byref(self._vy), byref(self._vz)) > 0:
return (self._vx.value, self._vy.value, self._vz.value)
x, y, z = (0, 0, 0)
if libdfhack.Gui_getViewCoords(self._gui_ptr, byref(x), byref(y), byref(z)) > 0:
return (x, y, z)
else:
return (-1, -1, -1)
def set_view_coords(self, v_coords):
self._vx.value, self._vy.value, self._vz.value = v_coords
libdfhack.Gui_setViewCoords(self._gui_ptr, self._vx, self._vy, self._vz)
view_coords = property(get_view_coords, set_view_coords)
def set_view_coords(self, x, y, z):
libdfhack.Gui_setViewCoords(self._gui_ptr, x, y, z)
def get_cursor_coords(self):
if libdfhack.Gui_getCursorCoords(self._gui_ptr, byref(self._cx), byref(self._cy), byref(self._cz)) > 0:
return (self._cx.value, self._cy.value, self._cz.value)
x, y, z = (0, 0, 0)
if libdfhack.Gui_getCursorCoords(self._gui_ptr, byref(x), byref(y), byref(z)) > 0:
return (x, y, z)
else:
return (-1, -1, -1)
def set_cursor_coords(self, c_coords):
self._cx.value, self._cy.value, self_cz.value = c_coords
libdfhack.Gui_setCursorCoords(self._gui_ptr, self._cx, self._cy, self._cz)
cursor_coords = property(get_cursor_coords, set_cursor_coords)
def set_cursor_coords(self, x, y, z):
libdfhack.Gui_setCursorCoords(self._gui_ptr, x, y, z)
def read_hotkeys(self):
return check_pointer_cache(libdfhack.Gui_ReadHotkeys(self._gui_ptr))
def get_screen_tiles(self, width, height):
return check_pointer_cache(libdfhack.Gui_getScreenTiles(self._gui_ptr, width, height))
@property
def window_size(self):
if libdfhack.Gui_getWindowSize(self._gui_ptr, byref(self._ww), byref(self._wh)) > 0:
return (self._ww.value, self._wh.value)
width, height = (0, 0)
if libdfhack.Gui_getWindowSize(self._gui_ptr, byref(width), byref(height)) > 0:
return (width, height)
else:
return (-1, -1)