diff --git a/library/include/dfhack-c/modules/Gui_C.h b/library/include/dfhack-c/modules/Gui_C.h index a1be816a4..f10f23b4c 100644 --- a/library/include/dfhack-c/modules/Gui_C.h +++ b/library/include/dfhack-c/modules/Gui_C.h @@ -36,6 +36,18 @@ extern "C" { DFHACK_EXPORT int Gui_Start(DFHackObject* gui); DFHACK_EXPORT int Gui_Finish(DFHackObject* gui); +DFHACK_EXPORT int Gui_getViewCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z); +DFHACK_EXPORT int Gui_setViewCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z); + +DFHACK_EXPORT int Gui_getCursorCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z); +DFHACK_EXPORT int Gui_setCursorCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z); + +DFHACK_EXPORT t_hotkey* Gui_ReadHotkeys(DFHackObject* gui); + +DFHACK_EXPORT int Gui_getWindowSize(DFHackObject* gui, int32_t* width, int32_t* height); + +DFHACK_EXPORT t_screen* Gui_getScreenTiles(DFHackObject* gui, int32_t width, int32_t height); + DFHACK_EXPORT int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen); DFHACK_EXPORT int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState); diff --git a/library/modules/Gui_C.cpp b/library/modules/Gui_C.cpp index 218d16d94..5566e2eb6 100644 --- a/library/modules/Gui_C.cpp +++ b/library/modules/Gui_C.cpp @@ -48,126 +48,103 @@ int Gui_Finish(DFHackObject* gui) return -1; } -int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen) +int Gui_getViewCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z) { if(gui != NULL) { - return ((DFHack::Gui*)gui)->ReadViewScreen(*viewscreen); + int32_t tx, ty, tz; + + if(((DFHack::Gui*)gui)->getViewCoords(tx, ty, tz)) + { + *x = tx; + *y = ty; + *z = tz; + + return 1; + } + else + return 0; } return -1; } -int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState) +int Gui_setViewCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z) { if(gui != NULL) { - *menuState = ((DFHack::Gui*)gui)->ReadMenuState(); - - return 1; + if(((DFHack::Gui*)gui)->setViewCoords(x, y, z)) + return 1; + else + return 0; } return -1; } -int Gui_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) -{ - if(pos != NULL) - { - int32_t tx, ty, tz; - - if(((DFHack::Gui*)pos)->getViewCoords(tx, ty, tz)) - { - *x = tx; - *y = ty; - *z = tz; - - return 1; - } - else - return 0; - } - - return -1; -} - -int Gui_setViewCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) -{ - if(pos != NULL) - { - if(((DFHack::Gui*)pos)->setViewCoords(x, y, z)) - return 1; - else - return 0; - } - - return -1; -} - - -int Gui_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z) +int Gui_getCursorCoords(DFHackObject* gui, int32_t* x, int32_t* y, int32_t* z) { - if(pos != NULL) - { - int32_t tx, ty, tz; - - if(((DFHack::Gui*)pos)->getCursorCoords(tx, ty, tz)) - { - *x = tx; - *y = ty; - *z = tz; - - return 1; - } - else - return 0; - } - - return -1; + if(gui != NULL) + { + int32_t tx, ty, tz; + + if(((DFHack::Gui*)gui)->getCursorCoords(tx, ty, tz)) + { + *x = tx; + *y = ty; + *z = tz; + + return 1; + } + else + return 0; + } + + return -1; } -int Gui_setCursorCoords(DFHackObject* pos, int32_t x, int32_t y, int32_t z) +int Gui_setCursorCoords(DFHackObject* gui, int32_t x, int32_t y, int32_t z) { - if(pos != NULL) - { - if(((DFHack::Gui*)pos)->setCursorCoords(x, y, z)) - return 1; - else - return 0; - } - - return -1; + if(gui != NULL) + { + if(((DFHack::Gui*)gui)->setCursorCoords(x, y, z)) + return 1; + else + return 0; + } + + return -1; } -t_hotkey* Gui_ReadHotkeys(DFHackObject* pos) +t_hotkey* Gui_ReadHotkeys(DFHackObject* gui) { - if(pos != NULL) - { - t_hotkey* buf = NULL; - - (*alloc_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); - - if(buf != NULL) - { - if(((DFHack::Gui*)pos)->ReadHotkeys(buf)) - return buf; - else - return NULL; - } - else - return NULL; - } - - return NULL; + if(gui != NULL) + { + t_hotkey* buf; + + (*alloc_t_hotkey_buffer_callback)(&buf, NUM_HOTKEYS); + + if(buf != NULL) + { + if(((DFHack::Gui*)gui)->ReadHotkeys(buf)) + return buf; + else + return NULL; + } + else + return NULL; + } + + return NULL; } -int Gui_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height) +int Gui_getWindowSize(DFHackObject* gui, int32_t* width, int32_t* height) { - if(pos != NULL) + if(gui != NULL) { int32_t tw, th; - if(((DFHack::Gui*)pos)->getWindowSize(tw, th)) + if(((DFHack::Gui*)gui)->getWindowSize(tw, th)) { *width = tw; *height = th; @@ -181,26 +158,47 @@ int Gui_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height) return -1; } -t_screen* Gui_getScreenTiles(DFHackObject* pos, int32_t width, int32_t height) +t_screen* Gui_getScreenTiles(DFHackObject* gui, int32_t width, int32_t height) { - if(pos != NULL) - { - t_screen* buf = NULL; - - (*alloc_screen_buffer_callback)(&buf, width * height); - - if(buf == NULL) - return NULL; - - if(((DFHack::Gui*)pos)->getScreenTiles(width, height, buf)) - return buf; - else - return NULL; - } - - return NULL; + if(gui != NULL) + { + t_screen* buf; + + (*alloc_t_screen_buffer_callback)(&buf, width * height); + + if(buf == NULL) + return NULL; + + if(((DFHack::Gui*)gui)->getScreenTiles(width, height, buf)) + return buf; + else + return NULL; + } + + return NULL; } +int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen) +{ + if(gui != NULL) + { + return ((DFHack::Gui*)gui)->ReadViewScreen(*viewscreen); + } + + return -1; +} + +int Gui_ReadMenuState(DFHackObject* gui, uint32_t* menuState) +{ + if(gui != NULL) + { + *menuState = ((DFHack::Gui*)gui)->ReadMenuState(); + + return 1; + } + + return -1; +} #ifdef __cplusplus }