Skip to content

Commit

Permalink
Merge pull request #62 from bramtechs/master
Browse files Browse the repository at this point in the history
Suggestion: Get texture2d width and height (issue #51)
  • Loading branch information
bakpakin authored May 12, 2024
2 parents 51e88ff + 5f75bb4 commit c47d417
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,42 @@ static Shader *jaylib_getshader(const Janet *argv, int32_t n) {
return ((Shader *)janet_getabstract(argv, n, &AT_Shader));
};

int texture2d_get(void* p, Janet key, Janet *out);

static const JanetAbstractType AT_Texture2D = {
"jaylib/texture2d",
JANET_ATEND_NAME
NULL,
NULL,
texture2d_get,
JANET_ATEND_GET,
};

static Texture2D *jaylib_gettexture2d(const Janet *argv, int32_t n) {
return ((Texture2D *)janet_getabstract(argv, n, &AT_Texture2D));
}

int texture2d_get(void* p, Janet key, Janet *out) {
Texture2D *texture = (Texture2D *) p;

if (!janet_checktype(key, JANET_KEYWORD)) {
janet_panic("expected keyword");
}

const uint8_t *kw = janet_unwrap_keyword(key);

if (!janet_cstrcmp(kw, "width")) {
*out = janet_wrap_integer(texture->width);
return 1;
}

if (!janet_cstrcmp(kw, "height")) {
*out = janet_wrap_integer(texture->height);
return 1;
}

return 0;
}

static const JanetAbstractType AT_Image = {
"jaylib/image",
JANET_ATEND_NAME
Expand Down

0 comments on commit c47d417

Please sign in to comment.