From d43f0e457c00b168bd98b25054599ce4d8f1fe62 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 31 Jul 2024 21:54:42 +0300 Subject: [PATCH] gg: add an optional size: parameter to the .draw_pixels and .draw_pixel methods (defaults to 1.0) --- vlib/gg/draw.c.v | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/vlib/gg/draw.c.v b/vlib/gg/draw.c.v index e8ddf08c1b..989cdcdd01 100644 --- a/vlib/gg/draw.c.v +++ b/vlib/gg/draw.c.v @@ -6,19 +6,24 @@ import gx import math import sokol.sgl +@[params] +pub struct DrawPixelConfig { +pub mut: + size f32 = 1.0 +} + // draw_pixel draws one pixel on the screen. // // NOTE calling this function frequently is very *inefficient*, // for drawing shapes it's recommended to draw whole primitives with // functions like `draw_rect_empty` or `draw_triangle_empty` etc. -@[inline] -pub fn (ctx &Context) draw_pixel(x f32, y f32, c gx.Color) { +pub fn (ctx &Context) draw_pixel(x f32, y f32, c gx.Color, params DrawPixelConfig) { if c.a != 255 { sgl.load_pipeline(ctx.pipeline.alpha) } - sgl.c4b(c.r, c.g, c.b, c.a) - sgl.begin_points() + sgl.c4b(c.r, c.g, c.b, c.a) + sgl.point_size(params.size) sgl.v2f(x * ctx.scale, y * ctx.scale) sgl.end() } @@ -28,8 +33,8 @@ pub fn (ctx &Context) draw_pixel(x f32, y f32, c gx.Color) { // NOTE calling this function frequently is very *inefficient*, // for drawing shapes it's recommended to draw whole primitives with // functions like `draw_rect_empty` or `draw_triangle_empty` etc. -@[direct_array_access; inline] -pub fn (ctx &Context) draw_pixels(points []f32, c gx.Color) { +@[direct_array_access] +pub fn (ctx &Context) draw_pixels(points []f32, c gx.Color, params DrawPixelConfig) { if points.len % 2 != 0 { return } @@ -38,9 +43,9 @@ pub fn (ctx &Context) draw_pixels(points []f32, c gx.Color) { if c.a != 255 { sgl.load_pipeline(ctx.pipeline.alpha) } - sgl.c4b(c.r, c.g, c.b, c.a) - sgl.begin_points() + sgl.c4b(c.r, c.g, c.b, c.a) + sgl.point_size(params.size) for i in 0 .. len { x, y := points[i * 2], points[i * 2 + 1] sgl.v2f(x * ctx.scale, y * ctx.scale)