1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

gg/ft: minor Sokol fixes

This commit is contained in:
Alexander Medvednikov 2020-06-04 23:51:54 +02:00
parent d0f9bdf85e
commit e7f52ebed6
2 changed files with 24 additions and 8 deletions

View File

@ -53,14 +53,19 @@ pub fn new(c Config) ?&FT{
pub fn (ft &FT) draw_text(x, y int, text string, cfg gx.TextCfg) { pub fn (ft &FT) draw_text(x, y int, text string, cfg gx.TextCfg) {
ft.fons.set_font(ft.font_normal) ft.fons.set_font(ft.font_normal)
ft.fons.set_size(2.0 * ft.scale * f32(cfg.size)) ft.fons.set_size(2.0 * ft.scale * f32(cfg.size))
C.fonsSetAlign(ft.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_TOP) if cfg.align == gx.align_right {
C.fonsSetAlign(ft.fons, C.FONS_ALIGN_RIGHT | C.FONS_ALIGN_TOP)
}
else {
C.fonsSetAlign(ft.fons, C.FONS_ALIGN_LEFT | C.FONS_ALIGN_TOP)
}
color := C.sfons_rgba(cfg.color.r, cfg.color.g, cfg.color.b, 255) color := C.sfons_rgba(cfg.color.r, cfg.color.g, cfg.color.b, 255)
C.fonsSetColor(ft.fons, color) C.fonsSetColor(ft.fons, color)
ascender := f32(0.0) ascender := f32(0.0)
descender := f32(0.0) descender := f32(0.0)
lh := f32(0.0) lh := f32(0.0)
ft.fons.vert_metrics(&ascender, &descender, &lh) ft.fons.vert_metrics(&ascender, &descender, &lh)
C.fonsDrawText(ft.fons, x, y, text.str, 0) // TODO: check offsets/alignment C.fonsDrawText(ft.fons, x*ft.scale, y*ft.scale, text.str, 0) // TODO: check offsets/alignment
} }
pub fn (ft &FT) draw_text_def(x, y int, text string) { pub fn (ft &FT) draw_text_def(x, y int, text string) {

View File

@ -38,6 +38,7 @@ pub:
fail_fn FNFail = voidptr(0) fail_fn FNFail = voidptr(0)
wait_events bool // set this to true for UIs, to save power wait_events bool // set this to true for UIs, to save power
font_path string font_path string
fullscreen bool
} }
pub struct Context { pub struct Context {
@ -127,6 +128,7 @@ f32(cfg.bg_color.b) / 255.0, 1.0)
width: cfg.width width: cfg.width
height: cfg.height height: cfg.height
high_dpi: cfg.scale > 1 high_dpi: cfg.scale > 1
fullscreen: cfg.fullscreen
} }
//b := sapp.high_dpi() //b := sapp.high_dpi()
//println('scale=$g.scale high_dpi=$b') //println('scale=$g.scale high_dpi=$b')
@ -150,14 +152,23 @@ pub fn (ctx &Context) draw_rect(x, y, w, h f32, c gx.Color) {
sgl.end() sgl.end()
} }
pub fn (gg &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) { pub fn (ctx &Context) draw_empty_rect(x, y, w, h f32, c gx.Color) {
sgl.c4b(c.r, c.g, c.b, 128) sgl.c4b(c.r, c.g, c.b, 128)
sgl.begin_line_strip() sgl.begin_line_strip()
sgl.v2f(x, y) if ctx.scale == 1 {
sgl.v2f(x + w, y) sgl.v2f(x, y)
sgl.v2f(x + w, y + h) sgl.v2f(x + w, y)
sgl.v2f(x, y + h) sgl.v2f(x + w, y + h)
sgl.v2f(x, y) sgl.v2f(x, y + h)
sgl.v2f(x, y)
}
else {
sgl.v2f(x * ctx.scale, y * ctx.scale)
sgl.v2f((x + w) * ctx.scale, y * ctx.scale)
sgl.v2f((x + w) * ctx.scale, (y + h) * ctx.scale)
sgl.v2f(x * ctx.scale, (y + h) * ctx.scale)
sgl.v2f(x*ctx.scale, y*ctx.scale)
}
sgl.end() sgl.end()
} }