Compare commits
4 Commits
c63d08c462
...
a8b7171709
| Author | SHA1 | Date | |
|---|---|---|---|
| a8b7171709 | |||
| ed2b36ef0f | |||
| bb6a166f2a | |||
| 793fd1aa28 |
@ -7,7 +7,7 @@
|
|||||||
"working_dir": ""
|
"working_dir": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"args": "build -g",
|
"args": "build -g --threads 8",
|
||||||
"command": "c3c",
|
"command": "c3c",
|
||||||
"working_dir": ""
|
"working_dir": ""
|
||||||
}
|
}
|
||||||
|
|||||||
@ -264,7 +264,7 @@ fn void? Ctx.frame_begin(&ctx)
|
|||||||
elem.layout.h = @exact(ctx.height);
|
elem.layout.h = @exact(ctx.height);
|
||||||
|
|
||||||
ctx.div_scissor = elem.bounds;
|
ctx.div_scissor = elem.bounds;
|
||||||
|
|
||||||
ctx.skip_frame = false;
|
ctx.skip_frame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +278,8 @@ fn void? Ctx.frame_end(&ctx)
|
|||||||
// 2. clear input fields
|
// 2. clear input fields
|
||||||
ctx.input = ctx.current_input;
|
ctx.input = ctx.current_input;
|
||||||
ctx.current_input.events = {};
|
ctx.current_input.events = {};
|
||||||
ctx.current_input.keyboard.text_len = 0;
|
ctx.current_input.mouse.scroll = {};
|
||||||
|
ctx.current_input.keyboard = {};
|
||||||
|
|
||||||
// DO THE LAYOUT
|
// DO THE LAYOUT
|
||||||
ctx.layout_element_tree()!;
|
ctx.layout_element_tree()!;
|
||||||
@ -296,7 +297,7 @@ fn void? Ctx.frame_end(&ctx)
|
|||||||
// Propagate input events to the right elements
|
// Propagate input events to the right elements
|
||||||
ctx.set_elem_events(ctx.hover_id);
|
ctx.set_elem_events(ctx.hover_id);
|
||||||
ctx.set_elem_events(ctx.focus_id);
|
ctx.set_elem_events(ctx.focus_id);
|
||||||
|
|
||||||
|
|
||||||
// 1. clear the tree
|
// 1. clear the tree
|
||||||
ctx.tree.nuke();
|
ctx.tree.nuke();
|
||||||
@ -310,7 +311,7 @@ fn void? Ctx.frame_end(&ctx)
|
|||||||
ctx.push_update_atlas(&ctx.sprite_atlas.atlas)!;
|
ctx.push_update_atlas(&ctx.sprite_atlas.atlas)!;
|
||||||
ctx.sprite_atlas.should_update = false;
|
ctx.sprite_atlas.should_update = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send skip frame request
|
// send skip frame request
|
||||||
if (ctx.skip_frame) {
|
if (ctx.skip_frame) {
|
||||||
ctx.cmd_queue.push({.type = CMD_REQ_SKIP_FRAME});
|
ctx.cmd_queue.push({.type = CMD_REQ_SKIP_FRAME});
|
||||||
@ -338,11 +339,6 @@ $if $feature(DEBUG_POINTER):
|
|||||||
};
|
};
|
||||||
ctx.cmd_queue.push(cmd);
|
ctx.cmd_queue.push(cmd);
|
||||||
$endif
|
$endif
|
||||||
|
|
||||||
// foreach (i, c: ctx.cmd_queue) {
|
|
||||||
// io::printf("[%d]: ", i);
|
|
||||||
// io::printn(c);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -364,16 +360,16 @@ fn void Ctx.update_hover_and_focus(&ctx, Elem* elem)
|
|||||||
|
|
||||||
hover = !(different && still_hovered && shown && above);
|
hover = !(different && still_hovered && shown && above);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (focus) {
|
if (focus) {
|
||||||
Elem* prev_focus = ctx.find_elem(ctx.hover_id);
|
Elem* prev_focus = ctx.find_elem(ctx.hover_id);
|
||||||
bool different = prev_focus.id != elem.id;
|
bool different = prev_focus.id != elem.id;
|
||||||
bool shown = prev_focus.flags.shown;
|
bool shown = prev_focus.flags.shown;
|
||||||
bool above = prev_focus.z_index > elem.z_index;
|
bool above = prev_focus.z_index > elem.z_index;
|
||||||
|
|
||||||
focus = !(different && shown && above);
|
focus = !(different && shown && above);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hover) ctx.hover_id = elem.id;
|
if (hover) ctx.hover_id = elem.id;
|
||||||
if (focus) ctx.focus_id = elem.id;
|
if (focus) ctx.focus_id = elem.id;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -145,7 +145,7 @@ fn void? Ctx.checkbox_id(&ctx, Id id, String description, bool* active, String t
|
|||||||
if (*active) {
|
if (*active) {
|
||||||
Sprite* sprite = ctx.sprite_atlas.get(tick_sprite)!;
|
Sprite* sprite = ctx.sprite_atlas.get(tick_sprite)!;
|
||||||
Id tex_id = ctx.sprite_atlas.id;
|
Id tex_id = ctx.sprite_atlas.id;
|
||||||
ctx.push_sprite(sprite.rect().center_to(check_bounds), sprite.uv(), tex_id, parent.z_index, type: sprite.type)!;
|
ctx.push_sprite(check_bounds, sprite.uv(), tex_id, parent.z_index, type: sprite.type)!;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (*active) {
|
if (*active) {
|
||||||
|
|||||||
@ -4,9 +4,9 @@ struct ElemSprite {
|
|||||||
Id id;
|
Id id;
|
||||||
}
|
}
|
||||||
|
|
||||||
macro Ctx.sprite(&ctx, String name, ...)
|
macro Ctx.sprite(&ctx, String name, short size = 0, ...)
|
||||||
=> ctx.sprite_id(@compute_id($vasplat), name);
|
=> ctx.sprite_id(@compute_id($vasplat), name, size);
|
||||||
fn void? Ctx.sprite_id(&ctx, Id id, String name)
|
fn void? Ctx.sprite_id(&ctx, Id id, String name, short size = 0)
|
||||||
{
|
{
|
||||||
id = ctx.gen_id(id)!;
|
id = ctx.gen_id(id)!;
|
||||||
Elem* parent, elem;
|
Elem* parent, elem;
|
||||||
@ -16,11 +16,26 @@ fn void? Ctx.sprite_id(&ctx, Id id, String name)
|
|||||||
Sprite* sprite = ctx.sprite_atlas.get(name)!;
|
Sprite* sprite = ctx.sprite_atlas.get(name)!;
|
||||||
elem.sprite.id = ctx.get_sprite_atlas_id(name);
|
elem.sprite.id = ctx.get_sprite_atlas_id(name);
|
||||||
|
|
||||||
elem.layout.w = elem.layout.children.w = @exact(sprite.w);
|
// scale the sprite so that the biggest dimension becomes "size"
|
||||||
elem.layout.h = elem.layout.children.h = @exact(sprite.h);
|
short width = sprite.w;
|
||||||
|
short height = sprite.h;
|
||||||
|
if (size > 0) {
|
||||||
|
if (sprite.w >= sprite.h) {
|
||||||
|
width = size;
|
||||||
|
height = (short)(size * (float)height/width);
|
||||||
|
} else {
|
||||||
|
width = (short)(size * (float)width/height);
|
||||||
|
height = size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elem.layout.w = elem.layout.children.w = @exact(width);
|
||||||
|
elem.layout.h = elem.layout.children.h = @exact(height);
|
||||||
|
elem.layout.content_offset = style.margin + style.border + style.padding;
|
||||||
|
|
||||||
update_parent_size(elem, parent);
|
update_parent_size(elem, parent);
|
||||||
|
|
||||||
Id tex_id = ctx.sprite_atlas.id;
|
Id tex_id = ctx.sprite_atlas.id;
|
||||||
return ctx.push_sprite(elem.bounds, sprite.uv(), tex_id, parent.z_index, type: sprite.type)!;
|
Rect content_bounds = elem.bounds.pad(elem.layout.content_offset);
|
||||||
|
return ctx.push_sprite(content_bounds, sprite.uv(), tex_id, parent.z_index, type: sprite.type)!;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
"type": "executable"
|
"type": "executable"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"opt": "O0",
|
"safe": true,
|
||||||
|
"opt": "O1",
|
||||||
"debug-info": "full"
|
"debug-info": "full"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,7 @@ void sprite_main()
|
|||||||
{
|
{
|
||||||
ivec2 ts = textureSize(sprite_atlas, 0);
|
ivec2 ts = textureSize(sprite_atlas, 0);
|
||||||
vec2 fts = vec2(ts);
|
vec2 fts = vec2(ts);
|
||||||
vec2 real_uv = in_uv / fts;
|
vec2 real_uv = in_uv.xy / fts;
|
||||||
fragColor = texture(sprite_atlas, real_uv);
|
fragColor = texture(sprite_atlas, real_uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ void font_main()
|
|||||||
{
|
{
|
||||||
ivec2 ts = textureSize(font_atlas, 0);
|
ivec2 ts = textureSize(font_atlas, 0);
|
||||||
vec2 fts = vec2(ts);
|
vec2 fts = vec2(ts);
|
||||||
vec2 real_uv = in_uv / fts;
|
vec2 real_uv = in_uv.xy / fts;
|
||||||
|
|
||||||
vec4 opacity = texture(font_atlas, real_uv);
|
vec4 opacity = texture(font_atlas, real_uv);
|
||||||
fragColor = vec4(in_color.rgb, in_color.a*opacity.r);
|
fragColor = vec4(in_color.rgb, in_color.a*opacity.r);
|
||||||
@ -85,7 +85,7 @@ void font_main()
|
|||||||
void msdf_main() {
|
void msdf_main() {
|
||||||
ivec2 ts = textureSize(sprite_atlas, 0);
|
ivec2 ts = textureSize(sprite_atlas, 0);
|
||||||
vec2 fts = vec2(ts);
|
vec2 fts = vec2(ts);
|
||||||
vec2 real_uv = in_uv / fts;
|
vec2 real_uv = in_uv.xy / fts;
|
||||||
|
|
||||||
vec3 msd = texture(sprite_atlas, real_uv).rgb;
|
vec3 msd = texture(sprite_atlas, real_uv).rgb;
|
||||||
float sd = median(msd.r, msd.g, msd.b);
|
float sd = median(msd.r, msd.g, msd.b);
|
||||||
|
|||||||
@ -10,7 +10,7 @@ layout(set = 1, binding = 0) uniform Viewport {
|
|||||||
// inputs
|
// inputs
|
||||||
layout(location = 0) in ivec2 in_position;
|
layout(location = 0) in ivec2 in_position;
|
||||||
layout(location = 1) in ivec4 in_attr; // quad x,y,w,h
|
layout(location = 1) in ivec4 in_attr; // quad x,y,w,h
|
||||||
layout(location = 2) in ivec2 in_uv;
|
layout(location = 2) in ivec4 in_uv;
|
||||||
layout(location = 3) in uvec4 in_color;
|
layout(location = 3) in uvec4 in_color;
|
||||||
layout(location = 4) in uint in_type;
|
layout(location = 4) in uint in_type;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ void main()
|
|||||||
out_color = vec4(in_color) / 255.0;
|
out_color = vec4(in_color) / 255.0;
|
||||||
|
|
||||||
// uv output. only useful if the type is SPRITE
|
// uv output. only useful if the type is SPRITE
|
||||||
vec2 px_uv = in_uv.xy + in_position.xy * in_attr.zw;
|
vec2 px_uv = in_uv.xy + in_position.xy * in_uv.zw;
|
||||||
out_uv = vec2(px_uv);
|
out_uv = vec2(px_uv);
|
||||||
|
|
||||||
// quad size and radius output, only useful if type is RECT
|
// quad size and radius output, only useful if type is RECT
|
||||||
|
|||||||
@ -79,7 +79,7 @@ text-box {
|
|||||||
fg: #fbf1c7ff;
|
fg: #fbf1c7ff;
|
||||||
primary: #cc241dff;
|
primary: #cc241dff;
|
||||||
secondary: #458588ff;
|
secondary: #458588ff;
|
||||||
accent: #fabd2fff;
|
accent: #8f3f61a8;
|
||||||
border: 1;
|
border: 1;
|
||||||
padding: 4;
|
padding: 4;
|
||||||
margin: 2;
|
margin: 2;
|
||||||
|
|||||||
@ -55,7 +55,7 @@ struct QuadAttributes {
|
|||||||
short x, y, w, h;
|
short x, y, w, h;
|
||||||
}
|
}
|
||||||
struct uv {
|
struct uv {
|
||||||
short u, v;
|
short u, v, w, h;
|
||||||
}
|
}
|
||||||
uint color;
|
uint color;
|
||||||
uint type;
|
uint type;
|
||||||
@ -483,7 +483,7 @@ fn void Renderer.create_pipeline(&self, String shader_name, PipelineType type)
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
.num_vertex_buffers = 2,
|
.num_vertex_buffers = 2,
|
||||||
// the description of each vertex
|
// the description of each vertex, quad and bindings
|
||||||
.vertex_attributes = (GPUVertexAttribute[]){
|
.vertex_attributes = (GPUVertexAttribute[]){
|
||||||
{ // at location zero there is the position of the vertex
|
{ // at location zero there is the position of the vertex
|
||||||
.location = 0,
|
.location = 0,
|
||||||
@ -500,7 +500,7 @@ fn void Renderer.create_pipeline(&self, String shader_name, PipelineType type)
|
|||||||
{ // at location two there are the per-quad uv coordinates
|
{ // at location two there are the per-quad uv coordinates
|
||||||
.location = 2,
|
.location = 2,
|
||||||
.buffer_slot = 1,
|
.buffer_slot = 1,
|
||||||
.format = GPU_VERTEXELEMENTFORMAT_SHORT2,
|
.format = GPU_VERTEXELEMENTFORMAT_SHORT4,
|
||||||
.offset = QuadAttributes.uv.offsetof,
|
.offset = QuadAttributes.uv.offsetof,
|
||||||
},
|
},
|
||||||
{ // at location three there is the quad color
|
{ // at location three there is the quad color
|
||||||
@ -713,11 +713,11 @@ const uint TYPE_FONT = 1;
|
|||||||
const uint TYPE_SPRITE = 2;
|
const uint TYPE_SPRITE = 2;
|
||||||
const uint TYPE_MSDF = 3;
|
const uint TYPE_MSDF = 3;
|
||||||
|
|
||||||
fn bool Renderer.push_sprite(&self, short x, short y, short w, short h, short u, short v, uint color = 0xffffffff, uint type)
|
fn bool Renderer.push_sprite(&self, short x, short y, short w, short h, short u, short v, short sw, short sh, uint color = 0xffffffff, uint type)
|
||||||
{
|
{
|
||||||
QuadAttributes qa = {
|
QuadAttributes qa = {
|
||||||
.pos = {.x = x, .y = y, .w = w, .h = h},
|
.pos = {.x = x, .y = y, .w = w, .h = h},
|
||||||
.uv = {.u = u, .v = v},
|
.uv = {.u = u, .v = v, .w = sw, .h = sh},
|
||||||
.color = color,
|
.color = color,
|
||||||
.type = type,
|
.type = type,
|
||||||
};
|
};
|
||||||
@ -980,7 +980,7 @@ fn void Renderer.render_ugui(&self, CmdQueue* queue)
|
|||||||
} else {
|
} else {
|
||||||
unreachable("unrecognized command type");
|
unreachable("unrecognized command type");
|
||||||
}
|
}
|
||||||
self.push_sprite(s.rect.x, s.rect.y, s.texture_rect.w, s.texture_rect.h, s.texture_rect.x, s.texture_rect.y, s.hue.to_uint(), type);
|
self.push_sprite(s.rect.x, s.rect.y, s.rect.w, s.rect.h, s.texture_rect.x, s.texture_rect.y, s.texture_rect.w, s.texture_rect.h, s.hue.to_uint(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.upload_quads();
|
self.upload_quads();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user