mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
freetype: cleanup calculation of text y position while drawing the text
This commit is contained in:
parent
990e44cd14
commit
bfaf2a4a62
@ -287,17 +287,16 @@ fn (ctx mut FreeType) private_draw_text(_x, _y int, utext ustring, cfg gx.TextCf
|
|||||||
*/
|
*/
|
||||||
mut x := f32(_x)
|
mut x := f32(_x)
|
||||||
mut y := f32(_y)
|
mut y := f32(_y)
|
||||||
|
wx, wy := ctx.text_size(utext.s)
|
||||||
// println('scale=$ctx.scale size=$cfg.size')
|
// println('scale=$ctx.scale size=$cfg.size')
|
||||||
if cfg.align == gx.ALIGN_RIGHT {
|
if cfg.align == gx.ALIGN_RIGHT {
|
||||||
//width := utext.len * 7
|
//width := utext.len * 7
|
||||||
width := ctx.text_width(utext.s)
|
width := wx
|
||||||
x -= width + 10
|
x -= width + 10
|
||||||
}
|
}
|
||||||
x *= ctx.scale// f32(2)
|
x *= ctx.scale
|
||||||
// println('y=$_y height=$ctx.height')
|
y *= ctx.scale
|
||||||
// _y = _y * int(ctx.scale) //+ 26
|
y = f32(ctx.height) - y //invert y direction
|
||||||
y = y * ctx.scale + ((cfg.size * ctx.scale) / 2) + 5 * ctx.scale
|
|
||||||
y = f32(ctx.height) - y
|
|
||||||
color := cfg.color
|
color := cfg.color
|
||||||
// Activate corresponding render state
|
// Activate corresponding render state
|
||||||
ctx.shader.use()
|
ctx.shader.use()
|
||||||
@ -344,7 +343,8 @@ fn (ctx mut FreeType) private_draw_text(_x, _y int, utext ustring, cfg gx.TextCf
|
|||||||
// continue
|
// continue
|
||||||
}
|
}
|
||||||
xpos := x + f32(ch.horizontal_bearing_px.x) * 1
|
xpos := x + f32(ch.horizontal_bearing_px.x) * 1
|
||||||
ypos := y - f32(ch.size.y - ch.horizontal_bearing_px.y) * 1
|
ypos := y - f32(ch.size.y + wy - ch.horizontal_bearing_px.y) * 1
|
||||||
|
//ypos := y - wy
|
||||||
w := f32(ch.size.x) * 1
|
w := f32(ch.size.x) * 1
|
||||||
h := f32(ch.size.y) * 1
|
h := f32(ch.size.y) * 1
|
||||||
// Update VBO for each character
|
// Update VBO for each character
|
||||||
@ -431,8 +431,8 @@ pub fn (ctx mut FreeType) text_size(s string) (int, int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//println('text width "$s" = ${time.ticks() - t} ms')
|
//println('text width "$s" = ${time.ticks() - t} ms')
|
||||||
scaled_x := int(f64(x) / ctx.scale)
|
scaled_x := int(f64(x))
|
||||||
scaled_y := int(f64(maxy) / ctx.scale)
|
scaled_y := int(f64(maxy))
|
||||||
//println('text_size of "${s}" | x,y: $x,$maxy | scaled_x: ${scaled_x:3d} | scaled_y: ${scaled_y:3d} ')
|
//println('text_size of "${s}" | x,y: $x,$maxy | scaled_x: ${scaled_x:3d} | scaled_y: ${scaled_y:3d} ')
|
||||||
return scaled_x, scaled_y
|
return scaled_x, scaled_y
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user