more microui

This commit is contained in:
2026-03-25 17:48:46 +05:45
parent 5bc235f1ab
commit 00ae6cbc4e
5 changed files with 239 additions and 42 deletions
+37 -18
View File
@@ -36,6 +36,7 @@ engine_state :: struct
input : input_state,
mu_ctx : mu.Context,
mu_tex : u32,
}
MAX_KEYS :: 512
@@ -177,14 +178,43 @@ engine_init :: proc($GameType : typeid, state: ^engine_state, font_path : strin
//Glyph and microui
{
//Create index
mu.init(&state.mu_ctx)
state.mu_ctx.style.font = cast(mu.Font)&state.draw.glyph
state.mu_ctx.text_width = mui_text_width
state.mu_ctx.text_height = mui_text_height
texture_data := make([]u8, mu.DEFAULT_ATLAS_WIDTH* mu.DEFAULT_ATLAS_HEIGHT * 4)
idx :i32 = 0
for y in 0..<mu.DEFAULT_ATLAS_HEIGHT
{
for x in 0..<mu.DEFAULT_ATLAS_WIDTH
{
texture_data[idx + 0] = 255
texture_data[idx + 1] = 255
texture_data[idx + 2] = 255
texture_data[idx + 3] = mu.default_atlas_alpha[idx/4]
idx += 4
}
}
state.mu_tex = e2_draw.create_texture(texture_data, mu.DEFAULT_ATLAS_WIDTH, mu.DEFAULT_ATLAS_HEIGHT)
}
}
normalize_rect :: proc(rect : mu.Rect, size : i32) -> e2_draw.Rect
{
points : e2_draw.Rect
points.x = f32(rect.x) / f32(size)
points.y = f32(rect.y) / f32(size)
points.w = f32(rect.w) / f32(size)
points.h = f32(rect.h) / f32(size)
return points
}
update_frame :: proc(state: ^engine_state)
{
@@ -264,7 +294,7 @@ end_frame :: proc(state: ^engine_state)
for &p, i in &points do points[i] = e2_draw.camera_convert_screen_to_world(&draw.cam, p)
color := c.color
//hex_color := e2_draw.make_hex_color({color.r, color.g, color.b, color.a})
e2_draw.solid_polygon_add(&draw.polygons, {q = e2_draw.Rot{c = 1}}, &points[0], 4, 0, transmute([4]u8)color)
e2_draw.solid_polygon_add(&draw.polygons, {q = e2_draw.Rot{c = 1}}, &points[0], 4, 0.01, transmute([4]u8)color)
}
case ^mu.Command_Clip:
{
@@ -272,19 +302,13 @@ end_frame :: proc(state: ^engine_state)
gl.Scissor(rect.x, state.height - (rect.y + rect.h), rect.w, rect.h)
}
case ^mu.Command_Icon:{
rect := mu.default_atlas[c.id]
if c.id == .CHECK
{
pos :[2]f32= {f32(c.rect.x), f32(c.rect.y)}
pos.x += f32(c.rect.w)/2.0
pos.y += f32(c.rect.h)/2.0
pos = e2_draw.camera_convert_screen_to_world(&draw.cam, pos)
e2_draw.solid_circle_add(&draw.solid_circles,{p = pos, q = e2_draw.Rot{c = 1}} , 0.1,{255, 255, 255, 255})
}else{
fmt.println(c.id)
}
append(&draw.textures.textures, e2_draw.TextureData{
texture_id = state.mu_tex,
src_rect = normalize_rect(rect, mu.DEFAULT_ATLAS_WIDTH),
dst_rect = e2_draw.Rect{f32(c.rect.x), f32(c.rect.y), f32(rect.w), f32(rect.h)},
})
}
}
@@ -346,8 +370,3 @@ draw_flush :: proc(d: ^e2_draw.Draw)
e2_draw.draw_flush(d)
}