Compare commits

..

6 Commits

Author SHA1 Message Date
Mid
69f355eae4 Up max index count to 4 gigs 2025-09-30 11:03:49 +03:00
Mid
676127c41f Correct drawing order 2025-09-19 23:11:19 +03:00
Mid
9ae4abbb56 memcpy -> memmove 2025-09-19 23:11:12 +03:00
Mid
0461199e64 Prefer size property over struct field 2025-09-19 23:11:03 +03:00
Mid
05d0c75937 Linear layout should acknowledge width property 2025-09-19 23:10:44 +03:00
Mid
1ee7d6c26e Fix font boundary 2025-09-19 23:10:25 +03:00
4 changed files with 30 additions and 11 deletions

View File

@ -283,7 +283,7 @@ void k3MdlUpdateNrm(struct k3Mdl *mdl, uint8_t *nrm) {
glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, mdl->offN, 3 * mdl->verts, nrm); glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, mdl->offN, 3 * mdl->verts, nrm);
} }
void k3MdlAddMesh(struct k3Mdl *mdl, struct k3Mat *mat, uint16_t idxStart, uint16_t idxNumber) { void k3MdlAddMesh(struct k3Mdl *mdl, struct k3Mat *mat, uint32_t idxStart, uint32_t idxNumber) {
mdl->meshes = realloc(mdl->meshes, sizeof(*mdl->meshes) * (mdl->meshCount + 1)); mdl->meshes = realloc(mdl->meshes, sizeof(*mdl->meshes) * (mdl->meshCount + 1));
struct k3Mesh *mehs = &mdl->meshes[mdl->meshCount++]; struct k3Mesh *mehs = &mdl->meshes[mdl->meshCount++];
mehs->idxStart = idxStart; mehs->idxStart = idxStart;

View File

@ -146,7 +146,7 @@ struct k3Light {
}; };
struct k3Mesh { struct k3Mesh {
uint16_t idxStart, idxNumber; uint32_t idxStart, idxNumber;
struct k3Mat mat; struct k3Mat mat;
}; };
@ -159,7 +159,7 @@ void k3StorageUnref(struct k3Storage*);
struct k3Mdl; struct k3Mdl;
struct k3Mdl *k3MdlCreate(size_t verts, size_t indices, size_t boneCount, vec3 *pos, uint8_t *nrm, float *uvs, uint8_t *cols, uint8_t *boneids, uint16_t *boneweights, uint16_t *inds, mat4 *invBind, uint8_t *boneParents); struct k3Mdl *k3MdlCreate(size_t verts, size_t indices, size_t boneCount, vec3 *pos, uint8_t *nrm, float *uvs, uint8_t *cols, uint8_t *boneids, uint16_t *boneweights, uint16_t *inds, mat4 *invBind, uint8_t *boneParents);
void k3MdlUpdatePos(struct k3Mdl *mdl, vec3 *pos); void k3MdlUpdatePos(struct k3Mdl *mdl, vec3 *pos);
void k3MdlAddMesh(struct k3Mdl*, struct k3Mat*, uint16_t idxStart, uint16_t idxNumber); void k3MdlAddMesh(struct k3Mdl*, struct k3Mat*, uint32_t idxStart, uint32_t idxNumber);
struct k3Mesh *k3MdlGetMeshes(struct k3Mdl*, size_t *count); struct k3Mesh *k3MdlGetMeshes(struct k3Mdl*, size_t *count);
void k3MdlAddAnim(struct k3Mdl*, struct k3AnimationFountain*); void k3MdlAddAnim(struct k3Mdl*, struct k3AnimationFountain*);
struct k3AnimationFountain *k3MdlGetAnim(struct k3Mdl*, uint16_t id); struct k3AnimationFountain *k3MdlGetAnim(struct k3Mdl*, uint16_t id);

View File

@ -153,13 +153,15 @@ void k3FontDraw(struct k3Font *this, float xStart, float yStart, float sz, const
break; break;
} }
lineLength++;
struct k3FontGlyph *g = k3FontGetGlyph(this, cp2); struct k3FontGlyph *g = k3FontGetGlyph(this, cp2);
if(g) { if(g) {
if(lineWidth + g->width * this->lineScale * sz > wall) { if(lineWidth + g->width * this->lineScale * sz > wall) {
break; break;
} }
}
lineLength++;
if(g) {
lineWidth += g->xadvance * this->lineScale * sz; lineWidth += g->xadvance * this->lineScale * sz;
} }
} }
@ -189,7 +191,7 @@ void k3FontDraw(struct k3Font *this, float xStart, float yStart, float sz, const
size_t texH = this->texH; size_t texH = this->texH;
k3BatchAdd(tex, k3BatchAdd(tex,
(struct k3RectF) {(float) g->x / texW, (float) g->y / texH, (float) g->width / texW, (float) g->height / texH}, (struct k3RectF) {(float) (g->x + 0.5) / texW, (float) (g->y + 0.5) / texH, (float) (g->width - 1) / texW, (float) (g->height - 1) / texH},
(struct k3RectF) { (struct k3RectF) {
x + g->xoffset * this->lineScale * sz, x + g->xoffset * this->lineScale * sz,
y + ((-g->height - g->yoffset) * this->lineScale + 1) * sz, y + ((-g->height - g->yoffset) * this->lineScale + 1) * sz,

View File

@ -100,6 +100,15 @@ static bool linear_arrange(struct k3MEvent *ev, uint8_t *ud) {
c->x = o->x + padding[3]; c->x = o->x + padding[3];
c->y = y; c->y = y;
struct k3MProperty *prop = k3MFindProperty(c, k3M_PROP_WIDTH, true);
if(prop) {
if(prop->units[0] == k3M_UNIT_ABSOLUTE) {
c->w = prop->f[0];
} else if(prop->units[0] == k3M_UNIT_PROPORTION) {
c->w = o->w * prop->f[0];
}
}
if(c->w > o->w - padding[1] - padding[3]) { if(c->w > o->w - padding[1] - padding[3]) {
c->w = o->w - padding[1] - padding[3]; c->w = o->w - padding[1] - padding[3];
} }
@ -245,7 +254,7 @@ static bool label_draw(struct k3MEvent *ev, uint8_t *ud) {
if(va != k3M_ALIGN_TOP) { if(va != k3M_ALIGN_TOP) {
struct k3RectF txtsz; struct k3RectF txtsz;
k3FontSz(this->font, this->sz, this->txt, this->w, &txtsz); k3FontSz(this->font, sz, this->txt, this->w, &txtsz);
if(va == k3M_ALIGN_CENTER) { if(va == k3M_ALIGN_CENTER) {
y += (this->h - txtsz.h) / 2; y += (this->h - txtsz.h) / 2;
} else if(va == k3M_ALIGN_BOTTOM) { } else if(va == k3M_ALIGN_BOTTOM) {
@ -262,8 +271,12 @@ static bool label_draw(struct k3MEvent *ev, uint8_t *ud) {
static bool label_measure(struct k3MEvent *ev, uint8_t *ud) { static bool label_measure(struct k3MEvent *ev, uint8_t *ud) {
struct k3MLabel *this = (void*) ev->target; struct k3MLabel *this = (void*) ev->target;
float sz = this->sz;
struct k3MProperty *prop = k3MFindProperty(this, k3M_PROP_FONT_SIZE, false);
if(prop) sz = prop->f[0];
struct k3RectF txtsz; struct k3RectF txtsz;
k3FontSz(this->font, this->sz, this->txt, -1, &txtsz); k3FontSz(this->font, sz, this->txt, -1, &txtsz);
this->w = ceilf(txtsz.w); this->w = ceilf(txtsz.w);
this->h = ceilf(txtsz.h); this->h = ceilf(txtsz.h);
@ -273,8 +286,12 @@ static bool label_measure(struct k3MEvent *ev, uint8_t *ud) {
static bool label_set_height_from_width(struct k3MEvent *ev, uint8_t *ud) { static bool label_set_height_from_width(struct k3MEvent *ev, uint8_t *ud) {
struct k3MLabel *this = (void*) ev->target; struct k3MLabel *this = (void*) ev->target;
float sz = this->sz;
struct k3MProperty *prop = k3MFindProperty(this, k3M_PROP_FONT_SIZE, false);
if(prop) sz = prop->f[0];
int16_t pxsz[2]; int16_t pxsz[2];
immdraw_font_size(this->font, this->sz, this->txt, this->w, pxsz); immdraw_font_size(this->font, sz, this->txt, this->w, pxsz);
this->h = pxsz[1]; this->h = pxsz[1];
@ -297,7 +314,7 @@ struct k3MLabel *k3MLabel(struct k3Font *font, float sz, const char *txt) {
int k3MRemoveChild(struct k3MObj *parent, struct k3MObj *child) { int k3MRemoveChild(struct k3MObj *parent, struct k3MObj *child) {
for(size_t i = 0; i < parent->childCount; i++) { for(size_t i = 0; i < parent->childCount; i++) {
if(parent->children[i] == child) { if(parent->children[i] == child) {
memcpy(&parent->children[i], &parent->children[i + 1], sizeof(*parent->children) * (parent->childCount - i - 1)); memmove(&parent->children[i], &parent->children[i + 1], sizeof(*parent->children) * (parent->childCount - i - 1));
parent->childCount--; parent->childCount--;
@ -455,7 +472,7 @@ static bool screen_ev(struct k3MEvent *ev, uint8_t *ud) {
} }
for(intmax_t i = this->childCount - 1; i >= 0; i--) { for(intmax_t i = 0; i < this->childCount; i++) {
if(!this->children[i]->invisible) { if(!this->children[i]->invisible) {
struct k3MEvent newev = *ev; struct k3MEvent newev = *ev;
newev.kind = k3M_EVENTKIND_CAPTURE; newev.kind = k3M_EVENTKIND_CAPTURE;