fix layout
This commit is contained in:
23
meson.build
23
meson.build
@@ -24,6 +24,13 @@ endif
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
|
||||
# adding cblas
|
||||
if host_machine.system() == 'darwin'
|
||||
deps += dependency('appleframeworks', modules: 'accelerate')
|
||||
else
|
||||
deps += dependency('cblas')
|
||||
endif
|
||||
|
||||
if host_machine.system() == 'linux'
|
||||
deps += cc.find_library('asound', required:true)
|
||||
deps += [dependency('x11'), dependency('xi'), dependency('xcursor'), dependency('egl'), dependency('gl')]
|
||||
@@ -59,26 +66,12 @@ if storefront == 'steam'
|
||||
deps += dependency('qjs-steam',static:false)
|
||||
endif
|
||||
|
||||
cmake = import('cmake')
|
||||
#cmake_ozz = cmake.subproject('ozz')
|
||||
cmake_sdl3 = cmake.subproject('SDL')
|
||||
message('CMake targets:\n - ' + '\n - '.join(cmake_sdl3.target_list()))
|
||||
sdl3_lib = cmake_sdl3.dependency('SDL3-shared')
|
||||
|
||||
#deps += dependency('openblas')
|
||||
deps += dependency('qjs-layout',static:true)
|
||||
deps += dependency('qjs-nota',static:true)
|
||||
deps += dependency('qjs-miniz',static:true)
|
||||
deps += dependency('qjs-soloud',static:true)
|
||||
deps += sdl3_lib
|
||||
|
||||
deps += dependency('sdl3')
|
||||
deps += dependency('physfs',static:true)
|
||||
#deps += cmake_ozz.dependency('ozz_base')
|
||||
#deps += dependency('sdl2_image')
|
||||
#deps += dependency('ogg') # for sdl2_mixer
|
||||
#deps += dependency('sdl2_mixer')
|
||||
#deps += dependency('sdl2_ttf')
|
||||
|
||||
|
||||
deps += dependency('threads')
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ var clay_base = {
|
||||
margin:0,
|
||||
offset:[0,0],
|
||||
size:undefined,
|
||||
background_color: undefined
|
||||
};
|
||||
|
||||
var root_item;
|
||||
@@ -38,7 +39,7 @@ clay.normalizeSpacing = function normalizeSpacing(spacing) {
|
||||
}
|
||||
}
|
||||
|
||||
clay.draw = function draw(size, fn)
|
||||
clay.draw = function draw(size, fn, config = {})
|
||||
{
|
||||
lay_ctx.reset();
|
||||
boxes = [];
|
||||
@@ -74,6 +75,10 @@ clay.draw = function draw(size, fn)
|
||||
box.marginbox.y -= margin.t;
|
||||
box.marginbox.width += margin.l+margin.r;
|
||||
box.marginbox.height += margin.t+margin.b;
|
||||
box.content.y *= -1;
|
||||
box.content.y += size.y;
|
||||
box.boundingbox.y *= -1;
|
||||
box.boundingbox.y += size.y;
|
||||
box.content.anchor_y = 1;
|
||||
box.boundingbox.anchor_y = 1;
|
||||
}
|
||||
@@ -220,13 +225,10 @@ layout.newframe = function() { hovered = undefined; }
|
||||
layout.draw_commands = function draw_commands(cmds, pos = [0,0], mousepos)
|
||||
{
|
||||
for (var cmd of cmds) {
|
||||
var boundingbox = geometry.rect_move(cmd.boundingbox,pos);
|
||||
// boundingbox.x -= boundingbox.width*pos.anchor_x;
|
||||
// boundingbox.y += boundingbox.height*pos.anchor_y;
|
||||
var content = geometry.rect_move(cmd.content,pos);
|
||||
// content.x -= content.width*pos.anchor_x;
|
||||
// content.y += content.height*pos.anchor_y;
|
||||
var config = cmd.config;
|
||||
var config = cmd.config;
|
||||
var boundingbox = geometry.rect_move(cmd.boundingbox,pos.add(config.offset));
|
||||
var content = geometry.rect_move(cmd.content,pos.add(config.offset));
|
||||
|
||||
|
||||
if (config.hovered && geometry.rect_point_inside(boundingbox, mousepos)) {
|
||||
config.hovered.__proto__ = config;
|
||||
@@ -259,11 +261,7 @@ layout.draw_debug = function draw_debug(cmds, pos = [0,0])
|
||||
for (var i = 0; i < cmds.length; i++) {
|
||||
var cmd = cmds[i];
|
||||
var boundingbox = geometry.rect_move(cmd.boundingbox,pos);
|
||||
// boundingbox.x -= boundingbox.width*pos.anchor_x;
|
||||
// boundingbox.y += boundingbox.height*pos.anchor_y;
|
||||
var content = geometry.rect_move(cmd.content,pos);
|
||||
// content.x -= content.width*pos.anchor_x;
|
||||
// content.y += content.height*pos.anchor_y;
|
||||
render.rectangle(content, dbg_colors.content);
|
||||
render.rectangle(boundingbox, dbg_colors.boundingbox);
|
||||
// render.rectangle(geometry.rect_move(cmd.marginbox,pos), dbg_colors.margin);
|
||||
|
||||
@@ -114,8 +114,6 @@ prosperon.init = function () {
|
||||
};
|
||||
if (io.exists("game.js")) global.app = actor.spawn("game.js");
|
||||
else global.app = actor.spawn("nogame.js");
|
||||
|
||||
console.log(io.exists("game.js"))
|
||||
};
|
||||
|
||||
prosperon.release_mode = function () {
|
||||
|
||||
@@ -865,6 +865,8 @@ render.rectangle = function render_rectangle(rect, color = Color.white, shader =
|
||||
};
|
||||
|
||||
render.text = function text(str, rect, font = cur_font, size = 0, color = Color.white, wrap = -1, ) {
|
||||
if (typeof font === 'string')
|
||||
font = render.get_font(font)
|
||||
var mesh = os.make_text_buffer(str, rect, 0, color, wrap, font);
|
||||
render._main.geometry(font.texture, mesh);
|
||||
return;
|
||||
@@ -1171,7 +1173,6 @@ render.get_font = function get_font(path,size)
|
||||
}
|
||||
path = Resources.find_font(path);
|
||||
var fontstr = `${path}.${size}`;
|
||||
console.log(`getting ${fontstr}`);
|
||||
if (fontcache[fontstr]) return fontcache[fontstr];
|
||||
|
||||
var data = io.slurpbytes(path);
|
||||
|
||||
@@ -12,7 +12,6 @@ if (ignore = io.slurp('.prosperonignore')) {
|
||||
}
|
||||
}
|
||||
*/
|
||||
//console.info(allpaths)
|
||||
|
||||
var appy = {};
|
||||
appy.inputs = {};
|
||||
@@ -302,8 +301,6 @@ Cmdline.register_order(
|
||||
if (io.exists("config.js")) global.mixin("config.js");
|
||||
else console.warn("No config.js file found. Starting with default parameters.");
|
||||
var window = game.engine_start(prosperon);
|
||||
console.log(game.renderers());
|
||||
console.log(game.cameras());
|
||||
var renderer = window.make_renderer("gpu");
|
||||
render._main = renderer;
|
||||
|
||||
|
||||
@@ -86,26 +86,24 @@ struct sFont *MakeFont(void *ttf_buffer, size_t len, int height) {
|
||||
if (!SDL_WriteSurfacePixel(newfont->surface, j, i, 255,255,255,bitmap[i*packsize+j]))
|
||||
printf("SDLERROR: %s\n", SDL_GetError());
|
||||
|
||||
printf("FONT SURFACE IS %p\n", newfont->surface);
|
||||
|
||||
for (unsigned char c = 32; c < 127; c++) {
|
||||
stbtt_packedchar glyph = glyphs[c - 32];
|
||||
|
||||
struct rect r;
|
||||
r.x = (glyph.x0) / (float)packsize;
|
||||
r.w = (glyph.x1-glyph.x0) / (float)packsize;
|
||||
r.y = (glyph.y1) / (float)packsize;
|
||||
r.h = (glyph.y0-glyph.y1) / (float)packsize;
|
||||
rect uv;
|
||||
uv.x = (glyph.x0) / (float)packsize;
|
||||
uv.w = (glyph.x1-glyph.x0) / (float)packsize;
|
||||
uv.y = (glyph.y1) / (float)packsize;
|
||||
uv.h = (glyph.y0-glyph.y1) / (float)packsize;
|
||||
newfont->Characters[c].uv = uv;
|
||||
|
||||
newfont->Characters[c].size = (HMM_Vec2){
|
||||
.x = glyph.x1-glyph.x0,
|
||||
.y = glyph.y1-glyph.y0
|
||||
};
|
||||
|
||||
newfont->Characters[c].Advance = glyph.xadvance; /* x distance from this char to the next */
|
||||
newfont->Characters[c].leftbearing = glyph.xoff;
|
||||
newfont->Characters[c].topbearing = glyph.yoff2;//newfont->ascent - glyph.yoff; -glyph.yoff2;
|
||||
newfont->Characters[c].rect = r;
|
||||
rect quad;
|
||||
quad.x = glyph.xoff;
|
||||
quad.w = glyph.xoff2-glyph.xoff;
|
||||
quad.y = -glyph.yoff2;
|
||||
quad.h = glyph.yoff2-glyph.yoff;
|
||||
newfont->Characters[c].quad = quad;
|
||||
newfont->Characters[c].advance = glyph.xadvance;
|
||||
// printf("glyph for %c is x0,y0,x1,y1: %d,%d,%d,%d\n xoff %g, yoff %g, xadvance %g, xoff2 %g, yoff2 %g\n", c, glyph.x0, glyph.y1, glyph.x1, glyph.y1, glyph.xoff, glyph.yoff, glyph.xadvance, glyph.xoff2, glyph.yoff2);
|
||||
}
|
||||
|
||||
free(bitmap);
|
||||
@@ -136,17 +134,17 @@ int text_flush() {
|
||||
*/
|
||||
}
|
||||
|
||||
void sdrawCharacter(struct text_vert **buffer, struct Character c, HMM_Vec2 cursor, float scale, struct rgba color) {
|
||||
void sdrawCharacter(struct text_vert **buffer, stbtt_packedchar c, HMM_Vec2 cursor, float scale, struct rgba color) {
|
||||
struct text_vert vert;
|
||||
|
||||
vert.pos.x = cursor.X + c.leftbearing;
|
||||
vert.pos.y = cursor.Y + c.topbearing;
|
||||
// vert.pos.x = cursor.X + c.leftbearing;
|
||||
// vert.pos.y = cursor.Y + c.topbearing;
|
||||
// vert.wh = c.size;
|
||||
|
||||
// if (vert.pos.x > frame.l || vert.pos.y > frame.t || (vert.pos.y + vert.wh.y) < frame.b || (vert.pos.x + vert.wh.x) < frame.l) return;
|
||||
|
||||
vert.uv.x = c.rect.x;
|
||||
vert.uv.y = c.rect.y;
|
||||
// vert.uv.x = c.rect.x;
|
||||
// vert.uv.y = c.rect.y;
|
||||
// vert.st.x = c.rect.w;
|
||||
// vert.st.y = c.rect.h;
|
||||
rgba2floats(vert.color.e, color);
|
||||
@@ -154,30 +152,32 @@ void sdrawCharacter(struct text_vert **buffer, struct Character c, HMM_Vec2 curs
|
||||
arrput(*buffer, vert);
|
||||
}
|
||||
|
||||
void draw_char_verts(struct text_vert **buffer, struct Character c, HMM_Vec2 cursor, float scale, struct rgba color)
|
||||
void draw_char_verts(struct text_vert **buffer, struct character c, HMM_Vec2 cursor, float scale, struct rgba color)
|
||||
{
|
||||
// packedchar has
|
||||
// Adds four verts: bottom left, bottom right, top left, top right
|
||||
text_vert bl;
|
||||
bl.pos.x = cursor.X + c.leftbearing;
|
||||
bl.pos.y = cursor.Y - c.topbearing;
|
||||
bl.uv.x = c.rect.x;
|
||||
bl.uv.y = c.rect.y+c.rect.h;
|
||||
bl.pos.x = cursor.X + c.quad.x;
|
||||
bl.pos.y = cursor.Y + c.quad.y;
|
||||
bl.uv.x = c.uv.x;
|
||||
bl.uv.y = c.uv.y;
|
||||
rgba2floats(bl.color.e, color);
|
||||
arrput(*buffer, bl);
|
||||
|
||||
|
||||
text_vert br = bl;
|
||||
br.pos.x += c.size.x;
|
||||
br.uv.x += c.rect.w;
|
||||
br.pos.x += c.quad.w;
|
||||
br.uv.x += c.uv.w;
|
||||
arrput(*buffer, br);
|
||||
|
||||
text_vert ul = bl;
|
||||
ul.pos.y -= c.size.y;
|
||||
ul.uv.y = c.rect.y;
|
||||
ul.pos.y += c.quad.h;
|
||||
ul.uv.y += c.uv.h;
|
||||
arrput(*buffer, ul);
|
||||
|
||||
text_vert ur = ul;
|
||||
ur.pos.x += c.size.x;
|
||||
ur.uv.x += c.rect.w;
|
||||
ur.pos.x = br.pos.x;
|
||||
ur.uv.x = br.uv.x;
|
||||
arrput(*buffer, ur);
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ HMM_Vec2 measure_text(const char *text, font *f, float size, float letterSpacing
|
||||
height += lineHeight + f->linegap;
|
||||
continue;
|
||||
}
|
||||
lineWidth += f->Characters[*c].Advance + letterSpacing;
|
||||
lineWidth += f->Characters[*c].advance + letterSpacing;
|
||||
}
|
||||
|
||||
maxWidth = fmaxf(maxWidth, lineWidth);
|
||||
@@ -255,7 +255,7 @@ struct text_vert *renderText(const char *text, HMM_Vec2 pos, font *f, float scal
|
||||
}
|
||||
|
||||
draw_char_verts(&buffer, f->Characters[*c], cursor, scale, color);
|
||||
cursor.x += f->Characters[*c].Advance;
|
||||
cursor.x += f->Characters[*c].advance;
|
||||
}
|
||||
return buffer;
|
||||
/*
|
||||
@@ -267,7 +267,7 @@ struct text_vert *renderText(const char *text, HMM_Vec2 pos, font *f, float scal
|
||||
while (*line != '\0') {
|
||||
if (isblank(*line)) {
|
||||
sdrawCharacter(f->Characters[*line], cursor, scale, usecolor);
|
||||
cursor.X += f->Characters[*line].Advance * scale;
|
||||
cursor.X += f->Characters[*line].advance * scale;
|
||||
line++;
|
||||
} else if (isspace(*line)) {
|
||||
sdrawCharacter(f->Characters[*line], cursor, scale, usecolor);
|
||||
@@ -283,7 +283,7 @@ struct text_vert *renderText(const char *text, HMM_Vec2 pos, font *f, float scal
|
||||
|
||||
while (!isspace(*line) && *line != '\0') {
|
||||
|
||||
wordWidth += f->Characters[*line].Advance * scale;
|
||||
wordWidth += f->Characters[*line].advance * scale;
|
||||
line++;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ struct text_vert *renderText(const char *text, HMM_Vec2 pos, font *f, float scal
|
||||
|
||||
sdrawCharacter(f->Characters[*wordstart], cursor, scale, usecolor);
|
||||
|
||||
cursor.X += f->Characters[*wordstart].Advance * scale;
|
||||
cursor.X += f->Characters[*wordstart].advance * scale;
|
||||
wordstart++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <quickjs.h>
|
||||
#include "texture.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include "render.h"
|
||||
|
||||
typedef enum {
|
||||
LEFT,
|
||||
@@ -25,13 +26,14 @@ typedef struct text_vert text_vert;
|
||||
struct shader;
|
||||
struct window;
|
||||
|
||||
/// Holds all state information relevant to a character as loaded using FreeType
|
||||
struct Character {
|
||||
float Advance; // Horizontal offset to advance to next glyph
|
||||
float leftbearing; // X offset from cursor to render at
|
||||
float topbearing; // Y offset from cursor to render at
|
||||
struct rect rect; // the rect on the font image to render from, uv coordinates
|
||||
HMM_Vec2 size; // The pixel size of this letter
|
||||
struct character {
|
||||
float advance;
|
||||
rect quad;
|
||||
rect uv;
|
||||
float xoff;
|
||||
float yoff;
|
||||
float width;
|
||||
float height;
|
||||
};
|
||||
|
||||
// text data
|
||||
@@ -40,7 +42,7 @@ struct sFont {
|
||||
float ascent; // pixels
|
||||
float descent; // pixels
|
||||
float linegap; //pixels
|
||||
struct Character Characters[256];
|
||||
struct character Characters[256];
|
||||
SDL_Surface *surface;
|
||||
};
|
||||
|
||||
|
||||
@@ -497,8 +497,6 @@ int js_print_exception(JSContext *js, JSValue v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef SDL_FRect rect;
|
||||
|
||||
rect js2rect(JSContext *js,JSValue v) {
|
||||
rect rect;
|
||||
rect.w = js_getnum(js,v,width_atom);
|
||||
@@ -716,12 +714,13 @@ JSValue make_quad_indices_buffer(JSContext *js, int quads)
|
||||
|
||||
JSC_CCALL(os_make_text_buffer,
|
||||
const char *s = JS_ToCString(js, argv[0]);
|
||||
HMM_Vec2 startpos = js2vec2(js,argv[1]);
|
||||
rect rectpos = js2rect(js,argv[1]);
|
||||
float size = js2number(js,argv[2]);
|
||||
font *f = js2font(js,argv[5]);
|
||||
if (!size) size = f->height;
|
||||
struct rgba c = js2color(js,argv[3]);
|
||||
int wrap = js2number(js,argv[4]);
|
||||
HMM_Vec2 startpos = {.x = rectpos.x, .y = rectpos.y };
|
||||
text_vert *buffer = renderText(s, startpos, f, size, c, wrap);
|
||||
size_t verts = arrlen(buffer);
|
||||
|
||||
@@ -2740,7 +2739,6 @@ JSC_CCALL(os_make_font,
|
||||
if (!f) return JS_ThrowReferenceError(js, "could not create font");
|
||||
ret = font2js(js,f);
|
||||
JS_SetPropertyStr(js, ret, "surface", SDL_Surface2js(js,f->surface));
|
||||
printf("texture is %dx%d at %p\n", f->surface->w, f->surface->h, f->surface);
|
||||
)
|
||||
|
||||
JSC_CCALL(os_make_transform, return transform2js(js,make_transform()))
|
||||
|
||||
@@ -54,6 +54,8 @@ struct rect {
|
||||
float x,y,w,h;
|
||||
};
|
||||
|
||||
typedef SDL_FRect rect;
|
||||
|
||||
float *rgba2floats(float *r, struct rgba c);
|
||||
|
||||
static inline float lerp(float f, float a, float b)
|
||||
|
||||
Reference in New Issue
Block a user