gg: fix draw_line on hi dpi screens

pull/6197/head
Alexander Medvednikov 2020-08-23 04:57:12 +02:00
parent c5eec881c1
commit 5407d9b062
1 changed files with 22 additions and 0 deletions

View File

@ -274,7 +274,29 @@ pub fn (gg &Context) end() {
}
}
fn abs(a f32) f32 {
if a >= 0 {
return a
}
return -a
}
pub fn (ctx &Context) draw_line(x, y, x2, y2 f32, c gx.Color) {
if ctx.scale > 1 {
// Make the line more clear on hi dpi screens: draw a rectangle
mut width := abs(x2 - x)
mut height := abs(y2 - y)
if width == 0 {
width = 1
}
else if height == 0 {
height = 1
}
ctx.draw_rect(x, y, width, height, c)
return
}
sgl.c4b(c.r, c.g, c.b, c.a)
sgl.begin_line_strip()
sgl.v2f(x * ctx.scale, y * ctx.scale)