72 lines
1.7 KiB
Odin
72 lines
1.7 KiB
Odin
// Raylib renderer for microui
|
|
|
|
package ui
|
|
|
|
import "core:log"
|
|
import "core:strings"
|
|
import rl "libs:raylib"
|
|
import "libs: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:
|
|
}
|
|
}
|
|
}
|