diff --git a/artifacts/scripting/functions.yml b/artifacts/scripting/functions.yml index 2476df76..d3cd784c 100644 --- a/artifacts/scripting/functions.yml +++ b/artifacts/scripting/functions.yml @@ -1774,6 +1774,7 @@ - name: get_window_under_mouse detail: int get_window_under_mouse() opcode: 0x821f + doc: "Returns internal ID of a top-most window under mouse cursor." - name: create_win detail: void create_win(string winName, int x, int y, int width, int height, int flags) doc: "`flags` argument is optional. Works just like vanilla `CreateWin` function, but creates a window with `MoveOnTop` flag if the flags argument is not specified, and allows to set additional flags for the created window. `MoveOnTop` flag allows the created window to be placed on top of the game interface." @@ -1788,6 +1789,7 @@ - `attrType`: `0` - checks and returns a value of 1 if the specified interface window is created by the game (same as without the argument) `1` - X position, `2` - Y position (relative to the top-left corner of the game screen) `3` - interface width size, `4` - interface height size + `5` - window ID (to compare with get_window_under_mouse) `-1` - returns an associative array of keys (left, top, right, bottom) and values that define the position of the window rectangle (use standard syntax to access array values, e.g. `winRect.top`, `winRect.bottom`) - returns -1 if the specified attribute cannot be obtained diff --git a/artifacts/scripting/headers/sfall.h b/artifacts/scripting/headers/sfall.h index 8cf5b2b8..3094cef3 100644 --- a/artifacts/scripting/headers/sfall.h +++ b/artifacts/scripting/headers/sfall.h @@ -320,6 +320,7 @@ #define get_interface_y(winType) sfall_func2("get_window_attribute", winType, 2) #define get_interface_width(winType) sfall_func2("get_window_attribute", winType, 3) #define get_interface_height(winType) sfall_func2("get_window_attribute", winType, 4) +#define get_interface_id(winType) sfall_func2("get_window_attribute", winType, 5) #define get_inven_ap_cost sfall_func0("get_inven_ap_cost") #define get_map_enter_position sfall_func0("get_map_enter_position") #define get_metarule_table sfall_func0("get_metarule_table") diff --git a/sfall/Modules/Scripting/Handlers/Interface.cpp b/sfall/Modules/Scripting/Handlers/Interface.cpp index c926153a..2845f42b 100644 --- a/sfall/Modules/Scripting/Handlers/Interface.cpp +++ b/sfall/Modules/Scripting/Handlers/Interface.cpp @@ -722,6 +722,11 @@ static long InterfaceDrawImage(OpcodeContext& ctx, fo::Window* ifaceWin) { int width = (w >= 0) ? w : frm.width; int height = (h >= 0) ? h : frm.height; + if (x + width > ifaceWin->width || y + height > ifaceWin->height) { + ctx.printOpcodeError("%s() - attempt to draw beyond window bounds (%d, %d)", ctx.getMetaruleName(), ifaceWin->width, ifaceWin->height); + return -1; + } + BYTE* surface = (ifaceWin->randY) ? WindowRender::GetOverlaySurface(ifaceWin) : ifaceWin->surface; fo::func::trans_cscale(frm.pixelData, frm.width, frm.height, frm.width, @@ -783,6 +788,9 @@ void mf_get_window_attribute(OpcodeContext& ctx) { case 4: result = win->height; break; + case 5: + result = win->wID; + break; } ctx.setReturn(result); }