vector imgui
This commit is contained in:
parent
5ddf3558ef
commit
d33c1af92c
3
Makefile
3
Makefile
|
@ -75,7 +75,7 @@ else
|
|||
CPPFLAGS += -O2
|
||||
endif
|
||||
|
||||
CPPFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DCP_USE_DOUBLES=0 -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) $(WARNING_FLAGS) -I. -DVER=\"$(SEM)\" -DCOM=\"$(COM)\" -DINFO=\"$(INFO)\" -Wno-narrowing #-DENABLE_SINC_MEDIUM_CONVERTER -DENABLE_SINC_FAST_CONVERTER -DCP_COLLISION_TYPE_TYPE=uintptr_t -DCP_BITMASK_TYPE=uintptr_t
|
||||
CPPFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DCP_USE_DOUBLES=0 -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) $(WARNING_FLAGS) -I. -DVER=\"$(SEM)\" -DCOM=\"$(COM)\" -DDATE=\"$(DATE)\" -DINFO=\"$(INFO)\" -Wno-narrowing #-DENABLE_SINC_MEDIUM_CONVERTER -DENABLE_SINC_FAST_CONVERTER -DCP_COLLISION_TYPE_TYPE=uintptr_t -DCP_BITMASK_TYPE=uintptr_t
|
||||
CPPFLAGS += -DCONFIG_VERSION=\"2024-02-14\" -DCONFIG_BIGNUM #for quickjs
|
||||
|
||||
# ENABLE_SINC_[BEST|FAST|MEDIUM]_CONVERTER
|
||||
|
@ -166,6 +166,7 @@ APP = prosperon
|
|||
NAME = $(APP)$(INFO)$(EXT)
|
||||
SEM != git describe --tags --abbrev=0
|
||||
COM != git rev-parse --short HEAD
|
||||
DATE != date +%s
|
||||
|
||||
LDLIBS += $(STEAMAPI)
|
||||
LDLIBS := $(addprefix -l, $(LDLIBS))
|
||||
|
|
|
@ -113,7 +113,6 @@ Resources.is_path = function(str)
|
|||
return !/[\\\/:*?"<>|]/.test(str);
|
||||
}
|
||||
|
||||
|
||||
globalThis.json = {};
|
||||
json.encode = function (value, replacer, space = 1) {
|
||||
return JSON.stringify(value, replacer, space);
|
||||
|
|
244
scripts/gui.js
244
scripts/gui.js
|
@ -1,244 +0,0 @@
|
|||
/*
|
||||
gui functions take screen space coordinates
|
||||
*/
|
||||
|
||||
gui.scissor_win = function() { gui.scissor(0,0,window.size.x,window.y); }
|
||||
|
||||
gui.input_lmouse_pressed = function() {
|
||||
if (gui.selected)
|
||||
gui.selected.action();
|
||||
};
|
||||
|
||||
gui.input_s_pressed = function() {
|
||||
if (gui.selected?.down) {
|
||||
gui.selected.selected = false;
|
||||
gui.selected = gui.selected.down;
|
||||
gui.selected.selected = true;
|
||||
}
|
||||
};
|
||||
|
||||
gui.input_w_pressed = function() {
|
||||
if (gui.selected?.up) {
|
||||
gui.selected.selected = false;
|
||||
gui.selected = gui.selected.up;
|
||||
gui.selected.selected = true;
|
||||
}
|
||||
};
|
||||
|
||||
gui.input_enter_pressed = function() {
|
||||
if (gui.selected) {
|
||||
gui.selected.action();
|
||||
}
|
||||
}
|
||||
|
||||
gui.controls = {};
|
||||
gui.controls.toString = function() { return "gui controls"; };
|
||||
gui.controls.update = function() { };
|
||||
|
||||
gui.controls.set_mum = function(mum)
|
||||
{
|
||||
mum.selected = true;
|
||||
|
||||
if (this.selected && this.selected !== mum)
|
||||
this.selected.selected = false;
|
||||
|
||||
this.selected = mum;
|
||||
}
|
||||
gui.controls.check_bb = function(mum)
|
||||
{
|
||||
if (bbox.pointin(mum.bb, input.mouse.screenpos()))
|
||||
gui.controls.set_mum(mum);
|
||||
}
|
||||
gui.controls.inputs = {};
|
||||
gui.controls.inputs.fallthru = false;
|
||||
gui.controls.inputs.mouse = {};
|
||||
gui.controls.inputs.mouse.move = function(pos,dpos)
|
||||
{
|
||||
}
|
||||
gui.controls.inputs.mouse.scroll = function(scroll)
|
||||
{
|
||||
}
|
||||
|
||||
gui.controls.check_submit = function() {
|
||||
if (this.selected && this.selected.action)
|
||||
this.selected.action(this.selected);
|
||||
}
|
||||
|
||||
var Mum = {
|
||||
padding:[0,0], /* Each element inset with this padding on all sides */
|
||||
offset:[0,0],
|
||||
font: "fonts/c64.ttf",
|
||||
selectable: false,
|
||||
selected: false,
|
||||
font_size: 1,
|
||||
text_align: "left", /* left, center, right */
|
||||
scale: 1,
|
||||
angle: 0,
|
||||
anchor: [0,1],
|
||||
hovered: {},
|
||||
text_shadow: {
|
||||
pos: [0,0],
|
||||
color: Color.white,
|
||||
},
|
||||
text_outline: 1, /* outline in pixels */
|
||||
color: Color.white,
|
||||
margin: [0,0], /* Distance between elements for things like columns */
|
||||
width: 0,
|
||||
height: 0,
|
||||
max_width: Infinity,
|
||||
max_height: Infinity,
|
||||
image_repeat: false,
|
||||
image_repeat_offset: [0,0],
|
||||
debug: false, /* set to true to draw debug boxes */
|
||||
|
||||
make(def) {
|
||||
var n = Object.create(this);
|
||||
Object.assign(n, def);
|
||||
return n;
|
||||
},
|
||||
|
||||
prestart() {
|
||||
this.hovered.__proto__ = this;
|
||||
},
|
||||
|
||||
start() {},
|
||||
|
||||
extend(def) {
|
||||
var n = Object.create(this);
|
||||
Object.assign(n, def);
|
||||
var fn = function(def) {
|
||||
var p = n.make(def);
|
||||
p.prestart();
|
||||
p.start();
|
||||
return p;
|
||||
};
|
||||
fn._int = n;
|
||||
return fn;
|
||||
},
|
||||
}
|
||||
|
||||
Mum.text = Mum.extend({
|
||||
draw(cursor = [0,0], cnt = Mum) {
|
||||
if (this.hide) return;
|
||||
if (this.selectable) gui.controls.check_bb(this);
|
||||
this.caret ??= -1;
|
||||
|
||||
/* if (!this.bb)
|
||||
this.calc_bb(cursor);
|
||||
else
|
||||
this.update_bb(cursor);
|
||||
*/
|
||||
var params = this.selected ? this.hovered : this;
|
||||
|
||||
this.width = Math.min(params.max_width, cnt.max_width);
|
||||
|
||||
this.calc_bb(cursor);
|
||||
this.height = this.wh.y;
|
||||
var aa = [0,1].sub(params.anchor);
|
||||
var pos = cursor.add(params.wh.scale(aa)).add(params.offset);
|
||||
// gui.font_set(params.font);
|
||||
render.text(params.str, pos, params.font_size, params.color, this.width, undefined, params.caret);
|
||||
},
|
||||
|
||||
update_bb(cursor) {
|
||||
this.bb = bbox.move(this.bb, cursor.sub(this.wh.scale(this.anchor)));
|
||||
},
|
||||
|
||||
calc_bb(cursor) {
|
||||
var bb = render.text_size(this.str, this.font_size, this.width);
|
||||
this.wh = bbox.towh(bb);
|
||||
var pos = cursor.add(this.wh.scale([0,1].sub(this.anchor))).add(this.offset);
|
||||
this.bb = bbox.move(bb,pos.add([this.wh.x/2,0]));
|
||||
},
|
||||
start() {
|
||||
this.calc_bb([0,0]);
|
||||
},
|
||||
});
|
||||
|
||||
Mum.button = Mum.text._int.extend({
|
||||
selectable: true,
|
||||
color: Color.blue,
|
||||
hovered:{
|
||||
color: Color.red
|
||||
},
|
||||
action() { console.warn("Button has no action."); },
|
||||
});
|
||||
|
||||
Mum.window = Mum.extend({
|
||||
start() {
|
||||
this.wh = [this.width, this.height];
|
||||
this.bb = bbox.fromcwh([0,0], this.wh);
|
||||
},
|
||||
draw(cursor = [0,0], cnt = Mum) {
|
||||
var p = cursor.sub(this.wh.scale(this.anchor)).add(this.padding);
|
||||
render.window(p,this.wh, this.color);
|
||||
this.bb = bbox.blwh(p, this.wh);
|
||||
this.max_width = this.width;
|
||||
if (this.selectable) gui.controls.check_bb(this);
|
||||
var pos = [this.bb.l, this.bb.t].add(this.padding);
|
||||
this.items.forEach(function(item) {
|
||||
if (item.hide) return;
|
||||
item.draw(pos.slice(),this);
|
||||
}, this);
|
||||
|
||||
bind.inst = render.flushtext();
|
||||
render.spdraw(bind);
|
||||
gui.scissor_win();
|
||||
},
|
||||
});
|
||||
|
||||
Mum.image = Mum.extend({
|
||||
start() {
|
||||
if (!this.path) {
|
||||
console.warn("Mum image needs a path.");
|
||||
this.draw = function(){};
|
||||
return;
|
||||
}
|
||||
|
||||
var tex_wh = texture.dimensions(this.path);
|
||||
this.wh = tex_wh.slice();
|
||||
if (this.width !== 0) this.wh.x = this.width;
|
||||
if (this.height !== 0) this.wh.y = this.height;
|
||||
|
||||
this.wh = wh.scale(this.scale);
|
||||
this.sendscale = [wh.x/tex_wh.x, wh.y/tex_wh.y];
|
||||
},
|
||||
|
||||
draw(pos) {
|
||||
this.calc_bb(pos);
|
||||
gui_img(this.path, pos.sub(this.anchor.scale([this.width, this.height])), this.sendscale, this.angle, this.image_repeat, this.image_repeat_offset, this.color);
|
||||
},
|
||||
|
||||
calc_bb(pos) {
|
||||
this.bb = bbox.fromcwh(this.wh.scale([0.5,0.5]), wh);
|
||||
this.bb = bbox.move(this.bb, pos.sub(this.wh.scale(this.anchor)));
|
||||
}
|
||||
});
|
||||
|
||||
Mum.column = Mum.extend({
|
||||
draw(cursor = [0,0], cnt = Mum) {
|
||||
if (this.hide) return;
|
||||
cursor = cursor.add(this.offset);
|
||||
this.max_width = cnt.width;
|
||||
|
||||
this.items.forEach(function(item) {
|
||||
if (item.hide) return;
|
||||
item.draw(cursor, this);
|
||||
cursor.y -= item.height;
|
||||
cursor.y -= this.padding.y;
|
||||
}, this);
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
Mum.debug_colors = {
|
||||
bounds: Color.red.slice(),
|
||||
margin: Color.blue.slice(),
|
||||
padding: Color.green.slice()
|
||||
};*/
|
||||
|
||||
//Object.values(Mum.debug_colors).forEach(function(v) { v.a = 100; });
|
||||
|
||||
//return { Mum };
|
||||
|
||||
|
|
@ -260,8 +260,6 @@ prosperon.semver.cmp = function (v1, v2) {
|
|||
return 0;
|
||||
};
|
||||
|
||||
prosperon.semver.doc =
|
||||
"Functions for semantic versioning numbers. Semantic versioning is given as a triple digit number, as MAJOR.MINOR.PATCH.";
|
||||
prosperon.semver.cmp.doc =
|
||||
"Compare two semantic version numbers, given like X.X.X.";
|
||||
prosperon.semver.valid.doc = `Test if semantic version v is valid, given a range.
|
||||
|
@ -312,7 +310,6 @@ global.mixin("scripts/input");
|
|||
global.mixin("scripts/std");
|
||||
global.mixin("scripts/diff");
|
||||
global.mixin("scripts/color");
|
||||
global.mixin("scripts/gui");
|
||||
global.mixin("scripts/tween");
|
||||
global.mixin("scripts/ai");
|
||||
global.mixin("scripts/particle");
|
||||
|
|
|
@ -213,11 +213,6 @@ Cmdline.register_order("init", function() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!(io.ls().filter(x => x[0] !== '.').length === 0)) {
|
||||
say("Directory is not empty. Make an empty one and init there.");
|
||||
return;
|
||||
}
|
||||
|
||||
io.mkdir(io.dumpfolder);
|
||||
var project = {};
|
||||
project.version = prosperon.version;
|
||||
|
|
|
@ -111,11 +111,32 @@ JSC_CCALL(imgui_sokol_gfx,
|
|||
)
|
||||
|
||||
JSC_SCALL(imgui_slider,
|
||||
float val = js2number(argv[1]);
|
||||
float low = JS_IsUndefined(argv[2]) ? 0.0 : js2number(argv[2]);
|
||||
float high = JS_IsUndefined(argv[3]) ? 1.0 : js2number(argv[3]);
|
||||
|
||||
if (JS_IsArray(js, argv[1])) {
|
||||
int n = js_arrlen(argv[1]);
|
||||
float a[n];
|
||||
js2floatarr(argv[1], n, a);
|
||||
|
||||
switch(n) {
|
||||
case 2:
|
||||
ImGui::SliderFloat2(str, a, low, high);
|
||||
break;
|
||||
case 3:
|
||||
ImGui::SliderFloat3(str, a, low, high);
|
||||
break;
|
||||
case 4:
|
||||
ImGui::SliderFloat3(str, a, low, high);
|
||||
break;
|
||||
}
|
||||
|
||||
ret = floatarr2js(n, a);
|
||||
} else {
|
||||
float val = js2number(argv[1]);
|
||||
ImGui::SliderFloat(str, &val, low, high, "%.3f");
|
||||
ret = number2js(val);
|
||||
}
|
||||
)
|
||||
|
||||
JSC_SCALL(imgui_checkbox,
|
||||
|
|
|
@ -384,6 +384,20 @@ struct boundingbox js2bb(JSValue v)
|
|||
cpVect js2cvec2(JSValue v) { return js2vec2(v).cp; }
|
||||
JSValue cvec22js(cpVect v) { return vec22js((HMM_Vec2)v); }
|
||||
|
||||
void js2floatarr(JSValue v, int n, float *a) {
|
||||
if (!JS_IsArray(js,v)) return;
|
||||
for (int i = 0; i < n; i++)
|
||||
a[i] = js2number(js_getpropidx(v,i));
|
||||
}
|
||||
|
||||
JSValue floatarr2js(int n, float *a) {
|
||||
JSValue arr = JS_NewArray(js);
|
||||
for (int i = 0; i < n; i++)
|
||||
js_setprop_num(arr, i, number2js(a[i]));
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
HMM_Vec2 js2vec2(JSValue v)
|
||||
{
|
||||
HMM_Vec2 v2;
|
||||
|
@ -692,7 +706,6 @@ sg_bindings js2bind(JSValue v)
|
|||
JSValue imgs = js_getpropstr(v, "images");
|
||||
for (int i = 0; i < js_arrlen(imgs); i++) {
|
||||
bind.fs.images[i] = js2texture(js_getpropidx(imgs, i))->id;
|
||||
// printf("printing image with id %d\n", js2texture(js_getpropidx(imgs, i))->id);
|
||||
bind.fs.samplers[i] = std_sampler;
|
||||
}
|
||||
|
||||
|
@ -2716,9 +2729,9 @@ static FILE *cycles;
|
|||
|
||||
JSC_CCALL(os_check_cycles,
|
||||
if (ftell(cycles) == 0) return JS_UNDEFINED;
|
||||
ret = tmp2js(cycles);
|
||||
cycles = tmpfile();
|
||||
quickjs_set_cycleout(cycles);
|
||||
ret = tmp2js(cycles);
|
||||
)
|
||||
|
||||
JSC_CCALL(os_check_gc,
|
||||
|
@ -3256,6 +3269,7 @@ void ffi_load() {
|
|||
|
||||
JS_SetPropertyStr(js, prosperon, "version", str2js(VER));
|
||||
JS_SetPropertyStr(js, prosperon, "revision", str2js(COM));
|
||||
JS_SetPropertyStr(js, prosperon, "date", str2js(DATE));
|
||||
JS_SetPropertyStr(js, globalThis, "window", window2js(&mainwin));
|
||||
JS_SetPropertyStr(js, globalThis, "texture", JS_DupValue(js,texture_proto));
|
||||
|
||||
|
|
|
@ -165,6 +165,8 @@ JSValue js_getpropstr(JSValue v, const char *str);
|
|||
void jsfreestr(const char *str);
|
||||
int js_arrlen(JSValue v);
|
||||
void js_setpropstr(JSValue v, const char *str, JSValue p);
|
||||
void js2floatarr(JSValue v, int n, float *a);
|
||||
JSValue floatarr2js(int n, float *a);
|
||||
|
||||
int js2boolean(JSValue v);
|
||||
JSValue boolean2js(int b);
|
||||
|
|
|
@ -70,12 +70,13 @@ void log_shutdown()
|
|||
const char *logfmt = "%s:%d: [%s] %s, %s: ";
|
||||
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
|
||||
{
|
||||
return;
|
||||
#ifndef NDEBUG
|
||||
time_t now = time(NULL);
|
||||
struct tm *tinfo = localtime(&now);
|
||||
char timebuf[80];
|
||||
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S", tinfo);
|
||||
|
||||
/*
|
||||
fprintf(logout, logfmt, file, line, timebuf, logstr[priority], catstr[category]);
|
||||
|
||||
va_list args;
|
||||
|
@ -83,7 +84,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
|||
vfprintf(logout, message, args);
|
||||
va_end(args);
|
||||
fprintf(logout, "\n");
|
||||
|
||||
*/
|
||||
if (priority == LOG_DEBUG || priority >= stdout_lvl) {
|
||||
printf(logfmt, file, line, timebuf, logcolor[priority], catstr[category]);
|
||||
va_list args;
|
||||
|
@ -108,17 +109,17 @@ void mYughLog(int category, int priority, int line, const char *file, const char
|
|||
void log_print(const char *str)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
fprintf(writeout, "%s", str);
|
||||
//fprintf(writeout, "%s", str);
|
||||
#else
|
||||
printf(str);
|
||||
fflush(stdout);
|
||||
//printf(str);
|
||||
//fflush(stdout);
|
||||
#endif
|
||||
}
|
||||
|
||||
void term_print(const char *str)
|
||||
{
|
||||
fprintf(stdout, "%s", str);
|
||||
fflush(stdout);
|
||||
//fprintf(stdout, "%s", str);
|
||||
//fflush(stdout);
|
||||
}
|
||||
|
||||
void sg_logging(const char *tag, uint32_t lvl, uint32_t id, const char *msg, uint32_t line, const char *file, void *data) {
|
||||
|
|
Loading…
Reference in a new issue