Start implementing UI for debug viz
This commit is contained in:
parent
bdd7bbb9b1
commit
02d4a7aac5
@ -27,6 +27,7 @@ import "game:physics"
|
||||
import "game:physics/bvh"
|
||||
import "game:physics/collision"
|
||||
import "libs:tracy"
|
||||
import "ui"
|
||||
import rl "vendor:raylib"
|
||||
import "vendor:raylib/rlgl"
|
||||
|
||||
@ -84,6 +85,8 @@ Game_Memory :: struct {
|
||||
assetman: assets.Asset_Manager,
|
||||
runtime_world: Runtime_World,
|
||||
es: Editor_State,
|
||||
ui_context: ui.Context,
|
||||
default_font: rl.Font,
|
||||
editor: bool,
|
||||
preview_bvh: int,
|
||||
preview_node: int,
|
||||
@ -662,9 +665,33 @@ update :: proc() {
|
||||
cam.fovy = 60
|
||||
cam.projection = .PERSPECTIVE
|
||||
|
||||
|
||||
get_runtime_world().camera = cam
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
ui.begin(&g_mem.ui_context)
|
||||
defer ui.end(&g_mem.ui_context)
|
||||
|
||||
if ui.window(
|
||||
&g_mem.ui_context,
|
||||
"Hello, world",
|
||||
ui.Rect{x = 0, y = 0, w = 100, h = 100},
|
||||
ui.Options{.AUTO_SIZE},
|
||||
) {
|
||||
ui.layout_column(&g_mem.ui_context)
|
||||
|
||||
ui.text(&g_mem.ui_context, "It Works!")
|
||||
|
||||
ui.begin_line(&g_mem.ui_context, ui.Color{255, 0, 0, 255})
|
||||
defer ui.end_line(&g_mem.ui_context)
|
||||
|
||||
ui.push_line_point(&g_mem.ui_context, {0, 0})
|
||||
ui.push_line_point(&g_mem.ui_context, {1, 1})
|
||||
}
|
||||
}
|
||||
|
||||
update_runtime_world(get_runtime_world(), dt)
|
||||
}
|
||||
}
|
||||
@ -923,6 +950,8 @@ draw :: proc() {
|
||||
rl.ORANGE,
|
||||
)
|
||||
}
|
||||
|
||||
ui.rl_draw(&g_mem.ui_context)
|
||||
}
|
||||
|
||||
if g_mem.editor {
|
||||
@ -1102,6 +1131,13 @@ game_init :: proc() {
|
||||
|
||||
physics.init_physics_scene(&g_mem.runtime_world.world.physics_scene, 100)
|
||||
|
||||
g_mem.default_font = rl.GetFontDefault()
|
||||
ui.init(&g_mem.ui_context)
|
||||
|
||||
g_mem.ui_context.style.font = ui.Font(&g_mem.default_font)
|
||||
g_mem.ui_context.text_width = ui.rl_measure_text_width
|
||||
g_mem.ui_context.text_height = ui.rl_measure_text_height
|
||||
|
||||
game_hot_reloaded(g_mem)
|
||||
}
|
||||
|
||||
|
1755
game/ui/microui.odin
Normal file
1755
game/ui/microui.odin
Normal file
File diff suppressed because it is too large
Load Diff
16519
game/ui/microui_default_atlas.odin
Normal file
16519
game/ui/microui_default_atlas.odin
Normal file
File diff suppressed because it is too large
Load Diff
71
game/ui/raylib.odin
Normal file
71
game/ui/raylib.odin
Normal file
@ -0,0 +1,71 @@
|
||||
// Raylib renderer for microui
|
||||
|
||||
package ui
|
||||
|
||||
import "core:log"
|
||||
import "core:strings"
|
||||
import rl "vendor:raylib"
|
||||
import "vendor:raylib/rlgl"
|
||||
|
||||
to_rl_color :: proc(c: Color) -> rl.Color {
|
||||
return rl.Color{c.r, c.g, c.b, c.a}
|
||||
}
|
||||
|
||||
rl_get_font_size :: proc(font: Font) -> i32 {
|
||||
font := cast(^rl.Font)font
|
||||
return font.baseSize if font != nil else 16
|
||||
}
|
||||
|
||||
rl_measure_text_2d :: #force_inline proc(font: Font, text: string) -> rl.Vector2 {
|
||||
font_size := rl_get_font_size(font)
|
||||
font := (cast(^rl.Font)font)^ if font != nil else rl.GetFontDefault()
|
||||
size := rl.MeasureTextEx(
|
||||
font,
|
||||
strings.clone_to_cstring(text, context.temp_allocator),
|
||||
f32(font_size),
|
||||
0,
|
||||
)
|
||||
|
||||
return size
|
||||
}
|
||||
|
||||
rl_measure_text_width :: proc(font: Font, text: string) -> i32 {
|
||||
return i32(rl_measure_text_2d(font, text).x)
|
||||
}
|
||||
|
||||
rl_measure_text_height :: proc(font: Font) -> i32 {
|
||||
return i32(rl_measure_text_2d(font, "A").y)
|
||||
}
|
||||
|
||||
rl_draw :: proc(ctx: ^Context) {
|
||||
tmp_cmd: ^Command
|
||||
for cmd in next_command_iterator(ctx, &tmp_cmd) {
|
||||
log.debugf("ui cmd: %v", cmd)
|
||||
switch c in cmd {
|
||||
case ^Command_Clip:
|
||||
rlgl.Scissor(c.rect.x, c.rect.y, c.rect.w, c.rect.h)
|
||||
case ^Command_Text:
|
||||
font := cast(^rl.Font)c.font
|
||||
rl.DrawText(
|
||||
strings.clone_to_cstring(c.str, context.temp_allocator),
|
||||
c.pos.x,
|
||||
c.pos.y,
|
||||
font.baseSize if font != nil else 16,
|
||||
to_rl_color(c.color),
|
||||
)
|
||||
case ^Command_Rect:
|
||||
rl.DrawRectangle(c.rect.x, c.rect.y, c.rect.w, c.rect.h, to_rl_color(c.color))
|
||||
case ^Command_Line:
|
||||
segments := get_line_segments(ctx, c.first_segment, c.num_segments)
|
||||
|
||||
for i in 1 ..< len(segments) {
|
||||
p1 := segments[i - 1]
|
||||
p2 := segments[i]
|
||||
|
||||
rl.DrawLineV(p1, p2, to_rl_color(c.color))
|
||||
}
|
||||
case ^Command_Jump:
|
||||
case ^Command_Icon:
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user