From 5407d9b062f643a942a6632c96e7847093ca55da Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 23 Aug 2020 04:57:12 +0200 Subject: [PATCH] gg: fix draw_line on hi dpi screens --- vlib/gg/gg.v | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/vlib/gg/gg.v b/vlib/gg/gg.v index db7e2e3a98..c8f6cd2fd7 100644 --- a/vlib/gg/gg.v +++ b/vlib/gg/gg.v @@ -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)