Skip to content

Commit

Permalink
library: itemicon colour() api
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamcake committed Dec 1, 2024
1 parent c3a74a0 commit b27b30d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/library/gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ void _bolt_gl_onDrawElements(GLenum mode, GLsizei count, GLenum type, const void
}
int32_t xy0[2];
int32_t xy2[2];
float abgr[4];
_bolt_get_attr_binding_int(c, vertex_userdata.position, indices[i], 2, xy0);
_bolt_get_attr_binding_int(c, vertex_userdata.position, indices[i + 2], 2, xy2);
struct RenderItemIconEvent event;
Expand All @@ -1545,6 +1546,10 @@ void _bolt_gl_onDrawElements(GLenum mode, GLsizei count, GLenum type, const void
event.target_y = (int16_t)((int32_t)batch.screen_height - xy2[1]);
event.target_w = (uint16_t)(xy0[0] - xy2[0]);
event.target_h = (uint16_t)(xy2[1] - xy0[1]);
_bolt_get_attr_binding(c, vertex_userdata.colour, indices[i], 4, abgr);
for (size_t i = 0; i < 4; i += 1) {
event.rgba[i] = abgr[3 - i];
}
_bolt_plugin_handle_rendericon(&event);
batch_start = i + batch.vertices_per_icon;
}
Expand Down
1 change: 1 addition & 0 deletions src/library/plugin/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ struct RenderItemIconEvent {
uint16_t target_y;
uint16_t target_w;
uint16_t target_h;
float rgba[4];
};

struct MinimapTerrainEvent {
Expand Down
12 changes: 11 additions & 1 deletion src/library/plugin/plugin_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ static int api_rendericon_modelvertexpoint(lua_State* state) {
}

static int api_rendericon_modelvertexcolour(lua_State* state) {
const struct RenderItemIconEvent* event = require_self_userdata(state, "modelvertexpoint");
const struct RenderItemIconEvent* event = require_self_userdata(state, "modelvertexcolour");
const size_t model = luaL_checkinteger(state, 2);
const size_t vertex = luaL_checkinteger(state, 3);
for (size_t i = 0; i < 4; i += 1) {
Expand All @@ -1257,6 +1257,14 @@ static int api_rendericon_modelvertexcolour(lua_State* state) {
return 4;
}

static int api_rendericon_colour(lua_State* state) {
const struct RenderItemIconEvent* event = require_self_userdata(state, "colour");
for (size_t i = 0; i < 4; i += 1) {
lua_pushnumber(state, event->rgba[i]);
}
return 4;
}

static int api_rendericon_modelviewmatrix(lua_State* state) {
const struct RenderItemIconEvent* event = require_self_userdata(state, "modelviewmatrix");
const size_t model = luaL_checkinteger(state, 2);
Expand Down Expand Up @@ -1648,6 +1656,8 @@ static struct ApiFuncTemplate rendericon_functions[] = {
BOLTFUNC(modelprojectionmatrix, rendericon),
BOLTFUNC(modelviewprojmatrix, rendericon),
BOLTALIAS(modelvertexcolour, modelvertexcolor, rendericon),
BOLTFUNC(colour, rendericon),
BOLTALIAS(colour, color, rendericon),
};

static struct ApiFuncTemplate minimapterrain_functions[] = {
Expand Down

0 comments on commit b27b30d

Please sign in to comment.