diff --git a/src/library/doc.texi b/src/library/doc.texi index 3116457..c299724 100644 --- a/src/library/doc.texi +++ b/src/library/doc.texi @@ -2477,7 +2477,19 @@ and @ref{objects-minimaprender2d}. @eventobjectwarning{} -@node renderminimap-xywh +@node renderminimap-sourcexywh +@subsection xywh + +Returns the x, y, width and height of the section of the minimap image +being drawn, in pixels. + +@example lua +@verbatim +local x, y, width, height = event:targetxywh() +@end verbatim +@end example + +@node renderminimap-targetxywh @subsection xywh Returns the x, y, width and height of where the minimap is being drawn @@ -2486,7 +2498,7 @@ top-left pixel of the inner area of the window. @example lua @verbatim -local x, y, width, height = event:xywh() +local x, y, width, height = event:targetxywh() @end verbatim @end example diff --git a/src/library/gl.c b/src/library/gl.c index 87b70c4..0c115ed 100644 --- a/src/library/gl.c +++ b/src/library/gl.c @@ -1392,12 +1392,25 @@ void _bolt_gl_onDrawElements(GLenum mode, GLsizei count, GLenum type, const void const uint8_t is_minimap2d_target = tex_target && tex_target->is_minimap_tex_small; if (tex->is_minimap_tex_small && count == 6) { - const struct GLAttrBinding* binding = &attributes[c->bound_program->loc_aVertexPosition2D]; + const struct GLAttrBinding* position = &attributes[c->bound_program->loc_aVertexPosition2D]; + const struct GLAttrBinding* uv = &attributes[c->bound_program->loc_aTextureUV]; int32_t xy0[2]; int32_t xy2[2]; - if (!_bolt_get_attr_binding_int(c, binding, 0, 2, xy0)) return; - if (!_bolt_get_attr_binding_int(c, binding, 2, 2, xy2)) return; + float uv0[2]; + float uv2[2]; + if (!_bolt_get_attr_binding_int(c, position, 0, 2, xy0)) return; + if (!_bolt_get_attr_binding_int(c, position, 2, 2, xy2)) return; + _bolt_get_attr_binding(c, uv, 0, 2, uv0); + _bolt_get_attr_binding(c, uv, 2, 2, uv2); + const int16_t x1 = (int16_t)roundf(uv0[0] * tex->width); + const int16_t x2 = (int16_t)roundf(uv2[0] * tex->width); + const int16_t y1 = (int16_t)roundf(uv2[1] * tex->height); + const int16_t y2 = (int16_t)roundf(uv0[1] * tex->height); const struct RenderMinimapEvent event = { + .source_x = x1, + .source_y = y1, + .source_w = x2 - x1, + .source_h = y2 - y1, .target_x = (int16_t)xy0[0], .target_y = (int16_t)(roundf(2.0 / projection_matrix[5]) - xy0[1]), .target_w = (uint16_t)(xy2[0] - xy0[0]), diff --git a/src/library/plugin/plugin.h b/src/library/plugin/plugin.h index db2a471..1a87f4d 100644 --- a/src/library/plugin/plugin.h +++ b/src/library/plugin/plugin.h @@ -312,6 +312,10 @@ struct MinimapTerrainEvent { }; struct RenderMinimapEvent { + int16_t source_x; + int16_t source_y; + uint16_t source_w; + uint16_t source_h; int16_t target_x; int16_t target_y; uint16_t target_w; diff --git a/src/library/plugin/plugin_api.c b/src/library/plugin/plugin_api.c index 3304362..63674df 100644 --- a/src/library/plugin/plugin_api.c +++ b/src/library/plugin/plugin_api.c @@ -785,8 +785,17 @@ static int api_minimapterrain_position(lua_State* state) { return 2; } -static int api_renderminimap_xywh(lua_State* state) { - const struct RenderMinimapEvent* render = require_self_userdata(state, "xywh"); +static int api_renderminimap_sourcexywh(lua_State* state) { + const struct RenderMinimapEvent* render = require_self_userdata(state, "sourcexywh"); + lua_pushinteger(state, render->source_x); + lua_pushinteger(state, render->source_y); + lua_pushinteger(state, render->source_w); + lua_pushinteger(state, render->source_h); + return 4; +} + +static int api_renderminimap_targetxywh(lua_State* state) { + const struct RenderMinimapEvent* render = require_self_userdata(state, "targetxywh"); lua_pushinteger(state, render->target_x); lua_pushinteger(state, render->target_y); lua_pushinteger(state, render->target_w); @@ -1648,7 +1657,8 @@ static struct ApiFuncTemplate minimapterrain_functions[] = { }; static struct ApiFuncTemplate renderminimap_functions[] = { - BOLTFUNC(xywh, renderminimap), + BOLTFUNC(sourcexywh, renderminimap), + BOLTFUNC(targetxywh, renderminimap), }; static struct ApiFuncTemplate point_functions[] = {